|
|
|
@ -3,6 +3,7 @@ package com.ibeetl.jlw.service;
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.bean.copier.CopyOptions;
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
|
import cn.hutool.core.lang.Snowflake;
|
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
|
import cn.hutool.core.util.EnumUtil;
|
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
|
@ -81,6 +82,8 @@ public class TeacherOpenCourseMergeResourcesQuestionService extends CoreBaseServ
|
|
|
|
|
@Autowired
|
|
|
|
|
private ResourcesQuestionSnapshotService resourcesQuestionSnapshotService;
|
|
|
|
|
|
|
|
|
|
private static final Snowflake snowflake = new Snowflake();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PageQuery<TeacherOpenCourseMergeResourcesQuestion> queryByCondition(PageQuery query) {
|
|
|
|
|
PageQuery ret = teacherOpenCourseMergeResourcesQuestionDao.queryByCondition(query);
|
|
|
|
@ -465,8 +468,8 @@ public class TeacherOpenCourseMergeResourcesQuestionService extends CoreBaseServ
|
|
|
|
|
* @param allCourseInfo 指定的所有课程章节信息
|
|
|
|
|
* @param courseInfoIdPair 拷贝过来的ID段,旧ID和新ID的一个映射关系(非必填)
|
|
|
|
|
*/
|
|
|
|
|
public void copySystemQuestionToOpenCourse(@NotNull(message = "开课ID不能为空!") Long teacherOpenCourseId,
|
|
|
|
|
Collection<CourseInfo> allCourseInfo, @NotNull Map<Long, Long> courseInfoIdPair) {
|
|
|
|
|
public Map<Long, Long> copySystemQuestionToOpenCourse(@NotNull(message = "开课ID不能为空!") Long teacherOpenCourseId,
|
|
|
|
|
Collection<CourseInfo> allCourseInfo, @NotNull Map<Long, Long> courseInfoIdPair) {
|
|
|
|
|
|
|
|
|
|
// 待拷贝的系统课程ID不能为空.才会执行
|
|
|
|
|
if (ObjectUtil.isNotEmpty(allCourseInfo)) {
|
|
|
|
@ -480,33 +483,12 @@ public class TeacherOpenCourseMergeResourcesQuestionService extends CoreBaseServ
|
|
|
|
|
// 系统题目库ID集合
|
|
|
|
|
Set<Long> resourcesQuestionIds = resourcesQuestionList.stream().map(ResourcesQuestion::getResourcesQuestionId).collect(toSet());
|
|
|
|
|
// 拷贝系统题目库到教师开课
|
|
|
|
|
copyFromSystemQuestion(resourcesQuestionIds, teacherOpenCourseId, courseInfoIdPair);
|
|
|
|
|
return copyFromSystemQuestion(resourcesQuestionIds, teacherOpenCourseId, courseInfoIdPair);
|
|
|
|
|
}
|
|
|
|
|
return new HashMap<>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据指定的课程ID和章节ID集合,去从系统题目拷贝到开课题目库
|
|
|
|
|
*
|
|
|
|
|
* @param teacherOpenCourseId 开课ID
|
|
|
|
|
* @param allCourseInfoIdsJoin 指定的所有课程章节ID
|
|
|
|
|
* @param courseInfoIdPair 拷贝过来的ID段,旧ID和新ID的一个映射关系(非必填)
|
|
|
|
|
*/
|
|
|
|
|
public void copySystemQuestionToOpenCourse(@NotNull(message = "开课ID不能为空!") Long teacherOpenCourseId,
|
|
|
|
|
String allCourseInfoIdsJoin, @NotNull Map<Long, Long> courseInfoIdPair) {
|
|
|
|
|
|
|
|
|
|
// 待拷贝的系统课程ID不能为空.才会执行
|
|
|
|
|
if (ObjectUtil.isNotEmpty(allCourseInfoIdsJoin)) {
|
|
|
|
|
ResourcesQuestionQuery resourcesQuestionQuery = new ResourcesQuestionQuery();
|
|
|
|
|
resourcesQuestionQuery.setCourseInfoIds(allCourseInfoIdsJoin);
|
|
|
|
|
resourcesQuestionQuery.setQuestionStatus(1);
|
|
|
|
|
List<ResourcesQuestion> resourcesQuestionList = resourcesQuestionService.getValuesByQuery(resourcesQuestionQuery);
|
|
|
|
|
|
|
|
|
|
// 系统题目库ID集合
|
|
|
|
|
Set<Long> resourcesQuestionIds = resourcesQuestionList.stream().map(ResourcesQuestion::getResourcesQuestionId).collect(toSet());
|
|
|
|
|
// 拷贝系统题目库到教师开课
|
|
|
|
|
copyFromSystemQuestion(resourcesQuestionIds, teacherOpenCourseId, courseInfoIdPair);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 从resources_question 表,拷贝数据。类似从模板中,拉取数据
|
|
|
|
@ -519,11 +501,11 @@ public class TeacherOpenCourseMergeResourcesQuestionService extends CoreBaseServ
|
|
|
|
|
* @param courseInfoIdPair
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public void copyFromSystemQuestion(Set<Long> systemResourcesQuestionIds,
|
|
|
|
|
@NotNull(message = "开课ID不能为空!") Long teacherOpenCourseId, Map<Long, Long> courseInfoIdPair) {
|
|
|
|
|
public Map<Long, Long> copyFromSystemQuestion(Set<Long> systemResourcesQuestionIds,
|
|
|
|
|
@NotNull(message = "开课ID不能为空!") Long teacherOpenCourseId, Map<Long, Long> courseInfoIdPair) {
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(systemResourcesQuestionIds)) {
|
|
|
|
|
return;
|
|
|
|
|
return courseInfoIdPair;
|
|
|
|
|
}
|
|
|
|
|
// 题目ID集合
|
|
|
|
|
String ids = join(systemResourcesQuestionIds.toArray(), ",");
|
|
|
|
@ -536,11 +518,13 @@ public class TeacherOpenCourseMergeResourcesQuestionService extends CoreBaseServ
|
|
|
|
|
// 转换后的数据暂存
|
|
|
|
|
List<TeacherOpenCourseMergeResourcesQuestion> convertedList = new ArrayList<>();
|
|
|
|
|
// 类转换方法
|
|
|
|
|
resourcesQuestionConvertToTeacherOpenCourseMergeResourcesQuestion(resourcesQuestions, convertedList, courseInfoIdPair);
|
|
|
|
|
Map<Long, Long> resourcesQuestionIdPair = resourcesQuestionConvertToTeacherOpenCourseMergeResourcesQuestion(resourcesQuestions, convertedList, courseInfoIdPair);
|
|
|
|
|
// 设置开课ID
|
|
|
|
|
convertedList.forEach(item -> item.setTeacherOpenCourseId(teacherOpenCourseId));
|
|
|
|
|
// 批量插入
|
|
|
|
|
teacherOpenCourseMergeResourcesQuestionDao.insertBatch(convertedList);
|
|
|
|
|
|
|
|
|
|
return resourcesQuestionIdPair;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -550,21 +534,37 @@ public class TeacherOpenCourseMergeResourcesQuestionService extends CoreBaseServ
|
|
|
|
|
* @param to
|
|
|
|
|
* @param courseInfoIdPair
|
|
|
|
|
*/
|
|
|
|
|
public void resourcesQuestionConvertToTeacherOpenCourseMergeResourcesQuestion(
|
|
|
|
|
public Map<Long, Long> resourcesQuestionConvertToTeacherOpenCourseMergeResourcesQuestion(
|
|
|
|
|
@NotNull Collection<ResourcesQuestion> from,
|
|
|
|
|
@NotNull Collection<TeacherOpenCourseMergeResourcesQuestion> to,
|
|
|
|
|
Map<Long, Long> courseInfoIdPair) {
|
|
|
|
|
|
|
|
|
|
Map<Long, Long> resourcesQuestionIdPair = new HashMap<>();
|
|
|
|
|
// 拷贝部分字段映射
|
|
|
|
|
CopyOptions copyOptions = CopyOptions.create().setFieldMapping(MapUtil.of("courseInfoId", "teacherOpenCourseMergeCourseInfoId"));
|
|
|
|
|
Map<String, String> of = MapUtil.of("courseInfoId", "teacherOpenCourseMergeCourseInfoId");
|
|
|
|
|
of.put("resourcesQuestionId", "teacherOpenCourseMergeResourcesQuestionId");
|
|
|
|
|
CopyOptions copyOptions = CopyOptions.create().setFieldMapping(of);
|
|
|
|
|
// 拷贝
|
|
|
|
|
to.addAll(BeanUtil.copyToList(from, TeacherOpenCourseMergeResourcesQuestion.class, copyOptions));
|
|
|
|
|
|
|
|
|
|
// 主动更改Id,并记录映射关系
|
|
|
|
|
for (TeacherOpenCourseMergeResourcesQuestion teacherOpenCourseMergeResourcesQuestion : to) {
|
|
|
|
|
long newId = snowflake.nextId();
|
|
|
|
|
|
|
|
|
|
// 记录映射关系
|
|
|
|
|
resourcesQuestionIdPair.put(teacherOpenCourseMergeResourcesQuestion.getTeacherOpenCourseMergeResourcesQuestionId(),
|
|
|
|
|
newId);
|
|
|
|
|
teacherOpenCourseMergeResourcesQuestion.setTeacherOpenCourseMergeCourseInfoId(newId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isAllEmpty(to, courseInfoIdPair)) {
|
|
|
|
|
return;
|
|
|
|
|
return new HashMap<>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 重置开课课程ID
|
|
|
|
|
resetNewId(to, courseInfoIdPair);
|
|
|
|
|
|
|
|
|
|
return resourcesQuestionIdPair;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|