危化品全生命周期管理后端
heheng
2025-02-26 996c091a4913ac768324b7ea69a8494ba9d6ece0
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?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.hazmat.system.mapper.HzHazmatMapper">
    <resultMap type="com.gkhy.hazmat.system.domain.HzHazmat" id="HzHazmatResult">
        <result property="id"       column="id"       />
        <result property="basicId"    column="basic_id"    />
        <result property="warehouseId"     column="warehouse_id"     />
        <result property="remaining"  column="remaining"  />
        <result property="state"  column="state"  />
        <result property="code"  column="code"  />
        <result property="delFlag"  column="del_flag"  />
        <result property="companyId"         column="company_id"          />
        <result property="version"         column="version"          />
        <result property="createBy"       column="create_by"       />
        <result property="createTime"     column="create_time"     />
        <result property="updateBy"       column="update_by"       />
        <result property="updateTime"     column="update_time"     />
        <result property="remark"         column="remark"          />
        <result property="warehouseName"         column="warehouse_name"          />
        <result property="cupboardName"         column="cupboard_name"          />
        <association property="hazmatBasic" javaType="com.gkhy.hazmat.system.domain.HzHazmatBasic" resultMap="hazmatBasicResult" />
    </resultMap>
 
 
    <resultMap type="com.gkhy.hazmat.system.domain.HzHazmatBasic" id="hazmatBasicResult">
        <result property="id"       column="basic_id"       />
        <result property="name"    column="basic_name"    />
        <result property="cas"     column="basic_cas"     />
        <result property="hazmatType"  column="basic_hazmat_type"  />
        <result property="hazmatCharacter"  column="basic_hazmat_character"  />
        <result property="supplier"  column="basic_supplier"  />
        <result property="minPackage"  column="basic_min_package"  />
        <result property="manufacturer"  column="basic_manufacturer"  />
        <result property="metering"  column="basic_metering"  />
        <result property="unit"  column="basic_unit"  />
        <result property="productSn"  column="product_sn"  />
    </resultMap>
 
    <sql id="selectHazmatVo">
        select a.id, a.basic_id, a.warehouse_id, a.code,a.remaining, a.state,a.company_id,a.version, a.create_by, a.create_time, a.update_by, a.update_time, a.remark,
               b.id as basic_id,b.name as basic_name,b.cas as basic_cas,b.hazmat_type as basic_hazmat_type,b.hazmat_character as basic_hazmat_character,
               b.supplier as basic_supplier,b.manufacturer as basic_manufacturer,b.metering as basic_metering,b.unit as basic_unit,
               b.product_sn,b.min_package as basic_min_package,c.name as warehouse_name,d.cupboard_name as cupboard_name
        from hz_hazmat a
        left join hz_hazmat_basic b on b.id=a.basic_id
        left join hz_warehouse c on c.id=a.warehouse_id
        left join hz_warehouse_cupboard d on d.id=a.cupboard_id
    </sql>
 
    <update id="deleteHazmatById" parameterType="com.gkhy.hazmat.system.domain.HzHazmat">
        update hz_hazmat set del_flag=1 where id=#{hazmatId}
    </update>
 
    <select id="selectHazmatList" resultMap="HzHazmatResult"
            parameterType="com.gkhy.hazmat.system.domain.HzHazmat">
        <include refid="selectHazmatVo"/>
        <where>
            and a.del_flag=0
            <if test="warehouseId != null">
                and a.warehouse_id=#{warehouseId}
            </if>
            <if test="state != null">
                and a.state=#{state}
            </if>
            <if test="basicId != null">
                and a.basic_id=#{basicId}
            </if>
            <if test="entryId != null">
                and a.entry_id=#{entryId}
            </if>
            <if test="companyId != null">
                AND a.company_id= #{companyId}
            </if>
        </where>
        order by a.id desc
    </select>
 
    <select id="selectHazmatGroupWareHouse" resultType="com.gkhy.hazmat.system.domain.vo.HzHazmatWarehouseVO">
        select a.basic_id,a.warehouse_id,a.cupboard_id,
        (select count(1) from hz_hazmat where state=0 and basic_id=a.basic_id and warehouse_id=a.warehouse_id) as stock,
        (select count(1) from hz_hazmat where state=1 and basic_id=a.basic_id and warehouse_id=a.warehouse_id) as miss_stock
        from hz_hazmat a
        left join hz_hazmat_basic b on b.id=a.basic_id
        <where>
            <if test="companyId != null">
                AND a.company_id= #{companyId}
            </if>
            <if test="basicId != null">
                AND a.basic_id= #{basicId}
            </if>
            <if test="state != null">
                AND a.state= #{state}
            </if>
            <if test="warehouseId != null">
                AND a.warehouse_id= #{warehouseId}
            </if>
            <if test="params.name != null and params.name != ''">
                AND b.name like concat(#{params.name},"%")
            </if>
            <if test="params.productSn != null and params.productSn != ''">
                AND b.product_sn =#{params.productSn}
            </if>
            and a.del_flag=0
        </where>
        group by a.basic_id,a.warehouse_id, a.cupboard_id
    </select>
 
 
 
    <select id="selectHazmatCountOfWarehouse" resultType="integer">
        select count(a.id) from hz_hazmat a
        inner join hz_hazmat_basic b on b.id=basic_id
        where a.warehouse_id=#{warehouseId} and b.id=#{basicId} and a.company_id=#{companyId} and b.company_id=#{companyId}
          and a.del_flag=0 and (a.state=0 or a.state=1) and a.cupboard_id = #{cupboardId}
    </select>
 
 
    <select id="selectHazmatWarehouseCheck" resultType="com.gkhy.hazmat.system.domain.vo.TabooDisVo">
        select DISTINCT b.peculiarity_number spNum ,b.id  from hz_hazmat a
                                    inner join hz_hazmat_basic b on b.id=basic_id
        where a.warehouse_id=#{warehouseId}  and a.company_id=#{companyId} and b.company_id=#{companyId}
          and a.del_flag=0 and (a.state=0 or a.state=1) and a.cupboard_id = #{cupboardId}
    </select>
 
    <select id="selectHazmatByCode" resultMap="HzHazmatResult">
        <include refid="selectHazmatVo"/>
        where a.del_flag=0 and a.code=#{code} and a.company_id=#{companyId} limit 1
    </select>
 
    <select id="useCountEverydayStatic" resultType="com.gkhy.hazmat.system.domain.vo.HzEntryRecordVO">
        select count(*) as count, month(create_time) as month,day(create_time) as day from hz_hazmat
        where create_time &gt;= #{startTime} and create_time &lt;= #{endTime} and state in (2,3)
        <if test="companyId!=null">
            and company_id=#{companyId}
        </if>
        group by month,day
        order by month asc,day asc
    </select>
 
    <select id="maxUseCountStatic" resultType="com.gkhy.hazmat.system.domain.vo.HzHazmatUseVO">
        select count(*) as count,basic_id from hz_hazmat
        where create_time &gt;= #{startTime} and create_time &lt;= #{endTime} and state in (1,2,3)
        <if test="companyId!=null">
            and company_id=#{companyId}
        </if>
        group by basic_id
        order by count desc
        limit 10
    </select>
 
    <select id="useCountStatic" resultType="com.gkhy.hazmat.system.domain.vo.HzHazmatUseVO">
        select count(*) as count,basic_id from hz_hazmat
        where create_time &gt;= #{startTime} and create_time &lt;= #{endTime} and state =3
        <if test="companyId!=null">
            and company_id=#{companyId}
        </if>
        group by basic_id
        order by count desc
    </select>
 
 
    <select id="selectWarningHazmatList" resultType="com.gkhy.hazmat.system.domain.HzHazmat">
        select * from hz_hazmat_#{slice} a
        left join hz_hazmat_basic b on b.id=a.basic_id
        left join hz_warning c on c.hazmat_id=a.id and c.state=0
         <where>
            and c.id is null and b.threshold>0 and a.state=2 and DATE_ADD(a.update_time,INTERVAL b.threshold HOUR) &lt;= now()
         </where>
        order by a.id
        limit #{startIndex},#{pageSize}
    </select>
</mapper>