1
luodangjia
2024-05-12 533558ecfbb188f43cbb151e5245abff1b1aa818
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
package cn.stylefeng.rest.modular.user.controller;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import cn.stylefeng.guns.modular.business.dto.*;
import cn.stylefeng.guns.modular.business.dto.request.*;
import cn.stylefeng.guns.modular.business.entity.*;
import cn.stylefeng.guns.modular.business.service.*;
import cn.stylefeng.guns.modular.business.service.impl.ImBizService;
import cn.stylefeng.rest.ijpay.controller.AliPayController;
import cn.stylefeng.rest.ijpay.controller.WxPayController;
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.customer.api.pojo.CustomerInfo;
import cn.stylefeng.roses.kernel.customer.modular.entity.Customer;
import cn.stylefeng.roses.kernel.customer.modular.service.CustomerService;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.enums.*;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.rule.pojo.response.ErrorResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRole;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
 
/**
 * 咨询师信息管理类
 * @author guo
 */
@Slf4j
@RestController
@Api(tags = "咨询师信息")
@ApiResource(name = "咨询师信息", resBizType = ResBizTypeEnum.BUSINESS)
@RequestMapping
public class CounsellingInfoController {
 
    @Resource
    private ICounsellingInfoService counsellingInfoService;
 
    @Resource
    private ICounsellingTagService counsellingTagService;
 
    @Resource
    private ICounsellingSetMealService counsellingSetMealService;
 
    @Resource
    private CustomerService customerService;
 
    @Resource
    private ICounsellingTimeConfigService counsellingTimeConfigService;
 
    @Resource
    private ICounsellingSpecialTimeConfigService counsellingSpecialTimeConfigService;
 
    @Resource
    private ICounsellingOrderReservationService counsellingOrderReservationService;
 
    @Resource
    private ICounsellingOrderService counsellingOrderService;
 
    @Resource
    private IContractRecordService contractRecordService;
 
    @Resource
    private ICounsellingReservationWorkService counsellingReservationWorkService;
 
    @Resource
    private ImBizService imBizService;
 
    @Resource
    private IImGroupService imGroupService;
 
    @Resource
    private ICounsellingUserService counsellingUserService;
 
    @Resource
    private WxPayController wxPayController;
 
    @Resource
    private AliPayController aliPayController;
    @Resource
    private IMentalAppointmentService mentalAppointmentService;
 
    @Value("${refund.alipay-url}")
    private String refundAlipayUrl;
    @Value("${refund.wxpay-url}")
    private String refundWxpayUrl;
 
    @Resource
    private RedissonClient redissonClient;
 
 
 
 
 
 
    /**
     * 获取咨询师信息详情
     */
    @ApiOperation("获取咨询师信息详情")
    @GetResource(name = "获取咨询师信息详情", path = "/counsellingInfo/detail/{id}", requiredPermission = false)
    public ResponseData<CounsellinginfoResponseDTO> detail(@PathVariable("id") Long id) {
        CounsellingInfo counsellingInfo = this.counsellingInfoService.getById(id);
        //获取课程标签名称
        LambdaQueryWrapper<CounsellingTag> counsellingTagLambdaQueryWrapper = new QueryWrapper<CounsellingTag>().select(" GROUP_CONCAT(tag_name)  tagName ").lambda();
        Map<String,Object> map = counsellingTagService.getMap(counsellingTagLambdaQueryWrapper.in(CounsellingTag::getId,counsellingInfo.getCounsellingTagIds().split(",")));
        if (ObjectUtil.isNotEmpty(map)){
            counsellingInfo.setCounsellingTagNames(map.get("tagName").toString());
        }
        //查询套餐信息
        counsellingInfo.setCounsellingSetMealList(this.counsellingSetMealService.list(new LambdaQueryWrapper<CounsellingSetMeal>().eq(CounsellingSetMeal::getCounsellingInfoId,counsellingInfo.getId()).eq(CounsellingSetMeal::getIsDelete,false)));
        //根据客户信息
        Customer customer = this.customerService.getById(counsellingInfo.getUserId());
        if (customer != null){
            counsellingInfo.setUserName(customer.getNickName());
        }
        //查询是否首次购买
        CounsellinginfoResponseDTO counsellinginfoResponseDTO = BeanUtil.copyProperties(counsellingInfo, CounsellinginfoResponseDTO.class);
        counsellinginfoResponseDTO.setWorkStatus(customer.getWorkStatus());
        counsellinginfoResponseDTO.setCounsellingSetMealList(counsellingInfo.getCounsellingSetMealList());
        LambdaQueryWrapper<CounsellingOrder> lambdaQueryWrapper = new LambdaQueryWrapper<CounsellingOrder>()
                .eq(CounsellingOrder::getUserId,LoginContext.me().getLoginUser().getUserId()).in(CounsellingOrder::getStatusFlag,1,2).eq(CounsellingOrder::getCounsellingInfoId,id)
                .eq(CounsellingOrder::getOrderType,1);
        long count = this.counsellingOrderService.count(lambdaQueryWrapper);
        if (count > 0){
            counsellinginfoResponseDTO.setIsFirstBuy(true);
        }
        return new SuccessResponseData<>(counsellinginfoResponseDTO);
    }
 
 
    @Resource
    private CacheOperatorApi<List<CounsellinginfoResponseDTO>> roleInfoCacheApi;
 
 
    /**
     * 获取咨询师信息列表(分页)
     */
    @ApiOperation("获取咨询师信息列表(分页)")
    @GetResource(name = "获取咨询师信息列表(分页)", path = "/counsellingInfo/page")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "分页:第几页(从1开始)", dataTypeClass = Integer.class, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页:每页大小(默认10)", dataTypeClass = Integer.class, paramType = "query"),
            @ApiImplicitParam(name = "searchType", value = "查询类型 1-严选,2-普通查询,默认2", dataTypeClass = Integer.class, paramType = "query")
    })
    public ResponseData<PageResult<CounsellinginfoResponseDTO>> page(Integer pageNo, Integer pageSize,Integer searchType) {
//        if (roleInfoCacheApi.get("customer:"+LoginContext.me().getLoginUser().getUserId())!=null){
//            List<CounsellinginfoResponseDTO> customer = roleInfoCacheApi.get("customer:"+LoginContext.me().getLoginUser().getUserId());
//            return  new SuccessResponseData<>(customer);
//        }
//
//        LambdaQueryWrapper<CounsellingInfo> lambdaQueryWrapper = new LambdaQueryWrapper<CounsellingInfo>().eq(CounsellingInfo::getIsDelete,false)
//                .orderByDesc(CounsellingInfo::getSort,CounsellingInfo::getCreateTime).eq(CounsellingInfo::getListingStatus,1);
//        //默认普通查询
//        if (searchType != null  && searchType.intValue() == 1){
//            List<Customer> customerList = customerService.getWorkerListByLineStatusAndPost(null, null, PostIdEnum.PO_22.getCode(), CustomerWorkStatusEnum.ON_WORK.getCode());
//            if (CollectionUtil.isNotEmpty(customerList)){
//                List<Long> customerIds = customerList.stream().map(Customer::getCustomerId).collect(Collectors.toList());
//                lambdaQueryWrapper.in(CounsellingInfo::getUserId,customerIds);
//            }
//        }
//        List<CounsellingInfo> page = this.counsellingInfoService.list(lambdaQueryWrapper);
//        if (CollectionUtil.isNotEmpty(page)){
//            List<Long> counseIds = page.stream().map(CounsellingInfo::getId).collect(Collectors.toList());
//            QueryWrapper<CounsellingOrder> orderQueryWrapper = new QueryWrapper<CounsellingOrder>().select("counselling_info_id counsellingInfoId,count(1) num ");
//            //查询是否首次咨询
//            orderQueryWrapper.lambda().eq(CounsellingOrder::getUserId,LoginContext.me().getLoginUser().getUserId()).in(CounsellingOrder::getStatusFlag,1,2).in(CounsellingOrder::getCounsellingInfoId,counseIds)
//                    .eq(CounsellingOrder::getOrderType,1).groupBy(CounsellingOrder::getCounsellingInfoId).having(" num > 0 ");
//            List<Map<String,Object>> mapList = this.counsellingOrderService.listMaps(orderQueryWrapper);
//            Map<Long,Object> fristMap = new HashMap<>();
//            if (CollectionUtil.isNotEmpty(mapList)){
//
//                mapList.stream().forEach(stringObjectMap -> {
//                    fristMap.put(Long.parseLong(stringObjectMap.get("counsellingInfoId").toString()),stringObjectMap.get("num"));
//                });
//            }
//            //查询标签总条数
//            List<CounsellingTag> counsellingTags = this.counsellingTagService.list(new LambdaQueryWrapper<CounsellingTag>()
//                    .select(CounsellingTag::getId,CounsellingTag::getTagName));
//            List<Long> custommerIds = page.stream().map(CounsellingInfo::getUserId).collect(Collectors.toList());
//            //查询客户ids
//            List<Customer> customerList = this.customerService.list(new LambdaQueryWrapper<Customer>().select(Customer::getCustomerId,Customer::getNickName).in(Customer::getCustomerId,custommerIds));
//            //查询套餐最低价
//            List<Map<String,Object>> lowMapList = this.counsellingSetMealService.listMaps(new QueryWrapper<CounsellingSetMeal>().select(" counselling_info_id counsellingInfoId,IFNULL(min(price),0) price ").lambda().in(CounsellingSetMeal::getCounsellingInfoId,counseIds)
//                    .eq(CounsellingSetMeal::getSetMealType,1).eq(CounsellingSetMeal::getIsDelete,0));
//
//            List<CounsellinginfoResponseDTO> counsellinginfoResponseDTOS = BeanUtil.copyToList(page,CounsellinginfoResponseDTO.class, CopyOptions.create());
//            counsellinginfoResponseDTOS.stream().forEach(counsellinginfoResponseDTO -> {
//                if (fristMap.get(counsellinginfoResponseDTO.getId()) != null){
//                    counsellinginfoResponseDTO.setIsFirstBuy(true);
//                }
//                if (StrUtil.isNotBlank(counsellinginfoResponseDTO.getCounsellingTagIds())){
//                    List<String> counsellingTagList = Arrays.asList(counsellinginfoResponseDTO.getCounsellingTagIds().split(","));
//                    String tagNames = counsellingTags.stream().filter(cou -> counsellingTagList.contains(cou.getId().toString())).map(CounsellingTag::getTagName).collect(Collectors.joining(","));
//                    //获取课程标签名称
////                    LambdaQueryWrapper<CounsellingTag> counsellingTagLambdaQueryWrapper = new QueryWrapper<CounsellingTag>().select(" GROUP_CONCAT(tag_name)  tagName ").lambda();
////                    Map<String,Object> map = counsellingTagService.getMap(counsellingTagLambdaQueryWrapper.in(CounsellingTag::getId,counsellinginfoResponseDTO.getCounsellingTagIds().split(",")));
////                    if (ObjectUtil.isNotEmpty(map)){
//                    counsellinginfoResponseDTO.setCounsellingTagNames(tagNames);
////                    }
//                }
//                counsellinginfoResponseDTO.setPersonalProfile(null);
//
//                counsellinginfoResponseDTO.setNikeName(customerList.stream().filter(cus -> counsellinginfoResponseDTO.getUserId().longValue() == cus.getCustomerId().longValue()).findFirst().get().getNickName());
//
////                BigDecimal lowPrice = this.counsellingSetMealService.getObj(new QueryWrapper<CounsellingSetMeal>().select(" counselling_info_id counsellingInfoId,IFNULL(min(price),0) price ").lambda().eq(CounsellingSetMeal::getCounsellingInfoId,counsellinginfoResponseDTO.getId())
////                        .eq(CounsellingSetMeal::getSetMealType,1).eq(CounsellingSetMeal::getIsDelete,0),Convert::toBigDecimal);
//
//
//                if (CollectionUtil.isNotEmpty(lowMapList)){
//                    lowMapList.stream().forEach(stringObjectMap -> {
//                        if (stringObjectMap.get("counsellingInfoId") != null){
//                            counsellinginfoResponseDTO.setLowPrice(new BigDecimal(stringObjectMap.get("price").toString()));
//                        }
//                    });
//                    if (counsellinginfoResponseDTO.getLowPrice() == null){
//                        counsellinginfoResponseDTO.setLowPrice(new BigDecimal(0));
//                    }
//                }
//
//
//            });
//            roleInfoCacheApi.put("customer:"+LoginContext.me().getLoginUser().getUserId(),counsellinginfoResponseDTOS,600L);
//
//            return  new SuccessResponseData<>(counsellinginfoResponseDTOS);
//        }
//
//        return  new SuccessResponseData<>();
 
 
 
 
 
 
        LambdaQueryWrapper<CounsellingInfo> lambdaQueryWrapper = new LambdaQueryWrapper<CounsellingInfo>().eq(CounsellingInfo::getIsDelete,false)
                    .orderByDesc(CounsellingInfo::getSort,CounsellingInfo::getCreateTime).eq(CounsellingInfo::getListingStatus,1);
        //默认普通查询
        if (searchType != null  && searchType.intValue() == 1){
            List<Customer> customerList = customerService.getWorkerListByLineStatusAndPost(null, null, PostIdEnum.PO_22.getCode(), CustomerWorkStatusEnum.ON_WORK.getCode());
            if (CollectionUtil.isNotEmpty(customerList)){
                List<Long> customerIds = customerList.stream().map(Customer::getCustomerId).collect(Collectors.toList());
                lambdaQueryWrapper.in(CounsellingInfo::getUserId,customerIds);
            }
        }
        Page<CounsellingInfo> page = this.counsellingInfoService.page(PageFactory.defaultPage(), lambdaQueryWrapper);
        if (CollectionUtil.isNotEmpty(page.getRecords())){
            List<Long> counseIds = page.getRecords().stream().map(CounsellingInfo::getId).collect(Collectors.toList());
            QueryWrapper<CounsellingOrder> orderQueryWrapper = new QueryWrapper<CounsellingOrder>().select("counselling_info_id counsellingInfoId,count(1) num ");
            //查询是否首次咨询
            orderQueryWrapper.lambda().eq(CounsellingOrder::getUserId,LoginContext.me().getLoginUser().getUserId()).in(CounsellingOrder::getStatusFlag,1,2).in(CounsellingOrder::getCounsellingInfoId,counseIds)
                    .eq(CounsellingOrder::getOrderType,1).groupBy(CounsellingOrder::getCounsellingInfoId).having(" num > 0 ");
            List<Map<String,Object>> mapList = this.counsellingOrderService.listMaps(orderQueryWrapper);
            Map<Long,Object> fristMap = new HashMap<>();
            if (CollectionUtil.isNotEmpty(mapList)){
 
                mapList.stream().forEach(stringObjectMap -> {
                    fristMap.put(Long.parseLong(stringObjectMap.get("counsellingInfoId").toString()),stringObjectMap.get("num"));
                });
            }
            //查询标签总条数
            List<CounsellingTag> counsellingTags = this.counsellingTagService.list(new LambdaQueryWrapper<CounsellingTag>()
                    .select(CounsellingTag::getId,CounsellingTag::getTagName));
            List<Long> custommerIds = page.getRecords().stream().map(CounsellingInfo::getUserId).collect(Collectors.toList());
            //查询客户ids
            List<Customer> customerList = this.customerService.list(new LambdaQueryWrapper<Customer>().select(Customer::getCustomerId,Customer::getNickName).in(Customer::getCustomerId,custommerIds));
            //查询套餐最低价
            List<Map<String,Object>> lowMapList = this.counsellingSetMealService.listMaps(new QueryWrapper<CounsellingSetMeal>().select(" counselling_info_id counsellingInfoId,IFNULL(min(price),0) price ").lambda().in(CounsellingSetMeal::getCounsellingInfoId,counseIds)
                    .eq(CounsellingSetMeal::getSetMealType,1).eq(CounsellingSetMeal::getIsDelete,0)
                    .groupBy(CounsellingSetMeal::getCounsellingInfoId));
 
            List<CounsellinginfoResponseDTO> counsellinginfoResponseDTOS = BeanUtil.copyToList(page.getRecords(),CounsellinginfoResponseDTO.class, CopyOptions.create());
            counsellinginfoResponseDTOS.stream().forEach(counsellinginfoResponseDTO -> {
                if (fristMap.get(counsellinginfoResponseDTO.getId()) != null){
                    counsellinginfoResponseDTO.setIsFirstBuy(true);
                }
                if (StrUtil.isNotBlank(counsellinginfoResponseDTO.getCounsellingTagIds())){
                    List<String> counsellingTagList = Arrays.asList(counsellinginfoResponseDTO.getCounsellingTagIds().split(","));
                    String tagNames = counsellingTags.stream().filter(cou -> counsellingTagList.contains(cou.getId().toString())).map(CounsellingTag::getTagName).collect(Collectors.joining(","));
                    //获取课程标签名称
//                    LambdaQueryWrapper<CounsellingTag> counsellingTagLambdaQueryWrapper = new QueryWrapper<CounsellingTag>().select(" GROUP_CONCAT(tag_name)  tagName ").lambda();
//                    Map<String,Object> map = counsellingTagService.getMap(counsellingTagLambdaQueryWrapper.in(CounsellingTag::getId,counsellinginfoResponseDTO.getCounsellingTagIds().split(",")));
//                    if (ObjectUtil.isNotEmpty(map)){
                        counsellinginfoResponseDTO.setCounsellingTagNames(tagNames);
//                    }
                }
                counsellinginfoResponseDTO.setPersonalProfile(null);
 
                counsellinginfoResponseDTO.setNikeName(customerList.stream().filter(cus -> counsellinginfoResponseDTO.getUserId().longValue() == cus.getCustomerId().longValue()).findFirst().get().getNickName());
 
//                BigDecimal lowPrice = this.counsellingSetMealService.getObj(new QueryWrapper<CounsellingSetMeal>().select(" counselling_info_id counsellingInfoId,IFNULL(min(price),0) price ").lambda().eq(CounsellingSetMeal::getCounsellingInfoId,counsellinginfoResponseDTO.getId())
//                        .eq(CounsellingSetMeal::getSetMealType,1).eq(CounsellingSetMeal::getIsDelete,0),Convert::toBigDecimal);
 
 
                if (CollectionUtil.isNotEmpty(lowMapList)){
                    lowMapList.stream().forEach(stringObjectMap -> {
                        if (stringObjectMap.get("counsellingInfoId") != null && stringObjectMap.get("counsellingInfoId").toString().equals(counsellinginfoResponseDTO.getId().toString()) ){
                            counsellinginfoResponseDTO.setLowPrice(new BigDecimal(stringObjectMap.get("price").toString()));
                        }
                    });
                    if (counsellinginfoResponseDTO.getLowPrice() == null){
                        counsellinginfoResponseDTO.setLowPrice(new BigDecimal(0));
                    }
                }
 
 
            });
 
            return  new SuccessResponseData<>(PageResultFactory.createPageResult(counsellinginfoResponseDTOS,page.getTotal(), Convert.toInt(page.getSize()),Convert.toInt(page.getCurrent())));
        }
 
        return  new SuccessResponseData<>(PageResultFactory.createPageResult(new ArrayList<CounsellinginfoResponseDTO>(),page.getTotal(), Convert.toInt(page.getSize()),Convert.toInt(page.getCurrent())));
    }
 
 
 
 
    @ApiOperation("获取指定咨询师近多少天的特殊时间配置")
    @GetResource (name = "获取指定咨询师近多少天的特殊时间配置", path = {"/counsellingInfo/getCounsellingSpecialTimeConfigByCounsellingInfoId","/worker/counsellingInfo/getCounsellingSpecialTimeConfigByCounsellingInfoId"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "counsellingInfoId", value = "咨询师id", dataTypeClass = Long.class, paramType = "query"),
            @ApiImplicitParam(name = "dayNum", value = "最近多少天的特殊时间配置",defaultValue = "7",dataTypeClass = Integer.class, paramType = "query")
    })
    public ResponseData<List<CounsellingSpecialTimeConfig>> getCounsellingSpecialTimeConfigByCounsellingInfoId(Long counsellingInfoId,Integer dayNum){
        Date beginDate = new Date();
        if (dayNum == null){
          dayNum = 7;
        }
        Date endDate = DateUtil.offsetDay(beginDate,dayNum);
        List<CounsellingSpecialTimeConfig> counsellingSpecialTimeConfigList = this.counsellingSpecialTimeConfigService.list(new LambdaQueryWrapper<CounsellingSpecialTimeConfig>().ge(CounsellingSpecialTimeConfig::getSpecialDay,DateUtil.formatDate(beginDate))
                .le(CounsellingSpecialTimeConfig::getSpecialDay,DateUtil.formatDate(endDate)).eq(CounsellingSpecialTimeConfig::getCounsellingInfoId,counsellingInfoId));
        return new SuccessResponseData<>(counsellingSpecialTimeConfigList);
    }
 
 
    @ApiOperation("获取指定咨询师近多少天的预约剩余人数")
    @GetResource (name = "获取指定咨询师近多少天的预约剩余人数", path = {"/counsellingInfo/getReservationTimeTable","/worker/counsellingInfo/getReservationTimeTable"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "counsellingInfoId", value = "咨询师id", dataTypeClass = Long.class, paramType = "query"),
            @ApiImplicitParam(name = "dayNum", value = "最近多少天的预约",defaultValue = "7",dataTypeClass = Integer.class, paramType = "query")
    })
    public ResponseData<List<CounsellingReservationDTO>> getReservationTimeTable(Long counsellingInfoId, Integer dayNum){
        if (dayNum == null){
            dayNum =7 ;
        }
        Date nowDate = new Date();
        Date beginTime = DateUtil.offsetHour(nowDate,2);
        //当天时间date
        String beginTimeStr = DateUtil.formatDate(beginTime);
        int nowDay = DateUtil.dayOfWeekEnum(nowDate).getIso8601Value();
        List<CounsellingReservationDTO> list = new ArrayList<>();
        //获取最近几天的时间排表
        List<DateTime> dateList = DateUtil.rangeToList(nowDate,DateUtil.offsetDay(new Date(),dayNum), DateField.DAY_OF_YEAR);
        dateList.forEach(dateTime -> {
            CounsellingReservationDTO counsellingReservationDTO = new CounsellingReservationDTO();
            //查询是否有特殊时间点
            long count = this.counsellingSpecialTimeConfigService.count(new LambdaQueryWrapper<CounsellingSpecialTimeConfig>()
                    .eq(CounsellingSpecialTimeConfig::getSpecialDay,dateTime.toDateStr()).eq(CounsellingSpecialTimeConfig::getCounsellingInfoId,counsellingInfoId)
                    .ne(CounsellingSpecialTimeConfig::getIsCancelDay,1));
            //查询普通时间点
            int day = DateUtil.dayOfWeekEnum(dateTime).getIso8601Value();
            //查询是否取消当天
            long cancleCount = this.counsellingSpecialTimeConfigService.count(new LambdaQueryWrapper<CounsellingSpecialTimeConfig>()
                    .eq(CounsellingSpecialTimeConfig::getSpecialDay,dateTime.toDateStr()).eq(CounsellingSpecialTimeConfig::getCounsellingInfoId,counsellingInfoId)
                    .eq(CounsellingSpecialTimeConfig::getIsCancelDay,1));
            if (cancleCount > 0l){
                counsellingReservationDTO.setRemainingNum(0l);
            }else{
                //查询预约记录
                long reservCount = 0l;
//                        this.counsellingOrderReservationService.count(new LambdaQueryWrapper<CounsellingOrderReservation>().eq(CounsellingOrderReservation::getCounsellingInfoId,counsellingInfoId)
//                        .ge(CounsellingOrderReservation::getReservationBeginTime,DateUtil.beginOfDay(dateTime)).le(CounsellingOrderReservation::getReservationEndTime,DateUtil.endOfDay(dateTime))
//                        .in(CounsellingOrderReservation::getStauts,1,2,3,4));
                //查询普通时间点
                List<CounsellingTimeConfig> timeConfigList = this.counsellingTimeConfigService.list(new LambdaQueryWrapper<CounsellingTimeConfig>().eq(CounsellingTimeConfig::getCounsellingInfoId,counsellingInfoId).eq(CounsellingTimeConfig::getWeekDay,day)
                );
                long dayCount = 0l;
                if (CollectionUtil.isNotEmpty(timeConfigList)){
 
                    for (CounsellingTimeConfig counsellingTimeConfig:timeConfigList){
                        if (counsellingTimeConfig.getWeekDay().intValue() == nowDay && beginTimeStr.equals(dateTime.toDateStr())){
                            Date beginTimeDate = DateUtil.parseDateTime(DateUtil.formatDate(new Date())+" "+counsellingTimeConfig.getBeginTimePoint()+":00");
                            //判断时间是否
                            if (beginTimeDate.getTime() < beginTime.getTime() && beginTimeDate.getTime() >= nowDate.getTime()){
                                continue;
                            }
                            if (beginTimeDate.getTime() <=   nowDate.getTime()){
                                continue;
                            }
                        }
 
                        dayCount++;
                    }
 
                }
                counsellingReservationDTO.setRemainingNum(dayCount +count-reservCount);
            }
 
 
//            //查询预约记录
//            long reservCount = this.counsellingOrderReservationService.count(new LambdaQueryWrapper<CounsellingOrderReservation>().eq(CounsellingOrderReservation::getCounsellingInfoId,counsellingInfoId)
//                    .ge(CounsellingOrderReservation::getReservationBeginTime,DateUtil.beginOfDay(dateTime)).le(CounsellingOrderReservation::getReservationEndTime,DateUtil.endOfDay(dateTime))
//                    .in(CounsellingOrderReservation::getStauts,1,2,3));
//            if (count > 0){
//                counsellingReservationDTO.setRemainingNum(count -reservCount);
//            }else{
//                //查询普通时间点
//                long dayCount = this.counsellingTimeConfigService.count(new LambdaQueryWrapper<CounsellingTimeConfig>().eq(CounsellingTimeConfig::getCounsellingInfoId,counsellingInfoId).eq(CounsellingTimeConfig::getWeekDay,day));
//                counsellingReservationDTO.setRemainingNum(dayCount -reservCount);
//            }
            counsellingReservationDTO.setCounsellingInfoId(counsellingInfoId);
            counsellingReservationDTO.setReservationDay(dateTime);
            list.add(counsellingReservationDTO);
        });
        return new SuccessResponseData<>(list);
    }
 
 
 
    /**
     * 获取咨询订单预约记录列表(分页)
     */
    @ApiOperation("查看日程(分页)")
    @GetResource(name = "查看日程(分页)", path = "/counsellingInfo/pageCounsellingOrderReservation", requiredPermission = false)
    public ResponseData<PageResult<CounsellingOrderReservation>> pageCounsellingOrderReservation(CounsellingOrderReservationRequestDTO counsellingOrderReservationRequestDTO) {
        Page<CounsellingOrderReservation> page = this.counsellingOrderReservationService.findPage(PageFactory.defaultPage(), counsellingOrderReservationRequestDTO);
        return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
    }
 
    @ApiOperation("获取指定咨询师近多少天的预约记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "counsellingInfoId", value = "咨询师id", dataTypeClass = Long.class, paramType = "query"),
            @ApiImplicitParam(name = "dayNum", value = "最近多少天的预约",defaultValue = "7",dataTypeClass = Integer.class, paramType = "query")
    })
    @GetResource(name = "获取指定咨询师近多少天的预约记录", path = {"/counsellingInfo/getCounsellingOrderReservationByCounsellingInfoId","/worker/counsellingInfo/getCounsellingOrderReservationByCounsellingInfoId"}, requiredPermission = false)
    public ResponseData<List<CounsellingOrderReservationResponseDTO>> getCounsellingOrderReservationByCounsellingInfoId(Long counsellingInfoId,Integer dayNum) {
        CounsellingOrderReservationRequestDTO counsellingOrderReservationRequestDTO = new CounsellingOrderReservationRequestDTO();
        counsellingOrderReservationRequestDTO.setCounsellingInfoId(counsellingInfoId);
        counsellingOrderReservationRequestDTO.setPageNo(1);
        counsellingOrderReservationRequestDTO.setPageSize(Integer.MAX_VALUE);
        counsellingOrderReservationRequestDTO.setSearchEndTime(DateUtil.endOfDay(new Date()).toString());
        if(dayNum == null){
            dayNum = 7;
        }
        counsellingOrderReservationRequestDTO.setSearchBeginTime(DateUtil.offsetDay(DateUtil.beginOfDay(new Date()),-dayNum).toString());
        Page<CounsellingOrderReservation> page = this.counsellingOrderReservationService.findPage(PageFactory.defaultPage(counsellingOrderReservationRequestDTO), counsellingOrderReservationRequestDTO);
        if (CollectionUtil.isNotEmpty(page.getRecords())){
            return new SuccessResponseData<>(BeanUtil.copyToList(page.getRecords(),CounsellingOrderReservationResponseDTO.class));
        }
        return new SuccessResponseData<>();
    }
 
 
    @ApiOperation("获取指定咨询师当天之后多少天的预约记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "counsellingInfoId", value = "咨询师id", dataTypeClass = Long.class, paramType = "query"),
            @ApiImplicitParam(name = "dayNum", value = "多少天后的预约",defaultValue = "7",dataTypeClass = Integer.class, paramType = "query")
    })
    @GetResource(name = "获取指定咨询师当天之后多少天的预约记录", path = {"/counsellingInfo/getCounsellingOrderReservationByCounsellingInfoIdForAfterDay","/worker/counsellingInfo/getCounsellingOrderReservationByCounsellingInfoIdForAfterDay"}, requiredPermission = false)
    public ResponseData<List<CounsellingOrderReservationResponseDTO>> getCounsellingOrderReservationByCounsellingInfoIdForAfterDay(Long counsellingInfoId,Integer dayNum) {
        CounsellingOrderReservationRequestDTO counsellingOrderReservationRequestDTO = new CounsellingOrderReservationRequestDTO();
        counsellingOrderReservationRequestDTO.setCounsellingInfoId(counsellingInfoId);
        counsellingOrderReservationRequestDTO.setPageNo(1);
        counsellingOrderReservationRequestDTO.setPageSize(Integer.MAX_VALUE);
        counsellingOrderReservationRequestDTO.setSearchBeginTime(DateUtil.beginOfDay(new Date()).toString());
        if(dayNum == null){
            dayNum = 7;
        }
        counsellingOrderReservationRequestDTO.setSearchEndTime(DateUtil.offsetDay(DateUtil.endOfDay(new Date()),dayNum).toString());
        Page<CounsellingOrderReservation> page = this.counsellingOrderReservationService.findPage(PageFactory.defaultPage(counsellingOrderReservationRequestDTO), counsellingOrderReservationRequestDTO);
        if (CollectionUtil.isNotEmpty(page.getRecords())){
            return new SuccessResponseData<>(BeanUtil.copyToList(page.getRecords(),CounsellingOrderReservationResponseDTO.class));
        }
        return new SuccessResponseData<>();
    }
    
    @ApiOperation("获取指定咨询师星期时间点配置")
    @GetResource(name = "获取指定咨询师星期时间点配置", path = {"/counsellingInfo/getCounsellingTimeConfigByCounsellingInfoId","/worker/counsellingInfo/getCounsellingTimeConfigByCounsellingInfoId"}, requiredPermission = false)
    public ResponseData<List<CounsellingTimeConfig>> getCounsellingTimeConfigByCounsellingInfoId(Long counsellingInfoId){
        List<CounsellingTimeConfig> counsellingTimeConfigs = this.counsellingTimeConfigService.list(new LambdaQueryWrapper<CounsellingTimeConfig>().eq(CounsellingTimeConfig::getCounsellingInfoId,counsellingInfoId));
        return new SuccessResponseData<>(counsellingTimeConfigs);
        
    }
 
 
    @ApiOperation("添加合同签订")
    @PostResource(name = "添加合同签订", path = "/contractRecord/add")
    public ResponseData<?> add(@RequestBody ContractRecord contractRecord) {
        contractRecord.setUserId(LoginContext.me().getLoginUser().getUserId());
        //查询是否已存在合约,存在就更新
        ContractRecord contractRecord1 = this.contractRecordService.getOne(new LambdaQueryWrapper<ContractRecord>().eq(ContractRecord::getUserId,LoginContext.me().getLoginUser().getUserId()));
        if (contractRecord1 != null){
            contractRecord1.setContractContent(contractRecord.getContractContent());
            contractRecord1.setSignUrl(contractRecord.getSignUrl());
            contractRecord1.setSigningTime(new Date());
            this.contractRecordService.updateById(contractRecord1);
        }else{
            contractRecord.setSigningTime(new Date());
            this.contractRecordService.save(contractRecord);
        }
        return new SuccessResponseData<>();
    }
 
    @ApiOperation("查询签订合同")
    @GetResource(name = "查询签订合同", path = "/contractRecord/info")
    public ResponseData<ContractRecord> info(Long userId) {
        if (userId == null){
            userId = LoginContext.me().getLoginUser().getUserId();
        }
        //查询是否已存在合约,存在就更新
        ContractRecord contractRecord1 = this.contractRecordService.getOne(new LambdaQueryWrapper<ContractRecord>().eq(ContractRecord::getUserId,userId));
 
        return new SuccessResponseData<ContractRecord>(contractRecord1);
    }
 
    @ApiOperation("创建咨询订单信息")
    @PostResource(name = "创建咨询订单信息", path = "/counsellingOrder/createCounsellingOrder")
    public ResponseData<CounsellingOrder> createCounsellingOrder(@RequestBody CreateCounsellingOrderRequest counsellingOrderRequest) {
        counsellingOrderRequest.setIsBack(false);
        counsellingOrderRequest.setUserId(LoginContext.me().getLoginUser().getUserId());
        CounsellingInfo counsellingInfo = this.counsellingInfoService.getOne(new LambdaQueryWrapper<CounsellingInfo>().select(CounsellingInfo::getId,CounsellingInfo::getListingStatus).eq(CounsellingInfo::getId,counsellingOrderRequest.getCounsellingInfoId()));
        if (counsellingInfo != null){
            if(counsellingInfo.getListingStatus().intValue() != 1){
                return new ErrorResponseData<>("咨询师已经下架,无法进行购买,请联系咨询顾问");
            }
        }
        Customer customer = this.customerService.getById(LoginContext.me().getLoginUser().getUserId());
        if (customer.getStatusFlag() != null &&customer.getStatusFlag() !=1){
            return new ErrorResponseData<>("账号已被冻结或者被注销,无法进行下单");
        }
 
        if (counsellingOrderRequest.getFirstAppointmentDate() != null && counsellingOrderRequest.getOrderType().intValue() ==1){
            //验证未支付的首次咨询订单
            long counselllingCount = this.counsellingOrderService.count(new LambdaQueryWrapper<CounsellingOrder>().eq(CounsellingOrder::getFirstAppointmentDate,DateUtil.formatDate(counsellingOrderRequest.getFirstAppointmentDate()))
                    .eq(CounsellingOrder::getFirstAppointmentTimes,counsellingOrderRequest.getFirstAppointmentTimes()).in(CounsellingOrder::getStatusFlag,0,1,2).eq(CounsellingOrder::getIsDelete,0).eq(CounsellingOrder::getCounsellingInfoId,counsellingOrderRequest.getCounsellingInfoId()));
            if (counselllingCount >0){
                throw new ServiceException("当前时间段已预约,请选择其他时间段!");
            }
        }
 
        CounsellingOrder counsellingOrder = this.counsellingOrderService.createCounsellingOrder(counsellingOrderRequest);
        return new SuccessResponseData<>(counsellingOrder);
    }
 
 
 
    @ApiOperation("咨询订单预约")
    @PostResource(name = "咨询订单预约", path = "/counsellingOrderReservation/saveCounsellingOrderReservation")
    public ResponseData<CounsellingOrderReservation> saveCounsellingOrderReservation(@RequestBody CounsellingReservationRequest counsellingReservationRequest) throws ParseException {
 
        //查询咨询师当天是否取消预约
        CounsellingSpecialTimeConfig specialTimeConfig = this.counsellingSpecialTimeConfigService.getOne(new LambdaQueryWrapper<CounsellingSpecialTimeConfig>().eq(CounsellingSpecialTimeConfig::getCounsellingInfoId,counsellingReservationRequest.getCounsellingId())
                .eq(CounsellingSpecialTimeConfig::getSpecialDay,counsellingReservationRequest.getDayTime()).eq(CounsellingSpecialTimeConfig::getIsCancelDay,1));
        if (specialTimeConfig != null){
            throw new ServiceException("当天咨询已取消,无法进行预约,请群内联系咨询顾问!");
        }
        //判断是否有用户咨询师信息
        CounsellingUser counsellingUserOld = this.counsellingUserService.getOne(new LambdaQueryWrapper<CounsellingUser>().eq(CounsellingUser::getCounsellingInfoId,counsellingReservationRequest.getCounsellingId())
                .eq(CounsellingUser::getUserId,LoginContext.me().getLoginUser().getUserId()));
        if(counsellingUserOld.getIsFirstAppointment().intValue() != 1){
            if (counsellingUserOld != null && counsellingUserOld.getResidueClassHours() != null && counsellingUserOld.getResidueClassHours().intValue() <= 0){
                throw new ServiceException("预约失败,当前剩余课时不足,请群内联系咨询顾问!");
            }
            if (counsellingUserOld != null && counsellingUserOld.getResidueClassHours() != null && counsellingUserOld.getResidueClassHours().intValue() > 0){
                int waitHour = this.counsellingOrderReservationService.getObj(new QueryWrapper<CounsellingOrderReservation>().select("IFNULL(sum(consume_course_hour),0) hour").lambda().eq(CounsellingOrderReservation::getCounsellingInfoId,counsellingReservationRequest.getCounsellingId())
                        .eq(CounsellingOrderReservation::getUserId,LoginContext.me().getLoginUser().getUserId()).in(CounsellingOrderReservation::getStauts,1,2,3),Convert::toInt);
                if (counsellingUserOld.getResidueClassHours().intValue() - waitHour <= 0){
                    throw new ServiceException("预约失败,当前剩余课时不足,请群内联系咨询顾问!");
                }
 
            }
        }
 
 
        CounsellingOrder counsellingOrder = null;
        if (counsellingReservationRequest.getCounsellingOrderId() == null){
            counsellingOrder = this.counsellingOrderService.getOne(new LambdaQueryWrapper<CounsellingOrder>().eq(CounsellingOrder::getCounsellingInfoId,counsellingReservationRequest.getCounsellingId())
                    .eq(CounsellingOrder::getUserId,LoginContext.me().getLoginUser().getUserId()).eq(CounsellingOrder::getStatusFlag,1).orderByDesc(CounsellingOrder::getCreateTime).last( " limit 1"));
        }else{
            counsellingOrder = this.counsellingOrderService.getById(counsellingReservationRequest.getCounsellingOrderId());
 
        }
        if (counsellingOrder == null){
            throw new ServiceException("没有在咨询的订单,无法进行预约!");
        }
        String key = "counsel:" + counsellingReservationRequest.getCounsellingId()+"_"+counsellingReservationRequest.getDayTime()+"_"+counsellingReservationRequest.getTimePoint();
        RLock lock = redissonClient.getLock(key);
        boolean tryLock = false;
        try {
            log.info("咨询key:"+key+",userId:"+counsellingOrder.getUserId());
            tryLock = lock.tryLock(20, TimeUnit.SECONDS);
            if (!tryLock) {
                throw new ServiceException("当前时间段已预约,请选择其他时间段!");
            }
 
        //验证未支付的首次咨询订单
        long counselllingCount = this.counsellingOrderService.count(new LambdaQueryWrapper<CounsellingOrder>().eq(CounsellingOrder::getFirstAppointmentDate,counsellingReservationRequest.getDayTime())
                .eq(CounsellingOrder::getFirstAppointmentTimes,counsellingReservationRequest.getTimePoint()).in(CounsellingOrder::getStatusFlag,0,1,2).eq(CounsellingOrder::getIsDelete,0).eq(CounsellingOrder::getCounsellingInfoId,counsellingReservationRequest.getCounsellingId()));
        if (counselllingCount >0){
            throw new ServiceException("当前时间段已预约,请选择其他时间段!");
        }
 
        CounsellingOrderReservation counsellingOrderReservation = new CounsellingOrderReservation();
        counsellingOrderReservation.setCounsellingOrderId(counsellingOrderReservation.getCounsellingOrderId());
        counsellingOrderReservation.setCounsellingInfoId(counsellingOrder.getCounsellingInfoId());
        counsellingOrderReservation.setCompanionUserId(counsellingOrder.getCompanionUserId());
        counsellingOrderReservation.setConsultantUserId(counsellingOrder.getConsultantUserId());
        counsellingOrderReservation.setCreateTime(new Date());
        counsellingOrderReservation.setUserId(counsellingOrder.getUserId());
        counsellingOrderReservation.setCounsellingOrderId(counsellingOrder.getId());
        //跟进结束和开始预约时间设置耗时
        if (StrUtil.isNotBlank(counsellingReservationRequest.getTimePoint()) && StrUtil.isNotBlank(counsellingReservationRequest.getDayTime())){
            String beginTime = counsellingReservationRequest.getDayTime()+" "+counsellingReservationRequest.getTimePoint().split("-")[0]+":00";
            counsellingOrderReservation.setReservationBeginTime(DateUtil.parseDateTime(beginTime));
            String endTime = counsellingReservationRequest.getDayTime()+" "+counsellingReservationRequest.getTimePoint().split("-")[1]+":00";
            counsellingOrderReservation.setReservationEndTime(DateUtil.parseDateTime(endTime));
            counsellingOrderReservation.setConsumeCourseHour((int) Math.ceil((counsellingOrderReservation.getReservationEndTime().getTime() - counsellingOrderReservation.getReservationBeginTime().getTime())/3600000d));
 
            if (counsellingUserOld != null && counsellingUserOld.getResidueClassHours() != null && counsellingUserOld.getResidueClassHours().intValue() > 0){
                if (counsellingUserOld.getResidueClassHours().intValue() < counsellingOrderReservation.getConsumeCourseHour().intValue() ){
                    throw new ServiceException("预约失败,当前剩余课时不足,请群内联系咨询顾问!");
                }
 
            }
            //验证是否重复预约
            long count = this.counsellingOrderReservationService.count(new LambdaQueryWrapper<CounsellingOrderReservation>().eq(CounsellingOrderReservation::getReservationBeginTime,counsellingOrderReservation.getReservationBeginTime())
                    .eq(CounsellingOrderReservation::getReservationEndTime,counsellingOrderReservation.getReservationEndTime()).eq(CounsellingOrderReservation::getCounsellingInfoId,counsellingOrderReservation.getCounsellingInfoId())
                    .eq(CounsellingOrderReservation::getUserId,counsellingOrderReservation.getUserId()).notIn(CounsellingOrderReservation::getStauts,5,6));
            if (count >0){
                return new ErrorResponseData<>("500","当前时间段已预约,请选择其他时间段!");
            }
        }
        if (counsellingOrder.getOrderType().intValue() ==1){
            counsellingOrderReservation.setStauts(2);
            counsellingOrderReservation.setReservationType(1);
            this.counsellingOrderReservationService.save(counsellingOrderReservation);
            //更新订单的首次预约时间
            counsellingOrder.setFirstAppointmentDate(DateUtil.parseDate(counsellingReservationRequest.getDayTime()));
            counsellingOrder.setFirstAppointmentTimes(counsellingReservationRequest.getTimePoint());
            counsellingUserOld.setFirstAppointmentDate(counsellingOrder.getFirstAppointmentDate());
            counsellingUserOld.setFirstAppointmentTimes(counsellingOrder.getFirstAppointmentTimes());
            if (counsellingReservationRequest.getCustomerUpdateRequest() != null){
                counsellingOrder.setUserInfoJson(JSONUtil.toJsonStr(counsellingReservationRequest.getCustomerUpdateRequest()));
                counsellingOrder.setPhone(counsellingReservationRequest.getCustomerUpdateRequest().getLinkPhone());
                counsellingUserOld.setPhone(counsellingOrder.getPhone());
                counsellingUserOld.setUserInfoJson(counsellingOrder.getUserInfoJson());
            }
            counsellingUserOld.setIsFirstAppointment(2);
            this.counsellingOrderService.updateById(counsellingOrder);
            this.counsellingUserService.updateById(counsellingUserOld);
 
            CounsellingInfo counsellingInfo = this.counsellingInfoService.getById(counsellingOrder.getCounsellingInfoId());
 
            //将此条消息加入到可聊天的表中t_mental_appointment
            MentalAppointment mentalAppointment = MentalAppointment.builder()
                    .userId(counsellingOrder.getUserId())
                    .type("1")
                    .statusFlag(1)
                    .appointmentDay(new SimpleDateFormat("yyyy-MM-dd").parse(counsellingReservationRequest.getDayTime()))
                    .beginTimePoint(counsellingReservationRequest.getTimePoint().split("-")[0])
                    .endTimePoint(counsellingReservationRequest.getTimePoint().split("-")[1])
                    .workerId(counsellingInfo.getUserId())
                    .build();
            // 用户信息
            CustomerInfo customerInfo = customerService.getCustomerInfoById(counsellingOrder.getUserId());
            mentalAppointment.setUserName(customerInfo.getRealName());
            mentalAppointment.setPhone(customerInfo.getLinkPhone());
            mentalAppointmentService.save(mentalAppointment);
 
            // 发送IM消息
            ImPushDataDTO pushData1 = ImPushDataDTO.builder()
                    .type(ImPushTypeEnum.C_TO_W_IM_1V1_START_CONSULT_FIRST.getCode())
                    .title(ImPushTypeEnum.C_TO_W_IM_1V1_START_CONSULT_FIRST.getName())
                    .content("预约成功"+",请注意预约时间:"+counsellingReservationRequest.getDayTime()+counsellingReservationRequest.getTimePoint())
//                    .content("预约成功!")
                    .objId(ObjUtil.toString(counsellingInfo.getId()))
                    .data1(ObjUtil.toString(counsellingOrder.getUserId()))
                    .data2(ObjUtil.toString(counsellingInfo.getUserId()))
                    .build();
            imBizService.messageSendPrivate(
                    ObjUtil.toString(counsellingOrder.getUserId()),
                    new String[]{ObjUtil.toString(counsellingInfo.getUserId())},
                    pushData1);
 
            // 推送消息内容
            String pushContent = "你的预约("+DateUtil.formatDate(counsellingOrder.getFirstAppointmentDate())+" "+counsellingOrder.getFirstAppointmentTimes()+")已确认,请按时参加";
            // IM推送数据json
            ImPushDataDTO pushData = ImPushDataDTO.builder()
                    .type(ImPushTypeEnum.S_TO_W_TIP_CONSULT_PAY_SUCCESS.getCode())
                    .objId(ObjUtil.toString(counsellingOrderReservation.getId()))
                    .title("通知")
                    .data1(ObjUtil.toString(counsellingInfo.getUserId()))
                    .data2(ObjUtil.toString(counsellingOrder.getUserId()))
                    .content(pushContent)
//                    .extra("("+DateUtil.formatDate(counsellingOrder.getFirstAppointmentDate())+" "+counsellingOrder.getFirstAppointmentTimes()+")")
                    .build();
            // 发送首次预约
            imBizService.messageSendSystem(counsellingOrderReservation.getUserId()+"", new String[]{counsellingOrderReservation.getUserId()+""}, pushData, ImUserTypeEnum.USER, null, true);
 
 
            //给咨询师发消息
            Customer customerOld = this.customerService.getById(counsellingOrderReservation.getUserId());
 
            String pushContent1 = "你有新的预约,请注意查收。预约用户:"+customerOld.getNickName()+",预约时间:"+DateUtil.formatDate(counsellingOrder.getFirstAppointmentDate())+" "+counsellingOrder.getFirstAppointmentTimes();
//                    +"预约时间:"+counsellingOrder.getEffectiveEndTime()+"~"+counsellingOrder.getEffectiveEndTime();
            // IM推送数据json
            ImPushDataDTO pushData2 = ImPushDataDTO.builder()
                    .type(ImPushTypeEnum.S_TO_W_TIP_CONSULT_PAY_GROUP_SUCCESS.getCode())
                    .objId(ObjUtil.toString(counsellingInfo.getUserId()))
                    .title("通知")
                    .content(pushContent1)
                    .data1(ObjUtil.toString(counsellingOrder.getUserId()))
                    .data2(ObjUtil.toString(counsellingInfo.getUserId()))
//                    .extra("去查看。")
                    .build();
            // 发送预约提示
            imBizService.messageSendSystem(counsellingOrder.getUserId()+"", new String[]{counsellingInfo.getUserId()+""}, pushData2, ImUserTypeEnum.WORKER, PostIdEnum.PO_22, true);
        }else{
            counsellingOrderReservation.setStauts(1);
            counsellingOrderReservation.setReservationType(2);
            this.counsellingOrderReservationService.save(counsellingOrderReservation);
            CounsellingInfo counsellingInfo = this.counsellingInfoService.getById(counsellingOrder.getCounsellingInfoId());
 
            // 推送消息内容
            String pushContent = "你有新的预约申请等待审核,";
            // IM推送数据json
            ImPushDataDTO pushData = ImPushDataDTO.builder()
                    .type(ImPushTypeEnum.S_TO_W_TIP_CONSULT_AUDIT_APPOINTMENT_SUCCESS.getCode())
                    .objId(ObjUtil.toString(counsellingOrderReservation.getId()))
                    .title("通知")
                    .content(pushContent)
//                    .extra("去查看。")
                    .build();
            // 发送预约提示
            imBizService.messageSendSystem(counsellingOrderReservation.getUserId()+"", new String[]{counsellingInfo.getUserId()+""}, pushData, ImUserTypeEnum.WORKER, PostIdEnum.PO_22, true);
        }
        if (counsellingReservationRequest.getCustomerUpdateRequest() != null){
            //更新用户信息
            Customer customer = BeanUtil.toBean(counsellingReservationRequest.getCustomerUpdateRequest(), Customer.class);
            customer.setCustomerId(LoginContext.me().getLoginUser().getUserId());
            // 修改用户信息
            customerService.updateCustomerRemoveCache(customer);
        }
 
            try {
 
            CustomerUpdateRequest customerUpdateRequest = counsellingReservationRequest.getCustomerUpdateRequest();
            Customer customer = new Customer();
            BeanUtil.copyProperties(customerUpdateRequest,customer);
                LoginUser loginUser = LoginContext.me().getLoginUser();
                customer.setCustomerId(loginUser.getUserId());
            customerService.updateById(customer);
            }catch (Exception e){
                e.printStackTrace();
                log.info("编辑用户报错");
            }
            return new SuccessResponseData<>(counsellingOrderReservation);
        }catch (Exception ex){
            log.error("咨询预约服务异常",ex.getStackTrace());
            throw new ServiceException("当前时间段已在进行预约,请稍后再试!");
        }finally {
            if(tryLock){
                lock.unlock();
            }
        }
 
  }
 
 
   @ApiOperation("根据咨询订单id查询咨询信息")
    @GetResource(name = "根据咨询订单id查询咨询信息", path = {"/counsellingOrder/getCounsellingOrderInfoById","/worker/counsellingOrder/getCounsellingOrderInfoById"})
    public ResponseData<CounsellingOrderResponseDTO> getCounsellingOrderInfoById(Long counsellingOrderId){
        CounsellingOrder counsellingOrder = this.counsellingOrderService.getById(counsellingOrderId);
        CounsellingOrderResponseDTO counsellingOrderResponseDTO = BeanUtil.copyProperties(counsellingOrder,CounsellingOrderResponseDTO.class);
        CounsellingInfo counsellingInfo = this.counsellingInfoService.getById(counsellingOrder.getCounsellingInfoId());
        Customer customer = this.customerService.getById(counsellingInfo.getUserId());
        counsellingOrderResponseDTO.setCounsellingName(customer.getNickName());
        return new SuccessResponseData<>(counsellingOrderResponseDTO);
 
    }
 
 
//    @ApiOperation("分页查询指定条件的预约记录,指定咨询订单")
//    @GetResource(name = "分页查询指定条件的预约记录,指定咨询订单", path = "/counsellingOrderReservation/getCounsellingOrderReservationForPage", requiredPermission = false)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "pageNo", value = "分页:第几页(从1开始)", dataTypeClass = Integer.class, paramType = "query"),
//            @ApiImplicitParam(name = "pageSize", value = "分页:每页大小(默认10)", dataTypeClass = Integer.class, paramType = "query"),
//            @ApiImplicitParam(name = "counsellingOrderId", value = "咨询订单id", dataTypeClass = Integer.class, paramType = "query")
//    } )
//    public ResponseData<PageResult<CounsellingOrderReservation>> getCounsellingOrderReservationForPage(Integer pageNo, Integer pageSize,Long counsellingOrderId) {
//        CounsellingOrderReservationRequestDTO counsellingOrderReservationRequestDTO = new CounsellingOrderReservationRequestDTO();
//        counsellingOrderReservationRequestDTO.setCounsellingOrderId(counsellingOrderId);
//        Page<CounsellingOrderReservation> page = this.counsellingOrderReservationService.findPage(PageFactory.defaultPage(), counsellingOrderReservationRequestDTO);
//        return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
//    }
 
    @ApiOperation("分页查询指定条件的预约记录--指定咨询师")
    @GetResource(name = "分页查询指定条件的预约记录--指定咨询师", path = "/counsellingOrderReservation/getCounsellingOrderReservationForPage", requiredPermission = false)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "分页:第几页(从1开始)", dataTypeClass = Integer.class, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页:每页大小(默认10)", dataTypeClass = Integer.class, paramType = "query"),
            @ApiImplicitParam(name = "counsellingInfoId", value = "咨询师id", dataTypeClass = Integer.class, paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "用户id,默认当前用户", dataTypeClass = Integer.class, paramType = "query")
    } )
    public ResponseData<PageResult<CounsellingOrderReservation>> getCounsellingOrderReservationForPage(Integer pageNo, Integer pageSize,Long counsellingInfoId,Long userId) {
        CounsellingOrderReservationRequestDTO counsellingOrderReservationRequestDTO = new CounsellingOrderReservationRequestDTO();
        counsellingOrderReservationRequestDTO.setCounsellingInfoId(counsellingInfoId);
        if (userId != null){
            counsellingOrderReservationRequestDTO.setCustomerId(userId);
        }else{
            counsellingOrderReservationRequestDTO.setCustomerId(LoginContext.me().getLoginUser().getUserId());
        }
        Page<CounsellingOrderReservation> page = this.counsellingOrderReservationService.findReservationPage(PageFactory.defaultPage(), counsellingOrderReservationRequestDTO);
 
 
        return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
    }
 
    @ApiOperation("咨询预约-根据咨询师id和当前用户查询咨询课程详细信息")
    @GetResource(name = "咨询预约-根据咨询师id和当前用户查询咨询课程详细信息", path = "/counsellingUser/getCounsellingUserInfo", requiredPermission = false)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "counsellingInfoId", value = "咨询师id", dataTypeClass = Integer.class, paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "用户id,不传默认当前用户id", dataTypeClass = Integer.class, paramType = "query")
    } )
    public ResponseData<CounsellingUser> getCounsellingUserInfo(Long counsellingInfoId,Long userId) {
        CounsellingUserRequest counsellingUserRequest = new CounsellingUserRequest();
        counsellingUserRequest.setCounsellingInfoId(counsellingInfoId);
        if (userId != null){
            counsellingUserRequest.setUserId(userId);
 
        }else{
            counsellingUserRequest.setUserId(LoginContext.me().getLoginUser().getUserId());
        }
        Page<CounsellingUser> page = this.counsellingUserService.findCounsellingUserPage(PageFactory.defaultPage(), counsellingUserRequest);
        if (CollectionUtil.isNotEmpty(page.getRecords())){
            return new SuccessResponseData<>(page.getRecords().get(0));
        }
        return new SuccessResponseData<>();
    }
 
 
    @Transactional
    @ApiOperation("取消咨询预约")
    @PostResource(name = "取消咨询预约", path = "/counsellingOrderReservation/cancleCounsellingReservation/{counsellingOrderReservationId}", requiredPermission = false)
    public ResponseData<?> cancleCounsellingReservation(@PathVariable("counsellingOrderReservationId") Long counsellingOrderReservationId){
        CounsellingOrderReservation counsellingOrderReservation = this.counsellingOrderReservationService.getById(counsellingOrderReservationId);
        if (counsellingOrderReservation != null){
            counsellingOrderReservation.setStauts(5);
        }
        CounsellingUser counsellingUser = this.counsellingUserService.getOne(new LambdaQueryWrapper<CounsellingUser>().eq(CounsellingUser::getCounsellingInfoId,counsellingOrderReservation.getCounsellingInfoId())
                .eq(CounsellingUser::getUserId,counsellingOrderReservation.getUserId()).eq(CounsellingUser::getIsDelete,0)
                .last(" limit 1 "));
        //取消预约时间间隔,6小时
        long minte = DateUtil.between(new Date(),counsellingOrderReservation.getReservationBeginTime(), DateUnit.MINUTE,false);
        if (minte <= 360l && minte >=0){
 
//            Customer customer = this.customerService.getById(counsellingOrderReservation.getUserId());
//            customer.setCancelNum(customer.getCancelNum()+1);
//            this.customerService.updateById(customer);
            if (counsellingOrderReservation.getReservationType().intValue() != 1){
                counsellingUser.setCancelNum(counsellingUser.getCancelNum()+1);
                //每三次扣一次
                if (counsellingUser.getCancelNum().intValue() > 0 && counsellingUser.getCancelNum().intValue()%3 == 0){
                    //分钟数
                    long minute = DateUtil.between(counsellingOrderReservation.getReservationBeginTime(),counsellingOrderReservation.getReservationEndTime(), DateUnit.MINUTE);
                    int ceil = (int) Math.ceil(minute / 60d);
                    CounsellingOrder counsellingOrderold = this.counsellingOrderService.getById(counsellingOrderReservation.getCounsellingOrderId());
 
                    //扣除工时
                    counsellingOrderold.setResidueClassHours(counsellingOrderold.getResidueClassHours().intValue() -1);
                    //判断是否完成咨询订单服务
                    if (counsellingOrderold.getResidueClassHours().intValue() <= 0 ){
                        counsellingOrderold.setStatusFlag(2);
                        counsellingUser.setStatusFlag(2);
                    }
                    this.counsellingOrderService.updateById(counsellingOrderold);
 
                    counsellingOrderReservation.setConsumeCourseHour(1);
                    counsellingOrderReservation.setRemark("多次提前取消预约,扣除课时");
 
                    counsellingUser.setResidueClassHours(counsellingUser.getResidueClassHours().intValue() - 1);
 
                }
             }
 
            this.counsellingUserService.updateById(counsellingUser);
 
        }
        this.counsellingOrderReservationService.updateById(counsellingOrderReservation);
        //首次咨询取消取消掉咨询订单内的首次咨询时间
        if (counsellingOrderReservation.getReservationType().intValue() == 1){
            this.counsellingOrderService.update(new LambdaUpdateWrapper<CounsellingOrder>().set(CounsellingOrder::getFirstAppointmentDate,null).set(CounsellingOrder::getFirstAppointmentTimes,null)
                    .eq(CounsellingOrder::getId,counsellingOrderReservation.getCounsellingOrderId()));
            //处理用户咨询预约
            this.counsellingUserService.update(new LambdaUpdateWrapper<CounsellingUser>().eq(CounsellingUser::getCounsellingInfoId,counsellingOrderReservation.getCounsellingInfoId())
                    .eq(CounsellingUser::getUserId,counsellingOrderReservation.getUserId()).set(CounsellingUser::getFirstAppointmentDate,null)
                    .set(CounsellingUser::getFirstAppointmentTimes,null).set(CounsellingUser::getIsFirstAppointment,1));
        }
 
        return new SuccessResponseData<>();
    }
 
 
    @ApiOperation("根据预约记录id获取咨询作业列表")
    @GetResource(name = "根据预约记录id获取咨询作业列表", path ={"/counsellingReservationWork/list","/worker/counsellingReservationWork/list"} , requiredPermission = false)
    public ResponseData<List<CounsellingReservationWork>> list(Long counsellingOrderReservationId) {
        LambdaQueryWrapper<CounsellingReservationWork> lambdaQueryWrapper = new LambdaQueryWrapper<CounsellingReservationWork>().eq(CounsellingReservationWork::getIsDelete,false)
                .orderByDesc(CounsellingReservationWork::getId).eq(CounsellingReservationWork::getCounsellingOrderReservationId,counsellingOrderReservationId);
        return new SuccessResponseData<>(counsellingReservationWorkService.list(lambdaQueryWrapper));
    }
 
    @ApiOperation("获取咨询订单信息列表(分页)")
    @GetResource(name = "获取咨询订单信息列表(分页)", path = "/counsellingOrder/page", requiredPermission = false)
    public ResponseData<PageResult<CounsellingOrderResponseDTO>> counsellingOrderPage(CounsellingOrderRequest counsellingOrderRequest) {
        counsellingOrderRequest.setUserId(LoginContext.me().getLoginUser().getUserId());
        Page<CounsellingOrderResponseDTO> page = this.counsellingOrderService.findCounsellingOrderPage(PageFactory.defaultPage(), counsellingOrderRequest);
        return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
    }
 
 
    @ApiOperation("我的预约-咨询预约(分页)")
    @GetResource(name = "我的预约-咨询预约(分页)", path = "/counsellingUser/page", requiredPermission = false)
    public ResponseData<PageResult<CounsellingUser>> counsellingUserPage(CounsellingUserRequest counsellingUserRequest) {
        counsellingUserRequest.setUserId(LoginContext.me().getLoginUser().getUserId());
        Page<CounsellingUser> page = this.counsellingUserService.findCounsellingUserPage(PageFactory.defaultPage(), counsellingUserRequest);
        return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
    }
 
    @ApiOperation("取消咨询订单")
    @PostResource(name = "取消咨询订单", path = "/counsellingOrder/cancleCounsellingOrder")
    public ResponseData<?> cancleCounsellingOrder(Long orderId) {
        CounsellingOrder counsellingOrder = this.counsellingOrderService.getById(orderId);
        if (counsellingOrder == null){
            throw  new ServiceException("订单不存在,请仔细检查!");
        }
        if (counsellingOrder.getStatusFlag().intValue() ==1 || counsellingOrder.getStatusFlag().intValue() == 2){
            Date endDate = DateUtil.offsetHour(new Date(),24);
            long countRes = this.counsellingOrderReservationService.count(new LambdaQueryWrapper<CounsellingOrderReservation>()
                    .eq(CounsellingOrderReservation::getCounsellingOrderId,orderId).ge(CounsellingOrderReservation::getReservationBeginTime,DateUtil.formatDateTime(new Date()))
                    .le(CounsellingOrderReservation::getReservationBeginTime,DateUtil.formatDateTime(endDate)).in(CounsellingOrderReservation::getStauts,1,2,3,4));
            if (countRes > 0l){
                throw new ServiceException("24小时有预约不能取消订单!");
            }
        }
 
 
        LambdaUpdateWrapper<CounsellingOrder> lambdaUpdateWrapper = new LambdaUpdateWrapper<CounsellingOrder>().set(CounsellingOrder::getStatusFlag,9);
        lambdaUpdateWrapper.eq(CounsellingOrder::getId, orderId);
        this.counsellingOrderService.update(lambdaUpdateWrapper);
        CounsellingOrder counsellingOrderTwo = this.counsellingOrderService.getById(orderId);
        CounsellingUser counsellingUser = this.counsellingUserService.getOne(new LambdaQueryWrapper<CounsellingUser>().eq(CounsellingUser::getCounsellingInfoId,counsellingOrder.getCounsellingInfoId())
                .eq(CounsellingUser::getUserId,counsellingOrder.getUserId()).eq(CounsellingUser::getIsDelete,0).last(" limit 1 "));
        if (counsellingUser != null){
            if (counsellingOrderTwo.getOrderType().intValue() ==1){
                this.counsellingUserService.update(new LambdaUpdateWrapper<CounsellingUser>().set(CounsellingUser::getStatusFlag,9)
                        .set(CounsellingUser::getClassHours,0).set(CounsellingUser::getResidueClassHours,0).set(CounsellingUser::getIsFirstAppointment,null)
                                .set(CounsellingUser::getFirstAppointmentDate,null).set(CounsellingUser::getFirstAppointmentTimes,null)
                        .eq(CounsellingUser::getCounsellingInfoId,counsellingOrder.getCounsellingInfoId())
                        .eq(CounsellingUser::getUserId,counsellingOrder.getUserId()));
            }else{
                this.counsellingUserService.update(new LambdaUpdateWrapper<CounsellingUser>().set(CounsellingUser::getStatusFlag,9)
                        .set(CounsellingUser::getClassHours,0).set(CounsellingUser::getResidueClassHours,0)
                        .eq(CounsellingUser::getCounsellingInfoId,counsellingOrder.getCounsellingInfoId())
                        .eq(CounsellingUser::getUserId,counsellingOrder.getUserId()));
            }
 
 
        }
        //取消对应的咨询预约
        this.counsellingOrderReservationService.update(new LambdaUpdateWrapper<CounsellingOrderReservation>().eq(CounsellingOrderReservation::getCounsellingOrderId,orderId)
                .in(CounsellingOrderReservation::getStauts,1,2,3).set(CounsellingOrderReservation::getStauts,5).set(CounsellingOrderReservation::getRemark,"订单退款取消"));
        //        //是否调用退款
        if (StrUtil.isNotBlank(counsellingOrder.getTransactionNo())) {
            if (counsellingOrder.getPayType().equals("1")) {
                Map<String, Object> map = new HashMap(2);
                map.put("transactionId", counsellingOrder.getOrderNo());
                map.put("outTradeNo", counsellingOrder.getTransactionNo());
                String result = HttpUtil.createGet(refundWxpayUrl).form(map).execute().body();
               log.info("咨询订单微信退款信息:" + result);
            } else if (counsellingOrder.getPayType().equals("2")) {
                Map<String, Object> map = new HashMap(2);
                map.put("outTradeNo", counsellingOrder.getOrderNo());
                map.put("tradeNo", counsellingOrder.getTransactionNo());
                String result = HttpUtil.createGet(refundAlipayUrl).form(map).execute().body();
                log.info("咨询订单退款支付宝:{},{},{}", counsellingOrder.getOrderNo(), counsellingOrder.getTransactionNo(), result);
 
           }
        }
 
        return new SuccessResponseData<>();
    }
 
    @ApiOperation("发送消息更新群最后聊天信息")
    @PostResource(name = "发送消息更新群最后聊天信息", path = {"/group/{groupId}","/worker/group/{groupId}"}, requiredPermission = false)
    public ResponseData<?> updateGroupIm(@PathVariable Long groupId){
        this.imGroupService.update(new LambdaUpdateWrapper<ImGroup>().set(ImGroup::getLastChatTime,new Date()).eq(ImGroup::getId,groupId));
        return new SuccessResponseData<>();
    }
 
    @ApiOperation("根据预约id查询预约记录详细")
    @GetResource(name = "根据预约id查询预约记录详细", path ={"/counsellingInfo/getCounsellingOrderReservationResponseDTOById","/worker/counsellingInfo/getCounsellingOrderReservationResponseDTOById"}, requiredPermission = false)
    public ResponseData<CounsellingOrderReservationResponseDTO> getCounsellingOrderReservationResponseDTOById(Long counsellingOrderReservationId){
        CounsellingOrderReservation counsellingOrderReservation = this.counsellingOrderReservationService.getById(counsellingOrderReservationId);
        CounsellingOrderReservationResponseDTO counsellingOrderReservationResponseDTO = BeanUtil.copyProperties(counsellingOrderReservation,CounsellingOrderReservationResponseDTO.class);
        CounsellingOrder counsellingInfoOrder = this.counsellingOrderService.getById(counsellingOrderReservationResponseDTO.getCounsellingOrderId());
        if (counsellingInfoOrder != null){
            CounsellingOrderResponseDTO counsellingOrderResponseDTO = BeanUtil.copyProperties(counsellingInfoOrder,CounsellingOrderResponseDTO.class);
            counsellingOrderReservationResponseDTO.setPhone(counsellingOrderResponseDTO.getPhone());
            Customer customer = this.customerService.getById(counsellingInfoOrder.getUserId());
            counsellingOrderReservationResponseDTO.setUserName(customer.getNickName());
        }
        return new SuccessResponseData<>(counsellingOrderReservationResponseDTO);
 
    }
 
 
}