From 0d7c3e7923c420ae6d3f8feff280bf4fcaac5ce7 Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期四, 28 五月 2026 11:22:06 +0800
Subject: [PATCH] feat 人员合同、设备定时保养、排班之后APP推送通知

---
 src/main/resources/mapper/stock/StockInventoryMapper.xml |   63 ++++++++++++++++++++++++++++++-
 1 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/src/main/resources/mapper/stock/StockInventoryMapper.xml b/src/main/resources/mapper/stock/StockInventoryMapper.xml
index 428e8da..a8642f0 100644
--- a/src/main/resources/mapper/stock/StockInventoryMapper.xml
+++ b/src/main/resources/mapper/stock/StockInventoryMapper.xml
@@ -222,6 +222,7 @@
         unit,
         product_name,
         product_id
+        order by combined.create_time desc
     </select>
 
     <select id="listStockInventoryExportData" resultType="com.ruoyi.stock.execl.StockInventoryExportData">
@@ -367,6 +368,7 @@
                 and sir.create_time &lt;= #{ew.endMonth}
             </if>
         </where>
+        order by sir.id desc
     </select>
 
     <select id="stockInAndOutRecord" resultType="com.ruoyi.stock.dto.StockInventoryDto">
@@ -512,8 +514,9 @@
           and (si.qualitity - ifnull(si.locked_quantity, 0)) > 0
         order by si.product_model_id, si.batch_no
     </select>
-    <select id="getByModelId" resultType="com.ruoyi.stock.pojo.StockInventory">
-        select si.id, si.batch_no, si.locked_quantity, (si.qualitity - IFNULL(sd.qualitity, 0)) as qualitity
+    <select id="getByModelId" resultType="com.ruoyi.stock.dto.StockInventoryDto">
+        select si.id, si.batch_no, si.locked_quantity, (si.qualitity - IFNULL(sd.qualitity, 0)) as qualitity,
+               p.product_name, pm.model, pm.unit
         from stock_inventory si
                  left join (
                     select spd.stock_inventory_id, sum(spd.quantity) as qualitity
@@ -530,6 +533,8 @@
                     )
                     group by spd.stock_inventory_id
                  ) as sd on sd.stock_inventory_id = si.id
+                 left join product_model pm on si.product_model_id = pm.id
+                 left join product p on pm.product_id = p.id
         where si.product_model_id = #{productModelId}
         and si.qualitity > IFNULL(sd.qualitity, 0)
     </select>
@@ -668,4 +673,58 @@
         batch_no
     </select>
 
+    <!-- 鍒嗛〉鏌ヨ浜у搧搴撳瓨鍜岄鐢ㄩ噺锛堟寜鎵瑰彿鍖哄垎锛� -->
+    <select id="pageStockAndBorrow" resultType="com.ruoyi.stock.dto.StockInventoryDto">
+        WITH RECURSIVE product_tree AS (
+            SELECT id
+            FROM product
+            WHERE id = #{ew.topParentProductId}
+            UNION ALL
+            SELECT p.id
+            FROM product p
+            INNER JOIN product_tree pt ON p.parent_id = pt.id
+        )
+        SELECT
+            pm.id as product_model_id,
+            pm.model,
+            pm.product_code,
+            pm.unit,
+            p.product_name,
+            p.id as product_id,
+            si.batch_no,
+            IFNULL(si.qualitity, 0) as qualitity,
+            IFNULL(si.locked_quantity, 0) as locked_quantity,
+            IFNULL(borrowed.borrowed_quantity, 0) as borrowed_quantity,
+            IFNULL(si.qualitity, 0) - IFNULL(borrowed.borrowed_quantity, 0) as available_quantity
+        FROM product_model pm
+        LEFT JOIN product p ON pm.product_id = p.id
+        LEFT JOIN stock_inventory si ON pm.id = si.product_model_id
+        LEFT JOIN (
+            SELECT
+                product_model_id,
+                batch_no,
+                SUM(borrow_quantity - IFNULL(returned_quantity, 0)) as borrowed_quantity
+            FROM product_borrow
+            WHERE approval_status = 1
+              AND status != 2
+            GROUP BY product_model_id, batch_no
+        ) borrowed ON pm.id = borrowed.product_model_id
+            AND (si.batch_no = borrowed.batch_no OR (si.batch_no IS NULL AND borrowed.batch_no IS NULL))
+        <where>
+            <if test="ew.topParentProductId != null and ew.topParentProductId > 0">
+                AND p.id IN (SELECT id FROM product_tree)
+            </if>
+            <if test="ew.productName != null and ew.productName != ''">
+                AND p.product_name LIKE CONCAT('%', #{ew.productName}, '%')
+            </if>
+            <if test="ew.model != null and ew.model != ''">
+                AND pm.model LIKE CONCAT('%', #{ew.model}, '%')
+            </if>
+            <if test="ew.batchNo != null and ew.batchNo != ''">
+                AND si.batch_no LIKE CONCAT('%', #{ew.batchNo}, '%')
+            </if>
+        </where>
+        ORDER BY pm.id DESC, si.batch_no
+    </select>
+
 </mapper>

--
Gitblit v1.9.3