危化品全生命周期管理后端
“djh”
2025-05-07 da2c594ade5d69621dd11a13bb758477e2dc079e
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?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 and b.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>
    <select id="useCountHourlyStatic" resultType="com.gkhy.hazmat.system.domain.vo.HzEntryRecordVO">
        SELECT
        DATE_FORMAT(create_time, '%H') AS hour,
        COUNT(*) AS count
        FROM hz_hazmat
        WHERE create_time &gt;= #{startDate}
        AND create_time &lt; #{endDate}
        AND state IN (2, 3)
        <if test="companyId != null">
            AND company_id = #{companyId}
        </if>
        GROUP BY hour
        ORDER BY hour ASC
    </select>
 
 
 
    <select id="companyMessage" resultType="com.gkhy.hazmat.system.domain.vo.HzCompanyMessage">
        SELECT
            sc.id,
            sc.name as company_name,
            scf.longitude,
            scf.latitude,
            COALESCE(hw.warehouse_count, 0) AS warehouse_count,
            COALESCE(htw.warning_count, 0) AS warning_count,
            htw.latest_warning_time
        FROM sys_company sc
                 LEFT JOIN (
            SELECT company_id, COUNT(*) AS warehouse_count
            FROM hz_warehouse
            WHERE del_flag = 0
            GROUP BY company_id
        ) hw ON sc.id = hw.company_id
                 LEFT JOIN (
            SELECT
                company_id,
                COUNT(*) AS warning_count,
                MAX(create_time) AS latest_warning_time
            FROM hz_taboo_warning
            WHERE del_flag = 0
            GROUP BY company_id
        ) htw ON sc.id = htw.company_id
        LEFT JOIN sys_config scf on sc.id = scf.company_id
        <where>
            sc.del_flag = 0
            <if test="type!=null">
                and sc.type = #{type}
            </if>
        </where>
        ORDER BY htw.latest_warning_time DESC;
    </select>
    <select id="countTotal" resultType="java.lang.Integer">
        SELECT
        COUNT(*) AS total_count
        FROM hz_hazmat
        WHERE state IN (2, 3)
        <if test="companyId != null">
            AND company_id = #{companyId}
        </if>
    </select>
    <!--    SELECT COUNT(*) AS count, DATE_FORMAT(create_time, '%H') AS hour-->
<!--    FROM hz_hazmat-->
<!--    WHERE create_time &gt;= #{startDate} AND create_time &lt;  #{endDate}-->
<!--    AND state IN (2, 3)-->
<!--    <if test="companyId != null">-->
<!--        AND company_id = #{companyId}-->
<!--    </if>-->
<!--    GROUP BY hour-->
<!--    ORDER BY hour ASC-->
</mapper>