| | |
| | | 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.bpm.api.task.BpmProcessInstanceApi; |
| | | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; |
| | | import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.equipmentreceipt.vo.MesWmEquipmentReceiptImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.equipmentreceipt.vo.MesWmEquipmentReceiptImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.equipmentreceipt.vo.MesWmEquipmentReceiptPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.equipmentreceipt.vo.MesWmEquipmentReceiptSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.equipmentreceipt.MesWmEquipmentReceiptDO; |
| | |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| | |
| | | */ |
| | | private static final String EQUIPMENT_RECEIPT_APPROVE_BIZ_TYPE = "equipment_receipt_approve"; |
| | | |
| | | /** |
| | | * 设备入库单审批的 BPM 流程定义 Key |
| | | */ |
| | | private static final String EQUIPMENT_RECEIPT_APPROVE_PROCESS_KEY = "equipment_receipt_approve"; |
| | | |
| | | @Resource |
| | | private MesWmEquipmentReceiptMapper equipmentReceiptMapper; |
| | | |
| | | @Resource |
| | | private BpmProcessInstanceApi bpmProcessInstanceApi; |
| | | @Resource |
| | | @Lazy |
| | | private MesWmEquipmentReceiptLineService equipmentReceiptLineService; |
| | |
| | | approvalConfigApi.validateApprovalEnabledAndGetApprovers(EQUIPMENT_RECEIPT_APPROVE_BIZ_TYPE); |
| | | // 4. 状态置为审批中,并清空上一轮审核结果 |
| | | equipmentReceiptMapper.submitAndResetAuditInfo(id, MesWmEquipmentReceiptStatusEnum.APPROVING.getStatus()); |
| | | // 5. 创建 BPM 流程实例,使审批出现在「协同办公 - 我的流程」 |
| | | bpmProcessInstanceApi.createProcessInstance(getLoginUserId(), |
| | | new BpmProcessInstanceCreateReqDTO() |
| | | .setProcessDefinitionKey(EQUIPMENT_RECEIPT_APPROVE_PROCESS_KEY) |
| | | .setBusinessKey(String.valueOf(id))); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateEquipmentReceiptAuditStatus(Long id, Integer bpmStatus, String reason) { |
| | | // BPM 审批结果映射为单据状态:通过=已审批 / 不通过=草稿 / 取消=已取消 |
| | | Integer status; |
| | | if (BpmTaskStatusEnum.APPROVE.getStatus().equals(bpmStatus)) { |
| | | status = MesWmEquipmentReceiptStatusEnum.APPROVED.getStatus(); |
| | | } else if (BpmTaskStatusEnum.REJECT.getStatus().equals(bpmStatus)) { |
| | | status = MesWmEquipmentReceiptStatusEnum.PREPARE.getStatus(); |
| | | } else if (BpmTaskStatusEnum.CANCEL.getStatus().equals(bpmStatus)) { |
| | | status = MesWmEquipmentReceiptStatusEnum.CANCELED.getStatus(); |
| | | } else { |
| | | return; |
| | | } |
| | | if (equipmentReceiptMapper.updateAuditStatusByBpm(id, status, reason) != 1) { |
| | | log.warn("[updateEquipmentReceiptAuditStatus] 设备入库单({}) 不处于审批中状态,忽略 BPM 结果({})", id, bpmStatus); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | validateEquipmentReceiptExistsAndPrepare(id); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public MesWmEquipmentReceiptImportRespVO importEquipmentReceiptList(List<MesWmEquipmentReceiptImportExcelVO> importList, boolean updateSupport) { |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(WM_EQUIP_RECEIPT_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesWmEquipmentReceiptImportRespVO respVO = MesWmEquipmentReceiptImportRespVO.builder() |
| | | .createCodes(new ArrayList<>()).updateCodes(new ArrayList<>()) |
| | | .failureCodes(new LinkedHashMap<>()).build(); |
| | | AtomicInteger index = new AtomicInteger(1); |
| | | importList.forEach(importItem -> { |
| | | int currentIndex = index.getAndIncrement(); |
| | | String code = importItem.getCode(); |
| | | String key = StrUtil.blankToDefault(code, "第 " + currentIndex + " 行"); |
| | | if (StrUtil.isBlank(code)) { |
| | | respVO.getFailureCodes().put(key, "单号不能为空"); |
| | | return; |
| | | } |
| | | if (StrUtil.isBlank(importItem.getName())) { |
| | | respVO.getFailureCodes().put(key, "名称不能为空"); |
| | | return; |
| | | } |
| | | MesWmEquipmentReceiptDO existing = equipmentReceiptMapper.selectByCode(code); |
| | | if (existing != null && updateSupport) { |
| | | if (!MesWmEquipmentReceiptStatusEnum.PREPARE.getStatus().equals(existing.getStatus())) { |
| | | respVO.getFailureCodes().put(key, "单据非草稿状态,不允许覆盖更新"); |
| | | return; |
| | | } |
| | | MesWmEquipmentReceiptDO updateObj = BeanUtils.toBean(importItem, MesWmEquipmentReceiptDO.class); |
| | | updateObj.setId(existing.getId()); |
| | | updateObj.setStatus(existing.getStatus()); |
| | | equipmentReceiptMapper.updateById(updateObj); |
| | | respVO.getUpdateCodes().add(code); |
| | | } else if (existing != null) { |
| | | respVO.getFailureCodes().put(key, "单号已存在:" + code); |
| | | } else { |
| | | MesWmEquipmentReceiptDO createObj = BeanUtils.toBean(importItem, MesWmEquipmentReceiptDO.class); |
| | | createObj.setId(null); |
| | | createObj.setStatus(MesWmEquipmentReceiptStatusEnum.PREPARE.getStatus()); |
| | | equipmentReceiptMapper.insert(createObj); |
| | | respVO.getCreateCodes().add(code); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |