From 127a7be36b05ded77e16d6651f55c0d4db848a2c Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期五, 23 一月 2026 14:27:06 +0800
Subject: [PATCH] 诊所一键添加库存修改

---
 ruoyi-system/src/main/resources/mapper/system/TErpProcurementMapper.xml |   30 ++++++++++++++++++++++++------
 1 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/ruoyi-system/src/main/resources/mapper/system/TErpProcurementMapper.xml b/ruoyi-system/src/main/resources/mapper/system/TErpProcurementMapper.xml
index dc9224e..b44e7fb 100644
--- a/ruoyi-system/src/main/resources/mapper/system/TErpProcurementMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/TErpProcurementMapper.xml
@@ -74,19 +74,37 @@
     <select id="inventoryNotEnoughList" resultType="com.ruoyi.system.vo.TErpGoodsVO">
         select * from (
         select <include refid="Base_Column_List1"/>
-        COALESCE(sum(t2.goods_count), 0) - COALESCE(sum(t3.outbound_count), 0) as allNum,
-        SUM(t2.unit_amount * (t2.goods_count - COALESCE(t3.outbound_count, 0))) as allTotalPrice,
+        COALESCE(sum(t5.purchase_count), 0) - COALESCE(sum(t3.outbound_count), 0) as allNum,
+        SUM(t5.unit_amount * (t5.purchase_count - COALESCE(t3.outbound_count, 0))) as allTotalPrice,
 
         COALESCE(sum(t3.outbound_count), 0) as outNum
-        from t_erp_goods t1  left join  t_erp_supplier_warehousing t2  on t1.id = t2.goods_id
-        left join  t_erp_supplier_outbound_goods t3 on t2.id = t3.warehousing_id
-        left join t_crm_supplier t4 on t1.supplier_clinic_id = t4.id and t1.goods_source =1 and t4.status =1
-        where t1.disabled = 0 and t2.id is not null and t1.goods_source =1 and t1.clinic_purchase_price is not null
+        from t_erp_goods t1
+        LEFT JOIN t_erp_clinic_warehousing_batch t5 ON t5.goods_id = t1.id
+        LEFT JOIN t_erp_clinic_outbound_goods t3 ON t3.warehousing_batch_id = t5.id
+        LEFT JOIN t_crm_clinic t4 ON t4.id  = t1.supplier_clinic_id
+        where t1.disabled = 0 and t5.id is not null
+        and (t1.supplier_clinic_id = #{clinicId} or FIND_IN_SET(#{clinicId},t1.clinic_ids))
         GROUP BY t1.id
         ) o where 1=1
         and  o.warning_inventory  > (o.allNum-o.outNum)
         order by o.create_time desc
     </select>
+<!--    <select id="inventoryNotEnoughList" resultType="com.ruoyi.system.vo.TErpGoodsVO">-->
+<!--        select * from (-->
+<!--        select <include refid="Base_Column_List1"/>-->
+<!--        COALESCE(sum(t2.goods_count), 0) - COALESCE(sum(t3.outbound_count), 0) as allNum,-->
+<!--        SUM(t2.unit_amount * (t2.goods_count - COALESCE(t3.outbound_count, 0))) as allTotalPrice,-->
+
+<!--        COALESCE(sum(t3.outbound_count), 0) as outNum-->
+<!--        from t_erp_goods t1  left join  t_erp_supplier_warehousing t2  on t1.id = t2.goods_id-->
+<!--        left join  t_erp_supplier_outbound_goods t3 on t2.id = t3.warehousing_id-->
+<!--        left join t_crm_supplier t4 on t1.supplier_clinic_id = t4.id and t1.goods_source =1 and t4.status =1-->
+<!--        where t1.disabled = 0 and t2.id is not null and t1.goods_source =1 and t1.clinic_purchase_price is not null-->
+<!--        GROUP BY t1.id-->
+<!--        ) o where 1=1-->
+<!--        and  o.warning_inventory  > (o.allNum-o.outNum)-->
+<!--        order by o.create_time desc-->
+<!--    </select>-->
     <select id="pageListWarehouse" resultType="com.ruoyi.system.vo.TErpProcurementVo">
         select t1.id,
                t1.procurement_code,

--
Gitblit v1.7.1