| | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.*; |
| | |
| | | */ |
| | | @Service |
| | | @Validated |
| | | @lombok.extern.slf4j.Slf4j |
| | | public class MesProFeedbackServiceImpl implements MesProFeedbackService { |
| | | |
| | | @Resource |
| | |
| | | private MesMdmItemService mdmItemService; |
| | | @Resource |
| | | private MdmItemBatchConfigApi itemBatchConfigApi; |
| | | @Resource |
| | | private cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi processInstanceApi; |
| | | |
| | | @Override |
| | | public Long createFeedback(MesProFeedbackSaveReqVO createReqVO) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void submitFeedback(Long id) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void submitFeedback(MesProFeedbackSubmitReqVO reqVO) { |
| | | Long id = reqVO.getId(); |
| | | // 1. 校验存在 + 草稿状态 |
| | | validateFeedbackStatusPrepare(id); |
| | | MesProFeedbackDO feedback = validateFeedbackStatusPrepare(id); |
| | | |
| | | // 2. 更新状态为审批中(报工人和报工时间由表单保存时确定,提交不覆盖) |
| | | feedbackMapper.updateById(new MesProFeedbackDO().setId(id) |
| | | .setStatus(MesProFeedbackStatusEnum.APPROVING.getStatus())); |
| | | MesProWorkOrderDO workOrder = workOrderService.getWorkOrder(feedback.getWorkOrderId()); |
| | | |
| | | if (workOrder != null && Boolean.TRUE.equals(workOrder.getFeedbackApprove()) && cn.hutool.core.util.StrUtil.isNotBlank(workOrder.getProcessDefinitionKey())) { |
| | | // 2. 更新状态为审批中,并启动流程 |
| | | String processInstanceId = processInstanceApi.createProcessInstance(cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId(), |
| | | new cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO() |
| | | .setProcessDefinitionKey(workOrder.getProcessDefinitionKey()) |
| | | .setBusinessKey(String.valueOf(id))); |
| | | |
| | | feedbackMapper.updateById(new MesProFeedbackDO().setId(id) |
| | | .setStatus(MesProFeedbackStatusEnum.APPROVING.getStatus()) |
| | | .setProcessDefinitionKey(workOrder.getProcessDefinitionKey()) |
| | | .setProcessInstanceId(processInstanceId)); |
| | | } else { |
| | | // 2. 判断这个报工需不需要批次号 |
| | | MesProFeedbackBatchCheckRespVO mesProFeedbackBatchCheckRespVO = checkBatchRequirements(id); |
| | | if (mesProFeedbackBatchCheckRespVO.getNeedBatchInput()) { |
| | | if (StrUtil.isBlank(reqVO.getLotNumber())) { |
| | | throw exception(MD_ITEM_BATCH_CONFIG_AT_LEAST_ONE_APPROVE_FLAG); |
| | | } |
| | | } |
| | | |
| | | // 3. 更新状态为审批中,然后直接通过审批 |
| | | feedbackMapper.updateById(new MesProFeedbackDO().setId(id) |
| | | .setStatus(MesProFeedbackStatusEnum.APPROVING.getStatus())); |
| | | MesProFeedbackApproveReqVO approveReqVO = cn.iocoder.yudao.framework.common.util.object.BeanUtils.toBean(reqVO, MesProFeedbackApproveReqVO.class); |
| | | approveFeedback(approveReqVO); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void handleBpmProcessResult(Long id, Integer bpmResult,String reason) { |
| | | // 1. 柔性校验:获取报工单并判断状态 |
| | | MesProFeedbackDO feedback = feedbackMapper.selectById(id); |
| | | if (feedback == null) { |
| | | log.warn("[handleBpmProcessResult] 生产报工({}) 不存在", id); |
| | | return; |
| | | } |
| | | if (!MesProFeedbackStatusEnum.APPROVING.getStatus().equals(feedback.getStatus())) { |
| | | log.warn("[handleBpmProcessResult] 生产报工({}) 不处于审批中状态,当前状态:{}", id, feedback.getStatus()); |
| | | return; |
| | | } |
| | | |
| | | // 2. 根据审批结果进行处理 |
| | | if (cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum.APPROVE.getStatus().equals(bpmResult)) { |
| | | MesProFeedbackApproveReqVO reqVO = new MesProFeedbackApproveReqVO(); |
| | | reqVO.setId(id); |
| | | // 判断这个报工需不需要批次号 |
| | | MesProFeedbackBatchCheckRespVO mesProFeedbackBatchCheckRespVO = checkBatchRequirements(id); |
| | | if (mesProFeedbackBatchCheckRespVO.getNeedBatchInput()){ |
| | | if (StrUtil.isBlank(reason)){ |
| | | // 报错 请在审批意见里填写批次号 |
| | | throw exception(MD_ITEM_BATCH_CONFIG_AT_LEAST_ONE_APPROVE_FLAG); |
| | | }else { |
| | | BeanUtils.copyProperties(mesProFeedbackBatchCheckRespVO,reqVO); |
| | | reqVO.setLotNumber(reason); |
| | | } |
| | | } |
| | | approveFeedback(reqVO); |
| | | } else if (cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum.REJECT.getStatus().equals(bpmResult) || |
| | | cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum.CANCEL.getStatus().equals(bpmResult)) { |
| | | rejectFeedback(id); |
| | | } |
| | | } |
| | | |
| | | @Override |