From 47806d9e390ee00e1d29ad1da8c1aa908882a758 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期二, 11 八月 2026 14:43:59 +0800
Subject: [PATCH] 用河南鹤壁代码覆盖山西长治
---
src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java | 163 +++++++++++++++++++++++-------------------------------
1 files changed, 70 insertions(+), 93 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 00161b5..5fbc6b3 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
@@ -13,22 +13,12 @@
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
-
-import java.time.LocalDateTime;
import com.ruoyi.stock.dto.StockInRecordDto;
import com.ruoyi.stock.dto.StockInventoryDto;
import com.ruoyi.stock.dto.StockUninventoryDto;
import com.ruoyi.stock.execl.StockInRecordExportData;
import com.ruoyi.production.mapper.ProductionOrderPickMapper;
import com.ruoyi.production.pojo.ProductionOrderPick;
-import com.ruoyi.procurementrecord.mapper.ReturnManagementMapper;
-import com.ruoyi.procurementrecord.mapper.ReturnSaleProductMapper;
-import com.ruoyi.procurementrecord.pojo.ReturnManagement;
-import com.ruoyi.procurementrecord.pojo.ReturnSaleProduct;
-import com.ruoyi.sales.mapper.SalesLedgerMapper;
-import com.ruoyi.sales.mapper.ShippingInfoMapper;
-import com.ruoyi.sales.pojo.SalesLedger;
-import com.ruoyi.sales.pojo.ShippingInfo;
import com.ruoyi.stock.mapper.StockInRecordMapper;
import com.ruoyi.stock.mapper.StockInventoryMapper;
import com.ruoyi.stock.mapper.StockUninventoryMapper;
@@ -53,10 +43,6 @@
private StockInventoryMapper stockInventoryMapper;
private StockUninventoryMapper stockUninventoryMapper;
private ProductionOrderPickMapper productionOrderPickMapper;
- private ReturnSaleProductMapper returnSaleProductMapper;
- private ReturnManagementMapper returnManagementMapper;
- private ShippingInfoMapper shippingInfoMapper;
- private SalesLedgerMapper salesLedgerMapper;
@Override
public IPage<StockInRecordDto> listPage(Page page, StockInRecordDto stockInRecordDto) {
@@ -66,17 +52,13 @@
// 鏂板鍏ュ簱
@Override
@Transactional(rollbackFor = Exception.class)
- public int add(StockInRecordDto stockInRecordDto) {
- LocalDateTime createTime = stockInRecordDto.getCreateTime();
- if (createTime == null) {
- createTime = LocalDateTime.now();
- }
- String no = OrderUtils.countTodayByCreateTime(stockInRecordMapper, "RK","inbound_batches", createTime);
+ public StockInRecord add(StockInRecordDto stockInRecordDto) {
+ String no = OrderUtils.countTodayByCreateTime(stockInRecordMapper, "RK","inbound_batches");
stockInRecordDto.setInboundBatches(no);
- stockInRecordDto.setCreateTime(createTime);
StockInRecord stockInRecord = new StockInRecord();
BeanUtils.copyProperties(stockInRecordDto, stockInRecord);
- return stockInRecordMapper.insert(stockInRecord);
+ stockInRecordMapper.insert(stockInRecord);
+ return stockInRecord;
}
@Override
@@ -88,9 +70,56 @@
throw new BaseException("璇ュ叆搴撹褰曚笉瀛樺湪,鏃犳硶鏇存柊!!!");
}
+ // 璁板綍淇敼鍓嶇殑 batch_no
+ String oldBatchNo = stockInRecord.getBatchNo();
+ String newBatchNo = stockInRecordDto.getBatchNo();
+
String[] ignoreProperties = {"id", "inbound_batches"};//鎺掗櫎id灞炴��
BeanUtils.copyProperties(stockInRecordDto, stockInRecord, ignoreProperties);
- return stockInRecordMapper.updateById(stockInRecord);
+ int result = stockInRecordMapper.updateById(stockInRecord);
+
+ // 濡傛灉 batch_no 鍙戠敓鍙樺寲锛岄渶瑕佸悓姝ユ洿鏂板叧鑱旇〃
+ if (newBatchNo != null && !newBatchNo.equals(oldBatchNo)) {
+ updateRelatedBatchNo(stockInRecord, oldBatchNo, newBatchNo);
+ }
+
+ return result;
+ }
+
+ /**
+ * 鍚屾鏇存柊鍏宠仈琛ㄧ殑 batch_no
+ * @param stockInRecord 鍏ュ簱璁板綍
+ * @param oldBatchNo 淇敼鍓嶇殑鎵瑰彿
+ * @param newBatchNo 淇敼鍚庣殑鎵瑰彿
+ */
+ private void updateRelatedBatchNo(StockInRecord stockInRecord, String oldBatchNo, String newBatchNo) {
+ // 1. 鏇存柊 stock_inventory 琛紙鍚堟牸搴撳瓨锛�
+ LambdaQueryWrapper<StockInventory> inventoryEq = new LambdaQueryWrapper<StockInventory>()
+ .eq(StockInventory::getProductModelId, stockInRecord.getProductModelId());
+ if (StringUtils.isEmpty(oldBatchNo)) {
+ inventoryEq.isNull(StockInventory::getBatchNo);
+ } else {
+ inventoryEq.eq(StockInventory::getBatchNo, oldBatchNo);
+ }
+ StockInventory stockInventory = stockInventoryMapper.selectOne(inventoryEq);
+ if (stockInventory != null) {
+ stockInventory.setBatchNo(newBatchNo);
+ stockInventoryMapper.updateById(stockInventory);
+ }
+
+ // 2. 鏇存柊 stock_uninventory 琛紙涓嶅悎鏍煎簱瀛橈級
+ LambdaQueryWrapper<StockUninventory> uninventoryEq = new LambdaQueryWrapper<StockUninventory>()
+ .eq(StockUninventory::getProductModelId, stockInRecord.getProductModelId());
+ if (StringUtils.isEmpty(oldBatchNo)) {
+ uninventoryEq.isNull(StockUninventory::getBatchNo);
+ } else {
+ uninventoryEq.eq(StockUninventory::getBatchNo, oldBatchNo);
+ }
+ StockUninventory stockUninventory = stockUninventoryMapper.selectOne(uninventoryEq);
+ if (stockUninventory != null) {
+ stockUninventory.setBatchNo(newBatchNo);
+ stockUninventoryMapper.updateById(stockUninventory);
+ }
}
@Override
@@ -235,9 +264,9 @@
if (stockInRecord == null) {
throw new BaseException("鍏ュ簱璁板綍涓嶅瓨鍦�,鏃犳硶瀹℃壒!!!");
}
- if (stockInRecord.getApprovalStatus() != null && !ReviewStatusEnum.PENDING_REVIEW.getCode().equals(stockInRecord.getApprovalStatus())) {
+ /*if (stockInRecord.getApprovalStatus() != null && !ReviewStatusEnum.PENDING_REVIEW.getCode().equals(stockInRecord.getApprovalStatus())) {
throw new BaseException("鍙湁寰呭鎵圭姸鎬佺殑璁板綍鎵嶈兘瀹℃壒,鍏ュ簱鎵规:" + stockInRecord.getInboundBatches());
- }
+ }*/
stockInRecord.setApprovalStatus(approvalStatus);
stockInRecordMapper.updateById(stockInRecord);
@@ -257,19 +286,16 @@
stockInventoryDto.setBatchNo(stockInRecord.getBatchNo());
stockInventoryDto.setQualitity(stockInRecord.getStockInNum());
stockInventoryDto.setRemark(stockInRecord.getRemark());
+ stockInventoryDto.setWarnNum(stockInRecord.getWarnNum());
if (stockInventory == null) {
- try {
- stockInventoryMapper.insert(new StockInventory() {{
- setProductModelId(stockInRecord.getProductModelId());
- setQualitity(stockInRecord.getStockInNum());
- setBatchNo(stockInRecord.getBatchNo());
- setRemark(stockInRecord.getRemark());
- setWarnNum(stockInRecord.getWarnNum());
- setVersion(1);
- }});
- } catch (org.springframework.dao.DuplicateKeyException e) {
- stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
- }
+ stockInventoryMapper.insert(new StockInventory() {{
+ setProductModelId(stockInRecord.getProductModelId());
+ setQualitity(stockInRecord.getStockInNum());
+ setWarnNum(stockInRecord.getWarnNum());
+ setBatchNo(stockInRecord.getBatchNo());
+ setRemark(stockInRecord.getRemark());
+ setVersion(1);
+ }});
} else {
stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
}
@@ -282,23 +308,17 @@
stockUninventoryDto.setQualitity(stockInRecord.getStockInNum());
stockUninventoryDto.setRemark(stockInRecord.getRemark());
if (stockUninventory == null) {
- try {
- stockUninventoryMapper.insert(new StockUninventory() {{
- setProductModelId(stockInRecord.getProductModelId());
- setQualitity(stockInRecord.getStockInNum());
- setBatchNo(stockInRecord.getBatchNo());
- setRemark(stockInRecord.getRemark());
- setVersion(1);
- }});
- } catch (org.springframework.dao.DuplicateKeyException e) {
- stockUninventoryMapper.updateAddStockUnInventory(stockUninventoryDto);
- }
+ stockUninventoryMapper.insert(new StockUninventory() {{
+ setProductModelId(stockInRecord.getProductModelId());
+ setQualitity(stockInRecord.getStockInNum());
+ setBatchNo(stockInRecord.getBatchNo());
+ setRemark(stockInRecord.getRemark());
+ setVersion(1);
+ }});
} else {
stockUninventoryMapper.updateAddStockUnInventory(stockUninventoryDto);
}
}
- // 閿�鍞��璐у叆搴�:鎵e噺閿�鍞彴璐﹀疄闄呭悎鍚岄噾棰�(閫�璐х敓鏁�)
- handleSalesReturnRefund(stockInRecord);
}
}
return ids.size();
@@ -348,48 +368,5 @@
}
return ids.size();
- }
-
- /**
- * 閿�鍞��璐у叆搴撳鎵归�氳繃鏃�,鎵e噺瀵瑰簲閿�鍞彴璐︾殑瀹為檯鍚堝悓閲戦銆�
- * 鍏宠仈閾�:stock_in_record.record_id = return_sale_product.id
- * 鈫� return_management.shipping_id = shipping_info.id
- * 鈫� shipping_info.sales_ledger_id = sales_ledger.id
- * 鍙鐞� record_type 涓� 14(鍚堟牸)鎴� 15(涓嶅悎鏍�)鐨勯攢鍞��璐у叆搴撱��
- */
- private void handleSalesReturnRefund(StockInRecord stockInRecord) {
- String recordType = stockInRecord.getRecordType();
- if (!StockInQualifiedRecordTypeEnum.RETURN_HE_IN.getCode().equals(recordType)
- && !StockInQualifiedRecordTypeEnum.RETURN_UNSTOCK_IN.getCode().equals(recordType)) {
- return;
- }
- if (stockInRecord.getRecordId() == null) {
- return;
- }
- ReturnSaleProduct rsp = returnSaleProductMapper.selectById(stockInRecord.getRecordId());
- if (rsp == null || rsp.getReturnManagementId() == null) {
- return;
- }
- ReturnManagement rm = returnManagementMapper.selectById(rsp.getReturnManagementId());
- if (rm == null || rm.getShippingId() == null) {
- return;
- }
- ShippingInfo shippingInfo = shippingInfoMapper.selectById(rm.getShippingId());
- if (shippingInfo == null || shippingInfo.getSalesLedgerId() == null) {
- return;
- }
- SalesLedger salesLedger = salesLedgerMapper.selectById(shippingInfo.getSalesLedgerId());
- if (salesLedger == null || salesLedger.getContractAmount() == null) {
- return;
- }
- BigDecimal refund = rsp.getAmount() != null ? rsp.getAmount() : BigDecimal.ZERO;
- if (refund.compareTo(BigDecimal.ZERO) == 0) {
- return;
- }
- BigDecimal baseAmount = salesLedger.getNetContractAmount() != null
- ? salesLedger.getNetContractAmount()
- : salesLedger.getContractAmount();
- salesLedger.setNetContractAmount(baseAmount.subtract(refund));
- salesLedgerMapper.updateById(salesLedger);
}
}
--
Gitblit v1.9.3