郑永安
2023-09-19 69185134fcfaf913ea45f1255677225a2cc311a4
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
<?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.doublePrevention.repository.PreventDangerCheckTaskRepository">
 
    <resultMap id="BaseResultMap" type="com.gk.hotwork.doublePrevention.entity.PreventDangerCheckTask">
        <id property="id" column="id"/>
        <result property="uuid" column="uuid"/>
        <result property="deleteStatus" column="delete_status"/>
        <result property="result" column="result"/>
        <result property="taskStatus" column="task_status"/>
        <result property="taskBelong" column="task_belong"/>
        <result property="belongTime" column="belong_time"/>
        <result property="taskType" column="task_type"/>
        <result property="startTime" column="start_time"/>
        <result property="validTime" column="valid_time"/>
        <result property="noticeTime" column="notice_time"/>
        <result property="gmtCreate" column="gmt_create"/>
        <result property="gmtModitify" column="gmt_moditify"/>
        <result property="checkWorkId" column="check_work_id"/>
        <result property="checkTaskUnitId" column="check_task_unit_id"/>
        <result property="execUserId" column="exec_user_id"/>
        <result property="enterpriseId" column="enterprise_id"/>
        <result property="checkTaskUnitUuid" column="check_task_unit_uuid"/>
        <result property="checkWorkUuid" column="check_work_uuid"/>
        <result property="enterpriseUuid" column="enterprise_uuid"/>
        <result property="taskCode" column="task_code"/>
        <result property="execUserName" column="exec_user_name"/>
        <result property="createUserName" column="create_user_name"/>
        <result property="lastEditUserName" column="last_edit_user_name"/>
        <result property="execDepId" column="exec_dep_id"/>
        <result property="execDepUuid" column="exec_dep_uuid"/>
        <result property="desc" column="desc"/>
        <result column="report_status" property="reportStatus"/>
        <result column="report_time" property="reportTime"/>
        <result column="update_report_data_time" property="updateReportDataTime"/>
        <result column="report_switch" property="reportSwitch"/>
    </resultMap>
 
    <resultMap id="PreventTaskRectifyDO" type="com.gk.hotwork.doublePrevention.entity.PreventDangerCheckTaskRectifyDO">
        <result property="manageId" column="manage_id"/>
        <result property="manageUuid" column="manage_uuid"/>
        <result property="registerTime" column="register_time"/>
        <result property="dangerLevel" column="danger_level"/>
        <result property="dangerType" column="danger_type"/>
        <result property="dangerSource" column="danger_source"/>
        <result property="dangerStatus" column="danger_status"/>
        <result property="registantId" column="registant_id"/>
        <result property="produceDeviceId" column="produce_device_id"/>
        <result property="dangerCode" column="danger_code"/>
        <result property="registantName" column="registant_name"/>
        <result property="dangerDesc" column="danger_desc"/>
        <result property="dangerReason" column="danger_reason"/>
        <result property="dangerResult" column="danger_result"/>
        <result property="depId" column="dep_id"/>
        <result property="riskUnitId" column="risk_unit_id"/>
        <result property="dangerReview" column="danger_review"/>
        <result property="dangerCloseReason" column="danger_close_reason"/>
        <result property="rectifyId" column="rectify_id"/>
        <result property="rectifyType" column="rectify_type"/>
        <result property="rectifyTime" column="rectify_time"/>
        <result property="liablePersonId" column="liable_person_id"/>
        <result property="checkAcceptTime" column="check_accept_time"/>
        <result property="checkAcceptPersonId" column="check_accept_person_id"/>
        <result property="liablePerson" column="liable_person"/>
        <result property="checkAcceptPerson" column="check_accept_person"/>
        <result property="rectifyDepId" column="rectify_dep_id"/>
        <result property="rectifyDesc" column="rectify_desc"/>
        <result property="cost" column="cost"/>
        <result property="rectifyApplyTime" column="rectify_apply_time"/>
        <result property="timeOutDesc" column="time_out_desc"/>
        <result property="rectifyInfo" column="rectify_info"/>
    </resultMap>
 
    <!--IPage<PreventDangerCheckTask> getTaskPage(Page<Object> page, PreventDangerCheckTaskQueryReqDTO taskQueryReqDTO);-->
    <select id="getTaskPage" resultMap="BaseResultMap">
        select * from prevent_danger_check_task
        <where>
            delete_status = 0
            <if test="taskQueryReqDTO.taskStatus != 3 and taskQueryReqDTO.taskStatus != null">
                and task_status = #{taskQueryReqDTO.taskStatus}
                <if test="taskQueryReqDTO.result != null">
                    and result = #{taskQueryReqDTO.result}
                </if>
                <if test="taskQueryReqDTO.taskType != null">
                    and task_type = #{taskQueryReqDTO.taskType}
                </if>
                <if test="taskQueryReqDTO.execDepId != null">
                    and exec_dep_id = #{taskQueryReqDTO.execDepId}
                </if>
            </if>
 
            <if test="taskQueryReqDTO.taskStatus == 3">
                and task_status = #{taskQueryReqDTO.taskStatus} and task_belong =2
                <if test="taskQueryReqDTO.result != null">
                    and result = #{taskQueryReqDTO.result}
                </if>
                <if test="taskQueryReqDTO.taskType != null">
                    and task_type = #{taskQueryReqDTO.taskType}
                </if>
                <if test="taskQueryReqDTO.execDepId != null">
                    and exec_dep_id = #{taskQueryReqDTO.execDepId}
                </if>
            </if>
 
            <if test="taskQueryReqDTO.taskStatus == null">
                and (task_status !=3
                    <if test="taskQueryReqDTO.result != null">
                    and result = #{taskQueryReqDTO.result}
                    </if>
                    <if test="taskQueryReqDTO.taskType != null">
                        and task_type = #{taskQueryReqDTO.taskType}
                    </if>
                    <if test="taskQueryReqDTO.execDepId != null">
                        and exec_dep_id = #{taskQueryReqDTO.execDepId}
                    </if>)
                or (task_status =3 and task_belong = 2
                    <if test="taskQueryReqDTO.result != null">
                    and result = #{taskQueryReqDTO.result}
                    </if>
                    <if test="taskQueryReqDTO.taskType != null">
                        and task_type = #{taskQueryReqDTO.taskType}
                    </if>
                    <if test="taskQueryReqDTO.execDepId != null">
                        and exec_dep_id = #{taskQueryReqDTO.execDepId}
                    </if>)
            </if>
        </where>
        order by gmt_create desc
 
<!--        select * from-->
<!--            (select * from prevent_danger_check_task where task_status !=3 or (task_status =3 and task_belong = 2))-->
<!--        as t-->
<!--        <where>-->
<!--            delete_status = 0-->
<!--            <if test="taskQueryReqDTO.result != null">-->
<!--                and result = #{taskQueryReqDTO.result}-->
<!--            </if>-->
<!--            <if test="taskQueryReqDTO.taskStatus != null">-->
<!--                and task_status = #{taskQueryReqDTO.taskStatus}-->
<!--            </if>-->
<!--            <if test="taskQueryReqDTO.taskType != null">-->
<!--                and task_type = #{taskQueryReqDTO.taskType}-->
<!--            </if>-->
<!--            <if test="taskQueryReqDTO.execDepId != null">-->
<!--                and exec_dep_id = #{taskQueryReqDTO.execDepId}-->
<!--            </if>-->
<!--        </where>-->
<!--        order by gmt_create desc-->
    </select>
 
<!--    IPage<PreventDangerCheckTask> getTaskPageForMobile(Page<Object> page, PreventDangerCheckTaskQueryReqDTO taskQueryReqDTO);-->
    <select id="getTaskPageForMobile"  resultMap="BaseResultMap">
        select * from prevent_danger_check_task
        <where>
            delete_status = 0
            <if test="taskQueryReqDTO.taskStatus != 3">
                and task_status = #{taskQueryReqDTO.taskStatus} and task_type = #{taskQueryReqDTO.taskType}
                <if test="taskQueryReqDTO.execDepId != null">
                    and exec_dep_id = #{taskQueryReqDTO.execDepId}
                </if>
            </if>
            <if test="taskQueryReqDTO.taskStatus == 3">
                and task_status = #{taskQueryReqDTO.taskStatus} and task_type = #{taskQueryReqDTO.taskType} and task_belong = 2
                <if test="taskQueryReqDTO.execDepId != null">
                    and exec_dep_id = #{taskQueryReqDTO.execDepId}
                </if>
            </if>
        </where>
        order by gmt_create desc
    </select>
 
    <!--PreventDangerCheckTask getTaskById(Long checkTaskId);-->
    <select id="getTaskById" resultType="com.gk.hotwork.doublePrevention.entity.PreventDangerCheckTask">
        select *
        from prevent_danger_check_task
        where delete_status = 0 and  id = #{checkTaskId}
    </select>
 
    <!--PreventDangerCheckTask getTaskByCode(Long taskCode);-->
    <select id="getTaskByCode" resultType="com.gk.hotwork.doublePrevention.entity.PreventDangerCheckTask">
        select
            id,
            uuid
        from prevent_danger_check_task
        where delete_status = 0 and  task_code = #{taskCode}
    </select>
 
    <!--int updateCheckTaskReport(PreventHandReportConfigReqDTO preventHandReportConfigReqDTO);-->
    <update id="updateCheckTaskReport">
        update prevent_danger_check_task set
            report_switch = #{reportSwitch}
        where id = #{id}
    </update>
 
 
    <!--PreventDangerCheckTask getTaskByCheckWorkId(Long checkWorkId)-->
    <select id="getTaskByCheckWorkId" resultMap="BaseResultMap">
        select id, uuid, check_work_id, task_status,valid_time
        from prevent_danger_check_task where delete_status = 0 and  (task_status = 1 or task_status = 4)
    </select>
 
    <!--boolean updateTaskStatus(Long taskId, Byte taskStatus);-->
    <update id="updateTaskStatus">
        update  prevent_danger_check_task set
            task_status = #{taskStatus}
        where delete_status = 0 and id = #{taskId}  and (task_status = 1 or task_status = 4)
    </update>
 
    <!--int resetTaskStatus(Long taskId);-->
    <update id="resetTaskStatus">
        update  prevent_danger_check_task set
            task_status = 3,
            result = 3
        where delete_status = 0 and task_status = 4 and id = #{taskId}
    </update>
 
 
    <!--int updateTaskUnitIdById(PreventDangerCheckTaskUpdateParams updateParams);-->
    <update id="updateTask">
        update prevent_danger_check_task set
            result = #{result},
            gmt_moditify = #{gmtModitify},
            last_edit_user_name = #{lastEditUserName},
            task_status = #{taskStatus}
        where delete_status = 0 and id = #{id}
    </update>
 
    <!--int deleteTask(PreventDeleteParams deleteParams);-->
    <update id="deleteTask">
        update prevent_danger_check_task set
            gmt_moditify = #{gmtModitify},
            last_edit_user_name = #{lastEditUserName},
            update_report_data_time = #{updateReportDataTime},
            delete_status = 1
        where delete_status = 0 and id = #{id}
    </update>
 
    <!--int taskToUser(PreventTaskToUserParams taskToUserParams);-->
    <update id="taskToUser">
        update prevent_danger_check_task set
            gmt_moditify = #{gmtModitify},
            last_edit_user_name = #{lastEditUserName},
            exec_user_id= #{execUserId},
            exec_user_name= #{execUserName},
            task_belong = #{taskBelong},
            belong_time = #{belongTime}
        where delete_status = 0 and id = #{id}
    </update>
 
 
 
    <!--PreventDangerCheckTask getTaskByCheckWorkIdAndStartTime(Long workId, Date checkTime);-->
    <select id="getTaskByCheckWorkIdAndStartTime" resultMap="BaseResultMap">
        select id,start_time
        from prevent_danger_check_task
        where delete_status = 0 and check_work_id = #{workId} and start_time = #{checkTime}
    </select>
 
    <!--int updateTaskReportStatus(Long id, byte code);-->
    <update id="updateTaskReportStatus">
        update prevent_danger_check_task set
            report_status =  #{reportStatus},
            report_time = #{reportTime}
        where id = #{id}
    </update>
 
    <!--List<PreventDangerCheckTask> listReportTask();-->
    <select id="listReportTask" resultMap="BaseResultMap">
        select * from prevent_danger_check_task
        where report_switch = 1 and task_belong = 2 and (update_report_data_time > report_time or report_time is null)
        order by gmt_create
    </select>
    <select id="selectInspectorsStatistics" resultType="java.util.Map">
 
        select
        a.taskDate,
        ifnull(b.num,0) num
        from (
        <foreach collection="list" item="item" separator="union all" index="index">
            select  #{item}
            <if test="index == 0">
               as  taskDate
            </if>
        </foreach>
        )  as a left join (
            select
            date_format(start_time,'%Y-%m-%d') taskDate,
            count(0) num
            from prevent_danger_check_task
            where start_time &gt;= #{startTime}
            and start_time   &lt; #{endTime}
            and task_belong is not null
            and exec_dep_id = #{depId}
            group by date_format(start_time,'%Y-%m-%d')
        ) as b on a.taskDate = b.taskDate
 
 
    </select>
    <select id="selectInspectionCompleted" resultType="java.util.Map">
 
        select
        a.taskDate,
        ifnull(b.num,0) num
        from (
        <foreach collection="list" item="item" separator="union all" index="index">
            select  #{item}
            <if test="index == 0">
                as  taskDate
            </if>
        </foreach>
        )  as a left join (
        select
        date_format(start_time,'%Y-%m-%d') taskDate,
        count(0) num
        from prevent_danger_check_task
        where start_time &gt;= #{startTime}
        and start_time   &lt; #{endTime}
        <if test="status != null">
            and task_type = #{status}
        </if>
        <if test="depId != null">
            and exec_dep_id = #{depId}
        </if>
 
        group by date_format(start_time,'%Y-%m-%d')
        ) as b on a.taskDate = b.taskDate
        order by a.taskDate
    </select>
 
<!--    List<PreventDangerCheckTask> listOverTask(Date startTime, Date endTime);-->
    <select id="listOverTask" resultMap="BaseResultMap">
        select * from prevent_danger_check_task
        where delete_status = 0 and valid_time > #{startTime} and  #{endTime} > valid_time and task_status = 4
    </select>
 
<!--    List<PreventDangerCheckTask> listWaitExecTask(Date endTime);-->
    <select id="listWaitExecTask" resultMap="BaseResultMap">
        select * from prevent_danger_check_task
        where delete_status = 0 and valid_time > #{endTime} and  #{endTime} > start_time and task_status = 1
    </select>
 
 
    <!--        List<PreventDangerCheckTask> listTimeOutTask(Date endTime);-->
    <select id="listTimeOutTask" resultMap="BaseResultMap">
        select * from prevent_danger_check_task
        where delete_status = 0 and  #{endTime} > valid_time and (task_status = 1 or task_status = 4)
    </select>
 
 
 
 
 
    <select id="selectInspectionTask" resultType="java.util.Map">
 
 
    </select>
    <select id="selectInspectionClaimedTask" resultType="java.util.Map">
        select
        a.taskDate,
        ifnull(b.num,0) num
        from (
        <foreach collection="list" item="item" separator="union all" index="index">
            select  #{item}
            <if test="index == 0">
                as  taskDate
            </if>
        </foreach>
        )  as a left join (
        select
        date_format(belong_time,'%Y-%m-%d') taskDate,
        count(0) num
        from prevent_danger_check_task
        where belong_time &gt;= #{startTime}
        and belong_time   &lt; #{endTime}
        and task_belong = 2
        and belong_time is not null
        and exec_dep_id = #{depId}
        group by date_format(belong_time,'%Y-%m-%d')
        ) as b on a.taskDate = b.taskDate
        order by a.taskDate
 
 
    </select>
    <select id="selectInspectionCompletedTask" resultType="java.util.Map">
        select
        a.taskDate,
        ifnull(b.num,0) num
        from (
        <foreach collection="list" item="item" separator="union all" index="index">
            select  #{item}
            <if test="index == 0">
                as  taskDate
            </if>
        </foreach>
        )  as a left join (
        select
        date_format(gmt_moditify,'%Y-%m-%d') taskDate,
        count(0) num
        from prevent_danger_check_task
        where gmt_moditify &gt;= #{startTime}
        and gmt_moditify   &lt; #{endTime}
        and task_status = 2
        and exec_dep_id = #{depId}
        group by date_format(gmt_moditify,'%Y-%m-%d')
        ) as b on a.taskDate = b.taskDate
        order by a.taskDate
    </select>
    <select id="selectInspectionUnCompletedTask" resultType="java.util.Map">
        select
        a.taskDate,
        ifnull(b.num,0) num
        from (
        <foreach collection="list" item="item" separator="union all" index="index">
            select  #{item}
            <if test="index == 0">
                as  taskDate
            </if>
        </foreach>
        )  as a left join (
        select
        date_format(gmt_moditify,'%Y-%m-%d') taskDate,
        count(0) num
        from prevent_danger_check_task
        where gmt_moditify &gt;= #{startTime}
        and gmt_moditify   &lt; #{endTime}
        and task_status != 2
        and belong_time is not null
        and exec_dep_id = #{depId}
        group by date_format(gmt_moditify,'%Y-%m-%d')
        ) as b on a.taskDate = b.taskDate
        order by a.taskDate
 
    </select>
    <select id="selectPreventDangerPage"
            resultMap="PreventTaskRectifyDO">
        select
        dangerManage.id manage_id,
        dangerManage.uuid manage_uuid,
        dangerManage.register_time register_time,
        dangerManage.danger_level danger_level,
        dangerManage.danger_type danger_type,
        dangerManage.danger_source danger_source,
        dangerManage.danger_status danger_status,
        dangerManage.registant_id registant_id,
        dangerManage.produce_device_id produce_device_id,
        dangerManage.danger_code danger_code,
        dangerManage.registant_name registant_name,
        dangerManage.danger_desc danger_desc,
        dangerManage.danger_reason danger_reason,
        dangerManage.danger_result danger_result,
        dangerManage.dep_id dep_id,
        dangerManage.risk_unit_id risk_unit_id,
        dangerManage.danger_review danger_review,
        dangerManage.danger_close_reason danger_close_reason,
        rectify.id rectify_id,
        rectify.rectify_type rectify_type,
        rectify.rectify_time rectify_time,
        rectify.liable_person_id liable_person_id,
        rectify.check_accept_time check_accept_time,
        rectify.check_accept_person_id check_accept_person_id,
        rectify.liable_person liable_person,
        rectify.check_accept_person check_accept_person,
        rectify.rectify_dep_id rectify_dep_id,
        rectify.rectify_desc rectify_desc,
        rectify.cost cost,
        rectify.apply_time rectify_apply_time,
        rectify.time_out_desc time_out_desc,
        rectify.rectify_info rectify_info
        from  prevent_danger_manage as dangerManage
        left join prevent_danger_rectify as rectify on rectify.danger_manager_id = dangerManage.id
        where dangerManage.delete_status = 0
        <if test="query.serialCode != null and query.serialCode != ''">
            and dangerManage.serial_code  like concat("%",#{query.serialCode},"%")
        </if>
        <if test="query.dangerLevel != null and query.dangerLevel != ''">
            and dangerManage.danger_level  =  #{query.dangerLevel}
        </if>
        <if test="query.dangerType != null and query.dangerType != ''">
            and dangerManage.danger_type  =  #{query.dangerType}
        </if>
        <if test="query.dangerSource != null and query.dangerSource != ''">
            and dangerManage.danger_source  =  #{query.dangerSource}
        </if>
        <if test="query.dangerStatus != null">
            and dangerManage.danger_status  =  #{query.dangerStatus}
        </if>
        <if test="query.registantName != null and query.registantName != ''">
            and dangerManage.registant_name  like concat("%",#{query.registantName},"%")
        </if>
        <if test="query.liablePersonName != null and query.liablePersonName != ''">
            and rectify.liable_person  like concat("%",#{query.liablePersonName},"%")
        </if>
        <if test="query.acceptPersonName != null and query.acceptPersonName != ''">
            and rectify.accept_person_name  like concat("%",#{query.acceptPersonName},"%")
        </if>
        order by dangerManage.gmt_create desc
    </select>
    <select id="selectRectifyNum" resultType="java.util.Map">
        select
        sum(dangerManage.danger_status = 0) rectifying,
        sum(dangerManage.danger_status = 1) toAccept,
        sum(dangerManage.danger_status = 2) postpone,
        sum(dangerManage.danger_status = 3) overTime,
        sum(dangerManage.danger_status = 9) accepted
        from prevent_danger_manage as dangerManage
        left join prevent_danger_rectify as rectify on rectify.danger_manager_id = dangerManage.id
        where dangerManage.delete_status = 0
 
    </select>
</mapper>