From 504333e56f249d16e71e8ac2a435cf2212040c23 Mon Sep 17 00:00:00 2001 From: cuikaidong <ckd2942379034@163.com> Date: 星期二, 27 五月 2025 17:32:50 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamThirdMaintenanceOrderServiceImpl.java | 259 ++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 201 insertions(+), 58 deletions(-) diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamThirdMaintenanceOrderServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamThirdMaintenanceOrderServiceImpl.java index 6840c49..383da21 100644 --- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamThirdMaintenanceOrderServiceImpl.java +++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamThirdMaintenanceOrderServiceImpl.java @@ -7,19 +7,23 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.flowable.engine.TaskService; import org.flowable.task.api.Task; +import org.jeecg.common.api.vo.FileUploadResult; 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.aspect.annotation.EquipmentHistoryLog; import org.jeecg.modules.eam.constant.BusinessCodeConst; import org.jeecg.modules.eam.constant.EquipmentMaintenanceStatus; -import org.jeecg.modules.eam.constant.SecondMaintenanceStatusEnum; +import org.jeecg.modules.eam.constant.EquipmentOperationTagEnum; import org.jeecg.modules.eam.constant.ThirdMaintenanceStatusEnum; import org.jeecg.modules.eam.entity.EamEquipment; import org.jeecg.modules.eam.entity.EamThirdMaintenanceOrder; @@ -35,6 +39,7 @@ import org.jeecg.modules.flowable.service.IFlowDefinitionService; import org.jeecg.modules.flowable.service.IFlowTaskService; 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; @@ -166,32 +171,28 @@ } //鍒ゆ柇鏄惁瀛樺湪淇濆吇浜� 濡傛灉瀛樺湪鍒欏惎鍔ㄦ祦绋� if (StringUtils.isNotBlank(order.getOperator())) { - //鍚姩娴佺▼ TODO -// flowCommonService.initActBusiness("宸ュ崟鍙�:" + order.getOrderNum() + ";璁惧缂栧彿: " + equipment.getEquipmentCode() + ";杩涜璁惧浜屼繚", -// order.getId(), "IEamWeekMaintenanceOrderService", "week_maintenance_process", null); -// Map<String, Object> variables = new HashMap<>(); -// variables.put("dataId", order.getId()); -// if (StrUtil.isEmpty(order.getRemark())) { -// variables.put("organization", "鏂板鍛ㄤ繚宸ュ崟榛樿鍚姩娴佺▼"); -// variables.put("comment", "鏂板鍛ㄤ繚宸ュ崟榛樿鍚姩娴佺▼"); -// } else { -// variables.put("organization", order.getRemark()); -// variables.put("comment", order.getRemark()); -// } -// variables.put("proofreading", true); -// List<String> usernames = new ArrayList<>(); -// usernames.add(order.getOperator()); -// variables.put("NextAssignee", usernames); -// Result result = flowDefinitionService.startProcessInstanceByKey("week_maintenance_process", variables); -// if (result != null) { -// //鏇存柊鍛ㄤ繚鐘舵�� -// order.setMaintenanceStatus(WeekMaintenanceStatusEnum.UNDER_MAINTENANCE.name()); -// order.setActualStartTime(new Date()); -// eamWeekMaintenanceOrderMapper.updateById(order); -// //鏇存柊璁惧淇濆吇鐘舵�� -// eamEquipmentExtendService.updateEquipmentMaintenanceStatus(order.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name()); -// return result.isSuccess(); -// } + //鍚姩娴佺▼ + flowCommonService.initActBusiness("宸ュ崟鍙�:" + order.getOrderNum() + ";璁惧缂栧彿: " + equipment.getEquipmentCode() + ";杩涜璁惧涓変繚", + order.getId(), "IEamThirdMaintenanceOrderService", "third_maintenance_process", null); + Map<String, Object> variables = new HashMap<>(); + variables.put("dataId", order.getId()); + if (StrUtil.isEmpty(order.getRemark())) { + variables.put("organization", "鏂板涓変繚宸ュ崟榛樿鍚姩娴佺▼"); + variables.put("comment", "鏂板涓変繚宸ュ崟榛樿鍚姩娴佺▼"); + } else { + variables.put("organization", order.getRemark()); + variables.put("comment", order.getRemark()); + } + variables.put("proofreading", true); + //骞惰浠诲姟浼氱 + variables.put("maintenance_execution", Collections.singletonList(request.getOperator())); + variables.put("precision_check", Collections.singletonList(equipment.getEquipmentManager())); + Result result = flowDefinitionService.startProcessInstanceByKey("third_maintenance_process", variables); + if (result != null) { + //鏇存柊璁惧淇濆吇鐘舵�� + eamEquipmentExtendService.updateEquipmentMaintenanceStatus(order.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_THIRD_MAINTENANCE.name()); + return result.isSuccess(); + } } return true; @@ -241,32 +242,28 @@ } //鍒ゆ柇鏄惁瀛樺湪淇濆吇浜� 濡傛灉瀛樺湪鍒欏惎鍔ㄦ祦绋� if (StringUtils.isNotBlank(entity.getOperator())) { - //鍚姩娴佺▼ TODO -// flowCommonService.initActBusiness("宸ュ崟鍙�:" + entity.getOrderNum() + ";璁惧缂栧彿: " + equipment.getEquipmentCode() + ";杩涜璁惧鍛ㄤ繚", -// entity.getId(), "IEamWeekMaintenanceOrderService", "week_maintenance_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); -// List<String> usernames = new ArrayList<>(); -// usernames.add(entity.getOperator()); -// variables.put("NextAssignee", usernames); -// Result result = flowDefinitionService.startProcessInstanceByKey("week_maintenance_process", variables); -// if (result != null) { -// //鏇存柊鍛ㄤ繚鐘舵�� -// entity.setMaintenanceStatus(WeekMaintenanceStatusEnum.UNDER_MAINTENANCE.name()); -// entity.setActualStartTime(new Date()); -// eamWeekMaintenanceOrderMapper.updateById(entity); -// //鏇存柊璁惧淇濆吇鐘舵�� -// eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name()); -// return result.isSuccess(); -// } + //鍚姩娴佺▼ + flowCommonService.initActBusiness("宸ュ崟鍙�:" + entity.getOrderNum() + ";璁惧缂栧彿: " + equipment.getEquipmentCode() + ";杩涜璁惧涓変繚", + entity.getId(), "IEamThirdMaintenanceOrderService", "third_maintenance_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); + //骞惰浠诲姟浼氱 + variables.put("maintenance_execution", Collections.singletonList(request.getOperator())); + variables.put("precision_check", Collections.singletonList(equipment.getEquipmentManager())); + Result result = flowDefinitionService.startProcessInstanceByKey("third_maintenance_process", variables); + if (result != null) { + //鏇存柊璁惧淇濆吇鐘舵�� + eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_THIRD_MAINTENANCE.name()); + return result.isSuccess(); + } } return true; @@ -279,15 +276,18 @@ if (entity == null) { throw new JeecgBootException("瑕侀鍙栫殑宸ュ崟涓嶅瓨鍦紝璇峰埛鏂伴噸璇曪紒"); } - if (!SecondMaintenanceStatusEnum.WAIT_MAINTENANCE.name().equals(entity.getMaintenanceStatus())) { + if (!ThirdMaintenanceStatusEnum.WAIT_MAINTENANCE.name().equals(entity.getMaintenanceStatus())) { throw new JeecgBootException("璇ュ伐鍗曞凡杩涜杩囬鍙栵紒"); } EamEquipment equipment = eamEquipmentService.getById(entity.getEquipmentId()); if (equipment == null) { throw new JeecgBootException("璁惧涓嶅瓨鍦紝娣诲姞澶辫触锛�"); } + if (StringUtils.isBlank(equipment.getEquipmentManager())) { + throw new JeecgBootException("璁惧鏈垎閰嶈澶囩鐞嗗憳锛屾棤娉曡繘鍏ヤ笅绾у鎵癸紒"); + } LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); - if(sysUser == null || !BusinessCodeConst.PCR0001.equals(sysUser.getPost())) { + if (sysUser == null || !BusinessCodeConst.PCR0001.equals(sysUser.getPost())) { throw new JeecgBootException("涓嶆槸鎿嶄綔宸ワ紝鏃犳硶棰嗗彇姝ゅ伐鍗曪紒"); } entity.setOperator(sysUser.getUsername()); @@ -310,9 +310,9 @@ variables.put("comment", entity.getRemark()); } variables.put("proofreading", true); - List<String> usernames = new ArrayList<>(); - usernames.add(entity.getOperator()); - variables.put("NextAssignee", usernames); + //骞惰浠诲姟浼氱 + variables.put("maintenance_execution", Collections.singletonList(sysUser.getUsername())); + variables.put("precision_check", Collections.singletonList(equipment.getEquipmentManager())); Result result = flowDefinitionService.startProcessInstanceByKey("third_maintenance_process", variables); if (result != null) { //鏇存柊璁惧淇濆吇鐘舵�� @@ -322,6 +322,149 @@ return true; } + @Override + @Transactional(rollbackFor = Exception.class) + @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.THIRD_MAINTENANCE, businessTable = "eam_third_maintenance_order") + public EamThirdMaintenanceOrder approval(EamThirdMaintenanceRequest request) { + EamThirdMaintenanceOrder entity = eamThirdMaintenanceOrderMapper.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 = isUserAuthorized(flowMyBusiness, user); + if (!userAuthorized) { + throw new JeecgBootException("鐢ㄦ埛鏃犳潈鎿嶄綔姝や换鍔★紝璇峰埛鏂板悗閲嶈瘯锛�"); + } + // 璁ら浠诲姟 + if (!claimTask(flowMyBusiness.getTaskId(), user)) { + throw new JeecgBootException("浠诲姟涓嶅瓨鍦ㄣ�佸凡瀹屾垚鎴栧凡琚粬浜鸿棰嗭紒"); + } + + EamEquipment equipment = eamEquipmentService.getById(entity.getEquipmentId()); + if (equipment == null) { + throw new JeecgBootException("璁惧涓嶅瓨鍦紝璇锋鏌ワ紒"); + } + + ThirdMaintenanceStatusEnum status = ThirdMaintenanceStatusEnum.getInstance(entity.getMaintenanceStatus()); + if (status == null) { + return null; + } + //娴佺▼鍙橀噺 + Map<String, Object> values = new HashMap<>(); + List<String> userApprovalList; + List<UserSelector> userSelectors; + switch (status) { + case UNDER_MAINTENANCE: + boolean parallelCompletion = flowTaskService.checkParallelCompletion(flowMyBusiness.getTaskId()); + //鎵ц瀹屾垚 + userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getOrgId(), BusinessCodeConst.PCR0006); + 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", "涓変繚鎵ц缁撴潫"); + if (parallelCompletion) { + values.put("NextAssignee", userApprovalList); + } + request.setComment("涓変繚鎵ц缁撴潫"); + //璁剧疆entity + if (parallelCompletion) { + entity.setMaintenanceStatus(ThirdMaintenanceStatusEnum.WAIT_CONFIRM.name()); + entity.setActualEndTime(new Date()); + } + if ("maintenance_execution".equals(flowMyBusiness.getTaskNameId())) { + //鎵ц淇濆吇 + //澶勭悊闄勪欢 + if (CollectionUtil.isNotEmpty(request.getImageFilesResult())) { + List<FileUploadResult> fileUploadResultList = request.getImageFilesResult(); + ObjectMapper mapper = new ObjectMapper(); + try { + String referenceFile = mapper.writeValueAsString(fileUploadResultList); + entity.setImageFiles(referenceFile); + } catch (JsonProcessingException e) { + log.error("JSON杞崲澶辫触锛�" + e.getMessage(), e); + } + } + //澶勭悊璇︽儏 + if (CollectionUtil.isNotEmpty(request.getTableDetailList())) { + thirdMaintenanceOrderDetailService.updateBatchById(request.getTableDetailList()); + } + } else if ("precision_check".equals(flowMyBusiness.getTaskNameId())) { + entity.setPrecisionChecker(user.getUsername()); + entity.setPrecisionCheckTime(new Date()); + //澶勭悊绮惧害妫�楠� + if (CollectionUtil.isNotEmpty(request.getPrecisionDetailList())) { + precisionCheckDetailService.updateBatchById(request.getPrecisionDetailList()); + } + } + if (parallelCompletion) { + //鏇存柊璁惧淇濆吇鐘舵�� + eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.THIRD_MAINTENANCE_WAIT_CONFIRM.name()); + } + break; + case WAIT_CONFIRM: + userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getOrgId(), 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.getConfirmComment()); + values.put("comment", request.getConfirmComment()); + values.put("NextAssignee", userApprovalList); + values.put("confirmation", request.getConfirmDealType()); + request.setComment(request.getConfirmComment()); + //璁剧疆entity + entity.setMaintenanceStatus(ThirdMaintenanceStatusEnum.WAIT_LEADER_CONFIRM.name()); + entity.setConfirmUser(user.getUsername()); + entity.setConfirmComment(request.getConfirmComment()); + entity.setConfirmTime(new Date()); + //澶勭悊鎶ヤ慨 + List<EamThirdMaintenanceOrderDetail> collect = request.getTableDetailList().stream().filter((detail) -> CommonConstant.DEFAULT_1.equals(detail.getReportFlag())).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(collect)) { + eamReportRepairService.reportRepairFromThirdMaintenance(equipment.getId(), entity.getOperator(), collect); + } + break; + case WAIT_LEADER_CONFIRM: + values.put("dataId", entity.getId()); + values.put("organization", request.getLeaderConfirmComment()); + values.put("comment", request.getLeaderConfirmComment()); + request.setComment(request.getLeaderConfirmComment()); + //璁剧疆entity + entity.setMaintenanceStatus(ThirdMaintenanceStatusEnum.COMPLETE.name()); + entity.setConfirmLeader(user.getUsername()); + entity.setLeaderConfirmComment(request.getLeaderConfirmComment()); + entity.setLeaderConfirmTime(new Date()); + //鏇存柊璁惧淇濆吇鐘舵�� + eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.NORMAL.name()); + break; + } + request.setValues(values); + + // 瀹屾垚娴佺▼浠诲姟 + Result result = flowTaskService.complete(request); + if (!result.isSuccess()) { + throw new JeecgBootException("瀹℃壒澶辫触锛岃鍒锋柊鏌ョ湅锛�"); + } + //淇濆瓨宸ュ崟 + eamThirdMaintenanceOrderMapper.updateById(entity); + return entity; + } + private boolean isUserAuthorized(FlowMyBusiness flowMyBusiness, LoginUser user) { List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class); return todoUsers != null && todoUsers.contains(user.getUsername()); -- Gitblit v1.9.3