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
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
<?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.OpeApplyDao">
  <resultMap id="OpeApply" type="com.nanometer.smartlab.entity.OpeApply">
    <id property="id" column="id"/>
      <result property="firstUser" column="first_user"></result>
      <result property="reagentId" column="reagent_id"></result>
      <result property="firName" column="fir_name"></result>
      <result property="secondUserName" column="second_user_name"></result>
    <result property="applyCode" column="apply_code"></result>
    <result property="num" column="num"></result>
    <result property="deadline" column="deadline"></result>
    <result property="applyUserId" column="apply_user_id"></result>
    <result property="projectId" column="project_id"></result>
    <result property="status" column="status" typeHandler="com.nanometer.smartlab.entity.handler.ApplyStatusHandler"></result>
    <result property="createTime" column="create_time"></result>
    <result property="updateTime" column="update_time"></result>
    <result property="validFlag" column="valid_flag" typeHandler="com.nanometer.smartlab.entity.handler.ValidFlagHandler"></result>
    <result property="approveUserId" column="approve_user_id"></result>
    <result property="beforeApproveUserId" column="before_approve_user_id"></result>
    <result property="memo" column="memo"></result>
    <result property="applyUserName" column="apply_user_name"></result>
    <result property="applyUserProject" column="apply_user_project"></result>
    <result property="applyUserDepartment" column="apply_user_department"></result>
    <result property="approveUserName" column="approve_user_name"></result>
    <result property="startReagentCode" column="start_reagent_code"></result>
    <result property="endReagentCode" column="end_reagent_code"></result>
    <result property="arrivalNum" column="arrival_num"></result>
      <result property="articleNumber" column="article_number"></result>
      <result property="houseId" column="house_id"></result>
      <result property="containerId" column="container_id"></result>
      <result property="place" column="place"></result>
      <result property="applyGoal" column="apply_goal"></result>
      <result property="applyPrice" column="apply_price"></result>
      <result property="stockFlag" column="stock_flag"></result>
    <association property="reagent" javaType="com.nanometer.smartlab.entity.SysReagent">
      <id property="id" column="reagent_id"></id>
      <result property="name" column="reagent_name"></result>
      <result property="cas" column="reagent_cas"></result>
      <result property="reagentType" column="reagent_type"></result>
      <result property="reagentCharacter" column="reagent_character"></result>
      <result property="supplierId" column="reagent_supplier_id"></result>
      <result property="reagentFormat" column="reagent_format"></result>
      <result property="mainMetering" column="reagent_main_metering"></result>
      <result property="reagentUnit" column="reagent_unit"></result>
      <result property="price" column="reagent_price"></result>
      <result property="perBox" column="reagent_per_box"></result>
      <result property="memo" column="reagent_memo"></result>
      <result property="validFlag" column="reagent_valid_flag"></result>
      <result property="createTime" column="reagent_create_time"></result>
      <result property="updateTime" column="reagent_update_time"></result>
      <result property="supplierName" column="supplier_name"></result>
      <result property="productSn" column="reagent_product_sn"></result>
      <result property="controlProducts" column="control_products"></result>
      <result property="dangerousFlag" column="reagent_dangerous_flag" typeHandler="com.nanometer.smartlab.entity.handler.DangerousFlagHandler"></result>
      <result property="productHome" column="product_home"></result>
      <result property="type" column="type"></result>
      <result property="supplierFlag" column="supplier_flag"></result>
    </association>
      <association property="order" javaType="com.nanometer.smartlab.entity.OpeOrder">
          <id property="id" column="order_id"></id>
          <result property="orderName" column="order_name"></result>
          <result property="orderCode" column="order_code"></result>
      </association>
  </resultMap>
 
   <resultMap id="OpeApplyReserve" type="com.nanometer.smartlab.entity.OpeApplyReserve">
    <id property="id" column="id"/>
    <result property="applyCode" column="apply_code"></result>
    <result property="num" column="num"></result>
    <result property="used" column="used"></result>
    <result property="arrivalNum" column="arrival_num"></result>
    <result property="status" column="status" typeHandler="com.nanometer.smartlab.entity.handler.ApplyStatusHandler"></result>
    <result property="applyUserId" column="apply_user_id"></result>
    <result property="applyUser" column="apply_user"></result>
    <result property="arrivalTime" column="arrival_time"></result>
    <result property="articleNumber" column="article_number"></result>
    <result property="projectManage" column="project_manage"/>
    <result property="projectName" column="project_name"/>
   <result property="startReagentCode" column="start_reagent_code"></result>
   <result property="endReagentCode" column="end_reagent_code"></result>
    <association property="reagent" javaType="com.nanometer.smartlab.entity.SysReagent">
        <id property="id" column="reagent_id"></id>
        <result property="name" column="reagent_name"></result>
        <result property="cas" column="reagent_cas"></result>
        <result property="reagentType" column="reagent_type"></result>
        <result property="reagentCharacter" column="reagent_character"></result>
        <result property="supplierId" column="reagent_supplier_id"></result>
        <result property="reagentFormat" column="reagent_format"></result>
        <result property="mainMetering" column="reagent_main_metering"></result>
        <result property="reagentUnit" column="reagent_unit"></result>
        <result property="price" column="reagent_price"></result>
        <result property="perBox" column="reagent_per_box"></result>
        <result property="memo" column="reagent_memo"></result>
        <result property="validFlag" column="reagent_valid_flag"></result>
        <result property="createTime" column="reagent_create_time"></result>
        <result property="updateTime" column="reagent_update_time"></result>
        <result property="supplierName" column="supplier_name"></result>
        <result property="productSn" column="reagent_product_sn"></result>
        <result property="controlProducts" column="control_products"></result>
        <result property="dangerousFlag" column="reagent_dangerous_flag" typeHandler="com.nanometer.smartlab.entity.handler.DangerousFlagHandler"></result>
        <result property="productHome" column="product_home"></result>
    </association>
  </resultMap>
 
    <sql id="queryWhereSql">
        <if test="reagentName != null and reagentName != ''">
            and sr.name like #{reagentName}
        </if>
        <if test="startDeadline != null">
            and oa.deadline >= #{startDeadline}
        </if>
        <if test="endDeadline != null">
            and #{endDeadline} >= oa.deadline
        </if>
        <if test="status != null">
            and oa.status = #{status}
        </if>
        <if test="applyUserId != null and applyUserId != ''">
            and oa.apply_user_id = #{applyUserId}
        </if>
        <if test="approveUserId != null and approveUserId != ''">
            and (oa.approve_user_id = #{approveUserId} or oa.before_approve_user_id = #{approveUserId})
        </if>
        <if test="searchApproval != null and searchApproval != ''">
            and (oa.approve_user_id = #{searchApproval} or oa.before_approve_user_id = #{searchApproval})
        </if>
 
        <if test="approvaUserName != null and approvaUserName != ''">
            and (suApprove.name like concat('%',#{approvaUserName},'%')
            or sys.name like concat('%',#{approvaUserName},'%') )
        </if>
 
        <if test="editId != null and editId != ''">
            and oa.id != #{editId}
        </if>
        <if test="cas != null and cas != ''">
            and sr.cas like #{cas}
        </if>
        <if test="applyCode != null and applyCode != ''">
            and oa.apply_code like concat('%',#{applyCode},'%')
        </if>
        <if test="applyUserName != null and applyUserName != ''">
            and su.name like concat('%',#{applyUserName},'%')
        </if>
    </sql>
 
  <select id="getOpeApply"  resultMap="OpeApply" >
    select oa.*,sys.name as secondUserName,
    sr.name as reagent_name, sr.cas as reagent_cas ,sr.reagent_type as reagent_type, sr.reagent_character as reagent_character,
    sr.supplier_id as reagent_supplier_id, sr.dangerous_flag as reagent_dangerous_flag,
    sr.reagent_format as reagent_format, sr.main_metering as reagent_main_metering, sr.reagent_unit as reagent_unit,
    sr.price as reagent_price, sr.per_box as reagent_per_box,sr.memo as reagent_memo, sr.valid_flag as reagent_valid_flag,
    sr.create_time as reagent_create_time, sr.update_time as reagent_update_time,sr.control_products as control_products,
    sr.product_sn as reagent_product_sn,sr.product_home as product_home,
    ss.name as supplier_name,
    su.name as apply_user_name,
    sp.project_name as apply_user_project,
    bm2.meta_value as apply_user_department,
    fir.name as firName,
    suApprove.name as approve_user_name,
    ss.valid_flag  as supplier_flag,
    sr.type as type
    from ope_apply 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.apply_user_id = su.id
    left join sys_user as suApprove on oa.approve_user_id = suApprove.id
    left join sys_user as sys on sys.id=oa.before_approve_user_id
    left join sys_user as fir on fir.id=oa.first_user
     left join base_meta as bm2 on bm2.id = su.department
    left join sys_project sp on sp.id=su.project_id=sp.id
    where oa.id = #{id} and oa.valid_flag = 1
  </select>
 
  <select id="getOpeApplyList" parameterType="java.util.Map" resultMap="OpeApply">
    select oa.*,sys.name as second_user_name,
    sr.name as reagent_name,sr.price as reagent_price ,sr.cas as reagent_cas, sr.reagent_type as reagent_type,
    sr.reagent_character as reagent_character, sr.supplier_id as reagent_supplier_id,
    sr.reagent_format as reagent_format, sr.main_metering as reagent_main_metering, sr.reagent_unit as reagent_unit,
    sr.per_box as reagent_per_box,sr.memo as reagent_memo, sr.valid_flag as reagent_valid_flag, sr.create_time as reagent_create_time,
    sr.update_time as reagent_update_time, sr.product_sn as reagent_product_sn,
    sr.dangerous_flag as reagent_dangerous_flag,sr.control_products as control_products,sr.product_home as product_home,
    ss.name as supplier_name,
    su.name as apply_user_name,
    sp.project_name as apply_user_project,
    bm2.meta_value as apply_user_department,
    suApprove.name as approve_user_name,
    fir.name as fir_name,
    ss.valid_flag  as supplier_flag,
    sr.type as type
    from ope_apply 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.apply_user_id = su.id
    left join sys_user as suApprove on oa.approve_user_id = suApprove.id
    left join sys_user as sys on sys.id=oa.before_approve_user_id
    left join sys_user as fir on fir.id=oa.first_user
    left join base_meta as bm2 on bm2.id = su.department
    left join sys_project as sp on sp.id=su.project_id
    where oa.valid_flag = 1
    <if test="isShow != null and isShow ==0">
        and (ss.valid_flag = 1 or sr.type = 0)
    </if>
      <if test="controlProduct != null and controlProduct != ''">
          and sr.control_products like concat("%",#{controlProduct},"%")
      </if>
    <include refid="queryWhereSql"/>
    order by oa.create_time desc
    <if test="first != null and pageSize != null">
      limit #{first}, #{pageSize}
    </if>
  </select>
 
  <select id="getOpeApplyTotalCount" parameterType="java.util.Map" resultType="int">
    select count(1)
    from ope_apply 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.apply_user_id = su.id
      left join sys_user as suApprove on oa.approve_user_id = suApprove.id
      left join sys_user as sys on sys.id=oa.before_approve_user_id
      left join sys_user as fir on fir.id=oa.first_user
      where oa.valid_flag = 1
      <if test="isShow != null and isShow ==0">
          and (ss.valid_flag = 1 or sr.type = 0)
      </if>
      <if test="controlProduct != null and controlProduct != ''">
          and sr.control_products like concat("%",#{controlProduct},"%")
      </if>
    <include refid="queryWhereSql"/>
  </select>
 
  <insert id="insertOpeApply" parameterType="com.nanometer.smartlab.entity.OpeApply" useGeneratedKeys = "true" keyProperty = "id">
    insert into ope_apply( apply_code, reagent_id, num, deadline, apply_user_id, project_id, status, approve_user_id, memo, valid_flag, create_time, update_time)
    values ( #{applyCode}, #{reagent.id}, #{num}, #{deadline}, #{applyUserId}, #{projectId}, #{status}, #{approveUserId}, #{memo}, 1, now(), now())
  </insert>
 
  <insert id="insertOpeApplyList" parameterType="java.util.List" >
      insert into ope_apply
      (apply_code, reagent_id, num, deadline, apply_user_id, project_id, status, approve_user_id, memo, valid_flag, create_time, update_time,apply_goal,apply_price,first_user)
      values
      <foreach collection="opeApplyList" item="opeApply" separator=",">
          ( #{opeApply.applyCode}, #{opeApply.reagent.id}, #{opeApply.num}, #{opeApply.deadline},
          #{opeApply.applyUserId}, #{opeApply.projectId}, #{opeApply.status}, #{opeApply.approveUserId}, #{opeApply.memo}, 1, now(), now(),#{opeApply.applyGoal},#{opeApply.reagent.price},#{opeApply.approveUserId})
      </foreach>
  </insert>
    <insert id="insertList" parameterType="java.util.List" useGeneratedKeys = "true" keyProperty = "id">
        insert into ope_apply
        (apply_code, reagent_id, num, deadline, apply_user_id, project_id, status, approve_user_id, memo, valid_flag, create_time, update_time,apply_goal,apply_price,first_user)
        values
        <foreach collection="list" item="opeApply" separator=",">
            ( #{opeApply.applyCode}, #{opeApply.reagent.id}, #{opeApply.num}, #{opeApply.deadline},
            #{opeApply.applyUserId}, #{opeApply.projectId}, #{opeApply.status}, #{opeApply.approveUserId}, #{opeApply.memo}, 1, #{opeApply.createTime}, #{opeApply.updateTime},#{opeApply.applyGoal},#{opeApply.reagent.price},#{opeApply.approveUserId})
        </foreach>
    </insert>
 
    <update id="updateFirst" parameterType="java.util.Map">
        update ope_apply set first_user=approve_user_id where id=#{id}
    </update>
    <update id="updateFirst2" parameterType="java.util.Map">
        update ope_apply set first_user=before_approve_user_id where id=#{id}
    </update>
  <update id="updateOpeApply" parameterType="com.nanometer.smartlab.entity.OpeApply">
    update ope_apply
    <set>
    <if test="applyCode!=null and applyCode!=''">
        apply_code=#{applyCode},
    </if>
      <if test="reagent!=null and reagent.id!=null">
    reagent_id=#{reagent.id},
      </if>
      <if test="num!=null and num!=''">
    num=#{num},
      </if>
      <if test="deadline!=null">
    deadline=#{deadline},
      </if>
      <if test="applyUserId!=null and applyUserId!=''">
    apply_user_id=#{applyUserId},
      </if>
      <if test="projectId!=null and projectId!=''">
    project_id=#{projectId},
      </if>
      <if test="status!=null">
    status=#{status},
      </if>
      <if test="approveUserId!=null and approveUserId!=''">
    approve_user_id=#{approveUserId},
      </if>
      <if test="memo!=null and memo!=''">
    memo=#{memo},
      </if>
    update_time=now(),
      <if test="startReagentCode!=null and startReagentCode!=''">
    start_reagent_code=#{startReagentCode},
      </if>
      <if test="endReagentCode!=null and endReagentCode!=''">
    end_reagent_code=#{endReagentCode},
      </if>
      <if test="arrivalNum!=null and arrivalNum!=''">
    arrival_num=#{arrivalNum},
      </if>
      <if test="houseId!=null and houseId!=''">
    house_id=#{houseId},
      </if>
      <if test="place!=null and place!=''">
    place=#{place},
      </if>
      <if test="containerId!=null and containerId!=''">
    container_id=#{containerId},
      </if>
      <if test="articleNumber!=null and articleNumber!=''">
    article_number=#{articleNumber}
      </if>
    </set>
    where id=#{id}
 
  </update>
 
  <update id="updateOpeApplyStatus" parameterType="java.util.Map" >
    update ope_apply set status=#{status},
     <if test="memo !=null and memo != ''">
         memo=#{memo},
     </if>
      update_time=now()
    where id in
    <foreach collection="applyIds" item="item" index="index" open="(" separator="," close=")">
      #{item}
    </foreach>
  </update>
 
    <update id="updateOpeApplyStatusById" >
        update ope_apply set status=#{status},update_time=now()
        where id =#{id}
    </update>
 
    <update id="updateOpeApplyProject" parameterType="java.util.Map">
        update ope_apply set project_id =#{newObjective} where project_id=#{oldObjective}
    </update>
 
 
    <update id="cancelApply" parameterType="java.util.Map">
        update ope_apply set status=#{status} where id=#{id}
    </update>
 
    <update id="updateOpeApplyUsed" parameterType="com.nanometer.smartlab.entity.OpeApplyReserve">
        update ope_apply set used=#{used} where id=#{id}
    </update>
 
  <update id="updateOpeApplyAdmin" parameterType="java.util.Map" >
    update ope_apply set before_memo=#{memo}, before_approve_user_id=approve_user_id,
    approve_user_id=#{userId}, update_time=now()
    where id in
    <foreach collection="applyIds" item="item" index="index" open="(" separator="," close=")">
      #{item}
    </foreach>
  </update>
 
    <update id="updateOpeApplyAdmin2" parameterType="java.util.Map" >
        update ope_apply set before_memo=#{memo}, before_approve_user_id=#{beforeUserId},
        approve_user_id=#{userId}, update_time=now()
        where id =#{id}
    </update>
 
 
  <update id="deleteOpeApply" parameterType="java.util.List">
    update ope_apply set valid_flag=0, update_time=now()
    where id in
    <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
      #{item}
    </foreach>
  </update>
 
 
    <select id="selectOpeApplyByPrimaryKey" parameterType="java.util.Map" resultMap="OpeApply">
        select *
        from ope_apply as oa
        where id = #{id}
    </select>
 
    <sql id="getOpeApplyReserveList_queryColumns">
        select oa.id, oa.apply_code,
        sr.id reagent_id,
        oa.status,
        sr.product_sn reagent_product_sn,
        sr.`name` reagent_name,
        sr.control_products,
        sr.reagent_format,
        sr.main_metering reagent_main_metering,
        sr.price reagent_price,
        sr.cas reagent_cas,
        oa.article_number article_number,
        sr.reagentCharacter,
        sr.product_home,
        sr.dangerous_flag,
        oa.num,
        oa.used,
        su.`name` apply_user_id
    </sql>
 
    <sql id="getOpeApplyReserveList_queryJoins1">
        left JOIN sys_reagent sr on sr.id = oa.reagent_id
        left JOIN sys_user su on su.id = oa.apply_user_id
    </sql>
 
<!--    <sql id="getOpeApplyReserveList_queryJoins2">-->
<!--        left join base_meta as bm2 on sr.control_products = bm2.id-->
<!--        left join base_meta as bm3 on sr.reagent_format = bm3.id-->
<!--        left join base_meta as bm4 on sr.reagent_character = bm4.id-->
<!--        left join base_meta as bm1 on sr.product_home = bm1.id-->
<!--    </sql>-->
 
    <sql id="getOpeApplyReserveList_queryWhereSql">
        <if test="reagentName != null and reagentName != ''">
            and sr.name like concat('%',#{reagentName},'%')
        </if>
        <if test="personName != null and personName != ''">
            and su.name like concat('%',#{personName},'%')
        </if>
        <if test="userId != null and userId != ''">
            and oa.apply_user_id =#{userId}
        </if>
        <if test="status != null ">
            and oa.status =#{status}
        </if>
        <if test="productSn != null and productSn != ''">
            and sr.product_sn like concat('%',#{productSn},'%')
        </if>
        <if test="applyCode != null and applyCode != ''">
            and oa.apply_code = #{applyCode}
        </if>
    </sql>
 
    <select id="getOpeApplyReserveTotalCount" parameterType="java.util.Map"
        resultType="int">
        select count(1)
        from ope_apply as oa
        <include refid="getOpeApplyReserveList_queryJoins1" />
        where oa.valid_flag = 1
        <include refid="getOpeApplyReserveList_queryWhereSql" />
    </select>
 
    <select id="getOpeApplyReserveTotalCountFor" parameterType="java.util.Map"
            resultType="int">
        select count(1)
        from
        (select count(1)
        from ope_apply as oa
        LEFT JOIN sys_reagent sr ON sr.id = oa.reagent_id
        LEFT JOIN sys_user su ON su.id = oa.apply_user_id
        LEFT JOIN sys_project as project on project.id = su.project_id
        LEFT JOIN sys_user as su1 on su1.id = project.sys_user_id
        where oa.valid_flag = 1 and (
        <choose>
            <when test="status != null and status == 10">
                oa.status = 10
            </when>
            <otherwise>
                oa.status=4 or oa.status=6 or oa.status=9
            </otherwise>
        </choose>
        )
        <include refid="getOpeApplyReserveList_queryWhereSql" />
        <if test="isAllApply != null">
            <choose>
                <when test="isAllApply == 1">
                    and oa.used = oa.num
                </when>
                <otherwise>
                    and oa.used != oa.num
                </otherwise>
            </choose>
        </if>
        GROUP BY oa.id
        )as oaa
    </select>
 
    <select id="getOpeApplyReserveList" parameterType="java.util.Map"
        resultMap="OpeApplyReserve">
        <include refid="getOpeApplyReserveList_queryColumns" />
        from ope_apply as oa
        <include refid="getOpeApplyReserveList_queryJoins1" />
        where oa.valid_flag = 1
        <include refid="getOpeApplyReserveList_queryWhereSql" />
        GROUP BY oa.id
        order by oa.update_time desc
        <if test="first != null and pageSize != null">
            limit #{first}, #{pageSize}
        </if>
    </select>
 
    <select id="getOpeApplyReserveListFor" parameterType="java.util.Map"
            resultMap="OpeApplyReserve">
        SELECT
        oa.id,
        oa.apply_code,
        sr.id reagent_id,
        oa.status,
        sr.product_sn reagent_product_sn,
        sr.`name` reagent_name,
        sr.main_metering reagent_main_metering,
        sr.price reagent_price,
        sr.cas reagent_cas,
        sr.reagent_unit,
        oa.article_number article_number,
        sr.dangerous_flag,
        sr.control_products control_products,
        sr.reagent_character,
        sr.reagent_format,
        sr.product_home,
        oa.num,
        su.name apply_user,
        oa.apply_user_id,
        oa.used,
        su.`name` apply_user_name,
        project.project_name as project_name,
        su1.`name` as project_manage,
        oa.arrival_time
        FROM
        ope_apply AS oa
        LEFT JOIN sys_reagent sr ON sr.id = oa.reagent_id
        LEFT JOIN sys_user su ON su.id = oa.apply_user_id
        LEFT JOIN sys_project as project on project.id = su.project_id
        LEFT JOIN sys_user as su1 on su1.id = project.sys_user_id
        where oa.valid_flag = 1 and (
        <choose>
            <when test="status != null and status == 10">
                oa.status = 10
            </when>
            <otherwise>
                oa.status=4 or oa.status=6 or oa.status=9
            </otherwise>
        </choose>
        )
        <if test="reagentName != null and reagentName != ''">
            and sr.name like concat('%',#{reagentName},'%')
        </if>
        <if test="personName != null and personName != ''">
            and su.name like concat('%',#{personName},'%')
        </if>
        <if test="userId != null and userId != ''">
            and oa.apply_user_id =#{userId}
        </if>
        <if test="status != null ">
            and oa.status =#{status}
        </if>
        <if test="productSn != null and productSn != ''">
            and sr.product_sn like concat('%',#{productSn},'%')
        </if>
        <if test="applyCode != null and applyCode != ''">
            and oa.apply_code = #{applyCode}
        </if>
        <if test="isAllApply != null">
            <choose>
                <when test="isAllApply == 1">
                    and oa.used = oa.num
                </when>
                <otherwise>
                    and oa.used != oa.num
                </otherwise>
            </choose>
        </if>
        GROUP BY oa.id
        order by oa.update_time desc
        <if test="first != null and pageSize != null">
            limit #{first}, #{pageSize}
        </if>
    </select>
    <update id="updaetOpeApplyPrice" parameterType="java.util.Map" >
        update ope_apply set apply_price=#{applyPrice}
        where id=#{id}
    </update>
 
    <update id="updaetOpeApplyStockFlag" parameterType="java.util.Map">
        update ope_apply set stock_flag=#{stockFlag} where id=#{id}
    </update>
 
    <select id="selectByReId" resultMap="OpeApply">
        select * from ope_apply where reagent_id=#{id}
    </select>
    <select id="getOpeApplyDetail" resultMap="OpeApplyReserve">
        select oa.id, oa.apply_code,
        sr.id reagent_id,
        oa.status,
        sr.product_sn reagent_product_sn,
        sr.`name` reagent_name,
        sr.control_products,
        sr.reagent_format,
        sr.main_metering reagent_main_metering,
        sr.price reagent_price,
        sr.cas reagent_cas,
        oa.article_number article_number,
        sr.reagent_character,
        sr.product_home,
        sr.dangerous_flag,
        oa.num,
        oa.used,
        oa.arrival_num,
        su.id apply_user_id,
        CONCAT(rc.code_prex,LPAD(rc.start_code,4,'0')) as start_reagent_code,
        CONCAT(rc.code_prex,LPAD(rc.end_code,4,'0')) as end_reagent_code
        from ope_apply as oa
        left JOIN sys_reagent sr on sr.id = oa.reagent_id
        left JOIN sys_user su on su.id = oa.apply_user_id
        left join ope_reagent_code  rc on rc.apply_id=oa.id
        where oa.valid_flag = 1
        and oa.id = #{0}
    </select>
    <select id="getOpeApplyReserveListByNameForRowData"
            resultMap="OpeApplyReserve">
         SELECT
        oa.id,
        oa.apply_code,
        sr.id reagent_id,
        oa. STATUS,
        sr.product_sn reagent_product_sn,
        sr.`name` reagent_name,
        sr.control_products,
        sr.reagent_format,
        sr.reagent_unit,
        sr.main_metering reagent_main_metering,
        sr.price reagent_price,
        sr.cas reagent_cas,
        oa.article_number article_number,
        sr.reagent_character,
        sr.product_home,
        sr.dangerous_flag,
        oa.num,
        oa.apply_user_id apply_user_id,
        oa.used,
        su.`name` apply_user,
        project.project_name apply_user_project,
        su1.`name` as project_manage,
        oa.arrival_time
        FROM
        ope_apply AS oa
        LEFT JOIN sys_reagent sr ON sr.id = oa.reagent_id
        LEFT JOIN sys_user su ON su.id = oa.apply_user_id
        LEFT JOIN sys_project as project on project.id = su.project_id
        LEFT JOIN sys_user as su1 on su1.id = project.sys_user_id
        where oa.id = #{id}
 
 
    </select>
    <select id="getApplyControlInfo" resultType="java.util.Map">
               (SELECT sum(oa.num) sum,"易制毒" name from ope_apply oa
        LEFT JOIN sys_reagent sr on oa.reagent_id = sr.id
        where
        oa.valid_flag = 1
        and sr.valid_flag = 1
        and YEAR(oa.create_time)=YEAR(NOW())
        and oa.status in(2,3,4,6)
        and
        sr.control_products like "%易制毒%") UNION ALL(
 
            SELECT sum(oa.num) sum,"易制爆"  name from ope_apply oa
        LEFT JOIN sys_reagent sr on oa.reagent_id = sr.id
        where
        oa.valid_flag = 1
        and sr.valid_flag = 1
        and YEAR(oa.create_time)=YEAR(NOW())
        and oa.status in(2,3,4,6)
        and sr.control_products like "%易制爆%")UNION ALL(
 
        SELECT sum(oa.num) sum,"总数"  name from ope_apply oa
        LEFT JOIN sys_reagent sr on oa.reagent_id = sr.id
        where
        oa.valid_flag = 1
        and sr.valid_flag = 1
        and YEAR(oa.create_time)=YEAR(NOW())
        and oa.status in(2,3,4,6)
        )
 
    </select>
    <select id="getOpeApplySupplerRequireMngTotalCount" resultType="java.lang.Integer">
        select count(1)
        from ope_apply 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.apply_user_id = su.id
        left join sys_user as suApprove on oa.approve_user_id = suApprove.id
        left join sys_user as sys on sys.id=oa.before_approve_user_id
        left join sys_user as fir on fir.id=oa.first_user
        where oa.valid_flag = 1
        <if test="isShow != null and isShow ==0">
            and (ss.valid_flag = 1 or sr.type = 0)
        </if>
        <if test="reagentName != null and reagentName != ''">
            and sr.name like concat("%",#{reagentName},"%")
        </if>
        <if test="startDeadline != null">
            and oa.deadline >= #{startDeadline}
        </if>
        <if test="endDeadline != null">
            and #{endDeadline} >= oa.deadline
        </if>
        <if test="status != null">
            and oa.status = #{status}
        </if>
        <if test="company != null and company != ''">
            and ss.name = #{company}
        </if>
 
    </select>
    <select id="getOpeApplySupplerRequireMngList" parameterType="java.util.Map" resultMap="OpeApply">
 
        select oa.*,sys.name as secondUserName,
        sr.name as reagent_name,sr.price as reagent_price ,sr.cas as reagent_cas, sr.reagent_type as reagent_type, sr.reagent_character as reagent_character,
        sr.supplier_id as reagentSupplierId,sr.reagent_format as reagent_format, sr.main_metering as reagent_main_metering,
        sr.reagent_unit as reagent_unit, sr.per_box as reagent_per_box,sr.memo as reagent_memo, sr.valid_flag as reagent_valid_flag,
        sr.create_time as reagent_create_time, sr.update_time as reagent_update_time, sr.product_sn as reagent_product_sn,
        sr.dangerous_flag as reagent_dangerous_flag,sr.control_products as control_products,sr.product_home as product_home,
        ss.name as supplier_name,
        su.name as applyUser_name,
        suApprove.name as approve_user_name,
        sr.product_home as apply_user_project,
        fir.name as fir_name,
        ss.valid_flag  as supplier_flag,
        sr.type as type
        from ope_apply 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.apply_user_id = su.id
        left join sys_user as suApprove on oa.approve_user_id = suApprove.id
        left join sys_user as sys on sys.id=oa.before_approve_user_id
        left join sys_user as fir on fir.id=oa.first_user
        where oa.valid_flag = 1
        <if test="isShow != null and isShow ==0">
            and (ss.valid_flag = 1 or sr.type = 0)
        </if>
        <if test="company != null and company != ''">
            and ss.name = #{company}
        </if>
        <if test="reagentName != null and reagentName != ''">
            and sr.name like concat("%",#{reagentName},"%")
        </if>
        <if test="startDeadline != null">
            and oa.deadline >= #{startDeadline}
        </if>
        <if test="endDeadline != null">
            and #{endDeadline} >= oa.deadline
        </if>
        <if test="status != null">
            and oa.status = #{status}
        </if>
        order by oa.create_time desc
        <if test="first != null and pageSize != null">
            limit #{first}, #{pageSize}
        </if>
    </select>
 
 
    <update id="updateByReId" parameterType="java.util.Map">
        update ope_apply set reagent_id=#{newReId} where reagent_id=#{oldReId}
    </update>
 
    <update id="updateOpeApplyInfo" parameterType="java.util.Map">
        update
        ope_apply
        set status = #{status}
        <if test="arrivalTime!=null" >
            ,arrival_time = #{arrivalTime}
        </if>
        <if test="consigneeId!=null" >
            ,consignee_id = #{consigneeId}
        </if>
        <if test="arrivalNum!=null" >
            ,arrival_num = #{arrivalNum}
        </if>
        where valid_flag = 1
        and id = #{applyId}
    </update>
 
    <select id="getOpeApplyByOrderId" resultMap="OpeApply">
        select distinct a.id,a.apply_code,a.reagent_id,a.used,a.num,a.arrival_num,a.apply_user_id,a.status,a.project_id,a.deadline,a.approve_user_id,a.apply_price,a.create_time,a.memo,a.article_number,a.place,
                        CONCAT(c.code_prex,LPAD(c.start_code,4,'0')) as start_reagent_code,CONCAT(c.code_prex,LPAD(c.end_code,4,'0')) as end_reagent_code,
                        d.name as reagent_name, d.cas as reagent_cas, d.reagent_type as reagent_type, d.reagent_character as reagent_character,
                        d.supplier_id as reagent_supplier_id,d.product_home as product_home,d.product_sn as reagent_product_sn,
                        d.reagent_format as reagent_format, d.main_metering as reagent_main_metering, d.reagent_unit as reagent_unit,
                        d.price as reagent_price, d.per_box as reagent_per_box,d.control_products,
                        e.name as apply_user_name
        from ope_apply a
        left join ope_apply_order b on b.ope_apply_id=a.id
        left join ope_reagent_code  c on c.apply_id=a.id
        left join sys_reagent d on a.reagent_id = d.id
        left join sys_user e on a.apply_user_id = e.id
        where b.ope_order_id=#{orderId}
    </select>
 
 
    <select id="getReagentByApplyId" resultType="com.nanometer.smartlab.entity.SysReagent">
        select sa.* from sys_reagent sa
        left join ope_apply oa on oa.reagent_id=sa.id
        where oa.id=#{applyId}
    </select>
 
 
    <select id="getOpeApplyCountWithOrder" resultType="int">
        select count(1)
        from ope_apply as oa
        inner join ope_apply_order ao on ao.ope_apply_id=oa.id
        inner join ope_order oo on oo.id=ao.ope_order_id
        <where>
            oa.valid_flag = 1 and oo.valid_flag=1
            <if test="applyCode!=null and applyCode!=''">
                and oa.apply_code=#{applyCode}
            </if>
        </where>
    </select>
 
    <select id="getOpeApplyListWithOrder" resultMap="OpeApply">
        select oa.*,
        sr.name as reagent_name,sr.cas as reagent_cas, sr.reagent_type as reagent_type,
        sr.reagent_character as reagent_character,sr.product_sn as reagent_product_sn,sr.product_home as product_home,
        ss.name as supplier_name,
        su.name as apply_user_name,
        oo.id as order_id,oo.order_name,oo.order_code
        from ope_apply as oa
        inner join ope_apply_order ao on ao.ope_apply_id=oa.id
        inner join ope_order oo on oo.id=ao.ope_order_id
        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.apply_user_id = su.id
        <where>
            oa.valid_flag = 1 and oo.valid_flag=1
            <if test="applyCode!=null and applyCode!=''">
                and oa.apply_code=#{applyCode}
            </if>
            <if test="orderCode!=null and orderCode!=''">
                and oo.order_code=#{orderCode}
            </if>
            <if test="orderName!=null and orderName!=''">
                and oo.order_name like concat('%',#{orderName},'%')
            </if>
        </where>
        order by oo.create_time desc
        <if test="first != null and pageSize != null">
            limit #{first}, #{pageSize}
        </if>
    </select>
 
 
    <select id="getArrivalNumById" resultType="int">
        select ifnull(arrival_num ,0)from ope_apply where id=#{applyId}
    </select>
 
</mapper>