From 684e4306a08feeae188070f264148e6765da8dcf Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期日, 20 九月 2026 19:25:15 +0800
Subject: [PATCH] feat(account): 更新往来付款回款流水表及接口

---
 src/main/resources/mapper/sales/ShippingInfoMapper.xml |   93 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 88 insertions(+), 5 deletions(-)

diff --git a/src/main/resources/mapper/sales/ShippingInfoMapper.xml b/src/main/resources/mapper/sales/ShippingInfoMapper.xml
index aa73dac..fe60cdc 100644
--- a/src/main/resources/mapper/sales/ShippingInfoMapper.xml
+++ b/src/main/resources/mapper/sales/ShippingInfoMapper.xml
@@ -2,6 +2,11 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.sales.mapper.ShippingInfoMapper">
 
+    <!--
+      鍙戣揣鍙拌处鍒楄〃 = 鍙戣揣鍗�(shipping_info) UNION ALL 閿�鍞被娌瑰搧鍑哄簱(stock_out_record)銆�
+      涓ゅ垎鏀垪椤哄簭蹇呴』涓ユ牸涓�鑷达紙鍏� 31 鍒楋級锛屽垪鍚嶄互鍒嗘敮 A 涓哄噯銆�
+      娉ㄦ剰锛氭暟鎹潈闄愭嫤鎴櫒鍙粰绗竴涓� from 鐨勮〃鍔犳潯浠讹紝鍒嗘敮 B 闇�鍦ㄦ湰 XML 閲岃嚜琛岃ˉ鍚岀瓑杩囨护銆�
+    -->
     <select id="listPage" resultType="com.ruoyi.sales.dto.ShippingInfoDto">
         SELECT
         s.id,
@@ -24,7 +29,17 @@
         p.product_name,
         sl.customer_name,
         spd.totalQuantity,
-        sor.outboundBatches
+        sor.outboundBatches,
+        'shipping' as source,
+        NULL as stockOutRecordId,
+        NULL as outCategory,
+        NULL as tankNo,
+        NULL as oilProduct,
+        NULL as oilDepotName,
+        NULL as driverName,
+        NULL as contactPerson,
+        NULL as contactPhone,
+        NULL as outBatchNo
         FROM shipping_info s
         LEFT JOIN (select shipping_info_id,sum(quantity) totalQuantity from shipping_product_detail GROUP BY shipping_info_id) spd ON spd.shipping_info_id = s.id
         LEFT JOIN sales_ledger sl ON s.sales_ledger_id = sl.id
@@ -47,6 +62,68 @@
         </if>
         <if test="req.expressNumber != null and req.expressNumber != ''">
             AND s.express_number LIKE CONCAT('%',#{req.expressNumber},'%')
+        </if>
+        UNION ALL
+        SELECT
+        o.id,
+        NULL as sales_ledger_id,
+        o.out_date as shipping_date,
+        o.truck_plate_no as shipping_car_number,
+        NULL as express_number,
+        NULL as express_company,
+        o.outbound_batches as shipping_no,
+        NULL as type,
+        '宸插彂璐�' as status,
+        o.create_time,
+        o.update_time,
+        o.create_user,
+        o.update_user,
+        NULL as tenant_id,
+        NULL as sales_contract_no,
+        pm2.model as specification_model,
+        pm2.unit,
+        p2.product_name,
+        o.customer_name,
+        o.stock_out_num as totalQuantity,
+        o.outbound_batches as outboundBatches,
+        'oilOut' as source,
+        o.id as stockOutRecordId,
+        o.out_category as outCategory,
+        o.tank_no as tankNo,
+        o.oil_product as oilProduct,
+        o.oil_depot_name as oilDepotName,
+        o.driver_name as driverName,
+        o.contact_person as contactPerson,
+        o.contact_phone as contactPhone,
+        o.batch_no as outBatchNo
+        FROM stock_out_record o
+        left join product_model pm2 on pm2.id = o.product_model_id
+        left join product p2 on p2.id = pm2.product_id
+        WHERE o.out_category = '閿�鍞�' AND o.approval_status = 1
+        <!-- 娌瑰搧鍑哄簱娌℃湁鍚堝悓鍙�/蹇�掑崟锛屾寜杩欎袱椤圭瓫閫夋椂涓嶅簲杩斿洖浠讳綍娌瑰搧琛� -->
+        <if test="req.salesContractNo != null and req.salesContractNo != ''">
+            AND 1=0
+        </if>
+        <if test="req.expressNumber != null and req.expressNumber != ''">
+            AND 1=0
+        </if>
+        <if test="req.shippingCarNumber != null and req.shippingCarNumber != ''">
+            AND o.truck_plate_no LIKE CONCAT('%',#{req.shippingCarNumber},'%')
+        </if>
+        <if test="req.shippingNo != null and req.shippingNo != ''">
+            AND o.outbound_batches LIKE CONCAT('%',#{req.shippingNo},'%')
+        </if>
+        <if test="req.createUser != null">
+            AND o.create_user = #{req.createUser}
+        </if>
+        <if test="req.deptId != null">
+            AND o.dept_id = #{req.deptId}
+        </if>
+        <if test="req.deptIds != null and req.deptIds.length > 0">
+            AND o.dept_id IN
+            <foreach collection="req.deptIds" item="deptId" open="(" separator="," close=")">
+                #{deptId}
+            </foreach>
         </if>
         order by create_time DESC
     </select>
@@ -72,12 +149,14 @@
             slp.product_category,
             slp.specification_model,
             slp.unit,
+            slp.product_model_id,
             sor.outbound_batches,
             sor.stock_out_num,
             sor.batch_no,
             slp.tax_inclusive_unit_price,
             GREATEST(sor.stock_out_num - COALESCE(rs.total_return_num, 0), 0) AS un_quantity,
-            COALESCE(rs.total_return_num, 0) AS total_return_num
+            COALESCE(rs.return_num, 0) AS total_return_num,
+            COALESCE(rs.pending_return_num, 0) AS pending_return_num
         FROM shipping_info si
         LEFT JOIN shipping_product_detail spd ON spd.shipping_info_id = si.id
         LEFT JOIN stock_out_record sor ON sor.record_id = si.id and sor.record_type = '13'
@@ -85,7 +164,9 @@
         LEFT JOIN (
         SELECT
         stock_out_record_id,
-        SUM(num) AS total_return_num
+        SUM(num) AS total_return_num,
+        SUM( CASE WHEN rsp.STATUS = 0 THEN rsp.num ELSE 0 END ) AS pending_return_num ,
+        SUM( CASE WHEN rsp.STATUS = 1 THEN rsp.num ELSE 0 END ) AS return_num
         FROM return_sale_product rsp
         left join return_management rm on rm.id = rsp.return_management_id
         left join shipping_info si on si.id = rm.shipping_id
@@ -97,10 +178,12 @@
                 si.id = #{shippingId}
             </if>
         </where>
+        order by sor.id
     </select>
     <select id="getShippingInfoByCustomerName" resultType="com.ruoyi.sales.pojo.ShippingInfo">
-        select * from shipping_info si
+        select distinct si.* from shipping_info si
         left join sales_ledger sl on si.sales_ledger_id = sl.id
-        where  sl.customer_name = #{customerName}
+        inner join stock_out_record sor on sor.record_id = si.id and sor.record_type = '13' and sor.approval_status = 1
+        where sl.customer_name = #{customerName} and si.status = '瀹℃牳閫氳繃'
     </select>
 </mapper>

--
Gitblit v1.9.3