nickchange
2023-11-17 a9564eae9f0169ca39329b2f14a8f13d13358a0a
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
package com.dsh.course.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dsh.course.entity.*;
import com.dsh.course.feignclient.account.AppUserClient;
import com.dsh.course.feignclient.account.CoachClient;
import com.dsh.course.feignclient.account.StudentClient;
import com.dsh.course.feignclient.account.model.Coach;
import com.dsh.course.feignclient.account.model.Student;
import com.dsh.course.feignclient.other.StoreClient;
import com.dsh.course.model.CancelClassesQuery;
import com.dsh.course.model.CancelClassesVO;
import com.dsh.course.service.*;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.text.SimpleDateFormat;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @author zhibing.pu
 * @Date 2023/8/12 3:47
 */
@RestController
@RequestMapping("")
public class CancelledClassesController {
 
    @Autowired
    private CancelledClassesService cancelledClassesService;
    @Autowired
    private StoreClient storeClient;
    @Autowired
    private AppUserClient appUserClient;
    @Autowired
    private CoachClient coachClient;
    @Autowired
    private StudentClient studentClient;
    @Autowired
    private TCoursePackageService coursePackageService;
    @Autowired
    private TCoursePackagePaymentService coursePackagePaymentService;
    @Autowired
    private ICoursePackageSchedulingService coursePackageSchedulingService;
 
    /**
     * 获取消课记录
     */
    @ResponseBody
    @PostMapping("/cancelledClasses/listAll")
    public List<CancelClassesVO> listAll(@RequestBody CancelClassesQuery query){
        List<CancelClassesVO> res = new ArrayList<>();
        if (query.getStudentName()!=null){
            if (!query.getStudentName().equals("")){
                List<Integer> s = new ArrayList<>();
                List<Student> students = studentClient.queryStudentListByName(query.getStudentName());
                if (students.size()==0){
                    return new ArrayList<>();
                }
                for (Student coach : students) {
                    s.add(coach.getId());
                }
                query.setStudentIds(s);
            }
        }
        if (query.getCoachName()!=null){
            if (!query.getCoachName().equals("")){
                List<Integer> c = new ArrayList<>();
                List<Coach> coaches = coachClient.queryCoachListByName(query.getCoachName());
                if (coaches.size()==0){
                    return new ArrayList<>();
                }
                for (Coach coach : coaches) {
                    c.add(coach.getId());
                }
                query.setCoachIds(c);
            }
        }
        List<Integer> collect =new ArrayList<>();
        if(query.getStoreId()!=null){
            List<TCoursePackage> list = coursePackageService.list(new LambdaQueryWrapper<TCoursePackage>().eq(TCoursePackage::getStoreId, query.getStoreId()));
             collect = list.stream().map(TCoursePackage::getId).collect(Collectors.toList());
            if(collect.size()==0){
                collect.add(-1);
            }
        }
        if(query.getStoreIds()!=null && query.getStoreIds().size()!=0){
            List<TCoursePackage> list = coursePackageService
                    .list(new LambdaQueryWrapper<TCoursePackage>()
                            .in(TCoursePackage::getStoreId, query.getStoreIds()));
            collect = list.stream().map(TCoursePackage::getId).collect(Collectors.toList());
            if(collect.size()==0){
                collect.add(-1);
            }
        }
        List<CancelClassesVO> result = cancelledClassesService.listAll(query,collect);
        for (CancelClassesVO cancelClassesVO : result) {
            CoursePackageScheduling byId1 = coursePackageSchedulingService.getById(cancelClassesVO.getCoursePackageSchedulingId());
            if (byId1==null){
                continue;
            }
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String string = format.format(byId1.getClassDate());
            String string1 = format.format(byId1.getEndDate());
            String hour = string1.substring(11, 13);
            String minute = string1.substring(14, 16);
            // 去除后三位
            String s = string.substring(0, string.length() - 3);
            String temp = s+"-"+hour+":"+ minute;
            cancelClassesVO.setStartAndEnd(temp);
            TCoursePackagePayment byId = coursePackagePaymentService.getById(cancelClassesVO.getCoursePackagePaymentId());
            cancelClassesVO.setStoreName(storeClient.queryStoreById(cancelClassesVO.getStoreId()).getName());
            cancelClassesVO.setStudentName(studentClient.queryStudentById(byId.getStudentId()).getName());
            cancelClassesVO.setCoachName(coachClient.queryCoachById(cancelClassesVO.getCoachId()).getName());
 
        }
        return result;
    }
 
 
    @Autowired
    private CourseCounsumService courseCounsumService;
    /**
     * 添加数据
     * @param cancelledClasses
     */
    @ResponseBody
    @PostMapping("/cancelledClasses/addCancelledClasses")
    public void addCancelledClasses(@RequestBody CancelledClasses cancelledClasses){
        cancelledClassesService.save(cancelledClasses);
 
        TCoursePackagePayment byId = coursePackagePaymentService.getById(cancelledClasses.getCoursePackagePaymentId());
        CourseCounsum courseCounsum = new CourseCounsum();
        courseCounsum.setPaymentId(byId.getId());
        courseCounsum.setChangeType(0);
        courseCounsum.setNum(cancelledClasses.getCancelledClassesNumber());
        courseCounsum.setInsertTime(new Date());
        courseCounsum.setReason("消课");
        courseCounsumService.save(courseCounsum);
    }
 
}