liyong
2026-05-22 2d03ec79e1892248b520cf097e8a58dd82a4892f
src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -6,11 +6,10 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum;
import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.domain.R;
import com.ruoyi.sales.dto.SimpleProductDto;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.stock.dto.StockInRecordDto;
import com.ruoyi.stock.dto.StockInventoryDto;
import com.ruoyi.stock.dto.StockOutRecordDto;
@@ -29,6 +28,7 @@
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
 * <p>
@@ -97,7 +97,7 @@
        stockOutRecordDto.setProductModelId(stockInventoryDto.getProductModelId());
        stockOutRecordDto.setType("0");
        stockOutRecordService.add(stockOutRecordDto);
        StockInventory oldStockInventory = stockInventoryMapper.selectOne(new QueryWrapper<StockInventory>().lambda().eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId()).eq(StockInventory::getProductCode,stockInventoryDto.getProductCode()));
        StockInventory oldStockInventory = stockInventoryMapper.selectOne(new QueryWrapper<StockInventory>().lambda().eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId()));
        if (ObjectUtils.isEmpty(oldStockInventory)) {
            throw new RuntimeException("产品库存不存在");
        }
@@ -117,7 +117,7 @@
    public R importStockInventory(MultipartFile file) {
        try {
            // 查询所有的产品
            List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectProduct();
            List<SimpleProductDto> salesLedgerProducts = salesLedgerProductMapper.selectProduct();
            ExcelUtil<StockInventoryExportData> util = new ExcelUtil<StockInventoryExportData>(StockInventoryExportData.class);
            List<StockInventoryExportData> list = util.importExcel(file.getInputStream());
@@ -127,12 +127,16 @@
            list.forEach(dto -> {
                boolean matched = false;
                for (SalesLedgerProduct item : salesLedgerProducts) {
                for (SimpleProductDto item : salesLedgerProducts) {
                    if (ObjectUtils.isEmpty(dto.getWarehouseCode())) {
                        return;
                    }
                    if (item.getProductCategory().equals(dto.getProductName()) &&
                            item.getSpecificationModel().equals(dto.getModel())) {
                            item.getSpecificationModel().equals(dto.getModel())
                            && Optional.ofNullable(item.getUnit()).orElse("").equals(dto.getUnit())
                            && Optional.ofNullable(item.getSubUnit()).orElse("").equals(dto.getSubUnit())
                    ) {
                        StockInventoryDto stockInventoryDto = new StockInventoryDto();
                        stockInventoryDto.setWarehouseCode(dto.getWarehouseCode());
                        stockInventoryDto.setWarehouseName(dto.getWarehouseName());
@@ -149,8 +153,8 @@
                }
                if (!matched) {
                    // 记录未匹配的数据
                    String unmatchedInfo = String.format("产品名称:%s,规格型号:%s",
                            dto.getProductName(), dto.getModel());
                    String unmatchedInfo = String.format("产品名称:%s,规格型号:%s 主单位:%s 辅单位:%s",
                            dto.getProductName(), dto.getModel(), dto.getUnit(), dto.getSubUnit());
                    unmatchedRecords.add(unmatchedInfo);
                }
            });