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/resources/mapper/account/sales/AccountSalesCollectionMapper.xml |   60 ++++++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/src/main/resources/mapper/account/sales/AccountSalesCollectionMapper.xml b/src/main/resources/mapper/account/sales/AccountSalesCollectionMapper.xml
index 6a35890..4c1ebdb 100644
--- a/src/main/resources/mapper/account/sales/AccountSalesCollectionMapper.xml
+++ b/src/main/resources/mapper/account/sales/AccountSalesCollectionMapper.xml
@@ -28,7 +28,11 @@
                GROUP_CONCAT(sour.outbound_batches SEPARATOR ',') AS outboundBatches
         from account_sales_collection ascc
         left join customer c on ascc.customer_id = c.id
+        <!-- 鎵嬪伐鍙戣揣鍗曞嚭搴撴寜 stock_out_record_ids 鎵撅紝娌瑰搧鍑哄簱鎸夌粦瀹氳 stock_out_binding_ids 鍙嶆煡鎵�鍦ㄧ殑鍑哄簱鍗� -->
         left join stock_out_record sour on FIND_IN_SET(sour.id, ascc.stock_out_record_ids) > 0
+            OR EXISTS (select 1 from stock_out_record_sales_ledger b
+                       where b.stock_out_record_id = sour.id
+                         and FIND_IN_SET(b.id, ascc.stock_out_binding_ids) > 0)
         GROUP BY ascc.id)A
        left join account_statement_details asd on A.collection_number = asd.receipt_number
          <where>
@@ -55,6 +59,12 @@
             FIND_IN_SET(#{id}, stock_out_record_ids)
         </foreach>
     </select>
+    <!-- 鍙敹娆剧殑閿�鍞嚭搴撳�欓�夈��
+         鈶� record_type='13' 鐨勬墜宸ュ彂璐у崟鍑哄簱 鈫� b.id 涓� NULL锛屽凡鏀舵棰濇寜 stock_out_record_ids 姹囨�伙紱
+         鈶� 娌瑰搧鍑哄簱锛坱ype 涓虹┖锛夋寜銆屽嚭搴撳崟脳瀹㈡埛銆嶆媶鍒扮粦瀹氳 鈫� 宸叉敹娆鹃鎸� stock_out_binding_ids 姹囨�伙紝
+         閲戦鍙畻璇ュ鎴峰垎鎽婄殑閭i儴鍒嗐�備袱涓� id 绌洪棿涓嶈兘娣锋瘮锛屾晠鎸� b.id 鏄惁涓虹┖鍒嗗紑銆�
+         宸叉敹娆鹃鏀规垚鏍囬噺瀛愭煡璇細鍘熸潵鐢� LEFT JOIN + GROUP BY outbound_batches 鑱氬悎锛屼笖鏉′欢鍐欐垚
+         acsc.stock_out_record_ids = sor.id锛堢瓑鍊兼瘮閫楀彿涓诧級锛屼竴涓嚭搴撳崟鏀惰繃娆惧悗闈㈢殑灏卞啀涔熷尮閰嶄笉涓娿�� -->
     <select id="getOutboundBatchesByCustomer"
             resultType="com.ruoyi.account.bean.vo.sales.SalesOutboundVo">
         SELECT
@@ -74,36 +84,58 @@
                 SELECT
                     sor.id,
                     sor.outbound_batches,
-                    sl.customer_name,
+                    IFNULL(b.customer_name, sl.customer_name) AS customer_name,
                     sor.create_time AS shipping_date,
-                    p.product_name,
-                    pm.model AS specification_model,
-                    slp.tax_rate,
-                    sor.stock_out_num * slp.tax_inclusive_unit_price AS outbound_amount,
+                    IFNULL(pb.product_name, p.product_name) AS product_name,
+                    IFNULL(pmb.model, pm.model) AS specification_model,
+                    IFNULL(slpb.tax_rate, slp.tax_rate) AS tax_rate,
+                    CASE
+                        WHEN b.id IS NOT NULL THEN b.quantity * slpb.tax_inclusive_unit_price
+                        ELSE sor.stock_out_num * slp.tax_inclusive_unit_price
+                    END AS outbound_amount,
                     s.shipping_no,
-                    sl.sales_contract_no,
-                    COALESCE ( SUM( acsc.collection_amount ), 0 ) AS amount_received
+                    IFNULL(slb.sales_contract_no, sl.sales_contract_no) AS sales_contract_no,
+                    (SELECT COALESCE(SUM(acsc.collection_amount), 0)
+                     FROM account_sales_collection acsc
+                     WHERE (b.id IS NULL AND FIND_IN_SET(sor.id, acsc.stock_out_record_ids) > 0)
+                        OR (b.id IS NOT NULL AND FIND_IN_SET(b.id, acsc.stock_out_binding_ids) > 0)
+                    ) AS amount_received
                 FROM
                     stock_out_record sor
+                        LEFT JOIN stock_out_record_sales_ledger b ON b.stock_out_record_id = sor.id
                         LEFT JOIN shipping_info s ON sor.record_id = s.id
                         LEFT JOIN sales_ledger sl ON s.sales_ledger_id = sl.id
                         LEFT JOIN sales_ledger_product slp ON s.sales_ledger_product_id = slp.id
                         AND slp.type = 1
+                        LEFT JOIN sales_ledger slb ON slb.id = b.sales_ledger_id
+                        LEFT JOIN sales_ledger_product slpb ON slpb.id = b.sales_ledger_product_id
+                        AND slpb.type = 1
                         LEFT JOIN product_model pm ON slp.product_model_id = pm.id
                         LEFT JOIN product p ON pm.product_id = p.id
-                        LEFT JOIN account_sales_collection acsc ON acsc.stock_out_record_ids = sor.id
+                        LEFT JOIN product_model pmb ON sor.product_model_id = pmb.id
+                        LEFT JOIN product pb ON pmb.product_id = pb.id
                 WHERE
-                    sor.record_type = '13'
-                  AND sor.approval_status = 1
-                  AND sl.customer_id = #{customerId}
-                GROUP BY
-                    sor.outbound_batches
+                    sor.approval_status = 1
+                  AND (
+                        sor.record_type = '13'
+                     OR (b.id IS NOT NULL AND (sor.type IS NULL OR sor.type = ''))
+                      )
+                  AND IFNULL(b.customer_id, sl.customer_id) = #{customerId}
                 ORDER BY
-                    sor.id
+                    sor.id, IFNULL(b.id, 0)
             ) tempA
         WHERE
             amount_received &lt; outbound_amount
     </select>
+    <!-- 娌瑰搧鍑哄簱鐨勭粦瀹氳涓庡嚭搴撳崟鏄袱涓嫭绔� id 绌洪棿锛屽垽閲嶈鍒嗗紑鏌� -->
+    <select id="existsByStockOutBindingId" resultType="java.lang.Boolean">
+        SELECT COUNT(*) > 0
+        FROM account_sales_collection
+        WHERE
+        <foreach collection="stockOutBindingIds" item="id" open="(" separator=" OR " close=")">
+            FIND_IN_SET(#{id}, stock_out_binding_ids)
+        </foreach>
+    </select>
     <select id="selectIncomeStats" resultType="com.ruoyi.home.dto.IncomeExpenseAnalysisDto">
          SELECT DATE_FORMAT(collection_date, #{dateFormat}) AS dateStr,
                 IFNULL(SUM(collection_amount), 0)            AS amount

--
Gitblit v1.9.3