src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -31,10 +31,6 @@
import com.ruoyi.other.mapper.TempFileMapper;
import com.ruoyi.other.pojo.TempFile;
import com.ruoyi.production.mapper.*;
import com.ruoyi.production.pojo.ProductOrder;
import com.ruoyi.production.pojo.ProductProcessRouteItem;
import com.ruoyi.production.pojo.ProductWorkOrder;
import com.ruoyi.production.pojo.ProductionProductMain;
import com.ruoyi.production.service.ProductionProductMainService;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.domain.SysUser;
@@ -45,6 +41,8 @@
import com.ruoyi.sales.mapper.*;
import com.ruoyi.sales.pojo.*;
import com.ruoyi.sales.service.ISalesLedgerService;
import com.ruoyi.stock.mapper.StockInventoryMapper;
import com.ruoyi.stock.pojo.StockInventory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
@@ -140,6 +138,8 @@
    private final QualityInspectMapper qualityInspectMapper;
    private final StockInventoryMapper stockInventoryMapper;
    @Autowired
    private SysDeptMapper sysDeptMapper;
@@ -168,7 +168,7 @@
    }
    public List<SalesLedgerProduct> getSalesLedgerProductListByRelateId(Long relateId, SaleEnum type){
    public List<SalesLedgerProduct> getSalesLedgerProductListByRelateId(Long relateId, SaleEnum type) {
        LambdaQueryWrapper<SalesLedgerProduct> productWrapper = new LambdaQueryWrapper<>();
        productWrapper.eq(SalesLedgerProduct::getSalesLedgerId, relateId);
        productWrapper.eq(SalesLedgerProduct::getType, type.getCode());
@@ -194,6 +194,9 @@
            product.setTempnoInvoiceAmount(product.getNoInvoiceAmount());
            product.setTempNoInvoiceNum(product.getNoInvoiceNum());
            product.setRegister(SecurityUtils.getLoginUser().getUser().getNickName());
            product.setUidNo(product.getUidNo());
            product.setUnit(product.getUnit());
            product.setBatchNo(product.getBatchNo());
            product.setRegisterDate(LocalDateTime.now());
            // 发货信息
            ShippingInfo shippingInfo = shippingInfoMapper.selectOne(new LambdaQueryWrapper<ShippingInfo>()
@@ -660,7 +663,7 @@
            // 4. 处理子表数据
            List<SalesLedgerProduct> productList = salesLedgerDto.getProductData();
            if (productList != null && !productList.isEmpty()) {
                handleSalesLedgerProducts(salesLedger.getId(), productList, EnumUtil.fromCode(SaleEnum.class,salesLedgerDto.getType()));
                handleSalesLedgerProducts(salesLedger.getId(), productList, EnumUtil.fromCode(SaleEnum.class, salesLedgerDto.getType()));
                updateMainContractAmount(
                        salesLedger.getId(),
                        productList,
@@ -925,32 +928,20 @@
                map.put("filingCertificateNo", productModel.getFilingCertificateNo());
            }
            amount = amount.add(product.getTaxInclusiveTotalPrice());
            List<ProductOrder> productOrders = productOrderMapper.selectList(new LambdaQueryWrapper<ProductOrder>()
                    .eq(ProductOrder::getBatchNo, product.getBatchNo()));
            if (CollectionUtils.isEmpty(productOrders)) {
            List<StockInventory> stockInventoryList = stockInventoryMapper.selectList(new LambdaQueryWrapper<StockInventory>().eq(StockInventory::getProductModelId, product.getProductModelId())
                    .eq(StockInventory::getBatchNo, product.getBatchNo())
                    .eq(StockInventory::getCustomer, product.getCustomer()));
            if (CollectionUtils.isEmpty(stockInventoryList)) {
                throw new RuntimeException("批号不存在");
            }
            List<ProductWorkOrder> productWorkOrders = productWorkOrderMapper.selectList(new LambdaQueryWrapper<ProductWorkOrder>()
                    .eq(ProductWorkOrder::getProductOrderId, productOrders.get(0).getId()));
            List<Long> ids = productWorkOrders.stream().map(ProductWorkOrder::getId).collect(Collectors.toList());
            List<ProductionProductMain> productionProductMains = productionProductMainMapper.selectList(new LambdaQueryWrapper<ProductionProductMain>()
                    .in(ProductionProductMain::getWorkOrderId, ids)
                    .orderByDesc(ProductionProductMain::getCreateTime));
            List<ProductProcessRouteItem> productProcessRouteItems = productProcessRouteItemMapper.selectList(new LambdaQueryWrapper<ProductProcessRouteItem>()
                    .in(ProductProcessRouteItem::getId, productionProductMains.stream()
                            .map(ProductionProductMain::getProductProcessRouteItemId).collect(Collectors.toList()))
                    .eq(ProductProcessRouteItem::getProductModelId, product.getProductModelId())
                    .orderByDesc(ProductProcessRouteItem::getCreateTime));
            if (CollectionUtils.isEmpty(productProcessRouteItems)) {
                throw new RuntimeException("生产数据不存在");
            }
            String productionDate = productProcessRouteItems.get(0).getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            if (productModel.getValidityPeriod() == null) {
                throw new RuntimeException("有效期不能为空");
            }
            String expiryDate = productProcessRouteItems.get(0).getCreateTime().plusYears(productModel.getValidityPeriod().longValue()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            String productionDate = stockInventoryList.get(0).getProductionDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            map.put("productionDate", productionDate);
            map.put("expiryDate", expiryDate);
            List<ProductModel> productModelList = productModelMapper.selectList(new LambdaQueryWrapper<ProductModel>().eq(ProductModel::getId, product.getProductModelId()));
            BigDecimal validityPeriod = productModelList.get(0).getValidityPeriod();
            LocalDate expiryDate = stockInventoryList.get(0).getProductionDate()
                    .plusYears(validityPeriod.longValue());
            String expiryDateStr = expiryDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            map.put("expiryDate", expiryDateStr);
            products.add(map);
        }
        Map<String, Object> data = new HashMap<>();
@@ -990,6 +981,5 @@
            e.printStackTrace();
            throw new RuntimeException("导出失败");
        }
    }
}