| | |
| | | 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.miscreceipt.vo.MesWmMiscReceiptImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.miscreceipt.vo.MesWmMiscReceiptImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.miscreceipt.vo.MesWmMiscReceiptPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.miscreceipt.vo.MesWmMiscReceiptSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.miscreceipt.MesWmMiscReceiptDO; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | 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 MISC_RECEIPT_APPROVE_BIZ_TYPE = "misc_receipt_approve"; |
| | | |
| | | /** |
| | | * 杂项入库单审批的 BPM 流程定义 Key |
| | | */ |
| | | private static final String MISC_RECEIPT_APPROVE_PROCESS_KEY = "misc_receipt_approve"; |
| | | |
| | | @Resource |
| | | private MesWmMiscReceiptMapper miscReceiptMapper; |
| | | |
| | | @Resource |
| | | private BpmProcessInstanceApi bpmProcessInstanceApi; |
| | | |
| | | @Resource |
| | | @Lazy |
| | |
| | | approvalConfigApi.validateApprovalEnabledAndGetApprovers(MISC_RECEIPT_APPROVE_BIZ_TYPE); |
| | | // 4. 提交审批(草稿 → 审批中),并清空上一轮审核结果 |
| | | miscReceiptMapper.submitAndResetAuditInfo(id, MesWmMiscReceiptStatusEnum.APPROVING.getStatus()); |
| | | // 5. 创建 BPM 流程实例,使审批出现在「协同办公 - 我的流程」 |
| | | bpmProcessInstanceApi.createProcessInstance(getLoginUserId(), |
| | | new BpmProcessInstanceCreateReqDTO() |
| | | .setProcessDefinitionKey(MISC_RECEIPT_APPROVE_PROCESS_KEY) |
| | | .setBusinessKey(String.valueOf(id))); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateMiscReceiptAuditStatus(Long id, Integer bpmStatus, String reason) { |
| | | // BPM 审批结果映射为单据状态:通过=已审批 / 不通过=草稿 / 取消=已取消 |
| | | Integer status; |
| | | if (BpmTaskStatusEnum.APPROVE.getStatus().equals(bpmStatus)) { |
| | | status = MesWmMiscReceiptStatusEnum.APPROVED.getStatus(); |
| | | } else if (BpmTaskStatusEnum.REJECT.getStatus().equals(bpmStatus)) { |
| | | status = MesWmMiscReceiptStatusEnum.PREPARE.getStatus(); |
| | | } else if (BpmTaskStatusEnum.CANCEL.getStatus().equals(bpmStatus)) { |
| | | status = MesWmMiscReceiptStatusEnum.CANCELED.getStatus(); |
| | | } else { |
| | | return; |
| | | } |
| | | if (miscReceiptMapper.updateAuditStatusByBpm(id, status, reason) != 1) { |
| | | log.warn("[updateMiscReceiptAuditStatus] 杂项入库单({}) 不处于审批中状态,忽略 BPM 结果({})", id, bpmStatus); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | wmTransactionService.createTransactionList(convertList(lines, line -> new MesWmTransactionSaveReqDTO() |
| | | .setType(MesWmTransactionTypeEnum.IN.getType()).setItemId(line.getItemId()) |
| | | .setQuantity(line.getQuantity()) // 入库数量为正数 |
| | | .setBatchCode(line.getBatchCode()) // 批次管理物料需携带批次号 |
| | | .setWarehouseId(line.getWarehouseId()).setLocationId(line.getLocationId()).setAreaId(line.getAreaId()) |
| | | .setBizType(MesBizTypeConstants.WM_MISC_RECPT).setBizId(receipt.getId()).setBizCode(receipt.getCode()).setBizLineId(line.getId()))); |
| | | } |
| | |
| | | validateMiscReceiptExistsAndPrepare(id); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public MesWmMiscReceiptImportRespVO importMiscReceiptList(List<MesWmMiscReceiptImportExcelVO> importList, boolean updateSupport) { |
| | | // 校验导入数据不能为空 |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(WM_MISC_RECEIPT_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesWmMiscReceiptImportRespVO respVO = MesWmMiscReceiptImportRespVO.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; |
| | | } |
| | | MesWmMiscReceiptDO existing = miscReceiptMapper.selectByCode(code); |
| | | if (existing != null && updateSupport) { |
| | | if (!MesWmMiscReceiptStatusEnum.PREPARE.getStatus().equals(existing.getStatus())) { |
| | | respVO.getFailureCodes().put(key, "单据非草稿状态,不允许覆盖更新"); |
| | | return; |
| | | } |
| | | MesWmMiscReceiptDO updateObj = BeanUtils.toBean(importItem, MesWmMiscReceiptDO.class); |
| | | updateObj.setId(existing.getId()); |
| | | updateObj.setStatus(existing.getStatus()); |
| | | miscReceiptMapper.updateById(updateObj); |
| | | respVO.getUpdateCodes().add(code); |
| | | } else if (existing != null) { |
| | | respVO.getFailureCodes().put(key, "单号已存在:" + code); |
| | | } else { |
| | | MesWmMiscReceiptDO createObj = BeanUtils.toBean(importItem, MesWmMiscReceiptDO.class); |
| | | createObj.setId(null); |
| | | createObj.setStatus(MesWmMiscReceiptStatusEnum.PREPARE.getStatus()); |
| | | miscReceiptMapper.insert(createObj); |
| | | respVO.getCreateCodes().add(code); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |