| | |
| | | import cn.iocoder.yudao.module.mes.api.mps.MesProMpsApi; |
| | | import cn.iocoder.yudao.module.mes.api.mps.dto.MesProMpsCreateReqDTO; |
| | | import cn.iocoder.yudao.module.mes.api.mps.dto.MesProMpsRespDTO; |
| | | import cn.iocoder.yudao.module.mes.api.salesnotice.MesWmSalesNoticeApi; |
| | | import cn.iocoder.yudao.module.system.api.storage.StorageAttachmentApi; |
| | | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| | | import com.mzt.logapi.starter.annotation.LogRecord; |
| | |
| | | private MdmItemApi mdmItemApi; |
| | | @Resource |
| | | private MesProMpsApi mpsApi; |
| | | @Resource |
| | | private MesWmSalesNoticeApi salesNoticeApi; |
| | | |
| | | @Resource |
| | | private StorageAttachmentApi storageAttachmentApi; |
| | |
| | | } |
| | | |
| | | // 4. 创建 BPM 流程实例(审批在协同办公完成) |
| | | // 全局免审批:业务校验通过后直接执行审批通过逻辑,无需流程模型。 |
| | | if (processInstanceApi.isGlobalAutoApprove()) { |
| | | saleOrderMapper.updateById(new ErpSaleOrderDO() |
| | | .setId(id) |
| | | .setStatus(ErpAuditStatus.APPROVING.getStatus()) |
| | | .setProcessInstanceId("")); |
| | | updateSaleOrderAuditStatus(id, cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum.APPROVE.getStatus()); |
| | | return; |
| | | } |
| | | |
| | | String processInstanceId = processInstanceApi.createProcessInstance(userId, |
| | | new BpmProcessInstanceCreateReqDTO() |
| | | .setProcessDefinitionKey(processDefinitionKey) |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void cancelSaleOrder(Long id) { |
| | | // 1.1 校验存在 |
| | | ErpSaleOrderDO saleOrder = validateSaleOrderExists(id); |
| | | ErpSaleOrderDO saleOrder = saleOrderMapper.selectByIdForUpdate(id); |
| | | if (saleOrder == null) throw exception(SALE_ORDER_NOT_EXISTS); |
| | | // 1.2 校验状态:只有已审核的订单才能作废 |
| | | if (!ErpAuditStatus.APPROVE.getStatus().equals(saleOrder.getStatus())) { |
| | | throw exception(SALE_ORDER_CANCEL_FAIL_NOT_APPROVE, saleOrder.getNo()); |
| | |
| | | if (outCount.compareTo(BigDecimal.ZERO) > 0) { |
| | | throw exception(SALE_ORDER_CANCEL_FAIL_EXISTS_OUT); |
| | | } |
| | | |
| | | // 销售订单审核后可能已生成 MPS。未取消的计划不能随着订单作废继续执行。 |
| | | List<ErpSaleOrderItemDO> orderItems = saleOrderItemMapper.selectListByOrderId(id); |
| | | if (CollUtil.isNotEmpty(orderItems)) { |
| | | List<Long> itemIds = convertList(orderItems, ErpSaleOrderItemDO::getId); |
| | | List<MesProMpsRespDTO> plans = mpsApi.getMpsListBySaleOrderItemIds(itemIds); |
| | | if (plans == null) throw exception(SALE_ORDER_CANCEL_FAIL_MPS_UNKNOWN); |
| | | if (plans.stream().anyMatch(plan -> plan == null || ObjectUtil.notEqual(plan.getStatus(), MPS_STATUS_CANCELED))) { |
| | | throw exception(SALE_ORDER_CANCEL_FAIL_ACTIVE_MPS); |
| | | } |
| | | } |
| | | Map<Long, Boolean> noticeStatus = salesNoticeApi.checkSalesNoticeBySaleOrderIds(List.of(id)); |
| | | if (noticeStatus == null || noticeStatus.get(id) == null) throw exception(SALE_ORDER_CANCEL_FAIL_NOTICE_UNKNOWN); |
| | | if (Boolean.TRUE.equals(noticeStatus.get(id))) throw exception(SALE_ORDER_CANCEL_FAIL_NOTICE_EXISTS); |
| | | |
| | | // 2. 更新状态为已作废 |
| | | int updateCount = saleOrderMapper.updateByIdAndStatus(id, saleOrder.getStatus(), |
| | |
| | | |
| | | @Override |
| | | public PageResult<ErpSaleOrderDO> getSaleOrderPage(ErpSaleOrderPageReqVO pageReqVO) { |
| | | List<Long> permittedCustomerIds = customerApi.getPermittedCustomerIds(); |
| | | return saleOrderMapper.selectPage(pageReqVO, permittedCustomerIds); |
| | | return saleOrderMapper.selectPage(pageReqVO); |
| | | } |
| | | |
| | | // ==================== 订单项 ==================== |