From 6b4cfc6f9d660b92be99ba4e3411a3267bc57155 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期六, 18 四月 2026 15:24:33 +0800
Subject: [PATCH] feat: 销售/采购订单的扫码合格/不合格出入库功能
---
src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 202 insertions(+), 7 deletions(-)
diff --git a/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java b/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
index ce2cbc9..4b9dd7b 100644
--- a/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
+++ b/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
@@ -1,24 +1,219 @@
package com.ruoyi.procurementrecord.utils;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.procurementrecord.mapper.ProcurementRecordMapper;
import com.ruoyi.procurementrecord.mapper.ProcurementRecordOutMapper;
+import com.ruoyi.stock.dto.StockInRecordDto;
+import com.ruoyi.stock.dto.StockInventoryDto;
+import com.ruoyi.stock.dto.StockUninventoryDto;
+import com.ruoyi.stock.pojo.StockInRecord;
+import com.ruoyi.stock.pojo.StockInventory;
+import com.ruoyi.stock.pojo.StockOutRecord;
+import com.ruoyi.stock.pojo.StockUninventory;
+import com.ruoyi.stock.service.StockInRecordService;
+import com.ruoyi.stock.service.StockInventoryService;
+import com.ruoyi.stock.service.StockOutRecordService;
+import com.ruoyi.stock.service.StockUninventoryService;
+import com.ruoyi.stock.service.impl.StockInRecordServiceImpl;
+import com.ruoyi.stock.service.impl.StockOutRecordServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
@Component
@RequiredArgsConstructor
public class StockUtils {
private final ProcurementRecordOutMapper procurementRecordOutMapper;
private final ProcurementRecordMapper procurementRecordMapper;
+ private final StockUninventoryService stockUninventoryService;
+ private final StockInventoryService stockInventoryService;
+ private final StockInRecordService stockInRecordService;
+ private final StockOutRecordService stockOutRecordService;
- // 鑾峰彇鍟嗗搧鍓╀綑搴撳瓨
- public BigDecimal getStockQuantity(Long productModelId) {
- // 鍏ュ簱鏁伴噺
- BigDecimal sumQuantity = procurementRecordMapper.getSumQuantity(productModelId);
- // 鍑哄簱鏁伴噺
- BigDecimal outQuantity = procurementRecordOutMapper.getSumQuantity(productModelId);
- return outQuantity.compareTo(sumQuantity) > 0 ? BigDecimal.ZERO : sumQuantity.subtract(outQuantity);
+ /**
+ * 鍚堟牸搴撳瓨鍑哄簱鍓嶆牎楠岋細鎸� stock_inventory 鍙敤鏁伴噺锛堟暟閲� 鈭� 鍐荤粨锛�
+ */
+ public void assertQualifiedAvailable(Long productModelId, BigDecimal outboundQty) {
+ if (productModelId == null) {
+ throw new ServiceException("鍑哄簱澶辫触,浜у搧瑙勬牸鏈淮鎶�");
+ }
+ if (outboundQty == null || outboundQty.compareTo(BigDecimal.ZERO) <= 0) {
+ return;
+ }
+ StockInventory inv = stockInventoryService.getOne(
+ Wrappers.<StockInventory>lambdaQuery().eq(StockInventory::getProductModelId, productModelId));
+ if (inv == null) {
+ throw new ServiceException("鍑哄簱澶辫触,鍚堟牸搴撲腑鏃犺浜у搧搴撳瓨");
+ }
+ BigDecimal locked = inv.getLockedQuantity() == null ? BigDecimal.ZERO : inv.getLockedQuantity();
+ BigDecimal qty = inv.getQualitity() == null ? BigDecimal.ZERO : inv.getQualitity();
+ BigDecimal available = qty.subtract(locked);
+ if (outboundQty.compareTo(available) > 0) {
+ throw new ServiceException("鍑哄簱澶辫触,鍑哄簱鏁伴噺涓嶈兘澶т簬褰撳墠鍚堟牸搴撳瓨鍙敤鏁伴噺");
+ }
+ }
+
+ /**
+ * 涓嶅悎鏍煎簱瀛樺嚭搴撳墠鏍¢獙锛氭寜 stock_uninventory 鍙敤鏁伴噺锛堟暟閲� 鈭� 鍐荤粨锛�
+ */
+ public void assertUnqualifiedAvailable(Long productModelId, BigDecimal outboundQty) {
+ if (productModelId == null) {
+ throw new ServiceException("鍑哄簱澶辫触,浜у搧瑙勬牸鏈淮鎶�");
+ }
+ if (outboundQty == null || outboundQty.compareTo(BigDecimal.ZERO) <= 0) {
+ return;
+ }
+ StockUninventory inv = stockUninventoryService.getOne(
+ Wrappers.<StockUninventory>lambdaQuery().eq(StockUninventory::getProductModelId, productModelId));
+ if (inv == null) {
+ throw new ServiceException("鍑哄簱澶辫触,涓嶅悎鏍煎簱涓棤璇ヤ骇鍝佸簱瀛�");
+ }
+ BigDecimal locked = inv.getLockedQuantity() == null ? BigDecimal.ZERO : inv.getLockedQuantity();
+ BigDecimal qty = inv.getQualitity() == null ? BigDecimal.ZERO : inv.getQualitity();
+ BigDecimal available = qty.subtract(locked);
+ if (outboundQty.compareTo(available) > 0) {
+ throw new ServiceException("鍑哄簱澶辫触,鍑哄簱鏁伴噺涓嶈兘澶т簬褰撳墠涓嶅悎鏍煎簱瀛樺彲鐢ㄦ暟閲�");
+ }
+ }
+
+ /**
+ * 涓嶅悎鏍煎叆搴�
+ *
+ * @param productModelId
+ * @param quantity
+ * @param recordType
+ * @param recordId
+ */
+ public void addUnStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
+ addUnStock(null, null, productModelId, quantity, recordType, recordId);
+ }
+
+ /**
+ * 涓嶅悎鏍煎叆搴擄紙甯﹂攢鍞鍗曞叧鑱旓紝鍐欏叆鍏ュ簱璁板綍锛�
+ */
+ public void addUnStock(Long salesLedgerId, Long salesLedgerProductId, Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
+ StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
+ stockUninventoryDto.setRecordId(recordId);
+ stockUninventoryDto.setRecordType(String.valueOf(recordType));
+ stockUninventoryDto.setQualitity(quantity);
+ stockUninventoryDto.setProductModelId(productModelId);
+ stockUninventoryDto.setSalesLedgerId(salesLedgerId);
+ stockUninventoryDto.setSalesLedgerProductId(salesLedgerProductId);
+ stockUninventoryService.addStockUninventory(stockUninventoryDto);
+ }
+
+ /**
+ * 涓嶅悎鏍煎嚭搴�
+ */
+ public void subtractUnStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
+ subtractUnStock(null, null, productModelId, quantity, recordType, recordId);
+ }
+
+ /**
+ * 涓嶅悎鏍煎嚭搴擄紙鍙甫閿�鍞鍗曞叧鑱斿啓鍏ュ嚭搴撹褰曪級
+ */
+ public void subtractUnStock(Long salesLedgerId, Long salesLedgerProductId, Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
+ StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
+ stockUninventoryDto.setRecordId(recordId);
+ stockUninventoryDto.setRecordType(recordType);
+ stockUninventoryDto.setQualitity(quantity);
+ stockUninventoryDto.setProductModelId(productModelId);
+ stockUninventoryDto.setSalesLedgerId(salesLedgerId);
+ stockUninventoryDto.setSalesLedgerProductId(salesLedgerProductId);
+ stockUninventoryService.subtractStockUninventory(stockUninventoryDto);
+ }
+
+ /**
+ * 鍚堟牸鍏ュ簱
+ *
+ * @param productModelId
+ * @param quantity
+ * @param recordType
+ * @param recordId
+ */
+ public void addStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
+ addStock(null, null, productModelId, quantity, recordType, recordId);
+ }
+
+ /**
+ * 鍚堟牸鍏ュ簱
+ *
+ * @param productModelId
+ * @param quantity
+ * @param recordType
+ * @param recordId
+ */
+ public void addStock(Long salesLedgerId, Long salesLedgerProductId, Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
+ StockInventoryDto stockInventoryDto = new StockInventoryDto();
+ stockInventoryDto.setRecordId(recordId);
+ stockInventoryDto.setRecordType(String.valueOf(recordType));
+ stockInventoryDto.setQualitity(quantity);
+ stockInventoryDto.setProductModelId(productModelId);
+ stockInventoryDto.setSalesLedgerId(salesLedgerId);
+ stockInventoryDto.setSalesLedgerProductId(salesLedgerProductId);
+ stockInventoryService.addstockInventory(stockInventoryDto);
+ }
+
+
+ /**
+ * 鍚堟牸鍑哄簱
+ *
+ * @param productModelId
+ * @param quantity
+ * @param recordType
+ * @param recordId
+ */
+ public void substractStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
+ StockInventoryDto stockInventoryDto = new StockInventoryDto();
+ stockInventoryDto.setRecordId(recordId);
+ stockInventoryDto.setRecordType(String.valueOf(recordType));
+ stockInventoryDto.setQualitity(quantity);
+ stockInventoryDto.setProductModelId(productModelId);
+ stockInventoryService.subtractStockInventory(stockInventoryDto);
+ }
+
+ /**
+ * 鍚堟牸鍑哄簱
+ *
+ * @param productModelId
+ * @param quantity
+ * @param recordType
+ * @param recordId
+ */
+ public void substractStock(Long salesId, Long salseProductId, Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
+ StockInventoryDto stockInventoryDto = new StockInventoryDto();
+ stockInventoryDto.setRecordId(recordId);
+ stockInventoryDto.setRecordType(String.valueOf(recordType));
+ stockInventoryDto.setQualitity(quantity);
+ stockInventoryDto.setProductModelId(productModelId);
+ stockInventoryDto.setSalesLedgerId(salesId);
+ stockInventoryDto.setSalesLedgerProductId(salseProductId);
+ stockInventoryService.subtractStockInventory(stockInventoryDto);
+ }
+
+ //涓嶅悎鏍煎簱瀛樺垹闄�
+ public void deleteStockInRecord(Long recordId, String recordType) {
+ StockInRecord one = stockInRecordService.getOne(new QueryWrapper<StockInRecord>()
+ .lambda().eq(StockInRecord::getRecordId, recordId)
+ .eq(StockInRecord::getRecordType, recordType));
+ if (ObjectUtils.isNotEmpty(one)) {
+ stockInRecordService.batchDelete(Collections.singletonList(one.getId()));
+ }
+ }
+
+ public void deleteStockOutRecord(Long recordId, String recordType) {
+ StockOutRecord one = stockOutRecordService.getOne(new QueryWrapper<StockOutRecord>()
+ .lambda().eq(StockOutRecord::getRecordId, recordId)
+ .eq(StockOutRecord::getRecordType, recordType));
+ if (ObjectUtils.isNotEmpty(one)) {
+ stockOutRecordService.batchDelete(Collections.singletonList(one.getId()));
+ }
}
}
--
Gitblit v1.9.3