| | |
| | | import com.ruoyi.sales.pojo.ShippingInfo; |
| | | import com.ruoyi.sales.pojo.ShippingProductDetail; |
| | | import com.ruoyi.sales.service.ShippingInfoService; |
| | | import com.ruoyi.stock.dto.StockInventoryDto; |
| | | import com.ruoyi.stock.dto.StockUninventoryDto; |
| | | import com.ruoyi.stock.service.StockInventoryService; |
| | | import com.ruoyi.stock.service.StockUninventoryService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | |
| | | private final ShippingProductDetailMapper shippingProductDetailMapper; |
| | | private final ApprovalTemplateMapper approvalTemplateMapper; |
| | | private final ApprovalInstanceService approvalInstanceService; |
| | | private final StockInventoryService stockInventoryService; |
| | | private final StockUninventoryService stockUninventoryService; |
| | | |
| | | @Override |
| | | public IPage<ShippingInfoDto> listPage(Page page, ShippingInfo req) { |
| | |
| | | throw new RuntimeException("发货信息不存在"); |
| | | } |
| | | for (ShippingProductDetail shippingProductDetail : shippingProductDetails) { |
| | | stockUtils.substractStock(shippingProductDetail.getProductModelId(), shippingProductDetail.getQuantity(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId(), shippingProductDetail.getBatchNo()); |
| | | addShippingStockOutRecord(shippingProductDetail, req.getId()); |
| | | } |
| | | } |
| | | byId.setExpressNumber(req.getExpressNumber()); |
| | |
| | | this.save(req); |
| | | req.getBatchNoDetailList().forEach(item -> item.setShippingInfoId(req.getId())); |
| | | shippingProductDetailMapper.insert(req.getBatchNoDetailList()); |
| | | for (ShippingProductDetail shippingProductDetail : req.getBatchNoDetailList()) { |
| | | stockUtils.substractStock(shippingProductDetail.getProductModelId(), shippingProductDetail.getQuantity(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId(), shippingProductDetail.getBatchNo()); |
| | | } |
| | | // 保存文件 |
| | | fileUtil.saveStorageAttachment(ApplicationTypeEnum.IMAGE, RecordTypeEnum.SHIPPING_INFO, req.getId(), req.getStorageBlobDTOs()); |
| | | return true; |
| | |
| | | approvalInstanceService.add(approvalInstance); |
| | | return true; |
| | | } |
| | | |
| | | private void addShippingStockOutRecord(ShippingProductDetail shippingProductDetail, Long shippingInfoId) { |
| | | String stockType = shippingProductDetail.getStockType(); |
| | | if (stockType != null) { |
| | | stockType = stockType.trim().toLowerCase(); |
| | | } |
| | | if ("waste".equals(stockType) || "unqualified".equals(stockType)) { |
| | | StockUninventoryDto stockUninventoryDto = new StockUninventoryDto(); |
| | | stockUninventoryDto.setRecordId(shippingInfoId); |
| | | stockUninventoryDto.setRecordType(StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode()); |
| | | stockUninventoryDto.setQualitity(shippingProductDetail.getQuantity()); |
| | | stockUninventoryDto.setProductModelId(shippingProductDetail.getProductModelId()); |
| | | stockUninventoryDto.setBatchNo(normalizeBatchNo(shippingProductDetail.getBatchNo())); |
| | | stockUninventoryDto.setType("waste"); |
| | | stockUninventoryService.addStockOutRecordOnly(stockUninventoryDto); |
| | | return; |
| | | } |
| | | if (!"qualified".equals(stockType)) { |
| | | throw new RuntimeException("发货明细库存类型无效,只支持 qualified 或 waste"); |
| | | } |
| | | StockInventoryDto stockInventoryDto = new StockInventoryDto(); |
| | | stockInventoryDto.setRecordId(shippingInfoId); |
| | | stockInventoryDto.setRecordType(StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode()); |
| | | stockInventoryDto.setQualitity(shippingProductDetail.getQuantity()); |
| | | stockInventoryDto.setProductModelId(shippingProductDetail.getProductModelId()); |
| | | stockInventoryDto.setBatchNo(normalizeBatchNo(shippingProductDetail.getBatchNo())); |
| | | stockInventoryService.addStockOutRecordOnly(stockInventoryDto); |
| | | } |
| | | |
| | | private String normalizeBatchNo(String batchNo) { |
| | | if (batchNo == null) { |
| | | return null; |
| | | } |
| | | String normalized = batchNo.trim(); |
| | | return normalized.isEmpty() ? null : normalized; |
| | | } |
| | | } |