From d36901a7f73ffea46a956b53b001efa0ad98aebc Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期四, 25 六月 2026 11:01:21 +0800
Subject: [PATCH] fix: 入库审批通过提交至质检
---
src/main/java/com/ruoyi/quality/service/impl/QualityInspectServiceImpl.java | 96 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 96 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ruoyi/quality/service/impl/QualityInspectServiceImpl.java b/src/main/java/com/ruoyi/quality/service/impl/QualityInspectServiceImpl.java
index f9a1d42..8d60a6d 100644
--- a/src/main/java/com/ruoyi/quality/service/impl/QualityInspectServiceImpl.java
+++ b/src/main/java/com/ruoyi/quality/service/impl/QualityInspectServiceImpl.java
@@ -32,6 +32,10 @@
import com.ruoyi.purchase.pojo.PurchaseLedger;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
+import com.ruoyi.sales.pojo.SalesLedger;
+import com.ruoyi.sales.mapper.SalesLedgerMapper;
+import com.ruoyi.stock.service.StockInventoryService;
+import com.ruoyi.stock.dto.StockInventoryDto;
import com.ruoyi.framework.security.LoginUser;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
@@ -69,6 +73,9 @@
private ProcurementRecordService procurementRecordService;
private IApproveProcessService approveProcessService;
+
+ private StockInventoryService stockInventoryService;
+ private SalesLedgerMapper salesLedgerMapper;
@Override
public int add(QualityInspectDto qualityInspectDto) {
@@ -148,6 +155,18 @@
);
syncQualifiedInboundToPurchaseProducts(qualityInspect, qualifiedQty);
}
+ } else if (Objects.equals(qualityInspect.getInspectType(), 2) && qualityInspect.getSalesLedgerId() != null) {
+ // 閿�鍞鍗曠殑鎴愬搧鍑哄巶妫�楠岋紝鎻愪氦鍚庣洿鎺ュ叆搴�
+ StockInventoryDto stockInventoryDto = new StockInventoryDto();
+ stockInventoryDto.setRecordId(qualityInspect.getSalesLedgerProductId());
+ stockInventoryDto.setRecordType(StockInQualifiedRecordTypeEnum.SALE_STOCK_IN.getCode());
+ stockInventoryDto.setQualitity(qualifiedQty);
+ stockInventoryDto.setProductModelId(qualityInspect.getProductModelId());
+ stockInventoryDto.setSalesLedgerId(qualityInspect.getSalesLedgerId());
+ stockInventoryDto.setSalesLedgerProductId(qualityInspect.getSalesLedgerProductId());
+ stockInventoryService.addstockInventory(stockInventoryDto);
+
+ syncQualifiedInboundToSalesProducts(qualityInspect, qualifiedQty);
} else {
stockUtils.addStock(
qualityInspect.getPurchaseLedgerId() == null ? null : qualityInspect.getPurchaseLedgerId(),
@@ -165,6 +184,9 @@
qualityInspect.setInspectState(1);
int updated = qualityInspectMapper.updateById(qualityInspect);
refreshPurchaseLedgerStockStatusByInspect(qualityInspect.getPurchaseLedgerId());
+ if (qualityInspect.getSalesLedgerId() != null) {
+ refreshSalesLedgerStockStatusByInspect(qualityInspect.getSalesLedgerId());
+ }
return updated;
}
@@ -397,6 +419,7 @@
qualityInspectParamService.remove(Wrappers.<QualityInspectParam>lambdaQuery().eq(QualityInspectParam::getInspectId, qualityInspectDto.getId()));
for (QualityInspectParam qualityInspectParam : qualityInspectDto.getQualityInspectParams()) {
qualityInspectParam.setInspectId(qualityInspectDto.getId());
+ qualityInspectParam.setId(null);
}
qualityInspectParamService.saveBatch(qualityInspectDto.getQualityInspectParams());
}
@@ -554,5 +577,78 @@
}
}
+ private void syncQualifiedInboundToSalesProducts(QualityInspect qualityInspect, BigDecimal inboundQty) {
+ if (qualityInspect == null || qualityInspect.getSalesLedgerProductId() == null || inboundQty == null) {
+ return;
+ }
+ if (inboundQty.compareTo(BigDecimal.ZERO) <= 0) {
+ return;
+ }
+
+ SalesLedgerProduct line = salesLedgerProductMapper.selectById(qualityInspect.getSalesLedgerProductId());
+ if (line == null) {
+ return;
+ }
+
+ BigDecimal orderQty = line.getQuantity() == null ? BigDecimal.ZERO : line.getQuantity();
+ BigDecimal stocked = line.getStockedQuantity() == null ? BigDecimal.ZERO : line.getStockedQuantity();
+ BigDecimal newStocked = stocked.add(inboundQty);
+
+ int status;
+ if (newStocked.compareTo(BigDecimal.ZERO) <= 0) {
+ status = 0;
+ } else if (orderQty.compareTo(BigDecimal.ZERO) > 0 && newStocked.compareTo(orderQty) < 0) {
+ status = 1;
+ } else {
+ status = 2;
+ }
+
+ line.setStockedQuantity(newStocked);
+ line.setProductStockStatus(status);
+ line.fillRemainingQuantity();
+ salesLedgerProductMapper.updateById(line);
+ }
+
+ private void refreshSalesLedgerStockStatusByInspect(Long salesLedgerId) {
+ if (salesLedgerId == null) {
+ return;
+ }
+ List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>()
+ .eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerId));
+ if (products == null || products.isEmpty()) {
+ return;
+ }
+
+ boolean hasStocked = false;
+ boolean allStocked = true;
+ for (SalesLedgerProduct product : products) {
+ BigDecimal orderQty = product.getQuantity() == null ? BigDecimal.ZERO : product.getQuantity();
+ BigDecimal sq = product.getStockedQuantity() == null ? BigDecimal.ZERO : product.getStockedQuantity();
+ if (sq.compareTo(BigDecimal.ZERO) > 0) {
+ hasStocked = true;
+ }
+ if (orderQty.compareTo(BigDecimal.ZERO) <= 0 || sq.compareTo(orderQty) < 0) {
+ allStocked = false;
+ }
+ }
+
+ long pendingInspectCount = qualityInspectMapper.selectCount(Wrappers.<QualityInspect>lambdaQuery()
+ .eq(QualityInspect::getSalesLedgerId, salesLedgerId)
+ .eq(QualityInspect::getInspectState, 0));
+ boolean allInspectFinished = pendingInspectCount == 0;
+
+ SalesLedger ledger = salesLedgerMapper.selectById(salesLedgerId);
+ if (ledger != null) {
+ int newStatus = ledger.getStockStatus() != null ? ledger.getStockStatus() : 0;
+ if (allInspectFinished) {
+ newStatus = allStocked ? 2 : 5; // 2: 宸插叆搴�(璐ㄦ瀹屾垚), 5: 閮ㄥ垎璐ㄦ瀹屾垚
+ } else {
+ newStatus = 4; // 4: 璐ㄦ涓�
+ }
+ ledger.setStockStatus(newStatus);
+ salesLedgerMapper.updateById(ledger);
+ }
+ }
+
}
--
Gitblit v1.9.3