| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void stockReturnVendor(Long id) { |
| | | // 校验存在 |
| | | // 校验存在 + 已审批(状态只能由 audit 推进:APPROVING → APPROVED) |
| | | MesWmReturnVendorDO returnVendor = validateReturnVendorExists(id); |
| | | if (ObjUtil.notEqual(MesWmReturnVendorStatusEnum.APPROVING.getStatus(), returnVendor.getStatus())) { |
| | | if (ObjUtil.notEqual(MesWmReturnVendorStatusEnum.APPROVED.getStatus(), returnVendor.getStatus())) { |
| | | throw exception(WM_RETURN_VENDOR_STATUS_INVALID); |
| | | } |
| | | // 执行拣货(待拣货 -> 待执行退货) |
| | | returnVendorMapper.updateById(new MesWmReturnVendorDO() |
| | | .setId(id).setStatus(MesWmReturnVendorStatusEnum.APPROVED.getStatus())); |
| | | // 仅校验行数量与明细数量一致,不修改单据状态 |
| | | if (!Boolean.TRUE.equals(checkReturnVendorQuantity(id))) { |
| | | throw exception(WM_RETURN_VENDOR_DETAIL_QUANTITY_MISMATCH); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (CollUtil.isEmpty(details)) { |
| | | throw exception(WM_RETURN_VENDOR_NO_DETAIL); |
| | | } |
| | | // 1.3 校验每行明细数量之和等于行退货数量,避免出库数量与单据不一致 |
| | | if (!Boolean.TRUE.equals(checkReturnVendorQuantity(id))) { |
| | | throw exception(WM_RETURN_VENDOR_DETAIL_QUANTITY_MISMATCH); |
| | | } |
| | | |
| | | // 2. 遍历所有明细,创建库存事务(扣减库存 + 记录流水) |
| | | createTransactionList(returnVendor, details); |
| | |
| | | private void createTransactionList(MesWmReturnVendorDO returnVendor, List<MesWmReturnVendorDetailDO> details) { |
| | | wmTransactionService.createTransactionList(convertList(details, detail -> new MesWmTransactionSaveReqDTO() |
| | | .setType(MesWmTransactionTypeEnum.OUT.getType()).setItemId(detail.getItemId()) |
| | | .setQuantity(detail.getQuantity().negate()) // 出库数量为负数 |
| | | .setQuantity(negateQuantity(detail.getQuantity())) // 出库数量为负数 |
| | | .setBatchId(detail.getBatchId()).setBatchCode(detail.getBatchCode()) |
| | | .setWarehouseId(detail.getWarehouseId()).setLocationId(detail.getLocationId()).setAreaId(detail.getAreaId()) |
| | | .setVendorId(returnVendor.getVendorId()) |
| | |
| | | .setBizCode(returnVendor.getCode()).setBizLineId(detail.getLineId()))); |
| | | } |
| | | |
| | | /** |
| | | * 出库数量取负:数量为空时抛出明确的业务异常,避免 NPE |
| | | */ |
| | | private BigDecimal negateQuantity(BigDecimal quantity) { |
| | | if (quantity == null) { |
| | | throw exception(WM_RETURN_VENDOR_DETAIL_QUANTITY_INVALID); |
| | | } |
| | | return quantity.negate(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void cancelReturnVendor(Long id) { |