Helius
2022-05-27 4351e71d782741143a98f86f6648acd16689165f
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
<?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.SysBeauticianStateDao">
 
    <resultMap type="SysBeauticianState" id="SysBeauticianStateMap">
        <id property="id" column="ID"/>
        <result property="staffId" column="STAFF_ID"/>
        <result property="state" column="STATE"/>
        <result property="beginTime" column="BEGIN_TIME"/>
        <result property="endTime" column="END_TIME"/>
        <result property="servicesId" column="SERVICES_ID"/>
        <result property="excTime" column="EXC_TIME"/>
        <result property="extract" column="extract"/>
        <result property="projId" column="proj_id"/>
        <result property="puseId" column="puse_id"/>
        <result property="count" column="count"/>
 
        <!--扩展字段 -->
        <result property="createTime" column="createTime"/>
        <result property="bedName" column="bedName"/>
        <result property="vipName" column="vipName"/>
        <association property="beautiStaffInfo" resultMap="com.matrix.system.common.dao.SysUsersDao.SysUsersMap"/>
        <association property="projInfo" resultMap="com.matrix.system.hive.dao.ShoppingGoodsDao.ShoppingGoodsMap"
        columnPrefix="goods_"/>
        <association property="projUse" resultMap="com.matrix.system.hive.dao.SysProjUseDao.SysProjUseMap"
                     columnPrefix="pu_"/>
 
    </resultMap>
 
 
    <!--  插入方法   -->
    <insert id="insert" parameterType="SysBeauticianState"
            useGeneratedKeys="true" keyProperty="id">
        INSERT INTO sys_beautician_state (
            ID,
            STAFF_ID,
            STATE,
            BEGIN_TIME,
            END_TIME,
            SERVICES_ID,
            EXC_TIME,
            extract,
            puse_id,
            count,
            proj_id
        )
    VALUES (
            #{id},
            #{staffId},
            #{state},
            #{beginTime},
            #{endTime},
            #{servicesId},
            #{excTime},
            #{extract},
            #{puseId},
            #{count},
            #{projId}
    )
    </insert>
 
 
    <!-- 根据美疗师的占用情况的开始时间 和结束时间查看该时段是否冲突 -->
    <select id="checkBeauticianClash" resultType="java.lang.Integer">
        SELECT
        count(*)
        FROM
        sys_beautician_state
        WHERE 1=1
        <if test="record!=null">
            <if test="record.beginTime != null   ">
                AND
                STAFF_ID=#{record.staffId}
                AND
                (STATE = '服务中' OR STATE='已预约')
                AND
                (
                #{record.beginTime} BETWEEN BEGIN_TIME and END_TIME
                OR
                #{record.endTime} BETWEEN BEGIN_TIME and END_TIME
                OR
                BEGIN_TIME BETWEEN #{record.beginTime} and #{record.endTime}
                OR
                END_TIME BETWEEN #{record.beginTime} and #{record.endTime}
                )
                AND
                SERVICES_ID != #{record.servicesId}
            </if>
        </if>
    </select>
 
    <!-- 根据时间段查询 -->
    <select id="selectByTimeAndStaff" resultMap="SysBeauticianStateMap">
        select 
        a.ID,
            a.STAFF_ID,
            a.STATE,
            a.BEGIN_TIME,
            a.END_TIME,
            a.SERVICES_ID,
            a.puse_id,
            a.count,
            b.STATE AS serviceOrderStatu,
            a.extract
            from sys_beautician_state a
            left join sys_proj_services b on a.SERVICES_ID=b.ID
         WHERE (a.STATE='服务中' or a.STATE='服务结束' or a.STATE='已预约')
         AND  a.STAFF_ID =#{staffId}
         AND  a.BEGIN_TIME BETWEEN  #{beginTime} and #{endTime}
         order by a.BEGIN_TIME
    </select>
 
 
    <!-- 根据服务人id与 服务单id查询 被占用美疗师
 
 
    -->
    <select id="selectBySerIds" resultMap="SysBeauticianStateMap">
        select
            a.ID,
            a.STAFF_ID,
            a.STATE,
            a.BEGIN_TIME,
            a.END_TIME,
            a.SERVICES_ID,
            a.EXC_TIME,
            a.extract,
            a.puse_id,
            a.count,
            a.proj_id,
            b.su_name,
            d.proj_name as goods_name,
            d.price as goods_seal_pice,
            c.TIME_LENGTH as goods_time_length,
            d.id as pu_id,
            d.SURPLUS_COUNT as pu_SURPLUS_COUNT,
            d.ASSEMBLE_ID as pu_ASSEMBLE_ID,
            d.price as pu_price,
            d.taocan_id as pu_taocan_id,
            d.source as pu_source
        from sys_beautician_state a
        left join sys_users b on a.staff_id= b.su_id
        left  join  shopping_goods c on a.proj_id=c.id
        left  join sys_proj_use d on a.puse_id=d.id
         where  a.SERVICES_ID =#{serId}
    </select>
 
    <!-- EXC_TIME =TIMESTAMPDIFF(MINUTE,BEGIN_TIME,now()) -->
    <update id="chengItemState">
        update sys_beautician_state set  state=#{record.state}
        where 1=1
        <if test="record.staffId != null">
            and STAFF_ID=#{record.staffId}
        </if>
          and SERVICES_ID =#{record.servicesId}
    </update>
 
    <!--  根据id更新 部分更新   -->
    <update id="update">
        UPDATE sys_beautician_state
        <set>
            <if test="staffId != null and staffId !='' ">
                STAFF_ID = #{staffId},
            </if>
            <if test="state != null and state !='' ">
                STATE = #{state},
            </if>
            <if test="beginTime != null  ">
                BEGIN_TIME = #{beginTime},
            </if>
            <if test="endTime != null  ">
                END_TIME = #{endTime},
            </if>
            <if test="servicesId != null and servicesId !='' ">
                SERVICES_ID = #{servicesId},
            </if>
            <if test="excTime != null and excTime !='' ">
                EXC_TIME = #{excTime},
            </if>
 
            <if test="extract != null and extract !='' ">
                extract = #{extract},
            </if>
            <if test="puseId != null and puseId !='' ">
                puse_id = #{puseId},
            </if>
 
            <if test="count != null and count !='' ">
                count = #{count},
            </if>
            <if test="projId != null and projId !='' ">
                proj_id = #{projId},
            </if>
        </set>
        WHERE ID=#{id}
    </update>
 
 
    <!-- 批量删除 -->
    <delete id="deleteByIds" parameterType="java.util.List">
        delete from sys_beautician_state where ID in
        <foreach collection="list" index="index" item="item" open="("
                 separator="," close=")">
            #{item}
        </foreach>
    </delete>
 
    <!-- 根据id删除-->
    <delete id="deleteById">
        DELETE FROM sys_beautician_state
        where  ID=#{id} 
    </delete>
 
 
    <!-- 分页查询 -->
    <select id="selectInPage" resultMap="SysBeauticianStateMap">
        <include refid="select1"></include>
        <include refid="from1"></include>
        <include refid="where1"></include>
        <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" resultType="java.lang.Integer">
        select count(*)
        <include refid="from1"></include>
        <include refid="where1"></include>
    </select>
 
    <sql id="select1">
            select *,
            svi.VIP_NAME vipName,
            ssi.SHOP_NAME shopName,
            si.su_name staffName,
            sps.service_no serviceNo,
            sc.service service,
            sc.environment environment,
            sc.suggestion suggestion,
            sc.create_time createTime
    </sql>
    <sql id="from1">
        from sys_beautician_state  sbs
        LEFT JOIN service_comment sc on sc.service_id=sbs.SERVICES_ID
        LEFT JOIN sys_proj_services sps on sps.id=sbs.SERVICES_ID
        LEFT JOIN sys_vip_info svi on svi.id=sps.vip_id
        LEFT JOIN sys_shop_info ssi on ssi.id=sps.shop_id 
        LEFT JOIN sys_users si on si.su_id=sbs.STAFF_ID
    </sql>
 
    <sql id="where1">
        where 1=1
        <if test="record!=null">
            <if test="record.serviceNo != null and record.serviceNo !='' ">
                and sps.service_no =#{record.serviceNo}
            </if>
            <if test="record.shopName != null and record.shopName !='' ">
                and ssi.SHOP_NAME =#{record.shopName}
            </if>
            <if test="record.vipName != null and record.vipName !='' ">
                and svi.VIP_NAME =#{record.vipName}
            </if>
            <if test="record.staffName!= null and record.staffName !='' ">
                and si.su_name =#{record.staffName}
            </if>
            <if test="record.projServiceState!= null and record.projServiceState !='' ">
                and sps.STATE =#{record.projServiceState}
            </if>
 
            <if test="record.id != null and record.id !='' ">
                and sbs.ID =#{record.id}
            </if>
            <if test="record.staffId != null and record.staffId !='' ">
                and sbs.STAFF_ID =#{record.staffId}
            </if>
            <if test="record.state != null and record.state !='' ">
                and sbs.STATE =#{record.state}
            </if>
            <if test="record.beginTime != null  ">
                and sbs.BEGIN_TIME =#{record.beginTime}
            </if>
            <if test="record.endTime != null  ">
                and sbs.END_TIME =#{record.endTime}
            </if>
            <if test="record.servicesId != null and record.servicesId !='' ">
                and sbs.SERVICES_ID =#{record.servicesId}
            </if>
 
 
        </if>
        order by sc.create_time desc
    </sql>
 
 
    <!-- 根据id查询-->
    <select id="selectById" resultMap="SysBeauticianStateMap">
        <include refid="select"></include>
        <include refid="from"></include>
        where ID=#{id}
    </select>
 
 
    <!-- 根据对象查询-->
    <select id="selectByModel" resultMap="SysBeauticianStateMap">
        <include refid="select"></include>
        <include refid="from"></include>
        <include refid="where"></include>
    </select>
 
    <select id="selectByTimeAndUset" resultMap="SysBeauticianStateMap">
        select a.*,
         c.VIP_NAME as vipName,
         d.PROJ_NAME as pu_proj_name,
         e.BED_NAME as bedName
         from sys_beautician_state a
        left join sys_proj_services b on  a.SERVICES_ID =b.ID
        left join sys_vip_info c on b.VIP_ID=c.ID
        left join sys_proj_use d on a.puse_id=d.id
        left join sys_bed_info e on b.BED_ID=e.id
        where
       <![CDATA[ a.BEGIN_TIME > #{beginTime}
        and a.END_TIME < #{endTime}
        and a.STAFF_ID = #{suId} ]]>
        and  a.STATE !='预约取消'
        and  a.STATE !='待确认'
        and  a.STATE !='服务单结束'
        and  a.STATE !='待预约'
        order by a.BEGIN_TIME asc
 
    </select>
 
 
    <select id="selectItemByTime" resultMap="SysBeauticianStateMap">
       select a.*,
       c.PRICE as pu_PRICE ,
       c.SOURCE as pu_SOURCE,
       c.ASSEMBLE_ID as pu_ASSEMBLE_ID
from sys_beautician_state a
         left join sys_proj_services b on  a.SERVICES_ID =b.ID
         left join sys_proj_use c on a.puse_id=c.id
where b.SHOP_ID=#{shopId}
      and to_days(b.consume_time)=to_days(#{time})
    </select>
 
 
    <sql id="select">
            select 
            ID,
            STAFF_ID,
            STATE,
            BEGIN_TIME,
            END_TIME,
            SERVICES_ID,
            EXC_TIME,
            extract,
            puse_id,
            count,
            proj_id
    </sql>
    <sql id="from">
        from sys_beautician_state 
    </sql>
    <sql id="where">
        where 1=1
        <if test="record!=null">
            <if test="record.excTime != null  ">
                and EXC_TIME =#{record.excTime}
            </if>
            <if test="record.id != null and record.id !='' ">
                and ID =#{record.id}
            </if>
            <if test="record.staffId != null and record.staffId !='' ">
                and STAFF_ID =#{record.staffId}
            </if>
            <if test="record.state != null and record.state !='' ">
                and STATE =#{record.state}
            </if>
            <if test="record.beginTime != null  ">
                and BEGIN_TIME =#{record.beginTime}
            </if>
            <if test="record.endTime != null  ">
                and END_TIME =#{record.endTime}
            </if>
            <if test="record.servicesId != null and record.servicesId !='' ">
                and SERVICES_ID =#{record.servicesId}
            </if>
 
            <if test="record.extract != null and record.extract !='' ">
                and extract = #{record.extract}
            </if>
            <if test="record.puseId != null and record.puseId !='' ">
                and puse_id = #{record.puseId}
            </if>
            <if test="record.count != null and record.count !='' ">
                and count = #{record.count}
            </if>
            <if test="record.projId != null and record.projId !='' ">
                and proj_id = #{record.projId}
            </if>
        </if>
    </sql>
 
 
    <!-- 服务明细查询-->
    <select id="selectItemDetail" resultType="java.util.HashMap" parameterType="java.util.HashMap">
        select
        f.SHOP_NAME,
        b.yy_time,
        b.consume_time,
        b.SERVICE_NO,
        d.su_name,
        e.VIP_NAME,
        h.PROJ_NAME,
        c.id,
        g.NAME as TYPE_NAME,
        a.COUNT,
        h.PRICE,
        h.SOURCE,
        a.STATE,
        a.extract
        from sys_beautician_state a
        left join sys_proj_services b on a.SERVICES_ID=b.ID
        left join shopping_goods c on a.proj_id=c.id
        left join sys_users d on d.su_id=a.STAFF_ID
        left join sys_vip_info e on e.ID=b.VIP_ID
        left join sys_shop_info f on f.ID=b.SHOP_ID
        left join shopping_goods_category g on c.cate_id=g.id
        left join sys_proj_use h on h.id=a.puse_id
        <where>
            <if test="shopId != null and  shopId != ''">
                and f.id =#{shopId}
            </if>
            <if test="beginTime != null and beginTime != '' ">
                and b.consume_time  <![CDATA[>=]]> #{beginTime}
            </if>
            <if test="endTime != null and endTime !='' ">
                and b.consume_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   h.proj_name like concat('%',#{projName},'%')
            </if>
 
            <if test="shopId != null and shopId != ''  ">
                and   f.id=#{shopId}
            </if>
 
            <if test="cateId != null and cateId != ''  ">
                and  c.cate_id=#{cateId}
            </if>
 
 
            <if test="staffId != null and staffId != ''  ">
                and  a.STAFF_ID=#{staffId}
            </if>
 
            <if test="state != null and state != ''  ">
                and  a.STATE=#{state}
            </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_beautician_state a
        left join sys_proj_services b on a.SERVICES_ID=b.ID
        left join shopping_goods c on a.proj_id=c.id
        left join sys_users d on d.su_id=a.STAFF_ID
        left join sys_vip_info e on e.ID=b.VIP_ID
        left join sys_shop_info f on f.ID=b.SHOP_ID
        left join shopping_goods_category g on c.cate_id=g.id
        left join sys_proj_use h on h.id=a.puse_id
        <where>
            <if test="shopId != null and  shopId != ''">
                and f.id =#{shopId}
            </if>
            <if test="beginTime != null and beginTime != '' ">
                and b.consume_time  <![CDATA[>=]]> #{beginTime}
            </if>
            <if test="endTime != null and endTime !='' ">
                and b.consume_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   h.proj_name like concat('%',#{projName},'%')
            </if>
 
            <if test="shopId != null and shopId != ''  ">
                and  f.id=#{shopId}
            </if>
 
            <if test="cateId != null and cateId != ''  ">
                and  c.cate_id=#{cateId}
            </if>
 
 
            <if test="staffId != null and staffId != ''  ">
                and  a.STAFF_ID=#{staffId}
            </if>
            <if test="state != null and state != ''  ">
                and  a.STATE=#{state}
            </if>
        </where>
    </select>
 
 
    <select id="summaryItemDetail" resultType="java.util.HashMap" parameterType="java.util.HashMap">
        select
        f.SHOP_NAME,
        h.PROJ_NAME,
        c.id,
        g.name as TYPE_NAME,
        SUM(a.COUNT) as COUNT,
        ROUND(SUM(h.PRICE*a.count),2) as PRICE
        from sys_beautician_state a
        left join sys_proj_services b on a.SERVICES_ID=b.ID
        left join shopping_goods c on a.proj_id=c.id
        left join sys_users d on d.su_id=a.STAFF_ID
        left join sys_vip_info e on e.ID=b.VIP_ID
        left join sys_shop_info f on f.ID=b.SHOP_ID
        left join shopping_goods_category g on c.cate_id=g.id
        left join sys_proj_use h on h.id=a.puse_id
        <where>
            <if test="shopId != null and  shopId != ''">
                and f.id =#{shopId}
            </if>
            <if test="beginTime != null and beginTime != '' ">
                and b.consume_time  <![CDATA[>=]]> #{beginTime}
            </if>
            <if test="endTime != null and endTime !='' ">
                and b.consume_time <![CDATA[<=]]> #{endTime}
            </if>
            <if test="projName != null   ">
                and   h.proj_name like concat('%',#{projName},'%')
            </if>
            <if test="shopId != null and shopId != ''  ">
                and   f.id=#{shopId}
            </if>
 
            <if test="cateId != null and cateId != ''  ">
                and   c.cate_id=#{cateId}
            </if>
            <if test="state != null and state != ''  ">
                and  a.STATE=#{state}
            </if>
        </where>
        group by c.id,f.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_beautician_state a
        left join sys_proj_services b on a.SERVICES_ID=b.ID
        left join shopping_goods c on a.proj_id=c.id
        left join sys_users d on d.su_id=a.STAFF_ID
        left join sys_vip_info e on e.ID=b.VIP_ID
        left join sys_shop_info f on f.ID=b.SHOP_ID
        left join shopping_goods_category g on c.cate_id=g.id
        left join sys_proj_use h on h.id=a.puse_id
        <where>
            <if test="shopId != null and  shopId != ''">
                and f.id =#{shopId}
            </if>
            <if test="beginTime != null and beginTime != '' ">
                and b.consume_time  <![CDATA[>=]]> #{beginTime}
            </if>
            <if test="endTime != null and endTime !='' ">
                and b.consume_time <![CDATA[<=]]> #{endTime}
            </if>
            <if test="projName != null and projName != ''  ">
                and   h.proj_name like concat('%',#{projName},'%')
            </if>
            <if test="shopId != null and shopId != ''  ">
                and   f.id=#{shopId}
            </if>
 
            <if test="cateId != null and cateId != ''  ">
                and   c.cate_id=#{cateId}
            </if>
            <if test="state != null and state != ''  ">
                and  a.STATE=#{state}
            </if>
        </where>
        group by c.id,f.id) t
    </select>
 
    <select id="selectByProjUse" resultMap="SysBeauticianStateMap">
        select * from sys_beautician_state
        where state!=#{state} and puse_id in
        <foreach collection="list" index="index" item="item" open="("
                 separator="," close=")">
            #{item.id}
        </foreach>
    </select>
 
    <select id="selectBeauticianStateByPuseIdAndNoStatus" resultMap="SysBeauticianStateMap">
        select * from sys_beautician_state
        where puse_id=#{puseId} and state!=#{state}
    </select>
</mapper>