From 189fe18f9aaabc39cc4bb4cc00f531bc43fe152e Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期二, 09 六月 2026 16:20:30 +0800
Subject: [PATCH] 新增台账时增加库存类型
---
src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java | 93 ++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 84 insertions(+), 9 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
index 15b56ea..d5b203b 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
@@ -26,9 +26,14 @@
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.sales.mapper.ShippingInfoMapper;
import com.ruoyi.sales.mapper.ShippingProductDetailMapper;
+import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.pojo.ShippingInfo;
import com.ruoyi.sales.pojo.ShippingProductDetail;
import com.ruoyi.sales.service.ShippingInfoService;
+import com.ruoyi.stock.dto.StockInventoryDto;
+import com.ruoyi.stock.dto.StockUninventoryDto;
+import com.ruoyi.stock.service.StockInventoryService;
+import com.ruoyi.stock.service.StockUninventoryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
@@ -62,6 +67,8 @@
private final ShippingProductDetailMapper shippingProductDetailMapper;
private final ApprovalTemplateMapper approvalTemplateMapper;
private final ApprovalInstanceService approvalInstanceService;
+ private final StockInventoryService stockInventoryService;
+ private final StockUninventoryService stockUninventoryService;
@Override
public IPage<ShippingInfoDto> listPage(Page page, ShippingInfo req) {
@@ -85,7 +92,7 @@
throw new RuntimeException("鍙戣揣淇℃伅涓嶅瓨鍦�");
}
for (ShippingProductDetail shippingProductDetail : shippingProductDetails) {
- stockUtils.substractStock(shippingProductDetail.getProductModelId(), shippingProductDetail.getQuantity(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId(), shippingProductDetail.getBatchNo());
+ addShippingStockOutRecord(shippingProductDetail, req.getId());
}
}
byId.setExpressNumber(req.getExpressNumber());
@@ -142,12 +149,13 @@
@Override
public boolean add(ShippingInfoDto req) {
+ String ledgerStockType = resolveLedgerStockType(req.getSalesLedgerProductId());
this.save(req);
- req.getBatchNoDetailList().forEach(item -> item.setShippingInfoId(req.getId()));
+ req.getBatchNoDetailList().forEach(item -> {
+ item.setShippingInfoId(req.getId());
+ item.setStockType(ledgerStockType);
+ });
shippingProductDetailMapper.insert(req.getBatchNoDetailList());
- for (ShippingProductDetail shippingProductDetail : req.getBatchNoDetailList()) {
- stockUtils.substractStock(shippingProductDetail.getProductModelId(), shippingProductDetail.getQuantity(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId(), shippingProductDetail.getBatchNo());
- }
// 淇濆瓨鏂囦欢
fileUtil.saveStorageAttachment(ApplicationTypeEnum.IMAGE, RecordTypeEnum.SHIPPING_INFO, req.getId(), req.getStorageBlobDTOs());
return true;
@@ -172,7 +180,7 @@
@Override
public boolean addReq(ShippingInfoDto req) {
- LoginUser loginUser = SecurityUtils.getLoginUser();
+ LoginUser loginUser = SecurityUtils.getLoginUser();
String sh = OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH","shipping_no",req.getCreateTime());
// 鍏堜繚瀛樺彂璐у崟锛屽啀鍙戣捣瀹℃壒锛涙棤瀹℃牳浜鸿嚜鍔ㄩ�氳繃鏃堕渶瑕佹寜鍙戣揣缂栧彿鍥炲啓鍙戣揣鐘舵�併��
req.setShippingNo(sh);
@@ -180,16 +188,83 @@
boolean save = this.add(req);
// 鍙戣揣瀹℃壒
ApprovalInstanceDto approvalInstance = new ApprovalInstanceDto();
- approvalInstance.setTemplateId(approvalTemplateMapper.selectOne(new LambdaQueryWrapper<ApprovalTemplate>().eq(ApprovalTemplate::getBusinessType,6L).orderByDesc(ApprovalTemplate::getId).last("LIMIT 1")).getId());
- approvalInstance.setTemplateName(approvalTemplateMapper.selectOne(new LambdaQueryWrapper<ApprovalTemplate>().eq(ApprovalTemplate::getBusinessType,6L).orderByDesc(ApprovalTemplate::getId).last("LIMIT 1")).getTemplateName());
+ approvalInstance.setTemplateId(approvalTemplateMapper.selectOne(new LambdaQueryWrapper<ApprovalTemplate>().eq(ApprovalTemplate::getBusinessType,7L).orderByDesc(ApprovalTemplate::getId).last("LIMIT 1")).getId());
+ approvalInstance.setTemplateName(approvalTemplateMapper.selectOne(new LambdaQueryWrapper<ApprovalTemplate>().eq(ApprovalTemplate::getBusinessType,7L).orderByDesc(ApprovalTemplate::getId).last("LIMIT 1")).getTemplateName());
approvalInstance.setBusinessId(req.getId());
approvalInstance.setBusinessType(7L);
approvalInstance.setCurrentLevel(1);
- approvalInstance.setTitle(sh+"瀹℃壒");
+ approvalInstance.setTitle(sh);
approvalInstance.setApplicantId(loginUser.getUserId());
approvalInstance.setApplicantName(loginUser.getNickName());
approvalInstance.setApplyTime(LocalDateTime.now());
approvalInstanceService.add(approvalInstance);
return true;
}
+
+ private void addShippingStockOutRecord(ShippingProductDetail shippingProductDetail, Long shippingInfoId) {
+ ShippingInfo shippingInfo = this.getById(shippingInfoId);
+ String stockType = resolveLedgerStockType(shippingInfo != null ? shippingInfo.getSalesLedgerProductId() : null);
+ if (stockType == null) {
+ stockType = normalizeStockType(shippingProductDetail.getStockType());
+ }
+ String detailStockType = normalizeStockType(shippingProductDetail.getStockType());
+ if (detailStockType != null && stockType != null && !stockType.equals(detailStockType)) {
+ throw new RuntimeException("鍙戣揣鏄庣粏搴撳瓨绫诲瀷涓庨攢鍞彴璐︿骇鍝佸簱瀛樼被鍨嬩笉涓�鑷�");
+ }
+ if ("waste".equals(stockType)) {
+ StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
+ stockUninventoryDto.setRecordId(shippingInfoId);
+ stockUninventoryDto.setRecordType(StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode());
+ stockUninventoryDto.setQualitity(shippingProductDetail.getQuantity());
+ stockUninventoryDto.setProductModelId(shippingProductDetail.getProductModelId());
+ stockUninventoryDto.setBatchNo(normalizeBatchNo(shippingProductDetail.getBatchNo()));
+ stockUninventoryDto.setType("waste");
+ stockUninventoryService.addStockOutRecordOnly(stockUninventoryDto);
+ return;
+ }
+ if (!"qualified".equals(stockType)) {
+ throw new RuntimeException("鍙戣揣鏄庣粏搴撳瓨绫诲瀷鏃犳晥锛屽彧鏀寔 qualified 鎴� waste");
+ }
+ StockInventoryDto stockInventoryDto = new StockInventoryDto();
+ stockInventoryDto.setRecordId(shippingInfoId);
+ stockInventoryDto.setRecordType(StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode());
+ stockInventoryDto.setQualitity(shippingProductDetail.getQuantity());
+ stockInventoryDto.setProductModelId(shippingProductDetail.getProductModelId());
+ stockInventoryDto.setBatchNo(normalizeBatchNo(shippingProductDetail.getBatchNo()));
+ stockInventoryService.addStockOutRecordOnly(stockInventoryDto);
+ }
+
+ private String normalizeBatchNo(String batchNo) {
+ if (batchNo == null) {
+ return null;
+ }
+ String normalized = batchNo.trim();
+ return normalized.isEmpty() ? null : normalized;
+ }
+
+ private String normalizeStockType(String stockType) {
+ if (stockType == null) {
+ return null;
+ }
+ String normalized = stockType.trim().toLowerCase();
+ if (normalized.isEmpty()) {
+ return null;
+ }
+ if ("unqualified".equals(normalized)) {
+ return "waste";
+ }
+ return normalized;
+ }
+
+ private String resolveLedgerStockType(Long salesLedgerProductId) {
+ if (salesLedgerProductId == null) {
+ return null;
+ }
+ SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(salesLedgerProductId);
+ if (salesLedgerProduct == null) {
+ throw new RuntimeException("閿�鍞彴璐︿骇鍝佷笉瀛樺湪");
+ }
+ String stockType = normalizeStockType(salesLedgerProduct.getStockType());
+ return stockType == null ? "qualified" : stockType;
+ }
}
--
Gitblit v1.9.3