From 530b456eded06e0692e1d8bd5891069439c8f8f8 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 17 四月 2026 15:10:56 +0800
Subject: [PATCH] fix: 1.已发货的销售台账对应的出入库记录做限制不能删除;2.销售台账入库操作后,点击删除,对应的销售入库记录未一并删除;3.销售台账入库状态新增部分入库
---
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java | 91 +++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 87 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index c7d988d..4847c22 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -18,6 +18,7 @@
import com.ruoyi.basic.service.ICustomerRegionsService;
import com.ruoyi.common.enums.FileNameType;
import com.ruoyi.common.enums.SaleEnum;
+import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.DateUtils;
@@ -47,6 +48,14 @@
import com.ruoyi.sales.service.ISalesLedgerProductProcessBindService;
import com.ruoyi.sales.service.ISalesLedgerProductProcessService;
import com.ruoyi.sales.service.ISalesLedgerService;
+import com.ruoyi.stock.dto.StockInventoryDto;
+import com.ruoyi.stock.mapper.StockInRecordMapper;
+import com.ruoyi.stock.mapper.StockOutRecordMapper;
+import com.ruoyi.stock.pojo.StockInRecord;
+import com.ruoyi.stock.pojo.StockOutRecord;
+import com.ruoyi.stock.service.StockInRecordService;
+import com.ruoyi.stock.service.StockInventoryService;
+import com.ruoyi.stock.service.StockOutRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
@@ -125,6 +134,12 @@
private final ISalesLedgerProductProcessBindService salesLedgerProductProcessBindService;
private final ISalesLedgerProcessRouteService salesLedgerProcessRouteService;
+
+ private final StockInventoryService stockInventoryService;
+ private final StockInRecordMapper stockInRecordMapper;
+ private final StockOutRecordMapper stockOutRecordMapper;
+ private final StockInRecordService stockInRecordService;
+ private final StockOutRecordService stockOutRecordService;
@Autowired
private SysDeptMapper sysDeptMapper;
@@ -461,7 +476,7 @@
.map(SalesLedgerProductImportDto::getTaxInclusiveTotalPrice)
.reduce(BigDecimal.ZERO, BigDecimal::add));
// 鍙戣揣鐘舵��
- salesLedger.setDeliveryStatus(0);
+ salesLedger.setDeliveryStatus(1);
salesLedgerMapper.insert(salesLedger);
for (SalesLedgerProductImportDto salesLedgerProductImportDto : salesLedgerProductImportDtos) {
@@ -698,6 +713,25 @@
if (CollectionUtils.isNotEmpty(shippingInfos)) {
shippingInfoServiceImpl.delete(shippingInfos.stream().map(ShippingInfo::getId).collect(Collectors.toList()));
}
+ // 鍒犻櫎鍏宠仈鐨勫叆搴�/鍑哄簱璁板綍锛堣蛋鏈嶅姟灞傚垹闄わ紝瑙﹀彂搴撳瓨鏁伴噺鍥為��锛�
+ List<Long> stockInRecordIds = stockInRecordMapper.selectList(new LambdaQueryWrapper<StockInRecord>()
+ .in(StockInRecord::getSalesLedgerId, idList)
+ .select(StockInRecord::getId))
+ .stream()
+ .map(StockInRecord::getId)
+ .collect(Collectors.toList());
+ if (CollectionUtils.isNotEmpty(stockInRecordIds)) {
+ stockInRecordService.batchDelete(stockInRecordIds);
+ }
+ List<Long> stockOutRecordIds = stockOutRecordMapper.selectList(new LambdaQueryWrapper<StockOutRecord>()
+ .in(StockOutRecord::getSalesLedgerId, idList)
+ .select(StockOutRecord::getId))
+ .stream()
+ .map(StockOutRecord::getId)
+ .collect(Collectors.toList());
+ if (CollectionUtils.isNotEmpty(stockOutRecordIds)) {
+ stockOutRecordService.batchDelete(stockOutRecordIds);
+ }
// 鍒犻櫎闄勪欢琛�
commonFileService.deleteByBusinessIds(idList, FileNameType.SALE.getValue());
@@ -727,15 +761,15 @@
SalesLedger salesLedger = convertToEntity(salesLedgerDto);
salesLedger.setCustomerName(customer.getCustomerName());
salesLedger.setTenantId(customer.getTenantId());
- salesLedger.setDeliveryStatus(1);
// 3. 鏂板鎴栨洿鏂颁富琛�
if (salesLedger.getId() == null) {
String contractNo = generateSalesContractNo();
salesLedger.setSalesContractNo(contractNo);
- salesLedger.setDeliveryStatus(0);
+ salesLedger.setDeliveryStatus(1);
+ salesLedger.setStockStatus(0);
salesLedgerMapper.insert(salesLedger);
} else {
- if (salesLedger.getDeliveryStatus() == 1) {
+ if (salesLedger.getDeliveryStatus() == 5) {
throw new ServiceException("璁㈠崟宸插彂璐�,绂佹缂栬緫");
}
salesLedgerMapper.updateById(salesLedger);
@@ -855,6 +889,7 @@
if (!updateList.isEmpty()) {
for (SalesLedgerProduct product : updateList) {
product.setType(type.getCode());
+ product.setProductStockStatus(0);
salesLedgerProductMapper.updateById(product);
// 娓呯┖閿�鍞骇鍝佺粦瀹氱殑鍔犲伐
salesLedgerProductProcessBindService.updateProductProcessBind(product.getSalesProductProcessList(), product.getId());
@@ -867,6 +902,7 @@
salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity());
salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getTaxInclusiveTotalPrice());
salesLedgerProduct.setPendingInvoiceTotal(salesLedgerProduct.getTaxInclusiveTotalPrice());
+ salesLedgerProduct.setProductStockStatus(0);
salesLedgerProductMapper.insert(salesLedgerProduct);
// 缁戝畾浜у搧棰濆鍔犲伐
// 娓呯┖閿�鍞骇鍝佺粦瀹氱殑鍔犲伐
@@ -1501,4 +1537,51 @@
return totalAmount;
}
}
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void salesStock(SalesProductStockDto dto) {
+ if (dto == null || dto.getSalesLedgerId() == null) {
+ throw new NullPointerException("鍏ュ簱澶辫触,璇烽�夋嫨闇�瑕佸叆搴撶殑閿�鍞鍗�");
+ }
+ // 鏌ヨ閿�鍞鍗曟槸鍚﹀瓨鍦�
+ SalesLedger ledger = baseMapper.selectById(dto.getSalesLedgerId());
+ if (ledger == null) {
+ throw new ServiceException("鍏ュ簱澶辫触,閿�鍞鍗曚笉瀛樺湪");
+ }
+ if (ledger.getStockStatus() == null) {
+ throw new ServiceException("鍏ュ簱澶辫触,閿�鍞鍗曞叆搴撶姸鎬佸紓甯�");
+ }
+ if (ledger.getStockStatus() == 2) {
+ throw new ServiceException("鍏ュ簱澶辫触,璇ラ攢鍞鍗曞凡鍏ュ簱,璇峰嬁閲嶅鍏ュ簱");
+ }
+ List<Long> products = dto.getSalesLedgerProducts();
+ if (products == null || products.isEmpty()) {
+ throw new ServiceException("鍏ュ簱澶辫触,鍏ュ簱浜у搧涓嶈兘涓虹┖");
+ }
+ // 鏌ヨ閿�鍞鍗曠殑浜у搧
+ List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(Wrappers.<SalesLedgerProduct>lambdaQuery().in(SalesLedgerProduct::getId, products));
+ if (salesLedgerProducts == null || salesLedgerProducts.isEmpty()) {
+ throw new ServiceException("鍏ュ簱澶辫触,鏈煡璇㈠埌璇ラ攢鍞鍗曠殑閿�鍞骇鍝�");
+ }
+ for (SalesLedgerProduct product : salesLedgerProducts) {
+ if (product.getProductModelId() == null) {
+ continue;
+ }
+ StockInventoryDto stockInventoryDto = new StockInventoryDto();
+ stockInventoryDto.setRecordId(product.getId());
+ stockInventoryDto.setRecordType(StockInQualifiedRecordTypeEnum.SALE_STOCK_IN.getCode());
+ stockInventoryDto.setQualitity(product.getQuantity());
+ stockInventoryDto.setProductModelId(product.getProductModelId());
+ stockInventoryDto.setSalesLedgerId(ledger.getId());
+ stockInventoryDto.setSalesLedgerProductId(product.getId());
+ stockInventoryService.addstockInventory(stockInventoryDto);
+ }
+ // 鎸夐攢鍞鍗曚骇鍝佸叆搴撴儏鍐垫洿鏂颁富鍗曞叆搴撶姸鎬侊細1-閮ㄥ垎鍏ュ簱锛�2-宸插叆搴�
+ List<SalesLedgerProduct> ledgerAllProducts = salesLedgerProductMapper.selectList(Wrappers.<SalesLedgerProduct>lambdaQuery().eq(SalesLedgerProduct::getSalesLedgerId, ledger.getId()));
+ boolean hasStocked = CollectionUtils.isNotEmpty(ledgerAllProducts) && ledgerAllProducts.stream().anyMatch(item -> Objects.equals(item.getProductStockStatus(), 1));
+ boolean allStocked = CollectionUtils.isNotEmpty(ledgerAllProducts) && ledgerAllProducts.stream().allMatch(item -> Objects.equals(item.getProductStockStatus(), 1));
+ ledger.setStockStatus(allStocked ? 2 : (hasStocked ? 1 : 0));
+ baseMapper.updateById(ledger);
+ }
}
--
Gitblit v1.9.3