From cdf2005b0dcb458b747958ebe808931914815541 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期二, 27 一月 2026 16:41:16 +0800
Subject: [PATCH] fix(enum): 代码迁移
---
src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java | 98 +++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 82 insertions(+), 16 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 35e2f13..99c4544 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -4,7 +4,7 @@
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.enums.StockQualifiedRecordTypeEnum;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.domain.R;
@@ -14,11 +14,10 @@
import com.ruoyi.stock.dto.StockInventoryDto;
import com.ruoyi.stock.dto.StockOutRecordDto;
import com.ruoyi.stock.execl.StockInventoryExportData;
-import com.ruoyi.stock.pojo.StockInventory;
import com.ruoyi.stock.mapper.StockInventoryMapper;
+import com.ruoyi.stock.pojo.StockInventory;
import com.ruoyi.stock.service.StockInRecordService;
import com.ruoyi.stock.service.StockInventoryService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.stock.service.StockOutRecordService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
@@ -26,6 +25,7 @@
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -70,6 +70,8 @@
newStockInventory.setQualitity(stockInventoryDto.getQualitity());
newStockInventory.setVersion(1);
newStockInventory.setRemark(stockInventoryDto.getRemark());
+ newStockInventory.setLockedQuantity(stockInventoryDto.getLockedQuantity());
+ newStockInventory.setWarnNum(stockInventoryDto.getWarnNum());
stockInventoryMapper.insert(newStockInventory);
}else {
stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
@@ -90,6 +92,9 @@
stockOutRecordDto.setType("0");
stockOutRecordService.add(stockOutRecordDto);
StockInventory oldStockInventory = stockInventoryMapper.selectOne(new QueryWrapper<StockInventory>().lambda().eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId()));
+ if (stockInventoryDto.getQualitity().compareTo( oldStockInventory.getQualitity().subtract(oldStockInventory.getLockedQuantity()))>0) {
+ throw new RuntimeException("搴撳瓨涓嶈冻鏃犳硶鍑哄簱");
+ }
if (ObjectUtils.isEmpty(oldStockInventory)) {
throw new RuntimeException("浜у搧搴撳瓨涓嶅瓨鍦�");
}else {
@@ -101,32 +106,59 @@
@Override
public R importStockInventory(MultipartFile file) {
try {
- final StringBuffer[] errorMsg = {new StringBuffer()};
- //鏌ヨ鎵�鏈夌殑浜у搧
- List<SalesLedgerProduct> salesLedgerProducts =salesLedgerProductMapper.selectProduct();
+ // 鏌ヨ鎵�鏈夌殑浜у搧
+ 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())) {
- //鏇存柊搴撳瓨
+
+ // 璁板綍鏈壘鍒板尮閰嶉」鐨勬暟鎹�
+ 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.setWarnNum(dto.getWarnNum());
+ if (ObjectUtils.isNotEmpty(dto.getLockedQuantity())&&dto.getLockedQuantity().compareTo(dto.getQualitity())>0) {
+ throw new RuntimeException("鍐荤粨鏁伴噺涓嶈兘瓒呰繃鏈瀵煎叆鐨勫簱瀛樻暟閲�");
+ }
+ stockInventoryDto.setLockedQuantity(dto.getLockedQuantity());
stockInventoryDto.setProductModelId(item.getProductModelId());
- this.addstockInventory(stockInventoryDto); }else {
- errorMsg[0] = errorMsg[0].append("浜у搧鍚嶇О锛�"+dto.getProductName()+"瑙勬牸锛�"+dto.getModel()+"涓嶅瓨鍦�").append("\n");
+ this.addstockInventory(stockInventoryDto);
+ matched = true;
+ break; // 鎵惧埌鍖归厤椤瑰悗璺冲嚭寰幆
}
- });
+ }
+ if (!matched) {
+ // 璁板綍鏈尮閰嶇殑鏁版嵁
+ String unmatchedInfo = String.format("浜у搧鍚嶇О锛�%s锛岃鏍煎瀷鍙凤細%s",
+ dto.getProductName(), dto.getModel());
+ unmatchedRecords.add(unmatchedInfo);
+ }
});
- return R.ok(errorMsg[0]);
- }catch (Exception e){
+ // 鏋勫缓杩斿洖淇℃伅
+ 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.fail();
+ return R.ok("瀵煎叆鎴愬姛");
}
+
@Override
public void exportStockInventory(HttpServletResponse response, StockInventoryDto stockInventoryDto) {
@@ -135,4 +167,38 @@
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);
+ }
+
+ @Override
+ public Boolean frozenStock(StockInventoryDto stockInventoryDto) {
+ StockInventory stockInventory = stockInventoryMapper.selectById(stockInventoryDto.getId());
+ if (stockInventory.getQualitity().compareTo(stockInventoryDto.getLockedQuantity())<0) {
+ throw new RuntimeException("鍐荤粨鏁伴噺涓嶈兘瓒呰繃搴撳瓨鏁伴噺");
+ }
+ if (ObjectUtils.isEmpty(stockInventory.getLockedQuantity())) {
+ stockInventory.setLockedQuantity(stockInventoryDto.getLockedQuantity());
+ }else {
+ stockInventory.setLockedQuantity(stockInventory.getLockedQuantity().add(stockInventoryDto.getLockedQuantity()));
+ }
+ return this.updateById(stockInventory);
+ }
+
+ @Override
+ public Boolean thawStock(StockInventoryDto stockInventoryDto) {
+ StockInventory stockInventory = stockInventoryMapper.selectById(stockInventoryDto.getId());
+ if (stockInventory.getLockedQuantity().compareTo(stockInventoryDto.getLockedQuantity())<0) {
+ throw new RuntimeException("瑙e喕鏁伴噺涓嶈兘瓒呰繃鍐荤粨鏁伴噺");
+ }
+ stockInventory.setLockedQuantity(stockInventory.getLockedQuantity().subtract(stockInventoryDto.getLockedQuantity()));
+ return this.updateById(stockInventory);
+ }
}
--
Gitblit v1.9.3