| | |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| | | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
| | | import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi; |
| | | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.returnvendor.vo.MesWmReturnVendorPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.returnvendor.vo.MesWmReturnVendorSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.returnvendor.vo.line.MesWmReturnVendorLineSaveReqVO; |
| | |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.returnvendor.MesWmReturnVendorLineDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.wm.returnvendor.MesWmReturnVendorMapper; |
| | | import cn.iocoder.yudao.module.mes.enums.MesBizTypeConstants; |
| | | import cn.iocoder.yudao.module.mes.enums.wm.MesWmReturnVendorHandleTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.wm.MesWmReturnVendorStatusEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.wm.MesWmTransactionTypeEnum; |
| | | import cn.iocoder.yudao.module.erp.api.finance.ErpFinancePaymentApi; |
| | | import cn.iocoder.yudao.module.erp.api.finance.dto.ErpFinancePaymentRedFlushCreateReqDTO; |
| | | import cn.iocoder.yudao.module.erp.api.purchase.ErpPurchaseOrderApi; |
| | | import cn.iocoder.yudao.module.erp.api.purchase.dto.ErpPurchaseOrderItemRespDTO; |
| | | import cn.iocoder.yudao.module.erp.api.purchase.dto.ErpPurchaseOrderRespDTO; |
| | | import cn.iocoder.yudao.module.srm.api.supplier.SrmSupplierApi; |
| | | import cn.iocoder.yudao.module.mes.service.wm.arrivalnotice.MesWmArrivalNoticeService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.transaction.MesWmTransactionService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.transaction.dto.MesWmTransactionSaveReqDTO; |
| | | import cn.iocoder.yudao.module.system.api.storage.StorageAttachmentApi; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | |
| | | */ |
| | | @Service |
| | | @Validated |
| | | @Slf4j |
| | | public class MesWmReturnVendorServiceImpl implements MesWmReturnVendorService { |
| | | |
| | | /** |
| | | * 附件业务类型:MES 供应商退货单 |
| | | */ |
| | | public static final String RETURN_VENDOR_RECORD_TYPE = "mes_wm_return_vendor"; |
| | | |
| | | @Resource |
| | | private MesWmReturnVendorMapper returnVendorMapper; |
| | |
| | | private MesWmTransactionService wmTransactionService; |
| | | @Resource |
| | | private ErpPurchaseOrderApi purchaseOrderApi; |
| | | @Resource |
| | | private ErpFinancePaymentApi financePaymentApi; |
| | | @Resource |
| | | private MesWmArrivalNoticeService arrivalNoticeService; |
| | | @Resource |
| | | private StorageAttachmentApi storageAttachmentApi; |
| | | @Resource |
| | | private BpmProcessInstanceApi processInstanceApi; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createReturnVendor(MesWmReturnVendorSaveReqVO createReqVO) { |
| | | // 1. 校验数据 |
| | | validateReturnVendorSaveData(createReqVO); |
| | | // 1.1. 若采购订单号为空但关联了采购订单,则从 ERP 采购订单补齐订单号 |
| | | fillPurchaseOrderCode(createReqVO); |
| | | // 1.1. 若采购订单号为空但关联了采购订单,则从 ERP 采购订单补齐订单号、合同号 |
| | | fillFromPurchaseOrder(createReqVO); |
| | | |
| | | // 2. 插入主表 |
| | | MesWmReturnVendorDO returnVendor = BeanUtils.toBean(createReqVO, MesWmReturnVendorDO.class); |
| | |
| | | if (returnVendor.getPurchaseOrderId() != null) { |
| | | autoImportLinesFromLinkedOrder(returnVendor.getId(), false); |
| | | } |
| | | // 2.2. 绑定附件(质量部发起退货时上传的检验报告、照片等) |
| | | storageAttachmentApi.bindAttachments("file", RETURN_VENDOR_RECORD_TYPE, |
| | | returnVendor.getId(), createReqVO.getBlobIds()); |
| | | return returnVendor.getId(); |
| | | } |
| | | |
| | |
| | | public void updateReturnVendor(MesWmReturnVendorSaveReqVO updateReqVO) { |
| | | // 1. 校验数据(含存在 + 草稿状态) |
| | | MesWmReturnVendorDO oldReturnVendor = validateReturnVendorSaveData(updateReqVO); |
| | | // 1.1. 若采购订单号为空但关联了采购订单,则从 ERP 采购订单补齐订单号 |
| | | fillPurchaseOrderCode(updateReqVO); |
| | | // 1.1. 若采购订单号为空但关联了采购订单,则从 ERP 采购订单补齐订单号、合同号 |
| | | fillFromPurchaseOrder(updateReqVO); |
| | | |
| | | Long oldPurchaseOrderId = oldReturnVendor != null ? oldReturnVendor.getPurchaseOrderId() : null; |
| | | Long newPurchaseOrderId = updateReqVO.getPurchaseOrderId(); |
| | |
| | | if (newPurchaseOrderId != null) { |
| | | autoImportLinesFromLinkedOrder(updateReqVO.getId(), purchaseOrderChanged); |
| | | } |
| | | |
| | | // 4. 增量更新附件(只处理新增/删除,未传 blobIds 时不动现有附件) |
| | | storageAttachmentApi.updateAttachments("file", RETURN_VENDOR_RECORD_TYPE, |
| | | updateReqVO.getId(), updateReqVO.getBlobIds()); |
| | | } |
| | | |
| | | /** |
| | | * 当采购订单号为空、但关联了采购订单时,从 ERP 采购订单补齐采购订单号 |
| | | * 关联了采购订单时,从 ERP 采购订单补齐采购订单号、合同号(合同号只做快照,不允许手工生成) |
| | | */ |
| | | private void fillPurchaseOrderCode(MesWmReturnVendorSaveReqVO reqVO) { |
| | | private void fillFromPurchaseOrder(MesWmReturnVendorSaveReqVO reqVO) { |
| | | if (reqVO == null || reqVO.getPurchaseOrderId() == null) { |
| | | return; |
| | | } |
| | | if (cn.hutool.core.util.StrUtil.isNotBlank(reqVO.getPurchaseOrderCode())) { |
| | | return; |
| | | } |
| | | ErpPurchaseOrderRespDTO purchaseOrder = |
| | | purchaseOrderApi.getPurchaseOrder(reqVO.getPurchaseOrderId()).getCheckedData(); |
| | | if (purchaseOrder != null) { |
| | | if (purchaseOrder == null) { |
| | | return; |
| | | } |
| | | if (StrUtil.isBlank(reqVO.getPurchaseOrderCode())) { |
| | | reqVO.setPurchaseOrderCode(purchaseOrder.getNo()); |
| | | } |
| | | if (StrUtil.isBlank(reqVO.getContractNo())) { |
| | | reqVO.setContractNo(purchaseOrder.getContractNo()); |
| | | } |
| | | } |
| | | |
| | |
| | | returnVendorDetailService.deleteReturnVendorDetailByReturnId(id); |
| | | // 2.2 级联删除行 |
| | | returnVendorLineService.deleteReturnVendorLineByReturnId(id); |
| | | // 2.3 删除主表 |
| | | // 2.3 删除附件 |
| | | storageAttachmentApi.deleteAttachmentsByRecord(RETURN_VENDOR_RECORD_TYPE, id); |
| | | // 2.4 删除主表 |
| | | returnVendorMapper.deleteById(id); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void submitReturnVendorApproval(Long id, String processDefinitionKey) { |
| | | // 1. 校验存在 + 草稿状态 + 至少一条行 |
| | | MesWmReturnVendorDO returnVendor = validateReturnVendorExistsAndPrepare(id); |
| | | if (CollUtil.isEmpty(returnVendorLineService.getReturnVendorLineListByReturnId(id))) { |
| | | throw exception(WM_RETURN_VENDOR_NO_LINE); |
| | | } |
| | | // 1.1. 质量部发起退货必须上传附件(质检报告、不合格照片等),否则审批人无法判断退货依据 |
| | | if (CollUtil.isEmpty(storageAttachmentApi.listAttachments(RETURN_VENDOR_RECORD_TYPE, id))) { |
| | | throw exception(WM_RETURN_VENDOR_ATTACHMENT_REQUIRED, returnVendor.getCode()); |
| | | } |
| | | |
| | | // 2. 全局免审批:直接置为「待拣货」,无需流程模型 |
| | | if (processInstanceApi.isGlobalAutoApprove()) { |
| | | returnVendorMapper.updateById(new MesWmReturnVendorDO() |
| | | .setId(id) |
| | | .setStatus(MesWmReturnVendorStatusEnum.APPROVING.getStatus()) |
| | | .setProcessDefinitionKey(processDefinitionKey) |
| | | .setProcessInstanceId("")); |
| | | return; |
| | | } |
| | | |
| | | // 3. 创建 BPM 流程实例;流程未发布时给出明确提示 |
| | | String processInstanceId; |
| | | try { |
| | | processInstanceId = processInstanceApi.createProcessInstance(getCurrentUserId(), |
| | | new BpmProcessInstanceCreateReqDTO() |
| | | .setProcessDefinitionKey(processDefinitionKey) |
| | | .setBusinessKey(String.valueOf(id))); |
| | | } catch (ServiceException ex) { |
| | | if (cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.PROCESS_DEFINITION_NOT_EXISTS |
| | | .getCode().equals(ex.getCode())) { |
| | | throw exception(WM_RETURN_VENDOR_APPROVE_PROCESS_NOT_PUBLISHED, processDefinitionKey); |
| | | } |
| | | throw ex; |
| | | } |
| | | |
| | | // 4. 更新退货单状态为审批中 |
| | | returnVendorMapper.updateById(new MesWmReturnVendorDO() |
| | | .setId(id) |
| | | .setStatus(MesWmReturnVendorStatusEnum.BPM_APPROVING.getStatus()) |
| | | .setProcessDefinitionKey(processDefinitionKey) |
| | | .setProcessInstanceId(processInstanceId)); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateReturnVendorAuditStatus(Long id, Integer bpmResult) { |
| | | // 1. 校验存在 + 审批中 |
| | | MesWmReturnVendorDO returnVendor = validateReturnVendorExists(id); |
| | | if (!MesWmReturnVendorStatusEnum.BPM_APPROVING.getStatus().equals(returnVendor.getStatus())) { |
| | | return; |
| | | } |
| | | |
| | | // 2. 根据审批结果更新状态:通过 -> 待拣货;驳回 -> 草稿;取消 -> 已取消 |
| | | Integer newStatus = convertBpmResultToReturnVendorStatus(bpmResult); |
| | | if (newStatus != null) { |
| | | returnVendorMapper.updateById(new MesWmReturnVendorDO().setId(id).setStatus(newStatus)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转换 BPM 审批结果为供应商退货单状态 |
| | | */ |
| | | private Integer convertBpmResultToReturnVendorStatus(Integer bpmResult) { |
| | | if (cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum.APPROVE.getStatus().equals(bpmResult)) { |
| | | return MesWmReturnVendorStatusEnum.APPROVING.getStatus(); |
| | | } |
| | | if (cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum.REJECT.getStatus().equals(bpmResult)) { |
| | | return MesWmReturnVendorStatusEnum.PREPARE.getStatus(); |
| | | } |
| | | if (cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum.CANCEL.getStatus().equals(bpmResult)) { |
| | | return MesWmReturnVendorStatusEnum.CANCELED.getStatus(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void stockReturnVendor(Long id) { |
| | | // 校验存在 |
| | | MesWmReturnVendorDO returnVendor = validateReturnVendorExists(id); |
| | |
| | | throw exception(WM_RETURN_VENDOR_NO_DETAIL); |
| | | } |
| | | |
| | | // 1.3 校验处理方式(退款 / 换货) |
| | | if (!MesWmReturnVendorHandleTypeEnum.isValid(returnVendor.getHandleType())) { |
| | | throw exception(WM_RETURN_VENDOR_HANDLE_TYPE_INVALID, returnVendor.getHandleType()); |
| | | } |
| | | |
| | | // 2. 遍历所有明细,创建库存事务(扣减库存 + 记录流水) |
| | | createTransactionList(returnVendor, details); |
| | | |
| | | // 3. 更新退货单状态 |
| | | // 3. 回写采购订单行的已退货数量(按物料匹配采购订单明细) |
| | | writeBackPurchaseOrderReturnCount(returnVendor); |
| | | |
| | | // 4. 先置为已完成,保证重复调用会被状态校验拦截(幂等) |
| | | returnVendorMapper.updateById(new MesWmReturnVendorDO() |
| | | .setId(id).setStatus(MesWmReturnVendorStatusEnum.FINISHED.getStatus())); |
| | | |
| | | // 5. 费用处理:退款 -> 负数冲红付款单;换货 -> 换货到货通知单(重新入库 + 重新质检) |
| | | if (MesWmReturnVendorHandleTypeEnum.REFUND.getType().equals(returnVendor.getHandleType())) { |
| | | createRedFlushPayment(id); |
| | | } else if (MesWmReturnVendorHandleTypeEnum.REPLACEMENT.getType().equals(returnVendor.getHandleType())) { |
| | | createReplacementNotice(id); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 把退货数量增量回写到关联采购订单的明细行,并同步订单级退货数量 |
| | | */ |
| | | private void writeBackPurchaseOrderReturnCount(MesWmReturnVendorDO returnVendor) { |
| | | if (returnVendor.getPurchaseOrderId() == null) { |
| | | return; |
| | | } |
| | | List<MesWmReturnVendorLineDO> lines = returnVendorLineService.getReturnVendorLineListByReturnId(returnVendor.getId()); |
| | | if (CollUtil.isEmpty(lines)) { |
| | | return; |
| | | } |
| | | List<ErpPurchaseOrderItemRespDTO> orderItems = purchaseOrderApi |
| | | .getPurchaseOrderItemList(returnVendor.getPurchaseOrderId()).getCheckedData(); |
| | | if (CollUtil.isEmpty(orderItems)) { |
| | | return; |
| | | } |
| | | Map<Long, Long> purchaseOrderItemIdMap = new HashMap<>(); |
| | | orderItems.stream() |
| | | .filter(item -> item.getProductId() != null) |
| | | .forEach(item -> purchaseOrderItemIdMap.putIfAbsent(item.getProductId(), item.getId())); |
| | | for (MesWmReturnVendorLineDO line : lines) { |
| | | Long purchaseOrderItemId = purchaseOrderItemIdMap.get(line.getItemId()); |
| | | if (purchaseOrderItemId == null || line.getQuantity() == null) { |
| | | continue; |
| | | } |
| | | purchaseOrderApi.updateOrderItemReturnCount(purchaseOrderItemId, line.getQuantity()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createRedFlushPayment(Long id) { |
| | | // 1. 校验存在 + 已完成 + 处理方式为退款 |
| | | MesWmReturnVendorDO returnVendor = validateReturnVendorFinished(id); |
| | | if (!MesWmReturnVendorHandleTypeEnum.REFUND.getType().equals(returnVendor.getHandleType())) { |
| | | throw exception(WM_RETURN_VENDOR_HANDLE_TYPE_INVALID, returnVendor.getHandleType()); |
| | | } |
| | | // 2. 幂等:已生成过冲红单直接返回 |
| | | if (returnVendor.getRedFlushPaymentId() != null) { |
| | | return returnVendor.getRedFlushPaymentId(); |
| | | } |
| | | // 3. 计算退款金额(未填写时按采购单价 × 退货数量) |
| | | BigDecimal refundAmount = resolveRefundAmount(returnVendor); |
| | | |
| | | // 4. 生成负数冲红付款单 |
| | | Long paymentId = financePaymentApi.createRedFlushPayment(new ErpFinancePaymentRedFlushCreateReqDTO() |
| | | .setSupplierId(returnVendor.getVendorId()) |
| | | .setRefundAmount(refundAmount) |
| | | .setSourceId(returnVendor.getId()) |
| | | .setSourceNo(returnVendor.getCode()) |
| | | .setFinanceUserId(getCurrentUserId()) |
| | | .setRemark("供应商退货单[" + returnVendor.getCode() + "]退款冲红,合同号[" + returnVendor.getContractNo() + "]")) |
| | | .getCheckedData(); |
| | | |
| | | // 5. 回写冲红单号与最终退款金额 |
| | | returnVendorMapper.updateById(new MesWmReturnVendorDO() |
| | | .setId(id).setRefundAmount(refundAmount).setRedFlushPaymentId(paymentId)); |
| | | return paymentId; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createReplacementNotice(Long id) { |
| | | // 1. 校验存在 + 已完成 + 处理方式为换货 |
| | | MesWmReturnVendorDO returnVendor = validateReturnVendorFinished(id); |
| | | if (!MesWmReturnVendorHandleTypeEnum.REPLACEMENT.getType().equals(returnVendor.getHandleType())) { |
| | | throw exception(WM_RETURN_VENDOR_HANDLE_TYPE_INVALID, returnVendor.getHandleType()); |
| | | } |
| | | // 2. 幂等:已生成过换货到货单直接返回 |
| | | if (returnVendor.getReplacementNoticeId() != null) { |
| | | return returnVendor.getReplacementNoticeId(); |
| | | } |
| | | |
| | | // 3. 生成换货到货通知单(待质检,行自动创建 IQC) |
| | | Long noticeId = arrivalNoticeService.createReplacementArrivalNotice(id); |
| | | |
| | | // 4. 回写到货通知单编号 |
| | | returnVendorMapper.updateById(new MesWmReturnVendorDO() |
| | | .setId(id).setReplacementNoticeId(noticeId)); |
| | | return noticeId; |
| | | } |
| | | |
| | | /** |
| | | * 解析退款金额:优先取单据填写值;未填写时按「采购单价 × 退货数量」逐行累加 |
| | | */ |
| | | private BigDecimal resolveRefundAmount(MesWmReturnVendorDO returnVendor) { |
| | | if (returnVendor.getRefundAmount() != null |
| | | && returnVendor.getRefundAmount().compareTo(BigDecimal.ZERO) > 0) { |
| | | return returnVendor.getRefundAmount(); |
| | | } |
| | | if (returnVendor.getPurchaseOrderId() == null) { |
| | | throw exception(WM_RETURN_VENDOR_REFUND_AMOUNT_REQUIRED, |
| | | returnVendor.getCode(), "未关联采购订单"); |
| | | } |
| | | List<ErpPurchaseOrderItemRespDTO> orderItems = purchaseOrderApi |
| | | .getPurchaseOrderItemList(returnVendor.getPurchaseOrderId()).getCheckedData(); |
| | | Map<Long, BigDecimal> priceMap = new HashMap<>(); |
| | | if (CollUtil.isNotEmpty(orderItems)) { |
| | | orderItems.stream().filter(item -> item.getProductId() != null) |
| | | .forEach(item -> priceMap.putIfAbsent(item.getProductId(), item.getProductPrice())); |
| | | } |
| | | List<MesWmReturnVendorLineDO> lines = returnVendorLineService.getReturnVendorLineListByReturnId(returnVendor.getId()); |
| | | if (CollUtil.isEmpty(lines)) { |
| | | throw exception(WM_RETURN_VENDOR_NO_LINE); |
| | | } |
| | | BigDecimal total = BigDecimal.ZERO; |
| | | for (MesWmReturnVendorLineDO line : lines) { |
| | | BigDecimal price = priceMap.get(line.getItemId()); |
| | | if (price == null) { |
| | | throw exception(WM_RETURN_VENDOR_REFUND_AMOUNT_REQUIRED, |
| | | returnVendor.getCode(), "物料ID=" + line.getItemId() + " 未匹配到采购单价"); |
| | | } |
| | | BigDecimal quantity = line.getQuantity() != null ? line.getQuantity() : BigDecimal.ZERO; |
| | | total = total.add(price.multiply(quantity)); |
| | | } |
| | | if (total.compareTo(BigDecimal.ZERO) <= 0) { |
| | | throw exception(WM_RETURN_VENDOR_REFUND_AMOUNT_REQUIRED, |
| | | returnVendor.getCode(), "采购单价 × 退货数量合计为 0"); |
| | | } |
| | | return total; |
| | | } |
| | | |
| | | /** |
| | | * 校验退货单存在且已完成(费用类操作仅在完成后退货单上执行) |
| | | */ |
| | | private MesWmReturnVendorDO validateReturnVendorFinished(Long id) { |
| | | MesWmReturnVendorDO returnVendor = validateReturnVendorExists(id); |
| | | if (!MesWmReturnVendorStatusEnum.FINISHED.getStatus().equals(returnVendor.getStatus())) { |
| | | throw exception(WM_RETURN_VENDOR_FINISHED_REQUIRED, returnVendor.getCode(), |
| | | resolveStatusName(returnVendor.getStatus())); |
| | | } |
| | | return returnVendor; |
| | | } |
| | | |
| | | /** |
| | | * 状态值转名称,解析失败回退为 ID 字符串 |
| | | */ |
| | | private String resolveStatusName(Integer status) { |
| | | for (MesWmReturnVendorStatusEnum value : MesWmReturnVendorStatusEnum.values()) { |
| | | if (value.getStatus().equals(status)) { |
| | | return value.getName(); |
| | | } |
| | | } |
| | | return "ID=" + status; |
| | | } |
| | | |
| | | /** |
| | | * 获取当前用户编号(BPM 流程发起人、财务人员) |
| | | */ |
| | | private Long getCurrentUserId() { |
| | | // 统一从安全框架取登录用户;Spring Security 的 principal 是 LoginUser 而非 Long, |
| | | // 直接强转会取到 null,导致 BPM 流程实例的发起人为字符串 "null" |
| | | return SecurityFrameworkUtils.getLoginUserId(); |
| | | } |
| | | |
| | | private void createTransactionList(MesWmReturnVendorDO returnVendor, List<MesWmReturnVendorDetailDO> details) { |
| | | wmTransactionService.createTransactionList(convertList(details, detail -> new MesWmTransactionSaveReqDTO() |
| | | .setType(MesWmTransactionTypeEnum.OUT.getType()).setItemId(detail.getItemId()) |
| | | // 按拣货时选中的库存记录扣减:生产批次可能没有 vendor_id,仅靠 物料+库位+批次+供应商 组合键会找不到库存 |
| | | .setMaterialStockId(detail.getMaterialStockId()) |
| | | .setQuantity(detail.getQuantity().negate()) // 出库数量为负数 |
| | | .setBatchId(detail.getBatchId()).setBatchCode(detail.getBatchCode()) |
| | | .setWarehouseId(detail.getWarehouseId()).setLocationId(detail.getLocationId()).setAreaId(detail.getAreaId()) |
| | |
| | | } |
| | | try { |
| | | importPurchaseOrderItems(id); |
| | | } catch (ServiceException ignore) { |
| | | // 采购订单无明细 / 无可退物料等业务异常:单据主体仍正常保存,可在物料区另行处理 |
| | | } catch (ServiceException ex) { |
| | | // 采购订单无明细 / 无可退物料等业务异常:单据主体仍正常保存,可在物料区点「重新带入订单物料」补带 |
| | | // 打日志便于排查(例如:保存后才入库,此时订单还没有可退数量) |
| | | log.warn("[autoImportLinesFromLinkedOrder][退货单({}) 关联采购订单({}) 自动带入物料失败:{}]", |
| | | id, returnVendor.getPurchaseOrderId(), ex.getMessage()); |
| | | } |
| | | } |
| | | |