From 0414ddb0b2b3a7199ae6181a770f97ac140dbd73 Mon Sep 17 00:00:00 2001
From: zhangf <1603559716@qq.com>
Date: 星期三, 08 五月 2024 16:46:22 +0800
Subject: [PATCH] spi统计

---
 equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialInfoMapper.xml |   86 +++++++++++++++++++++++++++++++++++++-----
 1 files changed, 75 insertions(+), 11 deletions(-)

diff --git a/equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialInfoMapper.xml b/equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialInfoMapper.xml
index cd3cfd2..49f481a 100644
--- a/equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialInfoMapper.xml
+++ b/equipment/equipment-service/src/main/resources/config/mapper/equipment/SafeMaterialInfoMapper.xml
@@ -7,11 +7,14 @@
     <resultMap type="com.gkhy.safePlatform.equipment.entity.SafeMaterialInfo" id="materialResult">
         <id column="id" property="id" jdbcType="BIGINT"/>
         <result column="serial_num" property="serialNum" jdbcType="VARCHAR"/>
-        <result column="material_classify_id" property="materialClassifyId" jdbcType="BIGINT"/>
+        <result column="big_classify_id" property="bigClassifyId" jdbcType="BIGINT"/>
+        <result column="small_classify_id" property="smallClassifyId" jdbcType="BIGINT"/>
         <result column="dep_id" property="depId" jdbcType="BIGINT"/>
         <result column="dep_name" property="depName" jdbcType="VARCHAR"/>
         <result column="material_name" property="materilaName" jdbcType="VARCHAR"/>
         <result column="consumable" property="consumable" jdbcType="TINYINT"/>
+        <result column="total_count" property="totalCount" jdbcType="INTEGER"/>
+        <result column="stock_count" property="stockCount" jdbcType="INTEGER"/>
         <result column="del_flag" property="delFlag" jdbcType="INTEGER"/>
         <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
         <result column="create_uid" property="createUid" jdbcType="BIGINT"/>
@@ -21,16 +24,33 @@
         <result column="update_uname" property="updateUname" jdbcType="VARCHAR"/>
     </resultMap>
     <!--查询单条数据-->
-    <select id="queryById" resultMap="materialResult">
-        select id,serial_num,material_classify_id,dep_id,dep_name,material_name,consumable,del_flag,create_time,create_uid,create_uname,update_time,update_uid,update_uname from safe_material where id = #{id} and del_flag = 0;
+    <select id="queryById" resultType="com.gkhy.safePlatform.equipment.entity.SafeMaterialDO">
+        select m.id,
+               m.serial_num,
+               m.big_classify_id as bigClassifyId,
+               m.small_classify_id as smallClassifyId,
+               m.dep_id,
+               m.dep_name,
+               m.material_name,
+               m.consumable,
+               m.stock_count,
+               m.total_count,
+               m.create_time,
+               m.material_name as smallClassifyName,
+               c.material_classify_name as bigClassifyName
+        from safe_material m
+        inner join safe_material_classify c
+        on m.big_classify_id = c.id
+        where m.del_flag = 0
+        and m.id = #{id};
     </select>
     <!--查询所有数量-->
     <select id="getTotalCount" resultType="java.lang.Integer">
         select count(1) from safe_material;
     </select>
-    <!--根据类型统计数量-->
-    <select id="getCountByClassify" resultType="java.lang.Integer">
-        select count(1) from safe_material where del_flag = 0 and material_classify_id = #{classifyId}
+    <!--根据小类型统计数量-->
+    <select id="getCountBySmallClassifyId" resultType="java.lang.Integer">
+        select count(1) from safe_material where del_flag = 0 and small_classify_id = #{smallClassifyId}
     </select>
     <update id="deleteBatch">
         update safe_material set del_flag = 1 where id in
@@ -42,24 +62,68 @@
     <select id="listByConditions" resultType="com.gkhy.safePlatform.equipment.entity.SafeMaterialDO">
         select m.id,
                m.serial_num,
-               m.material_classify_id,
+               m.big_classify_id as bigClassifyId,
+               m.small_classify_id as smallClassifyId,
                m.dep_id,
                m.dep_name,
                m.material_name,
                m.consumable,
-               c.material_classify_name
+               m.stock_count,
+               m.total_count,
+               m.create_time,
+               m.material_name as smallClassifyName,
+               c.material_classify_name as bigClassifyName
         from safe_material m
         inner join safe_material_classify c
-        on m.material_classify_id = c.id
+        on m.big_classify_id = c.id
         where m.del_flag = 0
         <if test="query.materialName != null and query.materialName != '' ">
             and instr(m.material_name,#{query.materialName})>0
         </if>
-        <if test="query.materialClassifyId != null">
-            and m.material_classify_id = #{query.materialClassifyId}
+        <if test="query.bigClassifyId != null">
+            and m.big_classify_id = #{query.bigClassifyId}
+        </if>
+        <if test="query.depId != null">
+            and m.dep_id = #{query.depId}
         </if>
         order by m.create_time desc
     </select>
+    <select id="checkMatrial" resultType="java.lang.Integer">
+        select count(1)
+        from safe_material
+        where del_flag = 0
+        and small_classify_id = #{smallClassifyId}
+        and dep_id = #{depId}
+        <if test="id != null">
+            and id != #{id}
+        </if>
+    </select>
+    <update id="updateCountById">
+        update safe_material
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="totalCount != null">
+                total_count = total_count + #{totalCount},
+            </if>
+            <if test="stockCount != null">
+                stock_count = stock_count + #{stockCount},
+            </if>
+        </trim>
+        where id = #{id}
+    </update>
+    <update id="updateStockCount">
+        <foreach collection="safeMaterialBOList" item="safeMaterialBO" separator=";">
+            update safe_material
+            <trim prefix="SET" suffixOverrides=",">
+                <if test="safeMaterialBO.totalCount != null">
+                    total_count = total_count + #{safeMaterialBO.totalCount},
+                </if>
+                <if test="safeMaterialBO.stockCount != null">
+                    stock_count = stock_count + #{safeMaterialBO.stockCount}
+                </if>
+            </trim>
+            where id = #{safeMaterialBO.id}
+        </foreach>
 
+    </update>
 
 </mapper>

--
Gitblit v1.9.2