| | |
| | | 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.dal.dataobject.definition.BpmCategoryDO; |
| | | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO; |
| | | import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum; |
| | | import cn.iocoder.yudao.module.bpm.service.definition.BpmCategoryService; |
| | | import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService; |
| | | import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.order.ErpPurchaseOrderPageReqVO; |
| | | import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.order.ErpPurchaseOrderSaveReqVO; |
| | | import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; |
| | | import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseOrderDO; |
| | | import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseOrderItemDO; |
| | | import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseRequestDO; |
| | | import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseRequestItemDO; |
| | | import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseOrderItemMapper; |
| | | import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseOrderMapper; |
| | | import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseRequestItemMapper; |
| | | import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseRequestMapper; |
| | | import cn.iocoder.yudao.module.erp.dal.redis.no.ErpNoRedisDAO; |
| | | import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus; |
| | | import cn.iocoder.yudao.module.erp.enums.ErpPurchaseOrderInStatusEnum; |
| | | import cn.iocoder.yudao.module.erp.service.finance.ErpAccountService; |
| | | import cn.iocoder.yudao.module.erp.service.product.ErpProductService; |
| | | import cn.iocoder.yudao.module.mes.api.arrivalnotice.MesArrivalNoticeApi; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.flowable.engine.repository.ProcessDefinition; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| | |
| | | public class ErpPurchaseOrderServiceImpl implements ErpPurchaseOrderService { |
| | | |
| | | /** |
| | | * BPM 采购订单审批流程标识 |
| | | * BPM 采购订单审批分类编码 |
| | | */ |
| | | public static final String BPM_PROCESS_DEFINITION_KEY = "erp-purchase-order-audit"; |
| | | private static final String PURCHASE_ORDER_APPROVE_CATEGORY_CODE = "purchase_request_approve"; |
| | | |
| | | @Resource |
| | | private ErpPurchaseOrderMapper purchaseOrderMapper; |
| | |
| | | private ErpNoRedisDAO noRedisDAO; |
| | | |
| | | @Resource |
| | | private ErpProductService productService; |
| | | @Resource |
| | | private ErpSupplierService supplierService; |
| | | @Resource |
| | | private ErpAccountService accountService; |
| | | |
| | | @Resource |
| | | private BpmProcessInstanceApi bpmProcessInstanceApi; |
| | | private BpmProcessInstanceApi processInstanceApi; |
| | | @Resource |
| | | private BpmCategoryService bpmCategoryService; |
| | | @Resource |
| | | private BpmProcessDefinitionService bpmProcessDefinitionService; |
| | | |
| | | @Resource |
| | | @Lazy |
| | | private MesArrivalNoticeApi arrivalNoticeApi; |
| | | |
| | | @Resource |
| | | private ErpPurchaseRequestItemMapper purchaseRequestItemMapper; |
| | | @Resource |
| | | private ErpPurchaseRequestMapper purchaseRequestMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | throw exception(PURCHASE_ORDER_NO_EXISTS); |
| | | } |
| | | |
| | | // 2.1 插入订单 |
| | | // 2.1 插入订单(采购订单创建后为未审核状态,需要提交审批) |
| | | ErpPurchaseOrderDO purchaseOrder = BeanUtils.toBean(createReqVO, ErpPurchaseOrderDO.class, in -> in |
| | | .setNo(no).setStatus(ErpAuditStatus.DRAFT.getStatus())); |
| | | .setNo(no).setStatus(ErpAuditStatus.PROCESS.getStatus()) |
| | | .setInCount(BigDecimal.ZERO).setInStatus(ErpPurchaseOrderInStatusEnum.NOT_IN.getStatus())); |
| | | calculateTotalPrice(purchaseOrder, purchaseOrderItems); |
| | | purchaseOrderMapper.insert(purchaseOrder); |
| | | // 2.2 插入订单项 |
| | |
| | | public void updatePurchaseOrder(ErpPurchaseOrderSaveReqVO updateReqVO) { |
| | | // 1.1 校验存在 |
| | | ErpPurchaseOrderDO purchaseOrder = validatePurchaseOrderExists(updateReqVO.getId()); |
| | | // 采购订单不允许修改(已审核状态) |
| | | if (ErpAuditStatus.APPROVE.getStatus().equals(purchaseOrder.getStatus())) { |
| | | throw exception(PURCHASE_ORDER_UPDATE_FAIL_APPROVE, purchaseOrder.getNo()); |
| | | } |
| | |
| | | if (purchaseOrder.getStatus().equals(status)) { |
| | | throw exception(approve ? PURCHASE_ORDER_APPROVE_FAIL : PURCHASE_ORDER_PROCESS_FAIL); |
| | | } |
| | | // 1.3 存在采购入单,无法反审核 |
| | | if (!approve && purchaseOrder.getInCount().compareTo(BigDecimal.ZERO) > 0) { |
| | | // 1.3 存在采购入库单,无法反审核 |
| | | BigDecimal inCount = purchaseOrder.getInCount(); |
| | | if (!approve && inCount != null && inCount.compareTo(BigDecimal.ZERO) > 0) { |
| | | throw exception(PURCHASE_ORDER_PROCESS_FAIL_EXISTS_IN); |
| | | } |
| | | // 1.4 存在采购退货单,无法反审核 |
| | | if (!approve && purchaseOrder.getReturnCount().compareTo(BigDecimal.ZERO) > 0) { |
| | | BigDecimal returnCount = purchaseOrder.getReturnCount(); |
| | | if (!approve && returnCount != null && returnCount.compareTo(BigDecimal.ZERO) > 0) { |
| | | throw exception(PURCHASE_ORDER_PROCESS_FAIL_EXISTS_RETURN); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void submitPurchaseOrder(Long id, String processDefinitionKey, Long userId) { |
| | | // 1. 校验存在 + 未审核状态 |
| | | ErpPurchaseOrderDO purchaseOrder = validatePurchaseOrderExists(id); |
| | | if (!ErpAuditStatus.PROCESS.getStatus().equals(purchaseOrder.getStatus())) { |
| | | throw exception(PURCHASE_ORDER_SUBMIT_FAIL_STATUS); |
| | | } |
| | | |
| | | // 2. 创建 BPM 流程实例 |
| | | String processInstanceId = processInstanceApi.createProcessInstance(userId, |
| | | new BpmProcessInstanceCreateReqDTO() |
| | | .setProcessDefinitionKey(processDefinitionKey) |
| | | .setBusinessKey(String.valueOf(id))); |
| | | |
| | | // 3. 更新采购订单状态为审批中 |
| | | purchaseOrderMapper.updateById(new ErpPurchaseOrderDO() |
| | | .setId(id) |
| | | .setStatus(ErpAuditStatus.APPROVING.getStatus()) |
| | | .setProcessInstanceId(processInstanceId)); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getPurchaseOrderApproveProcessDefinitionList() { |
| | | // 1. 校验分类和流程定义是否存在 |
| | | validatePurchaseOrderApproveCategoryAndProcessDefinition(); |
| | | |
| | | // 2. 获取分类下的流程定义信息 |
| | | List<BpmProcessDefinitionInfoDO> definitionInfoList = bpmProcessDefinitionService |
| | | .getProcessDefinitionInfoListByCategory(PURCHASE_ORDER_APPROVE_CATEGORY_CODE); |
| | | if (CollUtil.isEmpty(definitionInfoList)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | // 3. 遍历获取流程定义详情,过滤激活状态,保留最新版本 |
| | | Map<String, ProcessDefinition> latestVersionMap = new HashMap<>(); |
| | | for (BpmProcessDefinitionInfoDO info : definitionInfoList) { |
| | | ProcessDefinition pd = bpmProcessDefinitionService.getProcessDefinition(info.getProcessDefinitionId()); |
| | | if (pd == null || pd.isSuspended()) { |
| | | continue; |
| | | } |
| | | ProcessDefinition existing = latestVersionMap.get(pd.getKey()); |
| | | if (existing == null || pd.getVersion() > existing.getVersion()) { |
| | | latestVersionMap.put(pd.getKey(), pd); |
| | | } |
| | | } |
| | | |
| | | // 4. 返回流程定义列表 |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (ProcessDefinition pd : latestVersionMap.values()) { |
| | | Map<String, Object> item = new HashMap<>(); |
| | | item.put("id", pd.getId()); |
| | | item.put("key", pd.getKey()); |
| | | item.put("name", pd.getName()); |
| | | result.add(item); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updatePurchaseOrderAuditStatus(Long id, Integer bpmResult) { |
| | | // 1. 校验存在 |
| | | ErpPurchaseOrderDO purchaseOrder = validatePurchaseOrderExists(id); |
| | | if (!ErpAuditStatus.APPROVING.getStatus().equals(purchaseOrder.getStatus())) { |
| | | log.warn("[updatePurchaseOrderAuditStatus] 采购订单({}) 不处于审批中状态", id); |
| | | return; |
| | | } |
| | | |
| | | // 2. 根据审批结果更新状态 |
| | | Integer newStatus = convertBpmResultToAuditStatus(bpmResult); |
| | | if (newStatus != null) { |
| | | purchaseOrderMapper.updateById(new ErpPurchaseOrderDO() |
| | | .setId(id).setStatus(newStatus)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 校验采购订单审批分类和流程定义是否存在 |
| | | */ |
| | | private void validatePurchaseOrderApproveCategoryAndProcessDefinition() { |
| | | // 1. 校验分类是否存在 |
| | | List<BpmCategoryDO> categories = bpmCategoryService.getCategoryListByCode( |
| | | Collections.singletonList(PURCHASE_ORDER_APPROVE_CATEGORY_CODE)); |
| | | if (CollUtil.isEmpty(categories)) { |
| | | throw exception(PURCHASE_ORDER_BPM_CATEGORY_NOT_EXISTS); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转换 BPM 审批结果为审核状态 |
| | | */ |
| | | private Integer convertBpmResultToAuditStatus(Integer bpmResult) { |
| | | if (BpmTaskStatusEnum.APPROVE.getStatus().equals(bpmResult)) { |
| | | return ErpAuditStatus.APPROVE.getStatus(); |
| | | } else if (BpmTaskStatusEnum.REJECT.getStatus().equals(bpmResult)) { |
| | | return ErpAuditStatus.PROCESS.getStatus(); |
| | | } else if (BpmTaskStatusEnum.CANCEL.getStatus().equals(bpmResult)) { |
| | | return ErpAuditStatus.CANCEL.getStatus(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private List<ErpPurchaseOrderItemDO> validatePurchaseOrderItems(List<ErpPurchaseOrderSaveReqVO.Item> list) { |
| | | // 1. 校验产品存在 |
| | | List<ErpProductDO> productList = productService.validProductList( |
| | | convertSet(list, ErpPurchaseOrderSaveReqVO.Item::getProductId)); |
| | | Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId); |
| | | // 2. 转化为 ErpPurchaseOrderItemDO 列表 |
| | | // 转化为 ErpPurchaseOrderItemDO 列表(产品验证已移除) |
| | | return convertList(list, o -> BeanUtils.toBean(o, ErpPurchaseOrderItemDO.class, item -> { |
| | | item.setProductUnitId(productMap.get(item.getProductId()).getUnitId()); |
| | | item.setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount())); |
| | | if (item.getTotalPrice() == null) { |
| | | return; |
| | |
| | | private void updatePurchaseOrderItemList(Long id, List<ErpPurchaseOrderItemDO> newList) { |
| | | // 第一步,对比新老数据,获得添加、修改、删除的列表 |
| | | List<ErpPurchaseOrderItemDO> oldList = purchaseOrderItemMapper.selectListByOrderId(id); |
| | | List<List<ErpPurchaseOrderItemDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录 |
| | | List<List<ErpPurchaseOrderItemDO>> diffList = diffList(oldList, newList, |
| | | (oldVal, newVal) -> oldVal.getId().equals(newVal.getId())); |
| | | |
| | | // 第二步,批量添加、修改、删除 |
| | |
| | | } |
| | | if (inCount.compareTo(item.getCount()) > 0) { |
| | | throw exception(PURCHASE_ORDER_ITEM_IN_FAIL_PRODUCT_EXCEED, |
| | | productService.getProduct(item.getProductId()).getName(), item.getCount()); |
| | | "产品ID:" + item.getProductId(), item.getCount()); |
| | | } |
| | | purchaseOrderItemMapper.updateById(new ErpPurchaseOrderItemDO().setId(item.getId()).setInCount(inCount)); |
| | | }); |
| | |
| | | } |
| | | if (returnCount.compareTo(item.getInCount()) > 0) { |
| | | throw exception(PURCHASE_ORDER_ITEM_RETURN_FAIL_IN_EXCEED, |
| | | productService.getProduct(item.getProductId()).getName(), item.getInCount()); |
| | | "产品ID:" + item.getProductId(), item.getInCount()); |
| | | } |
| | | purchaseOrderItemMapper.updateById(new ErpPurchaseOrderItemDO().setId(item.getId()).setReturnCount(returnCount)); |
| | | }); |
| | |
| | | } |
| | | }); |
| | | |
| | | // 2. 遍历删除,并记录操作日志 |
| | | // 2. 遍历删除 |
| | | purchaseOrders.forEach(purchaseOrder -> { |
| | | // 2.1 删除订单 |
| | | purchaseOrderMapper.deleteById(purchaseOrder.getId()); |
| | | // 2.2 删除订单项 |
| | | purchaseOrderItemMapper.deleteByOrderId(purchaseOrder.getId()); |
| | | }); |
| | | } |
| | |
| | | return purchaseOrderItemMapper.selectListByOrderIds(orderIds); |
| | | } |
| | | |
| | | // ==================== BPM 流程审批 ==================== |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void submitPurchaseOrder(Long id, Long userId) { |
| | | // 1. 校验采购订单处于草稿状态 |
| | | ErpPurchaseOrderDO purchaseOrder = validatePurchaseOrderExists(id); |
| | | if (ObjectUtil.notEqual(purchaseOrder.getStatus(), ErpAuditStatus.DRAFT.getStatus())) { |
| | | throw exception(PURCHASE_ORDER_SUBMIT_FAIL_NOT_DRAFT); |
| | | public List<ErpPurchaseOrderDO> getPurchaseOrderListBySupplierIdAndStatus(Long supplierId, Integer status) { |
| | | if (supplierId == null) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | // 2. 创建采购订单审批流程实例 |
| | | String processInstanceId = bpmProcessInstanceApi.createProcessInstance(userId, new BpmProcessInstanceCreateReqDTO() |
| | | .setProcessDefinitionKey(BPM_PROCESS_DEFINITION_KEY) |
| | | .setBusinessKey(String.valueOf(id))); |
| | | |
| | | // 3. 更新采购订单工作流编号、状态 |
| | | purchaseOrderMapper.updateById(new ErpPurchaseOrderDO() |
| | | .setId(id) |
| | | .setProcessInstanceId(processInstanceId) |
| | | .setStatus(ErpAuditStatus.PROCESS.getStatus())); |
| | | return purchaseOrderMapper.selectList(supplierId, status); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updatePurchaseOrderAuditStatus(Long id, Integer bpmResult) { |
| | | // 1. 校验采购订单存在 |
| | | ErpPurchaseOrderDO purchaseOrder = validatePurchaseOrderExists(id); |
| | | |
| | | // 2. 校验采购订单处于审批中 |
| | | if (ObjectUtil.notEqual(purchaseOrder.getStatus(), ErpAuditStatus.PROCESS.getStatus())) { |
| | | log.error("[updatePurchaseOrderAuditStatus][purchaseOrder({}) 不处于审批中,无法更新审批结果({})]", |
| | | purchaseOrder.getId(), bpmResult); |
| | | throw exception(PURCHASE_ORDER_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS); |
| | | public List<ErpPurchaseOrderDO> getPurchaseOrderList(List<Long> ids) { |
| | | if (CollUtil.isEmpty(ids)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return purchaseOrderMapper.selectByIds(ids); |
| | | } |
| | | |
| | | // 3. 更新采购订单审批结果 |
| | | Integer auditStatus = convertBpmResultToAuditStatus(bpmResult); |
| | | @Override |
| | | public void updatePurchaseOrderInStatus(Long orderId) { |
| | | // 1. 获取采购订单 |
| | | ErpPurchaseOrderDO order = validatePurchaseOrderExists(orderId); |
| | | // 2. 获取采购订单明细 |
| | | List<ErpPurchaseOrderItemDO> items = purchaseOrderItemMapper.selectListByOrderId(orderId); |
| | | if (CollUtil.isEmpty(items)) { |
| | | return; |
| | | } |
| | | // 3. 计算入库状态 |
| | | int inStatus = calculateInStatus(items); |
| | | // 4. 更新采购订单入库状态 |
| | | purchaseOrderMapper.updateById(new ErpPurchaseOrderDO() |
| | | .setId(id) |
| | | .setStatus(auditStatus)); |
| | | .setId(orderId).setInStatus(inStatus)); |
| | | |
| | | // 5. 回写采购申请明细的入库数量和采购申请的入库状态 |
| | | updatePurchaseRequestInStatus(items, inStatus); |
| | | } |
| | | |
| | | /** |
| | | * 将 BPM 审批结果转换为 ERP 审批状态 |
| | | * 回写采购申请入库数量和入库状态 |
| | | * |
| | | * @param bpmResult BPM 审批结果 |
| | | * @return ERP 审批状态 |
| | | * @param orderItems 采购订单明细列表 |
| | | * @param orderInStatus 采购订单入库状态 |
| | | */ |
| | | private Integer convertBpmResultToAuditStatus(Integer bpmResult) { |
| | | // BPM 审批结果:2=通过,3=不通过,4=已取消 |
| | | if (bpmResult == 2) { |
| | | return ErpAuditStatus.APPROVE.getStatus(); |
| | | } else if (bpmResult == 3) { |
| | | return ErpAuditStatus.REJECT.getStatus(); |
| | | } else if (bpmResult == 4) { |
| | | return ErpAuditStatus.DRAFT.getStatus(); |
| | | } else { |
| | | log.warn("[convertBpmResultToAuditStatus][未知的 BPM 审批结果({})]", bpmResult); |
| | | return ErpAuditStatus.PROCESS.getStatus(); |
| | | private void updatePurchaseRequestInStatus(List<ErpPurchaseOrderItemDO> orderItems, int orderInStatus) { |
| | | // 获取所有关联的采购申请明细 ID |
| | | Set<Long> requestItemIds = new HashSet<>(); |
| | | for (ErpPurchaseOrderItemDO item : orderItems) { |
| | | if (item.getRequestItemId() != null) { |
| | | requestItemIds.add(item.getRequestItemId()); |
| | | } |
| | | } |
| | | if (requestItemIds.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | // 更新采购申请明细的入库数量 |
| | | for (ErpPurchaseOrderItemDO orderItem : orderItems) { |
| | | if (orderItem.getRequestItemId() != null && orderItem.getInCount() != null) { |
| | | purchaseRequestItemMapper.updateById(new ErpPurchaseRequestItemDO() |
| | | .setId(orderItem.getRequestItemId()) |
| | | .setInCount(orderItem.getInCount())); |
| | | } |
| | | } |
| | | |
| | | // 获取采购申请明细,找到对应的采购申请 ID |
| | | List<ErpPurchaseRequestItemDO> requestItems = purchaseRequestItemMapper.selectBatchIds(requestItemIds); |
| | | if (CollUtil.isEmpty(requestItems)) { |
| | | return; |
| | | } |
| | | Set<Long> requestIds = convertSet(requestItems, ErpPurchaseRequestItemDO::getRequestId); |
| | | |
| | | // 更新采购申请的入库状态 |
| | | for (Long requestId : requestIds) { |
| | | purchaseRequestMapper.updateById(new ErpPurchaseRequestDO() |
| | | .setId(requestId) |
| | | .setInStatus(orderInStatus)); |
| | | } |
| | | } |
| | | |
| | | } |
| | | /** |
| | | * 计算入库状态 |
| | | * |
| | | * @param items 采购订单明细列表 |
| | | * @return 入库状态 |
| | | */ |
| | | private int calculateInStatus(List<ErpPurchaseOrderItemDO> items) { |
| | | boolean allIn = true; |
| | | boolean anyIn = false; |
| | | |
| | | for (ErpPurchaseOrderItemDO item : items) { |
| | | BigDecimal count = item.getCount() != null ? item.getCount() : BigDecimal.ZERO; |
| | | BigDecimal inCount = item.getInCount() != null ? item.getInCount() : BigDecimal.ZERO; |
| | | |
| | | if (inCount.compareTo(BigDecimal.ZERO) > 0) { |
| | | anyIn = true; |
| | | } |
| | | if (inCount.compareTo(count) < 0) { |
| | | allIn = false; |
| | | } |
| | | } |
| | | |
| | | if (allIn) { |
| | | return ErpPurchaseOrderInStatusEnum.ALL_IN.getStatus(); |
| | | } else if (anyIn) { |
| | | return ErpPurchaseOrderInStatusEnum.PART_IN.getStatus(); |
| | | } else { |
| | | return ErpPurchaseOrderInStatusEnum.NOT_IN.getStatus(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long confirmReceipt(Long id) { |
| | | // 1. 校验采购订单存在且已审核 |
| | | ErpPurchaseOrderDO purchaseOrder = validatePurchaseOrder(id); |
| | | |
| | | // 2. 校验采购订单未全部入库 |
| | | if (ErpPurchaseOrderInStatusEnum.ALL_IN.getStatus().equals(purchaseOrder.getInStatus())) { |
| | | throw exception(PURCHASE_ORDER_ALL_IN); |
| | | } |
| | | |
| | | // 3. 调用 MES 接口生成到货通知单 |
| | | Long arrivalNoticeId = arrivalNoticeApi.generateArrivalNoticeFromPurchaseOrder(id); |
| | | log.info("[confirmReceipt] 采购订单({}) 确认收货,生成到货通知单({})", id, arrivalNoticeId); |
| | | |
| | | return arrivalNoticeId; |
| | | } |
| | | |
| | | } |