From 03386a78c3a1f92efa21a6748e38c2c5d1c996d9 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期二, 27 一月 2026 10:57:12 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_New' into dev_New
---
src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java | 84 +++++++++++++++++++++++++++++------------
1 files changed, 59 insertions(+), 25 deletions(-)
diff --git a/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java b/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
index 7b3ee2c..e103f75 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -4,11 +4,9 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.ruoyi.account.pojo.BorrowInfo;
import com.ruoyi.common.enums.StockQualifiedRecordTypeEnum;
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;
@@ -27,6 +25,7 @@
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -45,7 +44,6 @@
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,29 +100,55 @@
@Override
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());
-// list.stream().forEach(dto -> {
-// 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");
-// }
-// });
-// });
-// return R.ok(errorMsg[0]);
-// }catch (Exception e){
-// e.printStackTrace();
-// }
- return R.fail();
+ try {
+ // 鏌ヨ鎵�鏈夌殑浜у搧
+ List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectProduct();
+
+ ExcelUtil<StockInventoryExportData> util = new ExcelUtil<StockInventoryExportData>(StockInventoryExportData.class);
+ List<StockInventoryExportData> list = util.importExcel(file.getInputStream());
+
+ // 璁板綍鏈壘鍒板尮閰嶉」鐨勬暟鎹�
+ List<String> unmatchedRecords = new ArrayList<>();
+
+ list.forEach(dto -> {
+ boolean matched = false;
+ for (SalesLedgerProduct item : salesLedgerProducts) {
+ if (item.getProductCategory().equals(dto.getProductName()) &&
+ item.getSpecificationModel().equals(dto.getModel())) {
+ StockInventoryDto stockInventoryDto = new StockInventoryDto();
+ stockInventoryDto.setRecordId(0L);
+ stockInventoryDto.setRecordType(StockQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_IN.getCode());
+ stockInventoryDto.setQualitity(dto.getQualitity());
+ stockInventoryDto.setRemark(dto.getRemark());
+ stockInventoryDto.setProductModelId(item.getProductModelId());
+ this.addstockInventory(stockInventoryDto);
+ matched = true;
+ break; // 鎵惧埌鍖归厤椤瑰悗璺冲嚭寰幆
+ }
+ }
+ if (!matched) {
+ // 璁板綍鏈尮閰嶇殑鏁版嵁
+ String unmatchedInfo = String.format("浜у搧鍚嶇О锛�%s锛岃鏍煎瀷鍙凤細%s",
+ dto.getProductName(), dto.getModel());
+ unmatchedRecords.add(unmatchedInfo);
+ }
+ });
+ // 鏋勫缓杩斿洖淇℃伅
+ StringBuilder message = new StringBuilder();
+ if (!unmatchedRecords.isEmpty()) {
+ message.append("浠ヤ笅浜у搧鏈壘鍒板尮閰嶉」锛歕n");
+ for (String record : unmatchedRecords) {
+ message.append(record).append("\n");
+ }
+ throw new RuntimeException(message.toString());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return R.fail("瀵煎叆澶辫触锛�" + e.getMessage());
+ }
+ return R.ok("瀵煎叆鎴愬姛");
}
+
@Override
public void exportStockInventory(HttpServletResponse response, StockInventoryDto stockInventoryDto) {
@@ -133,4 +157,14 @@
ExcelUtil<StockInventoryExportData> util = new ExcelUtil<>(StockInventoryExportData.class);
util.exportExcel(response,list, "搴撳瓨淇℃伅");
}
+
+ @Override
+ public IPage<StockInRecordDto> stockInventoryPage(StockInventoryDto stockInventoryDto, Page page) {
+ return stockInventoryMapper.stockInventoryPage(stockInventoryDto,page);
+ }
+
+ @Override
+ public IPage<StockInventoryDto> stockInAndOutRecord(StockInventoryDto stockInventoryDto, Page page) {
+ return stockInventoryMapper.stockInAndOutRecord(stockInventoryDto,page);
+ }
}
--
Gitblit v1.9.3