44323
2023-09-26 6676f28a5a6ca65015a2b2c26e804fa998d625c8
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
package com.dsh.account.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsh.account.dto.*;
import com.dsh.account.entity.Coach;
import com.dsh.account.entity.GiftSearchDto;
import com.dsh.account.entity.TStudent;
import com.dsh.account.feignclient.course.CoursePaymentClient;
import com.dsh.account.feignclient.course.model.TCoursePackagePayment;
import com.dsh.account.model.StudentVo;
import com.dsh.account.service.TStudentService;
import com.dsh.account.util.ResultUtil;
import com.dsh.account.util.TokenUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.mappers.ModelMapper;
 
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * @author zhibing.pu
 * @date 2023/6/24 14:59
 */
@RestController
@RequestMapping("")
public class StudentController {
 
    @Autowired
    private TStudentService studentService;
 
    @Autowired
    private TokenUtil tokenUtil;
 
    /**
     * 添加学员
     * @return
     */
    @RequestMapping("/base/student/addStudent")
    public Object addStudent(@RequestBody TStudent student){
        student.setInsertTime(new Date());
        student.setIsDefault(1);
       return studentService.save(student);
    }
    /**
     * 获取用户学员列表
     * @param appUserId
     * @return
     */
    @ResponseBody
    @PostMapping("/student/queryStudentList")
    public List<TStudent> queryStudentList(@RequestBody Integer appUserId){
        try {
            List<TStudent> list = studentService.list(new QueryWrapper<TStudent>().eq("appUserId", appUserId).eq("state", 1));
            return list;
        }catch (Exception e){
            e.printStackTrace();
            return new ArrayList<>();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/student/queryDefaultStudent")
    public TStudent queryDefaultStudent(@RequestBody Integer appUserId){
        try {
            TStudent one = studentService.getOne(new QueryWrapper<TStudent>().eq("appUserId", appUserId).eq("isDefault", 1).eq("state", 1));
            return one;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/student/queryStudentList")
    @ApiOperation(value = "获取学员列表", tags = {"APP-课程列表"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<List<StudentVo>> queryStudentList(){
        try {
            Integer uid = tokenUtil.getUserIdFormRedis();
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            List<TStudent> list = studentService.list(new QueryWrapper<TStudent>().eq("appUserId", uid).eq("state", 1));
            List<StudentVo> listVo = new ArrayList<>();
            for (TStudent tStudent : list) {
                StudentVo studentVo = new StudentVo();
                studentVo.setId(tStudent.getId());
                studentVo.setPhone(tStudent.getPhone());
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                studentVo.setAge(Integer.valueOf(sdf.format(new Date())) - Integer.valueOf(sdf.format(tStudent.getBirthday())));
                listVo.add(studentVo);
                studentVo.setName(tStudent.getName());
            }
            return ResultUtil.success(listVo);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 根据电话号码学员信息
     * @param phone
     * @return
     */
    @ResponseBody
    @PostMapping("/student/queryStudentByPhone")
    public TStudent queryStudentByPhone(@RequestBody String phone){
        try {
            TStudent one = studentService.getOne(new QueryWrapper<TStudent>().eq("phone", phone).eq("state", 1));
            return one;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
 
 
    /**
     * 根据id获取数据
     * @param id
     * @return
     */
    @ResponseBody
    @PostMapping("/student/queryStudentById")
    public TStudent queryStudentById(@RequestBody Integer id){
        TStudent student = studentService.getById(id);
        return student;
    }
 
 
 
 
    /**
     * 根据名称模糊搜索学员
     * @param name
     * @return
     */
    @ResponseBody
    @PostMapping("/student/queryStudentListByName")
    public List<TStudent> queryStudentListByName(@RequestBody String name){
        return studentService.list(new QueryWrapper<TStudent>().eq("state", 1).like("name", name));
    }
    /**
     * 根据名称模糊搜索学员
     * @param name
     * @return
     */
    @PostMapping("/student/queryTStudentListByName")
    public List<TStudent> queryTStudentListByName(@RequestBody String name){
        return studentService.list(new QueryWrapper<TStudent>().eq("state", 1).like("name", name));
    }
 
    /**
     * web端查找学员
     *
     * @return
     */
 
    @ResponseBody
    @PostMapping("/student/webStudentList")
    public List<TStudentDto> querywebStudent(@RequestBody StudentSearch search){
        return studentService.listAll(search);
    }
 
    @ResponseBody
    @PostMapping("/student/webOneStudent")
    public TStudentDto querywebStudentOne(@RequestParam("id")Integer id){
        System.out.println("===?==》"+id);
        return studentService.listOne(id);
    }
 
    @ResponseBody
    @PostMapping("/student/update")
    public  void update(@RequestBody TStudent tStudent){
        System.out.println("======tStudent======"+tStudent);
        studentService.updateById(tStudent);
    }
 
    @ResponseBody
    @PostMapping("/student/createHistory")
    public  void createHistory(@RequestBody CreateHistoryDto createHistoryDto){
        createHistoryDto.setDate(new Date());
        studentService.createHistory(createHistoryDto);
    }
 
    @ResponseBody
    @PostMapping("/student/getHisory")
    public  List<GetHistoryDto> getHisory(){
        List<GetHistoryDto> getHistoryDtos =  studentService.getHistory();
        return getHistoryDtos;
    }
 
 
    @Resource
    private CoursePaymentClient paymentClient;
    @ResponseBody
    @PostMapping("/student/giftSelect")
    public  List<SelectDto> giftSelect(@RequestBody GiftSearchDto giftSearchDto){
        System.out.println("======giftSelect=========giftSearchDto===="+giftSearchDto);
 
//       Integer appId = studentService.getGiftSelect(giftSearchDto);
        TCoursePackagePayment coursePackagePaymentById = paymentClient.getCoursePackagePaymentById(giftSearchDto.getId());
//        System.out.println("=======giftSelect======appId====>"+appId);
        List<TStudent> selectDtos =  studentService.list(new QueryWrapper<TStudent>()
                .select("name, id")
                .eq("state", 1)
                .eq("name", giftSearchDto.getName()).eq("phone",giftSearchDto.getPhone()).ne("appUserId",coursePackagePaymentById.getAppUserId()));
 
 
        List<SelectDto> list = new ArrayList<>();
        for (TStudent student : selectDtos) {
            SelectDto selectDto = new SelectDto();
            selectDto.setValue(student.getName());
            selectDto.setId(student.getId());
            list.add(selectDto);
        }
        System.out.println("=======giftSelect======selectDtos====>"+list);
        return list;
    }
}