liyong
5 天以前 32b536caa833c1861c6f273d78d7202206445b74
src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -6,9 +6,13 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.basic.excel.SupplierManageExcelDto;
import com.ruoyi.basic.pojo.SupplierManage;
import com.ruoyi.common.enums.StockQualifiedRecordTypeEnum;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.domain.R;
import com.ruoyi.procurementrecord.utils.StockUtils;
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;
@@ -30,6 +34,8 @@
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
 * <p>
@@ -46,7 +52,8 @@
    private  StockInventoryMapper stockInventoryMapper;
    private StockInRecordService stockInRecordService;
    private StockOutRecordService stockOutRecordService;
    private SalesLedgerProductMapper salesLedgerProductMapper;
    private StockUtils stockUtils;
    @Override
    public IPage<StockInventoryDto> pagestockInventory(Page page, StockInventoryDto stockInventoryDto) {
        return stockInventoryMapper.pagestockInventory(page, stockInventoryDto);
@@ -102,20 +109,28 @@
    }
    @Override
    public Boolean importStockInventory(MultipartFile file) {
    public R importStockInventory(MultipartFile file) {
        try {
            final StringBuffer[] errorMsg = {new StringBuffer()};
            //查询所有的产品
            List<SalesLedgerProduct> salesLedgerProducts =salesLedgerProductMapper.selectProduct();
            ExcelUtil<StockInventoryExportData> util = new ExcelUtil<StockInventoryExportData>(StockInventoryExportData.class);
            List<StockInventoryExportData> list = util.importExcel(file.getInputStream());
            ArrayList<StockInventory> stockInventories = new ArrayList<>();
            list.stream().forEach(dto -> {
               // TODO: 2026/1/21 添加入库记录
                salesLedgerProducts.stream().forEach(item->{
                    if (item.getProductCategory().equals(dto.getProductName())&&item.getSpecificationModel().equals(dto.getModel())) {
                            //更新库存
                            stockUtils.addStock(item.getId(),dto.getQualitity(), StockQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_IN.getCode(),0L);
                    }else {
                        errorMsg[0] = errorMsg[0].append("产品名称:"+dto.getProductName()+"规格:"+dto.getModel()+"不存在").append("\n");
                    }
            });
            this.saveOrUpdateBatch(stockInventories);
            return true;
            });
            return R.ok(errorMsg[0]);
        }catch (Exception e){
            e.printStackTrace();
        }
        return false;
        return R.fail();
    }
}