郑永安
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
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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
package com.gkhy.safePlatform.specialWork.service.impl;
 
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.commons.enums.E;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.exception.AusinessException;
import com.gkhy.safePlatform.commons.exception.BusinessException;
import com.gkhy.safePlatform.commons.query.PageQuery;
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
import com.gkhy.safePlatform.commons.utils.StringUtils;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import com.gkhy.safePlatform.commons.vo.SearchResultVO;
import com.gkhy.safePlatform.equipment.rpc.api.EquipmentRpcAPi;
import com.gkhy.safePlatform.specialWork.entity.*;
import com.gkhy.safePlatform.specialWork.enums.*;
import com.gkhy.safePlatform.specialWork.model.dto.req.WorkProcessCheckReqDTO;
import com.gkhy.safePlatform.specialWork.model.dto.req.WorkProcessDetectionReqDTO;
import com.gkhy.safePlatform.specialWork.model.dto.resp.*;
import com.gkhy.safePlatform.specialWork.model.query.WorkProcessCheckPageQuery;
import com.gkhy.safePlatform.specialWork.model.query.WorkProcessDetectionPageQuery;
import com.gkhy.safePlatform.specialWork.model.query.WorkProcessWarningPageQuery;
import com.gkhy.safePlatform.specialWork.model.query.WorkProcessWorkApplyQuery;
import com.gkhy.safePlatform.specialWork.model.query.db.WorkProcessCheckPageDBQuery;
import com.gkhy.safePlatform.specialWork.model.query.db.WorkProcessDetectionPageDBQuery;
import com.gkhy.safePlatform.specialWork.model.query.db.WorkProcessWarningPageDBQuery;
import com.gkhy.safePlatform.specialWork.model.query.db.WorkProcessWorkApplyDBQuery;
import com.gkhy.safePlatform.specialWork.service.SpecialWorkMinoService;
import com.gkhy.safePlatform.specialWork.service.WorkProcessService;
import com.gkhy.safePlatform.specialWork.service.baseService.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
@Service("workProcessService")
public class WorkProcessServiceImpl implements WorkProcessService {
 
    @Autowired
    private WorkApplyInfoService workApplyInfoService;
    @Autowired
    private WorkProcessDetectionInfoService workProcessDetectionInfoService;
    @Autowired
    private WorkProcessCheckInfoService workProcessCheckInfoService;
    @Autowired
    private WorkProcessWarningInfoService workProcessWarningInfoService;
    @Autowired
    private WorkProcessCheckImgInfoService workProcessCheckImgInfoService;
    @Autowired
    private SpecialWorkMinoService specialWorkMinoService;
    @Autowired
    private MaterialDetailInfoService materialDetailInfoService;
    @Autowired
    private WorkMaterialInfoService workMaterialInfoService;
    @Autowired
    private WorkMaterialCheckService workMaterialCheckService;
    @DubboReference(check = false)
    private EquipmentRpcAPi equipmentRpcAPi;
 
    @Autowired
    private WorkMaterialRecordsInfoService workMaterialRecordsInfoService;
 
 
    @Override
    public void detectionReport(ContextCacheUser currentUser, WorkProcessDetectionReqDTO reqDTO) {
        if (StringUtils.isBlank(reqDTO.getWorkPermitNo())) {
            throw new AusinessException(E.DATA_PARAM_NULL,"作业编号为空");
        }
        if (reqDTO.getOxygen() == null &&
                reqDTO.getCarbonMonoxide() == null &&
                reqDTO.getCombustible() == null &&
                reqDTO.getHydrogenSulfide() == null) {
            throw new AusinessException(E.DATA_PARAM_NULL,"至少传入一个数据");
        }
        if (WorkReportSourceEnum.parse(reqDTO.getSource()) == null) {
            throw new AusinessException(E.DATA_STATUS_CHECK_INVALID, "数据状态非法");
        }
 
        StringBuffer sb = new StringBuffer();
        // 数据异常状态判断
        WorkProcessDetectionResultEnum detectionResult = WorkProcessDetectionResultEnum.NORMAL;
        // 氧气
        if (reqDTO.getOxygen() != null && reqDTO.getOxygen().compareTo(new BigDecimal("18")) < 0) {
            detectionResult = WorkProcessDetectionResultEnum.ABNORMAL;
            sb.append("氧气浓度低于");
            sb.append("18");
            sb.append(",");
        }
        // 可燃气
        if (reqDTO.getCombustible() != null && reqDTO.getCombustible().compareTo(new BigDecimal("1")) > 0) {
            detectionResult = WorkProcessDetectionResultEnum.ABNORMAL;
            sb.append("可燃气浓度超过");
            sb.append("18");
            sb.append(",");
        }
        // 一氧化碳
        if (reqDTO.getCarbonMonoxide() != null && reqDTO.getCarbonMonoxide().compareTo(new BigDecimal("24")) > 0) {
            detectionResult = WorkProcessDetectionResultEnum.ABNORMAL;
            sb.append("一氧化碳浓度超过");
            sb.append("24");
            sb.append(",");
        }
        // 硫化氢
        if (reqDTO.getHydrogenSulfide() != null && reqDTO.getHydrogenSulfide().compareTo(new BigDecimal("10")) > 0) {
            detectionResult = WorkProcessDetectionResultEnum.ABNORMAL;
            sb.append("硫化氢浓度超过");
            sb.append("10");
            sb.append(",");
        }
        if (sb.length() > 0) {
            sb.deleteCharAt(sb.length() - 1);
        }
 
        String workPermitNo = reqDTO.getWorkPermitNo().trim();
        WorkApplyInfo workApplyInfo = workApplyInfoService.getApplyInfoByWorkPermitNo(workPermitNo);
        if (workApplyInfo == null) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "作业编号不存在");
        }
        // 审批结束
        if (!workApplyInfo.getStatus().equals(WorkApplyStatusEnum.STATU_FINISH.getStatus())) {
            throw new AusinessException(E.DATA_STATUS_CHECK_INVALID, "未结束审批作业状态无法上报");
        }
        LocalDateTime operationTime = LocalDateTime.now();
        // 时间校验
        if (operationTime.isBefore(workApplyInfo.getExpStartTime()) ||
                operationTime.isAfter(workApplyInfo.getExpEndTime())) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "上报时间不在作业时间内");
        }
        // exc
        WorkProcessDetectionInfo detectionEntity = new WorkProcessDetectionInfo();
        detectionEntity.setId(IdUtil.getSnowflake(0,0).nextId());
        detectionEntity.setWorkApplyId(workApplyInfo.getId());
        detectionEntity.setWorkPermitNo(workPermitNo);
        detectionEntity.setWorkType(workApplyInfo.getWorkType());
        detectionEntity.setWorkLevel(workApplyInfo.getWorkLevel());
        detectionEntity.setOperationTime(operationTime);
        detectionEntity.setOperatorUid(currentUser.getUid());
        detectionEntity.setOperatorUname(currentUser.getRealName());
        detectionEntity.setOperationTime(operationTime);
        detectionEntity.setInfo(reqDTO.getInfo());
        detectionEntity.setCombustible(reqDTO.getCombustible());
        detectionEntity.setOxygen(reqDTO.getOxygen());
        detectionEntity.setCarbonMonoxide(reqDTO.getCarbonMonoxide());
        detectionEntity.setHydrogenSulfide(reqDTO.getHydrogenSulfide());
        detectionEntity.setStatus(WorkProcessDetectionStatusEnum.VALID.code);
        detectionEntity.setSource(reqDTO.getSource());
        detectionEntity.setResult(detectionResult.code);
        workProcessDetectionInfoService.saveWorkProcessDetectionInfo(detectionEntity);
 
        // 异常 => 预警
        if (detectionResult == WorkProcessDetectionResultEnum.ABNORMAL) {
            WorkProcessWarningInfo warningInfo = new WorkProcessWarningInfo();
            warningInfo.setId(IdUtil.getSnowflake(0,0).nextId());
            warningInfo.setWorkApplyId(workApplyInfo.getId());
            warningInfo.setWorkPermitNo(workApplyInfo.getWorkPermitNo());
            warningInfo.setWarningContent(sb.toString());
            warningInfo.setWarningType(WorkProcessWarningTypeEnum.CHECK.code);
            warningInfo.setWarningInfo(detectionEntity.getInfo());
            warningInfo.setOperatorUid(currentUser.getUid());
            warningInfo.setOperatorUname(currentUser.getRealName());
            warningInfo.setOperationTime(operationTime);
            warningInfo.setStatus(WorkProcessWarningStatusEnum.VALID.code);
            warningInfo.setSource(reqDTO.getSource());
            warningInfo.setWorkType(workApplyInfo.getWorkType());
            warningInfo.setWorkLevel(workApplyInfo.getWorkLevel());
            warningInfo.setOriginalId(detectionEntity.getId());
            workProcessWarningInfoService.saveWorkProcessWarningInfo(warningInfo);
        }
    }
 
    @Override
    public SearchResultVO<List<WorkProcessDetectionInfoRespDTO>> listDetectionByPage(ContextCacheUser currentUser, PageQuery<WorkProcessDetectionPageQuery> pageQuery) {
 
        WorkProcessDetectionPageDBQuery dbQuery = new WorkProcessDetectionPageDBQuery();
        if (pageQuery.getSearchParams() != null) {
            dbQuery.setResult(pageQuery.getSearchParams().getResult());
            dbQuery.setWorkPermitNo(pageQuery.getSearchParams().getWorkPermitNo());
            dbQuery.setWorkType(pageQuery.getSearchParams().getWorkType());
        }
        Page<WorkProcessDetectionInfo> page = new Page<>(pageQuery.getPageIndex(), pageQuery.getPageSize());
        List<WorkProcessDetectionInfo> dbData = workProcessDetectionInfoService.listWorkDetectionInfoByPage(page, dbQuery);
        List<WorkProcessDetectionInfoRespDTO> result = new ArrayList<>(dbData.size());
        if (dbData.size() > 0) {
            WorkProcessDetectionInfoRespDTO respDTO;
            WorkTypeEnum workTypeEnum;
            WorkLevelEnum workLevelEnum;
            WorkProcessDetectionStatusEnum statusEnum;
            WorkProcessDetectionResultEnum resultEnum;
            WorkReportSourceEnum sourceEnum;
            for (WorkProcessDetectionInfo detectionInfo : dbData) {
                respDTO = new WorkProcessDetectionInfoRespDTO();
                respDTO.setWorkProcessDetectionId(detectionInfo.getId());
                respDTO.setWorkApplyId(detectionInfo.getWorkApplyId());
                respDTO.setWorkPermitNo(detectionInfo.getWorkPermitNo());
                respDTO.setWorkType(detectionInfo.getWorkType());
                workTypeEnum = WorkTypeEnum.parse(detectionInfo.getWorkType());
                if (workTypeEnum != null) {
                    respDTO.setWorkTypeDesc(workTypeEnum.getName());
                }
                respDTO.setWorkLevel(detectionInfo.getWorkLevel());
                workLevelEnum = WorkLevelEnum.parse(detectionInfo.getWorkLevel());
                if (workLevelEnum != null) {
                    respDTO.setWorkLevelDesc(workLevelEnum.getTitle());
                }
                respDTO.setOperationTime(detectionInfo.getOperationTime());
                respDTO.setOperatorUname(detectionInfo.getOperatorUname());
                respDTO.setOperatorUid(detectionInfo.getOperatorUid());
                respDTO.setInfo(detectionInfo.getInfo());
                respDTO.setCombustible(detectionInfo.getCombustible());
                respDTO.setOxygen(detectionInfo.getOxygen());
                respDTO.setCarbonMonoxide(detectionInfo.getCarbonMonoxide());
                respDTO.setHydrogenSulfide(detectionInfo.getHydrogenSulfide());
                respDTO.setStatus(detectionInfo.getStatus());
                statusEnum = WorkProcessDetectionStatusEnum.parse(detectionInfo.getStatus());
                if (statusEnum != null) {
                    respDTO.setStatusDesc(statusEnum.value);
                }
                respDTO.setResult(detectionInfo.getResult());
                resultEnum = WorkProcessDetectionResultEnum.parse(detectionInfo.getResult());
                if (resultEnum != null) {
                    respDTO.setResultDesc(resultEnum.value);
                }
                respDTO.setSource(detectionInfo.getSource());
                sourceEnum = WorkReportSourceEnum.parse(detectionInfo.getSource());
                if (sourceEnum != null) {
                    respDTO.setSourceDesc(sourceEnum.value);
                }
 
                result.add(respDTO);
 
            }
        }
        return new SearchResultVO<>(
                true,
                page.getCurrent(),
                page.getSize(),
                page.getPages(),
                page.getTotal(),
                result,
                ResultCodes.OK);
    }
 
    @Override
    @Transactional
    public void checkReport(ContextCacheUser currentUser, WorkProcessCheckReqDTO reqDTO) {
        if (StringUtils.isBlank(reqDTO.getCheckContent())) {
            throw new AusinessException(E.DATA_PARAM_NULL, "检查上报内容为空");
        }
        if (StringUtils.isBlank(reqDTO.getWorkPermitNo())) {
            throw new AusinessException(E.DATA_PARAM_NULL,"作业编号为空");
        }
        String workPermitNo = reqDTO.getWorkPermitNo().trim();
        WorkApplyInfo workApplyInfo = workApplyInfoService.getApplyInfoByWorkPermitNo(workPermitNo);
        if (workApplyInfo == null) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "作业编号不存在");
        }
        // 审批结束
        if (!workApplyInfo.getStatus().equals(WorkApplyStatusEnum.STATU_FINISH.getStatus())) {
            throw new AusinessException(E.DATA_STATUS_CHECK_INVALID, "未结束审批作业状态无法上报");
        }
        LocalDateTime operationTime = LocalDateTime.now();
        // 时间校验
        if (operationTime.isBefore(workApplyInfo.getExpStartTime()) ||
                operationTime.isAfter(workApplyInfo.getExpEndTime())) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "上报时间不在作业时间内");
        }
        if (reqDTO.getCheckResult() == null) {
            throw new AusinessException(E.DATA_PARAM_NULL, "检查上报结果为空");
        }
        WorkProcessCheckResultEnum resultEnum = WorkProcessCheckResultEnum.parse(reqDTO.getCheckResult());
        if (resultEnum == null) {
            throw new AusinessException(E.DATA_STATUS_CHECK_INVALID, "检查上报结果参数非法");
        }
        if (WorkReportSourceEnum.parse(reqDTO.getSource()) == null) {
            throw new AusinessException(E.DATA_STATUS_CHECK_INVALID, "数据状态非法");
        }
        List<WorkMaterialRecordsInfo> listByRfids = null;
        if (!CollectionUtils.isEmpty(reqDTO.getRfids())) {
            listByRfids = workMaterialRecordsInfoService.listByRfids(reqDTO.getRfids());
        }
        Byte mcResult = -1;
        if(workApplyInfo.getMaBaseId() != null){
            mcResult = getMcResult(workApplyInfo.getId(),listByRfids);
        }
 
        // exc
        WorkProcessCheckInfo checkEntity = new WorkProcessCheckInfo();
        checkEntity.setId(IdUtil.getSnowflake(0,0).nextId());
        checkEntity.setWorkApplyId(workApplyInfo.getId());
        checkEntity.setWorkPermitNo(workApplyInfo.getWorkPermitNo());
        checkEntity.setCheckContent(reqDTO.getCheckContent());
        checkEntity.setCheckResult(reqDTO.getCheckResult());
        checkEntity.setOperatorUname(currentUser.getRealName());
        checkEntity.setOperatorUid(currentUser.getUid());
        checkEntity.setOperationTime(operationTime);
        checkEntity.setStatus(WorkProcessCheckStatusEnum.VALID.code);
        checkEntity.setSource(reqDTO.getSource());
        checkEntity.setWorkType(workApplyInfo.getWorkType());
        checkEntity.setWorkLevel(workApplyInfo.getWorkLevel());
        checkEntity.setInfo(reqDTO.getInfo());
        checkEntity.setMcResult(mcResult);
        workProcessCheckInfoService.saveWorkProcessCheckInfo(checkEntity);
        // img
        if (reqDTO.getImagePaths() != null && reqDTO.getImagePaths().size() > 0) {
            List<WorkProcessCheckImgInfo> checkImages = new ArrayList<>();
            WorkProcessCheckImgInfo checkImg;
            for (String path : reqDTO.getImagePaths()) {
                checkImg = new WorkProcessCheckImgInfo();
                checkImg.setId(IdUtil.getSnowflake(0, 0).nextId());
                checkImg.setWorkProcessCheckId(checkEntity.getId());
                checkImg.setPath(path);
                checkImages.add(checkImg);
            }
            workProcessCheckImgInfoService.saveCheckImages(checkImages);
        }
       /* //物资检查
        List<WorkMaterialCheckInfo> materialCheckInfoList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(reqDTO.getWorkMaterialList())) {
            for(WorkMaterialCheckReqDTO material:reqDTO.getWorkMaterialList()){
                WorkMaterialCheckInfo materialCheckInfo = new WorkMaterialCheckInfo();
                materialCheckInfo.setId(IdUtil.getSnowflake(0,0).nextId());
                materialCheckInfo.setMaterialName(material.getMaterialName());
                materialCheckInfo.setSceneCount(material.getSceneCount());
                materialCheckInfo.setWorkApplyId(workApplyInfo.getId());
                materialCheckInfo.setUseCount(material.getUseCount());
                materialCheckInfo.setWpcId(checkEntity.getId());
                materialCheckInfoList.add(materialCheckInfo);
            }
            workMaterialCheckService.saveMaterialCheckBatch(materialCheckInfoList);
        }*/
 
 
        // 异常 => 同步存入预警信息
        if (resultEnum == WorkProcessCheckResultEnum.ABNORMAL) {
            WorkProcessWarningInfo warningInfo = new WorkProcessWarningInfo();
            warningInfo.setId(IdUtil.getSnowflake(0,0).nextId());
            warningInfo.setWorkApplyId(workApplyInfo.getId());
            warningInfo.setWorkPermitNo(workApplyInfo.getWorkPermitNo());
            warningInfo.setWarningContent(checkEntity.getCheckContent());
            warningInfo.setWarningType(WorkProcessWarningTypeEnum.CHECK.code);
            warningInfo.setWarningInfo(checkEntity.getInfo());
            warningInfo.setOperatorUid(currentUser.getUid());
            warningInfo.setOperatorUname(currentUser.getRealName());
            warningInfo.setOperationTime(operationTime);
            warningInfo.setStatus(WorkProcessWarningStatusEnum.VALID.code);
            warningInfo.setSource(reqDTO.getSource());
            warningInfo.setWorkType(workApplyInfo.getWorkType());
            warningInfo.setWorkLevel(workApplyInfo.getWorkLevel());
            warningInfo.setOriginalId(checkEntity.getId());
            workProcessWarningInfoService.saveWorkProcessWarningInfo(warningInfo);
 
        }
 
    }
    private Byte getMcResult(Long workApplyId, List<WorkMaterialRecordsInfo> list){
        Byte mcResult = -1;
        if(!CollectionUtils.isEmpty(list)){
            List<WorkMaterialInfo> workMaterialInfoList = workMaterialInfoService.listByWorkApplyId(workApplyId);
            //过滤出必修
            List<WorkMaterialInfo> selectList = workMaterialInfoList
                    .stream()
                    .filter(wm -> wm.getConfigurationLevel().equals(ConfigurationLevelEnum.MANDATORY.getCode()))
                    .collect(Collectors.toList());
            if(selectList.size()>0){
                for(WorkMaterialInfo materialInfo:selectList){
                    //根据部门或者仓库过滤出物资
                    List<WorkMaterialRecordsInfo> collect = list
                            .stream()
                            .filter(cl -> cl.getWorkMaterialId().equals(materialInfo.getId()))
                            .collect(Collectors.toList());
                    if(mcResult != WorkMaterialCheckEnum.UNQUALIFIED.getType()){
                        if(collect.size()>=materialInfo.getUseCount()){
                            mcResult = WorkMaterialCheckEnum.QUALIFIED.getType();
                        }else {
                            mcResult = WorkMaterialCheckEnum.UNQUALIFIED.getType();
                        }
                    }
 
                }
            }else{
                mcResult = WorkMaterialCheckEnum.UNQUALIFIED.getType();
            }
        }
        return mcResult;
    }
 
    @Override
    public SearchResultVO<List<WorkProcessCheckInfoRespDTO>> listCheckByPage(ContextCacheUser currentUser, PageQuery<WorkProcessCheckPageQuery> pageQuery) {
        WorkProcessCheckPageDBQuery dbQuery = new WorkProcessCheckPageDBQuery();
        if (pageQuery.getSearchParams() != null) {
            dbQuery.setCheckResult(pageQuery.getSearchParams().getCheckResult());
            dbQuery.setWorkPermitNo(pageQuery.getSearchParams().getWorkPermitNo());
            dbQuery.setWorkType(pageQuery.getSearchParams().getWorkType());
        }
 
        Page<WorkProcessCheckInfo> page = new Page<>(pageQuery.getPageIndex(), pageQuery.getPageSize());
        List<WorkProcessCheckInfo> dbData = workProcessCheckInfoService.listWorkProcessCheckInfoByPage(page, dbQuery);
        List<WorkMaterialCheckInfo> materialCheckInfoList = new ArrayList<>();
        if(!CollectionUtils.isEmpty(dbData)){
            List<Long> idList = dbData.stream().map(WorkProcessCheckInfo::getId).collect(Collectors.toList());
            materialCheckInfoList = workMaterialCheckService.getListByWpcIds(idList);
        }
        List<WorkProcessCheckInfoRespDTO> result = new ArrayList<>(dbData.size());
        if (dbData.size() > 0) {
            WorkProcessCheckInfoRespDTO respDTO;
            WorkTypeEnum workTypeEnum;
            WorkLevelEnum workLevelEnum;
            WorkReportSourceEnum sourceEnum;
            WorkProcessCheckStatusEnum statusEnum;
            WorkProcessCheckResultEnum resultEnum;
            for (WorkProcessCheckInfo checkInfo : dbData) {
                respDTO = new WorkProcessCheckInfoRespDTO();
                respDTO.setWorkProcessCheckId(checkInfo.getId());
                respDTO.setWorkApplyId(checkInfo.getWorkApplyId());
                respDTO.setWorkPermitNo(checkInfo.getWorkPermitNo());
                respDTO.setWorkType(checkInfo.getWorkType());
                workTypeEnum = WorkTypeEnum.parse(checkInfo.getWorkType());
                if (workTypeEnum != null) {
                    respDTO.setWorkTypeDesc(workTypeEnum.getName());
                }
                respDTO.setWorkLevel(checkInfo.getWorkLevel());
                workLevelEnum = WorkLevelEnum.parse(checkInfo.getWorkLevel());
                if (workLevelEnum != null) {
                    respDTO.setWorkLevelDesc(workLevelEnum.getTitle());
                }
                respDTO.setOperationTime(checkInfo.getOperationTime());
                respDTO.setOperatorUname(checkInfo.getOperatorUname());
                respDTO.setOperatorUid(checkInfo.getOperatorUid());
                respDTO.setInfo(checkInfo.getInfo());
                respDTO.setStatus(checkInfo.getStatus());
                respDTO.setSource(checkInfo.getSource());
                respDTO.setMcResult(checkInfo.getMcResult());
                sourceEnum = WorkReportSourceEnum.parse(checkInfo.getSource());
                if (sourceEnum != null) {
                    respDTO.setSourceDesc(sourceEnum.value);
                }
                statusEnum = WorkProcessCheckStatusEnum.parse(checkInfo.getStatus());
                if (statusEnum != null) {
                    respDTO.setStatusDesc(statusEnum.value);
                }
                WorkMaterialCheckEnum materialCheckEnum = WorkMaterialCheckEnum.parse(checkInfo.getMcResult());
                if(materialCheckEnum != null){
                    respDTO.setMcResultName(materialCheckEnum.getDesc());
                }
                respDTO.setCheckContent(checkInfo.getCheckContent());
                respDTO.setCheckResult(checkInfo.getCheckResult());
                resultEnum = WorkProcessCheckResultEnum.parse(checkInfo.getCheckResult());
                if (resultEnum != null) {
                    respDTO.setCheckResultDesc(resultEnum.value);
                }
                List<WorkProcessCheckImgInfo> images = workProcessCheckImgInfoService.listImagesByCheckId(checkInfo.getId());
                respDTO.setImagePaths(images.stream().map(item -> specialWorkMinoService.viewFiles(item.getPath())).collect(Collectors.toList()));
                //获取对应物资检查的数据
                List<WorkMaterialCheckInfo> selectList = materialCheckInfoList
                        .stream()
                        .filter(mc -> mc.getWpcId().equals(checkInfo.getId()))
                        .collect(Collectors.toList());
                List<WorkMaterialCheckRespDTO> list = new ArrayList<>();
                if(selectList.size()>0){
                     list = BeanCopyUtils.copyBeanList(selectList, WorkMaterialCheckRespDTO.class);
                }
                respDTO.setWorkMaterialCheckList(list);
                result.add(respDTO);
 
            }
        }
        return new SearchResultVO<>(
                true,
                page.getCurrent(),
                page.getSize(),
                page.getPages(),
                page.getTotal(),
                result,
                ResultCodes.OK);
    }
 
    @Override
    public SearchResultVO<List<WorkProcessWarningInfoRespDTO>> listWarningByPage(ContextCacheUser currentUser, PageQuery<WorkProcessWarningPageQuery> pageQuery) {
        WorkProcessWarningPageDBQuery dbQuery = new WorkProcessWarningPageDBQuery();
        if (pageQuery.getSearchParams() != null) {
            dbQuery.setWarningType(pageQuery.getSearchParams().getWarningType());
            dbQuery.setWorkPermitNo(pageQuery.getSearchParams().getWorkPermitNo());
            dbQuery.setWorkType(pageQuery.getSearchParams().getWorkType());
        }
        Page<WorkProcessWarningInfo> page = new Page<>(pageQuery.getPageIndex(), pageQuery.getPageSize());
        List<WorkProcessWarningInfo> dbData = workProcessWarningInfoService.listWorkProcessWarningInfoByPage(page, dbQuery);
        List<WorkProcessWarningInfoRespDTO> result = new ArrayList<>(dbData.size());
        if (dbData.size() > 0) {
            WorkProcessWarningInfoRespDTO respDTO;
            WorkProcessWarningTypeEnum warningTypeEnum;
            WorkProcessWarningStatusEnum statusEnum;
            WorkReportSourceEnum sourceEnum;
            WorkTypeEnum workTypeEnum;
            WorkLevelEnum workLevelEnum;
            for (WorkProcessWarningInfo warningInfo : dbData) {
                respDTO = new WorkProcessWarningInfoRespDTO();
                respDTO.setWorkProcessWarningId(warningInfo.getId());
                respDTO.setWorkApplyId(warningInfo.getWorkApplyId());
                respDTO.setWorkPermitNo(warningInfo.getWorkPermitNo());
                respDTO.setWarningContent(warningInfo.getWarningContent());
                respDTO.setWarningType(warningInfo.getWarningType());
                warningTypeEnum = WorkProcessWarningTypeEnum.parse(warningInfo.getWarningType());
                if (warningTypeEnum != null) {
                    respDTO.setWarningTypeDesc(warningTypeEnum.value);
                }
                respDTO.setWarningInfo(warningInfo.getWarningInfo());
                respDTO.setOperatorUid(warningInfo.getOperatorUid());
                respDTO.setOperatorUname(warningInfo.getOperatorUname());
                respDTO.setOperationTime(warningInfo.getOperationTime());
                respDTO.setStatus(warningInfo.getStatus());
                statusEnum = WorkProcessWarningStatusEnum.parse(warningInfo.getStatus());
                if (statusEnum != null) {
                    respDTO.setStatusDesc(statusEnum.value);
                }
                respDTO.setSource(warningInfo.getSource());
                sourceEnum = WorkReportSourceEnum.parse(warningInfo.getSource());
                respDTO.setSourceDesc(sourceEnum.value);
                respDTO.setWorkType(warningInfo.getWorkType());
                workTypeEnum = WorkTypeEnum.parse(warningInfo.getWorkType());
                if (workTypeEnum != null) {
                    respDTO.setWorkTypeDesc(workTypeEnum.getName());
                }
                respDTO.setWorkLevel(warningInfo.getWorkLevel());
                workLevelEnum = WorkLevelEnum.parse(warningInfo.getWorkLevel());
                if (workLevelEnum != null) {
                    respDTO.setWorkLevelDesc(workLevelEnum.getTitle());
                }
                if (warningTypeEnum == WorkProcessWarningTypeEnum.CHECK) {
                    List<WorkProcessCheckImgInfo> images = workProcessCheckImgInfoService.listImagesByCheckId(warningInfo.getOriginalId());
                    respDTO.setImagePaths(images.stream().map(item -> specialWorkMinoService.viewFiles(item.getPath())).collect(Collectors.toList()));
                }
                result.add(respDTO);
            }
        }
        return new SearchResultVO<>(
                true,
                page.getCurrent(),
                page.getSize(),
                page.getPages(),
                page.getTotal(),
                result,
                ResultCodes.OK);
    }
 
    @Override
    public List<WorkApplyReportableRespDTO> listReportableWorkApply(ContextCacheUser currentUser, WorkProcessWorkApplyQuery query) {
 
 
        WorkProcessWorkApplyDBQuery dbQuery = new WorkProcessWorkApplyDBQuery();
        dbQuery.setWorkPermitNo(query.getWorkPermitNo());
        dbQuery.setWorkType(query.getWorkType());
        dbQuery.setNow(LocalDateTime.now());
        dbQuery.setStatus(WorkApplyStatusEnum.STATU_FINISH.getStatus());
        List<WorkApplyReportableDO> dbData = workApplyInfoService.listReportableWorkApply(dbQuery);
        List<WorkApplyReportableRespDTO> result = new ArrayList<>(dbData.size());
        if (dbData.size() > 0) {
            WorkApplyReportableRespDTO respDTO;
            WorkTypeEnum typeEnum;
            WorkLevelEnum levelEnum;
            WorkApplyStatusEnum statusEnum;
            for (WorkApplyReportableDO workApplyInfo : dbData) {
                respDTO = new WorkApplyReportableRespDTO();
                respDTO.setWorkApplyId(workApplyInfo.getId());
                respDTO.setWorkType(workApplyInfo.getWorkType());
                respDTO.setWorkLevel(workApplyInfo.getWorkLevel());
                respDTO.setWorkPermitNo(workApplyInfo.getWorkPermitNo());
                respDTO.setWorkContent(workApplyInfo.getWorkContent());
                respDTO.setWorkLocation(workApplyInfo.getWorkLocation());
                respDTO.setHazardIdentification(workApplyInfo.getHazardIdentification());
                respDTO.setStatus(workApplyInfo.getStatus());
                typeEnum = WorkTypeEnum.parse(workApplyInfo.getWorkType());
                if (typeEnum != null) {
                    respDTO.setWorkTypeDesc(typeEnum.getName());
                }
                levelEnum = WorkLevelEnum.parse(workApplyInfo.getWorkLevel());
                if (levelEnum != null) {
                    respDTO.setWorkLevelDesc(levelEnum.getTitle());
                }
                statusEnum = WorkApplyStatusEnum.parse(workApplyInfo.getStatus());
                if (statusEnum != null) {
                    respDTO.setStatusDesc(statusEnum.getDesc());
                }
                respDTO.setExpStartTime(workApplyInfo.getExpStartTime());
                respDTO.setExpEndTime(workApplyInfo.getExpEndTime());
                result.add(respDTO);
            }
        }
        return result;
    }
 
    @Override
    public ResultVO<List<ConfigurationLevelCheckRespDTO>> chekMaterialList(ContextCacheUser currentUser, String workPermitNo) {
        if(StringUtils.isBlank(workPermitNo)){
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        WorkApplyInfo workApplyInfo = workApplyInfoService.getApplyInfoByWorkPermitNo(workPermitNo.trim());
        if (workApplyInfo == null) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "作业编号不存在");
        }
        List<ConfigurationLevelCheckRespDTO> list = new ArrayList<>();
        if(null != workApplyInfo.getMaBaseId()) {
            //获取
            List<WorkMaterialInfo> workMaterialInfoList = workMaterialInfoService.listByWorkApplyId(workApplyInfo.getId());
            //循环配置级别
            for (ConfigurationLevelEnum levelEnum : ConfigurationLevelEnum.values()) {
                ConfigurationLevelCheckRespDTO levelCheckRespDTO = new ConfigurationLevelCheckRespDTO();
                levelCheckRespDTO.setConfigurationLevel(levelEnum.getCode());
                levelCheckRespDTO.setConfigurationLevelName(levelEnum.getValue());
                List<WorkMaterialInfo> selectList = workMaterialInfoList
                        .stream().filter(wm -> wm.getConfigurationLevel().equals(levelEnum.getCode()))
                        .collect(Collectors.toList());
                if (selectList.size() > 0) {
                    List<MaterialCheckRespDTO> materialList = new ArrayList<>();
                    for (WorkMaterialInfo materialInfo : selectList) {
                        MaterialCheckRespDTO materialCheckRespDTO = new MaterialCheckRespDTO();
                        materialCheckRespDTO.setMaterialName(materialInfo.getMaterialName());
                        materialCheckRespDTO.setConfigurationLevel(materialInfo.getConfigurationLevel());
                        materialCheckRespDTO.setUseCount(materialInfo.getUseCount());
                        materialList.add(materialCheckRespDTO);
                    }
                    levelCheckRespDTO.setMdList(materialList);
                    list.add(levelCheckRespDTO);
                }
            }
        }
        return new ResultVO<>(ResultCodes.OK,list);
    }
 
    public List<WorkMaterialRecordsRespDTO> getListByRfids(List<String> rfids){
        if(CollectionUtils.isEmpty(rfids)){
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        List<WorkMaterialRecordsRespDTO> list = new ArrayList<>();
        List<WorkMaterialRecordsInfo> workMaterialRecordsInfoList = workMaterialRecordsInfoService.listByRfids(rfids);
        if(!CollectionUtils.isEmpty(workMaterialRecordsInfoList)){
            list = BeanCopyUtils.copyBeanList(workMaterialRecordsInfoList,WorkMaterialRecordsRespDTO.class);
        }
        return list;
    }
 
}