zhangf
2024-05-08 0414ddb0b2b3a7199ae6181a770f97ac140dbd73
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gkhy.safePlatform.equipment.repository.SafeMaterialInfoRepository">
 
    <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="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"/>
        <result column="create_uname" property="createUname" jdbcType="VARCHAR"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="update_uid" property="updateUid" jdbcType="BIGINT"/>
        <result column="update_uname" property="updateUname" jdbcType="VARCHAR"/>
    </resultMap>
    <!--查询单条数据-->
    <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="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
        <foreach collection="ids" item="id" separator="," open="(" close=")" >
            #{id}
        </foreach>
    </update>
    <!--条件查询-->
    <select id="listByConditions" 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
        <if test="query.materialName != null and query.materialName != '' ">
            and instr(m.material_name,#{query.materialName})>0
        </if>
        <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>