郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?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.gkhy.safePlatform.safeCheck.repository.SafeCheckTaskAndQuotaRepository" >
    <resultMap id="BaseResultMap" type="com.gkhy.safePlatform.safeCheck.entity.SafeCheckTaskAndQuota" >
        <id column="id" property="id" />
        <result column="task_id" property="taskId"/>
        <result column="task_uuid" property="taskUuid" />
        <result column="point" property="point" />
        <result column="point_id" property="pointId" />
        <result column="region" property="region" />
        <result column="region_id" property="regionId" />
        <result column="rfid" property="rfid" />
        <result column="rfid_id" property="rfidId" />
        <result column="rfid_name" property="rfidName"></result>
        <result column="rfid_position" property="rfidPosition" />
        <result column="quota_unit" property="quotaUnit" />
        <result column="quota_content" property="quotaContent" />
        <result column="exec_sequence" property="execSequence" />
        <result column="data_report_type" property="dataReportType" />
        <result column="first_reference_value" property="firstReferenceValue" />
        <result column="second_reference_sign" property="secondReferenceSign" />
        <result column="second_reference_value" property="secondReferenceValue" />
        <result column="third_reference_sign" property="thirdReferenceSign" />
        <result column="third_reference_value" property="thirdReferenceValue" />
        <result column="first_reference_result" property="firstReferenceResult" />
        <result column="second_reference_result" property="secondReferenceResult" />
        <result column="point_check_status" property="pointCheckStatus" />
        <result column="report_result" property="reportResult" />
        <result column="report_time" property="reportTime" />
        <result column="exception_desc" property="exceptionDesc"/>
    </resultMap>
 
    <sql id="allTaskAndQuotaFields">
        id,task_id,task_uuid,point_id,point,region_id,region,rfid,rfid_id,rfid_name,rfid_position,quota_unit,quota_content,exec_sequence,
            data_report_type,first_reference_value,second_reference_sign,second_reference_value,third_reference_sign,third_reference_value
            ,first_reference_result,second_reference_result,point_check_status,report_result,report_time,exception_desc
    </sql>
    
    <insert id="saveTaskAndQuotas">
        insert into safe_check_task_and_quota
        (task_id,task_uuid,point_id,point,region_id,region,rfid,rfid_id,rfid_name,rfid_position,quota_unit,quota_content,exec_sequence,
        data_report_type,first_reference_value,second_reference_sign,second_reference_value,third_reference_sign,third_reference_value
        ,first_reference_result,second_reference_result,point_check_status,report_result,report_time,exception_desc
        )
        values
        <foreach collection="taskAndQuotas" item="taskAndQuota"   separator="," >
            (#{taskAndQuota.taskId},
            #{taskAndQuota.taskUuid},
            #{taskAndQuota.pointId},
            #{taskAndQuota.point},
            #{taskAndQuota.regionId},
            #{taskAndQuota.region},
            #{taskAndQuota.rfid},
            #{taskAndQuota.rfidId},
            #{taskAndQuota.rfidName},
            #{taskAndQuota.rfidPosition},
            #{taskAndQuota.quotaUnit},
            #{taskAndQuota.quotaContent},
            #{taskAndQuota.execSequence},
            #{taskAndQuota.dataReportType},
            #{taskAndQuota.firstReferenceValue},
            #{taskAndQuota.secondReferenceSign},
            #{taskAndQuota.secondReferenceValue},
            #{taskAndQuota.thirdReferenceSign},
            #{taskAndQuota.thirdReferenceValue},
            #{taskAndQuota.firstReferenceResult},
            #{taskAndQuota.secondReferenceResult},
            #{taskAndQuota.pointCheckStatus},
            #{taskAndQuota.reportResult},
            #{taskAndQuota.reportTime},
            #{taskAndQuota.exceptionDesc}
            )
        </foreach>
    </insert>
 
 
    <update id="updateRfidPositionStatusByTaskIdAndRfid">
        update safe_check_task_and_quota
        <set>
            <if test="rifdPositionStatus != null">
                rfid_position = #{rifdPositionStatus}
            </if>
            where task_id = #{taskId} and rfid = #{rfid}
        </set>
    </update>
 
 
    <update id="updatePointCheckResultByIdAndTaskId">
        update safe_check_task_and_quota
        <set>
            <if test="taskAndQuota.firstReferenceResult != null">
                first_reference_result = #{taskAndQuota.firstReferenceResult},
            </if>
            <if test="taskAndQuota.secondReferenceResult != null">
                second_reference_result = #{taskAndQuota.secondReferenceResult},
            </if>
            <if test="taskAndQuota.pointCheckStatus != null">
                point_check_status = #{taskAndQuota.pointCheckStatus},
            </if>
            <if test="taskAndQuota.reportResult != null">
                report_result = #{taskAndQuota.reportResult},
            </if>
            <if test="taskAndQuota.reportTime != null">
                report_time = #{taskAndQuota.reportTime}
            </if>
            where task_id = #{taskAndQuota.taskId} and id = #{taskAndQuota.id}
        </set>
    </update>
 
    <select id="countRfidReportIsAbnormalByTaskId" resultType="int">
        select count(*)
        from safe_check_task_and_quota
        where task_id = #{taskId} and report_result = #{reportResult}
    </select>
 
    <select id="findTaskAndQuotaByTaskId"
            resultType="com.gkhy.safePlatform.safeCheck.entity.SafeCheckTaskAndQuota">
        select
        <include refid="allTaskAndQuotaFields"></include>
        from safe_check_task_and_quota
        where id in (
        select id from safe_check_task_and_quota where task_id = #{id}
        )
    </select>
 
    <select id="getTaskAndQuotaById" resultType="com.gkhy.safePlatform.safeCheck.entity.SafeCheckTaskAndQuota">
        select
        <include refid="allTaskAndQuotaFields"></include>
        from safe_check_task_and_quota
        where id  = #{id}
    </select>
 
    <select id="countRfidSameByTaskId" resultType="java.lang.Integer">
        select count(*)
        from safe_check_task_and_quota
        <where>
            <if test="taskId != null">
                task_id = #{taskId}
            </if>
            <if test="rfid" >
                and rfid = #{rfid}
            </if>
        </where>
    </select>
 
    <select id="selectNoRfidPositionByTaskId" resultType="java.lang.String">
        select point
        from safe_check_task_and_quota
        where task_id = #{taskId} and rfid_position = 1
    </select>
 
    <select id="selectRfidNoReportByTaskId" resultType="java.lang.String">
        select point
        from safe_check_task_and_quota
        where task_id = #{taskId} and report_result is null;
    </select>
 
 
    <select id="listTaskAndQuotaByTaskId"
            resultType="com.gkhy.safePlatform.safeCheck.entity.SafeCheckTaskAndQuota">
        select
        <include refid="allTaskAndQuotaFields"></include>
        from safe_check_task_and_quota
        where task_id = #{taskId}
    </select>
 
 
    <select id="getTaskAndQuotaByIdAndTaskId"
            resultType="com.gkhy.safePlatform.safeCheck.entity.SafeCheckTaskAndQuota">
        select
        <include refid="allTaskAndQuotaFields"></include>
        from safe_check_task_and_quota
        where id = #{id} and task_id = #{taskId}
    </select>
 
 
    <select id="getWorkOrderRelatedData" parameterType="int"
            resultType="com.gkhy.safePlatform.safeCheck.entity.WorkOrderRelatedDataDO">
        SELECT
               temp.*,rf.exception_handler_id
        from
             (
                 SELECT
                        t.id,
                        t.task_id,
                        t.point_id,
                        t.point as point_code,
                        t.region_id,
                        r.region_department_id as region_dep,
                        r.region,
                        r.region_type,
                        t.rfid_id,
                        t.rfid_name,
                        t.data_report_type,
                        t.first_reference_value,
                        t.second_reference_sign,
                        t.second_reference_value,
                        t.third_reference_sign,
                        t.third_reference_value,
                        t.first_reference_result,
                        t.second_reference_result
                 from
                         (SELECT * from safe_check_task_and_quota WHERE id = #{id}) t
                          LEFT JOIN
                          safe_check_region r
                              ON t.region_id = r.id
                                     and
                                 r.delete_status = 0
                 )
                 as
                 temp
                 LEFT JOIN
                 safe_check_rfid rf
                     ON
                         temp.rfid_id = rf.id
                             and
                         rf.delete_status = 0
    </select>
</mapper>