From b2699c029a213fe896d2de7835791dd778a9fb49 Mon Sep 17 00:00:00 2001
From: nickchange <126672920+nickchange@users.noreply.github.com>
Date: 星期四, 26 十月 2023 10:24:56 +0800
Subject: [PATCH] 10.26.1
---
cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java | 610 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 580 insertions(+), 30 deletions(-)
diff --git a/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java b/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java
index 737901c..d3b0fcf 100644
--- a/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java
+++ b/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"));
@@ -229,7 +234,7 @@
.eq("coursePackageId", coursePackage.getId())
.eq("classDate", classDate.getTime())
.eq("endDate", endDate.getTime()));
- if (list.size()+1>coursePackage.getMaxSubscribeNumber()){
+ if (list1.size()+1>coursePackage.getMaxSubscribeNumber()){
// 当前课包预约人数已满
return 5001;
}
@@ -264,6 +269,13 @@
public Object changeState(@RequestBody CoursePackagePayDTO dto){
return packagePaymentService.changeState(dto);
+ }
+ @GetMapping("/coursePackagePayment/courseStore/{appUserId}/{coursePackageId}")
+ public List<TCoursePackagePayment> getByUserIdAndCoursePackageId(@PathVariable("appUserId") Integer appUserId,@PathVariable("coursePackageId") Integer coursePackageId){
+ List<TCoursePackagePayment> list = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
+ .eq("appUserId", appUserId)
+ .eq("coursePackageId", coursePackageId));
+ return list;
}
/**
* 获取购课记录
@@ -369,16 +381,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());
@@ -388,6 +411,11 @@
re.setPayUser(appUser.getName());
re.setPhone(appUser.getPhone());
re.setStoreName(store.getName());
+ // 在这里添加条件来删除不满足要求的元素
+
+ if (query.getInsertType() !=null && appUser.getInsertType() != query.getInsertType()) {
+ iterator.remove(); // 使用迭代器的 remove 方法删除元素
+ }
}
return res;
}
@@ -416,8 +444,10 @@
resp.setTotalCourseNums(tCoursePackagePayment.getTotalClassHours());
resp.setResidueNums(tCoursePackagePayment.getLaveClassHours());
resp.setDeductionNums(tCoursePackagePayment.getTotalClassHours()-tCoursePackagePayment.getLaveClassHours());
+ if (tCoursePackage.getValidDays()!=null){
String afterDayDate = DateUtil.getAfterDayDate2(tCoursePackage.getInsertTime(),tCoursePackage.getValidDays() + "");
resp.setPeriodOfValidity(afterDayDate);
+ }
resps.add(resp);
}
}
@@ -731,27 +761,53 @@
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
})
- public ResultUtil<List<AppUserVideoResponse>> queryAfterSourceList( CourseOfAfterRequest search){
- try {
+ public ResultUtil<List<AppUserVideoResponse>> queryAfterSourceList( CourseOfAfterRequest search) throws Exception {
+// try {
Integer appUserId = tokenUtil.getUserIdFormRedis();
if(null == appUserId){
return ResultUtil.tokenErr();
}
- List<Integer> courseIds = new ArrayList<>();
- QueryWrapper<TCoursePackagePayment> queryWrapper = new QueryWrapper<TCoursePackagePayment>().eq("appUserId", appUserId)
- .groupBy("coursePackageId");
+//
+// List<Integer> courseIds = new ArrayList<>();
+// QueryWrapper<TCoursePackagePayment> queryWrapper = new QueryWrapper<TCoursePackagePayment>().eq("appUserId", appUserId)
+// .groupBy("coursePackageId");
+// if (ToolUtil.isNotEmpty(search.getCourseTypeId())){
+// queryWrapper.eq("coursePackageId",search.getCourseTypeId());
+// }
+// List<TCoursePackagePayment> tCoursePackagePayments = packagePaymentService.list(queryWrapper);
+// if (tCoursePackagePayments.size() > 0 ){
+// courseIds = tCoursePackagePayments.stream().map(TCoursePackagePayment::getCoursePackageId).collect(Collectors.toList());
+// }
+
+
+ QueryWrapper<CoursePackageStudent> queryWrapper1 = new QueryWrapper<CoursePackageStudent>().eq("appUserId", appUserId);
if (ToolUtil.isNotEmpty(search.getCourseTypeId())){
- queryWrapper.eq("coursePackageId",search.getCourseTypeId());
+ queryWrapper1.eq("coursePackageId",search.getCourseTypeId());
}
- List<TCoursePackagePayment> tCoursePackagePayments = packagePaymentService.list(queryWrapper);
- if (tCoursePackagePayments.size() > 0 ){
- courseIds = tCoursePackagePayments.stream().map(TCoursePackagePayment::getCoursePackageId).collect(Collectors.toList());
+
+ List<CoursePackageStudent> list = coursePackageStudentService.list(queryWrapper1);
+ List<Long> longs = new ArrayList<>();
+ for (CoursePackageStudent coursePackageStudent : list) {
+ longs.add(coursePackageStudent.getCoursePackageSchedulingId());
}
- return ResultUtil.success(packagePaymentService.queryAfterVideo(search,courseIds));
- }catch (Exception e){
- return ResultUtil.runErr();
- }
+
+ System.out.println("======longs========"+longs);
+ List<CoursePackageScheduling> coursePackageSchedulings = coursePackageSchedulingService.list(new QueryWrapper<CoursePackageScheduling>().in("id",longs).isNotNull("courseId"));
+ List<AppUserVideoResponse> coursePackageSchedulings1 = coursePackageSchedulingService.queryAll(longs);
+
+
+
+
+ return ResultUtil.success(coursePackageSchedulings1);
+
+
+
+
+
+// }catch (Exception e){
+// return ResultUtil.runErr();
+// }
}
/**
@@ -1243,15 +1299,15 @@
return packagePaymentService.save(packagePayment);
}
-
+ @ResponseBody
@PostMapping("/base/coursePack/obtainStudentClassDetails")
public List<RecordAppoint> obtainStudentClassDetailsData(@RequestBody WeeksOfCourseRest stuId){
- try {
- return packagePaymentService.obtainStuClassDetails(stuId.getStuId(),stuId.getAppUserId());
- }catch (Exception e){
- e.printStackTrace();
- throw new RuntimeException();
- }
+// try {
+ return packagePaymentService.obtainStuClassDetails(stuId.getStuId(),stuId.getAppUserId(),stuId.getPageNum());
+// }catch (Exception e){
+// e.printStackTrace();
+// throw new RuntimeException();
+// }
}
@@ -1455,7 +1511,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);
@@ -1558,4 +1614,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;
+
+ }
}
--
Gitblit v1.7.1