From 72b971c98c46531064d74b68fc8fe8864ed0b544 Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Tue, 08 Nov 2022 09:04:56 +0800
Subject: [PATCH] 大屏溯源统计次数sql修改

---
 src/main/java/org/springblade/modules/InventoryLoss/mapper/InventoryMapper.xml |   33 ++++++++++++++-------------------
 1 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/springblade/modules/InventoryLoss/mapper/InventoryMapper.xml b/src/main/java/org/springblade/modules/InventoryLoss/mapper/InventoryMapper.xml
index 56ac5ee..ffec6f1 100644
--- a/src/main/java/org/springblade/modules/InventoryLoss/mapper/InventoryMapper.xml
+++ b/src/main/java/org/springblade/modules/InventoryLoss/mapper/InventoryMapper.xml
@@ -12,32 +12,27 @@
 
     <select id="selectSalePage" resultMap="inventoryResultMap">
         select inventory.*,
-               strain.strain_name,bdb.dict_value,
-        CASE WHEN inventory.type = 1 THEN
-        (
-        SELECT m.machining_type FROM sys_process_inv inv
-        LEFT JOIN sys_machining m ON m.id = inv.product_id
-        WHERE inventory.prod_id = inv.id
-        )
-        ELSE
-        (
-        SELECT strain.strain_name FROM sys_farm_product_stock sfps
-        LEFT JOIN sys_strain strain ON strain.id = sfps.strain_id
-        WHERE inventory.prod_id = sfps.id
-        )
-        END AS proName
+               strain.strain_name,mach.machining_type AS proName,bdb.dict_value
         from sys_inventory inventory
         LEFT JOIN sys_strain strain on inventory.strain_id = strain.id
         LEFT JOIN blade_dict_biz bdb ON inventory.reason = bdb.dict_key
         LEFT JOIN sys_land land ON land.id = inventory.land_id
+        LEFT JOIN sys_process_inv inv ON inv.id = inventory.prod_id
+        LEFT JOIN sys_machining mach ON mach.id = inv.product_id
         where
-        <if test="inventory.strainId !=null and inventory.strainId != '' ">
-            inventory.strain_id = #{inventory.strainId} AND
+        1=1
+        <if test="inventory.farmId != null and inventory.farmId !=''">
+            AND (land.farm_id = #{inventory.farmId} OR inv.fps_id = #{inventory.farmId})
         </if>
-        <if test="inventory.farmId != null and inventory.farmId !='' ">
-            land.farm_id = #{inventory.farmId} AND
+        <if test="inventory.type != null and inventory.type !='' ">
+            AND inventory.type = #{inventory.type}
         </if>
-              bdb.code = "lossReason" AND inventory.is_deleted = 0 ORDER BY inventory.create_time DESC
+        <if test="inventory.kind != null and inventory.kind !='' ">
+            AND (inv.product_id = #{inventory.kind} OR inventory.strain_id = #{inventory.kind})
+        </if>
+            AND bdb.code = "lossReason"
+            AND inventory.is_deleted = 0
+            ORDER BY inventory.create_time DESC
     </select>
 
 </mapper>

--
Gitblit v1.9.3