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/sales/service/impl/ShippingInfoServiceImpl.java |   89 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 88 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
index be34bc0..54337d8 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
@@ -20,9 +20,11 @@
 import com.ruoyi.framework.security.LoginUser;
 import com.ruoyi.procurementrecord.bean.vo.ShippingProductVo;
 import com.ruoyi.procurementrecord.utils.StockUtils;
+import com.ruoyi.sales.dto.SalesLedgerArrivalDto;
 import com.ruoyi.sales.dto.ShippingApproveDto;
 import com.ruoyi.sales.dto.ShippingInfoDto;
 import com.ruoyi.sales.dto.ShippingProductDetailDto;
+import com.ruoyi.sales.mapper.SalesLedgerArrivalMapper;
 import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
 import com.ruoyi.sales.mapper.ShippingInfoMapper;
 import com.ruoyi.sales.mapper.ShippingProductDetailMapper;
@@ -36,7 +38,12 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @author :yys
@@ -47,9 +54,14 @@
 @RequiredArgsConstructor
 public class ShippingInfoServiceImpl extends ServiceImpl<ShippingInfoMapper, ShippingInfo> implements ShippingInfoService {
 
+    /**
+     * listPage 鐨勮鏉ユ簮鏍囪锛歴hipping=鍙戣揣鍗曪紝oilOut=閿�鍞被娌瑰搧鍑哄簱
+     */
+    private static final String SOURCE_OIL_OUT = "oilOut";
 
     private final ShippingInfoMapper shippingInfoMapper;
 
+    private final SalesLedgerArrivalMapper salesLedgerArrivalMapper;
 
     private final SalesLedgerProductMapper salesLedgerProductMapper;
 
@@ -67,9 +79,56 @@
     public IPage<ShippingInfoDto> listPage(Page page, ShippingInfo req) {
         IPage<ShippingInfoDto> listPage = shippingInfoMapper.listPage(page, req);
         listPage.getRecords().forEach(item -> {
+            if (SOURCE_OIL_OUT.equals(item.getSource())) {
+                // 娌瑰搧鍑哄簱琛岀殑 id 鏄� stock_out_record.id锛屼笌 shipping_info.id 鍚屽煙浼氭挒鍙凤紝
+                // 鐢ㄥ畠鍘绘煡闄勪欢鍙細鎹炲嚭鍒殑鍙戣揣鍗曠殑鍥撅紝绱㈡�т笉鏌ワ紱闄勪欢鎸傚湪鍒拌揣璁板綍瀛愯涓�
+                // 娌瑰搧鍑哄簱琛屾病鏈� shipping_product_detail锛屾壒鍙锋槑缁嗗彧鑳界敱鍑哄簱璁板綍鑷韩瀛楁鏋勯��
+                item.setBatchNoList(buildOilOutBatchNoList(item));
+                return;
+            }
             item.setStorageBlobVOs(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.IMAGE, RecordTypeEnum.SHIPPING_INFO, item.getId()));
         });
+        assembleArrivals(listPage.getRecords());
         return listPage;
+    }
+
+    /**
+     * 鍙戣揣鍙拌处灞傜骇鍖栵細鐖惰 = 涓�娆″彂璐э紙鍙戣揣鍗� / 娌瑰搧鍑哄簱鍗曪級锛屽瓙琛� = 璇ュ嚭搴撳崟涓嬬殑鍒拌揣璁板綍銆�
+     * <p>
+     * 鍒绘剰涓嶆妸鍒拌揣璁板綍 UNION 杩涘垎椤� SQL锛氱幇鏈� UNION 鐨勬瘡涓�琛屽ぉ鐒跺氨鏄竴涓埗琛岋紝鐖惰缁村害鐨勫垎椤典笌
+     * total 宸茬粡姝g‘锛涙贩鍏ュ瓙琛屼細鎾戝ぇ鏉℃暟锛屼笖 {@code getDateilByShippingNo} 澶嶇敤鍚屼竴 listPage 鍙�
+     * 绗竴琛屾椂浼氶潤榛樺彇閿欍�傛敼鎴愪粠宸插垎椤电殑鐖惰閲屾敹闆� id锛屼竴娆℃壒閲忔煡瀛愯锛岄伩鍏� N+1銆�
+     */
+    private void assembleArrivals(List<ShippingInfoDto> records) {
+        List<Long> stockOutRecordIds = records.stream()
+                .filter(item -> SOURCE_OIL_OUT.equals(item.getSource()) && item.getStockOutRecordId() != null)
+                .map(ShippingInfoDto::getStockOutRecordId)
+                .toList();
+        if (stockOutRecordIds.isEmpty()) {
+            return;
+        }
+        Map<Long, List<SalesLedgerArrivalDto>> arrivalMap = salesLedgerArrivalMapper
+                .listByStockOutRecordIds(stockOutRecordIds).stream()
+                .collect(Collectors.groupingBy(SalesLedgerArrivalDto::getStockOutRecordId));
+        records.forEach(item -> {
+            if (!SOURCE_OIL_OUT.equals(item.getSource()) || item.getStockOutRecordId() == null) {
+                return;
+            }
+            List<SalesLedgerArrivalDto> arrivals = arrivalMap.get(item.getStockOutRecordId());
+            item.setChildren(arrivals == null ? new ArrayList<>() : new ArrayList<>(arrivals));
+        });
+    }
+
+    /**
+     * 娌瑰搧鍑哄簱琛岀殑鎵瑰彿鏄庣粏锛屼緵鍙戣揣鍙拌处璇︽儏寮规鐨勩�屾壒鍙枫�嶆槑缁嗚〃灞曠ず
+     */
+    private List<ShippingProductDetailDto> buildOilOutBatchNoList(ShippingInfoDto item) {
+        ShippingProductDetailDto detail = new ShippingProductDetailDto();
+        detail.setBatchNo(item.getOutBatchNo());
+        detail.setProductName(item.getProductName());
+        detail.setSpecificationModel(item.getSpecificationModel());
+        detail.setDeliveryQuantity(item.getTotalQuantity());
+        return Collections.singletonList(detail);
     }
 
     @Override
@@ -171,7 +230,6 @@
 
     @Override
     public boolean addReq(ShippingInfoDto req) {
-
         // 鏍¢獙璇ヤ骇鍝佹槸鍚﹀凡鏈夊緟瀹℃牳/瀹℃牳涓殑鍙戣揣璁板綍锛岄槻姝㈤噸澶嶆彁浜�
         Long salesLedgerProductId = req.getSalesLedgerProductId();
         if (salesLedgerProductId != null) {
@@ -216,4 +274,33 @@
         this.updateById(req);
         return true;
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Long addShippedFromOutbound(ShippingInfoDto req) {
+        // 浠撳偍鐗╂祦鍑哄簱鍗冲彂璐э細涓嶅彂璧峰彂璐у鎵癸紝鐩存帴钀戒负宸插彂璐э紝搴撳瓨鐢� add 鍐呴儴鎵e噺
+        req.setShippingNo(OrderUtils.countTodayByCreateTime(
+                shippingInfoMapper, "SH", "shipping_no", LocalDateTime.now()));
+        req.setStatus("宸插彂璐�");
+        if (req.getShippingDate() == null) {
+            req.setShippingDate(new Date());
+        }
+        this.add(req);
+        return req.getId();
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void cancelByOutbound(Long shippingInfoId) {
+        // <=0 蹇呴』鎸′綇锛氭补鍝佸嚭搴撶殑 record_id 鏄� 0 鑰� record_type 鍚屾牱鏄��13銆嶏紝
+        // 浼� 0 杩涙潵浼氭妸鍚岀被鍨嬬殑娌瑰搧鍑哄簱璁板綍褰撴垚鏈彂璐у崟鐨勯厤瀵瑰嚭搴撴暣鎵瑰垹鎺�
+        if (shippingInfoId == null || shippingInfoId <= 0) {
+            return;
+        }
+        // 鍥炴粴璇ュ彂璐у崟鍗犵敤鐨勫簱瀛�
+        stockUtils.deleteStockOutRecord(shippingInfoId, StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode());
+        shippingProductDetailMapper.delete(new LambdaQueryWrapper<ShippingProductDetail>()
+                .eq(ShippingProductDetail::getShippingInfoId, shippingInfoId));
+        this.removeById(shippingInfoId);
+    }
 }

--
Gitblit v1.9.3