|
@@ -1,6 +1,7 @@
|
|
|
package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
@@ -46,6 +47,7 @@ import java.time.LocalDate;
|
|
|
import java.time.temporal.TemporalAdjusters;
|
|
|
import java.util.*;
|
|
|
import java.util.function.BiConsumer;
|
|
|
+import java.util.function.BiFunction;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -443,31 +445,37 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
|
|
|
*/
|
|
|
private List<CourseCalendarEntity> generatePracticeCalendar(TeacherFreeTime teacherTime, LocalDate firstDay, LocalDate lastDay) {
|
|
|
//将老师设置的陪练课时间结构化 key::数字周几 1~7 value:具体的时间 开始时间-结束时间
|
|
|
- Map<Integer, List<CourseTimeEntity>> teacherPracticeTime = getTeacherPracticeTime(teacherTime);
|
|
|
+ Map<Integer, JSONArray> teacherPracticeTime = getTeacherPracticeTime(teacherTime);
|
|
|
//每日日期数据
|
|
|
List<CourseCalendarEntity> list = new ArrayList<>();
|
|
|
- //添加的天数
|
|
|
- int addDay = 0;
|
|
|
+
|
|
|
//获取每日日期数据
|
|
|
while (firstDay.isBefore(lastDay) || firstDay.isEqual(lastDay)) {
|
|
|
CourseCalendarEntity entity = new CourseCalendarEntity();
|
|
|
- List<CourseTimeEntity> times = new ArrayList<>();
|
|
|
//获取当前日期
|
|
|
entity.setDate(firstDay.toString());
|
|
|
//获取当前日期周几
|
|
|
int weekNum = firstDay.getDayOfWeek().getValue();
|
|
|
- List<CourseTimeEntity> timeEntities = teacherPracticeTime.get(weekNum);
|
|
|
- if (CollectionUtils.isNotEmpty(timeEntities)) {
|
|
|
- //将每日上课时间时间添加到日历中
|
|
|
- opsCourseDayTime(addDay, entity, times, timeEntities);
|
|
|
- }
|
|
|
+ JSONArray jsonArray = teacherPracticeTime.get(weekNum);
|
|
|
+ List<CourseTimeEntity> timeEntities = jsonArray.stream()
|
|
|
+ .map(t -> getCourseTimeEntity(entity, (JSONObject) t))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ entity.setCourseTime(timeEntities);
|
|
|
list.add(entity);
|
|
|
firstDay = firstDay.plusDays(1L);
|
|
|
- addDay++;
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+ private CourseTimeEntity getCourseTimeEntity(CourseCalendarEntity entity, JSONObject t) {
|
|
|
+ //拼接时间
|
|
|
+ BiFunction<String, String, Date> canCatTime = (date, time) -> DateUtil.toDateTime(date + " " + time);
|
|
|
+ CourseTimeEntity timeEntity = new CourseTimeEntity();
|
|
|
+ timeEntity.setStartTime(canCatTime.apply(entity.getDate(), t.getString("startTime")));
|
|
|
+ timeEntity.setEndTime(canCatTime.apply(entity.getDate(), t.getString("endTime")));
|
|
|
+ return timeEntity;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 将每日上课时间时间添加到日历中
|
|
|
*
|
|
@@ -491,15 +499,17 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
|
|
|
*
|
|
|
* @return key::数字周几 1~7 value:具体的时间 开始时间-结束时间
|
|
|
*/
|
|
|
- private Map<Integer, List<CourseTimeEntity>> getTeacherPracticeTime(TeacherFreeTime teacherTime) {
|
|
|
- Map<Integer, List<CourseTimeEntity>> teacherPracticeTime = new HashMap<>();
|
|
|
+ private Map<Integer, JSONArray> getTeacherPracticeTime(TeacherFreeTime teacherTime) {
|
|
|
+ Map<Integer, JSONArray> teacherPracticeTime = new HashMap<>();
|
|
|
//将老师设置的陪练课时间放入map中
|
|
|
BiConsumer<String, Integer> timeCon = (timeStr, weekNum) -> {
|
|
|
if (StringUtils.isBlank(timeStr)) {
|
|
|
return;
|
|
|
}
|
|
|
- List<CourseTimeEntity> timeEntityList = new ArrayList<>(JSONObject.parseArray(timeStr, CourseTimeEntity.class));
|
|
|
- teacherPracticeTime.put(weekNum, timeEntityList);
|
|
|
+ JSONArray objects = JSONObject.parseArray(timeStr);
|
|
|
+ if (CollectionUtils.isNotEmpty(objects)) {
|
|
|
+ teacherPracticeTime.put(weekNum, objects);
|
|
|
+ }
|
|
|
};
|
|
|
timeCon.accept(teacherTime.getMonday(), 1);
|
|
|
timeCon.accept(teacherTime.getTuesday(), 2);
|
|
@@ -983,7 +993,7 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
|
|
|
* @Author: cy
|
|
|
* @Date: 2022/4/26
|
|
|
*/
|
|
|
- public List<TeacherSubjectPrice> teacherSubjectPrice(Long teacherId){
|
|
|
+ public List<TeacherSubjectPrice> teacherSubjectPrice(Long teacherId) {
|
|
|
return teacherFreeTimeDao.selectPriceByTeacherId(teacherId);
|
|
|
}
|
|
|
}
|