From ba4f2ca4b3ae845d2bd1e92338b948a8f95ffaaa Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期二, 09 六月 2026 15:11:27 +0800
Subject: [PATCH] 修改废品入库类型
---
src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java | 53 ++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 48 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java b/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
index 2436940..81e6ae9 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
@@ -36,11 +36,15 @@
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.util.List;
@Service
@AllArgsConstructor
public class StockInRecordServiceImpl extends ServiceImpl<StockInRecordMapper, StockInRecord> implements StockInRecordService {
+
+ private static final String UNQUALIFIED_TYPE = "unqualified";
+ private static final String WASTE_TYPE = "waste";
private StockInRecordMapper stockInRecordMapper;
private StockInventoryMapper stockInventoryMapper;
@@ -100,9 +104,11 @@
stockInRecordDto.setQualitity(stockInRecord.getStockInNum());
stockInventoryMapper.updateSubtractStockInventory(stockInRecordDto);
}
- }else if (stockInRecord.getType().equals("1")) {
+ }else if (stockInRecord.getType().equals("1") || stockInRecord.getType().equals("2")) {
+ String uninventoryType = resolveUninventoryTypeByInRecordType(stockInRecord.getType());
LambdaQueryWrapper<StockUninventory> eq = new LambdaQueryWrapper<StockUninventory>()
- .eq(StockUninventory::getProductModelId, stockInRecord.getProductModelId());
+ .eq(StockUninventory::getProductModelId, stockInRecord.getProductModelId())
+ .eq(StockUninventory::getType, uninventoryType);
if (StringUtils.isEmpty(stockInRecord.getBatchNo())) {
eq.isNull(StockUninventory::getBatchNo);
} else {
@@ -116,6 +122,7 @@
stockUninventoryDto.setProductModelId(stockUninventory.getProductModelId());
stockUninventoryDto.setBatchNo(stockUninventory.getBatchNo());
stockUninventoryDto.setQualitity(stockInRecord.getStockInNum());
+ stockUninventoryDto.setType(uninventoryType);
stockUninventoryMapper.updateSubtractStockUnInventory(stockUninventoryDto);
}
}
@@ -148,9 +155,12 @@
return stockInventoryMapper.selectOne(eq);
}
- private StockUninventory getStockUninventory(Long productModelId, String batchNo) {
+ private StockUninventory getStockUninventory(Long productModelId, String batchNo, String uninventoryType) {
LambdaQueryWrapper<StockUninventory> eq = new LambdaQueryWrapper<>();
eq.eq(StockUninventory::getProductModelId, productModelId);
+ if (StringUtils.isNotEmpty(uninventoryType)) {
+ eq.eq(StockUninventory::getType, uninventoryType);
+ }
if (StringUtils.isEmpty(batchNo)) {
eq.isNull(StockUninventory::getBatchNo);
} else {
@@ -231,6 +241,7 @@
final BigDecimal finalStockInNum;
if (item.getStockInNum() != null && item.getStockInNum().compareTo(BigDecimal.ZERO) > 0) {
finalStockInNum = item.getStockInNum();
+ adjustPurchaseInboundAuditFields(stockInRecord, finalStockInNum);
// 鏇存柊鍏ュ簱璁板綍鐨勫叆搴撴暟閲�
stockInRecord.setStockInNum(finalStockInNum);
} else {
@@ -267,9 +278,10 @@
} else {
stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
}
- } else if ("1".equals(stockInRecord.getType())) {
+ } else if ("1".equals(stockInRecord.getType()) || "2".equals(stockInRecord.getType())) {
// 涓嶅悎鏍煎叆搴� -> 鍏堟煡搴撳瓨锛屽瓨鍦ㄥ垯鏇存柊锛屼笉瀛樺湪鍒欐柊澧�
- StockUninventory stockUninventory = getStockUninventory(stockInRecord.getProductModelId(), stockInRecord.getBatchNo());
+ String uninventoryType = resolveUninventoryTypeByInRecordType(stockInRecord.getType());
+ StockUninventory stockUninventory = getStockUninventory(stockInRecord.getProductModelId(), stockInRecord.getBatchNo(), uninventoryType);
StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
stockUninventoryDto.setProductModelId(stockInRecord.getProductModelId());
stockUninventoryDto.setBatchNo(stockInRecord.getBatchNo());
@@ -277,11 +289,13 @@
stockUninventoryDto.setRemark(stockInRecord.getRemark());
stockUninventoryDto.setManufacturerId(stockInRecord.getManufacturerId());
stockUninventoryDto.setSource(stockInRecord.getSource());
+ stockUninventoryDto.setType(uninventoryType);
if (stockUninventory == null) {
stockUninventoryMapper.insert(new StockUninventory() {{
setProductModelId(stockInRecord.getProductModelId());
setQualitity(finalStockInNum);
setBatchNo(stockInRecord.getBatchNo());
+ setType(uninventoryType);
setRemark(stockInRecord.getRemark());
setManufacturerId(stockInRecord.getManufacturerId());
setSource(stockInRecord.getSource());
@@ -296,6 +310,35 @@
return items.size();
}
+ private String resolveUninventoryTypeByInRecordType(String stockInType) {
+ if ("2".equals(stockInType)) {
+ return WASTE_TYPE;
+ }
+ return UNQUALIFIED_TYPE;
+ }
+
+ private void adjustPurchaseInboundAuditFields(StockInRecord stockInRecord, BigDecimal finalStockInNum) {
+ if (stockInRecord == null || finalStockInNum == null) {
+ return;
+ }
+ if (!StockInQualifiedRecordTypeEnum.PURCHASE_STOCK_IN.getCode().equals(stockInRecord.getRecordType())) {
+ return;
+ }
+ BigDecimal theoryStockInNum = stockInRecord.getTheoryStockInNum();
+ if (theoryStockInNum == null || theoryStockInNum.compareTo(BigDecimal.ZERO) <= 0) {
+ return;
+ }
+ if (finalStockInNum.compareTo(theoryStockInNum) > 0) {
+ throw new BaseException("閲囪喘鍏ュ簱瀹℃牳鏃讹紝瀹為檯鍏ュ簱鏁伴噺涓嶈兘澶т簬鐞嗚鍏ュ簱鏁伴噺");
+ }
+ if (Boolean.TRUE.equals(stockInRecord.getIsContainsWater())) {
+ BigDecimal waterContent = theoryStockInNum.subtract(finalStockInNum)
+ .multiply(new BigDecimal("100"))
+ .divide(theoryStockInNum, 4, RoundingMode.HALF_UP);
+ stockInRecord.setWaterContent(waterContent);
+ }
+ }
+
private static @NonNull StockInventoryDto getStockInventoryDto(StockInRecord stockInRecord) {
StockInventoryDto stockInventoryDto = new StockInventoryDto();
stockInventoryDto.setProductModelId(stockInRecord.getProductModelId());
--
Gitblit v1.9.3