nickchange
2023-10-18 062fb1ed6efcaac5d75bbe184524c4929dff7fcd
cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java
@@ -54,6 +54,11 @@
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
@@ -140,7 +145,7 @@
        Integer studentId = packagePayment.getStudentId();
        // 添加学员上课记录
        CoursePackageStudent coursePackageStudent = new CoursePackageStudent();
        TCoursePackagePayment one = packagePaymentService.getOne(new QueryWrapper<TCoursePackagePayment>().eq("studentId", packagePayment)
        TCoursePackagePayment one = packagePaymentService.getOne(new QueryWrapper<TCoursePackagePayment>().eq("studentId", packagePayment.getStudentId())
                .orderByDesc("insertTime")
                .last("LIMIT 1"));
@@ -149,7 +154,10 @@
            Integer absencesNumber = one.getAbsencesNumber();
            // 没有过期
            if (one.getUseTime().after(new Date())){
                packagePayment.setTotalClassHours(packagePayment.getClassHours()+one.getTotalClassHours());
                if (one.getLaveClassHours()-packagePayment.getClassHours()<0){
                    return 5002;
                }
                packagePayment.setTotalClassHours(one.getTotalClassHours());
                packagePayment.setLaveClassHours(one.getLaveClassHours()-packagePayment.getClassHours());
                packagePayment.setAbsencesNumber(one.getAbsencesNumber());
            }
@@ -366,16 +374,27 @@
        }
        List<RegisterOrderVO> res = packagePaymentService.listAllRegister(query);
        // 该运营商下没有门店
        if (query.getStoresIds()!=null){
            if (query.getStoresIds().size()==0){
                List<RegisterOrderVO> registerOrderVOS = new ArrayList<>();
                return registerOrderVOS;
            }
        }
        List<RegisterOrderVO> result = new ArrayList<>();
        for (RegisterOrderVO re : res) {
            if(re.getSalesName()==null){
        Iterator<RegisterOrderVO> iterator = res.iterator();
        while (iterator.hasNext()) {
            RegisterOrderVO re = iterator.next();
            if (re.getSalesName() == null) {
                re.setSalesName("无");
            }
            if(re.getPayType()!=null){
                if (re.getPayType() == 3){
                    re.setPayMoneyAndType(re.getPlayPaiCoin()+"玩湃币");
                }else{
                    re.setPayMoneyAndType("¥"+re.getMoney());
            if (re.getPayType() != null) {
                if (re.getPayType() == 3) {
                    re.setPayMoneyAndType(re.getPlayPaiCoin() + "玩湃币");
                } else {
                    re.setPayMoneyAndType("¥" + re.getMoney());
                }
            }
            Store store = storeClient.queryStoreById(re.getStoreId());
@@ -385,6 +404,10 @@
            re.setPayUser(appUser.getName());
            re.setPhone(appUser.getPhone());
            re.setStoreName(store.getName());
            // 在这里添加条件来删除不满足要求的元素
            if (appUser.getInsertType() != query.getInsertType()) {
                iterator.remove(); // 使用迭代器的 remove 方法删除元素
            }
        }
        return res;
    }
@@ -1452,7 +1475,7 @@
            String time1 = courseDetailReq.getTime();
            // 找出门店的所有课程 排出体验
            List<TCoursePackage> list = tcpService.list(new LambdaQueryWrapper<TCoursePackage>().eq(TCoursePackage::getStoreId, courseDetailReq.getStoreId()).ne(TCoursePackage::getType, 3).like(TCoursePackage::getClassWeeks,week));
            List<TCoursePackage> list = tcpService.list(new LambdaQueryWrapper<TCoursePackage>().eq(TCoursePackage::getStoreId, courseDetailReq.getStoreId()).ne(TCoursePackage::getType, 3).eq(TCoursePackage::getState,1).like(TCoursePackage::getClassWeeks,week));
            List<Integer> collect = list.stream().map(TCoursePackage::getId).collect(Collectors.toList());
            if(collect.size()==0){
                collect.add(-1);
@@ -1555,4 +1578,498 @@
        return a;
    }
    @ResponseBody
    @PostMapping("/coursePackagePayment/queryCourseData")
    public List<Map<String,Object>> queryCourseData(@RequestBody List<Integer> ids){
        // 找出课程类型  找出剩余的课时数
        List<TCoursePackageType> list = coursePackageTypeService.list();
        if(ids.size()==0){
            ids.add(-1);
        }
        List<TCoursePackagePayment> list1 = packagePaymentService.listOne(ids);
        List<Integer> collect = list1.stream().map(TCoursePackagePayment::getCoursePackageId).collect(Collectors.toList());
        if(collect.size()==0){
            collect.add(-1);
        }
        List<TCoursePackage> list2 = tcpService.list(new LambdaQueryWrapper<TCoursePackage>().in(TCoursePackage::getId, collect));
        for (TCoursePackagePayment tCoursePackagePayment : list1) {
            for (TCoursePackage tCoursePackage : list2) {
                if(tCoursePackagePayment.getCoursePackageId().equals(tCoursePackage.getId())){
                    tCoursePackagePayment.setType(tCoursePackage.getType());
                }
            }
        }
        List<Map<String,Object>> mapList = new ArrayList<>();
        for (TCoursePackageType tCoursePackageType : list) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("name",tCoursePackageType.getName());
            int a =0;
            for (TCoursePackagePayment tCoursePackagePayment : list1) {
                if(tCoursePackagePayment.getType().equals(tCoursePackageType.getId())){
                    a += tCoursePackagePayment.getLaveClassHours();
                }
            }
            map.put("value",a);
            mapList.add(map);
        }
        return mapList;
    }
    @ResponseBody
    @PostMapping("/coursePackagePayment/coursePt")
    HashMap<String, Object> coursePt(@RequestBody List<Integer> userPt){
        if(userPt.size()==0){
            userPt.add(-1);
        }
        HashMap<String, Object> map = new HashMap<>();
        List<TCoursePackagePayment> tCoursePackagePayments = packagePaymentService.listOne(userPt);
        int sum = tCoursePackagePayments.stream().mapToInt(TCoursePackagePayment::getTotalClassHours).sum();
        int sum1 = tCoursePackagePayments.stream().mapToInt(TCoursePackagePayment::getLaveClassHours).sum();
        map.put("allCourse",sum-sum1);
        //所有课包
        List<TCoursePackage> coursePackages = tcpService.list();
        // 年
        List<CoursePackageStudent> list = cspsService.list(new LambdaQueryWrapper<CoursePackageStudent>().in(CoursePackageStudent::getAppUserId, userPt));
        for (CoursePackageStudent coursePackageStudent : list) {
            for (TCoursePackage coursePackage : coursePackages) {
                if(coursePackageStudent.getCoursePackageId().equals(coursePackage.getId())){
                    if(ToolUtil.isEmpty(coursePackage.getNeedNum())){
                        coursePackageStudent.setNeedNum(0);
                    }else {
                        coursePackageStudent.setNeedNum(coursePackage.getNeedNum());
                    }
                }
            }
        }
        ArrayList<Object> integers = new ArrayList<>();
        int year = cn.hutool.core.date.DateUtil.year(new Date());
        for (int i = 0; i < 10; i++) {
            integers.add(year-i);
        }
        List<Object> collect = integers.stream().sorted().collect(Collectors.toList());
        // 年
        ArrayList<Integer> years = new ArrayList<>();
        for (Object o : collect) {
            String s = o.toString();
            List<CoursePackageStudent> collect1 = list.stream().filter(e -> e.getInsertTime().toString().contains(s)).filter(student -> student.getNeedNum() != null).collect(Collectors.toList());
            int sum2 = collect1.stream().mapToInt(CoursePackageStudent::getNeedNum).sum();
            years.add(sum2);
        }
        map.put("yearData",years);
        ArrayList<Integer> months = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 月
        for (int i = 1; i <= 12; i++) {
            String m=i+"";
            if(i<10){
                m="0"+i;
            }
            String s = year + "-" + m;
            List<CoursePackageStudent> collect1 = list.stream().filter(e -> format.format(e.getInsertTime()).contains(s)).filter(student -> student.getNeedNum() != null).collect(Collectors.toList());
            int sum2 = collect1.stream().mapToInt(CoursePackageStudent::getNeedNum).sum();
            months.add(sum2);
        }
        map.put("monthData",months);
        // 周
        // 获取最近四周
        LocalDateTime minNow = LocalDateTime.now().with(LocalTime.MIN);
        LocalDateTime maxNow = LocalDateTime.now().with(LocalTime.MAX);
        // 周度数据
        LocalDateTime s1 = minNow.minusDays(6);
        LocalDateTime s2 = maxNow;
        LocalDateTime s3 = minNow.minusDays(13);
        LocalDateTime s4 = maxNow.minusDays(6);
        LocalDateTime s5 = minNow.minusDays(20);
        LocalDateTime s6 = maxNow.minusDays(13);
        LocalDateTime s7 = minNow.minusDays(27);
        LocalDateTime s8 = maxNow.minusDays(20);
        ArrayList<Object> weekData = new ArrayList<>();
        int count  = 0;
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        for (CoursePackageStudent coursePackageStudent : list) {
            if (coursePackageStudent.getNeedNum()==null){
                continue;
            }
            // 如果到课状态为否 则不计算
            if (coursePackageStudent.getSignInOrNot() != 0) {
                Date insertTime = coursePackageStudent.getInsertTime();
                Instant instant = insertTime.toInstant();
                ZoneId zoneId = ZoneId.systemDefault();
                LocalDateTime dateTime = instant.atZone(zoneId).toLocalDateTime();
                if (dateTime.isAfter(s1) && dateTime.isBefore(s2)){
                    count+=coursePackageStudent.getNeedNum();
                }else if(dateTime.isAfter(s3) && dateTime.isBefore(s4)){
                    count1+=coursePackageStudent.getNeedNum();
                }else if(dateTime.isAfter(s5) && dateTime.isBefore(s6)){
                    count2+=coursePackageStudent.getNeedNum();
                }else if(dateTime.isAfter(s7) && dateTime.isBefore(s8)){
                    count3+=coursePackageStudent.getNeedNum();
                }
            }
        }
        weekData.add(count3);
        weekData.add(count2);
        weekData.add(count1);
        weekData.add(count);
        map.put("weekData",weekData);
        LocalDateTime currentDateTime = LocalDateTime.now();
        List<Integer> amountByDay = new ArrayList<>(Collections.nCopies(7,0));
        for (CoursePackageStudent coursePackageStudent : list) {
            Date insertTime = coursePackageStudent.getInsertTime();
            // 将 Date 转换为 LocalDateTime
            LocalDateTime insertDateTime = LocalDateTime.ofInstant(insertTime.toInstant(), ZoneId.systemDefault());
            // 计算日期与当前日期的差距
            long daysDifference = ChronoUnit.DAYS.between(insertDateTime.toLocalDate(), currentDateTime.toLocalDate());
            // 如果日期在七天内,累加金额
            if (daysDifference >= 0 && daysDifference < 7) {
                int index = (int) (6 - daysDifference); // 计算对应的索引位置
                Integer needNum = coursePackageStudent.getNeedNum();
                if (needNum!=null){
                    int i = amountByDay.get(index) + needNum;
                    amountByDay.set(index, i);
                }
            }
        }
        map.put("dayData", amountByDay);
        return map;
    }
    @ResponseBody
    @PostMapping("/coursePackagePayment/courseYys")
    HashMap<String, Object> courseYys(@RequestBody List<Integer> userPt){
        if(userPt.size()==0){
            userPt.add(-1);
        }
        HashMap<String, Object> map = new HashMap<>();
        List<TCoursePackagePayment> tCoursePackagePayments = packagePaymentService.listOne(userPt);
        int sum = tCoursePackagePayments.stream().mapToInt(TCoursePackagePayment::getTotalClassHours).sum();
        int sum1 = tCoursePackagePayments.stream().mapToInt(TCoursePackagePayment::getLaveClassHours).sum();
        map.put("allCourse",sum-sum1);
        //所有课包
        List<TCoursePackage> coursePackages = tcpService.list();
        // 年
        List<CoursePackageStudent> list = cspsService.list(new LambdaQueryWrapper<CoursePackageStudent>().in(CoursePackageStudent::getAppUserId, userPt));
        for (CoursePackageStudent coursePackageStudent : list) {
            for (TCoursePackage coursePackage : coursePackages) {
                if(coursePackageStudent.getCoursePackageId().equals(coursePackage.getId())){
                    if(ToolUtil.isEmpty(coursePackage.getNeedNum())){
                        coursePackageStudent.setNeedNum(0);
                    }else {
                        coursePackageStudent.setNeedNum(coursePackage.getNeedNum());
                    }
                }
            }
        }
        ArrayList<Object> integers = new ArrayList<>();
        int year = cn.hutool.core.date.DateUtil.year(new Date());
        for (int i = 0; i < 10; i++) {
            integers.add(year-i);
        }
        List<Object> collect = integers.stream().sorted().collect(Collectors.toList());
        // 年
        ArrayList<Integer> years = new ArrayList<>();
        for (Object o : collect) {
            String s = o.toString();
            List<CoursePackageStudent> collect1 = list.stream().filter(e -> e.getInsertTime().toString().contains(s)).filter(student -> student.getNeedNum() != null).collect(Collectors.toList());
            int sum2 = collect1.stream().mapToInt(CoursePackageStudent::getNeedNum).sum();
            years.add(sum2);
        }
        map.put("yearData",years);
        ArrayList<Integer> months = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 月
        for (int i = 1; i <= 12; i++) {
            String m=i+"";
            if(i<10){
                m="0"+i;
            }
            String s = year + "-" + m;
            List<CoursePackageStudent> collect1 = list.stream().filter(e -> format.format(e.getInsertTime()).contains(s)).filter(student -> student.getNeedNum() != null).collect(Collectors.toList());
            int sum2 = collect1.stream().mapToInt(CoursePackageStudent::getNeedNum).sum();
            months.add(sum2);
        }
        map.put("monthData",months);
        // 周
        // 获取最近四周
        LocalDateTime minNow = LocalDateTime.now().with(LocalTime.MIN);
        LocalDateTime maxNow = LocalDateTime.now().with(LocalTime.MAX);
        // 周度数据
        LocalDateTime s1 = minNow.minusDays(6);
        LocalDateTime s2 = maxNow;
        LocalDateTime s3 = minNow.minusDays(13);
        LocalDateTime s4 = maxNow.minusDays(6);
        LocalDateTime s5 = minNow.minusDays(20);
        LocalDateTime s6 = maxNow.minusDays(13);
        LocalDateTime s7 = minNow.minusDays(27);
        LocalDateTime s8 = maxNow.minusDays(20);
        ArrayList<Object> weekData = new ArrayList<>();
        int count  = 0;
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        for (CoursePackageStudent coursePackageStudent : list) {
            if (coursePackageStudent.getNeedNum()==null){
                continue;
            }
            // 如果到课状态为否 则不计算
            if (coursePackageStudent.getSignInOrNot() != 0) {
                Date insertTime = coursePackageStudent.getInsertTime();
                Instant instant = insertTime.toInstant();
                ZoneId zoneId = ZoneId.systemDefault();
                LocalDateTime dateTime = instant.atZone(zoneId).toLocalDateTime();
                if (dateTime.isAfter(s1) && dateTime.isBefore(s2)){
                    count+=coursePackageStudent.getNeedNum();
                }else if(dateTime.isAfter(s3) && dateTime.isBefore(s4)){
                    count1+=coursePackageStudent.getNeedNum();
                }else if(dateTime.isAfter(s5) && dateTime.isBefore(s6)){
                    count2+=coursePackageStudent.getNeedNum();
                }else if(dateTime.isAfter(s7) && dateTime.isBefore(s8)){
                    count3+=coursePackageStudent.getNeedNum();
                }
            }
        }
        weekData.add(count3);
        weekData.add(count2);
        weekData.add(count1);
        weekData.add(count);
        map.put("weekData",weekData);
        LocalDateTime currentDateTime = LocalDateTime.now();
        List<Integer> amountByDay = new ArrayList<>(Collections.nCopies(7,0));
        for (CoursePackageStudent coursePackageStudent : list) {
            Date insertTime = coursePackageStudent.getInsertTime();
            // 将 Date 转换为 LocalDateTime
            LocalDateTime insertDateTime = LocalDateTime.ofInstant(insertTime.toInstant(), ZoneId.systemDefault());
            // 计算日期与当前日期的差距
            long daysDifference = ChronoUnit.DAYS.between(insertDateTime.toLocalDate(), currentDateTime.toLocalDate());
            // 如果日期在七天内,累加金额
            if (daysDifference >= 0 && daysDifference < 7) {
                int index = (int) (6 - daysDifference); // 计算对应的索引位置
                Integer needNum = coursePackageStudent.getNeedNum();
                if (needNum!=null){
                    int i = amountByDay.get(index) + needNum;
                    amountByDay.set(index, i);
                }
            }
        }
        map.put("dayData", amountByDay);
        return map;
    }
    @ResponseBody
    @PostMapping("/coursePackagePayment/courseStore")
    HashMap<String, Object> courseStore(@RequestBody List<Integer> userPt){
        if(userPt.size()==0){
            userPt.add(-1);
        }
        HashMap<String, Object> map = new HashMap<>();
        List<TCoursePackagePayment> tCoursePackagePayments = packagePaymentService.listOne(userPt);
        int sum = tCoursePackagePayments.stream().mapToInt(TCoursePackagePayment::getTotalClassHours).sum();
        int sum1 = tCoursePackagePayments.stream().mapToInt(TCoursePackagePayment::getLaveClassHours).sum();
        map.put("allCourse",sum-sum1);
        //所有课包
        List<TCoursePackage> coursePackages = tcpService.list();
        // 年
        List<CoursePackageStudent> list = cspsService.list(new LambdaQueryWrapper<CoursePackageStudent>().in(CoursePackageStudent::getAppUserId, userPt));
        for (CoursePackageStudent coursePackageStudent : list) {
            for (TCoursePackage coursePackage : coursePackages) {
                if(coursePackageStudent.getCoursePackageId().equals(coursePackage.getId())){
                    if(ToolUtil.isEmpty(coursePackage.getNeedNum())){
                        coursePackageStudent.setNeedNum(0);
                    }else {
                        coursePackageStudent.setNeedNum(coursePackage.getNeedNum());
                    }
                }
            }
        }
        ArrayList<Object> integers = new ArrayList<>();
        int year = cn.hutool.core.date.DateUtil.year(new Date());
        for (int i = 0; i < 10; i++) {
            integers.add(year-i);
        }
        List<Object> collect = integers.stream().sorted().collect(Collectors.toList());
        // 年
        ArrayList<Integer> years = new ArrayList<>();
        for (Object o : collect) {
            String s = o.toString();
            List<CoursePackageStudent> collect1 = list.stream().filter(e -> e.getInsertTime().toString().contains(s)).filter(student -> student.getNeedNum() != null).collect(Collectors.toList());
            int sum2 = collect1.stream().mapToInt(CoursePackageStudent::getNeedNum).sum();
            years.add(sum2);
        }
        map.put("yearData",years);
        ArrayList<Integer> months = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 月
        for (int i = 1; i <= 12; i++) {
            String m=i+"";
            if(i<10){
                m="0"+i;
            }
            String s = year + "-" + m;
            List<CoursePackageStudent> collect1 = list.stream().filter(e -> format.format(e.getInsertTime()).contains(s)).filter(student -> student.getNeedNum() != null).collect(Collectors.toList());
            int sum2 = collect1.stream().mapToInt(CoursePackageStudent::getNeedNum).sum();
            months.add(sum2);
        }
        map.put("monthData",months);
        // 周
        // 获取最近四周
        LocalDateTime minNow = LocalDateTime.now().with(LocalTime.MIN);
        LocalDateTime maxNow = LocalDateTime.now().with(LocalTime.MAX);
        // 周度数据
        LocalDateTime s1 = minNow.minusDays(6);
        LocalDateTime s2 = maxNow;
        LocalDateTime s3 = minNow.minusDays(13);
        LocalDateTime s4 = maxNow.minusDays(6);
        LocalDateTime s5 = minNow.minusDays(20);
        LocalDateTime s6 = maxNow.minusDays(13);
        LocalDateTime s7 = minNow.minusDays(27);
        LocalDateTime s8 = maxNow.minusDays(20);
        ArrayList<Object> weekData = new ArrayList<>();
        int count  = 0;
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        for (CoursePackageStudent coursePackageStudent : list) {
            if (coursePackageStudent.getNeedNum()==null){
                continue;
            }
            // 如果到课状态为否 则不计算
            if (coursePackageStudent.getSignInOrNot() != 0) {
                Date insertTime = coursePackageStudent.getInsertTime();
                Instant instant = insertTime.toInstant();
                ZoneId zoneId = ZoneId.systemDefault();
                LocalDateTime dateTime = instant.atZone(zoneId).toLocalDateTime();
                if (dateTime.isAfter(s1) && dateTime.isBefore(s2)){
                    count+=coursePackageStudent.getNeedNum();
                }else if(dateTime.isAfter(s3) && dateTime.isBefore(s4)){
                    count1+=coursePackageStudent.getNeedNum();
                }else if(dateTime.isAfter(s5) && dateTime.isBefore(s6)){
                    count2+=coursePackageStudent.getNeedNum();
                }else if(dateTime.isAfter(s7) && dateTime.isBefore(s8)){
                    count3+=coursePackageStudent.getNeedNum();
                }
            }
        }
        weekData.add(count3);
        weekData.add(count2);
        weekData.add(count1);
        weekData.add(count);
        map.put("weekData",weekData);
        LocalDateTime currentDateTime = LocalDateTime.now();
        List<Integer> amountByDay = new ArrayList<>(Collections.nCopies(7,0));
        for (CoursePackageStudent coursePackageStudent : list) {
            Date insertTime = coursePackageStudent.getInsertTime();
            // 将 Date 转换为 LocalDateTime
            LocalDateTime insertDateTime = LocalDateTime.ofInstant(insertTime.toInstant(), ZoneId.systemDefault());
            // 计算日期与当前日期的差距
            long daysDifference = ChronoUnit.DAYS.between(insertDateTime.toLocalDate(), currentDateTime.toLocalDate());
            // 如果日期在七天内,累加金额
            if (daysDifference >= 0 && daysDifference < 7) {
                int index = (int) (6 - daysDifference); // 计算对应的索引位置
                Integer needNum = coursePackageStudent.getNeedNum();
                if (needNum!=null){
                    int i = amountByDay.get(index) + needNum;
                    amountByDay.set(index, i);
                }
            }
        }
        map.put("dayData", amountByDay);
        return map;
    }
}