5 天以前 d3a5c4420a7daf89bc9832f22ca8ed9d7e1adaf9
src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
@@ -13,6 +13,7 @@
import com.ruoyi.procurementrecord.mapper.ReturnSaleProductMapper;
import com.ruoyi.procurementrecord.pojo.ReturnManagement;
import com.ruoyi.procurementrecord.pojo.ReturnSaleProduct;
import com.ruoyi.procurementrecord.service.impl.ReturnManagementServiceImpl;
import com.ruoyi.procurementrecord.utils.StockUtils;
import com.ruoyi.sales.dto.SalesLedgerProductDto;
import com.ruoyi.sales.dto.ShippingInfoDto;
@@ -67,6 +68,9 @@
    @Autowired
    private ReturnSaleProductMapper returnSaleProductMapper;
    @Autowired
    private ReturnManagementServiceImpl returnManagementService;
    @Override
    public List<SalesLedgerProductDto> getReturnManagementDtoById(Long shippingId) {
        return shippingInfoMapper.getReturnManagementDtoById(shippingId );
@@ -75,8 +79,6 @@
    /**
     * 获取销售产品单的已发货数量
     * @param id
     * @return
     */
    @Override
    public Map<String, BigDecimal> getNumberOfSalesLedgerProduct(Long salesLedgerProductId) {
@@ -109,6 +111,15 @@
    }
    @Override
    public ShippingInfoDto getDateil(Long id) {
        ShippingInfoDto shippingInfoDto =  shippingInfoMapper.getDateil(id);
        if(shippingInfoDto != null){
            assembleDetails(shippingInfoDto);
        }
        return shippingInfoDto;
    }
    @Override
    public List<ShippingInfo> getShippingInfoByCustomerName(String customerName) {
        return shippingInfoMapper.getShippingInfoByCustomerName(customerName);
    }
@@ -116,22 +127,35 @@
    @Override
    public IPage<ShippingInfoDto> listPage(Page page, ShippingInfo req) {
        IPage<ShippingInfoDto> listPage = shippingInfoMapper.listPage(page, req);
        listPage.getRecords().forEach(item ->{
            item.setCommonFileList(commonFileService.getFileListByBusinessId(item.getId(), FileNameType.SHIP.getValue()));
            List<ShippingInfoDetail> shippingInfoDetails = shippingInfoDetailMapper.selectList(new LambdaQueryWrapper<ShippingInfoDetail>()
                    .eq(ShippingInfoDetail::getShippingInfoId, item.getId()));
            // 核心优化:层层防护空指针 + 处理空集合场景
            item.setShippingSuccessTotal(Optional.ofNullable(shippingInfoDetails)
                    .orElse(Collections.emptyList())
                    .stream()
                    .filter(Objects::nonNull)
                    .map(ShippingInfoDetail::getShippingNum)
                    .filter(Objects::nonNull)
                    .reduce(BigDecimal.ZERO, BigDecimal::add)); // 用Lambda替代方法引用
            item.setWaitShippingTotal(item.getShippingTotal().subtract(item.getShippingSuccessTotal()));
        });
        listPage.getRecords().forEach(this::assembleDetails);
        return listPage;
    }
    /**
     * 封装详情
     * @param item
     */
    public void assembleDetails(ShippingInfoDto item) {
        item.setCommonFileList(commonFileService.getFileListByBusinessId(item.getId(), FileNameType.SHIP.getValue()));
        List<ShippingInfoDetail> shippingInfoDetails = shippingInfoDetailMapper.selectList(new LambdaQueryWrapper<ShippingInfoDetail>()
                .eq(ShippingInfoDetail::getShippingInfoId, item.getId()));
        // 核心优化:层层防护空指针 + 处理空集合场景
        item.setShippingSuccessTotal(Optional.ofNullable(shippingInfoDetails)
                .orElse(Collections.emptyList())
                .stream()
                .filter(Objects::nonNull)
                .map(ShippingInfoDetail::getShippingNum)
                .filter(Objects::nonNull)
                .reduce(BigDecimal.ZERO, BigDecimal::add)); // 用Lambda替代方法引用
        item.setWaitShippingTotal(item.getShippingTotal().subtract(item.getShippingSuccessTotal()));
        // 查询退货数量
        if(CollectionUtils.isNotEmpty(shippingInfoDetails)){
            item.setReturnTotal(returnManagementService.getReturnSaleProductCountByShippingId(shippingInfoDetails
                    .stream()
                    .map(ShippingInfoDetail::getId)
                    .collect(Collectors.toList())));
        }
    }
    @Override
@@ -142,7 +166,7 @@
        }
        //扣减库存
        SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(byId.getSalesLedgerProductId());
        stockUtils.substractStock(salesLedgerProduct.getProductModelId(), salesLedgerProduct.getQuantity(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId());
        stockUtils.substractStock(salesLedgerProduct.getProductModelId(), req.getShippingTotal(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId());
        byId.setExpressNumber(req.getExpressNumber());
        byId.setExpressCompany(req.getExpressCompany());
        byId.setStatus(req.getStatus());