liujie
2023-10-09 e0cfe53794b2c90d9f42e5ec821dd5775758d737
cloud-server-account/src/main/java/com/dsh/account/controller/StudentController.java
@@ -1,16 +1,21 @@
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.Coach;
import com.dsh.account.entity.GiftSearchDto;
import com.dsh.account.entity.TStudent;
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;
@@ -19,10 +24,10 @@
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.List;
import java.util.*;
import java.util.stream.Collectors;
/**
 * @author zhibing.pu
@@ -37,6 +42,15 @@
    @Autowired
    private TokenUtil tokenUtil;
    @Autowired
    private TAppUserService appUserService;
    @Autowired
    private IVipPaymentService vipPaymentService;
    @Autowired
    private RechargeRecordsService rechargeRecordsService;
    /**
     * 添加学员
@@ -71,7 +85,7 @@
    @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));
            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();
@@ -213,7 +227,7 @@
        System.out.println("======giftSelect=========giftSearchDto===="+giftSearchDto);
//       Integer appId = studentService.getGiftSelect(giftSearchDto);
        TCoursePackagePayment coursePackagePaymentById = paymentClient.getCoursePackagePaymentById(giftSearchDto.getId());
        TCoursePackagePayment1 coursePackagePaymentById = paymentClient.getCoursePackagePaymentById1(giftSearchDto.getId());
//        System.out.println("=======giftSelect======appId====>"+appId);
        List<TStudent> selectDtos =  studentService.list(new QueryWrapper<TStudent>()
                .select("name, id")
@@ -231,4 +245,421 @@
        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>().eq(TAppUser::getInsertType, 1));
        return list.stream().map(TAppUser::getId).collect(Collectors.toList());
    }
    @PostMapping("/student/getUserYYs")
    @ResponseBody
   public  List<Integer> getUserYYs(@RequestBody Integer id){
        List<TAppUser> list = appUserService.list(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getInsertType, 2).eq(TAppUser::getAddUserId,id));
        return list.stream().map(TAppUser::getId).collect(Collectors.toList());
    }
    @PostMapping("/student/getUserStore")
    @ResponseBody
   public  List<Integer> getUserStore(@RequestBody Integer id){
        List<TAppUser> list = appUserService.list(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getInsertType, 3).eq(TAppUser::getAddUserId,id));
        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>().eq(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;
    }
    @PostMapping("/student/queryUserAge1")
    public HashMap<String, Object> queryUserAge1(){
        HashMap<String, Object> map = new HashMap<>();
        List<TAppUser> list = appUserService.list(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getInsertType, 1));
        List<Integer> collect = list.stream().map(TAppUser::getId).collect(Collectors.toList());
        if(collect.size()==0){
            collect.add(-1);
        }
        Set<String> strings = list.stream().collect(Collectors.groupingBy(TAppUser::getCity)).keySet();
        ArrayList<String> strings1 = new ArrayList<>();
        ArrayList<Integer> integers = new ArrayList<>();
        for (String string : strings) {
            int a = 0;
            strings1.add(string);
            for (TAppUser tAppUser : list) {
                if(tAppUser.getCity().equals(string)){
                    a++;
                }
            }
            integers.add(a);
        }
        map.put("cityData",strings1);
        map.put("cityNum",integers);
        int age1=0;
        int age2=0;
        int age3=0;
        int age4=0;
        int age5=0;
        int age6=0;
        int boy=0;
        int girl=0;
        for (TAppUser tStudent : list) {
            Date birthday = tStudent.getBirthday();
            long l =0;
            if(birthday!=null){
                 l = DateUtil.betweenYear(birthday, new Date(), true);
            }
            if(l<=12){
                age1++;
            }else if(l>12 && l<18){
                age2++;
            }else if(l>=19 && l<=25){
                age3++;
            }else if(l>=26 && l<=35){
                age4++;
            }else if(l>=36 && l<=50){
                age5++;
            }else {
                age6++;
            }
            if(tStudent.getGender()!=null &&tStudent.getGender()==1){
                boy++;
            }else {
                girl++;
            }
        }
        map.put("age1",age1);
        map.put("age2",age2);
        map.put("age3",age3);
        map.put("age4",age4);
        map.put("age5",age5);
        map.put("age6",age6);
        map.put("boy",boy);
        map.put("girl",girl);
        return map;
    }
    @PostMapping("/student/queryUserAgeYys")
    public HashMap<String, Object> queryUserAgeYys(Integer id){
        HashMap<String, Object> map = new HashMap<>();
        List<TAppUser> list = appUserService.list(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getInsertType, 2).eq(TAppUser::getAddUserId,id));
        List<Integer> collect = list.stream().map(TAppUser::getId).collect(Collectors.toList());
        if(collect.size()==0){
            collect.add(-1);
        }
        Set<String> strings = list.stream().collect(Collectors.groupingBy(TAppUser::getCity)).keySet();
        ArrayList<String> strings1 = new ArrayList<>();
        ArrayList<Integer> integers = new ArrayList<>();
        for (String string : strings) {
            int a = 0;
            strings1.add(string);
            for (TAppUser tAppUser : list) {
                if(tAppUser.getCity().equals(string)){
                    a++;
                }
            }
            integers.add(a);
        }
        map.put("cityData",strings1);
        map.put("cityNum",integers);
        int age1=0;
        int age2=0;
        int age3=0;
        int age4=0;
        int age5=0;
        int age6=0;
        int boy=0;
        int girl=0;
        for (TAppUser tStudent : list) {
            Date birthday = tStudent.getBirthday();
            long l =0;
            if(birthday!=null){
                 l = DateUtil.betweenYear(birthday, new Date(), true);
            }
            if(l<=12){
                age1++;
            }else if(l>12 && l<18){
                age2++;
            }else if(l>=19 && l<=25){
                age3++;
            }else if(l>=26 && l<=35){
                age4++;
            }else if(l>=36 && l<=50){
                age5++;
            }else {
                age6++;
            }
            if(tStudent.getGender()!=null &&tStudent.getGender()==1){
                boy++;
            }else {
                girl++;
            }
        }
        map.put("age1",age1);
        map.put("age2",age2);
        map.put("age3",age3);
        map.put("age4",age4);
        map.put("age5",age5);
        map.put("age6",age6);
        map.put("boy",boy);
        map.put("girl",girl);
        return map;
    }
    @PostMapping("/student/queryUserAgeStore")
    public HashMap<String, Object> queryUserAgeStore(Integer id){
        HashMap<String, Object> map = new HashMap<>();
        List<TAppUser> list = appUserService.list(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getInsertType, 3).eq(TAppUser::getAddUserId,id));
        List<Integer> collect = list.stream().map(TAppUser::getId).collect(Collectors.toList());
        if(collect.size()==0){
            collect.add(-1);
        }
        Set<String> strings = list.stream().collect(Collectors.groupingBy(TAppUser::getCity)).keySet();
        ArrayList<String> strings1 = new ArrayList<>();
        ArrayList<Integer> integers = new ArrayList<>();
        for (String string : strings) {
            int a = 0;
            strings1.add(string);
            for (TAppUser tAppUser : list) {
                if(tAppUser.getCity().equals(string)){
                    a++;
                }
            }
            integers.add(a);
        }
        map.put("cityData",strings1);
        map.put("cityNum",integers);
        int age1=0;
        int age2=0;
        int age3=0;
        int age4=0;
        int age5=0;
        int age6=0;
        int boy=0;
        int girl=0;
        for (TAppUser tStudent : list) {
            Date birthday = tStudent.getBirthday();
            long l =0;
            if(birthday!=null){
                 l = DateUtil.betweenYear(birthday, new Date(), true);
            }
            if(l<=12){
                age1++;
            }else if(l>12 && l<18){
                age2++;
            }else if(l>=19 && l<=25){
                age3++;
            }else if(l>=26 && l<=35){
                age4++;
            }else if(l>=36 && l<=50){
                age5++;
            }else {
                age6++;
            }
            if(tStudent.getGender()!=null &&tStudent.getGender()==1){
                boy++;
            }else {
                girl++;
            }
        }
        map.put("age1",age1);
        map.put("age2",age2);
        map.put("age3",age3);
        map.put("age4",age4);
        map.put("age5",age5);
        map.put("age6",age6);
        map.put("boy",boy);
        map.put("girl",girl);
        return map;
    }
    @PostMapping("/student/queryUserAgeYys1")
    public HashMap<String, Object> queryUserAgeYys1(@RequestBody Integer id){
        HashMap<String, Object> map = new HashMap<>();
        List<TAppUser> list = appUserService.list(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getInsertType, 2).eq(TAppUser::getAddUserId,id));
        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;
    }
    @PostMapping("/student/queryUserAgeStore1")
    public HashMap<String, Object> queryUserAgeStore1(@RequestBody Integer id){
        HashMap<String, Object> map = new HashMap<>();
        List<TAppUser> list = appUserService.list(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getInsertType, 3).eq(TAppUser::getAddUserId,id));
        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;
    }
}