lisy
2023-07-12 7fb22e9525770ba2c04169958a9b7c87a7a4dfeb
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
package com.dsh.course.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsh.course.entity.*;
import com.dsh.course.feignclient.account.AppUserClient;
import com.dsh.course.feignclient.account.model.AppUser;
import com.dsh.course.feignclient.model.*;
import com.dsh.course.model.BaseVo;
import com.dsh.course.model.dto.DiscountJsonDto;
import com.dsh.course.model.vo.CourseDetailRequest;
import com.dsh.course.model.vo.RegisterCourseVo;
import com.dsh.course.model.vo.request.*;
import com.dsh.course.model.vo.response.AppUserVideoResponse;
import com.dsh.course.model.vo.response.CourseDetailsResponse;
import com.dsh.course.model.vo.response.CourseOfVideoResponse;
import com.dsh.course.service.*;
import com.dsh.course.util.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
@Api
@CrossOrigin
@RestController
@RequestMapping("")
public class CoursePackagePaymentController {
 
    private Logger logger = LoggerFactory.getLogger("business-log");
 
 
    @Autowired
    private TCoursePackagePaymentService packagePaymentService;
 
    @Autowired
    private TCoursePackageService tcpService;
 
    @Autowired
    private TCoursePackageDiscountService tcpdService;
 
 
    @Autowired
    private ICoursePackagePaymentConfigService icppcService;
 
    @Autowired
    private UserVideoDetailsService uvdsService;
 
    @Autowired
    private TCourseService tcService;
 
 
 
    @Autowired
    private TCoursePackageTypeService coursePackageTypeService;
 
    @Autowired
    private TokenUtil tokenUtil;
 
    @Autowired
    private CancelledClassesService cancelledClassesService;
 
    @Autowired
    private AppUserClient appuClient;
 
    private final SimpleDateFormat format = new SimpleDateFormat("MM-dd HH:mm");
 
    /**
     * 获取 没有学员信息的图片配置
     * @param stuId 学员id
     * @return  课包列表
     */
    @PostMapping("/base/coursePack/queryPayment")
    public List<StuCourseResp> getStuCoursePackagePayment(@RequestParam("stuId") Integer stuId,@RequestParam("appUserId") Integer appUserId){
        List<StuCourseResp> resps = new ArrayList<>();
        List<TCoursePackagePayment> byUserId = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
                .eq("appUserId",appUserId)
                .eq("studentId",stuId));
 
        if (byUserId.size() > 0 ){
            for (TCoursePackagePayment tCoursePackagePayment : byUserId) {
                TCoursePackage tCoursePackage = tcpService.getById(tCoursePackagePayment.getCoursePackageId());
                StuCourseResp resp = new StuCourseResp();
                resp.setCourseId(tCoursePackage.getId());
                resp.setCourseName(tCoursePackage.getName());
                resp.setTotalCourseNums(tCoursePackagePayment.getTotalClassHours());
                resp.setResidueNums(tCoursePackagePayment.getLaveClassHours());
                resp.setDeductionNums(tCoursePackagePayment.getTotalClassHours()-tCoursePackagePayment.getLaveClassHours());
                resps.add(resp);
            }
        }
        return resps;
    }
 
    /**
     *
     * 获取发布的 课包列表
     */
    @PostMapping("/base/coursePack/storeOfCourse")
    public List<CourseOfStoreVo> getStuCourseWithStores(){
        List<CourseOfStoreVo> courseOfStoreVos = tcpService.queryStoreOfCourse();
        if (courseOfStoreVos.size() > 0){
            for (CourseOfStoreVo courseOfStoreVo : courseOfStoreVos) {
                String[] split = courseOfStoreVo.getClassWeeks().split(";");
                List<Integer> integers = new ArrayList<>();
                for (String s : split) {
                    int num = Integer.parseInt(s);
                    integers.add(num);
                }
                courseOfStoreVo.setClassWeekList(integers);
            }
        }
        return tcpService.queryStoreOfCourse();
    }
 
 
    /**
     *
     * 课程名称列表
     */
    @PostMapping("/base/coursePack/sessionNames")
    public List<StuSessionDetailsVo> getStuSessionList(@RequestBody CourseDetailRequest request){
        List<StuSessionDetailsVo> detailsVos = new ArrayList<>();
        List<TCoursePackagePayment> byUserId = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
                .between("insertTime", request.getStartTime(),request.getEndTime())
                .eq("appUserId",request.getAppUserId())
                .eq("studentId",request.getStuId()));
        if (byUserId.size() > 0){
            List<Integer> collect = byUserId.stream().map(TCoursePackagePayment::getCoursePackageId).collect(Collectors.toList());
            List<TCoursePackage> list = tcpService.list(new QueryWrapper<TCoursePackage>()
                    .in("id", collect));
            list.forEach(vo -> {
                StuSessionDetailsVo detVo = new StuSessionDetailsVo();
                detVo.setSessionid(vo.getId());
                detVo.setSessionName(vo.getName());
                String afterDayDate = DateUtil.getAfterDayDate2(vo.getInsertTime(),vo.getValidDays() + "");
                detVo.setPeriodOfValidity(afterDayDate);
                detailsVos.add(detVo);
            });
        }
        return detailsVos;
    }
 
    @PostMapping("/base/coursePack/paymentCourse")
    public List<PurchaseRecordVo> queryCourseDetails(@RequestParam("startTime") Date startTime, @RequestParam("endTime") Date  endTime,@RequestParam("stuId") Integer stuId, @RequestParam("appUserId") Integer appUserId) {
        List<PurchaseRecordVo> purchaseRecordVos = new ArrayList<>();
 
        List<TCoursePackagePayment> coursePackage = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
                .between("insertTime", startTime,endTime)
                .eq("appUserId",appUserId)
                .eq("studentId",stuId));
        if (coursePackage.size() > 0 ){
            coursePackage.forEach( cspackage -> {
                PurchaseRecordVo recordVo = new PurchaseRecordVo();
                recordVo.setPurchaseAmount("+"+cspackage.getClassHours());
                recordVo.setPurchaseTime(format.format(cspackage.getInsertTime()));
                recordVo.setPurchaseType("购买课包");
                purchaseRecordVos.add(recordVo);
            });
        }
        return purchaseRecordVos;
    }
 
 
 
    @PostMapping("/base/coursePack/stuOfCourses")
    public StuWithCoursesListVo getStuOfCoursesDetails(@RequestBody GetStuOfCoursesDetails getStuOfCoursesDetails){
        StuWithCoursesListVo lisco = new StuWithCoursesListVo();
        Integer totalNu = 0;
        Integer dedutNu = 0;
        Integer remainNu = 0;
        List<TCoursePackagePayment> byUserId = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
                .eq("appUserId",getStuOfCoursesDetails.getAppUserId())
                .eq("studentId",getStuOfCoursesDetails.getStuId()));
        if (byUserId.size() > 0 ){
            for (TCoursePackagePayment tCoursePackagePayment : byUserId) {
                totalNu = totalNu + tCoursePackagePayment.getTotalClassHours();
                dedutNu = dedutNu + tCoursePackagePayment.getLaveClassHours();
                remainNu = remainNu + (tCoursePackagePayment.getTotalClassHours()-tCoursePackagePayment.getLaveClassHours());
            }
            lisco.setTotalNums(totalNu);
            lisco.setDeductedNums(remainNu);
            lisco.setRemainingNums(dedutNu);
        }
        return lisco;
    }
 
 
 
    @PostMapping("/base/coursePack/continuingCourse")
    public StudentOfCourseVo getStudentCourse(@RequestBody GetStudentCourse getStudentCourse){
        StudentOfCourseVo courseVo = new StudentOfCourseVo();
        List<TCoursePackagePayment> tCoursePackagePayments = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
                .eq("appUserId", getStudentCourse.getAppUserId())
                .eq("coursePackageId", getStudentCourse.getCourseId())
                .eq("studentId", getStudentCourse.getStuId()));
        if (tCoursePackagePayments.size() > 0 ){
 
            List<CourseHoursType> typeList = new ArrayList<>();
            tCoursePackagePayments.forEach(cou -> {
                CourseHoursType hoursType = new CourseHoursType();
                hoursType.setCourseConfigId(cou.getId());
                hoursType.setCourseHourNums(cou.getClassHours());
                typeList.add(hoursType);
            });
            TCoursePackagePayment tCoursePackagePayment = tCoursePackagePayments.get(0);
            courseVo.setCoursePackageId(tCoursePackagePayment.getCoursePackageId());
            courseVo.setTypeList(typeList);
 
            TCoursePackage coursePackage = tcpService.getById(tCoursePackagePayment.getCoursePackageId());
            courseVo.setPackageImg(coursePackage.getCoverDrawing());
            courseVo.setCourseName(coursePackage.getName());
            courseVo.setCoachId(coursePackage.getCoachId());
            String classWeeks = coursePackage.getClassWeeks();
            List<Integer> integers = StrUtils.dealStrToList(classWeeks);
            if (integers.size() > 0){
                StringBuilder courWeeks = new StringBuilder("每");
                for (Integer integer : integers) {
                    switch (integer){
                        case 1:
                            courWeeks.append("周一、");
                            break;
                        case 2:
                            courWeeks.append("周二、");
                            break;
                        case 3:
                            courWeeks.append("周三、");
                            break;
                        case 4:
                            courWeeks.append("周四、");
                            break;
                        case 5:
                            courWeeks.append("周五、");
                            break;
                        case 6:
                            courWeeks.append("周六、");
                            break;
                        case 7:
                            courWeeks.append("周末、");
                            break;
                        default:
                            break;
                    }
                }
                if (courWeeks.length() > 0 && courWeeks.charAt(courWeeks.length() - 1) == ','){
                    courWeeks.deleteCharAt(courWeeks.length() - 1);
                }
                courseVo.setCourseWeek(courWeeks.toString());
            }
 
            courseVo.setCourseTime(coursePackage.getClassStartTime()+"-"+coursePackage.getClassEndTime());
            Integer payType = tCoursePackagePayment.getPayType();
            BigDecimal cashPayment = tCoursePackagePayment.getCashPayment();
            double cashPaymentValue = cashPayment.doubleValue();
            Integer playPaiCoin = tCoursePackagePayment.getPlayPaiCoin();
            TCoursePackageDiscount coursePackageDiscount = tcpdService.getOne(new QueryWrapper<TCoursePackageDiscount>()
                    .eq("coursePackageId",coursePackage.getId() )
                    .eq("type",1)
                    .eq("auditStatus",2));
            ObjectMapper objectMapper = new ObjectMapper();
            String content = coursePackageDiscount.getContent();
            double discountMember = 0.0;
            DiscountJsonDto discountJsonDto = null;
            try {
                discountJsonDto = objectMapper.readValue(content, DiscountJsonDto.class);
                discountMember = discountJsonDto.getDiscountMember();
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
            switch (payType) {
                case 1:
                case 2:
                    courseVo.setAmount(cashPaymentValue);
                    courseVo.setVipAmount(discountMember);
                    break;
                case 3:
                    courseVo.setWpGold(playPaiCoin);
                    break;
            }
            courseVo.setStoreId(coursePackage.getStoreId());
        }
 
        return courseVo;
    }
 
 
    @PostMapping("/base/coursePack/afterCourseTwos")
    public List<AfterVideoVo> getAfterCourseTwos(@RequestParam("appUserId") Integer appUserId){
        List<AfterVideoVo> videoVos = new ArrayList<>();
        List<UserVideoDetails> list = uvdsService.list(new QueryWrapper<UserVideoDetails>()
                .eq("appUserId",appUserId)
                .eq("state",1));
        if (list.size() > 0 ){
            List<Integer> courseIds = list.stream().map(UserVideoDetails::getCourseId).collect(Collectors.toList());
            List<TCourse> courseList = tcService.list(new QueryWrapper<TCourse>()
                    .in("id",courseIds)
                    .eq("type",1)
                    .eq("state",1)
                    .last("ORDER BY insertTime desc LIMIT 2"));
            for (TCourse tCourse : courseList) {
                AfterVideoVo videoVo = new AfterVideoVo();
                videoVo.setCourseId(tCourse.getId());
                videoVo.setCourseUrl(tCourse.getCourseVideo());
                videoVos.add(videoVo);
            }
        }
        return videoVos;
    }
 
    @PostMapping("/base/coursePack/allPaymentCourseList")
    public List<TCoursePackagePayment> getAppuserCourseList(@RequestBody Integer appUserId){
        return packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
                .eq("appUserId",appUserId)
                .eq("payType",3)
                .eq("payStatus",2)
                .eq("state",1));
    }
 
    @PostMapping("/base/coursePack/allAmountPayRecordOfUser")
    public List<TCoursePackagePayment> getAmountPayRecord(@RequestBody Integer appUserId){
        return packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
                .eq("appUserId",appUserId)
                .notIn("payType",3)
                .eq("payStatus",2)
                .eq("state",1));
    }
 
 
    @ResponseBody
    @PostMapping("/api/course/queryArrangeCourseList")
    @ApiOperation(value = "获取布置课程列表", tags = {"APP-课程列表"})
    @ApiImplicitParams({
    })
    public ResultUtil<List<BaseVo>> queryArrangePackageType(){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            List<TCoursePackagePayment> tCoursePackagePayments = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
                    .eq("appUserId",appUserId));
            List<BaseVo> list = new ArrayList<>();
            tCoursePackagePayments.forEach(c -> {
                BaseVo baseVo = new BaseVo();
                baseVo.setId(c.getCoursePackageId());
                TCoursePackage coursePackage = tcpService.getById(c.getCoursePackageId());
                baseVo.setName(coursePackage.getName());
                list.add(baseVo);
            });
            return ResultUtil.success();
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 课后视频课表
     */
    @ResponseBody
    @PostMapping("/api/startCource/afterSourceList")
    @ApiOperation(value = "课后视频课表", tags = {"APP-开始上课"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil<List<AppUserVideoResponse>> queryAfterSourceList( CourseOfAfterRequest search){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
 
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            List<Integer> courseIds = new ArrayList<>();
            List<TCoursePackagePayment> tCoursePackagePayments = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
                    .eq("coursePackageId",search.getCourseTypeId())
                    .eq("appUserId",appUserId));
            if (tCoursePackagePayments.size() > 0 ){
                courseIds = tCoursePackagePayments.stream().map(TCoursePackagePayment::getCoursePackageId).collect(Collectors.toList());
            }
            return ResultUtil.success(packagePaymentService.queryAfterVideo(search,courseIds));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
    /**
     * 课后视频详情
     */
    @ResponseBody
    @PostMapping("/api/startCource/afterSourceDetail")
    @ApiOperation(value = "课后视频详情", tags = {"APP-开始上课"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil<CourseOfVideoResponse> queryAfterSourceDetails( CourseWithDetailsRequest detailsRequest){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(packagePaymentService.queryVideoDetails(detailsRequest,appUserId));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 更新课后视频学习状态
     */
    @ResponseBody
    @PostMapping("/api/startCource/updateVideoStatus")
    @ApiOperation(value = "更新课后视频学习状态", tags = {"APP-开始上课"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil updateVideoStatus( UpdateCourseVideoStatusRequest detailsRequest){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(packagePaymentService.updateVideoStatus(detailsRequest,appUserId));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/course/getCourseAppUserDetails")
    @ApiOperation(value = "已报名课程-获取课程类型列表", tags = {"APP-课程列表"})
    @ApiImplicitParams({
    })
    public ResultUtil<List<BaseVo>> queryCoursePackageType(){
        try {
            List<TCoursePackageType> coursePackageTypes = coursePackageTypeService.list(new QueryWrapper<TCoursePackageType>().eq("state", 1));
            List<BaseVo> list = new ArrayList<>();
            coursePackageTypes.forEach(c -> {
                BaseVo baseVo = new BaseVo();
                BeanUtils.copyProperties(c, baseVo);
                list.add(baseVo);
            });
            return ResultUtil.success(list);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 已报名课程列表
     */
    @ResponseBody
    @PostMapping("/api/startCource/registeredCourses")
    @ApiOperation(value = "已报名课程-课程列表", tags = {"APP-开始上课"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil<List<RegisterCourseVo>> queryRegisteredCoursesDetails( CourseOfAfterRequest courseTypeId){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(packagePaymentService.queryRegisteredCourseList(courseTypeId,appUserId));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
 
    }
 
 
    /**
     * 已报名课程详情
     */
    @ResponseBody
    @PostMapping("/api/startCource/RegisteredData")
    @ApiOperation(value = "已报名课程详情", tags = {"APP-开始上课"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "coursePayId" ,value = "课包记录id",dataType = "long"),
    })
    public ResultUtil<CourseDetailsResponse> getRegisteredData( Integer coursePayId){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(packagePaymentService.queryRegisteredCourseDetails(coursePayId,appUserId));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 已报名课程-支付
     */
    @ResponseBody
    @PostMapping("/api/startCource/payment")
    @ApiOperation(value = "已报名课程-支付", tags = {"APP-开始上课"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil continuationOperation(ClasspaymentRequest request){
        try {
            Integer userIdFormRedis = tokenUtil.getUserIdFormRedis();
            if(null == userIdFormRedis){
                return ResultUtil.tokenErr();
            }
            return packagePaymentService.ContinuationOrpaymentCourse(userIdFormRedis,request);
        }catch (Exception e){
            return ResultUtil.runErr();
        }
 
    }
 
 
    /**
     * 获取学员剩余课时
     * @param id
     * @return
     */
    @ResponseBody
    @PostMapping("/coursePackagePayment/queryResidueClassHour")
    public Integer queryResidueClassHour(@RequestBody Integer id){
        try {
            List<TCoursePackagePayment> list = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>().eq("studentId", id).eq("payStatus", 2)
                    .eq("status", 1).eq("state", 1).gt("laveClassHours", 0));
            Integer total = 0;
            for (TCoursePackagePayment coursePackagePayment : list) {
                total += coursePackagePayment.getLaveClassHours();
            }
            return total;
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }
 
 
    /**
     * 课程用于支付进行扣减
     * @param paymentDeductionClassHour
     */
    @ResponseBody
    @PostMapping("/coursePackagePayment/paymentDeductionClassHour")
    public void paymentDeductionClassHour(@RequestBody PaymentDeductionClassHour paymentDeductionClassHour){
        try {
            List<TCoursePackagePayment> list = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>().eq("studentId", paymentDeductionClassHour.getId()).eq("payStatus", 2)
                    .eq("status", 1).eq("state", 1).gt("laveClassHours", 0));
            Integer classHour = paymentDeductionClassHour.getClassHour();
            for (TCoursePackagePayment coursePackagePayment : list) {
                if(coursePackagePayment.getLaveClassHours().compareTo(classHour) >= 0){
                    coursePackagePayment.setLaveClassHours(coursePackagePayment.getLaveClassHours() - classHour);
                    packagePaymentService.updateById(coursePackagePayment);
 
                    CancelledClasses cancelledClasses = new CancelledClasses();
                    cancelledClasses.setType(2);
                    cancelledClasses.setVoucher(paymentDeductionClassHour.getCode());
                    cancelledClasses.setCoursePackageId(coursePackagePayment.getCoursePackageId());
                    cancelledClasses.setCoursePackagePaymentId(coursePackagePayment.getId());
                    cancelledClasses.setCancelledClassesNumber(classHour);
                    cancelledClasses.setInsertTime(new Date());
                    cancelledClassesService.save(cancelledClasses);
                    break;
                }else{
                    CancelledClasses cancelledClasses = new CancelledClasses();
                    cancelledClasses.setType(2);
                    cancelledClasses.setVoucher(paymentDeductionClassHour.getCode());
                    cancelledClasses.setCoursePackageId(coursePackagePayment.getCoursePackageId());
                    cancelledClasses.setCoursePackagePaymentId(coursePackagePayment.getId());
                    cancelledClasses.setCancelledClassesNumber(coursePackagePayment.getLaveClassHours());
                    cancelledClasses.setInsertTime(new Date());
                    cancelledClassesService.save(cancelledClasses);
 
                    coursePackagePayment.setLaveClassHours(0);
                    packagePaymentService.updateById(coursePackagePayment);
 
                    classHour -= cancelledClasses.getCancelledClassesNumber();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
 
 
    /**
     * 取消赛事回退支付课时
     * @param paymentDeductionClassHour
     */
    @ResponseBody
    @PostMapping("/coursePackagePayment/rollbackPaymentDeductionClassHour")
    public void rollbackPaymentDeductionClassHour(@RequestBody PaymentDeductionClassHour paymentDeductionClassHour){
        try {
            List<CancelledClasses> voucher = cancelledClassesService.list(new QueryWrapper<CancelledClasses>().eq("voucher", paymentDeductionClassHour.getCode()));
            for (CancelledClasses cancelledClasses : voucher) {
                TCoursePackagePayment coursePackagePayment = packagePaymentService.getById(cancelledClasses.getCoursePackagePaymentId());
                coursePackagePayment.setLaveClassHours(coursePackagePayment.getLaveClassHours() + cancelledClasses.getCancelledClassesNumber());
                packagePaymentService.updateById(coursePackagePayment);
 
                cancelledClassesService.removeById(cancelledClasses.getId());
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
 
 
    /**
     * 课包续费玩湃币支付
     * @param
     */
    @PostMapping("/coursePackagePayment/courseRenewPlayPaiPay")
    public int paymentWanpaiRenewCourse(@RequestBody PlayPaiGoldCoursePackage coursePackage){
        try {
            Integer userIdFormRedis = tokenUtil.getUserIdFormRedis();
            if (null == userIdFormRedis){
                return 2;
            }
            CoursePackagePaymentConfig paymentConfig = icppcService.getById(coursePackage.getCoursePayConfigId());
            AppUser appUser = appuClient.queryAppUser(userIdFormRedis);
            if (appUser.getPlayPaiCoins() < paymentConfig.getPlayPaiCoin()){
                return 3;
            }
            TCoursePackagePayment packagePayment = packagePaymentService.getOne(new QueryWrapper<TCoursePackagePayment>()
                    .eq("code",coursePackage.getCode() ));
            packagePayment.setPayStatus(2);
            packagePayment.setPayUserId(userIdFormRedis);
            packagePayment.setClassHours(paymentConfig.getClassHours());
            packagePayment.setPlayPaiCoin(paymentConfig.getPlayPaiCoin());
            packagePayment.setTotalClassHours(paymentConfig.getClassHours());
            packagePayment.setLaveClassHours(paymentConfig.getClassHours());
            packagePaymentService.updateById(packagePayment);
 
            appUser.setPlayPaiCoins(appUser.getPlayPaiCoins()-paymentConfig.getPlayPaiCoin());
            appuClient.updateAppUser(appUser);
        } catch (Exception e) {
            return 4;
        }
        return 1;
    }
 
    @PostMapping("/base/coursePack/getPaymentCoursePackage")
    public TCoursePackagePayment getCoursePackagePaymentByCode(@RequestBody String code){
        return packagePaymentService.getOne(new QueryWrapper<TCoursePackagePayment>()
                .eq("code",code));
    }
 
    @PostMapping("/base/coursePack/delPaymentCoursePackage")
    public boolean delPaymentCoursePackage(@RequestBody Integer payId){
        return packagePaymentService.removeById(payId);
    }
    @PostMapping("/base/coursePack/updatePaymentCoursePackage")
    public boolean updatePaymentCoursePackage(@RequestBody TCoursePackagePayment packagePayment){
        return packagePaymentService.update(packagePayment,new QueryWrapper<TCoursePackagePayment>()
                .eq("id",packagePayment.getId()));
    }
 
    @PostMapping("/base/coursePack/savePaymentCoursePackage")
    public boolean savePaymentCoursePackage(@RequestBody TCoursePackagePayment packagePayment){
        return packagePaymentService.save(packagePayment);
    }
 
 
    @PostMapping("/base/coursePack/obtainStudentClassDetails")
    public List<RecordAppoint> obtainStudentClassDetailsData(@RequestBody Integer stuId){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            return packagePaymentService.obtainStuClassDetails(stuId,appUserId);
        }catch (Exception e){
            e.printStackTrace();
            throw new RuntimeException();
        }
    }
 
}