jinlin
2024-11-19 195bb5267a6ece13363303e177fee7d1fa3941aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 
<mapper namespace="com.zt.life.modules.mainPart.baseReliability.dao.ParamDataBasicDao">
    <update id="compute">
        update param_data f,
            (
                SELECT c.*,
                       CASE
                           WHEN WeightedFailure IS NOT NULL
                               AND WeightedFailure > 0 THEN
                               1 / WeightedFailure
                           ELSE 0
                           END AS basic_mtbf_regulate_tmp,
                       CASE
                           WHEN WeightedFailure IS NOT NULL
                               AND WeightedFailure > 0 THEN
                               WeightedMTTR / WeightedFailure
                           ELSE 0
                           END AS repair_mttcr
                FROM (
                         SELECT c.id,
                                c.name,
                                sum(
                                        CASE
                                            WHEN b.product_type &lt; 5 THEN
                                                1 * 1 / basic_mtbf_regulate_tmp
                                            WHEN a.reliab_distrib_type = 1 THEN
                                                    a.basic_unit_num * a.basic_mtbf_operating_ratio /
                                                    a.basic_mtbf_regulate_tmp
                                            WHEN a.reliab_distrib_type = 3 THEN
                                                    a.basic_unit_num * a.basic_mtbf_operating_ratio /
                                                    a.basic_mtbf_regulate_tmp
                                            ELSE 0 END
                                    ) AS WeightedFailure,
                                sum(
                                        CASE
                                            WHEN b.product_type &lt; 5 THEN
                                                1 * 1 * a.repair_mttcr / a.basic_mtbf_regulate_tmp
                                            WHEN a.repairable = 1 and a.reliab_distrib_type = 1 THEN
                                                    a.basic_unit_num * a.basic_mtbf_operating_ratio * a.repair_mttcr /
                                                    a.basic_mtbf_regulate_tmp
                                            WHEN a.repairable = 1 and a.reliab_distrib_type = 3 THEN
                                                    a.basic_unit_num * a.basic_mtbf_operating_ratio * a.repair_mttcr /
                                                    a.basic_mtbf_regulate_tmp
                                            ELSE 0
                                            END
                                    ) AS WeightedMttr
                         FROM param_data a,
                              product_model b,
                              product_model c
                         WHERE 1 = 1
                           and c.ship_id = ${shipId}
                           and c.product_type = ${productType}
                           and c.is_delete = 0
                           and b.ship_id = ${shipId}
                           and b.pid = c.id
                           and b.is_delete = 0
                           and a.IS_DELETE = 0
                           and a.product_id = b.id
                           AND ((b.product_type = 5 AND a.basic_join_compute = 1
                             and ((
                                          a.reliab_distrib_type = 1
                                          AND a.basic_mtbf_regulate_tmp > 0
                                      )
                                 OR (a.reliab_distrib_type = 3 AND a.basic_mtbf_regul_succ_rate > 0))
                                    )
                             || (b.product_type &lt; 5 AND a.basic_mtbf_regulate_tmp > 0))
                         GROUP BY c.id, c.name
                     ) c
            ) d
        set f.basic_mtbf_regulate_tmp = d.basic_mtbf_regulate_tmp,
            f.repair_mttcr            = d.repair_mttcr
        where f.product_id = d.id;
    </update>
 
    <update id="compute1">
        UPDATE param_data a, product_model b
        SET repair_mttcr = 0
        where b.ship_id = ${shipId}
          and repair_mttcr is null;
 
        UPDATE param_data a, product_model b
        SET basic_mtbf_regulate_tmp = basic_mtbf_regulate
        where b.ship_id = ${shipId};
 
        UPDATE param_data a, product_model b
        SET basic_mtbf_regulate_tmp = basic_mtbf_regul_succ_rate/(1-basic_mtbf_regul_succ_rate)
        where b.ship_id = ${shipId}
          and reliab_distrib_type = 3
    </update>
 
    <update id="compute2">
        UPDATE param_data a, product_model b
        SET basic_mtbf_regulate = basic_mtbf_regulate_tmp
        where b.ship_id = ${shipId}
          and (reliab_distrib_type = 1 or reliab_distrib_type is null)
          and a.product_id = b.id
          and a.IS_DELETE = 0
          and b.IS_DELETE = 0;
 
        UPDATE param_data a, product_model b
        SET ai = basic_mtbf_regulate_tmp / (basic_mtbf_regulate_tmp + repair_mttcr)
        where b.ship_id = ${shipId}
          and a.product_id = b.id
          and a.IS_DELETE = 0
          and b.IS_DELETE = 0;
 
        UPDATE param_data a,(
            select pid, case when count(1) > 0 then 1 else 0 end as basic_join_compute
            from param_data a,
                 product_model b
            where b.ship_id = ${shipId}
              and a.product_id = b.id
              and a.basic_join_compute = 1
              and b.product_type = 5
            group by b.pid
        ) b
        set a.basic_join_compute = b.basic_join_compute
        where a.product_id = b.pid;
 
        UPDATE param_data a,(
            select pid, case when count(1) > 0 then 1 else 0 end as basic_join_compute
            from param_data a,
                 product_model b
            where b.ship_id = ${shipId}
              and a.product_id = b.id
              and a.basic_join_compute = 1
              and b.product_type = 4
            group by b.pid
        ) b
        set a.basic_join_compute = b.basic_join_compute
        where a.product_id = b.pid;
 
        UPDATE param_data a,(
            select pid, case when count(1) > 0 then 1 else 0 end as basic_join_compute
            from param_data a,
                 product_model b
            where b.ship_id = ${shipId}
              and a.product_id = b.id
              and a.basic_join_compute = 1
              and b.product_type = 3
            group by b.pid
        ) b
        set a.basic_join_compute = b.basic_join_compute
        where a.product_id = b.pid;
    </update>
 
    <select id="getAI" resultType="com.zt.life.modules.mainPart.basicInfo.model.ParamData">
        SELECT a.NAME,
               a.id,
               a.pid,
               b.ai,
               b.basic_mtbf_regulate,
               b.repair_mttcr,
               b.basic_mtbf_operating_ratio,
               b.basic_mtbf_regul_succ_rate,
               b.basic_runs_num,
               b.basic_unit_num
        FROM product_model a
                 LEFT JOIN param_data b ON b.product_id = a.id and b.is_delete = 0
        where a.is_delete = 0
            and a.product_type &lt;&gt; 10
            and b.basic_join_compute = 1
            and a.ship_id = ${shipId}
           or a.id = ${shipId}
        ORDER BY a.product_type, a.sort
    </select>
 
</mapper>