111
k94314517
2023-10-16 ca73a173f008c8d7a9d700bad897ca24fe2d2203
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
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
<?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="doumeemes.dao.ext.WStockExtMapper">
 
  <!-- 管理页面查询 -->
  <resultMap id="WStockExtListVO" type="doumeemes.dao.ext.vo.WStockExtListVO" autoMapping="true">
    <id column="ID" jdbcType="INTEGER" property="id"/>
    <association property="mmodel" javaType="doumeemes.dao.business.model.Material">
      <id column="MMODEL_ID" jdbcType="INTEGER" property="id"/>
      <result column="MMODEL_DELETED" jdbcType="TINYINT" property="deleted"/>
      <result column="MMODEL_CREATE_USER" jdbcType="INTEGER" property="createUser"/>
      <result column="MMODEL_CREATE_TIME" jdbcType="TIMESTAMP" property="createTime"/>
      <result column="MMODEL_UPDATE_USER" jdbcType="INTEGER" property="updateUser"/>
      <result column="MMODEL_UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime"/>
      <result column="MMODEL_REMARK" jdbcType="VARCHAR" property="remark"/>
      <result column="MMODEL_ROOT_DEPART_ID" jdbcType="INTEGER" property="rootDepartId"/>
      <result column="MMODEL_NAME" jdbcType="VARCHAR" property="name"/>
      <result column="MMODEL_CODE" jdbcType="VARCHAR" property="code"/>
      <result column="MMODEL_ATTR" jdbcType="VARCHAR" property="attr"/>
      <result column="MMODEL_UNION_NAME" jdbcType="VARCHAR" property="unionName"/>
      <result column="MMODEL_UNIT_ID" jdbcType="INTEGER" property="unitId"/>
      <result column="MMODEL_CATE_UNION_ID" jdbcType="INTEGER" property="cateUnionId"/>
      <result column="MMODEL_FORMATION" jdbcType="TINYINT" property="formation"/>
      <result column="MMODEL_QRCODE_ID" jdbcType="VARCHAR" property="qrcodeId"/>
      <result column="MMODEL_STATUS" jdbcType="TINYINT" property="status"/>
      <result column="MMODEL_VALID_TIME" jdbcType="TIMESTAMP" property="validTime"/>
      <result column="MMODEL_INVALID_TIME" jdbcType="TIMESTAMP" property="invalidTime"/>
      <result column="MMODEL_CHECK_WAY" jdbcType="TINYINT" property="checkWay"/>
      <result column="MMODEL_QUALITY_REQUIRE" jdbcType="VARCHAR" property="qualityRequire"/>
      <result column="MMODEL_CHECK_NOTE" jdbcType="VARCHAR" property="checkNote"/>
    </association>
    <association property="umodel" javaType="doumeemes.dao.business.model.Unit">
      <id column="UMODEL_ID" jdbcType="INTEGER" property="id"/>
      <result column="UMODEL_DELETED" jdbcType="TINYINT" property="deleted"/>
      <result column="UMODEL_CREATE_USER" jdbcType="INTEGER" property="createUser"/>
      <result column="UMODEL_CREATE_TIME" jdbcType="TIMESTAMP" property="createTime"/>
      <result column="UMODEL_UPDATE_USER" jdbcType="INTEGER" property="updateUser"/>
      <result column="UMODEL_UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime"/>
      <result column="UMODEL_REMARK" jdbcType="VARCHAR" property="remark"/>
      <result column="UMODEL_ROOT_DEPART_ID" jdbcType="INTEGER" property="rootDepartId"/>
      <result column="UMODEL_NAME" jdbcType="VARCHAR" property="name"/>
      <result column="UMODEL_TYPE" jdbcType="TINYINT" property="type"/>
      <result column="UMODEL_STATUS" jdbcType="TINYINT" property="status"/>
    </association>
    <association property="lmodel" javaType="doumeemes.dao.business.model.WarehouseLocation">
      <id column="LMODEL_ID" jdbcType="INTEGER" property="id"/>
      <result column="LMODEL_DELETED" jdbcType="TINYINT" property="deleted"/>
      <result column="LMODEL_CREATE_USER" jdbcType="INTEGER" property="createUser"/>
      <result column="LMODEL_CREATE_TIME" jdbcType="TIMESTAMP" property="createTime"/>
      <result column="LMODEL_UPDATE_USER" jdbcType="INTEGER" property="updateUser"/>
      <result column="LMODEL_UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime"/>
      <result column="LMODEL_REMARK" jdbcType="VARCHAR" property="remark"/>
      <result column="LMODEL_ROOT_DEPART_ID" jdbcType="INTEGER" property="rootDepartId"/>
      <result column="LMODEL_WAREHOUSE_ID" jdbcType="INTEGER" property="warehouseId"/>
      <result column="LMODEL_UNION_NAME" jdbcType="VARCHAR" property="unionName"/>
      <result column="LMODEL_AREA" jdbcType="VARCHAR" property="area"/>
      <result column="LMODEL_SHELF" jdbcType="VARCHAR" property="shelf"/>
      <result column="LMODEL_CELL" jdbcType="VARCHAR" property="cell"/>
      <result column="LMODEL_QRCODE" jdbcType="INTEGER" property="qrcode"/>
      <result column="LMODEL_STATUS" jdbcType="TINYINT" property="status"/>
    </association>
    <association property="wmodel" javaType="doumeemes.dao.business.model.Warehouse">
      <id column="WMODEL_ID" jdbcType="INTEGER" property="id"/>
      <result column="WMODEL_DELETED" jdbcType="TINYINT" property="deleted"/>
      <result column="WMODEL_CREATE_USER" jdbcType="INTEGER" property="createUser"/>
      <result column="WMODEL_CREATE_TIME" jdbcType="TIMESTAMP" property="createTime"/>
      <result column="WMODEL_UPDATE_USER" jdbcType="INTEGER" property="updateUser"/>
      <result column="WMODEL_UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime"/>
      <result column="WMODEL_REMARK" jdbcType="VARCHAR" property="remark"/>
      <result column="WMODEL_ROOT_DEPART_ID" jdbcType="INTEGER" property="rootDepartId"/>
      <result column="WMODEL_DEPART_ID" jdbcType="INTEGER" property="departId"/>
      <result column="WMODEL_PROCEDURE_ID" jdbcType="INTEGER" property="procedureId"/>
      <result column="WMODEL_QRCODE" jdbcType="INTEGER" property="qrcode"/>
      <result column="WMODEL_NAME" jdbcType="VARCHAR" property="name"/>
      <result column="WMODEL_USE_LOCATION" jdbcType="TINYINT" property="useLocation"/>
      <result column="WMODEL_STATUS" jdbcType="TINYINT" property="status"/>
      <result column="WMODEL_ADDR" jdbcType="VARCHAR" property="addr"/>
    </association>
  </resultMap>
  <select id="getStatisticsStockList" parameterType="doumeemes.dao.ext.dto.QueryWStockExtDTO" resultType="doumeemes.dao.business.dto.statistics.StockDataModel">
    select sum(a.NUM) as num,c.`NAME` as materialName,d.name as warehouseName,f.UNION_NAME as location,u.name as unitName,p.`NAME` as procedureName
    from w_stock a
    left join material_distribute b on a.MATERIAL_ID=b.ID
    left join material c on b.MATERIAL_ID=c.ID
    left join warehouse d on a.WAREHOUSE_ID=d.ID
    left join warehouse_location f on a.LOCATION_ID=f.ID
    left join procedures p on p.ID=a.PROCEDURE_ID
    left join unit u on a.UNIT_ID=u.id
    where a.DELETED = 0 AND a.ROOT_DEPART_ID = #{rootDepartId} AND d.DEPART_ID=#{wmodelDepartId}
    GROUP BY a.MATERIAL_ID,a.WAREHOUSE_ID,a.BATCH
    ORDER BY c.code , p.SORTNUM
  </select>
  <select id="selectAllList" parameterType="doumeemes.dao.ext.dto.QueryWStockExtDTO" resultMap="WStockExtListVO">
    SELECT a.*
    FROM w_stock a
    <where>
      <if test="id != null">
        AND a.ID = #{id}
      </if>
      <if test="deleted != null">
        AND a.DELETED = #{deleted}
      </if>
      <if test="createUser != null">
        AND a.CREATE_USER = #{createUser}
      </if>
      <if test="createTime != null">
        AND a.CREATE_TIME = #{createTime}
      </if>
      <if test="updateUser != null">
        AND a.UPDATE_USER = #{updateUser}
      </if>
      <if test="updateTime != null">
        AND a.UPDATE_TIME = #{updateTime}
      </if>
      <if test="remark != null and remark != ''">
        AND a.REMARK = #{remark}
      </if>
      <if test="rootDepartId != null">
        AND a.ROOT_DEPART_ID = #{rootDepartId}
      </if>
      <if test="materialId != null">
        AND a.MATERIAL_ID = #{materialId}
      </if>
      <if test="materialIds != null and materialIds.size()>0">
        AND a.MATERIAL_ID in <foreach collection="materialIds" separator="," open="(" close=")" item="item">#{item}</foreach>
      </if>
      <if test="unitId != null">
        AND a.UNIT_ID = #{unitId}
      </if>
      <if test="locationId != null">
        AND a.LOCATION_ID = #{locationId}
      </if>
      <if test="warehouseId != null">
        AND a.WAREHOUSE_ID = #{warehouseId}
      </if>
      <if test="batch != null and batch != ''">
        AND a.BATCH = #{batch}
      </if>
      <if test="num != null">
        AND a.NUM = #{num}
      </if>
    </where>
 
  </select>
  <select id="selectListAll" parameterType="doumeemes.dao.ext.dto.QueryWStockExtDTO" resultMap="WStockExtListVO">
    SELECT
    a.ID,
    a.DELETED,
    a.CREATE_USER,
    a.CREATE_TIME,
    a.UPDATE_USER,
    a.UPDATE_TIME,
    a.REMARK,
    a.ROOT_DEPART_ID,
    a.MATERIAL_ID,
    a.UNIT_ID,
    a.LOCATION_ID,
    a.WAREHOUSE_ID,
    a.BATCH,
    a.NUM,
    mmodel.ID AS MMODEL_ID,
    mmodel.DELETED AS MMODEL_DELETED,
    mmodel.CREATE_USER AS MMODEL_CREATE_USER,
    mmodel.CREATE_TIME AS MMODEL_CREATE_TIME,
    mmodel.UPDATE_USER AS MMODEL_UPDATE_USER,
    mmodel.UPDATE_TIME AS MMODEL_UPDATE_TIME,
    mmodel.REMARK AS MMODEL_REMARK,
    mmodel.ROOT_DEPART_ID AS MMODEL_ROOT_DEPART_ID,
    mmodel.NAME AS MMODEL_NAME,
    mmodel.CODE AS MMODEL_CODE,
    mmodel.ATTR AS MMODEL_ATTR,
    mmodel.UNION_NAME AS MMODEL_UNION_NAME,
    mmodel.UNIT_ID AS MMODEL_UNIT_ID,
    mmodel.CATE_UNION_ID AS MMODEL_CATE_UNION_ID,
    mmodel.FORMATION AS MMODEL_FORMATION,
    mmodel.QRCODE_ID AS MMODEL_QRCODE_ID,
    mmodel.STATUS AS MMODEL_STATUS,
    mmodel.VALID_TIME AS MMODEL_VALID_TIME,
    mmodel.INVALID_TIME AS MMODEL_INVALID_TIME,
    mmodel.CHECK_WAY AS MMODEL_CHECK_WAY,
    mmodel.QUALITY_REQUIRE AS MMODEL_QUALITY_REQUIRE,
    mmodel.CHECK_NOTE AS MMODEL_CHECK_NOTE,
    umodel.ID AS UMODEL_ID,
    umodel.DELETED AS UMODEL_DELETED,
    umodel.CREATE_USER AS UMODEL_CREATE_USER,
    umodel.CREATE_TIME AS UMODEL_CREATE_TIME,
    umodel.UPDATE_USER AS UMODEL_UPDATE_USER,
    umodel.UPDATE_TIME AS UMODEL_UPDATE_TIME,
    umodel.REMARK AS UMODEL_REMARK,
    umodel.ROOT_DEPART_ID AS UMODEL_ROOT_DEPART_ID,
    umodel.NAME AS UMODEL_NAME,
    umodel.TYPE AS UMODEL_TYPE,
    umodel.STATUS AS UMODEL_STATUS,
    lmodel.ID AS LMODEL_ID,
    lmodel.DELETED AS LMODEL_DELETED,
    lmodel.CREATE_USER AS LMODEL_CREATE_USER,
    lmodel.CREATE_TIME AS LMODEL_CREATE_TIME,
    lmodel.UPDATE_USER AS LMODEL_UPDATE_USER,
    lmodel.UPDATE_TIME AS LMODEL_UPDATE_TIME,
    lmodel.REMARK AS LMODEL_REMARK,
    lmodel.ROOT_DEPART_ID AS LMODEL_ROOT_DEPART_ID,
    lmodel.WAREHOUSE_ID AS LMODEL_WAREHOUSE_ID,
    lmodel.UNION_NAME AS LMODEL_UNION_NAME,
    lmodel.AREA AS LMODEL_AREA,
    lmodel.SHELF AS LMODEL_SHELF,
    lmodel.CELL AS LMODEL_CELL,
    lmodel.QRCODE AS LMODEL_QRCODE,
    lmodel.STATUS AS LMODEL_STATUS,
    wmodel.ID AS WMODEL_ID,
    wmodel.DELETED AS WMODEL_DELETED,
    wmodel.CREATE_USER AS WMODEL_CREATE_USER,
    wmodel.CREATE_TIME AS WMODEL_CREATE_TIME,
    wmodel.UPDATE_USER AS WMODEL_UPDATE_USER,
    wmodel.UPDATE_TIME AS WMODEL_UPDATE_TIME,
    wmodel.REMARK AS WMODEL_REMARK,
    wmodel.ROOT_DEPART_ID AS WMODEL_ROOT_DEPART_ID,
    wmodel.DEPART_ID AS WMODEL_DEPART_ID,
    wmodel.PROCEDURE_ID AS WMODEL_PROCEDURE_ID,
    wmodel.QRCODE AS WMODEL_QRCODE,
    wmodel.NAME AS WMODEL_NAME,
    wmodel.USE_LOCATION AS WMODEL_USE_LOCATION,
    wmodel.STATUS AS WMODEL_STATUS,
    wmodel.ADDR AS WMODEL_ADDR
    FROM w_stock a
    LEFT JOIN material mmodel ON mmodel.ID=a.MATERIAL_ID
    LEFT JOIN unit umodel ON a.UNIT_ID=umodel.ID
    LEFT JOIN warehouse_location lmodel ON a.LOCATION_ID=lmodel.ID
    LEFT JOIN warehouse wmodel ON a.WAREHOUSE_ID=wmodel.ID
    <where>
      <if test="id != null">
        AND a.ID = #{id}
      </if>
      <if test="deleted != null">
        AND a.DELETED = #{deleted}
      </if>
      <if test="createUser != null">
        AND a.CREATE_USER = #{createUser}
      </if>
      <if test="createTime != null">
        AND a.CREATE_TIME = #{createTime}
      </if>
      <if test="updateUser != null">
        AND a.UPDATE_USER = #{updateUser}
      </if>
      <if test="updateTime != null">
        AND a.UPDATE_TIME = #{updateTime}
      </if>
      <if test="remark != null and remark != ''">
        AND a.REMARK = #{remark}
      </if>
      <if test="rootDepartId != null">
        AND a.ROOT_DEPART_ID = #{rootDepartId}
      </if>
      <if test="materialId != null">
        AND a.MATERIAL_ID = #{materialId}
      </if>
      <if test="unitId != null">
        AND a.UNIT_ID = #{unitId}
      </if>
      <if test="locationId != null">
        AND a.LOCATION_ID = #{locationId}
      </if>
      <if test="warehouseId != null">
        AND a.WAREHOUSE_ID = #{warehouseId}
      </if>
      <if test="batch != null and batch != ''">
        AND a.BATCH = #{batch}
      </if>
      <if test="num != null">
        AND a.NUM = #{num}
      </if>
      <if test="greaterZero != null and greaterZero = 1 ">
        AND a.NUM > 0
      </if>
 
      <if test="mmodelId != null">
        AND mmodel.ID = #{mmodelId}
      </if>
      <if test="mmodelDeleted != null">
        AND mmodel.DELETED = #{mmodelDeleted}
      </if>
      <if test="mmodelCreateUser != null">
        AND mmodel.CREATE_USER = #{mmodelCreateUser}
      </if>
      <if test="mmodelCreateTime != null">
        AND mmodel.CREATE_TIME = #{mmodelCreateTime}
      </if>
      <if test="mmodelUpdateUser != null">
        AND mmodel.UPDATE_USER = #{mmodelUpdateUser}
      </if>
      <if test="mmodelUpdateTime != null">
        AND mmodel.UPDATE_TIME = #{mmodelUpdateTime}
      </if>
      <if test="mmodelRemark != null and mmodelRemark != ''">
        AND mmodel.REMARK = #{mmodelRemark}
      </if>
      <if test="mmodelRootDepartId != null">
        AND mmodel.ROOT_DEPART_ID = #{mmodelRootDepartId}
      </if>
      <if test="mmodelName != null and mmodelName != ''">
        AND mmodel.NAME = #{mmodelName}
      </if>
      <if test="mmodelCode != null and mmodelCode != ''">
        AND mmodel.CODE = #{mmodelCode}
      </if>
      <if test="mmodelAttr != null and mmodelAttr != ''">
        AND mmodel.ATTR = #{mmodelAttr}
      </if>
      <if test="mmodelUnionName != null and mmodelUnionName != ''">
        AND mmodel.UNION_NAME = #{mmodelUnionName}
      </if>
      <if test="mmodelUnitId != null">
        AND mmodel.UNIT_ID = #{mmodelUnitId}
      </if>
      <if test="mmodelCateUnionId != null">
        AND mmodel.CATE_UNION_ID = #{mmodelCateUnionId}
      </if>
      <if test="mmodelFormation != null">
        AND mmodel.FORMATION = #{mmodelFormation}
      </if>
      <if test="mmodelQrcodeId != null and mmodelQrcodeId != ''">
        AND mmodel.QRCODE_ID = #{mmodelQrcodeId}
      </if>
      <if test="mmodelStatus != null">
        AND mmodel.STATUS = #{mmodelStatus}
      </if>
      <if test="mmodelValidTime != null">
        AND mmodel.VALID_TIME = #{mmodelValidTime}
      </if>
      <if test="mmodelInvalidTime != null">
        AND mmodel.INVALID_TIME = #{mmodelInvalidTime}
      </if>
      <if test="mmodelCheckWay != null">
        AND mmodel.CHECK_WAY = #{mmodelCheckWay}
      </if>
      <if test="mmodelQualityRequire != null and mmodelQualityRequire != ''">
        AND mmodel.QUALITY_REQUIRE = #{mmodelQualityRequire}
      </if>
      <if test="mmodelCheckNote != null and mmodelCheckNote != ''">
        AND mmodel.CHECK_NOTE = #{mmodelCheckNote}
      </if>
      <if test="umodelId != null">
        AND umodel.ID = #{umodelId}
      </if>
      <if test="umodelDeleted != null">
        AND umodel.DELETED = #{umodelDeleted}
      </if>
      <if test="umodelCreateUser != null">
        AND umodel.CREATE_USER = #{umodelCreateUser}
      </if>
      <if test="umodelCreateTime != null">
        AND umodel.CREATE_TIME = #{umodelCreateTime}
      </if>
      <if test="umodelUpdateUser != null">
        AND umodel.UPDATE_USER = #{umodelUpdateUser}
      </if>
      <if test="umodelUpdateTime != null">
        AND umodel.UPDATE_TIME = #{umodelUpdateTime}
      </if>
      <if test="umodelRemark != null and umodelRemark != ''">
        AND umodel.REMARK = #{umodelRemark}
      </if>
      <if test="umodelRootDepartId != null">
        AND umodel.ROOT_DEPART_ID = #{umodelRootDepartId}
      </if>
      <if test="umodelName != null and umodelName != ''">
        AND umodel.NAME = #{umodelName}
      </if>
      <if test="umodelType != null">
        AND umodel.TYPE = #{umodelType}
      </if>
      <if test="umodelStatus != null">
        AND umodel.STATUS = #{umodelStatus}
      </if>
      <if test="lmodelId != null">
        AND lmodel.ID = #{lmodelId}
      </if>
      <if test="lmodelDeleted != null">
        AND lmodel.DELETED = #{lmodelDeleted}
      </if>
      <if test="lmodelCreateUser != null">
        AND lmodel.CREATE_USER = #{lmodelCreateUser}
      </if>
      <if test="lmodelCreateTime != null">
        AND lmodel.CREATE_TIME = #{lmodelCreateTime}
      </if>
      <if test="lmodelUpdateUser != null">
        AND lmodel.UPDATE_USER = #{lmodelUpdateUser}
      </if>
      <if test="lmodelUpdateTime != null">
        AND lmodel.UPDATE_TIME = #{lmodelUpdateTime}
      </if>
      <if test="lmodelRemark != null and lmodelRemark != ''">
        AND lmodel.REMARK = #{lmodelRemark}
      </if>
      <if test="lmodelRootDepartId != null">
        AND lmodel.ROOT_DEPART_ID = #{lmodelRootDepartId}
      </if>
      <if test="lmodelWarehouseId != null">
        AND lmodel.WAREHOUSE_ID = #{lmodelWarehouseId}
      </if>
      <if test="lmodelUnionName != null and lmodelUnionName != ''">
        AND lmodel.UNION_NAME = #{lmodelUnionName}
      </if>
      <if test="lmodelArea != null and lmodelArea != ''">
        AND lmodel.AREA = #{lmodelArea}
      </if>
      <if test="lmodelShelf != null and lmodelShelf != ''">
        AND lmodel.SHELF = #{lmodelShelf}
      </if>
      <if test="lmodelCell != null and lmodelCell != ''">
        AND lmodel.CELL = #{lmodelCell}
      </if>
      <if test="lmodelQrcode != null">
        AND lmodel.QRCODE = #{lmodelQrcode}
      </if>
      <if test="lmodelStatus != null">
        AND lmodel.STATUS = #{lmodelStatus}
      </if>
      <if test="wmodelId != null">
        AND wmodel.ID = #{wmodelId}
      </if>
      <if test="wmodelDeleted != null">
        AND wmodel.DELETED = #{wmodelDeleted}
      </if>
      <if test="wmodelCreateUser != null">
        AND wmodel.CREATE_USER = #{wmodelCreateUser}
      </if>
      <if test="wmodelCreateTime != null">
        AND wmodel.CREATE_TIME = #{wmodelCreateTime}
      </if>
      <if test="wmodelUpdateUser != null">
        AND wmodel.UPDATE_USER = #{wmodelUpdateUser}
      </if>
      <if test="wmodelUpdateTime != null">
        AND wmodel.UPDATE_TIME = #{wmodelUpdateTime}
      </if>
      <if test="wmodelRemark != null and wmodelRemark != ''">
        AND wmodel.REMARK = #{wmodelRemark}
      </if>
      <if test="wmodelRootDepartId != null">
        AND wmodel.ROOT_DEPART_ID = #{wmodelRootDepartId}
      </if>
      <if test="wmodelDepartId != null">
        AND wmodel.DEPART_ID = #{wmodelDepartId}
      </if>
      <if test="wmodelProcedureId != null">
        AND wmodel.PROCEDURE_ID = #{wmodelProcedureId}
      </if>
      <if test="wmodelQrcode != null">
        AND wmodel.QRCODE = #{wmodelQrcode}
      </if>
      <if test="wmodelName != null and wmodelName != ''">
        AND wmodel.NAME = #{wmodelName}
      </if>
      <if test="wmodelUseLocation != null">
        AND wmodel.USE_LOCATION = #{wmodelUseLocation}
      </if>
      <if test="wmodelStatus != null">
        AND wmodel.STATUS = #{wmodelStatus}
      </if>
      <if test="wmodelAddr != null and wmodelAddr != ''">
        AND wmodel.ADDR = #{wmodelAddr}
      </if>
    </where>
  </select>
 
 
  <select id="getListBynum" parameterType="doumeemes.dao.ext.dto.QueryWStockExtDTO" resultMap="WStockExtListVO">
    SELECT
    a.ID,
    a.DELETED,
    a.CREATE_USER,
    a.CREATE_TIME,
    a.UPDATE_USER,
    a.UPDATE_TIME,
    a.REMARK,
    a.ROOT_DEPART_ID,
    a.MATERIAL_ID,
    a.UNIT_ID,
    a.LOCATION_ID,
    a.WAREHOUSE_ID,
    a.BATCH,
    a.NUM
    FROM w_stock a
    <where>
 
      <if test="id != null">
        AND a.ID = #{id}
      </if>
      <if test="deleted != null">
        AND a.DELETED = #{deleted}
      </if>
      <if test="createUser != null">
        AND a.CREATE_USER = #{createUser}
      </if>
      <if test="createTime != null">
        AND a.CREATE_TIME = #{createTime}
      </if>
      <if test="updateUser != null">
        AND a.UPDATE_USER = #{updateUser}
      </if>
      <if test="updateTime != null">
        AND a.UPDATE_TIME = #{updateTime}
      </if>
      <if test="remark != null and remark != ''">
        AND a.REMARK = #{remark}
      </if>
      <if test="rootDepartId != null">
        AND a.ROOT_DEPART_ID = #{rootDepartId}
      </if>
      <if test="materialId != null">
        AND a.MATERIAL_ID = #{materialId}
      </if>
      <if test="unitId != null">
        AND a.UNIT_ID = #{unitId}
      </if>
      <if test="locationId != null">
        AND a.LOCATION_ID = #{locationId}
      </if>
      <if test="warehouseId != null">
        AND a.WAREHOUSE_ID = #{warehouseId}
      </if>
      <if test="batch != null and batch != ''">
        AND a.BATCH = #{batch}
      </if>
      <if test="num != null and num != ''">
        AND a.NUM > #{num}
      </if>
    </where>
  </select>
 
 
 
  <select id="stockListByDto" parameterType="doumeemes.dao.ext.beanDto.QueryWStockDto"  resultMap="WStockExtListVO">
    SELECT
    a.ID,
    a.DELETED,
    a.CREATE_USER,
    a.CREATE_TIME,
    a.UPDATE_USER,
    a.UPDATE_TIME,
    a.REMARK,
    a.ROOT_DEPART_ID,
    a.MATERIAL_ID,
    a.UNIT_ID,
    a.LOCATION_ID,
    a.WAREHOUSE_ID,
    a.BATCH,
    a.NUM,
    mmodel.ID AS MMODEL_ID,
    mmodel.DELETED AS MMODEL_DELETED,
    mmodel.CREATE_USER AS MMODEL_CREATE_USER,
    mmodel.CREATE_TIME AS MMODEL_CREATE_TIME,
    mmodel.UPDATE_USER AS MMODEL_UPDATE_USER,
    mmodel.UPDATE_TIME AS MMODEL_UPDATE_TIME,
    mmodel.REMARK AS MMODEL_REMARK,
    mmodel.ROOT_DEPART_ID AS MMODEL_ROOT_DEPART_ID,
    mmodel.NAME AS MMODEL_NAME,
    mmodel.CODE AS MMODEL_CODE,
    mmodel.ATTR AS MMODEL_ATTR,
    mmodel.UNION_NAME AS MMODEL_UNION_NAME,
    mmodel.UNIT_ID AS MMODEL_UNIT_ID,
    mmodel.CATE_UNION_ID AS MMODEL_CATE_UNION_ID,
    mmodel.FORMATION AS MMODEL_FORMATION,
    mmodel.QRCODE_ID AS MMODEL_QRCODE_ID,
    mmodel.STATUS AS MMODEL_STATUS,
    mmodel.VALID_TIME AS MMODEL_VALID_TIME,
    mmodel.INVALID_TIME AS MMODEL_INVALID_TIME,
    mmodel.CHECK_WAY AS MMODEL_CHECK_WAY,
    mmodel.QUALITY_REQUIRE AS MMODEL_QUALITY_REQUIRE,
    mmodel.CHECK_NOTE AS MMODEL_CHECK_NOTE,
    umodel.ID AS UMODEL_ID,
    umodel.DELETED AS UMODEL_DELETED,
    umodel.CREATE_USER AS UMODEL_CREATE_USER,
    umodel.CREATE_TIME AS UMODEL_CREATE_TIME,
    umodel.UPDATE_USER AS UMODEL_UPDATE_USER,
    umodel.UPDATE_TIME AS UMODEL_UPDATE_TIME,
    umodel.REMARK AS UMODEL_REMARK,
    umodel.ROOT_DEPART_ID AS UMODEL_ROOT_DEPART_ID,
    umodel.NAME AS UMODEL_NAME,
    umodel.TYPE AS UMODEL_TYPE,
    umodel.STATUS AS UMODEL_STATUS,
    lmodel.ID AS LMODEL_ID,
    lmodel.DELETED AS LMODEL_DELETED,
    lmodel.CREATE_USER AS LMODEL_CREATE_USER,
    lmodel.CREATE_TIME AS LMODEL_CREATE_TIME,
    lmodel.UPDATE_USER AS LMODEL_UPDATE_USER,
    lmodel.UPDATE_TIME AS LMODEL_UPDATE_TIME,
    lmodel.REMARK AS LMODEL_REMARK,
    lmodel.ROOT_DEPART_ID AS LMODEL_ROOT_DEPART_ID,
    lmodel.WAREHOUSE_ID AS LMODEL_WAREHOUSE_ID,
    lmodel.UNION_NAME AS LMODEL_UNION_NAME,
    lmodel.AREA AS LMODEL_AREA,
    lmodel.SHELF AS LMODEL_SHELF,
    lmodel.CELL AS LMODEL_CELL,
    lmodel.QRCODE AS LMODEL_QRCODE,
    lmodel.STATUS AS LMODEL_STATUS,
    wmodel.ID AS WMODEL_ID,
    wmodel.DELETED AS WMODEL_DELETED,
    wmodel.CREATE_USER AS WMODEL_CREATE_USER,
    wmodel.CREATE_TIME AS WMODEL_CREATE_TIME,
    wmodel.UPDATE_USER AS WMODEL_UPDATE_USER,
    wmodel.UPDATE_TIME AS WMODEL_UPDATE_TIME,
    wmodel.REMARK AS WMODEL_REMARK,
    wmodel.ROOT_DEPART_ID AS WMODEL_ROOT_DEPART_ID,
    wmodel.DEPART_ID AS WMODEL_DEPART_ID,
    wmodel.PROCEDURE_ID AS WMODEL_PROCEDURE_ID,
    wmodel.QRCODE AS WMODEL_QRCODE,
    wmodel.NAME AS WMODEL_NAME,
    wmodel.USE_LOCATION AS WMODEL_USE_LOCATION,
    wmodel.STATUS AS WMODEL_STATUS,
    wmodel.ADDR AS WMODEL_ADDR
    FROM w_stock a
    LEFT JOIN material mmodel ON mmodel.ID=a.MATERIAL_ID
    LEFT JOIN unit umodel ON a.UNIT_ID=umodel.ID
    LEFT JOIN warehouse_location lmodel ON a.LOCATION_ID=lmodel.ID
    LEFT JOIN warehouse wmodel ON a.WAREHOUSE_ID=wmodel.ID
    <where>
      AND a.DELETED = 0
      <if test="rootDepartId != null">
        AND a.ROOT_DEPART_ID = #{rootDepartId}
      </if>
      <if test="warehouseId != null">
        AND a.WAREHOUSE_ID = #{warehouseId}
      </if>
      <if test="materialId != null">
        AND a.MATERIAL_ID = #{materialId}
      </if>
      <if test="locationId != null">
        AND a.LOCATION_ID = #{locationId}
      </if>
      <if test="unitId != null">
        AND a.UNIT_ID = #{unitId}
      </if>
      <if test="batch != null and batch != ''">
        AND a.BATCH like CONCAT('%',#{batch},'%')
      </if>
      <if test="procedureId != null  ">
        AND a.PROCEDURE_ID  = #{procedureId}
      </if>
      <if test="qualityType != null ">
        AND a.QUALITY_TYPE  = #{qualityType }
      </if>
    </where>
  </select>
 
 
  <select id="selectAdminList" parameterType="doumeemes.dao.ext.beanDto.QueryWStockDto"  resultMap="WStockExtListVO">
    SELECT
    c.name as unitName ,a.PROCEDURE_ID as procedureId , p.name as procedureName , a.QUALITY_TYPE as qualityType
    , b.attr , ifnull(sum( a.NUM ),0) as num
    <if test="groupType != null ">
      <choose>
        <when test="groupType == 1 ">
          ,b.code as materialCode , b.name as materialName
        </when>
        <when test="groupType == 2 ">
          ,b.code as materialCode, b.name as materialName , e.name as wareHouseName, d.UNION_NAME as locationName
        </when>
        <otherwise>
          ,b.code as materialCode, b.name as materialName , e.name as wareHouseName, a.batch , a.LOCATION_ID as locationId  ,  d.UNION_NAME as locationName
        </otherwise>
      </choose>
    </if>
    FROM w_stock a
    LEFT JOIN material_distribute f  on a.MATERIAL_ID = f.id
    LEFT JOIN material b ON f.MATERIAL_ID=b.id
    LEFT JOIN unit c ON a.UNIT_ID=c.ID
    LEFT JOIN warehouse_location d ON a.LOCATION_ID=d.ID
    LEFT JOIN warehouse e ON a.WAREHOUSE_ID=e.ID
    LEFT JOIN procedures p ON a.PROCEDURE_ID=p.ID
    <where>
      AND a.deleted = 0
      <if test="rootDepartId != null">
        AND a.ROOT_DEPART_ID = #{rootDepartId}
      </if>
      <if test="departId != null">
        AND e.DEPART_ID = #{departId}
      </if>
      <if test="warehouseId != null">
        AND a.WAREHOUSE_ID = #{warehouseId}
      </if>
      <if test="qualityType != null">
        AND a.QUALITY_TYPE = #{qualityType}
      </if>
      <if test="materialName != null and materialName != '' ">
        AND (b.name like concat('%',#{materialName},'%')  or b.code like concat('%',#{materialName},'%'))
      </if>
      <if test="batch != null and batch != '' ">
        AND  a.batch like  concat('%',#{batch},'%')
      </if>
 
      <if test="procedureName != null and procedureName != '' ">
        AND  p.name like  concat('%',#{procedureName},'%')
      </if>
      <if test="materialOrBatch != null and materialOrBatch != '' ">
        AND (e.name like concat('%',#{materialOrBatch},'%')  or b.code like concat('%',#{materialOrBatch},'%') )
      </if>
      <if test="locationId != null">
        AND a.LOCATION_ID = #{locationId}
      </if>
      <if test="greaterZero != null">
        <if test="greaterZero = 1 ">
          AND a.NUM > 0
        </if>
      </if>
    </where>
    group by c.name , b.ATTR , a.PROCEDURE_ID  , p.name , a.QUALITY_TYPE
    <if test="groupType != null ">
      <choose>
        <when test="groupType == 1 ">
          ,b.code, b.name
        </when>
        <when test="groupType == 2 ">
          ,b.code, b.name , e.name
        </when>
        <otherwise>
          ,b.code, b.name , e.name , a.batch , a.LOCATION_ID ,  d.UNION_NAME
        </otherwise>
      </choose>
    </if>
  </select>
 
 
  <select id="selectAdminListForH5" parameterType="doumeemes.dao.ext.beanDto.QueryWStockDto"  resultMap="WStockExtListVO">
    SELECT
    c.name as unitName , b.attr , ifnull(sum( a.NUM ),0) as num ,
    a.PROCEDURE_ID as procedureId , p.name as procedureName , a.QUALITY_TYPE as qualityType
    ,b.code as materialCode, b.name as materialName , e.name as wareHouseName, a.batch
    FROM w_stock a
    LEFT JOIN material_distribute f  on a.MATERIAL_ID = f.id
    LEFT JOIN material b ON f.MATERIAL_ID=b.id
    LEFT JOIN unit c ON a.UNIT_ID=c.ID
    LEFT JOIN warehouse_location d ON a.LOCATION_ID=d.ID
    LEFT JOIN warehouse e ON a.WAREHOUSE_ID=e.ID
    LEFT JOIN procedures p ON a.PROCEDURE_ID=p.ID
    <where>
      <if test="rootDepartId != null">
        AND a.ROOT_DEPART_ID = #{rootDepartId}
      </if>
      <if test="warehouseId != null">
        AND a.WAREHOUSE_ID = #{warehouseId}
      </if>
      <if test="materialName != null and materialName != '' ">
        AND a.MATERIAL_ID = #{materialId}
      </if>
      <if test="locationId != null">
        AND a.LOCATION_ID = #{locationId}
      </if>
      <if test="greaterZero != null">
        <if test="greaterZero = 1 ">
          AND a.NUM > 0
        </if>
      </if>
    </where>
    group by c.name , b.ATTR ,b.code, b.name , e.name , a.batch ,a.PROCEDURE_ID  , p.name , a.QUALITY_TYPE
  </select>
 
 
  <select id="choiceStockList" parameterType="doumeemes.dao.ext.beanDto.QueryWStockDto"  resultMap="WStockExtListVO">
 
    SELECT
    a.id ,
    f.id as materialId,
    b.CODE AS materialCode,
    b.NAME AS materialName,
    c.id AS unitId,
    c.NAME AS unitName,
    CONCAT( IFNULL(h.`NAME`,''), IFNULL(i.`NAME`,''), IFNULL(j.`NAME`,'') ) AS categoryName ,
    h.`NAME` as categoryBigName ,
    i.`NAME` as categoryMiddleName,
    j.`NAME`  as categorySmallName ,
    a.batch,
    a.LOCATION_ID AS locationId,
    d.UNION_NAME AS locationName,
    a.num ,
    b.ATTR ,
    c.ATTRIBUTE_DATA as unitAttribute ,
    a.PROCEDURE_ID as procedureId , p.name as procedureName , a.QUALITY_TYPE as qualityType
    FROM
    w_stock a
    INNER JOIN material_distribute f ON a.MATERIAL_ID = f.id
    INNER JOIN material b ON f.MATERIAL_ID = b.id
    INNER JOIN category_union g ON b.CATE_UNION_ID = g.id
    LEFT JOIN category h ON g.CATE_BIG_ID = h.id
    LEFT JOIN category i ON g.CATE_MIDDLE_ID = i.id
    LEFT JOIN category j ON g.CATE_SMALL_ID = j.id
    INNER JOIN unit c ON a.UNIT_ID = c.ID
    LEFT JOIN warehouse_location d ON a.LOCATION_ID = d.ID
    LEFT JOIN warehouse e ON a.WAREHOUSE_ID = e.ID
    LEFT JOIN procedures p ON a.PROCEDURE_ID=p.ID
    <where>
      and a.DELETED = 0
      and a.NUM > 0
      <if test="warehouseId != null">
        AND a.WAREHOUSE_ID = #{warehouseId}
      </if>
 
      <if test="batch != null and batch != '' ">
        AND a.batch = #{batch}
      </if>
 
      <if test="materialName != null and materialName != '' ">
        AND ( b.NAME like  CONCAT('%',#{materialName},'%') or b.code like  CONCAT('%',#{materialName},'%') )
      </if>
 
      <if test="materialId != null  ">
        AND a.material_id = #{materialId }
      </if>
 
      <if test="locationId != null  ">
        AND a.LOCATION_ID = #{locationId}
      </if>
 
      <if test="cateBigId != null">
        AND h.id = #{cateBigId}
      </if>
 
      <if test="cateMiddleId != null">
        AND  i.id = #{cateMiddleId}
      </if>
 
      <if test="cateSmallId != null">
        AND j.id = #{cateSmallId}
      </if>
      <if test="qualityType != null">
        AND a.QUALITY_TYPE = #{qualityType}
      </if>
      <if test="warehouseQualityType != null   and warehouseQualityType != '' ">
        AND a.QUALITY_TYPE = #{warehouseQualityType}
      </if>
      <if test="procedureId != null">
        AND a.procedure_id = #{procedureId}
      </if>
      <if test="ids != null and ids != '' ">
        AND not exists ( select 1 from w_stock wStock where find_in_set(wStock.id , #{ids}) and a.id = wStock.id  )
      </if>
 
      <if test="deviceId != null  ">
        AND  a.LOCATION_ID in ( select d.PRODUCE_WAREHOUSE_LOCATION_ID from device d where d.id = #{deviceId} )
      </if>
 
      <if test="materialDistributeId != null and materialDistributeId.size()>0">
        AND `a`.`MATERIAL_ID` in <foreach collection="materialDistributeId" open="(" close=")" item="item" separator=",">#{item}</foreach>
      </if>
 
    </where>
 
 
  </select>
 
 
  <select id="choiceStockPageByTransfer" parameterType="doumeemes.dao.ext.beanDto.QueryWStockHeadNewDTO"  resultMap="WStockExtListVO">
 
    SELECT
    a.id ,
    f.id as materialId,
    b.CODE AS materialCode,
    b.NAME AS materialName,
    c.id AS unitId,
    c.NAME AS unitName,
    CONCAT( IFNULL(h.`NAME`,''), IFNULL(i.`NAME`,''), IFNULL(j.`NAME`,'') ) AS categoryName ,
    h.`NAME` as categoryBigName ,
    i.`NAME` as categoryMiddleName,
    j.`NAME`  as categorySmallName ,
    a.batch,
    a.LOCATION_ID AS locationId,
    d.UNION_NAME AS locationName,
    a.num ,
    b.ATTR ,
    c.ATTRIBUTE_DATA as unitAttribute ,
    a.PROCEDURE_ID as procedureId , p.name as procedureName , a.QUALITY_TYPE as qualityType
    FROM
    w_stock a
    INNER JOIN material_distribute f ON a.MATERIAL_ID = f.id
    INNER JOIN material b ON f.MATERIAL_ID = b.id
    INNER JOIN category_union g ON b.CATE_UNION_ID = g.id
    LEFT JOIN category h ON g.CATE_BIG_ID = h.id
    LEFT JOIN category i ON g.CATE_MIDDLE_ID = i.id
    LEFT JOIN category j ON g.CATE_SMALL_ID = j.id
    INNER JOIN unit c ON a.UNIT_ID = c.ID
    LEFT JOIN warehouse_location d ON a.LOCATION_ID = d.ID
    LEFT JOIN warehouse e ON a.WAREHOUSE_ID = e.ID
    LEFT JOIN procedures p ON a.PROCEDURE_ID=p.ID
    <where>
      and a.DELETED = 0
      and a.NUM > 0
      <if test="warehouseId != null">
        AND a.WAREHOUSE_ID = #{warehouseId}
      </if>
 
      <if test="stockNewDTOList != null and stockNewDTOList.size > 0">
        AND  (
        <foreach collection="stockNewDTOList" open="(" close=")" separator="or" item="stockNewDTO">
            (
              <if test="stockNewDTO.materialId != null">
                 a.MATERIAL_ID = #{stockNewDTO.materialId}
              </if>
              <if test="stockNewDTO.unitId != null">
                and a.UNIT_ID = #{stockNewDTO.unitId}
              </if>
              <if test="stockNewDTO.procedureId != null">
                and a.PROCEDURE_ID = #{stockNewDTO.procedureId}
              </if>
              <if test="stockNewDTO.qualityType != null">
                and a.QUALITY_TYPE = #{stockNewDTO.qualityType}
              </if>
              <if test="stockNewDTO.locationId != null">
                and a.LOCATION_ID = #{stockNewDTO.locationId}
              </if>
              <if test="stockNewDTO.batch != null and stockNewDTO.batch != '' ">
                and a.BATCH = #{stockNewDTO.batch}
              </if>
            )
        </foreach>
        )
      </if>
 
    </where>
 
 
  </select>
 
  <select id="choiceStockListNoLocation" parameterType="doumeemes.dao.ext.beanDto.QueryWStockDto"  resultMap="WStockExtListVO">
 
    SELECT
    f.id as materialId,
    b.CODE AS materialCode,
    b.NAME AS materialName,
    c.id AS unitId,
    c.NAME AS unitName,
    CONCAT( h.`NAME`, i.`NAME`, j.`NAME` ) AS categoryName ,
    a.batch,
    ifnull( sum( a.NUM ), 0 ) AS num ,
    c.ATTRIBUTE_DATA as unitAttribute ,
    p.name as procedureName,
    a.procedure_id as procedureId,
    a.quality_type as qualityType
    FROM
    w_stock a
    INNER JOIN material_distribute f ON a.MATERIAL_ID = f.id
    INNER JOIN material b ON f.MATERIAL_ID = b.id
    INNER JOIN category_union g ON b.CATE_UNION_ID = g.id
    LEFT JOIN category h ON g.CATE_BIG_ID = h.id
    LEFT JOIN category i ON g.CATE_MIDDLE_ID = i.id
    LEFT JOIN category j ON g.CATE_SMALL_ID = j.id
    INNER JOIN unit c ON a.UNIT_ID = c.ID
    INNER JOIN warehouse e ON a.WAREHOUSE_ID = e.ID
    LEFT JOIN procedures p ON a.PROCEDURE_ID=p.ID
    <where>
      and a.DELETED = 0
      <if test="warehouseId != null">
        AND a.WAREHOUSE_ID = #{warehouseId}
      </if>
 
      <if test="batch != null and batch != '' ">
        AND a.batch  = #{batch}
      </if>
 
      <if test="materialName != null and materialName != '' ">
        AND ( b.NAME like  CONCAT('%',#{materialName},'%') or b.code like  CONCAT('%',#{materialName},'%') )
      </if>
 
      <if test="cateBigId != null">
        AND h.id = #{cateBigId}
      </if>
 
      <if test="cateMiddleId != null">
        AND  i.id = #{cateMiddleId}
      </if>
 
      <if test="cateSmallId != null">
        AND j.id = #{cateSmallId}
      </if>
 
      <if test="qualityType != null">
        AND a.QUALITY_TYPE = #{qualityType}
      </if>
 
      <if test="procedureId != null">
        AND p.id = #{procedureId}
      </if>
      <if test="procedureId == null">
        AND a.procedure_id is null
      </if>
 
      <if test="ids != null and ids != '' ">
        AND not exists ( select 1 from w_stock wStock where find_in_set(wStock.MATERIAL_ID , #{ids}) and a.MATERIAL_ID = wStock.MATERIAL_ID  )
      </if>
    </where>
    GROUP BY
    f.id,
    b.CODE,
    b.NAME,
    c.id,
    c.NAME,
    h.`NAME`,
    i.`NAME`,
    j.`NAME`,
    a.batch,
    c.ATTRIBUTE_DATA,
    p.name ,
    a.procedure_id,
    a.quality_type
 
  </select>
 
 
</mapper>