From 3e5e22f5358156ff7430ee117546123ffe042611 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期日, 20 九月 2026 20:23:52 +0800
Subject: [PATCH] feat(stock): 实现出品出库绑定销售台账功能
---
src/main/java/com/ruoyi/stock/service/impl/StockOutRecordServiceImpl.java | 76 ++++++++++++++++++++++++++++++++++++++
1 files changed, 76 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ruoyi/stock/service/impl/StockOutRecordServiceImpl.java b/src/main/java/com/ruoyi/stock/service/impl/StockOutRecordServiceImpl.java
index 1445d45..4a2f241 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockOutRecordServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockOutRecordServiceImpl.java
@@ -23,6 +23,11 @@
import com.ruoyi.outsourcing.mapper.OutsourcingOrderProductMapper;
import com.ruoyi.outsourcing.pojo.OutsourcingOrder;
import com.ruoyi.outsourcing.pojo.OutsourcingOrderProduct;
+import com.ruoyi.sales.dto.SalesLedgerDto;
+import com.ruoyi.sales.mapper.SalesLedgerMapper;
+import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
+import com.ruoyi.sales.pojo.SalesLedger;
+import com.ruoyi.sales.pojo.SalesLedgerProduct;
import java.time.LocalDateTime;
import com.ruoyi.stock.dto.OilOutAvailableDto;
@@ -64,6 +69,21 @@
*/
private static final String OUT_CATEGORY_SALE = "閿�鍞�";
+ /**
+ * 鍑哄簱绫诲埆锛氫唬鍌ㄣ�傚鎴锋妸鑷繁鐨勬补瀵勫瓨鍦ㄦ垜浠殑缃愰噷锛屾彁璧板彧鏄褰曚竴绗旓紝涓嶆墸搴撳瓨銆佷笉杩涘彂璐у彴璐�
+ */
+ private static final String OUT_CATEGORY_DEPOSIT = "浠e偍";
+
+ /**
+ * 閿�鍞彴璐︾殑閿�鍞被鍨嬶細浠e偍锛堝崠瀛樺偍浣嶇疆锛夈�傝繖绫诲彴璐︽病鏈変骇鍝佹槑缁嗭紝鍙湁娌瑰簱+鍌ㄧ綈锛岃 SalesLedger.ledgerType
+ */
+ private static final String LEDGER_TYPE_DEPOSIT = "浠e偍";
+
+ /**
+ * 閿�鍞彴璐︿骇鍝佹槑缁嗙殑琛岀被鍨嬶細閿�鍞�傝 sales_ledger_product.type
+ */
+ private static final Integer LEDGER_PRODUCT_TYPE_SALE = 1;
+
private final StockOutRecordMapper stockOutRecordMapper;
private final IVehicleService vehicleService;
private final StockInventoryMapper stockInventoryMapper;
@@ -72,6 +92,8 @@
private final AccountInvoiceApplicationMapper accountInvoiceApplicationMapper;
private final OutsourcingOrderProductMapper outsourcingOrderProductMapper;
private final OutsourcingOrderMapper outsourcingOrderMapper;
+ private final SalesLedgerMapper salesLedgerMapper;
+ private final SalesLedgerProductMapper salesLedgerProductMapper;
@Override
public IPage<StockOutRecordDto> listPage(Page page, StockOutRecordDto stockOutRecordDto) {
@@ -80,6 +102,7 @@
@Override
public int add(StockOutRecordDto stockOutRecordDto) {
+ resolveSalesLedgerBinding(stockOutRecordDto);
if (OUT_CATEGORY_SALE.equals(stockOutRecordDto.getOutCategory())) {
// 閿�鍞被娌瑰搧鍑哄簱瀹℃壒閫氳繃鏃惰鎸夋壒娆℃墸鍑忓簱瀛橈紝鎵规涓嶈兘涓虹┖
if (StringUtils.isEmpty(stockOutRecordDto.getBatchNo())) {
@@ -109,9 +132,53 @@
throw new BaseException("璇ュ嚭搴撹褰曚笉瀛樺湪,鏃犳硶鏇存柊!!!");
}
+ resolveSalesLedgerBinding(stockOutRecordDto);
String[] ignoreProperties = {"id", "outbound_batches"};//鎺掗櫎id灞炴��
BeanUtils.copyProperties(stockOutRecordDto, stockOutRecord, ignoreProperties);
return stockOutRecordMapper.updateById(stockOutRecord);
+ }
+
+ /**
+ * 缁戝畾閿�鍞彴璐︼細瀹㈡埛涓�寰嬩互鍙拌处涓哄噯瑕嗙洊锛岄伩鍏嶅嚭搴撹褰曚笌鍙拌处鐨勫鎴峰涓嶄笂锛涘嚭搴撶被鍒寜鍙拌处鐨勯攢鍞被鍨嬭嚜鍔ㄥ畾锛�
+ * 鍏嶅緱鍑虹幇銆岀粦浜嗗崠娌瑰彴璐﹀嵈鎸変唬鍌ㄤ笉鎵e簱瀛樸�嶈繖绫荤煕鐩炬暟鎹��
+ * <ul>
+ * <li>鍗栨补锛堝惈 ledgerType 涓虹┖锛夛細鍑哄簱绫诲埆缃�岄攢鍞�嶏紝骞舵牎楠屾墍閫夎鏍肩‘瀹炲湪璇ュ彴璐︾殑閿�鍞槑缁嗛噷</li>
+ * <li>浠e偍锛氬嚭搴撶被鍒疆銆屼唬鍌ㄣ�嶏紝甯﹀叆鍙拌处鐨勬补搴�/鍌ㄧ綈锛岃烦杩囦骇鍝佹牎楠� 鈥斺��
+ * 浠e偍鍙拌处鏈韩灏辨槸鍗栧瓨鍌ㄤ綅缃紝娌℃湁浜у搧鏄庣粏</li>
+ * </ul>
+ * salesLedgerId 涓虹┖鏃舵暣浣撹烦杩囷紝涓嶇粦鍙拌处鐨勫嚭搴撹涓轰笌鏀瑰姩鍓嶅畬鍏ㄤ竴鑷�
+ */
+ private void resolveSalesLedgerBinding(StockOutRecordDto stockOutRecordDto) {
+ if (stockOutRecordDto.getSalesLedgerId() == null) {
+ return;
+ }
+ SalesLedger salesLedger = salesLedgerMapper.selectById(stockOutRecordDto.getSalesLedgerId());
+ if (salesLedger == null) {
+ throw new BaseException("鎵�閫夐攢鍞彴璐︿笉瀛樺湪,閿�鍞彴璐d:" + stockOutRecordDto.getSalesLedgerId());
+ }
+ stockOutRecordDto.setCustomerId(salesLedger.getCustomerId());
+ stockOutRecordDto.setCustomerName(salesLedger.getCustomerName());
+ if (LEDGER_TYPE_DEPOSIT.equals(salesLedger.getLedgerType())) {
+ stockOutRecordDto.setOutCategory(OUT_CATEGORY_DEPOSIT);
+ stockOutRecordDto.setOilDepotId(salesLedger.getOilDepotId());
+ stockOutRecordDto.setOilDepotName(salesLedger.getOilDepotName());
+ stockOutRecordDto.setTankId(salesLedger.getTankId());
+ stockOutRecordDto.setTankNo(salesLedger.getTankNo());
+ return;
+ }
+ stockOutRecordDto.setOutCategory(OUT_CATEGORY_SALE);
+ if (stockOutRecordDto.getProductModelId() == null) {
+ throw new BaseException("缁戝畾閿�鍞彴璐︽椂蹇呴』閫夋嫨浜у搧瑙勬牸,閿�鍞悎鍚屽彿:" + salesLedger.getSalesContractNo());
+ }
+ boolean belongsToLedger = salesLedgerProductMapper.selectList(
+ Wrappers.<SalesLedgerProduct>lambdaQuery()
+ .eq(SalesLedgerProduct::getSalesLedgerId, stockOutRecordDto.getSalesLedgerId())
+ .eq(SalesLedgerProduct::getType, LEDGER_PRODUCT_TYPE_SALE))
+ .stream()
+ .anyMatch(item -> stockOutRecordDto.getProductModelId().equals(item.getProductModelId()));
+ if (!belongsToLedger) {
+ throw new BaseException("鎵�閫変骇鍝佷笉鍦ㄨ閿�鍞彴璐︽槑缁嗕腑,閿�鍞悎鍚屽彿:" + salesLedger.getSalesContractNo());
+ }
}
@Override
@@ -520,6 +587,15 @@
}
@Override
+ public IPage<SalesLedger> listBindableSalesLedger(Page page, SalesLedgerDto salesLedgerDto) {
+ // 璇ユ煡璇㈢敤 /*data_scope*/ 璺宠繃鏁版嵁鏉冮檺锛岃�� MP 榛樿浼氭妸 count 璇彞浼樺寲鎴愩�孲ELECT COUNT(*) FROM sales_ledger
+ // WHERE ...銆嶏紝浼樺寲鍚庢爣璁颁涪澶憋紝count 鍙嶈�岃杩藉姞鏉冮檺鏉′欢锛宼otal 浼氭瘮瀹為檯璁板綍灏戙�傚叧鎺� count 浼樺寲鍚�
+ // count 閫�鍖栨垚銆孲ELECT COUNT(*) FROM (鍘熷彞) TOTAL銆嶏紝鏍囪鍘熸牱淇濈暀
+ page.setOptimizeCountSql(false);
+ return stockOutRecordMapper.bindableSalesLedgerPage(page, salesLedgerDto);
+ }
+
+ @Override
@Transactional(rollbackFor = Exception.class)
public int releaseByRecordIds(List<Long> recordIds, String recordType) {
List<StockOutRecord> records = listByRecordIds(recordIds, recordType);
--
Gitblit v1.9.3