zhangherong
2 天以前 3d63e7c025d5d8164df640d7c947e601c149e951
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
package org.jeecg.modules.eam.service.impl;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.flowable.engine.TaskService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.DataBaseConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.eam.constant.*;
import org.jeecg.modules.eam.entity.*;
import org.jeecg.modules.eam.mapper.EamTechnicalStatusEvaluationOrderMapper;
import org.jeecg.modules.eam.request.EamTechnicalStatusEvaluationOrderQuery;
import org.jeecg.modules.eam.request.EamTechnicalStatusEvaluationOrderRequest;
import org.jeecg.modules.eam.service.*;
import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness;
import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService;
import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI;
import org.jeecg.modules.flowable.apithird.service.FlowCommonService;
import org.jeecg.modules.flowable.service.IFlowDefinitionService;
import org.jeecg.modules.flowable.service.IFlowTaskService;
import org.jeecg.modules.system.entity.BaseFactory;
import org.jeecg.modules.system.entity.BaseFactoryUser;
import org.jeecg.modules.system.service.IBaseFactoryService;
import org.jeecg.modules.system.service.IBaseFactoryUserService;
import org.jeecg.modules.system.service.ISysBusinessCodeRuleService;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.system.vo.UserSelector;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Description: 技术状态鉴定工单
 * @Author: jeecg-boot
 * @Date: 2025-07-09
 * @Version: V1.0
 */
@Service("IEamTechnicalStatusEvaluationOrderService")
public class EamTechnicalStatusEvaluationOrderServiceImpl extends ServiceImpl<EamTechnicalStatusEvaluationOrderMapper, EamTechnicalStatusEvaluationOrder> implements IEamTechnicalStatusEvaluationOrderService, FlowCallBackServiceI {
 
    @Autowired
    private IBaseFactoryUserService baseFactoryUserService;
    @Autowired
    private IBaseFactoryService baseFactoryService;
    @Autowired
    private IEamTechnicalStatusEvaluationOrderDetailService orderDetailService;
    @Autowired
    private IEamEquipmentService equipmentService;
    @Autowired
    private ISysBusinessCodeRuleService businessCodeRuleService;
    @Autowired
    private IEamTechnicalStatusEvaluationStandardService standardService;
    @Autowired
    private IEamTechnicalStatusEvaluationStandardDetailService standardDetailService;
    @Autowired
    private IEamBaseHFCodeService hfCodeService;
    @Autowired
    private FlowCommonService flowCommonService;
    @Autowired
    private IFlowDefinitionService flowDefinitionService;
    @Autowired
    private IFlowMyBusinessService flowMyBusinessService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private IFlowTaskService flowTaskService;
 
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private IEamEquipmentExtendService equipmentExtendService;
 
    @Override
    public IPage<EamTechnicalStatusEvaluationOrder> queryPageList(Page<EamTechnicalStatusEvaluationOrder> page, EamTechnicalStatusEvaluationOrderQuery query) {
        QueryWrapper<EamTechnicalStatusEvaluationOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ems.del_flag", CommonConstant.DEL_FLAG_0);
        //用户数据权限
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (sysUser == null) {
            return page;
        }
        if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) {
            //选择了设备,根据设备id过滤设备
            List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(","));
            queryWrapper.in("e.equipment_code", equipArr);
        } else {
            //没有选择设备,根据中心过滤设备
            List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService.
                    list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId, sysUser.getId()));
            if (!CollectionUtils.isEmpty(baseFactoryUserList)) {
                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
                Set<String> factoryCodeList = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
                queryWrapper.in("e.factory_org_code", factoryCodeList);
            } else {
                return page;
            }
        }
        if (query != null) {
            //编码 模糊查询
            if (StringUtils.isNotBlank(query.getOrderNum())) {
                queryWrapper.like("ems.order_num", query.getOrderNum());
            }
            //设备
            if (StringUtils.isNotBlank(query.getEquipmentId())) {
                queryWrapper.eq("ems.equipment_id", query.getEquipmentId());
            }
 
            //保养分类
            if (StringUtils.isNotBlank(query.getEvaluationStatus())) {
                queryWrapper.eq("ems.evaluation_status", query.getEvaluationStatus());
            }
            if (query.getDateBegin() != null && query.getDateEnd() != null) {
                queryWrapper.between("ems.evaluation_date", query.getDateBegin(), query.getDateEnd());
            }
            //排序
            if (StringUtils.isNotBlank(query.getColumn()) && StringUtils.isNotBlank(query.getOrder())) {
                String column = query.getColumn();
                if (column.endsWith(CommonConstant.DICT_TEXT_SUFFIX)) {
                    column = column.substring(0, column.lastIndexOf(CommonConstant.DICT_TEXT_SUFFIX));
                }
                if (DataBaseConstant.SQL_ASC.equalsIgnoreCase(query.getOrder())) {
                    queryWrapper.orderByAsc("ems." + oConvertUtils.camelToUnderline(column));
                } else {
                    queryWrapper.orderByDesc("ems." + oConvertUtils.camelToUnderline(column));
                }
            } else {
                queryWrapper.orderByDesc("ems.create_time");
            }
        } else {
            queryWrapper.orderByDesc("ems.create_time");
        }
        return this.getBaseMapper().queryPageList(page, queryWrapper);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addTechnicalStatusEvaluationOrder(EamTechnicalStatusEvaluationOrderRequest request) {
        EamEquipment equipment = equipmentService.getById(request.getEquipmentId());
        if (equipment == null) {
            throw new JeecgBootException("设备不存在,添加失败!");
        }
        EamTechnicalStatusEvaluationStandard standard = standardService.getById(request.getStandardId());
        if (standard == null) {
            throw new JeecgBootException("技术状态鉴定规范不存在,添加失败!");
        }
        if (!TechnicalStatusEvaluationStandardStatusEnum.ENABLE.name().equals(standard.getStandardStatus())) {
            throw new JeecgBootException("技术状态鉴定规范未启用,添加失败!");
        }
        List<EamTechnicalStatusEvaluationStandardDetail> standardDetailList = standardDetailService.queryList(standard.getId());
        if (CollectionUtil.isEmpty(standardDetailList)) {
            throw new JeecgBootException("技术状态鉴定规范检查项为空,添加失败!");
        }
        EamTechnicalStatusEvaluationOrder order = new EamTechnicalStatusEvaluationOrder();
        order.setEquipmentId(request.getEquipmentId());
        order.setStandardId(request.getStandardId());
        order.setEvaluationDate(request.getEvaluationDate());
        order.setFreezeOrderDate(request.getFreezeOrderDate());
        order.setOrderExpirationDate(request.getOrderExpirationDate());
        order.setRemark(request.getRemark());
        String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.TECHNICAL_STATUS_EVALUATION_ORDER_CODE_RULE);
        order.setOrderNum(codeSeq);
        order.setCreationMethod(request.getCreationMethod());
        //状态初始化
        order.setEvaluationStatus(TechnicalStatusEvaluationOrderStatusEnum.WAIT_EVALUATION.name());
        //删除标记
        order.setDelFlag(CommonConstant.DEL_FLAG_0);
        //技术状态鉴定表
        EamBaseHFCode eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.TECHNICAL_STATUS_EVALUATION.name());
        if (eamBaseHFCode == null) {
            throw new JeecgBootException("未配置技术状态鉴定表的HF编码,添加失败!");
        }
        order.setHfCodeA(eamBaseHFCode.getHfCode());
        //技术状态鉴定安全装置检查表
        eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.TECHNICAL_STATUS_EVALUATION_SAFETY_CHECK.name());
        if (eamBaseHFCode == null) {
            throw new JeecgBootException("未配置安全装置检查表的HF编码,添加失败!");
        }
        order.setHfCodeB(eamBaseHFCode.getHfCode());
        //技术状态鉴定其他检查表
        eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.TECHNICAL_STATUS_EVALUATION_OTHER_CHECK.name());
        if (eamBaseHFCode == null) {
            throw new JeecgBootException("未配置其他检查表的HF编码,添加失败!");
        }
        order.setHfCodeD(eamBaseHFCode.getHfCode());
        //技术状态鉴定设备精度检查表
        eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.TECHNICAL_STATUS_EVALUATION_PRECISION_CHECK.name());
        if (eamBaseHFCode == null) {
            throw new JeecgBootException("未配置设备精度检查表的HF编码,添加失败!");
        }
        order.setHfCodeC(eamBaseHFCode.getHfCode());
        this.getBaseMapper().insert(order);
        //处理明细数据
        List<EamTechnicalStatusEvaluationOrderDetail> orderDetailList = standardDetailList.stream().map(item -> new EamTechnicalStatusEvaluationOrderDetail(item, order.getId())).collect(Collectors.toList());
        orderDetailService.saveBatch(orderDetailList);
        return true;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean collect(String id) {
        EamTechnicalStatusEvaluationOrder entity = super.getBaseMapper().selectById(id);
        if (entity == null) {
            throw new JeecgBootException("要领取的工单不存在,请刷新重试!");
        }
        if (!TechnicalStatusEvaluationOrderStatusEnum.WAIT_EVALUATION.name().equals(entity.getEvaluationStatus())) {
            throw new JeecgBootException("该工单已进行过领取!");
        }
        EamTechnicalStatusEvaluationStandard standard = standardService.getById(entity.getStandardId());
        if (standard == null) {
            throw new JeecgBootException("设备保养标准不存在,请检查!");
        }
        EamEquipment equipment = equipmentService.getById(entity.getEquipmentId());
        if (equipment == null) {
            throw new JeecgBootException("设备不存在,添加失败!");
        }
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (sysUser == null) {
            throw new JeecgBootException("不是维修工,无法领取此工单!");
        }
        List<UserSelector> userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0002);
        if (CollectionUtil.isEmpty(userSelectors)) {
            throw new JeecgBootException("设备未分配给维修工,无法领取!");
        }
        List<String> userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
        if (!userApprovalList.contains(sysUser.getUsername())) {
            throw new JeecgBootException("您没有领取此工单的权限!");
        }
        entity.setEvaluator(sysUser.getUsername());
        entity.setEvaluationStatus(TechnicalStatusEvaluationOrderStatusEnum.UNDER_EVALUATION.name());
        entity.setActualStartTime(new Date());
        this.getBaseMapper().updateById(entity);
 
        //启动流程
        flowCommonService.initActBusiness("工单号: " + entity.getOrderNum() + ";设备编号: " + equipment.getEquipmentCode() + ";安装位置" + equipment.getInstallationPosition(),
                entity.getId(), "IEamTechnicalStatusEvaluationOrderService", "technical_status_evaluation_process", null);
        Map<String, Object> variables = new HashMap<>();
        variables.put("dataId", entity.getId());
        if (StrUtil.isEmpty(entity.getRemark())) {
            variables.put("organization", "技术状态鉴定工单默认启动流程");
            variables.put("comment", "技术状态鉴定工单默认启动流程");
        } else {
            variables.put("organization", entity.getRemark());
            variables.put("comment", entity.getRemark());
        }
        variables.put("proofreading", true);
        if (CommonConstant.STATUS_1.equals(standard.getHasSafetyEquipmentCheck())) {
            variables.put("hasSafetyEquipmentCheck", CommonConstant.STATUS_1);
            variables.put("safety_equipment_check", userApprovalList);
            entity.setSafetyCheckCompleted(CommonConstant.STATUS_0);
        } else {
            variables.put("hasSafetyEquipmentCheck", CommonConstant.STATUS_0);
            variables.put("safety_equipment_check", userApprovalList);
        }
        if (CommonConstant.STATUS_1.equals(standard.getHasPrecisionCheck())) {
            variables.put("hasPrecisionCheck", CommonConstant.STATUS_1);
            variables.put("equipment_precision_check", userApprovalList);
            entity.setPrecisionCheckCompleted(CommonConstant.STATUS_0);
        } else {
            variables.put("hasPrecisionCheck", CommonConstant.STATUS_0);
            variables.put("equipment_precision_check", userApprovalList);
        }
        if (CommonConstant.STATUS_1.equals(standard.getHasOtherCheck())) {
            variables.put("hasOtherCheck", CommonConstant.STATUS_1);
            variables.put("other_check", userApprovalList);
            entity.setOtherCheckCompleted(CommonConstant.STATUS_0);
        } else {
            variables.put("hasOtherCheck", CommonConstant.STATUS_0);
            variables.put("other_check", userApprovalList);
        }
        Result<?> result = flowDefinitionService.startProcessInstanceByKey("technical_status_evaluation_process", variables);
        if (result == null || !result.isSuccess()) {
            throw new JeecgBootException("启动流程失败,领取失败");
        }
        return true;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public EamTechnicalStatusEvaluationOrder approval(EamTechnicalStatusEvaluationOrderRequest request) {
        EamTechnicalStatusEvaluationOrder entity = this.getBaseMapper().selectById(request.getId());
        if (entity == null) {
            throw new JeecgBootException("审批的数据已删除,请刷新重试!");
        }
        // 获取当前登录用户
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (user == null || StrUtil.isBlank(user.getId())) {
            throw new JeecgBootException("未获取到登录用户,请重新登录后再试!");
        }
        request.setAssignee(user.getUsername());
        // 获取流程业务记录
        FlowMyBusiness flowMyBusiness = flowMyBusinessService.getFlowMyBusiness(request.getInstanceId(), request.getTaskId());
        if (flowMyBusiness == null) {
            throw new JeecgBootException("流程实例不存在,请刷新后重试!");
        }
 
        boolean userAuthorized = flowMyBusinessService.isUserAuthorized(flowMyBusiness, user);
        if (!userAuthorized) {
            throw new JeecgBootException("用户无权操作此任务,请刷新后重试!");
        }
        // 认领任务
        if (!flowMyBusinessService.claimTask(flowMyBusiness.getTaskId(), user)) {
            throw new JeecgBootException("任务不存在、已完成或已被他人认领!");
        }
 
        EamEquipment equipment = equipmentService.getById(entity.getEquipmentId());
        if (equipment == null) {
            throw new JeecgBootException("设备不存在,请检查!");
        }
 
        TechnicalStatusEvaluationOrderStatusEnum status = TechnicalStatusEvaluationOrderStatusEnum.getInstance(entity.getEvaluationStatus());
        if (status == null) {
            return null;
        }
        //流程变量
        Map<String, Object> values = new HashMap<>();
        List<String> userApprovalList;
        List<UserSelector> userSelectors;
        switch (status) {
            case UNDER_EVALUATION:
                if(CollectionUtil.isEmpty(request.getTableDetailList())) {
                    throw new JeecgBootException("检查明细信息为空!");
                }
                boolean parallelCompletion = flowTaskService.checkParallelCompletion(flowMyBusiness.getTaskId());
                //执行完成
                userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0008);
                if (CollectionUtil.isEmpty(userSelectors)) {
                    throw new JeecgBootException("设备未分配给维修室主任,无法进入下级审批!");
                }
                userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                values.put("dataId", entity.getId());
                values.put("organization", "技术状态鉴定执行结束");
                values.put("comment", "技术状态鉴定执行结束");
                request.setComment("技术状态鉴定执行结束");
                //设置entity
                if (CommonConstant.STATUS_1.equals(entity.getSafetyCheckCompleted())
                        && CommonConstant.STATUS_1.equals(entity.getPrecisionCheckCompleted())
                        && CommonConstant.STATUS_1.equals(entity.getOtherCheckCompleted())
                        && parallelCompletion) {
                    //多个任务都已完成且维修室主任都已审批通过,会签完成,进行维修工签字
                    userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0002);
                    userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                    values.put("NextAssignee", userApprovalList);
                    entity.setEvaluationStatus(TechnicalStatusEvaluationOrderStatusEnum.REPAIRER_SIGNING.name());
                    entity.setActualEndTime(new Date());
                }
                if ("safety_equipment_check".equals(flowMyBusiness.getTaskNameId())) {
                    //执行安全检查
                    //安全装置检查结果填报
                    List<EamTechnicalStatusEvaluationOrderDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList());
                    if (CollectionUtil.isEmpty(collect)) {
                        throw new JeecgBootException("安全装置检查项明细为空!");
                    }
                    //结果项检查
                    checkDetailResult(request.getTableDetailList(), TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK);
                    //添加操作人信息
                    for (EamTechnicalStatusEvaluationOrderDetail detail : collect) {
                        detail.setRepairmanSignature(user.getUsername());
                        detail.setRepairmanSignatureTime(new Date());
                    }
                    orderDetailService.updateBatchById(collect);
                    values.put("NextAssignee", userApprovalList);
                    entity.setSafetyCheckCompleted(CommonConstant.STATUS_1);
                } else if ("safety_equipment_check_confirm".equals(flowMyBusiness.getTaskNameId()) && CommonConstant.STATUS_1.equals(entity.getSafetyCheckCompleted())) {
                    values.put("safetyEquipmentCheckFlag", request.getSafetyCheckConfirmResult());
                    entity.setSafetyCheckConfirmResult(request.getSafetyCheckConfirmResult());
                    entity.setSafetyCheckConfirm(user.getUsername());
                    entity.setSafetyCheckConfirmTime(new Date());
                    entity.setSafetyCheckConfirmComment(request.getSafetyCheckConfirmComment());
                    //维修室主任审批
                    if (!CommonConstant.STATUS_1.equals(request.getSafetyCheckConfirmResult())) {
                        //驳回 给监察人
                        userApprovalList = Collections.singletonList(request.getTableDetailList().get(0).getRepairmanSignature());
                        values.put("NextAssignee", userApprovalList);
                        entity.setSafetyCheckCompleted(CommonConstant.STATUS_0);
                    }
                } else if ("equipment_precision_check".equals(flowMyBusiness.getTaskNameId())) {
                    //处理精度检验
                    //设备精度检查结果填报
                    List<EamTechnicalStatusEvaluationOrderDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList());
                    if (CollectionUtil.isEmpty(collect)) {
                        throw new JeecgBootException("设备精度检查项明细为空!");
                    }
                    //结果项检查
                    checkDetailResult(request.getTableDetailList(), TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK);
                    //添加操作人信息
                    for (EamTechnicalStatusEvaluationOrderDetail detail : collect) {
                        detail.setRepairmanSignature(user.getUsername());
                        detail.setRepairmanSignatureTime(new Date());
                    }
                    orderDetailService.updateBatchById(collect);
                    values.put("NextAssignee", userApprovalList);
                    entity.setPrecisionCheckCompleted(CommonConstant.STATUS_1);
                } else if ("equipment_precision_check_confirm".equals(flowMyBusiness.getTaskNameId()) && CommonConstant.STATUS_1.equals(entity.getPrecisionCheckCompleted())) {
                    values.put("precisionCheckFlag", request.getPrecisionCheckConfirmResult());
                    entity.setPrecisionCheckConfirmResult(request.getPrecisionCheckConfirmResult());
                    entity.setPrecisionCheckConfirm(user.getUsername());
                    entity.setPrecisionCheckConfirmTime(new Date());
                    entity.setPrecisionCheckConfirmComment(request.getPrecisionCheckConfirmComment());
                    //维修室主任审批
                    if (!CommonConstant.STATUS_1.equals(request.getPrecisionCheckConfirmResult())) {
                        //驳回 给监察人
                        userApprovalList = Collections.singletonList(request.getTableDetailList().get(0).getRepairmanSignature());
                        values.put("NextAssignee", userApprovalList);
                        entity.setPrecisionCheckCompleted(CommonConstant.STATUS_0);
                    }
                } else if ("other_check".equals(flowMyBusiness.getTaskNameId())) {
                    //处理其他检查
                    //其他检查结果填报
                    List<EamTechnicalStatusEvaluationOrderDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList());
                    if (CollectionUtil.isEmpty(collect)) {
                        throw new JeecgBootException("其他检查项明细为空!");
                    }
                    //结果项检查
                    checkDetailResult(request.getTableDetailList(), TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK);
                    //添加操作人信息
                    for (EamTechnicalStatusEvaluationOrderDetail detail : collect) {
                        detail.setRepairmanSignature(user.getUsername());
                        detail.setRepairmanSignatureTime(new Date());
                    }
                    orderDetailService.updateBatchById(collect);
                    values.put("NextAssignee", userApprovalList);
                    entity.setOtherCheckCompleted(CommonConstant.STATUS_1);
                } else if ("other_check_confirm".equals(flowMyBusiness.getTaskNameId()) && CommonConstant.STATUS_1.equals(entity.getOtherCheckCompleted())) {
                    values.put("otherCheckFlag", request.getOtherCheckConfirmResult());
                    entity.setOtherCheckConfirmResult(request.getOtherCheckConfirmResult());
                    entity.setOtherCheckConfirm(user.getUsername());
                    entity.setOtherCheckConfirmTime(new Date());
                    entity.setOtherCheckConfirmComment(request.getOtherCheckConfirmComment());
                    //维修室主任审批
                    if (!CommonConstant.STATUS_1.equals(request.getOtherCheckConfirmResult())) {
                        //驳回 给监察人
                        userApprovalList = Collections.singletonList(request.getTableDetailList().get(0).getRepairmanSignature());
                        values.put("NextAssignee", userApprovalList);
                        entity.setOtherCheckCompleted(CommonConstant.STATUS_0);
                    }
                }
                break;
            case REPAIRER_SIGNING:
                //维修工签字
                userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0008);
                if (CollectionUtil.isEmpty(userSelectors)) {
                    throw new JeecgBootException("设备未分配给维修室主任,无法进入下级审批!");
                }
                userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                values.put("dataId", entity.getId());
                values.put("organization", "维修工签字完成");
                values.put("comment", "维修工签字完成");
                values.put("NextAssignee", userApprovalList);
                request.setComment("维修工签字完成");
                //设置entity
                entity.setEvaluationStatus(TechnicalStatusEvaluationOrderStatusEnum.REPAIR_MANAGER_SIGNING.name());
                entity.setRepairerSignature(user.getUsername());
                entity.setRepairerSignatureTime(new Date());
                entity.setSafetyEquipmentCheckResult(request.getSafetyEquipmentCheckResult());
                entity.setPrecisionCheckResult(request.getPrecisionCheckResult());
                entity.setFunctionalCheckResult(request.getFunctionalCheckResult());
                entity.setOtherCheckResult(request.getOtherCheckResult());
                break;
            case REPAIR_MANAGER_SIGNING:
                //维修室主任签字
                userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0007);
                if (CollectionUtil.isEmpty(userSelectors)) {
                    throw new JeecgBootException("设备未分配给工艺员,无法进入下级审批!");
                }
                userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                values.put("dataId", entity.getId());
                values.put("organization", request.getRepairManagerComment());
                values.put("comment", request.getRepairManagerComment());
                request.setComment(request.getRepairManagerComment());
                values.put("repairManagerApprovalFlag", request.getRepairManagerSignatureResult());
                entity.setRepairManagerSignature(user.getUsername());
                entity.setRepairManagerSignatureTime(new Date());
                entity.setRepairManagerComment(request.getRepairManagerComment());
                entity.setRepairManagerSignatureResult(request.getRepairManagerSignatureResult());
                //设置entity
                if (BusinessCodeConst.APPROVED.equals(request.getRepairManagerSignatureResult())) {
                    values.put("NextAssignee", userApprovalList);
                    entity.setEvaluationStatus(TechnicalStatusEvaluationOrderStatusEnum.PROCESS_TECHNICIAN_SIGNING.name());
                } else {
                    userApprovalList = Collections.singletonList(entity.getRepairerSignature());
                    values.put("NextAssignee", userApprovalList);
                    entity.setEvaluationStatus(TechnicalStatusEvaluationOrderStatusEnum.REPAIRER_SIGNING.name());
                }
//                //更新设备保养状态
//                eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.NORMAL.name());
                break;
            case PROCESS_TECHNICIAN_SIGNING:
                //工艺员签字
                userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0010);
                if (CollectionUtil.isEmpty(userSelectors)) {
                    throw new JeecgBootException("设备未分配给使用单位技术主管,无法进入下级审批!");
                }
                userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                values.put("dataId", entity.getId());
                values.put("organization", request.getProcessTechnicianComment());
                values.put("comment", request.getProcessTechnicianComment());
                values.put("NextAssignee", userApprovalList);
                request.setComment(request.getProcessTechnicianComment());
                //设置entity
                entity.setEvaluationStatus(TechnicalStatusEvaluationOrderStatusEnum.DEPART_TECHNICAL_LEADER_SIGNING.name());
                entity.setProcessTechnicianSignature(user.getUsername());
                entity.setProcessTechnicianSignatureTime(new Date());
                entity.setSampleCheckResult(request.getSampleCheckResult());
                entity.setProcessTechnicianComment(request.getProcessTechnicianComment());
                break;
            case DEPART_TECHNICAL_LEADER_SIGNING:
                //使用单位技术主管签字
                userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0003);
                if (CollectionUtil.isEmpty(userSelectors)) {
                    throw new JeecgBootException("设备未分配给设备检验员,无法进入下级审批!");
                }
                userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                values.put("dataId", entity.getId());
                values.put("organization", request.getDepartTechnicalLeaderComment());
                values.put("comment", request.getDepartTechnicalLeaderComment());
                request.setComment(request.getDepartTechnicalLeaderComment());
                values.put("technicalLeaderApprovalFlag", request.getDepartTechnicalLeaderSignatureResult());
                entity.setDepartTechnicalLeaderSignature(user.getUsername());
                entity.setDepartTechnicalLeaderSignatureTime(new Date());
                entity.setDepartTechnicalLeaderComment(request.getDepartTechnicalLeaderComment());
                entity.setDepartTechnicalLeaderSignatureResult(request.getDepartTechnicalLeaderSignatureResult());
                //设置entity
                if (BusinessCodeConst.APPROVED.equals(request.getDepartTechnicalLeaderSignatureResult())) {
                    values.put("NextAssignee", userApprovalList);
                    entity.setEvaluationStatus(TechnicalStatusEvaluationOrderStatusEnum.INSPECTOR_SIGNING.name());
                } else {
                    userApprovalList = Collections.singletonList(entity.getProcessTechnicianSignature());
                    values.put("NextAssignee", userApprovalList);
                    entity.setEvaluationStatus(TechnicalStatusEvaluationOrderStatusEnum.PROCESS_TECHNICIAN_SIGNING.name());
                }
                break;
            case INSPECTOR_SIGNING:
                //设备检察员签字
                values.put("dataId", entity.getId());
                values.put("organization", request.getInspectorComment());
                values.put("comment", request.getInspectorComment());
                request.setComment(request.getInspectorComment());
                //设置entity
                entity.setEvaluationStatus(TechnicalStatusEvaluationOrderStatusEnum.COMPLETED.name());
                entity.setInspectorSignature(user.getUsername());
                entity.setInspectorSignatureTime(new Date());
                entity.setInspectorComment(request.getInspectorComment());
                entity.setEvaluationResult(request.getEvaluationResult());
                entity.setEvaluationReason(request.getEvaluationReason());
                break;
        }
        request.setValues(values);
 
        // 完成流程任务
        Result<?> result = flowTaskService.complete(request);
        if (!result.isSuccess()) {
            throw new JeecgBootException("审批失败,请刷新查看!");
        }
        //保存工单
        this.getBaseMapper().updateById(entity);
        return entity;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateEvaluationStatus(String orderId, String evaluationStatus) {
        UpdateWrapper<EamTechnicalStatusEvaluationOrder> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", orderId);
        updateWrapper.set("evaluation_status", evaluationStatus);
        updateWrapper.eq("del_flag", CommonConstant.DEL_FLAG_0);
        updateWrapper.in("evaluation_status", Arrays.asList(TechnicalStatusEvaluationOrderStatusEnum.WAIT_EVALUATION.name(), TechnicalStatusEvaluationOrderStatusEnum.LOCKED.name()));
        int update = this.getBaseMapper().update(null, updateWrapper);
        return update > 0;
    }
 
    private void checkDetailResult(List<EamTechnicalStatusEvaluationOrderDetail> detailList, TechnicalStatusEvaluationCheckCategoryEnum checkCategory) {
        boolean b;
        switch (checkCategory) {
            case SAFETY_EQUIPMENT_CHECK:
                b = detailList.stream().allMatch(item -> StringUtils.isNotBlank(item.getSafetyEquipmentCheckResult()));
                if (!b) {
                    throw new JeecgBootException("有安全装置检查结果未填写!");
                }
                break;
            case PRECISION_CHECK:
                b = detailList.stream().allMatch(item -> item.getPrecisionCheckResult() != null);
                if (!b) {
                    throw new JeecgBootException("有设备精度检查结果未填写!");
                }
                break;
            case OTHER_CHECK:
                b = detailList.stream().allMatch(item -> StringUtils.isNotBlank(item.getOtherCheckResult()));
                if (!b) {
                    throw new JeecgBootException("有其他检查结果未填写!");
                }
                break;
        }
    }
 
    @Override
    public void afterFlowHandle(FlowMyBusiness business) {
        business.getTaskNameId();//接下来审批的节点
        business.getValues();//前端传进来的参数
        business.getActStatus();
    }
 
    @Override
    public Object getBusinessDataById(String dataId) {
        return this.getById(dataId);
    }
 
    @Override
    public Map<String, Object> flowValuesOfTask(String taskNameId, Map<String, Object> values) {
        return null;
    }
 
    @Override
    public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) {
        //业务是否干预流程,业务干预,流程干预,指定人员进行处理
        //获取下一步处理人
        Object object = values.get("NextAssignee");
        return (List<String>) object;
    }
}