李宇
2021-07-02 5758b702aceacd76f2a1e1a63d848cd4948e99e1
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
<?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.nanometer.smartlab.dao.OpeUseFlowDao">
  <resultMap id="OpeUseFlow" type="com.nanometer.smartlab.entity.OpeUseFlow">
    <id property="id" column="id"/>
    <result property="reagentCode" column="reagent_code"></result>
    <result property="articleNumber" column="articleNumber"></result>
    <result property="status" column="status" typeHandler="com.nanometer.smartlab.entity.handler.ArrivalStatusHandler"></result>
    <result property="houseId" column="house_id"></result>
    <result property="containerId" column="container_id"></result>
    <result property="userId" column="user_id"></result>
    <result property="userName" column="userName"></result>
    <result property="validFlag" column="valid_flag" typeHandler="com.nanometer.smartlab.entity.handler.ValidFlagHandler"></result>
    <result property="createTime" column="create_time"></result>
    <result property="realstatus" column="realstatus"></result>
    <result property="operateState" column="operatestate"></result>
    <result property="remainder" column="remainder"></result>
    <result property="place" column="place"></result>
    <result property="storeType" column="store_type" typeHandler="com.nanometer.smartlab.entity.handler.StoreTypeHandler"></result>
    <result column="laboratoryName" jdbcType="VARCHAR" property="laboratoryName" />
    <result column="warehouseName" jdbcType="VARCHAR" property="warehouseName" />
    <result column="warehouseContainerName" jdbcType="VARCHAR" property="warehouseContainerName" />
    <result column="warehouseContainerCode" jdbcType="VARCHAR" property="warehouseContainerCode" />
    <result column="laboratoryContainerName" jdbcType="VARCHAR" property="laboratoryContainerName" />
    <result column="laboratoryContainerCode" jdbcType="VARCHAR" property="laboratoryContainerCode" />
    <result column="operatestateName" jdbcType="VARCHAR" property="operatestateName" />
    <result column="receipt_number" jdbcType="VARCHAR" property="receiptNumber" />
 
    <association property="reagent" javaType="com.nanometer.smartlab.entity.SysReagent">
          <id property="id" column="reagentId"/>
        <result property="name" column="name"></result>
        <result property="cas" column="cas"></result>
        <result property="reagentType" column="reagent_type"></result>
        <result property="reagentCharacter" column="reagent_character"></result>
        <result property="supplierId" column="supplier_id"></result>
        <result property="reagentFormat" column="reagent_format"></result>
        <result property="mainMetering" column="main_metering"></result>
        <result property="reagentUnit" column="reagent_unit"></result>
        <result property="price" column="price"></result>
        <result property="perBox" column="per_box"></result>
        <result property="memo" column="memo"></result>
        <result property="validFlag" column="valid_flag" typeHandler="com.nanometer.smartlab.entity.handler.ValidFlagHandler"></result>
        <result property="createTime" column="create_time"></result>
        <result property="updateTime" column="update_time"></result>
        <result property="supplierName" column="supplierName"></result>
    </association>
  </resultMap>
 
    <update id="updateTimeByCode" parameterType="java.util.Map">
        update ope_use_flow set create_time=now() where reagent_code=#{code} and status=#{status}
    </update>
    <update id="updateReceiptNumber">
        update ope_use_flow
        set receipt_number = #{1}
        where reagent_code = #{0}
    </update>
    <sql id="queryWhereSql">
    <if test="reagentId != null and reagentId != ''">
      and ors.reagent_id = #{reagentId}
    </if>
    <if test="userId != null and userId != ''">
      and oa.user_id = #{userId}
    </if>
    <if test="departmentUserIds != null">
      and oa.user_id in
      <foreach collection="departmentUserIds" item="item" index="index" open="(" separator="," close=")">
          #{item}
       </foreach>
    </if>
    <if test="reagentCode != null and reagentCode != ''">
      and oa.reagent_code like #{reagentCode}
    </if>
    <if test="status != null">
      and oa.status = #{status}
    </if>
    <if test="reagentName != null and reagentName != ''">
      and sr.name like concat('%',#{reagentName},'%')
    </if>
      <if test="houseName != null and houseName != ''">
          and ( l.name like concat('%',#{houseName},'%') or w.name like concat('%',#{houseName},'%') )
      </if>
    <if test="startDate != null and startDate !=''">
        and oa.create_time &gt;= #{startDate}
    </if>
    <if test="endDate != null and endDate !=''">
        and oa.create_time &lt;= #{endDate}
    </if>
    <if test="operatestate != null and operatestate !=''">
        and bm1.id = #{operatestate}
    </if>
    <if test="containerCode != null and containerCode !=''">
        and wc.container_code = #{containerCode}
        or lc.container_code =#{containerCode}
    </if>
  </sql>
 
    <sql id="queryColumns">
        select oa.*,
        sr.*,
        ors.article_number as articleNumber,
        sr.id as reagentId,
        su.name as userName,
        ss.name as supplierName,
        l.name as laboratoryName,
        w.name as warehouseName,
        lc.name as warehouseContainerName,
        wc.name as laboratoryContainerName,
        lc.container_code as warehouseContainerCode,
        wc.container_code as laboratoryContainerCode,
        bm1.meta_value as operatestateName
    </sql>
 
    <sql id="queryJoins">
        left join ope_reagent_status ors on ors.reagent_code = oa.reagent_code
        left join sys_reagent sr on ors.reagent_id = sr.id
        left join sys_supplier as ss on sr.supplier_id = ss.id
        left join sys_user as su on oa.user_id = su.id
        left join sys_warehouse_container wc on wc.id = oa.container_id
        left join sys_warehouse w on w.id = wc.warehouse_id
        left join sys_laboratory_container lc on lc.id = oa.container_id
        left join sys_laboratory l on l.id = lc.laboratory_id
        left join base_meta bm1 on bm1.id = oa.operatestate
    </sql>
 
    <select id="getOpeUseFlowList" parameterType="java.util.Map" resultMap="OpeUseFlow">
        select oa.*,
        sr.*,
        ors.article_number as articleNumber,
        sr.id as reagentId,
        su.name as userName,
        ss.name as supplierName,
        l.name as laboratoryName,
        w.name as warehouseName,
        wc.name as warehouseContainerName,
        lc.name as laboratoryContainerName,
        wc.container_code as warehouseContainerCode,
        lc.container_code as laboratoryContainerCode,
        bm1.meta_value as operatestateName
        from ope_use_flow as oa
        left join ope_reagent_status ors on ors.reagent_code = oa.reagent_code
        left join sys_reagent sr on ors.reagent_id = sr.id
        left join sys_supplier as ss on sr.supplier_id = ss.id
        left join sys_user as su on oa.user_id = su.id
        left join sys_warehouse_container wc on wc.id = oa.container_id
        left join sys_warehouse w on w.id = wc.warehouse_id
        left join sys_laboratory_container lc on lc.id = oa.container_id
        left join sys_laboratory l on l.id = lc.laboratory_id
        left join base_meta bm1 on bm1.id = oa.operatestate
        where oa.valid_flag = 1
        <include refid="queryWhereSql"/>
           order by oa.create_time desc
    <if test="first != null and pageSize != null">
      limit #{first}, #{pageSize}
    </if>
  </select>
 
  <select id="getOpeUseFlowTotalCount" parameterType="java.util.Map" resultType="int">
    select count(1)
    from ope_use_flow as oa
      <include refid="queryJoins"/>
    where oa.valid_flag = 1
    <include refid="queryWhereSql"/>
  </select>
  <select id="getOpeUseFlowByCode" resultType="com.nanometer.smartlab.entity.OpeUseFlow">
     SELECT
     *
    FROM
    ope_use_flow
    WHERE
    reagent_code = #{reagentCode}
    ORDER BY create_time DESC
    LIMIT 1
  </select>
    <select id="getRegentInfoFromReceiptNumber" resultType="java.util.Map">
        SELECT ors.reagent_id reagentId,count(ors.reagent_id) count
        from  ope_use_flow ouf
        LEFT JOIN ope_reagent_status ors on ors.reagent_code = ouf.reagent_code
        WHERE ouf.receipt_number = #{0}
        GROUP BY ors.reagent_id
    </select>
    <select id="getUserIdByReagentCode" resultType="java.util.Map">
        select user_id,create_time
        from ope_use_flow
        where reagent_code =#{0}
        and operatestate =#{1}
        and valid_flag = 1
        limit 1
    </select>
    <select id="countPersonalUseInfo" resultType="java.lang.Integer">
      select count(0) from (
      SELECT count(0)
        FROM
        ope_use_flow  ouf
        LEFT JOIN sys_user su on su.id = ouf.user_id
        LEFT JOIN base_meta bm on bm.id = ouf.operatestate
        LEFT JOIN ope_reagent_status ors on ors.reagent_code = ouf.reagent_code
        LEFT JOIN sys_reagent sr on sr.id = ors.reagent_id
        left join base_meta bm1 on bm1.id = su.department
        <if test="userId !=null and userId != ''">
            LEFT JOIN sys_reagent sr2 on sr2.id = ouf.user_id
        </if>
        WHERE ouf.operatestate = #{operatestate}
        and   LENGTH(trim(ouf.receipt_number))>0
        and ouf.valid_flag = 1
        <if test="reagentCode !=null and reagentCode != ''">
            and ouf.reagent_code like concat("%",#{reagentCode},"%")
        </if>
        <if test="startTime !=null and startTime != ''">
            and ouf.create_time &gt;#{startTime}
        </if>
        <if test="endTime !=null and endTime != ''">
            and ouf.create_time &lt;#{endTime}
        </if>
        <if test="project !=null and project != ''">
            and su.project like concat("%",#{project},"%")
        </if>
        <if test="department !=null and department != ''">
            and su.bm1.meta_value like concat("%",#{department},"%")
        </if>
        <if test="receiptNumber !=null and receiptNumber != ''">
            and ouf.receipt_number like concat("%",#{receiptNumber},"%")
        </if>
        <if test="reagentName !=null and reagentName != ''">
            and sr.name like concat("%",#{reagentName},"%")
        </if>
        <if test="applyPerson !=null and applyPerson != ''">
            and su.name like concat("%",#{applyPerson},"%")
        </if>
        group by ouf.receipt_number) a
    </select>
    <select id="selectPersonalUseInfo" resultType="com.nanometer.smartlab.entity.OpeUseFlow">
        SELECT ouf.receipt_number receiptNumber,
        count(ouf.reagent_code) applyNum,
        su.name username,
        su.project ,
        su.phone,
        bm1.meta_value department,
        sl.name laboratoryName,
        ouf.create_time createTime,
        ouf.house_id houseId
        FROM
        ope_use_flow  ouf
        LEFT JOIN sys_user su on su.id = ouf.user_id
        LEFT JOIN base_meta bm on bm.id = ouf.operatestate
        LEFT JOIN ope_reagent_status ors on ors.reagent_code = ouf.reagent_code
        LEFT JOIN sys_reagent sr on sr.id = ors.reagent_id
        left join base_meta bm1 on bm1.id = su.department
        left join sys_laboratory sl on sl.id = ouf.house_id
        <if test="userId !=null and userId != ''">
            LEFT JOIN sys_reagent sr2 on sr2.id = ouf.user_id
        </if>
        WHERE ouf.operatestate = #{operatestate}
        and   LENGTH(trim(ouf.receipt_number))>0
        and ouf.valid_flag = 1
        <if test="reagentCode !=null and reagentCode != ''">
            and ouf.reagent_code like concat("%",#{reagentCode},"%")
        </if>
        <if test="startTime !=null and startTime != ''">
            and ouf.create_time &gt;#{startTime}
        </if>
        <if test="endTime !=null and endTime != ''">
            and ouf.create_time &lt;#{endTime}
        </if>
        <if test="project !=null and project != ''">
            and su.project like concat("%",#{project},"%")
        </if>
        <if test="department !=null and department != ''">
            and su.bm1.meta_value like concat("%",#{department},"%")
        </if>
        <if test="receiptNumber !=null and receiptNumber != ''">
            and ouf.receipt_number like concat("%",#{receiptNumber},"%")
        </if>
        <if test="reagentName !=null and reagentName != ''">
            and sr.name like concat("%",#{reagentName},"%")
        </if>
        <if test="applyPerson !=null and applyPerson != ''">
            and su.name like concat("%",#{applyPerson},"%")
        </if>
        group by ouf.receipt_number
        ORDER BY ouf.create_time desc
        <if test="first != null and pageSize != null">
            limit #{first}, #{pageSize}
        </if>
    </select>
    <select id="getApplyInfo" resultType="com.nanometer.smartlab.entity.dto.PersonUseDetail">
         SELECT
        ors.reagent_id reagentId,
        ors.article_number articleNumber,
        ouf.reagent_code reagentCode,
        sr.product_sn productSn,
        sr.NAME reagentName,
        bm.meta_value  reagentFormat,
        CONCAT(sr.main_metering,bm1.meta_value) perInfo,
        bm2.meta_value productHome,
        bm3.meta_value controlProducts
        from `ope_use_flow` ouf
        LEFT JOIN ope_reagent_status ors ON ors.reagent_code = ouf.reagent_code
        LEFT join sys_reagent sr ON ors.reagent_id = sr.id
        LEFT JOIN base_meta bm ON bm.id = sr.reagent_format
        LEFT JOIN base_meta bm1 on bm1.id = sr.reagent_unit
        LEFT JOIN base_meta bm2 on bm2.id = sr.product_home
        LEFT JOIN base_meta bm3 on bm3.id = sr.control_products
        WHERE ouf.operatestate = #{operatestate}
        and ouf.receipt_number = #{receiptNumber}
        and ouf.valid_flag = 1
    </select>
 
 
    <select id="getApplyInfoSize" resultType="java.lang.Integer">
        SELECT
        count(0)
        from `ope_use_flow` ouf
        LEFT JOIN ope_reagent_status ors ON ors.reagent_code = ouf.reagent_code
        LEFT join sys_reagent sr ON ors.reagent_id = sr.id
        LEFT JOIN base_meta bm ON bm.id = sr.reagent_format
        LEFT JOIN base_meta bm1 on bm1.id = sr.reagent_unit
        LEFT JOIN base_meta bm2 on bm2.id = sr.product_home
        LEFT JOIN base_meta bm3 on bm3.id = sr.control_products
        WHERE ouf.operatestate = #{operatestate}
        and ouf.receipt_number = #{receiptNumber}
        and ouf.valid_flag = 1
    </select>
    <select id="countOpeUseFlow" resultType="java.lang.Integer" parameterType="com.nanometer.smartlab.entity.OpeUseFlow">
        select  count(0)
        from ope_use_flow
        where reagent_code = #{reagentCode}
        and status = #{status}
        and house_id = #{houseId}
        and container_id = #{containerId}
        and create_time = #{createTime}
        and operatestate =#{operateState}
        and valid_flag = 1
    </select>
    <select id="selectById" resultType="com.nanometer.smartlab.entity.OpeUseFlow">
        select  *
        from ope_use_flow
        where id = #{id}
    </select>
    <select id="selectByReceiptNumber" resultType="com.nanometer.smartlab.entity.OpeUseFlow">
        SELECT ouf.receipt_number receiptNumber,
        count(ouf.reagent_code) applyNum,
        su.name username,
        su.project ,
        su.phone,
        bm1.meta_value department,
        sl.name laboratoryName,
        ouf.create_time createTime,
        ouf.house_id houseId
        FROM
        ope_use_flow  ouf
        LEFT JOIN sys_user su on su.id = ouf.user_id
        LEFT JOIN base_meta bm on bm.id = ouf.operatestate
        LEFT JOIN ope_reagent_status ors on ors.reagent_code = ouf.reagent_code
        LEFT JOIN sys_reagent sr on sr.id = ors.reagent_id
        left join base_meta bm1 on bm1.id = su.department
        left join sys_laboratory sl on sl.id = ouf.house_id
        <if test="userId !=null and userId != ''">
            LEFT JOIN sys_reagent sr2 on sr2.id = ouf.user_id
        </if>
        WHERE ouf.operatestate = #{operatestate}
        and   LENGTH(trim(ouf.receipt_number))>0
        and ouf.valid_flag = 1
        and ouf.receipt_number =  #{receiptNumber}
        group by ouf.receipt_number
        ORDER BY ouf.create_time desc
    </select>
    <select id="selectAll" resultType="java.util.Map">
        select
        oa.reagent_code as reagentCode,
        sr.`name` as reagentName,
        CASE WHEN wc.container_code is NULL THEN lc.container_code ELSE wc.container_code END as laboratoryContainerCode,
        bm1.meta_value as operatestateName,
        CASE WHEN bm1.meta_value = '仓库入库' or bm1.meta_value='仓库领用' THEN NULL ELSE oa.remainder END as remainder,
        CASE WHEN w.name is NULL THEN l.name ELSE w.name END as warehouseContainerName,
        su.name as userName,
        oa.create_time as createTime
        from ope_use_flow as oa
        left join ope_reagent_status ors on ors.reagent_code = oa.reagent_code
        left join sys_reagent sr on ors.reagent_id = sr.id
        left join sys_supplier as ss on sr.supplier_id = ss.id
        left join sys_user as su on oa.user_id = su.id
        left join sys_warehouse_container wc on wc.id = oa.container_id
        left join sys_warehouse w on w.id = wc.warehouse_id
        left join sys_laboratory_container lc on lc.id = oa.container_id
        left join sys_laboratory l on l.id = lc.laboratory_id
        left join base_meta bm1 on bm1.id = oa.operatestate
        where oa.valid_flag = 1
        <include refid="queryWhereSql"/>
        order by oa.create_time desc
    </select>
    <insert id="insertOpeUseFlow" parameterType="com.nanometer.smartlab.entity.OpeUseFlow">
    insert into ope_use_flow(id, reagent_code, status, house_id, container_id, user_id, remainder, place, store_type, valid_flag, create_time, realstatus, operatestate
    <if test="receiptNumber != null">
        ,receipt_number
    </if>
    )
    values (#{id}, #{reagentCode}, #{status}, #{houseId}, #{containerId}, #{userId}, #{remainder}, #{place}, #{storeType}, 1, #{createTime}, #{realstatus},#{operateState}
        <if test="receiptNumber != null">
            ,#{receiptNumber}
        </if>)
  </insert>
 
 
    <delete id="deleteByReagentCode" parameterType="java.lang.String" >
        delete from ope_use_flow
        where reagent_code=#{reagentCode}
    </delete>
 
 
    <delete id="deleteByReagentCodeAndStatus" parameterType="java.util.Map" >
        update ope_use_flow
        set valid_flag = #{validFlag}
        where reagent_code = #{reagentCode} and status = #{status}
    </delete>
 
 
</mapper>