|
|
|
@ -49,7 +49,6 @@ import java.time.Duration;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static cn.hutool.core.util.ArrayUtil.join;
|
|
|
|
|
import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
|
|
|
|
@ -506,32 +505,28 @@ public class TeacherOpenCourseMergeCourseInfoService extends CoreBaseService<Tea
|
|
|
|
|
/**
|
|
|
|
|
* 处理一维集合,更换ID和父辈ID的方法
|
|
|
|
|
*
|
|
|
|
|
* @param copyToList
|
|
|
|
|
* @param copyToList 开课课程列表
|
|
|
|
|
* @param initIdPair 初始化的ID对
|
|
|
|
|
*/
|
|
|
|
|
public Map<Long, Long> batchUpdateArrayListSomeMergeId(CopyOnWriteArrayList<TeacherOpenCourseMergeCourseInfo> copyToList) {
|
|
|
|
|
public Map<Long, Long> batchUpdateArrayListSomeMergeId(List<TeacherOpenCourseMergeCourseInfo> copyToList,
|
|
|
|
|
// 不能为空,但是可以传递empty的Map
|
|
|
|
|
@NotNull(message = "初始化ID对不能为空!") Map<Long, Long> initIdPair) {
|
|
|
|
|
|
|
|
|
|
ConcurrentHashMap<Long, Long> idPair = new ConcurrentHashMap<>();
|
|
|
|
|
Map<Long, Long> idPair = new HashMap<>(initIdPair);
|
|
|
|
|
|
|
|
|
|
// 遍历所有节点
|
|
|
|
|
copyToList.stream().parallel().forEach(item -> {
|
|
|
|
|
// 先判断必要的条件不能为空!才能继续进行下面的重置ID操作
|
|
|
|
|
Assert.notNull(item.getTeacherOpenCourseMergeCourseInfoId(), "开课课程ID不能为空!");
|
|
|
|
|
// 查找列表中所有的ID
|
|
|
|
|
Set<Long> mergeCourseInfoIdSet = copyToList.stream()
|
|
|
|
|
.map(TeacherOpenCourseMergeCourseInfo::getTeacherOpenCourseMergeCourseInfoId).collect(toSet());
|
|
|
|
|
|
|
|
|
|
// 查找是否有子节点
|
|
|
|
|
CopyOnWriteArrayList<TeacherOpenCourseMergeCourseInfo> filterMatchList = copyToList.stream()
|
|
|
|
|
.filter(ref -> item.getTeacherOpenCourseMergeCourseInfoId().equals(ref.getCourseInfoParentId()))
|
|
|
|
|
.collect(Collectors.toCollection(CopyOnWriteArrayList::new));
|
|
|
|
|
for (Long oldId : mergeCourseInfoIdSet) {
|
|
|
|
|
// 只取第一次ID对,后面加进来的丢弃
|
|
|
|
|
if (!idPair.containsKey(oldId)) {
|
|
|
|
|
idPair.put(oldId, snowflake.nextId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Long newId = snowflake.nextId();
|
|
|
|
|
// 存储ID对
|
|
|
|
|
idPair.put(item.getTeacherOpenCourseMergeCourseInfoId(), newId);
|
|
|
|
|
// 重置父节点的ID
|
|
|
|
|
item.setTeacherOpenCourseMergeCourseInfoId(newId);
|
|
|
|
|
// 重置子节点的父辈ID
|
|
|
|
|
filterMatchList.forEach(e -> {
|
|
|
|
|
e.setCourseInfoParentId(newId);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
// 替换ID和父类ID
|
|
|
|
|
updateSpecifyMergeCourseInfoIdTargetList(copyToList, idPair);
|
|
|
|
|
|
|
|
|
|
return idPair;
|
|
|
|
|
}
|
|
|
|
@ -590,6 +585,64 @@ public class TeacherOpenCourseMergeCourseInfoService extends CoreBaseService<Tea
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据开课ID构建顶部系统课程信息
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public CourseInfo buildTopCourseInfo(@NotNull(message = "开课ID不能为空!") Long teacherOpenCourseId) {
|
|
|
|
|
TeacherOpenCourseMergeCourseInfoQuery teacherOpenCourseMergeCourseInfoQuery = new TeacherOpenCourseMergeCourseInfoQuery();
|
|
|
|
|
teacherOpenCourseMergeCourseInfoQuery.setTeacherOpenCourseId(teacherOpenCourseId);
|
|
|
|
|
teacherOpenCourseMergeCourseInfoQuery.setCourseInfoStatus(1);
|
|
|
|
|
teacherOpenCourseMergeCourseInfoQuery.setCourseInfoType(1);
|
|
|
|
|
TeacherOpenCourseMergeCourseInfo info = getInfo(teacherOpenCourseMergeCourseInfoQuery);
|
|
|
|
|
|
|
|
|
|
CopyOptions copyOptions = CopyOptions.create().setFieldMapping(MapUtil.of("teacherOpenCourseMergeCourseInfoId", "courseInfoId"));
|
|
|
|
|
CourseInfo target = new CourseInfo();
|
|
|
|
|
BeanUtil.copyProperties(info, target, copyOptions);
|
|
|
|
|
return target;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改章节点的父类ID字段
|
|
|
|
|
*
|
|
|
|
|
* @param courseInfoList 系统课程列表
|
|
|
|
|
* @param someIdPair 一些修改前修改后的ID对(指定一些修改的ID对)
|
|
|
|
|
*/
|
|
|
|
|
public void updateSpecifyIdTargetList(List<CourseInfo> courseInfoList,
|
|
|
|
|
@NotEmpty(message = "ID对不能为空!") Map<Long, Long> someIdPair) {
|
|
|
|
|
for (CourseInfo courseInfo : courseInfoList) {
|
|
|
|
|
someIdPair.forEach((oldId, newId) -> {
|
|
|
|
|
if(courseInfo.getCourseInfoId().equals(oldId)) {
|
|
|
|
|
courseInfo.setCourseInfoId(newId);
|
|
|
|
|
}
|
|
|
|
|
if(courseInfo.getCourseInfoParentId().equals(oldId)) {
|
|
|
|
|
courseInfo.setCourseInfoParentId(newId);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改章节点的父类ID字段
|
|
|
|
|
*
|
|
|
|
|
* @param courseInfoList 系统课程列表
|
|
|
|
|
* @param someIdPair 一些修改前修改后的ID对(指定一些修改的ID对)
|
|
|
|
|
*/
|
|
|
|
|
public void updateSpecifyMergeCourseInfoIdTargetList(List<TeacherOpenCourseMergeCourseInfo> courseInfoList,
|
|
|
|
|
@NotEmpty(message = "ID对不能为空!") Map<Long, Long> someIdPair) {
|
|
|
|
|
for (TeacherOpenCourseMergeCourseInfo courseInfo : courseInfoList) {
|
|
|
|
|
someIdPair.forEach((oldId, newId) -> {
|
|
|
|
|
if(courseInfo.getTeacherOpenCourseMergeCourseInfoId().equals(oldId)) {
|
|
|
|
|
courseInfo.setTeacherOpenCourseMergeCourseInfoId(newId);
|
|
|
|
|
}
|
|
|
|
|
if(courseInfo.getCourseInfoParentId().equals(oldId)) {
|
|
|
|
|
courseInfo.setCourseInfoParentId(newId);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 教师端-导入课程章节操作,逻辑拆分
|
|
|
|
|
*
|
|
|
|
@ -605,7 +658,11 @@ public class TeacherOpenCourseMergeCourseInfoService extends CoreBaseService<Tea
|
|
|
|
|
// 查询是否绑定过课程
|
|
|
|
|
boolean notExists = teacherOpenCourseMergeCourseInfoDao.isNotExistsByTeacherOpenCourseId(teacherOpenCourseId);
|
|
|
|
|
|
|
|
|
|
Assert.isTrue(notExists, "已绑定过课程,请先重置!");
|
|
|
|
|
// 开课课程节点的对象
|
|
|
|
|
TeacherOpenCourseMergeCourseInfo openCourseTargetInfo = teacherOpenCourseMergeCourseInfoDao.getValueByTeacherOpenCourseId(teacherOpenCourseId);
|
|
|
|
|
|
|
|
|
|
Assert.isTrue(notExists, "已绑定过章节,请先重置!");
|
|
|
|
|
Assert.notNull(openCourseTargetInfo, "未查询到开课的课程!");
|
|
|
|
|
|
|
|
|
|
// 开启并行处理
|
|
|
|
|
courseInfoIds.stream().parallel().forEach(courseInfoId -> {
|
|
|
|
@ -614,8 +671,8 @@ public class TeacherOpenCourseMergeCourseInfoService extends CoreBaseService<Tea
|
|
|
|
|
// 查询当前课程信息下的,章节或者小节信息,返回一维集合
|
|
|
|
|
List<CourseInfo> chapterList = courseInfoService.getCourseResources(courseInfoId);
|
|
|
|
|
|
|
|
|
|
// 将课程本身添加进集合
|
|
|
|
|
chapterList.add(currentCourseInfo);
|
|
|
|
|
// 全部归类到教师开课时候,创建的开课课程ID下。支持一对多个系统课程的拷贝
|
|
|
|
|
idPair.put(currentCourseInfo.getCourseInfoId(), openCourseTargetInfo.getTeacherOpenCourseMergeCourseInfoId());
|
|
|
|
|
// 先根据ID清楚现有的课程章节小节这个表
|
|
|
|
|
String delCourseInfoIds = chapterList.stream().map(CourseInfo::getCourseInfoId).collect(CollectorUtil.joining(","));
|
|
|
|
|
deleteTeacherOpenCourseMergeCourseInfo(delCourseInfoIds);
|
|
|
|
@ -631,8 +688,8 @@ public class TeacherOpenCourseMergeCourseInfoService extends CoreBaseService<Tea
|
|
|
|
|
item.setCourseInfoName(item.getCourseInfoName().replaceAll(" ", ""));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
copyToList = new CopyOnWriteArrayList<>(copyToList);
|
|
|
|
|
idPair.putAll(batchUpdateArrayListSomeMergeId((CopyOnWriteArrayList)copyToList));
|
|
|
|
|
// 最右侧的idPair 可以理解成是初始化的Map。Map特性Key是唯一的。
|
|
|
|
|
idPair.putAll(batchUpdateArrayListSomeMergeId(copyToList, idPair));
|
|
|
|
|
|
|
|
|
|
// 批量插入
|
|
|
|
|
teacherOpenCourseMergeCourseInfoDao.insertBatch(copyToList);
|
|
|
|
@ -659,7 +716,7 @@ public class TeacherOpenCourseMergeCourseInfoService extends CoreBaseService<Tea
|
|
|
|
|
// 开启并行处理
|
|
|
|
|
courseInfoIds.stream().parallel().forEach(courseInfoId -> {
|
|
|
|
|
// 获取这个课程章节下的所有的子章节信息
|
|
|
|
|
List<CourseInfo> chapterList = courseInfoService.getChapterList(courseInfoId);
|
|
|
|
|
List<CourseInfo> chapterList = courseInfoService.getCourseResources(courseInfoId);
|
|
|
|
|
HashSet<CourseInfo> courseInfos = CollectionUtil.newHashSet(chapterList);
|
|
|
|
|
|
|
|
|
|
// 如果课程章节没查到记录,则下面的资源也没必要执行,资源依赖课程章节
|
|
|
|
@ -758,14 +815,14 @@ public class TeacherOpenCourseMergeCourseInfoService extends CoreBaseService<Tea
|
|
|
|
|
*/
|
|
|
|
|
public TeacherOpenCourseMergeCourseInfo getTreeByTeacherOpenCourseId(
|
|
|
|
|
@NotNull(message = "开课ID不能为空!") final Long teacherOpenCourseId) {
|
|
|
|
|
TeacherOpenCourseMergeCourseInfo treeLocalCacheByTeacherOpenCourseId =
|
|
|
|
|
TeacherOpenCourseMergeCourseInfo treeCacheByTeacherOpenCourseId =
|
|
|
|
|
teacherOpenCourseMergeCourseInfoDao.getValueByTeacherOpenCourseId(teacherOpenCourseId);
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(treeLocalCacheByTeacherOpenCourseId)) {
|
|
|
|
|
if (ObjectUtil.isEmpty(treeCacheByTeacherOpenCourseId)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return getTreeById(treeLocalCacheByTeacherOpenCourseId.getTeacherOpenCourseMergeCourseInfoId());
|
|
|
|
|
return getTreeById(treeCacheByTeacherOpenCourseId.getTeacherOpenCourseMergeCourseInfoId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|