From 7bf754a7835d06f26240c4ca15bc5f83650de377 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 21 九月 2026 20:52:25 +0800
Subject: [PATCH] docs(api): 更新信托基金与代储台账及油品出库相关接口文档
---
src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java | 148 ++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 132 insertions(+), 16 deletions(-)
diff --git a/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java b/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
index 85fc1b1..158ee93 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
@@ -13,12 +13,23 @@
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
+
+import java.time.LocalDateTime;
import com.ruoyi.stock.dto.StockInRecordDto;
import com.ruoyi.stock.dto.StockInventoryDto;
import com.ruoyi.stock.dto.StockUninventoryDto;
import com.ruoyi.stock.execl.StockInRecordExportData;
import com.ruoyi.production.mapper.ProductionOrderPickMapper;
import com.ruoyi.production.pojo.ProductionOrderPick;
+import com.ruoyi.procurementrecord.mapper.ReturnManagementMapper;
+import com.ruoyi.procurementrecord.mapper.ReturnSaleProductMapper;
+import com.ruoyi.procurementrecord.pojo.ReturnManagement;
+import com.ruoyi.procurementrecord.pojo.ReturnSaleProduct;
+import com.ruoyi.sales.dto.SalesLedgerDto;
+import com.ruoyi.sales.mapper.SalesLedgerMapper;
+import com.ruoyi.sales.mapper.ShippingInfoMapper;
+import com.ruoyi.sales.pojo.SalesLedger;
+import com.ruoyi.sales.pojo.ShippingInfo;
import com.ruoyi.stock.mapper.StockInRecordMapper;
import com.ruoyi.stock.mapper.StockInventoryMapper;
import com.ruoyi.stock.mapper.StockUninventoryMapper;
@@ -43,6 +54,20 @@
private StockInventoryMapper stockInventoryMapper;
private StockUninventoryMapper stockUninventoryMapper;
private ProductionOrderPickMapper productionOrderPickMapper;
+ private ReturnSaleProductMapper returnSaleProductMapper;
+ private ReturnManagementMapper returnManagementMapper;
+ private ShippingInfoMapper shippingInfoMapper;
+ private SalesLedgerMapper salesLedgerMapper;
+
+ /**
+ * 鍏ュ簱绫诲埆锛氫唬鍌ㄥ叆搴撱�傚彧鏈夎繖涓被鍒姹傜粦瀹氶攢鍞鍗�
+ */
+ private static final String INBOUND_CATEGORY_DEPOSIT = "浠e偍鍏ュ簱";
+
+ /**
+ * 閿�鍞彴璐︾殑閿�鍞被鍨嬶細浠e偍銆備唬鍌ㄥ叆搴撳彧鑳界粦杩欎釜绫诲瀷鐨勫彴璐�
+ */
+ private static final String LEDGER_TYPE_DEPOSIT = "浠e偍";
@Override
public IPage<StockInRecordDto> listPage(Page page, StockInRecordDto stockInRecordDto) {
@@ -53,11 +78,49 @@
@Override
@Transactional(rollbackFor = Exception.class)
public int add(StockInRecordDto stockInRecordDto) {
- String no = OrderUtils.countTodayByCreateTime(stockInRecordMapper, "RK","inbound_batches");
+ resolveDepositSalesLedger(stockInRecordDto);
+ LocalDateTime createTime = stockInRecordDto.getCreateTime();
+ if (createTime == null) {
+ createTime = LocalDateTime.now();
+ }
+ String no = OrderUtils.countTodayByCreateTime(stockInRecordMapper, "RK","inbound_batches", createTime);
stockInRecordDto.setInboundBatches(no);
+ stockInRecordDto.setCreateTime(createTime);
StockInRecord stockInRecord = new StockInRecord();
BeanUtils.copyProperties(stockInRecordDto, stockInRecord);
return stockInRecordMapper.insert(stockInRecord);
+ }
+
+ /**
+ * 浠e偍鍏ュ簱锛坕nboundCategory=浠e偍鍏ュ簱锛夊繀椤荤粦瀹氫竴寮犮�屼唬鍌ㄣ�嶇被鍨嬬殑閿�鍞彴璐︼紙閿�鍞鍗曪級銆�
+ * 鍙仛鏍¢獙涓庤惤搴擄紝**涓嶇敤鍙拌处瑕嗙洊**鍏ュ簱鍗曚笂鐨勫鎴�/娌瑰簱/鍌ㄧ綈 鈥斺�� 閭e嚑椤逛粛浠ョ幇鍦哄~鍐欎负鍑嗐��
+ * 闈炰唬鍌ㄥ叆搴撲笉缁戝彴璐︼紝鍗充娇鍓嶇浼犱簡涔熺疆绌猴紝閬垮厤钀戒笅鏃犳剰涔夌殑鍏宠仈銆�
+ */
+ private void resolveDepositSalesLedger(StockInRecordDto stockInRecordDto) {
+ if (!INBOUND_CATEGORY_DEPOSIT.equals(stockInRecordDto.getInboundCategory())) {
+ stockInRecordDto.setSalesLedgerId(null);
+ return;
+ }
+ Long salesLedgerId = stockInRecordDto.getSalesLedgerId();
+ if (salesLedgerId == null) {
+ throw new BaseException("浠e偍鍏ュ簱蹇呴』缁戝畾閿�鍞鍗�");
+ }
+ SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerId);
+ if (salesLedger == null) {
+ throw new BaseException("鎵�閫夐攢鍞鍗曚笉瀛樺湪,閿�鍞鍗昳d:" + salesLedgerId);
+ }
+ if (!LEDGER_TYPE_DEPOSIT.equals(salesLedger.getLedgerType())) {
+ throw new BaseException("浠e偍鍏ュ簱鍙兘缁戝畾浠e偍绫诲瀷鐨勯攢鍞鍗�,閿�鍞悎鍚屽彿:" + salesLedger.getSalesContractNo());
+ }
+ }
+
+ @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 stockInRecordMapper.bindableSalesLedgerPage(page, salesLedgerDto);
}
@Override
@@ -239,14 +302,18 @@
stockInventoryDto.setQualitity(stockInRecord.getStockInNum());
stockInventoryDto.setRemark(stockInRecord.getRemark());
if (stockInventory == null) {
- stockInventoryMapper.insert(new StockInventory() {{
- setProductModelId(stockInRecord.getProductModelId());
- setQualitity(stockInRecord.getStockInNum());
- setBatchNo(stockInRecord.getBatchNo());
- setRemark(stockInRecord.getRemark());
- setWarnNum(stockInRecord.getWarnNum());
- setVersion(1);
- }});
+ try {
+ stockInventoryMapper.insert(new StockInventory() {{
+ setProductModelId(stockInRecord.getProductModelId());
+ setQualitity(stockInRecord.getStockInNum());
+ setBatchNo(stockInRecord.getBatchNo());
+ setRemark(stockInRecord.getRemark());
+ setWarnNum(stockInRecord.getWarnNum());
+ setVersion(1);
+ }});
+ } catch (org.springframework.dao.DuplicateKeyException e) {
+ stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
+ }
} else {
stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
}
@@ -259,17 +326,23 @@
stockUninventoryDto.setQualitity(stockInRecord.getStockInNum());
stockUninventoryDto.setRemark(stockInRecord.getRemark());
if (stockUninventory == null) {
- stockUninventoryMapper.insert(new StockUninventory() {{
- setProductModelId(stockInRecord.getProductModelId());
- setQualitity(stockInRecord.getStockInNum());
- setBatchNo(stockInRecord.getBatchNo());
- setRemark(stockInRecord.getRemark());
- setVersion(1);
- }});
+ try {
+ stockUninventoryMapper.insert(new StockUninventory() {{
+ setProductModelId(stockInRecord.getProductModelId());
+ setQualitity(stockInRecord.getStockInNum());
+ setBatchNo(stockInRecord.getBatchNo());
+ setRemark(stockInRecord.getRemark());
+ setVersion(1);
+ }});
+ } catch (org.springframework.dao.DuplicateKeyException e) {
+ stockUninventoryMapper.updateAddStockUnInventory(stockUninventoryDto);
+ }
} else {
stockUninventoryMapper.updateAddStockUnInventory(stockUninventoryDto);
}
}
+ // 閿�鍞��璐у叆搴�:鎵e噺閿�鍞彴璐﹀疄闄呭悎鍚岄噾棰�(閫�璐х敓鏁�)
+ handleSalesReturnRefund(stockInRecord);
}
}
return ids.size();
@@ -320,4 +393,47 @@
return ids.size();
}
+
+ /**
+ * 閿�鍞��璐у叆搴撳鎵归�氳繃鏃�,鎵e噺瀵瑰簲閿�鍞彴璐︾殑瀹為檯鍚堝悓閲戦銆�
+ * 鍏宠仈閾�:stock_in_record.record_id = return_sale_product.id
+ * 鈫� return_management.shipping_id = shipping_info.id
+ * 鈫� shipping_info.sales_ledger_id = sales_ledger.id
+ * 鍙鐞� record_type 涓� 14(鍚堟牸)鎴� 15(涓嶅悎鏍�)鐨勯攢鍞��璐у叆搴撱��
+ */
+ private void handleSalesReturnRefund(StockInRecord stockInRecord) {
+ String recordType = stockInRecord.getRecordType();
+ if (!StockInQualifiedRecordTypeEnum.RETURN_HE_IN.getCode().equals(recordType)
+ && !StockInQualifiedRecordTypeEnum.RETURN_UNSTOCK_IN.getCode().equals(recordType)) {
+ return;
+ }
+ if (stockInRecord.getRecordId() == null) {
+ return;
+ }
+ ReturnSaleProduct rsp = returnSaleProductMapper.selectById(stockInRecord.getRecordId());
+ if (rsp == null || rsp.getReturnManagementId() == null) {
+ return;
+ }
+ ReturnManagement rm = returnManagementMapper.selectById(rsp.getReturnManagementId());
+ if (rm == null || rm.getShippingId() == null) {
+ return;
+ }
+ ShippingInfo shippingInfo = shippingInfoMapper.selectById(rm.getShippingId());
+ if (shippingInfo == null || shippingInfo.getSalesLedgerId() == null) {
+ return;
+ }
+ SalesLedger salesLedger = salesLedgerMapper.selectById(shippingInfo.getSalesLedgerId());
+ if (salesLedger == null || salesLedger.getContractAmount() == null) {
+ return;
+ }
+ BigDecimal refund = rsp.getAmount() != null ? rsp.getAmount() : BigDecimal.ZERO;
+ if (refund.compareTo(BigDecimal.ZERO) == 0) {
+ return;
+ }
+ BigDecimal baseAmount = salesLedger.getNetContractAmount() != null
+ ? salesLedger.getNetContractAmount()
+ : salesLedger.getContractAmount();
+ salesLedger.setNetContractAmount(baseAmount.subtract(refund));
+ salesLedgerMapper.updateById(salesLedger);
+ }
}
--
Gitblit v1.9.3