huminmin
昨天 554738e1e277a9aafda4c20d420cba252d5f528f
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -13,6 +13,7 @@
import com.ruoyi.basic.mapper.ProductMapper;
import com.ruoyi.basic.mapper.ProductModelMapper;
import com.ruoyi.basic.pojo.Customer;
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.common.enums.FileNameType;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.DateUtils;
@@ -24,20 +25,18 @@
import com.ruoyi.other.mapper.TempFileMapper;
import com.ruoyi.other.pojo.TempFile;
import com.ruoyi.production.mapper.*;
import com.ruoyi.production.pojo.*;
import com.ruoyi.production.service.ProductionProductMainService;
import com.ruoyi.production.service.impl.ProductionProductMainServiceImpl;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysDeptMapper;
import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.quality.mapper.QualityInspectMapper;
import com.ruoyi.quality.pojo.QualityInspect;
import com.ruoyi.sales.dto.*;
import com.ruoyi.sales.mapper.*;
import com.ruoyi.sales.pojo.*;
import com.ruoyi.sales.service.ISalesLedgerProductService;
import com.ruoyi.sales.service.ISalesLedgerService;
import com.ruoyi.stock.dto.StockInventoryDto;
import com.ruoyi.stock.mapper.StockInventoryMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
@@ -130,6 +129,9 @@
    private final QualityInspectMapper qualityInspectMapper;
    private final StockInventoryMapper stockInventoryMapper;
    @Autowired
    private SysDeptMapper sysDeptMapper;
@@ -185,6 +187,9 @@
            if (shippingInfo != null) {
                product.setShippingStatus(shippingInfo.getStatus());
            }
            ProductModel productModel = productModelMapper.selectById(product.getProductModelId());
            product.setMaterialCode(productModel.getMaterialCode());
        }
        // 3.查询上传文件
@@ -708,9 +713,26 @@
        List<SalesLedgerProduct> updateList = partitionedProducts.get(true);
        List<SalesLedgerProduct> insertList = partitionedProducts.get(false);
        List<StockInventoryDto> stockInventoryDtos = stockInventoryMapper.selectProductList();
        // 执行更新操作
        if (!updateList.isEmpty()) {
            for (SalesLedgerProduct product : updateList) {
                // 查询库存数量
                SalesLedgerProduct oldProduct = salesLedgerProductMapper.selectById(product.getId());
                BigDecimal quantityChange = product.getQuantity().subtract(oldProduct.getQuantity());
                // 如果数量增加了,检查库存
                if (quantityChange.compareTo(BigDecimal.ZERO) > 0) {
                    for (StockInventoryDto stockInventoryDto : stockInventoryDtos) {
                        if (stockInventoryDto.getProductId().equals(product.getId())) {
                            if (quantityChange.compareTo(stockInventoryDto.getQualitity()) > 0) {
                                throw new RuntimeException("库存不足");
                            }
                            break;
                        }
                    }
                }
                product.setType(type);
                salesLedgerProductMapper.updateById(product);
            }
@@ -718,13 +740,18 @@
        // 执行插入操作
        if (!insertList.isEmpty()) {
            for (SalesLedgerProduct salesLedgerProduct : insertList) {
                for (StockInventoryDto stockInventoryDto : stockInventoryDtos) {
                    if (stockInventoryDto.getProductId().equals(salesLedgerProduct.getId())) {
                        if (salesLedgerProduct.getQuantity().compareTo(stockInventoryDto.getQualitity()) > 0) {
                            throw new RuntimeException("库存不足");
                        }
                    }
                }
                salesLedgerProduct.setType(type);
                salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity());
                salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getTaxInclusiveTotalPrice());
                salesLedgerProduct.setPendingInvoiceTotal(salesLedgerProduct.getTaxInclusiveTotalPrice());
                salesLedgerProductMapper.insert(salesLedgerProduct);
                // 添加生产数据
                salesLedgerProductServiceImpl.addProductionData(salesLedgerProduct);
            }
        }
    }