Helius
2021-04-12 b8d50f6ad9d1ab407e5b2a6867cf47bc4640a43c
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
<?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.SysProjUseDao">
 
    <resultMap type="SysProjUse" id="SysProjUseMap">
 
        <id property="id" column="ID"/>
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
        <result property="orderItemId" column="ORDER_ITEM_ID"/>
        <result property="projId" column="PROJ_ID"/>
        <result property="surplusCount" column="SURPLUS_COUNT"/>
        <result property="isOver" column="IS_OVER"/>
        <result property="taocanId" column="TAOCAN_ID"/>
        <result property="vipId" column="VIP_ID"/>
        <result property="failTime" column="FAIL_TIME"/>
        <result property="assembleId" column="ASSEMBLE_ID"/>
        <result property="source" column="SOURCE"/>
        <result property="status" column="STATUS"/>
        <result property="platformFlag" column="PLATFORM_FLAG"/>
        <result property="type" column="type"/>
        <result property="balance" column="balance"/>
        <result property="remark" column="remark"/>
        <result property="price" column="price"/>
        <result property="tcName" column="tcName"/>
        <result property="projName" column="proj_name"/>
        <result property="deductionNum" column="deductionNum"/>
        <result property="isCourse" column="is_course"/>
        <result property="timeLength" column="time_length"/>
        <result property="orderId" column="orderId"/>
        <!-- 对应项目信息-->
        <association property="projInfo" javaType="ShoppingGoods"
                     resultMap="com.matrix.system.hive.dao.ShoppingGoodsDao.ShoppingGoodsMap"/>
 
    </resultMap>
 
    <!-- 余次使用记录map -->
    <resultMap type="com.matrix.system.hive.bean.SysProjUseFlow" id="SysProjUseFlowMap">
        <id property="id" column="id"/>
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
        <result property="projUseId" column="proj_use_id"/>
        <result property="surplusCount" column="surplus_count"/>
        <result property="isOver" column="is_over"/>
        <result property="failTime" column="fail_time"/>
        <result property="price" column="price"/>
        <result property="status" column="status"/>
        <result property="balance" column="balance"/>
        <result property="remark" column="remark"/>
        <result property="projName" column="proj_name"/>
        <result property="optionType" column="option_type"/>
    </resultMap>
 
    <!-- 插入流水 -->
    <insert id="insertFlow" parameterType="SysProjUse" useGeneratedKeys="true"
            keyProperty="id">
        INSERT INTO sys_proj_use_flow (
        create_by,
        create_time,
        update_by,
        update_time,
        id,
        proj_use_id,
        surplus_count,
        is_over,
        fail_time,
        price,
        status,
        balance,
        remark,
        proj_name,
        option_type
        )
        VALUES (
        #{createBy},
        now(),
        #{updateBy},
        now(),
        #{id},
        #{projUseId},
        #{surplusCount},
        #{isOver},
        #{failTime},
        #{price},
        #{status},
        #{balance},
        #{remark},
        #{projName},
        #{optionType}
        )
    </insert>
 
    <!-- 查询流水 -->
    <select id="selectProjUseFlow" resultMap="SysProjUseFlowMap">
        select * from sys_proj_use_flow
        <where>
                and proj_use_id=#{record.projUseId}
            <if test="record.createBy !=null and record.createBy!='' ">
                and instr(createBy,#{record.createBy})
            </if>
            <if test="record.beginTime !=null and record.beginTime!=''">
                and create_time >= #{record.beginTime}
            </if>
            <if test="record.endTime !=null and record.endTime!=''">
                <![CDATA[ and create_time <=  #{record.endTime} ]]>
            </if>
 
        </where>
        <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="selectProjUseFlowTotal" resultType="java.lang.Integer">
        select count(*) from sys_proj_use_flow
        <where>
            and proj_use_id=#{record.projUseId}
            <if test="record.createBy !=null and record.createBy!='' ">
                and instr(createBy,#{record.createBy})
            </if>
            <if test="record.beginTime !=null and record.beginTime!=''">
                and create_time >= #{record.beginTime}
            </if>
            <if test="record.endTime !=null and record.endTime!=''">
                <![CDATA[ and create_time <=  #{record.endTime} ]]>
            </if>
 
        </where>
    </select>
 
    <!-- 插入方法 -->
    <insert id="insert" parameterType="SysProjUse" useGeneratedKeys="true"
            keyProperty="id">
        INSERT INTO sys_proj_use (
        ID,
        ORDER_ITEM_ID,
        PROJ_ID,
        SURPLUS_COUNT,
        IS_OVER,
        VIP_ID,
        TAOCAN_ID,
        FAIL_TIME,
        ASSEMBLE_ID,
        SOURCE,
        STATUS,
        PRICE,
        PLATFORM_FLAG,
        type,
        balance,
        remark,
        proj_name,
        tcName,
        deductionNum,
        is_course
        )
        VALUES (
        #{id},
        #{orderItemId},
        #{projId},
        #{surplusCount},
        #{isOver},
        #{vipId},
        #{taocanId},
        #{failTime},
        #{assembleId},
        #{source},
        #{status},
        #{price},
        #{platformFlag},
        #{type},
        #{balance},
        #{remark},
        #{projName},
        #{tcName},
        #{deductionNum},
        #{isCourse}
        )
    </insert>
 
    <!-- 根据id更新 部分更新 -->
    <update id="update">
        UPDATE sys_proj_use
        <set>
            <if test="orderItemId != null and orderItemId !='' ">
                ORDER_ITEM_ID = #{orderItemId},
            </if>
            <if test="projId != null and projId !='' ">
                PROJ_ID = #{projId},
            </if>
            <if test="(surplusCount != null and surplusCount !='') or  surplusCount == 0 ">
                SURPLUS_COUNT = #{surplusCount},
            </if>
            <if test="isOver != null and isOver !='' ">
                IS_OVER = #{isOver},
            </if>
            <if test="taocanId != null and taocanId !='' ">
                TAOCAN_ID = #{taocanId},
            </if>
            <if test="vipId != null and vipId !='' ">
                VIP_ID = #{vipId},
            </if>
            <if test="failTime != null  ">
                FAIL_TIME = #{failTime},
            </if>
            <if test="price != null and price !='' ">
                PRICE = #{price},
            </if>
            <if test="assembleId != null and assembleId !='' ">
                ASSEMBLE_ID = #{assembleId},
            </if>
            <if test="source != null and source !='' ">
                SOURCE = #{source},
            </if>
            <if test="status != null and status !='' ">
                STATUS = #{status},
            </if>
            <if test="platformFlag != null and platformFlag !='' ">
                PLATFORM_FLAG = #{platformFlag},
            </if>
            <if test="(balance != null and balance !='') or (balance == 0)  ">
                balance = #{balance},
            </if>
            <if test="type != null and type !='' ">
                type = #{type},
            </if>
            <if test="remark != null and remark !='' ">
                remark = #{remark},
            </if>
            <if test="(projName != null and projName !='') or (projName == 0)  ">
                proj_name = #{projName},
            </if>
            <if test="tcName != null and tcName !='' ">
                tcName = #{tcName},
            </if>
            <if test="deductionNum != null and deductionNum !='' ">
                deductionNum = #{deductionNum},
            </if>
            <if test="isCourse != null and isCourse !='' ">
                is_course = #{isCourse},
            </if>
        </set>
        WHERE id=#{id}
    </update>
 
 
    <update id="updateSurplusCount">
        UPDATE sys_proj_use
        <set>
            <if test="surplusCount != null ">
                SURPLUS_COUNT = #{surplusCount},
            </if>
            <if test="isOver != null and isOver !='' ">
                IS_OVER = #{isOver},
            </if>
            <if test="status != null and status !='' ">
                status = #{status},
            </if>
            <if test="balance != null ">
                balance = #{balance},
            </if>
            <if test="remark != null ">
                remark = #{remark},
            </if>
            <if test="projName != null ">
                proj_name = #{projName},
            </if>
            <if test="tcName != null ">
                tcName = #{tcName},
            </if>
            <if test="deductionNum != null ">
                deductionNum = #{deductionNum},
            </if>
            <if test="failTime != null ">
                fail_time = #{failTime},
            </if>
 
        </set>
        WHERE ID = #{id}
 
    </update>
 
 
    <!-- 根据id更新 部分更新 -->
    <update id="updateProjUseCancel">
        UPDATE sys_proj_use
        <set>
            <if test="key != null ">
                SURPLUS_COUNT = SURPLUS_COUNT +1
            </if>
        </set>
        WHERE id=#{key}
    </update>
 
    <!-- 批量删除 -->
    <delete id="deleteByIds" parameterType="java.util.List">
        delete from sys_proj_use where ID in
        <foreach collection="list" index="index" item="item" open="("
                 separator="," close=")">
            #{item}
        </foreach>
    </delete>
 
    <!-- 根据id删除 -->
    <delete id="deleteById">
        DELETE FROM sys_proj_use
        where ID=#{id}
    </delete>
 
 
    <!-- 根据id订单明细id删除 -->
    <delete id="deleteByOrderItemId">
        DELETE FROM sys_proj_use
        where ORDER_ITEM_ID=#{id}
    </delete>
 
 
    <!-- 分页查询 -->
    <select id="selectInPage" resultMap="SysProjUseMap">
        select
        a.*,
        d.id as orderId,
        b.TIME_LENGTH,
        b.img,
        b.code
        from sys_proj_use a
        left join shopping_goods b on a.proj_id=b.id
        left join sys_order_item c on a.ORDER_ITEM_ID=c.id
        left join sys_order d on c.ORDER_ID=d.id
        where 1=1
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and a.ID = #{record.id}
            </if>
            <if test="record.queryKey != null and record.queryKey !='' ">
                and (instr(b.name, #{record.queryKey}) or instr(b.zjm, #{record.queryKey}) or instr(goods_no, #{record.queryKey}))
            </if>
            <if test="record.orderItemId != null and record.orderItemId !='' ">
                and a.ORDER_ITEM_ID = #{record.orderItemId}
            </if>
            <if test="record.projId != null and record.projId !='' ">
                and a.PROJ_ID = #{record.projId}
            </if>
            <if test="record.surplusCount != null and record.surplusCount !='' ">
                and a.SURPLUS_COUNT = #{record.surplusCount}
            </if>
            <if test="record.isOver != null and record.isOver !='' ">
                and a.IS_OVER = #{record.isOver}
            </if>
            <!-- 查询具体某一个套餐的使用情况 -->
            <if
                    test="record.taocanId != null and record.taocanId !=-1 and record.taocanId !=-2">
                and a.TAOCAN_ID = #{record.taocanId}
            </if>
            <!-- 查询所有的项目使用情况 -->
            <if test="record.taocanId != null and record.taocanId ==-1 ">
                and a.TAOCAN_ID IS NULL
            </if>
            <!-- 查询所有的套餐使用情况 -->
            <if test="record.taocanId != null and record.taocanId ==-2 ">
                and a.TAOCAN_ID IS NOT NULL
            </if>
            <if test="record.vipId != null and record.vipId !='' ">
                and a.VIP_ID = #{record.vipId}
            </if>
            <if test="record.failTime != null  ">
                and a.FAIL_TIME = #{record.failTime}
            </if>
            <if test="record.targetFailTime != null  ">
                and date_format(#{record.targetFailTime}, '%Y-%m-%d') > date_format(a.FAIL_TIME, '%Y-%m-%d')
            </if>
            <if test="record.price != null and record.price !='' ">
                and a.PRICE = #{record.price}
            </if>
            <if test="record.assembleId != null and record.assembleId !='' ">
                and a.ASSEMBLE_ID = #{record.assembleId}
            </if>
            <if test="record.source != null and record.source !='' ">
                and a.SOURCE like concat('%',#{record.source},'%')
            </if>
            <if test="record.status != null and record.status !='' ">
                and a.STATUS = #{record.status}
            </if>
            <if test="record.platformFlag != null and record.platformFlag !='' ">
                and a.PLATFORM_FLAG = #{record.platformFlag}
            </if>
            <if test="record.type != null and record.type !='' ">
                and a.type = #{record.type}
            </if>
            <if test="record.projName != null and record.projName !='' ">
                and a.PROJ_NAME like concat('%',#{record.projName},'%')
            </if>
            <if test="record.balance != null and record.balance !='' ">
                and a.balance = #{record.balance}
            </if>
            <if test="record.remark != null and record.remark !='' ">
                and a.remark = #{record.remark}
            </if>
            <if test="record.isCourse != null and record.isCourse !='' ">
               and  a.is_course = #{record.isCourse},
            </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="selectByVipIdPrjUseCount"
            resultType="java.lang.Integer">
        select count(*) from
        sys_proj_use
        where
        VIP_ID=#{vipId}
        AND
        PROJ_ID=#{prjId}
    </select>
    <!-- 根据会员id查询 -->
    <select id="selectByVipIdPrjUse" resultMap="SysProjUseMap">
        select *
        from sys_proj_use
        where VIP_ID=#{vipId}
        and PROJ_ID=#{prjId}
    </select>
 
    <!-- 查询总条数 -->
    <select id="selectTotalRecord" resultType="java.lang.Integer">
        select count(*)
        from sys_proj_use a
        left join shopping_goods b on a.proj_id=b.id
        left join sys_order_item c on a.ORDER_ITEM_ID=c.id
        left join sys_order d on c.ORDER_ID=d.id
        where 1=1
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and a.ID = #{record.id}
            </if>
            <if test="record.queryKey != null and record.queryKey !='' ">
                and (instr(b.name, #{record.queryKey}) or instr(b.zjm, #{record.queryKey}) or instr(goods_no, #{record.queryKey}))
            </if>
            <if test="record.orderItemId != null and record.orderItemId !='' ">
                and a.ORDER_ITEM_ID = #{record.orderItemId}
            </if>
            <if test="record.projId != null and record.projId !='' ">
                and a.PROJ_ID = #{record.projId}
            </if>
            <if test="record.surplusCount != null and record.surplusCount !='' ">
                and a.SURPLUS_COUNT = #{record.surplusCount}
            </if>
            <if test="record.isOver != null and record.isOver !='' ">
                and a.IS_OVER = #{record.isOver}
            </if>
            <!-- 查询具体某一个套餐的使用情况 -->
            <if
                    test="record.taocanId != null and record.taocanId !=-1 and record.taocanId !=-2">
                and a.TAOCAN_ID = #{record.taocanId}
            </if>
            <!-- 查询所有的项目使用情况 -->
            <if test="record.taocanId != null and record.taocanId ==-1 ">
                and a.TAOCAN_ID IS NULL
            </if>
            <!-- 查询所有的套餐使用情况 -->
            <if test="record.taocanId != null and record.taocanId ==-2 ">
                and a.TAOCAN_ID IS NOT NULL
            </if>
            <if test="record.vipId != null and record.vipId !='' ">
                and a.VIP_ID = #{record.vipId}
            </if>
            <if test="record.failTime != null  ">
                and a.FAIL_TIME = #{record.failTime}
            </if>
            <if test="record.targetFailTime != null  ">
                and date_format(#{record.targetFailTime}, '%Y-%m-%d') > date_format(a.FAIL_TIME, '%Y-%m-%d')
            </if>
            <if test="record.price != null and record.price !='' ">
                and a.PRICE = #{record.price}
            </if>
            <if test="record.assembleId != null and record.assembleId !='' ">
                and a.ASSEMBLE_ID = #{record.assembleId}
            </if>
            <if test="record.source != null and record.source !='' ">
                and a.SOURCE like concat('%',#{record.source},'%')
            </if>
            <if test="record.status != null and record.status !='' ">
                and a.STATUS = #{record.status}
            </if>
            <if test="record.platformFlag != null and record.platformFlag !='' ">
                and a.PLATFORM_FLAG = #{record.platformFlag}
            </if>
            <if test="record.type != null and record.type !='' ">
                and a.type = #{record.type}
            </if>
            <if test="record.projName != null and record.projName !='' ">
                and a.PROJ_NAME like concat('%',#{record.projName},'%')
            </if>
            <if test="record.balance != null and record.balance !='' ">
                and a.balance = #{record.balance}
            </if>
            <if test="record.remark != null and record.remark !='' ">
                and a.remark = #{record.remark}
            </if>
            <if test="record.isCourse != null and record.isCourse !='' ">
                and  a.is_course = #{record.isCourse},
            </if>
        </if>
    </select>
 
    <!-- 根据id查询 -->
    <select id="selectById" resultMap="SysProjUseMap">
        select a.*,
        b.TIME_LENGTH,
        b.img
        from sys_proj_use a
        left join shopping_goods b on a.proj_id=b.id
        where
        a.id=#{id}
    </select>
 
    <!-- 根据id查询 -->
    <select id="selectBySerProjId" resultMap="SysProjUseMap">
        select
        a.*,
        b.id serProjId
        from sys_proj_use a
        LEFT JOIN sys_ser_proj b on
        a.ID =b.PRO_USEID
        WHERE b.id = #{serProjId}
 
    </select>
 
 
    <!-- 根据对象查询 -->
    <select id="selectByModel" resultMap="SysProjUseMap">
        select
        a.*,
        b.time_length,
        b.img
        from sys_proj_use a
        left join shopping_goods b on a.proj_id=b.id
        where 1=1
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and a.ID = #{record.id}
            </if>
            <if test="record.orderItemId != null and record.orderItemId !='' ">
                and a.ORDER_ITEM_ID = #{record.orderItemId}
            </if>
            <if test="record.projId != null and record.projId !='' ">
                and a.PROJ_ID = #{record.projId}
            </if>
            <if test="record.surplusCount != null and record.surplusCount !='' ">
                and a.SURPLUS_COUNT = #{record.surplusCount}
            </if>
            <if test="record.isOver != null and record.isOver !='' ">
                and a.IS_OVER = #{record.isOver}
            </if>
            <if test="record.taocanId != null and record.taocanId !=-1 ">
                and a.TAOCAN_ID = #{record.taocanId}
            </if>
            <if test="record.taocanId != null and record.taocanId ==-1 ">
                and a.TAOCAN_ID IS NULL
            </if>
            <if test="record.vipId != null and record.vipId !='' ">
                and a.VIP_ID = #{record.vipId}
            </if>
            <if test="record.price != null and record.price !='' ">
                and a.PRICE = #{record.price}
            </if>
            <if test="record.assembleId != null and record.assembleId !='' ">
                and a.ASSEMBLE_ID = #{record.assembleId}
            </if>
            <if test="record.source != null and record.source !='' ">
                and a.SOURCE like concat('%',#{record.source},'%')
            </if>
            <if test="record.status != null and record.status !='' ">
                and a.STATUS = #{record.status}
            </if>
            <if test="record.platformFlag != null and record.platformFlag !='' ">
                and a.PLATFORM_FLAG = #{record.platformFlag}
            </if>
            <if test="record.type != null and record.type !='' ">
                and a.type = #{record.type}
            </if>
            <if test="record.balance != null and record.balance !='' ">
                and a.balance = #{record.balance}
            </if>
            <if test="record.remark != null and record.remark !='' ">
                and a.remark = #{record.remark}
            </if>
            <if test="record.isCourse != null and record.isCourse !='' ">
                and  a.is_course = #{record.isCourse},
            </if>
        </if>
    </select>
 
 
    <!--根据orderItemId和 vipId更新套餐下的项目 -->
    <update id="updateProjStatus" parameterType="SysProjUse">
        UPDATE sys_proj_use
        <set>
            STATUS = #{status},
            <if test="source != null and source !='' ">
                SOURCE =#{source},
            </if>
            <if test="failTime != null ">
                FAIL_TIME =#{failTime},
            </if>
            <if test="remark != null and remark!='' ">
                remark = #{remark}
            </if>
        </set>
        where  id=#{id}
    </update>
 
    <!-- 批量更新套餐 -->
    <update id="updateAllVipTaocan" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" separator=";">
            UPDATE sys_proj_use
            <set>
                STATUS = #{item.status},
                <if test="item.source != null and item.source !='' ">
                    SOURCE =#{item.source},
                </if>
                <if test="item.failTime != null and item.failTime!='' ">
                    FAIL_TIME =#{item.failTime},
                </if>
                <if test="(item.surplusCount != null and item.surplusCount !='') or  item.surplusCount == 0 ">
                    SURPLUS_COUNT = #{item.surplusCount},
                </if>
                <if test="item.remark != null and item.remark!='' ">
                    remark = #{item.remark}
                </if>
            </set>
            where PLATFORM_FLAG = #{item.platformFlag}
            and VIP_ID=#{item.vipId}
            and PROJ_ID=#{item.projId}
        </foreach>
    </update>
 
 
    <update id="updateProjUseTck">
        UPDATE sys_proj_use
        set
        SURPLUS_COUNT = #{surplusCount},
        IS_OVER = #{isOver},
        status = #{status},
        balance = #{balance}
        WHERE  ORDER_ITEM_ID = #{orderItemId}
    </update>
    <!-- 冻结套餐 -->
    <update id="updateTcStatus" >
        update sys_proj_use  set STATUS = #{status}  where  id=#{id} or TAOCAN_ID=#{id};
    </update>
 
    <insert id="insertAll" parameterType="java.util.List">
        INSERT INTO sys_proj_use (
        ORDER_ITEM_ID,
        PROJ_ID,
        SURPLUS_COUNT,
        IS_OVER,
        VIP_ID,
        TAOCAN_ID,
        FAIL_TIME,
        ASSEMBLE_ID,
        SOURCE,
        STATUS,
        PRICE,
        PLATFORM_FLAG,
        balance,
        remark,
        proj_name,
        tcName,
        deductionNum,
        is_course
        )
        VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.orderItemId},
            #{item.projId},
            #{item.surplusCount},
            #{item.isOver},
            #{item.vipId},
            #{item.taocanId},
            #{item.failTime},
            #{item.assembleId},
            #{item.source},
            #{item.status},
            #{item.price},
            #{item.platformFlag},
            #{item.balance},
            #{item.remark},
            #{projName},
            #{tcName},
            #{deductionNum},
            #{isCourse}
            )
        </foreach>
    </insert>
 
    <select id="selectItemDetail" resultType="java.util.HashMap" parameterType="java.util.HashMap">
        select c.VIP_NAME,
        a.PROJ_NAME,
        f.name as TYPE_NAME,
        a.SURPLUS_COUNT,
        a.PRICE,
        a.IS_OVER,
        a.FAIL_TIME,
        a.type,
        a.SOURCE,
        e.ORDER_NO,
        a.remark
        from sys_proj_use a
        left join shopping_goods b on a.proj_id = b.id
        left join sys_vip_info c on c.ID = a.VIP_ID
        left join sys_order_item d on d.id = a.ORDER_ITEM_ID
        left join sys_order e on e.id = d.ORDER_ID
        left join shopping_goods_category f on f.id = b.cate_id
 
 
        <where>
            <if test="shopId != null and  shopId != ''">
                and c.shop_id =#{shopId}
            </if>
            <if test="beginTime != null and beginTime != ''  ">
                and a.FAIL_TIME  <![CDATA[>=]]> #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''    ">
                and a.FAIL_TIME <![CDATA[<=]]> #{endTime}
 
            </if>
            <if test="vipQueryKey != null and vipQueryKey != ''  ">
                and e.VIP_NAME like concat('%',#{vipQueryKey},'%')
                or (e.VIP_NO like concat('%',#{vipQueryKey},'%')
                or e.PHONE like concat('%',#{vipQueryKey},'%')
                )
            </if>
            <if test="projName != null and projName != ''  ">
              and  a.proj_name like concat('%',#{projName},'%')
            </if>
            <if test="cateId != null and cateId != ''  ">
                and  b.cate_id=#{cateId}
            </if>
        </where>
 
        <if test="sort !=null and sort!=''"> order by ${sort} ${order}</if>
        <if test="(offset !=null and offset!='') or offset==0 ">
            limit ${offset},${limit}
        </if>
    </select>
 
 
    <select id="selectItemDetailTotal" resultType="java.lang.Integer">
        select count(a.id)
        from sys_proj_use a
        left join shopping_goods b on a.proj_id = b.id
        left join sys_vip_info c on c.ID = a.VIP_ID
        left join sys_order_item d on d.id = a.ORDER_ITEM_ID
        left join sys_order e on e.id = d.ORDER_ID
        left join shopping_goods_category f on f.id = b.cate_id
        <where>
            <if test="shopId != null and  shopId != ''">
                and c.shop_id =#{shopId}
            </if>
            <if test="beginTime != null and beginTime != ''  ">
                and a.FAIL_TIME  <![CDATA[>=]]> #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''    ">
                and a.FAIL_TIME <![CDATA[<=]]> #{endTime}
 
            </if>
            <if test="vipQueryKey != null and vipQueryKey != ''  ">
                and e.VIP_NAME like concat('%',#{vipQueryKey},'%')
                or (e.VIP_NO like concat('%',#{vipQueryKey},'%')
                or e.PHONE like concat('%',#{vipQueryKey},'%')
                )
            </if>
            <if test="projName != null and projName != ''  ">
                and  a.proj_name like concat('%',#{projName},'%')
            </if>
            <if test="cateId != null and cateId != ''  ">
                and  b.cate_id=#{cateId}
            </if>
        </where>
    </select>
 
    <select id="summaryItemDetail" resultType="java.util.HashMap" parameterType="java.util.HashMap">
        select
        b.id,
        a.PROJ_NAME,
        f.name as TYPE_NAME,
        SUM(a.SURPLUS_COUNT) as SURPLUS_COUNT,
        ROUND(SUM(a.PRICE*a.SURPLUS_COUNT) ,2)as PRICE
        from sys_proj_use a
        left join shopping_goods b on a.proj_id = b.id
        left join sys_vip_info c on c.ID = a.VIP_ID
        left join shopping_goods_category f on f.id = b.cate_id
        <where>
            <if test="shopId != null and  shopId != ''">
                and c.shop_id =#{shopId}
            </if>
            <if test="projName != null and projName != ''  ">
                and  a.proj_name like concat('%',#{projName},'%')
            </if>
            <if test="cateId != null and cateId != ''  ">
                and  b.cate_id=#{cateId}
            </if>
        </where>
        group by b.id
 
        <if test="sort !=null and sort!=''"> order by ${sort} ${order}</if>
        <if test="(offset !=null and offset!='') or offset==0 ">
            limit ${offset},${limit}
        </if>
    </select>
 
    <select id="summaryItemDetailTotal" resultType="java.lang.Integer">
        select count(1) from (
        select count(1)
        from sys_proj_use a
        left join shopping_goods b on a.proj_id = b.id
        left join sys_vip_info c on c.ID = a.VIP_ID
        left join shopping_goods_category f on f.id = b.cate_id
        <where>
            <if test="shopId != null and  shopId != ''">
                and c.shop_id =#{shopId}
            </if>
            <if test="projName != null and projName != ''  ">
                and  a.proj_name like concat('%',#{projName},'%')
            </if>
            <if test="cateId != null and cateId != ''  ">
                and  b.cate_id=#{cateId}
            </if>
        </where>
        group by b.id) t
    </select>
 
    <select id="selectHasValidProjUse" resultMap="SysProjUseMap">
        select * from sys_proj_use
        where date_format(now(), '%Y-%m-%d') > date_format(FAIL_TIME, '%Y-%m-%d') and STATUS='有效'
    </select>
 
    <resultMap type="SysProjUse" id="TaoCanWithProjMap">
 
        <id property="id" column="ID"/>
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
        <result property="orderItemId" column="ORDER_ITEM_ID"/>
        <result property="projId" column="PROJ_ID"/>
        <result property="surplusCount" column="SURPLUS_COUNT"/>
        <result property="isOver" column="IS_OVER"/>
        <result property="taocanId" column="TAOCAN_ID"/>
        <result property="vipId" column="VIP_ID"/>
        <result property="failTime" column="FAIL_TIME"/>
        <result property="assembleId" column="ASSEMBLE_ID"/>
        <result property="source" column="SOURCE"/>
        <result property="status" column="STATUS"/>
        <result property="platformFlag" column="PLATFORM_FLAG"/>
        <result property="type" column="type"/>
        <result property="balance" column="balance"/>
        <result property="remark" column="remark"/>
        <result property="price" column="price"/>
        <result property="tcName" column="tcName"/>
        <result property="projName" column="proj_name"/>
        <result property="deductionNum" column="deductionNum"/>
        <result property="isCourse" column="is_course"/>
        <result property="timeLength" column="time_length"/>
        <result property="orderId" column="orderId"/>
 
        <collection property="taocanProjUse" ofType="com.matrix.system.hive.bean.SysProjUse">
            <id property="id" column="proj_info_id" />
            <result property="projName" column="proj_proj_name"/>
            <result property="failTime" column="proj_FAIL_TIME"/>
            <result property="surplusCount" column="proj_SURPLUS_COUNT"/>
            <result property="timeLength" column="proj_time_length"/>
            <result property="img" column="proj_img"/>
            <result property="projId" column="proj_projId"/>
        </collection>
    </resultMap>
 
    <select id="selectTaoCanListWithProj" resultMap="TaoCanWithProjMap">
        select
            a.*,
            d.id as orderId,
            b.TIME_LENGTH,
            b.img,
            b.code,
            e.proj_name proj_proj_name,
            e.FAIL_TIME proj_FAIL_TIME,
            e.SURPLUS_COUNT proj_SURPLUS_COUNT,
            e.id proj_info_id,
            e.proj_id proj_projId,
            f.time_length proj_time_length,
            f.img proj_img
        from sys_proj_use a
            left join shopping_goods b on a.proj_id=b.id
            left join sys_order_item c on a.ORDER_ITEM_ID=c.id
            left join sys_order d on c.ORDER_ID=d.id
            left join sys_proj_use e on a.id = e.TAOCAN_ID and e.VIP_ID=a.vip_id
            left join shopping_goods f on e.proj_id=f.id
        where 1=1 and a.type='套餐' and a.TAOCAN_ID IS NULL
        <if test="record.queryKey != null and record.queryKey !='' ">
            and (instr(b.name, #{record.queryKey}) or instr(b.zjm, #{record.queryKey}) or instr(goods_no, #{record.queryKey}))
        </if>
        <if test="record.isOver != null and record.isOver !='' ">
            and a.IS_OVER = #{record.isOver}
        </if>
        <if test="record.status != null and record.status !='' ">
            and a.STATUS = #{record.status}
        </if>
        <if test="record.vipId != null and record.vipId !='' ">
            and a.VIP_ID = #{record.vipId}
        </if>
    </select>
 
</mapper>