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/processInv/mapper/ProcessInvMapper.xml |   99 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 89 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/springblade/modules/processInv/mapper/ProcessInvMapper.xml b/src/main/java/org/springblade/modules/processInv/mapper/ProcessInvMapper.xml
index f0156dc..a163d77 100644
--- a/src/main/java/org/springblade/modules/processInv/mapper/ProcessInvMapper.xml
+++ b/src/main/java/org/springblade/modules/processInv/mapper/ProcessInvMapper.xml
@@ -20,31 +20,42 @@
 
     <select id="selectProcessInvPage" resultMap="processInvResultMap">
         select inv.*,m.machining_tp,
-               m.machining_type,strain_name
+               m.machining_type
         from sys_process_inv inv
         LEFT JOIN sys_machining m ON m.id = inv.product_id
-        LEFT JOIN sys_strain strain ON strain.id = inv.strain_id
-        where inv.is_deleted = 0
-        <if test="processInv.farmId != null and processInv.farmId != ''">
-            AND inv.farm_id = #{processInv.farmId}
+        LEFT JOIN sys_farm_product_stock fps ON inv.fps_id = fps.id
+        LEFT JOIN sys_land land ON land.id = fps.land_id
+        where inv.is_deleted = 0 AND inv.product_inventory_num != 0
+        <if test="processInv.fpsId != null and processInv.fpsId != ''">
+            AND inv.fps_id = #{processInv.fpsId}
+        </if>
+        <if test="processInv.farmId != null and processInv.farmId !=''">
+            AND inv.fps_id = #{processInv.farmId}
         </if>
     </select>
 
-    <select id="selectBy2Id" resultType="org.springblade.modules.processInv.entity.ProcessInv">
+    <select id="selectBySPId" resultType="org.springblade.modules.processInv.entity.ProcessInv">
         SELECT id,strain_id,product_id,product_inventory_num,create_time,update_user,update_time,status,is_deleted
-        FROM sys_process_inv WHERE strain_id = #{strainId} AND product_id = #{productId}
+        FROM sys_process_inv
+        WHERE is_deleted = 0 AND strain_id = #{strainId} AND product_id = #{productId} AND fps_id = #{fpsId}
+    </select>
+
+    <select id="selectBySFId" resultType="org.springblade.modules.processInv.entity.ProcessInv">
+        SELECT id,strain_id,product_id,product_inventory_num,create_time,update_user,update_time,status,is_deleted
+        FROM sys_process_inv
+        WHERE is_deleted = 0 AND strain_id = #{strainId} AND fps_id = #{fpsId}
     </select>
 
     <insert id="add">
-        INSERT INTO sys_process_inv (strain_id,product_id,product_inventory_num,create_time,status,is_deleted)
-        VALUES (#{processInv.strainId},#{processInv.productId},#{processInv.productInventoryNum},NOW(),1,0)
+        INSERT INTO sys_process_inv (strain_id,product_id,product_inventory_num,create_time,status,is_deleted,fps_id)
+        VALUES (#{processInv.strainId},#{processInv.productId},#{processInv.productInventoryNum},NOW(),1,0,#{processInv.fpsId})
     </insert>
 
     <select id="stockCompare" resultType="java.lang.Boolean">
         SELECT
             CASE
                 WHEN
-                    product_inventory_num > #{saleNum} THEN
+                    product_inventory_num >= #{saleNum} THEN
                     TRUE ELSE FALSE
                 END result
         FROM
@@ -58,8 +69,76 @@
         WHERE
             id = #{proid}
     </update>
+    <update id="stockAdd">
+        UPDATE sys_process_inv SET product_inventory_num = product_inventory_num + #{saleNum}
+        WHERE
+            id = #{proid}
+    </update>
 
     <delete id="del">
         DELETE FROM sys_process_inv WHERE id = #{id}
     </delete>
+
+    <select id="getLand" resultType="org.springblade.modules.processInv.vo.ProcessInvVO">
+        SELECT inv.id,inv.fps_id,fps.land_id
+        FROM sys_process_inv inv
+        LEFT JOIN sys_farm_product_stock fps ON inv.fps_id = fps.id
+        WHERE inv.is_deleted = 0
+        <if test="processInv.id != null and processInv.id != ''">
+            AND inv.id = #{processInv.id}
+        </if>
+    </select>
+    <select id="findById" resultType="org.springblade.modules.processInv.entity.ProcessInv">
+        SELECT id,strain_id,product_id,product_inventory_num,create_time,update_user,update_time,status,is_deleted
+        FROM sys_process_inv
+        WHERE is_deleted = 0 AND id = #{prodId}
+    </select>
+    <select id="statisticsStock" resultType="java.lang.Double">
+        SELECT SUM(inv.product_inventory_num) as sum
+        FROM sys_process_inv inv
+        WHERE 1=1 AND inv.is_deleted = 0
+        <if test="year!=null and year!=''">
+            and YEAR ( inv.create_time ) = #{year}
+        </if>
+        <if test="farmId!=null and farmId!=''">
+            and inv.fps_id = #{farmId}
+        </if>
+    </select>
+    <select id="selectByFarmIdProductId" resultType="org.springblade.modules.processInv.entity.ProcessInv">
+--         SELECT id,strain_id,product_id,product_inventory_num,create_time,update_user,update_time,status,is_deleted,fps_id
+        SELECT *
+        FROM sys_process_inv
+        WHERE is_deleted = 0
+        <if test="farmId != null and farmId !=''">
+            AND fps_id = #{farmId}
+        </if>
+        <if test="productId != null and productId !=''">
+            AND product_id = #{productId}
+        </if>
+    </select>
+    <select id="selectByProcessIdLandId" resultType="org.springblade.modules.processInv.entity.ProcessInv">
+        SELECT
+            inv.id,
+            inv.strain_id,
+            inv.product_id,
+            inv.product_inventory_num,
+            inv.create_time,
+            inv.update_user,
+            inv.update_time,
+            inv.fps_id,
+            inv.status,
+            inv.is_deleted
+        FROM
+            sys_process_inv inv
+            LEFT JOIN sys_land l ON l.farm_id = inv.fps_id
+        WHERE inv.is_deleted = 0 AND 1=1
+        <if test="processId !=null and processId !='' ">
+           AND inv.product_id = #{processId}
+        </if>
+        <if test="landId !=null and landId !='' ">
+            AND l.id = #{landId}
+        </if>
+
+    </select>
+
 </mapper>

--
Gitblit v1.9.3