增加周次

beetlsql3-dev
Mlxa0324 2 years ago
parent 7f24943441
commit a8d58fb9de

@ -1,20 +1,17 @@
package com.ibeetl.admin.core.util;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.ObjectUtil;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
public class DateUtil {
public class DateUtil extends cn.hutool.core.date.DateUtil {
public static Date MAX_DATE = maxDate();
public static String now() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(new Date());
}
public static String now(String format) {
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(new Date());
@ -28,4 +25,118 @@ public class DateUtil {
throw new RuntimeException(e);
}
}
/**
*
*
*
* @param dateTimeList
* @return
*/
public static <T extends Date> Integer dateListWeekSize(List<T> dateTimeList) {
if(ObjectUtil.isEmpty(dateTimeList)) { return 0; }
Set<Integer> weekNumber = new HashSet<>();
for (Date time : dateTimeList) {
// 一年中的第几周,只要有变化,就认为是其他周
weekNumber.add(weekOfYear(time));
}
return weekNumber.size();
}
/**
*
*
* @param dateTimeList
* @return
*/
public static <T extends Date> Map<Integer, List<T>> groupDateListToWeek(List<T> dateTimeList) {
Map<Integer, List<T>> res = new HashMap<>(6);
if(ObjectUtil.isEmpty(dateTimeList)) { return res; }
// 一共有多少周
Integer weekSize = dateListWeekSize(dateTimeList);
// 初始化
for (int i = 1; i <= weekSize; i++) {
res.put(i, new ArrayList<>());
// 迭代器,速度会快一些
Iterator<T> iterator = dateTimeList.iterator();
// 遍历列表
while (iterator.hasNext()) {
T next = iterator.next();
DateTime weekStartDateTime = beginOfWeek(next);
// 遍历的时间,和它自己周的开始时间,是它所在本年度的第几周相等。就认为是同一周
if(weekOfYear(next) == weekOfYear(weekStartDateTime)) {
res.get(i).add(next);
iterator.remove();
}
}
}
return res;
}
/**
*
*
*
* @return
*/
public static <T extends Date> Integer weekNumberInList(List<T> dateTimeList, T date) {
if(ObjectUtil.isEmpty(dateTimeList)) { return 0; }
TreeSet<Integer> weekNumber = new TreeSet<>();
for (Date dateTime : dateTimeList) {
// 一年中的第几周,只要有变化,就认为是其他周
weekNumber.add(weekOfYear(dateTime));
}
// 待查询的时间,在今天所在的周
int dateWeekOfYear = weekOfYear(date);
//计数
int i = 1;
for (Integer wn : weekNumber) {
if(wn.equals(dateWeekOfYear)) {
return i;
}
i++;
}
return 0;
}
/**
*
*
*
* @param date
* @return
* @param <T>
*/
public static <T extends Date> Integer weekNumberInList(T startDate, T date, int weekNumber) {
AtomicInteger index = new AtomicInteger(0);
// int pageTotalNumber = dateTimeList.size() / pageSize;
//
// // 分页
// List<T> list = ListUtil.page(1, pageSize, dateTimeList);
// page -> {
// for (int i = 0; i < page.size(); i++) {
// if(page.get(i).compareTo(date) == 0) {
// index.set(i + 1);
// }
// }
// }); TODO malixiang 这里要写
return index.get();
}
}

@ -323,4 +323,7 @@ create table teacher_open_course_merge_schedule_session
alter table teacher_open_course_merge_schedule_session comment '课程开课-关联-排课配置';
ALTER TABLE teacher_open_course_chat_log ADD COLUMN chat_log_send_type varchar(50) COMMENT '发送类型 枚举(ChatLogSendTypeEnum)';
ALTER TABLE teacher_open_course_chat_log ADD COLUMN chat_log_send_type varchar(50) COMMENT '发送类型 枚举(ChatLogSendTypeEnum)';
ALTER TABLE teacher_open_course_schedule_session_snap ADD COLUMN teacher_open_course_schedule_session_snap_current_week_number int(10) COMMENT '所在时间列表的第几周';

@ -98,8 +98,9 @@ public class TeacherOpenCourseScheduleSession extends BaseEntity{
private Long userId ;
@FetchSql("select * from teacher_open_course_schedule_session_snap where teacher_open_course_schedule_session_snap_status = 1 " +
" and teacher_open_course_id = #teacherOpenCourseId#" )
@FetchSql("select t.* from teacher_open_course_schedule_session_snap t where t.teacher_open_course_schedule_session_snap_status = 1 " +
" and t.teacher_open_course_id = #teacherOpenCourseId# " +
"order by t.teacher_open_course_schedule_session_day_time asc " )
@UpdateIgnore
@InsertIgnore
@DictDeep

@ -45,6 +45,10 @@ public class TeacherOpenCourseScheduleSessionSnap extends BaseEntity{
private Long teacherOpenCourseId ;
// 所在时间列表的第几周
private int teacherOpenCourseScheduleSessionSnapCurrentWeekNumber ;
//状态1正常 2删除
@Dict(type="global_status")

@ -39,10 +39,14 @@ import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.NotNull;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import static cn.hutool.core.collection.CollUtil.join;
import static cn.hutool.core.date.DatePattern.NORM_DATE_PATTERN;
import static cn.hutool.core.date.DateUtil.parseDate;
import static com.ibeetl.admin.core.util.DateUtil.weekNumberInList;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toMap;
@ -76,9 +80,28 @@ public class TeacherOpenCourseScheduleSessionService extends CoreBaseService<Tea
public PageQuery<TeacherOpenCourseScheduleSession> queryByConditionGroup(PageQuery query){
PageQuery ret = teacherOpenCourseScheduleSessionDao.queryByConditionGroup(query);
queryListAfter(ret.getList());
((List<TeacherOpenCourseScheduleSession>)ret.getList()).parallelStream()
.forEach(scheduleSession -> {
// 每周根据周次进行拆分
scheduleSession.set("partitionList", sessionTagListPartition(scheduleSession.getSessionTagList()));
});
return ret;
}
/**
*
*
* @param sessionTagList
* @return
*/
private Map<Integer, List<TeacherOpenCourseScheduleSessionSnap>> sessionTagListPartition(List<TeacherOpenCourseScheduleSessionSnap> sessionTagList) {
Map<Integer, List<TeacherOpenCourseScheduleSessionSnap>> listMap = sessionTagList.stream()
.collect(groupingBy(TeacherOpenCourseScheduleSessionSnap::getTeacherOpenCourseScheduleSessionSnapCurrentWeekNumber));
return listMap;
}
public PageQuery<TeacherOpenCourseScheduleSession>queryByConditionQuery(PageQuery query){
PageQuery ret = teacherOpenCourseScheduleSessionDao.queryByConditionQuery(query);
queryListAfter(ret.getList());
@ -215,7 +238,7 @@ public class TeacherOpenCourseScheduleSessionService extends CoreBaseService<Tea
public InsertByOptionResult insertScheduleSessionByOption(TeacherOpenCourseScheduleSessionOptions options) {
// 偏移周
DateTime startTime = DateUtil.parseDate(options.getStartTime());
DateTime startTime = parseDate(options.getStartTime());
DateTime endTime = DateUtil.offsetWeek(startTime, options.getWeekNum());
List<DateTime> dateTimes = DateUtil.rangeToList(startTime, endTime, DateField.DAY_OF_YEAR);
@ -270,6 +293,9 @@ public class TeacherOpenCourseScheduleSessionService extends CoreBaseService<Tea
List<DateTime> dateTimes = insertByOptionResult.getDateTimes();
Long teacherOpenCourseScheduleSessionId = insertByOptionResult.getTeacherOpenCourseScheduleSessionId();
DateTime startTime = parseDate(options.getStartTime());
DateTime endTime = DateUtil.offsetWeek(startTime, options.getWeekNum());
// 断言,确保开课节次不为空
Assert.notEmpty(options.getSessionClassList(), "开课节次不能为空!");
@ -310,14 +336,17 @@ public class TeacherOpenCourseScheduleSessionService extends CoreBaseService<Tea
// 循环遍历 天
for (DateTime dateTime: dateTimes) {
// 根据跟教室ID分组
Map<Long, TeacherOpenCourseScheduleSessionClass> classIdMap =
Optional.ofNullable(teacherOpenCourseScheduleSessionClassDao.getValuesByQuery(classQuery)).orElseGet(Lists::emptyList)
.stream().collect(toMap(TeacherOpenCourseScheduleSessionClass::getTeacherOpenCourseScheduleSessionClassId, sc -> sc));
// 一个教室ID对应一个或多个开课节次ID
options.getSessionClassList().forEach((sessionClassId ,sessionTagIdsList) -> {
// 为防止lambda里修改集合。
CopyOnWriteArrayList<DateTime> finalDateTimes = new CopyOnWriteArrayList<>(dateTimes);
// 班级和课次列表遍历
options.getSessionClassList().forEach((sessionClassId , sessionTagIdsList) -> {
// 断言,确保开课节次不为空
Assert.notEmpty(sessionTagIdsList, "开课节次列表不能为空!");
// 课次的标签ID
@ -334,6 +363,10 @@ public class TeacherOpenCourseScheduleSessionService extends CoreBaseService<Tea
item.setTeacherOpenCourseScheduleSessionClassName(className);
item.setTeacherOpenCourseScheduleSessionDayTime(dateTime.toString(NORM_DATE_PATTERN));
item.setTeacherOpenCourseId(options.getTeacherOpenCourseId());
// 根据具体周
item.setTeacherOpenCourseScheduleSessionSnapCurrentWeekNumber(weekNumberInList(finalDateTimes, dateTime));
// 根据天数来
// item.setTeacherOpenCourseScheduleSessionSnapCurrentWeekNumber(weekNumberInList(finalDateTimes, dateTime, options.getWeekNum()));
});
teacherOpenCourseScheduleSessionSnapDao.insertBatch(res);

@ -147,7 +147,7 @@ public class TeacherOpenCourseStudentSigninLogController{
if(null == coreUser){
throw new PlatformException("请登录后再操作");
}else{
} else {
Assert.notNull(condition.getTeacherOpenCourseId(), "teacherOpenCourseId 开课ID不能为空");
/** 构建表头 */

@ -37,6 +37,9 @@ public class TeacherOpenCourseScheduleSessionSnapQuery extends PageParam {
private String teacherOpenCourseScheduleSessionClassName;
@Query(name = "创建时间", display = false)
private Date teacherOpenCourseScheduleSessionSnapAddTime;
@Query(name = "所在时间列表的第几周", display = false)
private Integer teacherOpenCourseScheduleSessionSnapCurrentWeekNumber ;
@Query(name = "组织ID", display = false)
private Long orgId;
@Query(name = "用户ID", display = false)
@ -138,6 +141,7 @@ public class TeacherOpenCourseScheduleSessionSnapQuery extends PageParam {
pojo.setTeacherOpenCourseScheduleSessionTagEndTime(this.getTeacherOpenCourseScheduleSessionTagEndTime());
pojo.setTeacherOpenCourseScheduleSessionClassName(this.getTeacherOpenCourseScheduleSessionClassName());
pojo.setTeacherOpenCourseScheduleSessionSnapAddTime(this.getTeacherOpenCourseScheduleSessionSnapAddTime());
pojo.setTeacherOpenCourseScheduleSessionSnapCurrentWeekNumber(this.getTeacherOpenCourseScheduleSessionSnapCurrentWeekNumber());
pojo.setOrgId(this.getOrgId());
pojo.setUserId(this.getUserId());
return pojo;
@ -202,4 +206,12 @@ public class TeacherOpenCourseScheduleSessionSnapQuery extends PageParam {
public void setTeacherOpenCourseId(Long teacherOpenCourseId) {
this.teacherOpenCourseId = teacherOpenCourseId;
}
public Integer getTeacherOpenCourseScheduleSessionSnapCurrentWeekNumber() {
return teacherOpenCourseScheduleSessionSnapCurrentWeekNumber;
}
public void setTeacherOpenCourseScheduleSessionSnapCurrentWeekNumber(Integer teacherOpenCourseScheduleSessionSnapCurrentWeekNumber) {
this.teacherOpenCourseScheduleSessionSnapCurrentWeekNumber = teacherOpenCourseScheduleSessionSnapCurrentWeekNumber;
}
}

@ -57,6 +57,9 @@ queryByCondition
@if(!isEmpty(teacherOpenCourseScheduleSessionSnapAddTime)){
and t.teacher_open_course_schedule_session_snap_add_time =#teacherOpenCourseScheduleSessionSnapAddTime#
@}
@if(!isEmpty(teacherOpenCourseScheduleSessionSnapCurrentWeekNumber)){
and t.teacher_open_course_schedule_session_snap_current_week_number =#teacherOpenCourseScheduleSessionSnapCurrentWeekNumber#
@}
@if(!isEmpty(orgId)){
and t.org_id =#orgId#
@}
@ -130,6 +133,9 @@ queryByConditionQuery
@if(!isEmpty(teacherOpenCourseScheduleSessionSnapAddTime)){
and t.teacher_open_course_schedule_session_snap_add_time =#teacherOpenCourseScheduleSessionSnapAddTime#
@}
@if(!isEmpty(teacherOpenCourseScheduleSessionSnapCurrentWeekNumber)){
and t.teacher_open_course_schedule_session_snap_current_week_number =#teacherOpenCourseScheduleSessionSnapCurrentWeekNumber#
@}
@if(!isEmpty(orgId)){
and t.org_id =#orgId#
@}
@ -236,6 +242,13 @@ updateGivenByIds
teacher_open_course_schedule_session_snap_add_time = #teacherOpenCourseScheduleSessionSnapAddTime# ,
@}
@}
@if(contain("teacherOpenCourseScheduleSessionSnapCurrentWeekNumber",_given)){
@if(isEmpty(teacherOpenCourseScheduleSessionSnapCurrentWeekNumber)){
teacher_open_course_schedule_session_snap_current_week_number = null ,
@}else{
teacher_open_course_schedule_session_snap_current_week_number = #teacherOpenCourseScheduleSessionSnapCurrentWeekNumber# ,
@}
@}
@if(contain("orgId",_given)){
@if(isEmpty(orgId)){
org_id = null ,
@ -296,6 +309,9 @@ getTeacherOpenCourseScheduleSessionSnapValues
@if(!isEmpty(teacherOpenCourseScheduleSessionSnapAddTime)){
and t.teacher_open_course_schedule_session_snap_add_time =#teacherOpenCourseScheduleSessionSnapAddTime#
@}
@if(!isEmpty(teacherOpenCourseScheduleSessionSnapCurrentWeekNumber)){
and t.teacher_open_course_schedule_session_snap_current_week_number =#teacherOpenCourseScheduleSessionSnapCurrentWeekNumber#
@}
@if(!isEmpty(orgId)){
and t.org_id =#orgId#
@}
@ -359,6 +375,9 @@ getValuesByQuery
@if(!isEmpty(teacherOpenCourseScheduleSessionSnapAddTime)){
and t.teacher_open_course_schedule_session_snap_add_time =#teacherOpenCourseScheduleSessionSnapAddTime#
@}
@if(!isEmpty(teacherOpenCourseScheduleSessionSnapCurrentWeekNumber)){
and t.teacher_open_course_schedule_session_snap_current_week_number =#teacherOpenCourseScheduleSessionSnapCurrentWeekNumber#
@}
@if(!isEmpty(orgId)){
and t.org_id =#orgId#
@}

Loading…
Cancel
Save