kongzy
2024-09-23 d015cc0b48ca51a2b93b6c60c91dc352a104b1e7
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<?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.SafeMaterialDetailInfoRepository">
 
    <resultMap type="com.gkhy.safePlatform.equipment.entity.SafeMaterialDetailInfo" id="materialDetailResult">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
        <result column="material_no" property="materialNo" jdbcType="VARCHAR"/>
        <result column="big_classify_id" property="bigClassifyId" jdbcType="BIGINT"/>
        <result column="small_classify_id" property="smallClassifyId" jdbcType="BIGINT"/>
        <result column="rfid" property="rfid" jdbcType="VARCHAR"/>
        <result column="consumable" property="consumable" jdbcType="TINYINT"/>
        <result column="valid_type" property="validType" jdbcType="TINYINT"/>
        <result column="valid_time" property="validTime" jdbcType="TIMESTAMP"/>
        <result column="valid_status" property="validStatus" jdbcType="TINYINT"/>
        <result column="status" property="status" jdbcType="TINYINT"/>
        <result column="ir_status" property="irStatus" jdbcType="TINYINT"/>
        <result column="ware_housing_time" property="wareHousingTime" jdbcType="TIMESTAMP"/>
        <result column="delivery_time" property="deliveryTime" jdbcType="TIMESTAMP"/>
        <result column="sm_id" property="smId" jdbcType="BIGINT"/>
        <result column="receive_uid" property="receiveUid" jdbcType="BIGINT"/>
        <result column="receive_uname" property="receiveUname" jdbcType="VARCHAR"/>
        <result column="remark" property="remark" jdbcType="VARCHAR"/>
        <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="getTotalCount" resultType="java.lang.Integer">
        select count(1) from safe_material_detail
    </select>
    <select id="queryById" resultMap="materialDetailResult">
        select id,
               name,
               material_no,
               big_classify_id,
               rfid,
               consumable,
               valid_type,
               valid_time,
               valid_status,
               status,
               ir_status,
               ware_housing_time,
               delivery_time,
               sm_id,
               receive_uid,
               receive_uname
        from safe_material_detail where del_flag = 0 and id = #{id}
    </select>
    <update id="updateReceiptStatus" >
        update safe_material_detail
        set ir_status = #{status},
            ware_housing_time = #{wareHousingTime},
            receive_uid = null,
            receive_uname = null,
            delivery_time = null
        where id = #{id}
    </update>
    <select id="getListByIds" resultMap="materialDetailResult">
        select id,name,material_no,big_classify_id,rfid,consumable,valid_type,valid_time,valid_status,status,ir_status,ware_housing_time,ware_housing_time,delivery_time,sm_id,receive_uid,
        receive_uname,remark
               from safe_material_detail
               where del_flag = 0
                 and id in
                <foreach collection="ids" item="id" separator="," open="(" close=")">
                    #{id}
                </foreach>
    </select>
    <update id="updateReceiptStatusByIds" >
        update safe_material_detail
        set ir_status = #{irStatus},
            ware_housing_time = #{wareHousingTime},
            receive_uid = null,
            receive_uname = null,
            delivery_time = null
            where id in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </update>
    <select id="getCountGroupBySmId" resultType="com.gkhy.safePlatform.equipment.entity.SafeMaterialDetailCountDO">
        select smId,count(*)
        from safe_material_detail
        where del_flag = 0
          and ir_status = #{irStatus}
          and id in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
        group by smId
    </select>
    <select id="getStatisticsValidStock" resultType="com.gkhy.safePlatform.equipment.entity.SafeMaterialDetailCountDO">
        select count(1) as count,
               sm_id
        from safe_material_detail
        where del_flag = 0
            and valid_status = #{validStatus}
            and ir_status = #{irStatus}
            and sm_id in
            <foreach collection="smIds" item="smId" open="(" close=")" separator=",">
                #{smId}
            </foreach>
        GROUP BY
            sm_id
    </select>
    <!--批量删除-->
    <update id="deleteBatch">
        update safe_material_detail set del_flag = 1 where id in
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </update>
    <!--批量出库-根据ids-->
    <update id="updateDeliveryStatusByIds" >
        update safe_material_detail
        set ir_status = #{detailBO.irStatus},
            receive_uid = #{detailBO.receiveUid},
            receive_uname = #{detailBO.receiveUname},
            delivery_time = #{detailBO.deliveryTime}
        where id in
        <foreach collection="detailBO.ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </update>
 
    <select id="getValidStockCount" resultType="java.lang.Integer">
      select count(1)
      from safe_material_detail
      where del_flag = 0
        and valid_status = #{validStatus}
        and ir_status = #{irStatus}
        and sm_id = #{smId}
    </select>
    <select id="listByCondition" resultType="com.gkhy.safePlatform.equipment.entity.SafeMaterialDetailInfoDO">
        select sd.id,
               CONCAT(sd.name,'(',sm.serial_num,')') as name,
               sd.material_no,
               sd.big_classify_id,
               sd.rfid,
               sd.consumable,
               sd.valid_type,
               sd.valid_time,
               sd.valid_status,
               sd.status,
               sd.remark,
               sd.ir_status,
               sd.ware_housing_time,
               sd.receive_uname,
               sd.delivery_time,
               sm.dep_id,
               sm.dep_name,
               sd.sm_id,
               sc.material_classify_name as bigClassifyName
        from safe_material_detail sd
                 INNER JOIN safe_material_classify sc on sd.big_classify_id = sc.id
                 INNER JOIN safe_material sm on sd.sm_id = sm.id
        where sd.del_flag = 0
        <if test="query.rfid != null and query.rfid != '' ">
            and sd.rfid = #{query.rfid}
        </if>
        <if test="query.irStatus != null">
            and sd.ir_status = #{query.irStatus}
        </if>
        <if test="query.smId != null">
            and sd.sm_id = #{query.smId}
        </if>
        <if test="query.depId != null">
            and sm.dep_id = #{query.depId}
        </if>
        ORDER BY sd.create_time desc
    </select>
 
    <!--根据smId统计数量-->
    <select id="getCountBySmId" resultType="java.lang.Integer">
        select count(1) from safe_material_detail where del_flag = 0 and sm_id = #{smId}
    </select>
    <!--根据smIds统计数量-->
    <select id="getCountBySmIds" resultType="java.lang.Integer">
        select count(1) from safe_material_detail where del_flag = 0 and sm_id in
        <foreach collection="smIds" item="smId" open="(" close=")" separator=",">
            #{smId}
        </foreach>
    </select>
 
    <update id="updateValidStatus" >
        update safe_material_detail set valid_status = #{validStatus} where id = #{id}
    </update>
    <select id="getRfidNotNullList" resultType="java.lang.Long">
        select id from safe_material_detail where sm_id = #{smId} and ir_status = 0 and valid_status = 0 and del_flag = 0 and rfid is not null ORDER BY ware_housing_time asc LIMIT #{count}
    </select>
 
    <select id="getRfidNullList" resultType="java.lang.Long">
        select id from safe_material_detail where sm_id = #{smId} and ir_status = 0 and valid_status = 0 and del_flag = 0 and rfid is null ORDER BY ware_housing_time asc LIMIT #{count}
    </select>
    <select id="getListBySmIdAndRfid" resultType="com.gkhy.safePlatform.equipment.entity.SafeMaterialDetailInfo">
        select id,
               name,
               material_no,
               big_classify_id,
               rfid,
               consumable,
               valid_type,
               valid_time,
               valid_status,
               status,
               ir_status,
               ware_housing_time,
               delivery_time,
               sm_id,
               receive_uid,
               receive_uname
        from safe_material_detail where del_flag = 0 and sm_id = #{query.smId} and ir_status = #{query.irStatus} and valid_status = #{query.validStatus} and rfid = #{query.rfid} ORDER BY create_time asc LIMIT #{query.count}
    </select>
    <select id="getListBySmId" resultType="com.gkhy.safePlatform.equipment.entity.SafeMaterialDetailInfo">
        select id,
               name,
               material_no,
               big_classify_id,
               rfid,
               consumable,
               valid_type,
               valid_time,
               valid_status,
               status,
               ir_status,
               ware_housing_time,
               delivery_time,
               sm_id,
               receive_uid,
               receive_uname
        from safe_material_detail where del_flag = 0 and sm_id = #{query.smId} and ir_status = #{query.irStatus} and valid_status = #{query.validStatus} ORDER BY create_time asc LIMIT #{query.count}
    </select>
    <select id="getSmallClassifyStockByIds" resultType="com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyStockDO">
        select d.small_classify_id,
        m.dep_id,
        m.dep_name,
        count(1) as stockCount
        from safe_material_detail d
        INNER JOIN safe_material m
        ON d.sm_id = m.id
        where d.del_flag = 0
        and d.ir_status = 0
        and d.valid_status = 0
        and d.small_classify_id in
        <foreach collection="smallClassifyIds" item="smallClassifyId" separator="," open="(" close=")">
            #{smallClassifyId}
        </foreach>
        group By d.small_classify_id,m.dep_id,m.dep_name
    </select>
    <select id="getListBySmallClassifyIds" resultType="com.gkhy.safePlatform.equipment.entity.SafeMaterialDetailDO">
        SELECT
        sd.id,
        sd.rfid,
        sm.dep_id,
        sd.small_classify_id,
        sd.big_classify_id
        FROM
        safe_material_detail sd
        INNER JOIN safe_material sm ON sd.sm_id = sm.id
        WHERE
        sd.del_flag = 0
        AND sd.ir_status = 0
        AND sd.valid_status = 0
        AND sd.small_classify_id IN
        <foreach collection="smallClassifyIds" item="smallClassifyId" open="(" close=")" separator=",">
            #{smallClassifyId}
        </foreach>
        AND sm.dep_id IN
        <foreach collection="depIds" item="depId" open="(" close=")" separator=",">
            #{depId}
        </foreach>
        ORDER BY
        sd.create_time ASC
    </select>
    <select id="getListByRfids" resultType="com.gkhy.safePlatform.equipment.entity.SafeMaterialDetailInfoDO">
        SELECT
            sd.id,
            CONCAT( sd.NAME, '(NO', sd.material_no, ')' ) as name,
            sd.big_classify_id,
            sd.small_classify_id,
            sm.dep_id
        FROM
            safe_material_detail sd
        inner join safe_material sm on sd.sm_id = sm.id
        WHERE
            sd.del_flag = 0
          AND sd.ir_status = 1
          AND sd.rfid in
        <foreach collection="rfids" item="rfid" open="(" close=")" separator=",">
            #{rfid}
        </foreach>
    </select>
    <select id="updateValidStatusByIds" >
        update safe_material_detail set valid_status = #{validStatus} where id in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </select>
    <select id="getUnValidList" resultType="com.gkhy.safePlatform.equipment.entity.SafeMaterialDetailInfo">
        select
            id,
            name,
            material_no,
            big_classify_id,
            rfid,
            consumable,
            valid_type,
            valid_time,
            valid_status,
            ir_status,
            ware_housing_time,
            ware_housing_time,
            delivery_time,
            sm_id,
            receive_uid,
            receive_uname,
            status
        from safe_material_detail
        where del_flag = 0
            and valid_status = #{validStatus}
            and  DATE_FORMAT(valid_time,'%Y%m%d') &lt; DATE_FORMAT(CURDATE( ),'%Y%m%d')
    </select>
    <update id="updateBatch" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
            update safe_material_detail
            <trim prefix="SET" suffixOverrides=",">
                <if test="null != item.receiveUid">
                    receive_uid = #{item.receiveUid},
                </if>
                <if test="null != item.receiveUname and '' != item.receiveUname">
                    receive_uname = #{item.receiveUname},
                </if>
                <if test="null != item.irStatus">
                    ir_status = #{item.irStatus},
                </if>
                <if test="null != item.deliveryTime">
                    delivery_time = #{item.deliveryTime}
                </if>
                <if test="null != item.validStatus">
                    valid_status = #{item.validStatus}
                </if>
                <if test="null != item.remark and '' != item.remark">
                    remark = #{item.remark}
                </if>
                <if test="null != item.status">
                    status = #{item.status}
                </if>
 
            </trim>
            where id = #{item.id}
        </foreach>
    </update>
</mapper>