zf
2023-08-30 464fe41610a39c3a06f070d5a01c930134ff0163
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
<?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.gk.hotwork.Mapper.InspectionHiddenDangerMapper" >
     <update id="delByInspectionItemId">
       update inspection_hidden_danger set valid_flag = 0 , update_time = #{inspectionHiddenDanger.updateTime},update_by = #{inspectionHiddenDanger.updateBy}
        where self_inspection_item_id = #{inspectionHiddenDanger.selfInspectionItemId}
     </update>
 
    <update id="delByIds">
        update inspection_hidden_danger
        set valid_flag = 0
        where
            id in
        <foreach collection="idList" item="id" close=")" open="(" separator=",">
            #{id}
        </foreach>
 
    </update>
 
    <select id="selectPages" resultType="com.gk.hotwork.Domain.SafetySelfInspectionDO">
        SELECT
        l.*
        FROM
        (
        SELECT
        t.*,
        ( CASE WHEN t.unRectifyCount = t.hdTocalCount THEN - 1 WHEN t.rectifyCount = t.hdTocalCount THEN 2 ELSE 1 END ) rectificationStatus
        FROM
        (
        SELECT
        s.*,
        count( h.`status` = - 1 OR NULL ) unRectifyCount,
        count( h.`status` = 1 OR NULL ) rectifyCount,
        count( h.`status` ) hdTocalCount,
        count( h.LEVEL = 1 OR NULL ) sameAsCount,
        count( h.LEVEL = 2 OR NULL ) majorCount
        FROM
        safety_self_inspection s
        LEFT JOIN inspection_hidden_danger h ON s.id = h.self_inspection_id
        WHERE
        s.valid_flag = 1
        AND h.valid_flag = 1
        AND h.id IS NOT NULL
        GROUP BY
        s.id
        ) t
        ) l
        LEFT JOIN company AS co ON l.checked_company_id = co.id
        WHERE
        1 =1
        <if test="params.inspectionName != null  and params.inspectionName != ''">
            and l.inspection_name like concat("%",#{params.inspectionName},"%")
        </if>
        <if test="params.checkedCompanyId != null and params.checkedCompanyId != ''">
            and l.checked_company_id = #{params.checkedCompanyId}
        </if>
        <if test="params.checkedCompanyName != null and params.checkedCompanyName != ''">
            and l.checked_company_name like concat("%",#{params.checkedCompanyName},"%")
        </if>
        <if test="params.flag != null  and params.flag != '' ">
            and l.flag = #{params.flag}
        </if>
        <if test="params.rectificationStatus != null  and params.rectificationStatus != '' ">
            and l.rectificationStatus = #{params.rectificationStatus}
        </if>
        <if test="params.inspectionStartTime != null and params.inspectionStartTime != ''" >
            and l.inspection_time <![CDATA[ >= ]]> #{params.inspectionStartTime}
        </if>
        <if test="params.inspectionEndTime != null and params.inspectionEndTime != ''" >
            and l.inspection_time <![CDATA[ <= ]]> #{params.inspectionEndTime}
        </if>
        <if test="params.province != null and params.province != ''" >
            and co.province = #{params.province}
        </if>
        <if test="params.city != null and params.city != ''" >
            and co.city = #{params.city}
        </if>
        <if test="params.area != null and params.area != ''" >
            and co.area = #{params.area}
        </if>
        ORDER BY l.create_time desc
    </select>
    <select id="inspectionHdangerlist" resultType="com.gk.hotwork.Domain.InspectionHiddenDanger">
        SELECT
            h.*,
            i.element_a,
            a.`name` as elementAname,
            i.element_b,
            b.`name` as elementBname,
            i.element_c ,
            c.`name` as elementCname,
            i.standardization_requirements,
            i.enterprise_standard,
            i.review_method,
            i.veto
        FROM
            inspection_hidden_danger h
                LEFT JOIN safety_self_inspection_item s ON h.self_inspection_item_id = s.id
                LEFT JOIN safety_inspection_item i ON s.safety_inspection_item_id = i.id
                left join element_management a on a.id = i.element_a
                left join element_management b on b.id = i.element_b
                left join element_management c on c.id = i.element_c
        where h.valid_flag = 1
        and h.self_inspection_id = #{selfInspectionId}
    </select>
 
    <select id="getStatisticHiddenDanger" resultType="com.gk.hotwork.Domain.Do.CompanyInspectionCountDO">
        select
            l.checked_company_id as companyId,
            count(l.id) as checkTotal,
            sum(l.unRectifyTotal) as sUnReTotal,
            sum(l.reTotal) as sReTotal,
            sum(l.hdTocal) as sHdTotal,
            sum(l.saTotal) as sSaTotal,
            sum(l.maTotal) as sMaTotal,
            sum(l.saReTotal) as sSaReTotal,
            sum(l.maReTotal) as sMaReTotal
        from (
                 SELECT
                     s.id,
                     s.checked_company_id,
                     t.*
                 FROM
                     safety_self_inspection s
                         INner JOIN company c on s.checked_company_id = c.id
                         LEFT JOIN (
                         SELECT
                             h.self_Inspection_id,
                             count( h.`status` = - 1 OR NULL ) unRectifyTotal,
                             count( h.`status` = 1 OR NULL ) reTotal,
                             count( h.`status` ) hdTocal,
                             count( h.LEVEL = 1 OR NULL ) saTotal,
                             count( h.LEVEL = 2 OR NULL ) maTotal,
                             count( h.LEVEL = 1 AND h.`status` = 1 OR NULL ) saReTotal,
                             count( h.LEVEL = 2 AND h.`status` = 1 OR NULL ) maReTotal
                         FROM
                             inspection_hidden_danger h
                         WHERE
                             h.valid_flag = 1
                         GROUP BY
                             h.self_Inspection_id
                     ) t ON t.self_Inspection_id = s.id
                 WHERE
                        s.valid_flag = 1
                        and s.flag = 2
                    <if test="query.startTime != null" >
                        and s.inspection_time <![CDATA[ >= ]]> #{query.startTime}
                    </if>
                    <if test="query.endTime != null" >
                        and s.inspection_time <![CDATA[ <= ]]> #{query.endTime}
                    </if>
                    <if test="query.area != null and query.area != ''" >
                        and c.area = #{query.area}
                    </if>
             ) l
        GROUP BY l.checked_company_id
    </select>
 
</mapper>