9 小时以前 7bf754a7835d06f26240c4ca15bc5f83650de377
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -12,10 +12,12 @@
import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
import com.ruoyi.purchase.pojo.PurchaseLedger;
import com.ruoyi.quality.mapper.QualityInspectMapper;
import com.ruoyi.sales.mapper.SalesLedgerArrivalMapper;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.sales.mapper.ShippingInfoMapper;
import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.pojo.SalesLedgerArrival;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.pojo.ShippingInfo;
import com.ruoyi.sales.service.ISalesLedgerProductService;
@@ -59,6 +61,8 @@
    @Autowired
    private SalesLedgerMapper salesLedgerMapper;
    @Autowired
    private SalesLedgerArrivalMapper salesLedgerArrivalMapper;
    @Autowired
    private PurchaseLedgerMapper purchaseLedgerMapper;
    @Autowired
    private ProductionPlanMapper productionPlanMapper;
@@ -97,30 +101,23 @@
        List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectSalesLedgerProductList(salesLedgerProduct);
        if(!CollectionUtils.isEmpty(salesLedgerProducts)){
            salesLedgerProducts.forEach(item -> {
                // 发货信息(取最新一条,只查询审核通过或已发货的记录)
                ShippingInfo latestShippingInfo = shippingInfoMapper.selectOne(new LambdaQueryWrapper<ShippingInfo>()
                        .eq(ShippingInfo::getSalesLedgerProductId, item.getId())
                        .in(ShippingInfo::getStatus, "审核通过", "已发货")
                        .orderByDesc(ShippingInfo::getCreateTime)
                        .last("limit 1"));
                if(latestShippingInfo != null){
                    item.setShippingDate(latestShippingInfo.getShippingDate());
                    item.setExpressCompany(latestShippingInfo.getExpressCompany());
                    item.setExpressNumber(latestShippingInfo.getExpressNumber());
                // 发货信息:油品出库不再产发货单,改按到货记录回填(到货日期取最新一条;快递字段对整车油品无意义,留空)
                List<SalesLedgerArrival> arrivals = salesLedgerArrivalMapper.selectList(new LambdaQueryWrapper<SalesLedgerArrival>()
                        .eq(SalesLedgerArrival::getSalesLedgerProductId, item.getId())
                        .orderByAsc(SalesLedgerArrival::getArrivalDate)
                        .orderByAsc(SalesLedgerArrival::getId));
                if(CollectionUtils.isEmpty(arrivals)){
                    return;
                }
                // 车牌号:取所有审核通过或已发货记录的车牌号,逗号拼接
                List<ShippingInfo> allShippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>()
                        .eq(ShippingInfo::getSalesLedgerProductId, item.getId())
                        .in(ShippingInfo::getStatus, "审核通过", "已发货")
                        .orderByAsc(ShippingInfo::getCreateTime));
                if(!CollectionUtils.isEmpty(allShippingInfos)){
                    String carNumbers = allShippingInfos.stream()
                            .map(ShippingInfo::getShippingCarNumber)
                            .filter(carNo -> carNo != null && !carNo.trim().isEmpty())
                            .distinct()
                            .collect(Collectors.joining(","));
                    item.setShippingCarNumber(carNumbers);
                }
                SalesLedgerArrival latest = arrivals.get(arrivals.size() - 1);
                item.setShippingDate(latest.getArrivalDate() == null ? null : java.sql.Date.valueOf(latest.getArrivalDate()));
                // 车牌号:所有到货记录的车牌号,去重后逗号拼接
                String carNumbers = arrivals.stream()
                        .map(SalesLedgerArrival::getTruckPlateNo)
                        .filter(carNo -> carNo != null && !carNo.trim().isEmpty())
                        .distinct()
                        .collect(Collectors.joining(","));
                item.setShippingCarNumber(carNumbers);
            });
        }
        return salesLedgerProducts;