liyong
11 小时以前 74a29854bb8ff92d2ff2fcb55fa5028609ec6a33
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -27,7 +27,9 @@
import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.pojo.ShippingInfo;
import com.ruoyi.sales.pojo.WeighingRecord;
import com.ruoyi.sales.service.ISalesLedgerProductService;
import com.ruoyi.sales.service.IWeighingRecordService;
import com.ruoyi.stock.mapper.StockInventoryMapper;
import com.ruoyi.stock.pojo.StockInventory;
import lombok.AllArgsConstructor;
@@ -88,13 +90,14 @@
    private StockUtils stockUtils;
    @Autowired
    private ProductStructureMapper productStructureMapper;
    @Autowired
    private StockInventoryMapper stockInventoryMapper;
    @Autowired
    private ProductOrderServiceImpl productOrderServiceImpl;
    @Autowired
    private IWeighingRecordService iWeighingRecordService;
    @Override
    public SalesLedgerProduct selectSalesLedgerProductById(Long id) {
@@ -107,20 +110,23 @@
//        queryWrapper.eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerProduct.getSalesLedgerId())
//                .eq(SalesLedgerProduct::getType, salesLedgerProduct.getType());
        List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectSalesLedgerProductList(salesLedgerProduct);
        if(!CollectionUtils.isEmpty(salesLedgerProducts)){
        if (!CollectionUtils.isEmpty(salesLedgerProducts)) {
            salesLedgerProducts.forEach(item -> {
                // 发货信息
                ShippingInfo shippingInfo = shippingInfoMapper.selectOne(new LambdaQueryWrapper<ShippingInfo>()
                        .eq(ShippingInfo::getSalesLedgerProductId, item.getId())
                        .orderByDesc(ShippingInfo::getCreateTime)
                        .last("limit 1"));
                if(shippingInfo != null){
                    item.setShippingDate(shippingInfo.getShippingDate());
                    item.setShippingCarNumber(shippingInfo.getShippingCarNumber());
                    item.setShippingStatus(shippingInfo.getStatus());
                    item.setExpressCompany(shippingInfo.getExpressCompany());
                    item.setExpressNumber(shippingInfo.getExpressNumber());
                List<WeighingRecord> list = iWeighingRecordService.list(new QueryWrapper<WeighingRecord>().lambda().eq(WeighingRecord::getRecordId, item.getId()).orderByDesc(WeighingRecord::getCreateTime));
                if (!list.isEmpty()) {
                    BigDecimal reduce = list.stream().map(WeighingRecord::getNetWeight).collect(Collectors.toList()).stream().reduce(BigDecimal.ZERO, BigDecimal::add);
                    item.setShippingDate(list.get(0).getSecondWeighTime());
                    item.setShippingCarNumber(list.get(0).getCarNo());
                    if (reduce.compareTo(BigDecimal.ZERO) == 0) {
                        item.setShippingStatus("未发货");
                    } else if (reduce.compareTo(item.getQuantity()) < 0) {
                        item.setShippingStatus("部分发货");
                    } else {
                        item.setShippingStatus("已发货");
                    }
                }
                item.setShippingStatus("未发货");
            });
            // 开票
            InvoiceRegistrationProductDto invoiceRegistrationProductDto = new InvoiceRegistrationProductDto();
@@ -134,8 +140,8 @@
                    BigDecimal noInvoiceNum = BigDecimal.ZERO;
                    BigDecimal noInvoiceAmount = BigDecimal.ZERO;
                    for (InvoiceRegistrationProductDto registrationProductDto : invoiceRegistrationProductDtoList) {
                        if(ledgerProduct.getId().intValue() == registrationProductDto.getSalesLedgerProductId()){
                            invoiceNum =  invoiceNum.add(registrationProductDto.getInvoiceNum());
                        if (ledgerProduct.getId().intValue() == registrationProductDto.getSalesLedgerProductId()) {
                            invoiceNum = invoiceNum.add(registrationProductDto.getInvoiceNum());
                            invoiceAmount = invoiceAmount.add(registrationProductDto.getInvoiceAmount());
                        }
                    }
@@ -169,7 +175,7 @@
        //删除发货信息
        List<ShippingInfo> shippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>()
                .in(ShippingInfo::getSalesLedgerProductId, Arrays.asList(ids)));
        if(!CollectionUtils.isEmpty(shippingInfos)){
        if (!CollectionUtils.isEmpty(shippingInfos)) {
            shippingInfoService.delete(shippingInfos.stream().map(ShippingInfo::getId).collect(Collectors.toList()));
        }
@@ -296,12 +302,12 @@
        BigDecimal ticketsTotal = salesLedgerProduct.getTicketsTotal() != null ? salesLedgerProduct.getTicketsTotal() : BigDecimal.ZERO;
        // 待回款,付款
        if(salesLedgerProduct.getType().equals(1)){
        if (salesLedgerProduct.getType().equals(1)) {
            salesLedgerProduct.setPendingInvoiceTotal(totalPrice.subtract(invoiceTotal));
            //未开票数量+金额
            salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity());
            salesLedgerProduct.setNoInvoiceAmount(totalPrice);
        }else{
        } else {
            salesLedgerProduct.setPendingTicketsTotal(totalPrice.subtract(ticketsTotal));
            // 未来票数量+金额
            salesLedgerProduct.setFutureTickets(salesLedgerProduct.getQuantity());
@@ -376,7 +382,7 @@
        List<ProcessRoute> processRoutes = processRouteMapper.selectList(new QueryWrapper<ProcessRoute>().lambda()
                .eq(ProcessRoute::getProductModelId, salesLedgerProduct.getProductModelId())
                .orderByDesc(ProcessRoute::getCreateTime));
        if (processRoutes.size()>0){
        if (processRoutes.size() > 0) {
            ProcessRoute processRoute = processRoutes.get(0);
            //新增生产订单工艺路线主表
            ProductProcessRoute productProcessRoute = new ProductProcessRoute();
@@ -413,7 +419,7 @@
                        }
                    }
                    // 生成完整的工单号
                    String workOrderNoStr ="GD"+ String.format("%s%03d", datePrefix, sequenceNumber);
                    String workOrderNoStr = "GD" + String.format("%s%03d", datePrefix, sequenceNumber);
                    ProductWorkOrder productWorkOrder = new ProductWorkOrder();
                    productWorkOrder.setProductProcessRouteItemId(productProcessRouteItem.getId());
                    productWorkOrder.setProductOrderId(productOrder.getId());
@@ -434,7 +440,7 @@
     * 删除生产数据
     */
    public void deleteProductionData(List<Long> productIds) {
        if (productIds == null || productIds.isEmpty()){
        if (productIds == null || productIds.isEmpty()) {
            return;
        }
        //批量查询productOrder
@@ -533,9 +539,9 @@
            // 判断状态
            BigDecimal taxInclusiveTotalPrice = item.getTaxInclusiveTotalPrice();
            BigDecimal invoiceTotal = item.getInvoiceTotal();
            if(taxInclusiveTotalPrice != null && invoiceTotal != null && taxInclusiveTotalPrice.compareTo(invoiceTotal) == 0){
            if (taxInclusiveTotalPrice != null && invoiceTotal != null && taxInclusiveTotalPrice.compareTo(invoiceTotal) == 0) {
                item.setStatusName("已完成付款");
            }else{
            } else {
                item.setStatusName("未完成付款");
            }
        });
@@ -549,9 +555,9 @@
            // 判断状态
            BigDecimal taxInclusiveTotalPrice = item.getTaxInclusiveTotalPrice();
            BigDecimal ticketsTotal = item.getTicketsTotal();
            if(taxInclusiveTotalPrice != null && ticketsTotal != null && taxInclusiveTotalPrice.compareTo(ticketsTotal) == 0){
            if (taxInclusiveTotalPrice != null && ticketsTotal != null && taxInclusiveTotalPrice.compareTo(ticketsTotal) == 0) {
                item.setStatusName("已完成付款");
            }else{
            } else {
                item.setStatusName("未完成付款");
            }
        });
@@ -592,6 +598,7 @@
            throw new RuntimeException("动态更新主表金额失败", e);
        }
    }
    @Override
    public R judgmentInventory(SalesLedgerProduct salesLedgerProduct) {
        //获取产品最新的工艺路线
@@ -610,7 +617,7 @@
            //所需数量
            BigDecimal multiply = salesLedgerProduct.getQuantity().multiply(productStructureDto.getUnitQuantity());
            BigDecimal subtract =stockInventory.getQualitity().subtract(stockInventory.getLockedQuantity()).subtract(multiply).divide(BigDecimal.ONE, 2, RoundingMode.CEILING);
            BigDecimal subtract = stockInventory.getQualitity().subtract(stockInventory.getLockedQuantity()).subtract(multiply).divide(BigDecimal.ONE, 2, RoundingMode.CEILING);
            if (subtract.compareTo(BigDecimal.ZERO) <= 0) {
                count++;
                stringBuffer.append(productStructureDto.getProductName())
@@ -621,9 +628,9 @@
                        .append(System.lineSeparator());
            }
        }
        if (count>0) {
        if (count > 0) {
            return R.fail(stringBuffer.toString());
        }else {
        } else {
            return R.ok();
        }
    }