| | |
| | | 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.metadata.IPage; |
| | |
| | | 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.TranslateDictTextUtils; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.eam.constant.BusinessCodeConst; |
| | | import org.jeecg.modules.eam.constant.HfTemplateCategoryEnum; |
| | | import org.jeecg.modules.eam.constant.TechnicalStatusEvaluationOrderChangeStatusEnum; |
| | | import org.jeecg.modules.eam.constant.TechnicalStatusEvaluationOrderStatusEnum; |
| | | import org.jeecg.modules.eam.constant.*; |
| | | import org.jeecg.modules.eam.entity.EamBaseHFCode; |
| | | import org.jeecg.modules.eam.entity.EamEquipment; |
| | | import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationOrder; |
| | | import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationOrderChange; |
| | | import org.jeecg.modules.eam.mapper.EamTechnicalStatusEvaluationOrderChangeMapper; |
| | | import org.jeecg.modules.eam.request.EamTechnicalStatusEvaluationOrderChangeQuery; |
| | | import org.jeecg.modules.eam.request.EamTechnicalStatusEvaluationOrderChangeRequest; |
| | | import org.jeecg.modules.eam.service.IEamBaseHFCodeService; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentService; |
| | | import org.jeecg.modules.eam.service.IEamTechnicalStatusEvaluationOrderChangeService; |
| | | import org.jeecg.modules.eam.service.IEamTechnicalStatusEvaluationOrderService; |
| | | 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; |
| | |
| | | private ISysBusinessCodeRuleService businessCodeRuleService; |
| | | @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 TranslateDictTextUtils translateDictTextUtils; |
| | | @Autowired |
| | | private ISysUserService sysUserService; |
| | | |
| | | |
| | | @Override |
| | | public IPage<EamTechnicalStatusEvaluationOrderChange> queryPageList(Page<EamTechnicalStatusEvaluationOrderChange> page, EamTechnicalStatusEvaluationOrderChangeQuery query) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean submit(String id) { |
| | | EamTechnicalStatusEvaluationOrderChange entity = this.getBaseMapper().selectById(id); |
| | | if (entity == null) { |
| | | throw new JeecgBootException("è¦æäº¤çå·¥åä¸åå¨ï¼è¯·å·æ°éè¯ï¼"); |
| | | } |
| | | if (!TechnicalStatusEvaluationOrderChangeStatusEnum.WAIT_SUBMIT.name().equals(entity.getChangeStatus())) { |
| | | throw new JeecgBootException("该工åå·²è¿è¡è¿æäº¤ï¼"); |
| | | } |
| | | EamTechnicalStatusEvaluationOrder order = evaluationOrderService.getById(entity.getOrderId()); |
| | | if(order == 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 || !sysUser.getUsername().equals(entity.getApplicant())) { |
| | | throw new JeecgBootException("䏿¯æ¬äººï¼ä¸è½æäº¤æ¤å·¥åï¼"); |
| | | } |
| | | entity.setChangeStatus(TechnicalStatusEvaluationOrderChangeStatusEnum.EQUIPMENT_MANAGER_SIGNING.name()); |
| | | //æ¥è¯¢ä¸çº§å®¡æ¹äººå |
| | | List<UserSelector> userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0011); |
| | | if (CollectionUtil.isEmpty(userSelectors)) { |
| | | throw new JeecgBootException("è®¾å¤æªåé
ç»ä½¿ç¨åä½ä¸»ç®¡å®¤çº§é¢å¯¼ï¼æ æ³æäº¤ï¼"); |
| | | } |
| | | List<String> userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList()); |
| | | //æ´æ°å®ä½ |
| | | this.getBaseMapper().updateById(entity); |
| | | //å¯å¨æµç¨ |
| | | flowCommonService.initActBusiness("å·¥åå·: " + entity.getChangeOrderNum() + ";设å¤ç¼å·: " + equipment.getEquipmentCode() + ";å®è£
ä½ç½®" + equipment.getInstallationPosition(), |
| | | entity.getId(), "IEamTechnicalStatusEvaluationOrderChangeService", "evaluation_order_change_process", null); |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | variables.put("dataId", entity.getId()); |
| | | String applyReasonText = translateDictTextUtils.translateField("applyReason", entity.getApplyReason(), "technical_status_evaluation_order_change_reason"); |
| | | if (StrUtil.isEmpty(applyReasonText)) { |
| | | variables.put("organization", "æ°å¢ææ¯ç¶æé´å®å·¥ååæ´é»è®¤å¯å¨æµç¨"); |
| | | variables.put("comment", "æ°å¢ææ¯ç¶æé´å®å·¥ååæ´é»è®¤å¯å¨æµç¨"); |
| | | } else { |
| | | variables.put("organization", applyReasonText); |
| | | variables.put("comment", applyReasonText); |
| | | } |
| | | variables.put("proofreading", true); |
| | | variables.put("NextAssignee", userApprovalList); |
| | | Result<?> result = flowDefinitionService.startProcessInstanceByKey("evaluation_order_change_process", variables); |
| | | if(result == null || !result.isSuccess()) { |
| | | throw new JeecgBootException("å¯å¨æµç¨å¤±è´¥ï¼"); |
| | | } |
| | | //æ´æ°å·¥åç¶æä¸ºåæ´ä¸ |
| | | order.setEvaluationStatus(TechnicalStatusEvaluationOrderStatusEnum.CHANGING.name()); |
| | | boolean b = evaluationOrderService.updateById(order); |
| | | if(!b) { |
| | | throw new JeecgBootException("ææ¯ç¶æé´å®å·¥åç¶ææ´æ°å¤±è´¥ï¼"); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public EamTechnicalStatusEvaluationOrderChange approval(EamTechnicalStatusEvaluationOrderChangeRequest request) { |
| | | EamTechnicalStatusEvaluationOrderChange entity = this.getBaseMapper().selectById(request.getId()); |
| | | if (entity == null) { |
| | | throw new JeecgBootException("审æ¹çæ°æ®å·²å é¤ï¼è¯·å·æ°éè¯ï¼"); |
| | | } |
| | | EamTechnicalStatusEvaluationOrder order = evaluationOrderService.getById(entity.getOrderId()); |
| | | if(order == 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("设å¤ä¸åå¨ï¼è¯·æ£æ¥ï¼"); |
| | | } |
| | | |
| | | TechnicalStatusEvaluationOrderChangeStatusEnum status = TechnicalStatusEvaluationOrderChangeStatusEnum.getInstance(entity.getChangeStatus()); |
| | | if (status == null) { |
| | | return null; |
| | | } |
| | | //æµç¨åé |
| | | Map<String, Object> values = new HashMap<>(); |
| | | List<String> userApprovalList; |
| | | List<UserSelector> userSelectors; |
| | | switch (status) { |
| | | case EQUIPMENT_MANAGER_SIGNING: |
| | | //使ç¨åä½ä¸»ç®¡å®¤çº§é¢å¯¼å®¡æ ¸ |
| | | if(TechnicalStatusEvaluationOrderChangeReasonEnum.PRODUCTION_WORK_ORDER_EXPEDITED.name().equals(request.getApplyReason())) { |
| | | //çäº§ä»»å¡ |
| | | userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0012); |
| | | if (CollectionUtil.isEmpty(userSelectors)) { |
| | | throw new JeecgBootException("è®¾å¤æªåé
ç»çäº§ææ¥é¨å®¤çº§é¢å¯¼ï¼æ æ³è¿å
¥ä¸çº§å®¡æ¹ï¼"); |
| | | } |
| | | } else if(TechnicalStatusEvaluationOrderChangeReasonEnum.EQUIPMENT_BREAKDOWN_REPAIR.name().equals(request.getApplyReason())) { |
| | | //è®¾å¤æ
é |
| | | userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0013); |
| | | if (CollectionUtil.isEmpty(userSelectors)) { |
| | | throw new JeecgBootException("è®¾å¤æªåé
ç»ç»´ä¿®åºé¿ï¼æ æ³è¿å
¥ä¸çº§å®¡æ¹ï¼"); |
| | | } |
| | | } else if(TechnicalStatusEvaluationOrderChangeReasonEnum.EQUIPMENT_SCRAPPED.name().equals(request.getApplyReason())) { |
| | | //è®¾å¤æ¥åº |
| | | userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0014); |
| | | if (CollectionUtil.isEmpty(userSelectors)) { |
| | | throw new JeecgBootException("è®¾å¤æªåé
ç»èµäº§ç®¡çé¨ï¼æ æ³è¿å
¥ä¸çº§å®¡æ¹ï¼"); |
| | | } |
| | | } else if(TechnicalStatusEvaluationOrderChangeReasonEnum.EQUIPMENT_MAJOR.name().equals(request.getApplyReason())) { |
| | | //设å¤å¤§ä¿® |
| | | userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0016); |
| | | if (CollectionUtil.isEmpty(userSelectors)) { |
| | | throw new JeecgBootException("è®¾å¤æªåé
ç»è¿ç»´åå¡å®¤ä¸»ä»»ï¼æ æ³è¿å
¥ä¸çº§å®¡æ¹ï¼"); |
| | | } |
| | | }else if(TechnicalStatusEvaluationOrderChangeReasonEnum.EQUIPMENT_RELOCATION.name().equals(request.getApplyReason()) || TechnicalStatusEvaluationOrderChangeReasonEnum.EQUIPMENT_RETROFITTING.name().equals(request.getApplyReason())) { |
| | | //è®¾å¤æ¬è¿ãæ¹é |
| | | userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0015); |
| | | if (CollectionUtil.isEmpty(userSelectors)) { |
| | | throw new JeecgBootException("è®¾å¤æªåé
ç»é¡¹ç®ä¸»ç®¡é¨ï¼æ æ³è¿å
¥ä¸çº§å®¡æ¹ï¼"); |
| | | } |
| | | } else { |
| | | throw new JeecgBootException("åæ´ç³è¯·åå æ æ³è¯å«ï¼å®¡æ¹å¤±è´¥ï¼"); |
| | | } |
| | | userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList()); |
| | | values.put("dataId", entity.getId()); |
| | | if(StringUtils.isBlank(request.getEquipmentManagerComment())) { |
| | | values.put("organization", "ææ¯ç¶æé´å®å·¥ååæ´ä½¿ç¨åä½ä¸»ç®¡å®¤çº§é¢å¯¼"); |
| | | values.put("comment", "ææ¯ç¶æé´å®å·¥ååæ´ä½¿ç¨åä½ä¸»ç®¡å®¤çº§é¢å¯¼"); |
| | | request.setComment("ææ¯ç¶æé´å®å·¥ååæ´ä½¿ç¨åä½ä¸»ç®¡å®¤çº§é¢å¯¼"); |
| | | } else { |
| | | values.put("organization", request.getEquipmentManagerComment()); |
| | | values.put("comment", request.getEquipmentManagerComment()); |
| | | request.setComment(request.getEquipmentManagerComment()); |
| | | } |
| | | |
| | | //设置entity |
| | | entity.setEquipmentManagerSignature(user.getUsername()); |
| | | entity.setEquipmentManagerSignatureTime(new Date()); |
| | | entity.setEquipmentManagerComment(request.getEquipmentManagerComment()); |
| | | entity.setEquipmentManagerSignatureResult(request.getEquipmentManagerSignatureResult()); |
| | | values.put("departHeaderConfirmFlag", request.getEquipmentManagerSignatureResult()); |
| | | if(BusinessCodeConst.APPROVED.equals(request.getEquipmentManagerSignatureResult())) { |
| | | //éè¿ |
| | | entity.setChangeStatus(TechnicalStatusEvaluationOrderChangeStatusEnum.DEPART_MANAGER_SIGNING.name()); |
| | | values.put("NextAssignee", userApprovalList); |
| | | }else { |
| | | //驳å |
| | | entity.setChangeStatus(TechnicalStatusEvaluationOrderChangeStatusEnum.REJECTED.name()); |
| | | } |
| | | break; |
| | | case DEPART_MANAGER_SIGNING: |
| | | //é¨é¨é¢å¯¼å®¡æ ¸ |
| | | userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0017); |
| | | if (CollectionUtil.isEmpty(userSelectors)) { |
| | | throw new JeecgBootException("è®¾å¤æªåé
ç»è¿ç»´ç®¡çå®¤å®¤ä¸»ä»»ï¼æ æ³è¿å
¥ä¸çº§å®¡æ¹ï¼"); |
| | | } |
| | | userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList()); |
| | | values.put("dataId", entity.getId()); |
| | | if(StringUtils.isBlank(request.getDepartManagerComment())) { |
| | | values.put("organization", "ææ¯ç¶æé´å®å·¥ååæ´é¨é¨é¢å¯¼å®¡æ ¸"); |
| | | values.put("comment", "ææ¯ç¶æé´å®å·¥ååæ´é¨é¨é¢å¯¼å®¡æ ¸"); |
| | | request.setComment("ææ¯ç¶æé´å®å·¥ååæ´é¨é¨é¢å¯¼å®¡æ ¸"); |
| | | } else { |
| | | values.put("organization", request.getDepartManagerComment()); |
| | | values.put("comment", request.getDepartManagerComment()); |
| | | request.setComment(request.getDepartManagerComment()); |
| | | } |
| | | //设置entity |
| | | entity.setDepartManagerSignature(user.getUsername()); |
| | | entity.setDepartManagerSignatureTime(new Date()); |
| | | entity.setDepartManagerSignatureResult(request.getDepartManagerSignatureResult()); |
| | | entity.setDepartManagerComment(request.getDepartManagerComment()); |
| | | if(BusinessCodeConst.APPROVED.equals(request.getDepartManagerSignatureResult())) { |
| | | //éè¿ |
| | | entity.setChangeStatus(TechnicalStatusEvaluationOrderChangeStatusEnum.PRODUCTION_SUPPORT_SIGNING.name()); |
| | | values.put("NextAssignee", userApprovalList); |
| | | }else { |
| | | //驳å |
| | | entity.setChangeStatus(TechnicalStatusEvaluationOrderChangeStatusEnum.REJECTED.name()); |
| | | } |
| | | break; |
| | | case PRODUCTION_SUPPORT_SIGNING: |
| | | //维修室主任ç¾å |
| | | values.put("dataId", entity.getId()); |
| | | if(StringUtils.isBlank(request.getProductionSupportComment())) { |
| | | values.put("organization", "ææ¯ç¶æé´å®å·¥ååæ´ç产ä¿éé¨å®¡æ ¸"); |
| | | values.put("comment", "ææ¯ç¶æé´å®å·¥ååæ´ç产ä¿éé¨å®¡æ ¸"); |
| | | request.setComment("ææ¯ç¶æé´å®å·¥ååæ´ç产ä¿éé¨å®¡æ ¸"); |
| | | } else { |
| | | values.put("organization", request.getProductionSupportComment()); |
| | | values.put("comment", request.getProductionSupportComment()); |
| | | request.setComment(request.getProductionSupportComment()); |
| | | } |
| | | //设置entity |
| | | entity.setProductionSupportSignature(user.getUsername()); |
| | | entity.setProductionSupportSignatureTime(new Date()); |
| | | entity.setProductionSupportSignatureResult(request.getProductionSupportSignatureResult()); |
| | | entity.setProductionSupportComment(request.getProductionSupportComment()); |
| | | if(BusinessCodeConst.APPROVED.equals(request.getProductionSupportSignatureResult())) { |
| | | //éè¿ |
| | | entity.setChangeStatus(TechnicalStatusEvaluationOrderChangeStatusEnum.COMPLETED.name()); |
| | | order.setEvaluationStatus(TechnicalStatusEvaluationOrderStatusEnum.WAIT_EVALUATION.name()); |
| | | order.setEvaluationDate(entity.getDeferredEvaluationDate()); |
| | | evaluationOrderService.updateById(order); |
| | | }else { |
| | | //驳å |
| | | entity.setChangeStatus(TechnicalStatusEvaluationOrderChangeStatusEnum.REJECTED.name()); |
| | | } |
| | | break; |
| | | } |
| | | request.setValues(values); |
| | | |
| | | // 宿æµç¨ä»»å¡ |
| | | Result<?> result = flowTaskService.complete(request); |
| | | if (!result.isSuccess()) { |
| | | throw new JeecgBootException("审æ¹å¤±è´¥ï¼è¯·å·æ°æ¥çï¼"); |
| | | } |
| | | //ä¿åå·¥å |
| | | this.getBaseMapper().updateById(entity); |
| | | return entity; |
| | | } |
| | | |
| | | @Override |
| | | public void afterFlowHandle(FlowMyBusiness business) { |
| | | business.getTaskNameId();//æ¥ä¸æ¥å®¡æ¹çèç¹ |
| | | business.getValues();//åç«¯ä¼ è¿æ¥çåæ° |