kongzy
2024-07-01 47a751cb301d05276ae5d75145d57b2d090fe4e1
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
<?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.OpeReagentStatusDao">
  <resultMap id="OpeReagentStatus" type="com.nanometer.smartlab.entity.OpeReagentStatus">
      <id property="id" column="id"/>
      <result property="reagentId" column="reagent_id"></result>
      <result property="articleNumber" column="article_number"></result>
      <result property="reagentCode" column="reagent_code"></result>
      <result property="status" column="status" ></result>
      <result property="realstatus" column="realstatus" ></result>
      <result property="validFlag" column="valid_flag" ></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="updateTime" column="update_time"></result>
      <result property="remainder" column="remainder"></result>
      <result property="place" column="place"></result>
      <result property="storeType" column="store_type"></result>
      <result property="projectId" column="project_id"></result>
 
      <result property="containerCode" column="containerCode"></result>
      <result property="houseName" column="houseName"></result>
 
 
      <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"></result>
        <result property="createTime" column="create_time"></result>
        <result property="updateTime" column="update_time"></result>
        <result property="supplierName" column="supplierName"></result>
        <result property="deadline" column="deadline"></result>
        <result property="productHome" column="product_home"></result>
        <result property="density" column="density"></result>
    </association>
  </resultMap>
 
    <update id="updateTimeByCode" parameterType="java.util.Map">
        update ope_reagent_status set update_time=now() where reagent_code=#{code}
    </update>
 
    <update id="updateStatusByCode" parameterType="java.util.Map">
        update ope_reagent_status set status=#{status}  where reagent_code=#{code}
    </update>
 
  <sql id="queryWhereSql">
    <if test="reagentId != null and reagentId != ''">
      and oa.reagent_id = #{reagentId}
    </if>
    <if test="userId != null and userId != ''">
      and oa.user_id = #{userId}
    </if>
     <if test="department != null and department != ''">
      and sw.department = #{department}
    </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="articleNumber != null and articleNumber != ''">
      and oa.article_number = #{articleNumber}
    </if>
    <if test="editId != null and editId != ''">
      and oa.id != #{editId}
    </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 = #{reagentName}
    </if>
  </sql>
 
    <sql id="queryWhereSqlForLab">
        <if test="reagentId != null and reagentId != ''">
            and oa.reagent_id = #{reagentId}
        </if>
        <if test="userId != null and userId != ''">
            and oa.user_id = #{userId}
        </if>
        <if test="department != null and department != ''">
            and sw.department = #{department}
        </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="articleNumber != null and articleNumber != ''">
            and oa.article_number = #{articleNumber}
        </if>
        <if test="editId != null and editId != ''">
            and oa.id != #{editId}
        </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="name != null and name != ''">
            and sr.name like #{name}
        </if>
    </sql>
 
 
 
  <sql id="queryColumns">
        select oa.*,
        sr.*,
        sr.id as reagentId,
        su.name as userName,
        <if test="status != null">
            <choose>
                <when test="status == 1 or status == 2">
                    swc.container_code as containerCode,
                    sw.name as houseName,
                </when>
            </choose>
        </if>
         ss.name as supplierName
    </sql>
 
    <sql id="queryJoins">
        left join sys_reagent sr on oa.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
 
        <if test="status != null">
            <choose>
                <when test="status == 1">
                    left join sys_warehouse as sw on sw.id = oa.house_id
                     left join sys_warehouse_container as swc on swc.id = oa.container_id
                </when>
                <when test="status == 2">
                    left join sys_laboratory as sw on sw.id = oa.house_id
                     left join sys_laboratory_container as swc on swc.id = oa.container_id
                </when>
            </choose>
        </if>
    </sql>
 
  <select id="getOpeReagentStatusById"   resultMap="OpeReagentStatus" >
    select oa.*,
        sr.*,
        sr.id as reagentId,
        su.name as userName,
        (case when oa.status=1 then (select sw.container_code from sys_warehouse_container sw where sw.id=oa.container_id)
        when oa.status=2 then (select sw.container_code from sys_laboratory_container sw where sw.id=oa.container_id) else '' END)as containerCode,
        (case when oa.status=1 then (select sw.name from sys_warehouse sw where sw.id=oa.house_id)
        when oa.status=2 then (select sw.name from sys_laboratory sw where sw.id=oa.house_id) else '' END)as houseName,
        ss.name as supplierName
    from ope_reagent_status as oa
       left join sys_reagent sr on oa.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
    where oa.id = #{id} and oa.valid_flag = 1
  </select>
 
    <select id="getOpeReagentStatusByCode"  resultMap="OpeReagentStatus" >
        select oa.*,
               sr.*,
               sr.id as reagentId,
               su.name as userName,
               (case when oa.status=1 then (select sw.container_code from sys_warehouse_container sw where sw.id=oa.container_id)
                     when oa.status=2 then (select sw.container_code from sys_laboratory_container sw where sw.id=oa.container_id) else '' END)as containerCode,
               (case when oa.status=1 then (select sw.name from sys_warehouse sw where sw.id=oa.house_id)
                     when oa.status=2 then (select sw.name from sys_laboratory sw where sw.id=oa.house_id) else '' END)as houseName,
               ss.name as supplierName
        from ope_reagent_status as oa
                 left join sys_reagent sr on oa.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
        where oa.reagent_code = #{reagentCode} and oa.valid_flag = 1
    </select>
 
    <select id="getOpeReagentStatusInfoList" parameterType="java.util.Map"  resultMap="OpeReagentStatus">
        select s.id ,name,cas, deadline,reagent_code,bm3.meta_value reagent_format,r.main_metering,bm1.meta_value reagent_type,bm2.meta_value product_home,
        bm4.meta_value reagent_unit,
        r.density,
        s.article_number
        from ope_reagent_status s
        left join sys_reagent r on r.id = s.reagent_id
        left join base_meta bm1 on bm1.id = r.reagent_type
        left join base_meta bm2 on bm2.id = r.product_home
        left join base_meta bm3 on bm3.id = r.reagent_format
        left join base_meta bm4 on bm4.id = r.reagent_unit
        where s.update_time >= #{startTime} and #{endTime} > s.update_time
        <if test="containerid != null">
              and s.container_id = #{containerid}
        </if>
         <if test="status != null">
              and s.status = #{status}
        </if>
    </select>
 
  <select id="getOpeReagentStatusList" parameterType="java.util.Map" resultMap="OpeReagentStatus">
    <include refid="queryColumns"/>
    from ope_reagent_status as oa
   <include refid="queryJoins"/>
    where oa.valid_flag = 1
    <include refid="queryWhereSql"/>
 
    order by oa.reagent_code asc
    <if test="first != null and pageSize != null">
      limit #{first}, #{pageSize}
    </if>
  </select>
 
 
    <select id="getOpeReagentStatusList22" parameterType="java.util.Map" resultMap="OpeReagentStatus">
        <include refid="queryColumns"/>
        from ope_reagent_status as oa
        left join sys_reagent sr on oa.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
        <if test="status != null">
            <choose>
                <when test="status == 1">
                    inner join sys_warehouse as sw on sw.id = oa.house_id
                    left join sys_warehouse_container as swc on swc.id = oa.container_id
                </when>
                <when test="status == 2">
                    inner join sys_laboratory as sw on sw.id = oa.house_id
                    left join sys_laboratory_container as swc on swc.id = oa.container_id
                </when>
            </choose>
        </if>
        <where>
             oa.valid_flag = 1
            <if test="reagentId != null and reagentId != ''">
                and oa.reagent_id = #{reagentId}
            </if>
            <if test="articleNumber != null and articleNumber != ''">
                and oa.article_number = #{articleNumber}
            </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="applyCode != null and applyCode != ''">
                and oa.apply_code = #{applyCode}
            </if>
        </where>
        order by oa.reagent_code asc
        <if test="first != null and pageSize != null">
            limit #{first}, #{pageSize}
        </if>
    </select>
 
    <select id="getOpeReagentStatusListForLab" parameterType="java.util.Map" resultMap="OpeReagentStatus">
        select oa.*,
        sr.*,
        sr.id as reagentId,
        su.name as userName,
        <if test="status != null">
            <choose>
                <when test="status == 1 or status == 2">
                    swc.container_code as containerCode,
                    sw.name as houseName,
                </when>
            </choose>
        </if>
        ss.name as supplierName
        from ope_reagent_status as oa
        left join sys_reagent sr on oa.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
        <if test="status != null">
            <choose>
                <when test="status == 1">
                    left join sys_warehouse as sw on sw.id = oa.house_id
                    left join sys_warehouse_container as swc on swc.id = oa.container_id
                </when>
                <when test="status == 2">
                    left join sys_laboratory as sw on sw.id = oa.house_id
                    left join sys_laboratory_container as swc on swc.id = oa.container_id
                </when>
            </choose>
        </if>
        where oa.valid_flag = 1
        <if test="reagentId != null and reagentId != ''">
            and oa.reagent_id = #{reagentId}
        </if>
        <if test="userId != null and userId != ''">
            and oa.user_id = #{userId}
        </if>
        <if test="department != null and department != ''">
            and sw.department = #{department}
        </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="articleNumber != null and articleNumber != ''">
            and oa.article_number = #{articleNumber}
        </if>
        <if test="editId != null and editId != ''">
            and oa.id != #{editId}
        </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="name != null and name != ''">
            and sr.name like #{name}
        </if>
        <choose>
            <when test="status == 2 and project != null and project != ''">
                and sw.project like concat("%",#{project},"%")
            </when>
            <when test="status == 2 and labName != null and labName != ''">
                and sw.name like concat("%",#{labName},"%")
            </when>
        </choose>
        order by oa.reagent_code asc
        <if test="first != null and pageSize != null">
            limit #{first}, #{pageSize}
        </if>
    </select>
 
    <select id="getLabNoContainerByProjectId" parameterType="java.util.Map" resultMap="OpeReagentStatus">
        select oa.*,sr.*,sr.id as reagent_id,sl.name as house_name from sys_laboratory sl
        left join ope_reagent_status as oa on oa.house_id=sl.id
        left join sys_reagent sr on sr.id=oa.reagent_id
        where find_in_set(#{projectId},sl.project)
    </select>
 
   <select id="getPersonReagentStatusList" parameterType="java.util.Map" resultMap="OpeReagentStatus">
    <include refid="queryColumns3"/>
    from ope_reagent_status as oa
   <include refid="queryJoins3"/>
    where oa.valid_flag = 1
    <include refid="queryWhereSql3"/>
    <if    test="applyPerson != null and applyPerson != ''"  >
        and su.name like concat("%",#{applyPerson},"%")
    </if>
    <if test="startTime != null and startTime != ''">
        and  #{startTime} &lt; oa.update_time
    </if>
   <if test="endTime != null and endTime != ''">
        and  oa.update_time &lt; #{endTime}
   </if>
 
    order by oa.update_time DESC
    <if test="first != null and pageSize != null">
      limit #{first}, #{pageSize}
    </if>
  </select>
 
  <select id="getOpeReagentStatusTotalCount" parameterType="java.util.Map" resultType="int">
    select count(1)
    from ope_reagent_status as oa
   <include refid="queryJoins"/>
    where oa.valid_flag = 1
    <include refid="queryWhereSql"/>
  </select>
 
    <select id="getOpeReagentStatusTotalCountForLab" parameterType="java.util.Map" resultType="int">
        select count(1)
        from ope_reagent_status as oa
        left join sys_reagent sr on oa.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
        <if test="status != null">
            <choose>
                <when test="status == 1">
                    left join sys_warehouse as sw on sw.id = oa.house_id
                    left join sys_warehouse_container as swc on swc.id = oa.container_id
                </when>
                <when test="status == 2">
                    left join sys_laboratory as sw on sw.id = oa.house_id
                    left join sys_laboratory_container as swc on swc.id = oa.container_id
                </when>
            </choose>
        </if>
        where oa.valid_flag = 1
        <if test="reagentId != null and reagentId != ''">
            and oa.reagent_id = #{reagentId}
        </if>
        <if test="userId != null and userId != ''">
            and oa.user_id = #{userId}
        </if>
        <if test="department != null and department != ''">
            and sw.department = #{department}
        </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="articleNumber != null and articleNumber != ''">
            and oa.article_number = #{articleNumber}
        </if>
        <if test="editId != null and editId != ''">
            and oa.id != #{editId}
        </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="name != null and name != ''">
            and sr.name like #{name}
        </if>
        <choose>
            <when test="status == 2 and project != null and project != ''">
                and sw.project like concat("%",#{project},"%")
            </when>
            <when test="status == 2 and labName != null and labName != ''">
                and sw.name like concat("%",#{labName},"%")
            </when>
        </choose>
    </select>
 
  <select id="getPersonReagentStatusTotalCount" parameterType="java.util.Map" resultType="int">
    select count(1)
    from ope_reagent_status as oa
   <include refid="queryJoins2"/>
   left  join sys_user su on su.id = oa.user_id
    where oa.valid_flag = 1
    <include refid="queryWhereSql2"/>
      <if    test="applyPerson != null and applyPerson != ''"  >
          and su.name like concat("%",#{applyPerson},"%")
      </if>
      <if test="startTime != null and startTime != ''">
          and  #{startTime} &lt; oa.update_time
      </if>
      <if test="endTime != null and endTime != ''">
          and  oa.update_time &lt; #{endTime}
      </if>
  </select>
 
 
    <insert id="insertOpeReagentStatus" parameterType="com.nanometer.smartlab.entity.OpeReagentStatus" useGeneratedKeys = "true" keyProperty = "id">
        insert into ope_reagent_status( reagent_id, article_number, reagent_code, status, house_id, container_id, user_id, remainder, place, store_type, valid_flag, update_time,project_id)
        values ( #{reagentId}, #{articleNumber}, #{reagentCode}, #{status}, #{houseId}, #{containerId}, #{userId}, #{remainder}, #{place}, #{storeType}, 1, now(),#{projectId})
    </insert>
 
 
    <insert id="insertOpeReagentStatus2" parameterType="com.nanometer.smartlab.entity.OpeReagentStatus">
        insert into ope_reagent_status( reagent_id, article_number, reagent_code, status, house_id, container_id, user_id, remainder, place, store_type, valid_flag, update_time,project_id,apply_code,order_code)
        values (#{reagentId}, #{articleNumber}, #{reagentCode}, #{status}, #{houseId}, #{containerId}, #{userId}, #{remainder}, #{place}, #{storeType}, 1, now(),#{projectId},#{applyCode},#{orderCode})
    </insert>
 
    <insert id="batchInsertOpeReagentStatus">
        insert into ope_reagent_status( reagent_id, article_number, reagent_code, status, house_id, container_id, user_id, remainder, place, store_type, valid_flag, update_time,project_id,apply_code,order_code)
        values
        <foreach collection ="list" item="reagentStatus" separator =",">
            (#{reagentStatus.reagentId}, #{reagentStatus.articleNumber}, #{reagentStatus.reagentCode}, #{reagentStatus.status}, #{reagentStatus.houseId}, #{reagentStatus.containerId}, #{reagentStatus.userId}, #{reagentStatus.remainder}, #{reagentStatus.place}, #{reagentStatus.storeType}, 1, now(),#{reagentStatus.projectId},#{reagentStatus.applyCode},#{reagentStatus.orderCode})
        </foreach >
    </insert>
 
    <select id="getOpeReagentStatusByReagentCode"  resultMap="OpeReagentStatus">
        select *
        from ope_reagent_status
        where valid_flag = 1 and reagent_code = #{reagentCode}
    </select>
 
    <select id="getOpeReagentStatusByReagentCode2" parameterType="com.nanometer.smartlab.entity.OpeReagentStatus" resultMap="OpeReagentStatus">
        select *
        from ope_reagent_status
        <where>
            valid_flag = 1 and reagent_code = #{reagentCode}
            <if test="status!=null">
                and status=#{status}
            </if>
        </where>
        limit 1
    </select>
 
     <update id="updateOpeReagentStatusDao" parameterType="com.nanometer.smartlab.entity.OpeReagentStatus">
        update ope_reagent_status set status=#{status},house_id=#{houseId},container_id=#{containerId}, user_id=#{userId}, place=#{place}, update_time=now(),project_id=#{projectId}
        where id=#{id}
    </update>
 
 
    <update id="syncOpeReagentStatus"  parameterType="java.util.Map">
        <choose>
            <!--0:个人领用 1:在仓库sys_warehouse_container 2:在实验室sys_laboratory_container 3:报废-->
            <when test="status == 0">
                update ope_reagent_status set update_time = #{updateTime}, status = #{status}, realstatus = #{realstatus},container_id = 0, house_id = 0, user_id= #{userId} ,remainder= #{remainder} where reagent_code = #{reagentCode}
            </when>
            <when test="status == 1">
                update ope_reagent_status set update_time = #{updateTime}, status = #{status}, realstatus = #{realstatus},house_id= #{houseId}, container_id= #{containerId}, user_id= #{userId} ,remainder= #{remainder} where reagent_code = #{reagentCode}
            </when>
            <when test="status == 2">
                update ope_reagent_status set update_time = #{updateTime}, status = #{status}, realstatus = #{realstatus},house_id= #{houseId}, container_id= #{containerId}, user_id= #{userId} ,remainder= #{remainder} where reagent_code = #{reagentCode}
            </when>
            <when test="status == 3">
                update ope_reagent_status set update_time = #{updateTime}, status = #{status}, realstatus = #{realstatus},user_id= #{userId} ,remainder= #{remainder} where reagent_code = #{reagentCode}
            </when>
        </choose>
    </update>
 
    <update id="updateOpeReagentStatusForInterface" parameterType="com.nanometer.smartlab.entity.OpeReagentStatus">
        update ope_reagent_status set status=#{status}, user_id=#{userId}, update_time=now(), container_id=#{containerId}
        where reagent_code=#{reagentCode}
    </update>
 
 
    <delete id="deleteByReagentCode"  >
        delete from ope_reagent_status
        where reagent_code=#{reagentCode}
    </delete>
 
 
    <select id="getReagentStatusByContainerId"  resultMap="OpeReagentStatus">
        select *
        from ope_reagent_status ors
        LEFT JOIN sys_reagent sr on sr.id = ors.reagent_id
        where ors.valid_flag = 1 and ors.container_id = #{containerId}
    </select>
 
    <sql id="queryJoins2">
        left join sys_reagent sr on oa.reagent_id = sr.id
    </sql>
 
    <sql id="queryWhereSql2">
        <if test="reagentCode != null and reagentCode != ''">
            and oa.reagent_code like #{reagentCode}
        </if>
        <if test="reagentName != null and reagentName != ''">
            and sr.name like concat('%',#{reagentName},'%')
        </if>
        <if test="userId != null and userId != ''">
            and userId=#{userId}
        </if>
    </sql>
 
    <sql id="queryColumns3">
        select oa.*,
        sr.*,
        sr.id as reagentId,
        su.name as userName,
        <if test="status != null">
            <choose>
                <when test="status == 1 or status == 2">
                    swc.container_code as containerCode,
                    sw.name as houseName,
                </when>
            </choose>
        </if>
         ss.name as supplierName
    </sql>
 
    <sql id="queryJoins3">
        left join sys_reagent sr on oa.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
 
        <if test="status != null">
            <choose>
                <when test="status == 1">
                     left join sys_warehouse as sw on sw.id = oa.house_id
                     left join sys_warehouse_container as swc on swc.id = oa.container_id
                </when>
                <when test="status == 2">
                     left join sys_laboratory as sw on sw.id = oa.house_id
                     left join sys_laboratory_container as swc on swc.id = oa.container_id
                </when>
            </choose>
        </if>
    </sql>
     <sql id="queryWhereSql3">
        <if test="reagentId != null and reagentId != ''">
          and oa.reagent_id = #{reagentId}
        </if>
        <if test="userId != null and userId != ''">
          and oa.user_id = #{userId}
        </if>
         <if test="department != null and department != ''">
          and sw.department = #{department}
        </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="articleNumber != null and articleNumber != ''">
          and oa.article_number = #{articleNumber}
        </if>
        <if test="editId != null and editId != ''">
          and oa.id != #{editId}
        </if>
         <if test="reagentCode != null and reagentCode != ''">
          and oa.reagent_code like #{reagentCode}
        </if>
        <if test="reagentName != null and reagentName != ''">
          and sr.name like concat('%',#{reagentName},'%')
        </if>
  </sql>
    <select id="selectByReId" resultMap="OpeReagentStatus">
        select * from ope_reagent_status where reagent_id=#{id}
    </select>
 
    <update id="updateByReId" parameterType="java.util.Map">
        update ope_reagent_status set reagent_id=#{newReId} where reagent_id=#{oldReId}
    </update>
    <update id="updateArticleNumberByRCode">
        update ope_reagent_status set article_number = #{1}
        where reagent_code = #{0}
    </update>
 
    <select id="selectReagentCodesByReId" resultType="string">
    select reagent_code from ope_reagent_status WHERE
    reagent_id = #{reagentId}
    and valid_flag = 1
    ORDER BY update_time
</select>
    <select id="countReagentByArticleAndWarehouse" resultType="java.lang.Integer">
        select count(*)
        from ope_reagent_status
        WHERE status = 1
        <if test="reagentId != null and reagentId !=''">
            and reagent_id = #{reagentId}
        </if>
        <if test="articleNumber != null and articleNumber !=''">
            and article_number = #{articleNumber}
        </if>
        <if test="warehouseId != null and warehouseId !=''">
            and house_id = #{warehouseId}
        </if>
    </select>
    <select id="selectExportList" resultType="java.util.Map">
        select oa.article_number articleNumber,
        oa.reagent_code reagentCode,
        oa.remainder,
        bm1.meta_value productHome,
        bm2.meta_value reagentFomart,
        sr.name reagentName,
        sr.cas cas,
        <if test="status != null">
            <choose>
                <when test="status == 1 or status == 2">
                    swc.container_code as containerCode,
                    sw.name as houseName,
                </when>
            </choose>
        </if>
        ss.name as supplierName
        from ope_reagent_status as oa
        left join sys_reagent sr on oa.reagent_id = sr.id
        left join base_meta bm1 on bm1.id = sr.product_home
        left join base_meta bm2 on bm2.id = sr.reagent_format
        left join sys_supplier as ss on sr.supplier_id = ss.id
        left join sys_user as su on oa.user_id = su.id
        <if test="status != null">
            <choose>
                <when test="status == 1">
                    left join sys_warehouse as sw on sw.id = oa.house_id
                    left join sys_warehouse_container as swc on swc.id = oa.container_id
                </when>
                <when test="status == 2">
                    left join sys_laboratory as sw on sw.id = oa.house_id
                    left join sys_laboratory_container as swc on swc.id = oa.container_id
                </when>
            </choose>
        </if>
        where oa.valid_flag = 1
        <if test="reagentId != null and reagentId != ''">
            and oa.reagent_id = #{reagentId}
        </if>
        <if test="userId != null and userId != ''">
            and oa.user_id = #{userId}
        </if>
        <if test="department != null and department != ''">
            and sw.department = #{department}
        </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="articleNumber != null and articleNumber != ''">
            and oa.article_number = #{articleNumber}
        </if>
        <if test="editId != null and editId != ''">
            and oa.id != #{editId}
        </if>
        <if test="reagentCode != null and reagentCode != ''">
            and oa.reagent_code like  concat("%",#{reagentCode},"%")
        </if>
        <if test="status != null">
            and oa.status = #{status}
        </if>
        <if test="name != null and name != ''">
            and sr.name like concat("%",#{name},"%")
        </if>
        <choose>
            <when test="status == 2 and project != null and project != ''">
                and sw.project like concat("%",#{project},"%")
            </when>
            <when test="status == 2 and labName != null and labName != ''">
                and sw.name like concat("%",#{labName},"%")
            </when>
        </choose>
        order by oa.reagent_code asc
    </select>
    <select id="getStatus" resultMap="OpeReagentStatus">
 
          select *
        from ope_reagent_status
        where valid_flag = 1
        and reagent_code = #{reagentCode}
        and reagent_id = #{reagentId}
    </select>
 
    <update id="updateOpeReagentStatusByCode" parameterType="com.nanometer.smartlab.entity.OpeReagentStatus">
        update ope_reagent_status set status=#{status}
        where reagent_code=#{reagentCode}
    </update>
 
    <update id="batchUpdateReagentStatusByIds">
        update ope_reagent_status set house_id=#{houseId} , container_id=#{containerId},status=#{status}
        where id in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </update>
 
    <select id="getReagentStatusCountByApplyCode" resultType="integer">
        select count(1) from ope_reagent_status where apply_code=#{applyCode} and status!=1
    </select>
</mapper>