package com.dsh.account.controller;
|
|
import cn.hutool.core.date.DateUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.dsh.account.dto.*;
|
import com.dsh.account.entity.*;
|
import com.dsh.account.feignclient.course.CoursePaymentClient;
|
import com.dsh.account.feignclient.course.model.TCoursePackagePayment;
|
import com.dsh.account.model.QueryDataFee;
|
import com.dsh.account.model.StudentVo;
|
import com.dsh.account.service.IVipPaymentService;
|
import com.dsh.account.service.RechargeRecordsService;
|
import com.dsh.account.service.TAppUserService;
|
import com.dsh.account.service.TStudentService;
|
import com.dsh.account.util.ResultUtil;
|
import com.dsh.account.util.TokenUtil;
|
import com.dsh.account.util.ToolUtil;
|
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.math.BigDecimal;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* @author zhibing.pu
|
* @date 2023/6/24 14:59
|
*/
|
@RestController
|
@RequestMapping("")
|
public class StudentController {
|
|
@Autowired
|
private TStudentService studentService;
|
|
@Autowired
|
private TokenUtil tokenUtil;
|
|
@Autowired
|
private TAppUserService appUserService;
|
|
@Autowired
|
private IVipPaymentService vipPaymentService;
|
|
@Autowired
|
private RechargeRecordsService rechargeRecordsService;
|
|
/**
|
* 添加学员
|
* @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).last("limit 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);
|
TCoursePackagePayment1 coursePackagePaymentById = paymentClient.getCoursePackagePaymentById1(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;
|
}
|
|
|
@PostMapping("/student/getUserPt")
|
@ResponseBody
|
public List<Integer> getUserPt(@RequestBody List<Integer> ids){
|
if(ids.size()==0){
|
ids.add(-1);
|
}
|
List<TAppUser> list = appUserService.list(new LambdaQueryWrapper<TAppUser>().in(TAppUser::getInsertType, 1));
|
return list.stream().map(TAppUser::getId).collect(Collectors.toList());
|
}
|
|
|
@PostMapping("/student/queryFee")
|
public HashMap<String, Object> queryFee(@RequestBody QueryDataFee queryDataFee){
|
HashMap<String, Object> map = new HashMap<>();
|
String data = queryDataFee.getData();
|
List<Integer> ids = queryDataFee.getIds();
|
if(ids.size()==0){
|
ids.add(-1);
|
}
|
LambdaQueryWrapper<VipPayment> vipPaymentLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
if(ToolUtil.isNotEmpty(data)){
|
String stime = data.split(" - ")[0]+" 00:00:00";
|
String etime = data.split(" - ")[1]+" 23:59:59";
|
vipPaymentLambdaQueryWrapper.between(VipPayment::getInsertTime,stime,etime);
|
}
|
vipPaymentLambdaQueryWrapper.in(VipPayment::getAppUserId,ids);
|
vipPaymentLambdaQueryWrapper.eq(VipPayment::getPayStatus,2);
|
List<VipPayment> list = vipPaymentService.list(vipPaymentLambdaQueryWrapper);
|
double sum = list.stream().mapToDouble(VipPayment::getAmount).sum();
|
|
map.put("fee1",sum);
|
|
LambdaQueryWrapper<RechargeRecords> rechargeRecordsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
if(ToolUtil.isNotEmpty(data)){
|
String stime = data.split(" - ")[0]+" 00:00:00";
|
String etime = data.split(" - ")[1]+" 23:59:59";
|
rechargeRecordsLambdaQueryWrapper.between(RechargeRecords::getInsertTime,stime,etime);
|
}
|
rechargeRecordsLambdaQueryWrapper.in(RechargeRecords::getAppUserId,ids);
|
rechargeRecordsLambdaQueryWrapper.eq(RechargeRecords::getPayStatus,2);
|
List<RechargeRecords> list1 = rechargeRecordsService.list(rechargeRecordsLambdaQueryWrapper);
|
double sum1 = list1.stream().map(RechargeRecords::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add).doubleValue();
|
|
map.put("fee2",sum1);
|
|
|
|
|
return map;
|
|
|
}
|
|
|
|
@PostMapping("/student/queryUserAge")
|
public HashMap<String, Object> queryUserAge(){
|
HashMap<String, Object> map = new HashMap<>();
|
List<TAppUser> list = appUserService.list(new LambdaQueryWrapper<TAppUser>().in(TAppUser::getInsertType, 1));
|
List<Integer> collect = list.stream().map(TAppUser::getId).collect(Collectors.toList());
|
if(collect.size()==0){
|
collect.add(-1);
|
}
|
List<TStudent> list1 = studentService.list(new LambdaQueryWrapper<TStudent>().in(TStudent::getAppUserId, collect));
|
int age1=0;
|
int age2=0;
|
int age3=0;
|
int age4=0;
|
int boy=0;
|
int girl=0;
|
for (TStudent tStudent : list1) {
|
Date birthday = tStudent.getBirthday();
|
long l = DateUtil.betweenYear(birthday, new Date(), true);
|
if(l<7){
|
age1++;
|
}else if(l>=8 && l<11){
|
age2++;
|
}else if(l>=11 && l<=12){
|
age3++;
|
}else {
|
age4++;
|
}
|
if(tStudent.getSex()==1){
|
boy++;
|
}else {
|
girl++;
|
}
|
}
|
map.put("age1",age1);
|
map.put("age2",age2);
|
map.put("age3",age3);
|
map.put("age4",age4);
|
map.put("boy",boy);
|
map.put("girl",girl);
|
return map;
|
|
|
|
}
|
}
|