xiaoyong931011
2021-04-12 a13a93a493e7e94e28b2225c26e7e13b52d3288c
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
<?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.matrix.system.hive.dao.SysStoreInfoDao">
 
    <resultMap type="SysStoreInfo" id="SysStoreInfoMap">
        <id property="id" column="ID" />
        <result property="storeId" column="STORE_ID" />
        <result property="skuId" column="SKU_ID" />
        <result property="storeTotal" column="STORE_TOTAL" />
        <result property="goodsPrice" column="GOODS_PRICE" />
        <result property="batch" column="batch" />
        <result property="time" column="time" />
        <result property="shopId" column="shop_id"/>
        <result property="companyId" column="company_id"/>
 
 
 
        <!-- 扩展属性 -->
        <result property="storeName" column="STORE_NAME" />
        <result property="batchCount" column="batchCount" />
        <association property="goods"   resultMap="com.matrix.system.hive.dao.ShoppingGoodsDao.ShoppingGoodsMap" columnPrefix="gs_" />
 
    </resultMap>
    <resultMap type="SysStoreInfo" id="SysStoreInfoMapSimple">
        <id property="id" column="ID" />
        <result property="storeId" column="STORE_ID" />
        <result property="skuId" column="SKU_ID" />
        <result property="storeTotal" column="STORE_TOTAL" />
        <result property="goodsPrice" column="GOODS_PRICE" />
    </resultMap>
 
    <!--  插入方法   -->
    <insert id="insert" parameterType="SysStoreInfo"
            useGeneratedKeys="true" keyProperty="id">
        INSERT INTO sys_store_info (
            STORE_ID,
            SKU_ID,
            STORE_TOTAL,
            GOODS_PRICE,
            batch,
            time,
            shop_id,
            company_id
        )
    VALUES (
            #{storeId},
            #{skuId},
            #{storeTotal},
            #{goodsPrice},
            #{batch},
            #{time},
            #{shopId},
            #{companyId}
    )
    </insert>
 
    <!--  批量插入   -->
    <insert id="batchInsert" parameterType="java.util.List">
        INSERT INTO sys_store_info (
        STORE_ID,
        SKU_ID,
        STORE_TOTAL,
        GOODS_PRICE,
        batch,
        time,
        shop_id,
        company_id
        )
        VALUES
        <foreach collection="list" item="item" index="index" separator=",">(
            #{item.storeId},
            #{item.skuId},
            #{item.storeTotal},
            #{item.goodsPrice},
            #{item.batch},
            #{item.time},
            #{item.shopId},
            #{item.companyId}
            )</foreach>
    </insert>
 
 
 
 
    <update id="updateGoodsCk" >
        UPDATE sys_store_info
        <set>
            STORE_TOTAL =STORE_TOTAL - #{count}
        </set>
        where ID=#{id} and SKU_ID=#{skuId}
    </update>
 
 
    <!--  根据id更新 部分更新   -->
    <update id="update" >
        UPDATE sys_store_info
        <set>
            <if test="storeId != null and storeId !='' ">
                STORE_ID = #{storeId},
            </if>
            <if test="skuId != null and skuId !='' ">
                SKU_ID = #{skuId},
            </if>
            <if test="storeTotal != null ">
                STORE_TOTAL = #{storeTotal},
            </if>
            <if test="goodsPrice != null and goodsPrice !='' ">
                GOODS_PRICE = #{goodsPrice},
            </if>
            <if test="time != null">
                time = #{time},
            </if>
            <if test="batch != null and batch !='' ">
                batch = #{batch},
            </if>
        </set>
        WHERE ID=#{id}
    </update>
 
    <!-- 根据skuid 和仓库id 查询-->
    <select id="selectStoInfo" resultMap="SysStoreInfoMap">
        select
            ID,
            STORE_ID,
            SKU_ID,
            STORE_TOTAL,
            batch,
            time,
            GOODS_PRICE,
            shop_id,
            company_id
        from
            sys_store_info
        where
            batch=#{batch} and  STORE_ID=#{storeId}
 
    </select>
 
    <select id="selectStoInfoBySku" resultMap="SysStoreInfoMap">
        select
            ID,
            STORE_ID,
            SKU_ID,
            STORE_TOTAL,
            batch,
            time,
            GOODS_PRICE,
            shop_id,
            company_id
        from
            sys_store_info
        where
            sku_id=#{skuId} and  STORE_ID=#{storeId} and STORE_TOTAL>0
            order by time desc
 
    </select>
    <select id="selectByStoreId" resultMap="SysStoreInfoMap">
        select
            ID,
            STORE_ID,
            SKU_ID,
            STORE_TOTAL,
            batch,
            time,
            GOODS_PRICE,
            shop_id,
            company_id
        from
            sys_store_info
        where     STORE_ID=#{storeId}   and STORE_TOTAL>0
            order by time desc
    </select>
 
 
 
 
 
    <!-- 根据skuid 和仓库id 查询-->
    <select id="selectStoInfoSimple" resultMap="SysStoreInfoMapSimple">
        select
            ID,
            STORE_ID,
            SKU_ID,
            STORE_TOTAL,
            batch,
            time,
            GOODS_PRICE,
            shop_id,
            company_id
        from
            sys_store_info
        where
            SKU_ID=#{skuId} and  STORE_ID=#{storeId}
        order by time desc;
 
    </select>
 
 
    <select id="countDetail"   resultType="java.lang.Integer" >
        select count(*) from sys_store_info where  SKU_ID = #{skuId}
    </select>
 
 
    <!-- 分页查询 -->
    <select id="selectInPage" resultMap="SysStoreInfoMap">
        select
        a.ID,
        a.STORE_ID,
        (select name from warehouse t where t.id = STORE_ID) STORE_NAME,
        a.SKU_ID,
        a.STORE_TOTAL,
        a.GOODS_PRICE,
        a.batch,
        a.time,
        c.id as gs_id,
        c.code as gs_code,
        c.NAME as gs_NAME,
        c.UNIT as gs_UNIT,
        c.good_type as gs_good_type,
        c.GOODS_SORT_ID as gs_GOODS_SORT_ID,
        c.SUPPLIER_ID as gs_SUPPLIER_ID,
        (select TYPE_NAME from sys_goods_type t where t.id=c.GOODS_SORT_ID) gs_goodsSortName,
 
        c.alarm_num as gs_alarm_num,
        c.volume as gs_volume,
        c.price as gs_price,
        c.wholesale as gs_wholesale,
        a.shop_id,
        a.company_id
        from
        sys_store_info a
        left join  shopping_goods c
        on a.SKU_ID=c.ID
        left join warehouse d
        on a.STORE_ID=d.ID
        where
        a.STORE_TOTAL>0
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and ID = #{record.id}
            </if>
            <if test="record.batch != null and record.batch !='' ">
                and batch = #{record.batch}
            </if>
            <if test="record.storeId != null and record.storeId !='' ">
                and STORE_ID = #{record.storeId}
            </if>
 
            <if test="record.storeTotal != null and record.storeTotal !='' ">
                and STORE_TOTAL = #{record.storeTotal}
            </if>
            <if test="record.goods != null and record.goods.name!=null  and record.goods.name!=''">
                and  c.NAME like concat('%',#{record.goods.name},'%')
            </if>
            <if test="record.goods != null and record.goods.goodsSortId!=null and record.goods.goodsSortId !='' ">
                and c.GOODS_SORT_ID=#{record.goods.goodsSortId}
            </if>
<!--            <if test="record.goods != null and record.goods.goodsAttr!=null and record.goods.goodsAttr !='' ">-->
<!--                and c.GOODS_ATTR like concat('%', #{record.goods.goodsAttr} ,'%')-->
<!--            </if>-->
 
            <if test="record.goods != null and record.goods.goodsNo!=null and record.goods.goodsNo !='' ">
                and c.GOODS_NO like concat('%',#{record.goods.goodsNo},'%')
            </if>
 
            <if test="record.storeName != null and record.storeName !='' ">
                and d.name like concat('%',#{record.storeName},'%')
            </if>
            <if test="record.shopId != null and record.shopId !='' ">
                and a.shop_id=#{record.shopId}
            </if>
            <if test="record.companyId != null and record.companyId !='' ">
                and a.company_id=#{record.companyId}
            </if>
 
            <!-- 库存预警 -->
            <if test="record.isAlarm!= null and record.isAlarm !='' ">
                <if test="record.isAlarm==1">
                    and a.STORE_TOTAL &lt;= c.ALARM_NUM
                </if>
                <if test="record.isAlarm==2">
                    and a.STORE_TOTAL &gt; c.ALARM_NUM
                </if>
            </if>
 
        </if>
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            <if test="pageVo.sort !=null  and pageVo.order !=null">
                order by
                ${pageVo.sort} ${pageVo.order}
            </if>
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
    </select>
 
    <!-- 查询总条 -->
    <select id="selectTotalRecord" parameterType="SysStoreInfo"   resultType="java.lang.Integer">
        select
        count(*)
        from
        sys_store_info a
        left join  shopping_goods c
        on a.SKU_ID=c.ID
        left join warehouse d
        on a.STORE_ID=d.ID
        where
        a.STORE_TOTAL>0
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and ID = #{record.id}
            </if>
            <if test="record.batch != null and record.batch !='' ">
                and batch = #{record.batch}
            </if>
            <if test="record.storeId != null and record.storeId !='' ">
                and STORE_ID = #{record.storeId}
            </if>
 
            <if test="record.storeTotal != null and record.storeTotal !='' ">
                and STORE_TOTAL = #{record.storeTotal}
            </if>
            <if test="record.goods != null and record.goods.name!=null  and record.goods.name!=''">
                and  c.NAME like concat('%',#{record.goods.name},'%')
            </if>
            <if test="record.goods != null and record.goods.goodsSortId!=null and record.goods.goodsSortId !='' ">
                and c.GOODS_SORT_ID=#{record.goods.goodsSortId}
            </if>
<!--            <if test="record.goods != null and record.goods.goodsAttr!=null and record.goods.goodsAttr !='' ">-->
<!--                and c.GOODS_ATTR like concat('%', #{record.goods.goodsAttr} ,'%')-->
<!--            </if>-->
 
            <if test="record.goods  != null and record.goods.goodsNo!=null and record.goods.goodsNo !='' ">
                and c.GOODS_NO like concat('%',#{record.goods.goodsNo},'%')
            </if>
 
            <if test="record.storeName != null and record.storeName !='' ">
                and d.name like concat('%',#{record.storeName},'%')
            </if>
            <if test="record.shopId != null and record.shopId !='' ">
                and a.shop_id=#{record.shopId}
            </if>
            <if test="record.companyId != null and record.companyId !='' ">
                and a.company_id=#{record.companyId}
            </if>
 
            <!-- 库存预警 -->
            <if test="record.isAlarm!= null and record.isAlarm !='' ">
                <if test="record.isAlarm==1">
                    and a.STORE_TOTAL &lt;= c.ALARM_NUM
                </if>
                <if test="record.isAlarm==2">
                    and a.STORE_TOTAL &gt; c.ALARM_NUM
                </if>
            </if>
 
        </if>
    </select>
 
 
 
    <!-- 汇总查库存  -->
    <!-- 分页查询 -->
    <select id="selectCountInPage" resultMap="SysStoreInfoMap">
        select
        a.ID,
        a.STORE_ID,
        (select name from warehouse t where t.id = STORE_ID) STORE_NAME,
        a.SKU_ID,
        ROUND(SUM(a.STORE_TOTAL) ,2)as STORE_TOTAL,
        count(a.ID) as batchCount,
        AVG(a.GOODS_PRICE) as GOODS_PRICE,
        a.time,
        c.id as gs_id,
        c.code as gs_code,
        c.NAME as gs_NAME,
        c.UNIT as gs_UNIT,
        c.good_type as gs_good_type,
        c.GOODS_SORT_ID as gs_GOODS_SORT_ID,
        c.SUPPLIER_ID as gs_SUPPLIER_ID,
        (select TYPE_NAME from sys_goods_type t where t.id=c.GOODS_SORT_ID) gs_goodsSortName,
 
        c.alarm_num as gs_alarm_num,
        c.volume as gs_volume,
        c.price as gs_price,
        c.wholesale as gs_wholesale,
        c.img as gs_img,
        a.shop_id,
        a.company_id
        from
        sys_store_info a
        left join  shopping_goods c
        on a.SKU_ID=c.ID
        left join warehouse d
        on a.STORE_ID=d.ID
        where
        a.STORE_TOTAL>0
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and ID = #{record.id}
            </if>
            <if test="record.batch != null and record.batch !='' ">
                and batch = #{record.batch}
            </if>
 
            <if test="record.queryKey != null and record.queryKey !='' ">
                and (instr(c.name,#{record.queryKey}) or instr(c.goods_no, #{record.queryKey}) or instr(c.zjm, #{record.queryKey}))
            </if>
            <if test="record.storeId != null and record.storeId !='' ">
                and STORE_ID = #{record.storeId}
            </if>
 
            <if test="record.storeTotal != null and record.storeTotal !='' ">
                and STORE_TOTAL = #{record.storeTotal}
            </if>
            <if test="record.goods != null and record.goods.name!=null and record.goods.name!='' ">
                and  c.NAME like concat('%',#{record.goods.name},'%')
            </if>
            <if test="record.goods != null and record.goods.goodsSortId!=null and record.goods.goodsSortId !='' ">
                and c.GOODS_SORT_ID=#{record.goods.goodsSortId}
            </if>
<!--            <if test="record.goods != null and record.goods.goodsAttr!=null and record.goods.goodsAttr !='' ">-->
<!--                and c.GOODS_ATTR like concat('%', #{record.goods.goodsAttr} ,'%')-->
<!--            </if>-->
 
            <if test="record.goods != null and record.goods.goodsNo!=null and record.goods.goodsNo !='' ">
                and c.GOODS_NO like concat('%',#{record.goods.goodsNo},'%')
            </if>
 
            <if test="record.storeName != null and record.storeName !='' ">
                and d.name like concat('%',#{record.storeName},'%')
            </if>
            <if test="record.shopId != null and record.shopId !='' ">
                and a.shop_id=#{record.shopId}
            </if>
            <if test="record.companyId != null and record.companyId !='' ">
                and a.company_id=#{record.companyId}
            </if>
 
            <!-- 库存预警 -->
            <if test="record.isAlarm!= null and record.isAlarm !='' ">
                <if test="record.isAlarm==1">
                    and a.STORE_TOTAL &lt;= c.ALARM_NUM
                </if>
                <if test="record.isAlarm==2">
                    and a.STORE_TOTAL &gt; c.ALARM_NUM
                </if>
            </if>
 
        </if>
        group by a.SKU_ID,a.shop_id
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
 
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
 
    </select>
 
    <!-- 查询总条 -->
    <select id="selectCountTotalRecord" parameterType="SysStoreInfo"   resultType="java.lang.Integer">
    select count(1) from (
        select
        a.STORE_ID
        from
        sys_store_info a
        left join  shopping_goods c
        on a.SKU_ID=c.ID
        left join warehouse d
        on a.STORE_ID=d.ID
        where
        a.STORE_TOTAL>0
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and ID = #{record.id}
            </if>
            <if test="record.batch != null and record.batch !='' ">
                and batch = #{record.batch}
            </if>
            <if test="record.queryKey != null and record.queryKey !='' ">
                and (instr(c.name,#{record.queryKey}) or instr(c.goods_no, #{record.queryKey}) or instr(c.zjm, #{record.queryKey}))
            </if>
            <if test="record.storeId != null and record.storeId !='' ">
                and STORE_ID = #{record.storeId}
            </if>
 
            <if test="record.storeTotal != null and record.storeTotal !='' ">
                and STORE_TOTAL = #{record.storeTotal}
            </if>
            <if test="record.goods != null and record.goods.name!=null    and record.goods.name!=''">
                and  c.NAME like concat('%',#{record.goods.name},'%')
            </if>
            <if test="record.goods != null and record.goods.goodsSortId!=null and record.goods.goodsSortId !='' ">
                and c.GOODS_SORT_ID=#{record.goods.goodsSortId}
            </if>
<!--            <if test="record.goods != null and record.goods.goodsAttr!=null and record.goods.goodsAttr !='' ">-->
<!--                and c.GOODS_ATTR like concat('%', #{record.goods.goodsAttr} ,'%')-->
<!--            </if>-->
 
            <if test="record.goods  != null and record.goods.goodsNo!=null and record.goods.goodsNo !='' ">
                and c.GOODS_NO like concat('%',#{record.goods.goodsNo},'%')
            </if>
 
            <if test="record.storeName != null and record.storeName !='' ">
                and d.name like concat('%',#{record.storeName},'%')
            </if>
            <if test="record.shopId != null and record.shopId !='' ">
                and a.shop_id=#{record.shopId}
            </if>
            <if test="record.companyId != null and record.companyId !='' ">
                and a.company_id=#{record.companyId}
            </if>
 
            <!-- 库存预警 -->
            <if test="record.isAlarm!= null and record.isAlarm !='' ">
                <if test="record.isAlarm==1">
                    and a.STORE_TOTAL &lt;= c.ALARM_NUM
                </if>
                <if test="record.isAlarm==2">
                    and a.STORE_TOTAL &gt; c.ALARM_NUM
                </if>
            </if>
 
        </if>
        group by a.SKU_ID,a.shop_id) f
    </select>
    <!--汇总查询结束 -->
 
 
    <!-- 根据id查询-->
    <select id="selectById" resultMap="SysStoreInfoMap">
        select
            ID,
            STORE_ID,
            (select name from warehouse t where t.id = STORE_ID) STORE_NAME,
            SKU_ID,
            STORE_TOTAL,
            GOODS_PRICE,
            batch,
            time,
            shop_id,
            company_id
        from
            sys_store_info
        where
            id=#{id}
 
    </select>
 
 
    <!-- 根据对象查询-->
    <select id="selectByModel" resultMap="SysStoreInfoMap">
        select
        ID,
        STORE_ID,
        (select name from warehouse t where t.id = STORE_ID) STORE_NAME,
        SKU_ID,
        STORE_TOTAL,
        GOODS_PRICE,
        batch,
        time
        batch,
        time,
        a.shop_id,
        a.company_id,
        c.id as gs_id,
        c.code as gs_code,
        c.NAME as gs_NAME,
        c.UNIT as gs_UNIT,
        c.good_type as gs_good_type,
        c.GOODS_SORT_ID as gs_GOODS_SORT_ID,
        c.SUPPLIER_ID as gs_SUPPLIER_ID,
        (select TYPE_NAME from sys_goods_type t where t.id=c.GOODS_SORT_ID) gs_goodsSortName,
 
        c.alarm_num as gs_alarm_num,
        c.volume as gs_volume,
        c.price as gs_price,
        c.wholesale as gs_wholesale
        from
        sys_store_info a
        left join  shopping_goods c
        on a.SKU_ID=c.ID
        left join warehouse d
        on a.STORE_ID=d.ID
        where
        1=1
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and ID = #{record.id}
            </if>
            <if test="record.storeId != null and record.storeId !='' ">
                and STORE_ID = #{record.storeId}
            </if>
            <if test="record.batch != null and record.batch !='' ">
                and batch = #{record.batch}
            </if>
 
            <if test="record.storeTotal != null and record.storeTotal !='' ">
                and STORE_TOTAL = #{record.storeTotal}
            </if>
            <if test="record.goods != null and record.goods.name!=null  and record.goods.name!=''">
                and  c.NAME like concat('%',#{record.goods.name},'%')
            </if>
            <if test="record.goods != null and record.goods.goodsSortId!=null and record.goods.goodsSortId !='' ">
                and c.GOODS_SORT_ID=#{record.goods.goodsSortId}
            </if>
<!--            <if test="record.goods != null and record.goods.goodsAttr!=null and record.goods.goodsAttr !='' ">-->
<!--                and c.GOODS_ATTR like concat('%', #{record.goods.goodsAttr} ,'%')-->
<!--            </if>-->
 
            <if test="record.goods!= null  and record.goods.goodsNo!=null and record.goods.goodsNo !='' ">
                and c.GOODS_NO like concat('%',#{record.goods.goodsNo},'%')
            </if>
 
            <if test="record.storeName != null and record.storeName !='' ">
                and d.name like concat('%',#{record.storeName},'%')
            </if>
 
            <!-- 库存预警 -->
            <if test="record.isAlarm!= null and record.isAlarm !='' ">
                <if test="record.isAlarm==1">
                    and a.STORE_TOTAL &lt;= c.ALARM_NUM
                </if>
                <if test="record.isAlarm==2">
                    and a.STORE_TOTAL &gt; c.ALARM_NUM
                </if>
            </if>
 
        </if>
    </select>
 
    <!-- 查询库存中是否有这个商品 -->
    <select id="getStoreByGoodsId" resultMap="SysStoreInfoMap">
 
        select
            ID,
            STORE_ID,
            (select name from warehouse t where t.id = STORE_ID) STORE_NAME,
            SKU_ID,
            STORE_TOTAL,
            GOODS_PRICE,
            batch,
            time,
            shop_id,
            company_id
        from   
            sys_store_info
        where 
            SKU_ID = #{skuId}
        and
            STORE_ID = #{storeId}
    </select>
 
    <!-- 查询商品出入库明细 -->
    <select id="findStoreInOutRecord" resultType="com.matrix.system.hive.pojo.StoreInOutRecordVO">
 
SELECT
    *
FROM
    (
    SELECT
        b.id id,
        b.create_time as createTime,
        e.CODE,
        e.NAME,
        f.TYPE_NAME AS typeName,
        (0-a.AMOUNT) as AMOUNT,
        g.GOODS_PRICE as goodsPrice,
        (0-a.AMOUNT * g.GOODS_PRICE ) AS totalPrice,
        g.batch,
        b.out_store_no AS orderNo,
        b.remark,
        b.TYPE AS orderType ,
        c.su_name as userName,
        d.SHOP_NAME as shopName
    FROM
        sys_out_store_item a
        LEFT JOIN sys_out_store b ON a.OUT_STORE_ID = b.id
        LEFT JOIN sys_users c ON b.STAFF_ID = c.su_id
        LEFT JOIN sys_shop_info d ON b.SHOP_ID = d.id
        LEFT JOIN shopping_goods e ON a.SKU_ID = e.id
        LEFT JOIN sys_goods_type f ON e.GOODS_SORT_ID = f.id
        LEFT JOIN sys_store_info g ON a.store_id = g.id
        <where>
            <if test="record.shopId!=null and record.shopId!='' ">
                and d.id  = #{record.shopId}
            </if>
            <if test="record.goodsSortId!=null and record.goodsSortId!='' ">
                and f.id  = #{record.goodsSortId}
            </if>
            <if test="record.userName!=null and record.userName!='' ">
                and instr( c.su_name, #{record.userName})
            </if>
            <if test="record.name!=null and record.name!='' ">
                and (instr( e.NAME, #{record.name}) or instr( e.code, #{record.name}))
            </if>
            <if test="record.orderType!=null and record.orderType!='' ">
                and b.TYPE =  #{record.orderType}
            </if>
            <if test=" record.beginTime!=null  ">
                <![CDATA[ and #{record.beginTime}  <=  b.create_time]]>
            </if>
            <if test=" record.endTime!=null   ">
                <![CDATA[     and #{record.endTime} >=b.create_time]]>
            </if>
            <if test="record.companyId != null and record.companyId !='' ">
                and    b.company_id = #{record.companyId}
            </if>
 
        </where>
 
    UNION ALL
    SELECT
        t2_b.id id,
        t2_b.create_time,
        t2_e.CODE,
        t2_e.NAME,
        t2_f.TYPE_NAME AS typeName,
        t2_a.AMOUNT,
        t2_g.GOODS_PRICE,
        ( t2_a.AMOUNT * t2_g.GOODS_PRICE ) AS total_price,
        t2_g.batch,
        t2_b.instore_id,
        t2_b.remark,
        t2_b.instore_type,
        t2_c.su_name,
        t2_d.SHOP_NAME
    FROM
        sys_instore_detail t2_a
        LEFT JOIN sys_instore_info t2_b ON t2_a.INSTORE_ID = t2_b.id
        LEFT JOIN sys_users t2_c ON t2_b.MAKING_MAN_ID = t2_c.su_id
        LEFT JOIN sys_shop_info t2_d ON t2_b.SHOP_ID = t2_d.id
        LEFT JOIN shopping_goods t2_e ON t2_a.SKU_ID = t2_e.id
        LEFT JOIN sys_goods_type t2_f ON t2_e.GOODS_SORT_ID = t2_f.id
        LEFT JOIN sys_store_info t2_g ON t2_a.SKU_ID = t2_g.SKU_ID
        AND t2_a.batch = t2_g.batch
        <where>
            <if test="record.shopId!=null and record.shopId!='' ">
                and t2_d.id  = #{record.shopId}
            </if>
            <if test="record.goodsSortId!=null and record.goodsSortId!='' ">
                and t2_f.id  = #{record.goodsSortId}
            </if>
            <if test="record.userName!=null and record.userName!='' ">
                and instr( t2_c.su_name, #{record.userName})
            </if>
            <if test="record.name!=null and record.name!='' ">
                and (instr( t2_e.NAME, #{record.name}) or instr( t2_e.code, #{record.name}))
            </if>
            <if test="record.orderType!=null and record.orderType!='' ">
                and t2_b.instore_type =  #{record.orderType}
            </if>
            <if test=" record.beginTime!=null   ">
                <![CDATA[ and #{record.beginTime}  <=   t2_b.create_time ]]>
            </if>
            <if test=" record.endTime!=null  ">
                <![CDATA[     and #{record.endTime} >= t2_b.create_time  ]]>
            </if>
            <if test="record.companyId != null and record.companyId !='' ">
                and    t2_b.company_id = #{record.companyId}
            </if>
        </where>
 
 
 
    ) t
    order by    createTime desc
    <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
 
        <if test="pageVo.offset >=0  and pageVo.limit >0">
            limit
            #{pageVo.offset},#{pageVo.limit}
        </if>
    </if>
 
 
 
    </select>
 
    <!-- 统计数量 -->
    <select id="findStoreInOutTotal" resultType="java.lang.Integer">
 
        SELECT
        count(*)
        FROM
        (
        SELECT a.id
        FROM
        sys_out_store_item a
        LEFT JOIN sys_out_store b ON a.OUT_STORE_ID = b.id
        LEFT JOIN sys_users c ON b.STAFF_ID = c.su_id
        LEFT JOIN sys_shop_info d ON b.SHOP_ID = d.id
        LEFT JOIN shopping_goods e ON a.SKU_ID = e.id
        LEFT JOIN sys_goods_type f ON e.GOODS_SORT_ID = f.id
        LEFT JOIN sys_store_info g ON a.store_id = g.id
        <where>
            <if test="record.shopId!=null and record.shopId!='' ">
                and d.id  = #{record.shopId}
            </if>
            <if test="record.goodsSortId!=null and record.goodsSortId!='' ">
                and f.id  = #{record.goodsSortId}
            </if>
            <if test="record.userName!=null and record.userName!='' ">
                and instr( c.su_name, #{record.userName})
            </if>
            <if test="record.name!=null and record.name!='' ">
                and (instr( e.NAME, #{record.name}) or instr( e.code, #{record.name}))
            </if>
            <if test="record.orderType!=null and record.orderType!='' ">
                and b.TYPE =  #{record.orderType}
            </if>
            <if test=" record.beginTime!=null  ">
                <![CDATA[ and #{record.beginTime}  <=  b.create_time]]>
            </if>
            <if test=" record.endTime!=null  ">
                <![CDATA[     and #{record.endTime} >=b.create_time]]>
            </if>
            <if test="record.companyId != null and record.companyId !='' ">
                and    b.company_id = #{record.companyId}
            </if>
        </where>
        UNION ALL
        SELECT
        t2_a.id
        FROM
        sys_instore_detail t2_a
        LEFT JOIN sys_instore_info t2_b ON t2_a.INSTORE_ID = t2_b.id
        LEFT JOIN sys_users t2_c ON t2_b.MAKING_MAN_ID = t2_c.su_id
        LEFT JOIN sys_shop_info t2_d ON t2_b.SHOP_ID = t2_d.id
        LEFT JOIN shopping_goods t2_e ON t2_a.SKU_ID = t2_e.id
        LEFT JOIN sys_goods_type t2_f ON t2_e.GOODS_SORT_ID = t2_f.id
        LEFT JOIN sys_store_info t2_g ON t2_a.SKU_ID = t2_g.SKU_ID
        AND t2_a.batch = t2_g.batch
        <where>
            <if test="record.shopId!=null and record.shopId!='' ">
                and t2_d.id  = #{record.shopId}
            </if>
            <if test="record.goodsSortId!=null and record.goodsSortId!='' ">
                and t2_f.id  = #{record.goodsSortId}
            </if>
            <if test="record.userName!=null and record.userName!='' ">
                and instr( t2_c.su_name, #{record.userName})
            </if>
            <if test="record.name!=null and record.name!='' ">
                and (instr( t2_e.NAME, #{record.name}) or instr( t2_e.code, #{record.name}))
            </if>
            <if test="record.orderType!=null and record.orderType!='' ">
                and t2_b.instore_type =  #{record.orderType}
            </if>
            <if test=" record.beginTime!=null  ">
                <![CDATA[ and #{record.beginTime}  <=   t2_b.create_time ]]>
            </if>
            <if test=" record.endTime!=null   ">
                <![CDATA[     and #{record.endTime} >= t2_b.create_time  ]]>
            </if>
            <if test="record.companyId != null and record.companyId !='' ">
                and    t2_b.company_id = #{record.companyId}
            </if>
        </where>
        ) t
 
 
 
 
    </select>
 
 
 
</mapper>