cloudroam
2025-03-10 c306cba52bcc3e2c423f77d4a52c35ad04c52038
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
<?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.jsh.erp.datasource.mappers.MaterialMapperEx">
    <resultMap extends="com.jsh.erp.datasource.mappers.MaterialMapper.BaseResultMap" id="ResultMapList" type="com.jsh.erp.datasource.entities.MaterialVo4Unit">
        <result column="unitName" jdbcType="VARCHAR" property="unitName" />
        <result column="ratio" jdbcType="DECIMAL" property="ratio" />
        <result column="categoryName" jdbcType="VARCHAR" property="categoryName" />
        <result column="bar_code" jdbcType="VARCHAR" property="mBarCode" />
        <result column="commodity_unit" jdbcType="VARCHAR" property="commodityUnit" />
        <result column="purchase_decimal" jdbcType="VARCHAR" property="purchaseDecimal" />
        <result column="commodity_decimal" jdbcType="VARCHAR" property="commodityDecimal" />
        <result column="wholesale_decimal" jdbcType="VARCHAR" property="wholesaleDecimal" />
        <result column="low_decimal" jdbcType="VARCHAR" property="lowDecimal" />
        <result column="sku" jdbcType="VARCHAR" property="sku" />
    </resultMap>
 
    <resultMap extends="com.jsh.erp.datasource.mappers.MaterialMapper.BaseResultMap" id="ResultMapListWithStock" type="com.jsh.erp.datasource.entities.MaterialVo4Unit">
        <result column="unitName" jdbcType="VARCHAR" property="unitName" />
        <result column="categoryName" jdbcType="VARCHAR" property="categoryName" />
        <result column="mBarCode" jdbcType="VARCHAR" property="mBarCode" />
        <result column="purchaseDecimal" jdbcType="VARCHAR" property="purchaseDecimal" />
        <result column="currentUnitPrice" jdbcType="VARCHAR" property="currentUnitPrice" />
        <result column="initialStock" jdbcType="DECIMAL" property="initialStock" />
        <result column="currentStock" jdbcType="DECIMAL" property="currentStock" />
        <result column="currentStockPrice" jdbcType="DECIMAL" property="currentStockPrice" />
        <result column="currentStockMovePrice" jdbcType="DECIMAL" property="currentStockMovePrice" />
        <result column="currentWeight" jdbcType="DECIMAL" property="currentWeight" />
    </resultMap>
 
    <resultMap extends="com.jsh.erp.datasource.mappers.MaterialMapper.BaseResultMap" id="ResultAndUnitMap" type="com.jsh.erp.datasource.entities.MaterialVo4Unit">
        <result column="meId" jdbcType="BIGINT" property="meId" />
        <result column="unit_name" jdbcType="VARCHAR" property="unitName" />
        <result column="sku" jdbcType="VARCHAR" property="sku" />
    </resultMap>
 
    <resultMap id="InitialStockWithMaterialMap" type="com.jsh.erp.datasource.entities.MaterialInitialStockWithMaterial">
        <result column="material_id" jdbcType="BIGINT" property="materialId" />
        <result column="number" jdbcType="DECIMAL" property="number" />
    </resultMap>
 
    <select id="selectByConditionMaterial" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultMapList">
        select m.*,u.name unitName, mc.name categoryName, me.bar_code,
        me.purchase_decimal, me.commodity_decimal, me.wholesale_decimal,me.low_decimal,me.sku
        FROM jsh_material m
        left JOIN jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1'
        left JOIN jsh_unit u on m.unit_id = u.id and ifnull(u.delete_Flag,'0') !='1'
        left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
        where 1=1
        <if test="materialParam != null and materialParam !=''">
            <bind name="bindKey" value="'%'+materialParam+'%'"/>
            and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey}
            or m.model like #{bindKey} or m.color like #{bindKey} or m.brand like #{bindKey} or m.mfrs like #{bindKey})
        </if>
        <if test="standard != null and standard !=''">
            <bind name="bindStandard" value="'%'+standard+'%'"/>
            and m.standard like #{bindStandard}
        </if>
        <if test="model != null and model !=''">
            <bind name="bindModel" value="'%'+model+'%'"/>
            and m.model like #{bindModel}
        </if>
        <if test="color != null and color !=''">
            <bind name="bindColor" value="'%'+color+'%'"/>
            and m.color like #{bindColor}
        </if>
        <if test="brand != null and brand !=''">
            <bind name="bindBrand" value="'%'+brand+'%'"/>
            and m.brand like #{bindBrand}
        </if>
        <if test="mfrs != null and mfrs !=''">
            <bind name="bindMfrs" value="'%'+mfrs+'%'"/>
            and m.mfrs like #{bindMfrs}
        </if>
        <if test="materialOther != null and materialOther !=''">
            <bind name="bindOther" value="'%'+materialOther+'%'"/>
            and (m.other_field1 like #{bindOther} or m.other_field2 like #{bindOther} or m.other_field3 like #{bindOther})
        </if>
        <if test="weight != null and weight !=''">
            and m.weight = #{weight}
        </if>
        <if test="expiryNum != null and expiryNum !=''">
            and m.expiry_num = #{expiryNum}
        </if>
        <if test="enableSerialNumber != null and enableSerialNumber !=''">
            and m.enable_serial_number = #{enableSerialNumber}
        </if>
        <if test="enableBatchNumber != null and enableBatchNumber !=''">
            and m.enable_batch_number = #{enableBatchNumber}
        </if>
        <if test="position != null and position !=''">
            <bind name="bindPosition" value="'%'+position+'%'"/>
            and m.position like #{bindPosition}
        </if>
        <if test="enabled != null and enabled !=''">
            and m.enabled = #{enabled}
        </if>
        <if test="remark != null and remark !=''">
            <bind name="bindRemark" value="'%'+remark+'%'"/>
            and m.remark like #{bindRemark}
        </if>
        <if test="idList.size()>0">
            and m.category_id in
            <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        and ifnull(m.delete_flag,'0') !='1'
        group by m.id
        order by m.id desc
        <if test="offset != null and rows != null">
            limit #{offset},#{rows}
        </if>
    </select>
 
    <select id="countsByMaterial" resultType="java.lang.Long">
        SELECT
        COUNT(m.id)
        FROM jsh_material m
        left JOIN jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1'
        left JOIN jsh_unit u on m.unit_id = u.id and ifnull(u.delete_Flag,'0') !='1'
        left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
        WHERE 1=1
        and me.default_flag=1
        <if test="materialParam != null and materialParam !=''">
            <bind name="bindKey" value="'%'+materialParam+'%'"/>
            and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey}
            or m.model like #{bindKey} or m.color like #{bindKey} or m.brand like #{bindKey} or m.mfrs like #{bindKey})
        </if>
        <if test="standard != null and standard !=''">
            <bind name="bindStandard" value="'%'+standard+'%'"/>
            and m.standard like #{bindStandard}
        </if>
        <if test="model != null and model !=''">
            <bind name="bindModel" value="'%'+model+'%'"/>
            and m.model like #{bindModel}
        </if>
        <if test="color != null and color !=''">
            <bind name="bindColor" value="'%'+color+'%'"/>
            and m.color like #{bindColor}
        </if>
        <if test="brand != null and brand !=''">
            <bind name="bindBrand" value="'%'+brand+'%'"/>
            and m.brand like #{bindBrand}
        </if>
        <if test="mfrs != null and mfrs !=''">
            <bind name="bindMfrs" value="'%'+mfrs+'%'"/>
            and m.mfrs like #{bindMfrs}
        </if>
        <if test="materialOther != null and materialOther !=''">
            <bind name="bindOther" value="'%'+materialOther+'%'"/>
            and (m.other_field1 like #{bindOther} or m.other_field2 like #{bindOther} or m.other_field3 like #{bindOther})
        </if>
        <if test="weight != null and weight !=''">
            and m.weight = #{weight}
        </if>
        <if test="expiryNum != null and expiryNum !=''">
            and m.expiry_num = #{expiryNum}
        </if>
        <if test="enableSerialNumber != null and enableSerialNumber !=''">
            and m.enable_serial_number = #{enableSerialNumber}
        </if>
        <if test="enableBatchNumber != null and enableBatchNumber !=''">
            and m.enable_batch_number = #{enableBatchNumber}
        </if>
        <if test="position != null and position !=''">
            <bind name="bindPosition" value="'%'+position+'%'"/>
            and m.position like #{bindPosition}
        </if>
        <if test="enabled != null and enabled !=''">
            and m.enabled = #{enabled}
        </if>
        <if test="remark != null and remark !=''">
            <bind name="bindRemark" value="'%'+remark+'%'"/>
            and m.remark like #{bindRemark}
        </if>
        <if test="idList.size()>0">
            and m.category_id in
            <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        and ifnull(m.delete_flag,'0') !='1'
    </select>
 
    <insert id="insertSelectiveEx" parameterType="com.jsh.erp.datasource.entities.Material" useGeneratedKeys="true" keyProperty="id">
        insert into jsh_material
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="categoryId != null">
                category_id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="mfrs != null">
                mfrs,
            </if>
            <if test="model != null">
                model,
            </if>
            <if test="standard != null">
                standard,
            </if>
            <if test="brand != null">
                brand,
            </if>
            <if test="mnemonic != null">
                mnemonic,
            </if>
            <if test="color != null">
                color,
            </if>
            <if test="unit != null">
                unit,
            </if>
            <if test="remark != null">
                remark,
            </if>
            <if test="imgName != null">
                img_name,
            </if>
            <if test="unitId != null">
                unit_id,
            </if>
            <if test="expiryNum != null">
                expiry_num,
            </if>
            <if test="weight != null">
                weight,
            </if>
            <if test="enabled != null">
                enabled,
            </if>
            <if test="otherField1 != null">
                other_field1,
            </if>
            <if test="otherField2 != null">
                other_field2,
            </if>
            <if test="otherField3 != null">
                other_field3,
            </if>
            <if test="enableSerialNumber != null">
                enable_serial_number,
            </if>
            <if test="enableBatchNumber != null">
                enable_batch_number,
            </if>
            <if test="position != null">
                position,
            </if>
            <if test="tenantId != null">
                tenant_id,
            </if>
            <if test="deleteFlag != null">
                delete_flag,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=BIGINT},
            </if>
            <if test="categoryId != null">
                #{categoryId,jdbcType=BIGINT},
            </if>
            <if test="name != null">
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="mfrs != null">
                #{mfrs,jdbcType=VARCHAR},
            </if>
            <if test="model != null">
                #{model,jdbcType=VARCHAR},
            </if>
            <if test="standard != null">
                #{standard,jdbcType=VARCHAR},
            </if>
            <if test="brand != null">
                #{brand,jdbcType=VARCHAR},
            </if>
            <if test="mnemonic != null">
                #{mnemonic,jdbcType=VARCHAR},
            </if>
            <if test="color != null">
                #{color,jdbcType=VARCHAR},
            </if>
            <if test="unit != null">
                #{unit,jdbcType=VARCHAR},
            </if>
            <if test="remark != null">
                #{remark,jdbcType=VARCHAR},
            </if>
            <if test="imgName != null">
                #{imgName,jdbcType=VARCHAR},
            </if>
            <if test="unitId != null">
                #{unitId,jdbcType=BIGINT},
            </if>
            <if test="expiryNum != null">
                #{expiryNum,jdbcType=INTEGER},
            </if>
            <if test="weight != null">
                #{weight,jdbcType=DECIMAL},
            </if>
            <if test="enabled != null">
                #{enabled,jdbcType=BIT},
            </if>
            <if test="otherField1 != null">
                #{otherField1,jdbcType=VARCHAR},
            </if>
            <if test="otherField2 != null">
                #{otherField2,jdbcType=VARCHAR},
            </if>
            <if test="otherField3 != null">
                #{otherField3,jdbcType=VARCHAR},
            </if>
            <if test="enableSerialNumber != null">
                #{enableSerialNumber,jdbcType=VARCHAR},
            </if>
            <if test="enableBatchNumber != null">
                #{enableBatchNumber,jdbcType=VARCHAR},
            </if>
            <if test="position != null">
                #{position,jdbcType=VARCHAR},
            </if>
            <if test="tenantId != null">
                #{tenantId,jdbcType=BIGINT},
            </if>
            <if test="deleteFlag != null">
                #{deleteFlag,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
 
    <select id="findUnitList" resultType="com.jsh.erp.datasource.entities.Unit">
        select u.* from jsh_unit u
        left join jsh_material m on m.unit_id=u.id and ifnull(m.delete_flag,'0') !='1'
        where m.id = #{mId}
        and ifnull(u.delete_flag,'0') !='1'
    </select>
 
    <select id="findById" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultAndUnitMap">
        select m.*,u.name unit_name from jsh_material m
        left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_flag,'0') !='1'
        where m.id = #{id}
        and ifnull(m.delete_flag,'0') !='1'
    </select>
 
    <select id="findByIdWithBarCode" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultAndUnitMap">
        select m.*,u.name unit_name,me.bar_code m_bar_code, me.commodity_unit, me.purchase_decimal, me.commodity_decimal,
        me.wholesale_decimal, me.low_decimal
        from jsh_material m
        left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
        left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
        where me.id = #{meId}
        and ifnull(m.delete_flag,'0') !='1'
    </select>
 
    <select id="getMaterialByParam" resultType="com.jsh.erp.datasource.vo.MaterialVoSearch">
        select me.bar_code, m.name, m.mnemonic, m.standard, m.model, m.color, me.commodity_unit unit
        from jsh_material m
        left join jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1'
        where m.enabled=1 and me.id is not null
        <if test="materialParam != null and materialParam !=''">
            <bind name="bindKey" value="'%'+materialParam+'%'"/>
            and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey} or m.mnemonic like #{bindKey})
        </if>
        and ifnull(m.delete_flag,'0') !='1'
        order by m.id desc, me.default_flag desc, me.id asc
        limit 0,20
    </select>
 
    <select id="findBySelectWithBarCode" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultAndUnitMap">
        select m.*,u.name unit_name,mc.name categoryName,me.bar_code m_bar_code,me.id meId,me.commodity_unit,me.sku from jsh_material m
        left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
        left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
        left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
        where m.enabled=1 and me.id is not null
        <if test="q != null and q !=''">
            <bind name="bindKey" value="'%'+q+'%'"/>
            and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey}
            or m.model like #{bindKey} or m.color like #{bindKey} or m.brand like #{bindKey} or m.mfrs like #{bindKey})
        </if>
        <if test="standardOrModel != null and standardOrModel !=''">
            <bind name="bindStandardOrModel" value="'%'+standardOrModel+'%'"/>
            and (m.standard like #{bindStandardOrModel} or m.model like #{bindStandardOrModel})
        </if>
        <if test="color != null and color !=''">
            <bind name="bindColor" value="'%'+color+'%'"/>
            and m.color like #{bindColor}
        </if>
        <if test="brand != null and brand !=''">
            <bind name="bindBrand" value="'%'+brand+'%'"/>
            and m.brand like #{bindBrand}
        </if>
        <if test="mfrs != null and mfrs !=''">
            <bind name="bindMfrs" value="'%'+mfrs+'%'"/>
            and m.mfrs like #{bindMfrs}
        </if>
        <if test="idList.size()>0">
            and m.category_id in
            <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="enableSerialNumber != null and enableSerialNumber !=''">
            and m.enable_serial_number = #{enableSerialNumber}
        </if>
        <if test="enableBatchNumber != null and enableBatchNumber !=''">
            and m.enable_batch_number = #{enableBatchNumber}
        </if>
        and ifnull(m.delete_flag,'0') !='1'
        ORDER BY m.id desc, me.default_flag desc, me.id asc
        <if test="offset != null and rows != null">
            limit #{offset},#{rows}
        </if>
    </select>
 
    <select id="findBySelectWithBarCodeCount" resultType="java.lang.Integer">
        select count(1) from jsh_material m
        left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
        left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
        where m.enabled=1 and me.id is not null
        <if test="q != null and q !=''">
            <bind name="bindKey" value="'%'+q+'%'"/>
            and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey}
            or m.model like #{bindKey} or m.color like #{bindKey} or m.brand like #{bindKey} or m.mfrs like #{bindKey})
        </if>
        <if test="standardOrModel != null and standardOrModel !=''">
            <bind name="bindStandardOrModel" value="'%'+standardOrModel+'%'"/>
            and (m.standard like #{bindStandardOrModel} or m.model like #{bindStandardOrModel})
        </if>
        <if test="color != null and color !=''">
            <bind name="bindColor" value="'%'+color+'%'"/>
            and m.color like #{bindColor}
        </if>
        <if test="brand != null and brand !=''">
            <bind name="bindBrand" value="'%'+brand+'%'"/>
            and m.brand like #{bindBrand}
        </if>
        <if test="mfrs != null and mfrs !=''">
            <bind name="bindMfrs" value="'%'+mfrs+'%'"/>
            and m.mfrs like #{bindMfrs}
        </if>
        <if test="idList.size()>0">
            and m.category_id in
            <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="enableSerialNumber != null and enableSerialNumber !=''">
            and m.enable_serial_number = #{enableSerialNumber}
        </if>
        <if test="enableBatchNumber != null and enableBatchNumber !=''">
            and m.enable_batch_number = #{enableBatchNumber}
        </if>
        and ifnull(m.delete_flag,'0') !='1'
    </select>
 
    <select id="exportExcel" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultMapList">
        select m.*,u.name unitName, u.ratio, mc.name categoryName,me.bar_code,me.commodity_unit,me.purchase_decimal, me.commodity_decimal,
        me.wholesale_decimal, me.low_decimal, me.sku
        from jsh_material m
        left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
        left JOIN jsh_unit u on m.unit_id = u.id and ifnull(u.delete_Flag,'0') !='1'
        left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
        where 1=1
        and (me.default_flag=1 or (me.sku is not null and me.sku!=''))
        <if test="materialParam != null and materialParam !=''">
            <bind name="bindKey" value="'%'+materialParam+'%'"/>
            and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
        </if>
        <if test="color != null and color !=''">
            <bind name="bindColor" value="'%'+color+'%'"/>
            and m.color like #{bindColor}
        </if>
        <if test="materialOther != null and materialOther !=''">
            <bind name="bindOther" value="'%'+materialOther+'%'"/>
            and (m.mfrs like #{bindOther} or m.other_field1 like #{bindOther}
            or m.other_field2 like #{bindOther} or m.other_field3 like #{bindOther})
        </if>
        <if test="weight != null and weight !=''">
            and m.weight = #{weight}
        </if>
        <if test="expiryNum != null and expiryNum !=''">
            and m.expiry_num = #{expiryNum}
        </if>
        <if test="enabled != null and enabled !=''">
            and m.enabled = #{enabled}
        </if>
        <if test="enableSerialNumber != null and enableSerialNumber !=''">
            and m.enable_serial_number = #{enableSerialNumber}
        </if>
        <if test="enableBatchNumber != null and enableBatchNumber !=''">
            and m.enable_batch_number = #{enableBatchNumber}
        </if>
        <if test="remark != null and remark !=''">
            <bind name="bindRemark" value="'%'+remark+'%'"/>
            and m.remark like #{bindRemark}
        </if>
        <if test="idList.size()>0">
            and m.category_id in
            <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        and ifnull(m.delete_flag,'0') !='1'
        order by m.id desc, me.default_flag desc, me.id asc
    </select>
 
    <select id="getOtherMaterialList" resultType="com.jsh.erp.datasource.entities.MaterialExtend">
        select me.material_id, me.bar_code, me.commodity_unit from jsh_material_extend me
        where me.default_flag=0 and (me.sku='' or me.sku is null)
        and ifnull(me.delete_Flag,'0') !='1'
        group by me.material_id
    </select>
 
    <select id="findByMaterialName"  resultType="com.jsh.erp.datasource.entities.Material">
        select m.*
        FROM jsh_material m
        where 1=1
        <if test="name != null">
            and m.name =#{name}
        </if>
        and ifnull(m.delete_flag,'0') !='1'
    </select>
 
    <select id="getMaterialEnableSerialNumberList" parameterType="java.util.Map" resultMap="ResultAndUnitMap">
        select m.*,me.bar_code m_bar_code from jsh_material m
        left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
        where 1=1
        and m.enabled=1
        and m.enable_serial_number ='1'
        <if test="q != null and q !=''">
            <bind name="bindKey" value="'%'+q+'%'"/>
            and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
        </if>
        and ifnull(m.delete_flag,'0') !='1'
        order by m.id desc
        <if test="offset != null and rows != null">
            limit #{offset},#{rows}
        </if>
    </select>
 
    <select id="getMaterialEnableSerialNumberCount" resultType="java.lang.Long">
        select count(me.id) from jsh_material m
        left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
        where 1=1
        and m.enabled ='1'
        and m.enable_serial_number ='1'
        <if test="q != null and q !=''">
            <bind name="bindKey" value="'%'+q+'%'"/>
            and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
        </if>
        and ifnull(m.delete_flag,'0') !='1'
    </select>
 
    <update id="batchDeleteMaterialByIds">
        update jsh_material
        set delete_flag='1'
        where 1=1
        and ifnull(delete_flag,'0') !='1'
        and id in (
        <foreach collection="ids" item="id" separator=",">
            #{id}
        </foreach>
        )
    </update>
    <select id="getMaterialListByCategoryIds"  resultMap="com.jsh.erp.datasource.mappers.MaterialMapper.BaseResultMap">
        select
        <include refid="com.jsh.erp.datasource.mappers.MaterialMapper.Base_Column_List" />
        from jsh_material
        where 1=1
        and category_id in (
        <foreach collection="categoryIds" item="categoryId" separator=",">
            #{categoryId}
        </foreach>
        )
        and ifnull(delete_flag,'0') !='1'
    </select>
    <select id="getMaterialListByUnitIds"  resultMap="com.jsh.erp.datasource.mappers.MaterialMapper.BaseResultMap">
        select
        <include refid="com.jsh.erp.datasource.mappers.MaterialMapper.Base_Column_List" />
        from jsh_material
        where 1=1
        and unit_id in (
        <foreach collection="unitIds" item="unitId" separator=",">
            #{unitId}
        </foreach>
        )
        and ifnull(delete_flag,'0') !='1'
    </select>
 
    <select id="getMaxBarCode" resultType="java.lang.String">
        select max(CAST(me.bar_code AS SIGNED)) bar_code from jsh_material_extend me
        where 1=1
        and ifnull(me.delete_Flag,'0') !='1'
    </select>
 
    <select id="getMaterialByMeId" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultMapList">
        select m.*,me.bar_code,u.name unitName, mc.name categoryName
        FROM jsh_material m
        left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
        left JOIN jsh_unit u on m.unit_id = u.id and ifnull(u.delete_flag,'0') !='1'
        left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
        where 1=1
        <if test="meId != null">
            and me.id = #{meId}
        </if>
        and ifnull(m.delete_flag,'0') !='1'
    </select>
 
    <select id="getMaterialNameList" resultType="java.lang.String">
        select m.name from jsh_material m
        where m.name is not null and m.name !='' and ifnull(m.delete_flag,'0') !='1'
        group by m.name
        order by m.name asc
    </select>
 
    <select id="getMaterialByBarCode" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultAndUnitMap">
        select m.*,u.name unit_name, me.id meId,me.bar_code m_bar_code, me.commodity_unit, me.purchase_decimal, me.commodity_decimal,
        me.wholesale_decimal, me.low_decimal, me.sku
        from jsh_material m
        left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
        left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
        where
        me.bar_code in (
        <foreach collection="barCodeArray" item="barCode" separator=",">
            #{barCode}
        </foreach>
        )
        and ifnull(m.delete_flag,'0') !='1'
        order by m.id desc, me.default_flag desc, me.id asc
    </select>
 
    <select id="getMaterialByBarCodeAndWithOutMId" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultAndUnitMap">
        select m.*,u.name unit_name, me.id meId,me.bar_code m_bar_code, me.commodity_unit, me.purchase_decimal, me.commodity_decimal,
        me.wholesale_decimal, me.low_decimal, me.sku
        from jsh_material m
        left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
        left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
        where
        me.bar_code in (
        <foreach collection="barCodeArray" item="barCode" separator=",">
            #{barCode}
        </foreach>
        )
        and me.material_id!=#{mId}
        and ifnull(m.delete_flag,'0') !='1'
        order by me.id desc
    </select>
 
    <update id="setUnitIdToNull">
        update jsh_material
        set unit_id = null
        where 1=1
        and ifnull(delete_flag,'0') !='1'
        and id = #{id}
    </update>
 
    <update id="setExpiryNumToNull">
        update jsh_material
        set expiry_num = null
        where 1=1
        and ifnull(delete_flag,'0') !='1'
        and id = #{id}
    </update>
 
    <select id="getInitialStockWithMaterial" resultMap="InitialStockWithMaterialMap">
        select material_id, ifnull(sum(mis.number),0) number
        from jsh_material_initial_stock mis
        where 1=1
        <if test="depotList.size()>0">
            and mis.depot_id in
            <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        group by mis.material_id
    </select>
 
    <select id="getListWithStock" resultMap="ResultMapListWithStock">
        select m.*, me.commodity_unit unitName, mc.name categoryName, me.bar_code mBarCode,
        ifnull(me.purchase_decimal,0) purchaseDecimal,
        ifnull(mcs.current_unit_price,0) currentUnitPrice,
        ifnull(sum(mcs.current_number),0) currentStock,
        sum(ifnull(me.purchase_decimal, 0) * ifnull(mcs.current_number, 0)) currentStockPrice,
        sum(ifnull(mcs.current_unit_price, 0) * ifnull(mcs.current_number, 0)) currentStockMovePrice,
        sum(ifnull(m.weight, 0) * ifnull(mcs.current_number, 0)) currentWeight
        FROM jsh_material m
        left JOIN jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1'
        left join jsh_material_current_stock mcs on m.id = mcs.material_id and ifnull(mcs.delete_flag,'0') !='1'
        <if test="depotList.size()>0">
            and mcs.depot_id in
            <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        left JOIN jsh_unit u on m.unit_id = u.id and ifnull(u.delete_Flag,'0') !='1'
        left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
        where 1=1
        and me.default_flag=1
        <if test="idList.size()>0">
            and m.category_id in
            <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="position != null and position !=''">
            <bind name="bindPosition" value="'%'+position+'%'"/>
            and m.position like #{bindPosition}
        </if>
        <if test="materialParam != null">
            <bind name="bindKey" value="'%'+materialParam+'%'"/>
            and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
            or m.color like #{bindKey} or m.mfrs like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
            or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
        </if>
        and ifnull(m.delete_flag,'0') !='1'
        group by m.id
        <if test="zeroStock == 0">
            having currentStock!=0
        </if>
        <if test="column == 'createTime'">
            order by m.id desc
        </if>
        <if test="column != 'createTime'">
            order by ${column} ${order}
        </if>
        <if test="offset != null and rows != null">
            limit #{offset},#{rows}
        </if>
    </select>
 
    <select id="getListWithStockCount" resultType="java.lang.Integer">
        select count(tb.id) from
        (select m.id, ifnull(sum(mcs.current_number),0) currentStock from jsh_material m
        left JOIN jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1'
        left join jsh_material_current_stock mcs on m.id = mcs.material_id and ifnull(mcs.delete_flag,'0') !='1'
        <if test="depotList.size()>0">
            and mcs.depot_id in
            <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        left JOIN jsh_unit u on m.unit_id = u.id and ifnull(u.delete_Flag,'0') !='1'
        left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
        where 1=1
        and me.default_flag=1
        <if test="idList.size()>0">
            and m.category_id in
            <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="position != null and position !=''">
            <bind name="bindPosition" value="'%'+position+'%'"/>
            and m.position like #{bindPosition}
        </if>
        <if test="materialParam != null">
            <bind name="bindKey" value="'%'+materialParam+'%'"/>
            and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
            or m.color like #{bindKey} or m.mfrs like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
            or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
        </if>
        and ifnull(m.delete_flag,'0') !='1'
        group by m.id
        <if test="zeroStock == 0">
            having currentStock!=0
        </if>
        ) tb
    </select>
 
    <select id="getTotalStockAndPrice" resultType="com.jsh.erp.datasource.entities.MaterialVo4Unit">
        select
        ifnull(sum(mcs.current_number),0) currentStock,
        sum(ifnull(me.purchase_decimal,0)*ifnull(mcs.current_number,0)) currentStockPrice,
        sum(ifnull(mcs.current_unit_price,0)*ifnull(mcs.current_number,0)) currentStockMovePrice,
        sum(ifnull(m.weight,0)*ifnull(mcs.current_number,0)) currentWeight
        from jsh_material m
        left JOIN jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1'
        left join jsh_material_current_stock mcs on m.id = mcs.material_id and ifnull(mcs.delete_flag,'0') !='1'
        left JOIN jsh_unit u on m.unit_id = u.id and ifnull(u.delete_Flag,'0') !='1'
        left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
        where 1=1
        and me.default_flag=1
        <if test="depotList.size()>0">
            and mcs.depot_id in
            <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="idList.size()>0">
            and m.category_id in
            <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="position != null and position !=''">
            <bind name="bindPosition" value="'%'+position+'%'"/>
            and m.position like #{bindPosition}
        </if>
        <if test="materialParam != null">
            <bind name="bindKey" value="'%'+materialParam+'%'"/>
            and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
            or m.color like #{bindKey} or m.mfrs like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
            or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
        </if>
        and ifnull(m.delete_flag,'0') !='1'
    </select>
 
    <select id="checkIsExist" resultType="java.lang.Integer">
        select count(1) from jsh_material m
        where ifnull(m.delete_flag,'0') !='1'
        <if test="name != null">
            and m.name = #{name}
        </if>
        <if test="model != null">
            and m.model = #{model}
        </if>
        <if test="color != null">
            and m.color = #{color}
        </if>
        <if test="standard != null">
            and m.standard = #{standard}
        </if>
        <if test="mfrs != null">
            and m.mfrs = #{mfrs}
        </if>
        <if test="otherField1 != null">
            and m.other_field1 = #{otherField1}
        </if>
        <if test="otherField2 != null">
            and m.other_field2 = #{otherField2}
        </if>
        <if test="otherField3 != null">
            and m.other_field3 = #{otherField3}
        </if>
        <if test="unit != null">
            and m.unit = #{unit}
        </if>
        <if test="unitId != null">
            and m.unit_id = #{unitId}
        </if>
        <if test="id != null">
            and m.id != #{id}
        </if>
    </select>
 
    <select id="getMaterialExtendBySerialNumber" resultType="com.jsh.erp.datasource.entities.MaterialExtend">
        select me.bar_code
        from jsh_material m
        left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_flag,'0') !='1'
        left join jsh_serial_number sn on sn.material_id=m.id and ifnull(sn.delete_flag,'0') !='1'
        where sn.serial_number = #{serialNumber}
        and me.default_flag=1
        and ifnull(m.delete_flag,'0') !='1'
        limit 0,1
    </select>
</mapper>