diff --git a/admin-core/src/main/java/com/ibeetl/admin/core/service/CorePlatformService.java b/admin-core/src/main/java/com/ibeetl/admin/core/service/CorePlatformService.java index 767e811d..f8f474aa 100644 --- a/admin-core/src/main/java/com/ibeetl/admin/core/service/CorePlatformService.java +++ b/admin-core/src/main/java/com/ibeetl/admin/core/service/CorePlatformService.java @@ -63,6 +63,9 @@ public class CorePlatformService { public static final String USER_DATA_ACCESS_CACHE = "cache:core:userDataAccess"; public static final String USER_MENU_CACHE = "cache:core:userMenu"; + // 通过开课ID获取的课程节点信息缓存KEY + public static final String CACHE_CORE_GET_COURSE_TARGET_INFO_BY_TEACHER_OPEN_COURSE_ID = "cache:core:getCourseTargetInfoByTeacherOpenCourseId"; + /*当前用户会话*/ public static final String ACCESS_CURRENT_USER = "core:user"; /*当前登录用户所在部门*/ diff --git a/admin-core/src/main/java/com/ibeetl/admin/core/util/StreamUtils.java b/admin-core/src/main/java/com/ibeetl/admin/core/util/StreamUtils.java index d8b75228..1f4837ba 100644 --- a/admin-core/src/main/java/com/ibeetl/admin/core/util/StreamUtils.java +++ b/admin-core/src/main/java/com/ibeetl/admin/core/util/StreamUtils.java @@ -4,7 +4,9 @@ import cn.hutool.core.collection.CollectionUtil; import java.util.Collection; import java.util.Objects; +import java.util.Set; import java.util.function.Function; +import java.util.stream.Collector; import java.util.stream.Collectors; /** @@ -41,4 +43,29 @@ public class StreamUtils { public static String listJoin(Collection list, Function function) { return CollectionUtil.newArrayList(list).stream().map(function).map(Objects::toString).collect(Collectors.joining(",")); } + + /** + * List指定字段,并返回join后的值 + * @param list + * @param function + * @return + * @param + * @param + */ + public static Set getFieldToSet(Collection list, Function function) { + return CollectionUtil.newArrayList(list).stream().map(function).collect(Collectors.toSet()); + } + + /** + * List指定字段,并返回join后的值 + * @param list + * @param function + * @return + * @param + * @param + * @param + */ + public static R getFieldTo(Collection list, Function function, Collector collector) { + return CollectionUtil.newArrayList(list).stream().map(function).collect(collector); + } } diff --git a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseMergeCourseInfoService.java b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseMergeCourseInfoService.java index c7d9c930..a3810985 100644 --- a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseMergeCourseInfoService.java +++ b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseMergeCourseInfoService.java @@ -37,7 +37,9 @@ import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.beetl.sql.core.SqlId; import org.beetl.sql.core.engine.PageQuery; +import org.beetl.sql.core.query.LambdaQuery; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -57,6 +59,7 @@ import java.util.stream.Collectors; import static cn.hutool.core.util.ArrayUtil.join; import static cn.hutool.core.util.ObjectUtil.defaultIfNull; +import static com.ibeetl.admin.core.service.CorePlatformService.CACHE_CORE_GET_COURSE_TARGET_INFO_BY_TEACHER_OPEN_COURSE_ID; import static com.ibeetl.admin.core.util.ExcelUtil.getCellFormatValue; import static com.ibeetl.jlw.enums.CopyFromEnum.FROM_OPEN_COURSE; import static com.ibeetl.jlw.enums.GlobalUpStatusEnum.UP; @@ -168,14 +171,14 @@ public class TeacherOpenCourseMergeCourseInfoService extends CoreBaseService courseResources = getCourseResources(Long.valueOf(id)); + List courseInfoList = getCourseResources(Long.valueOf(id)); // TODO 这里要优化 // List courseResources2 = getCourseResourcesByList(Long.valueOf(id)); // // int a = 1/0; // 只匹配章节 - Set idSet = courseResources.stream().filter(item -> Integer.valueOf(2).equals(item.getCourseInfoType())) + Set idSet = courseInfoList.stream().filter(item -> Integer.valueOf(2).equals(item.getCourseInfoType())) .map(TeacherOpenCourseMergeCourseInfo::getTeacherOpenCourseMergeCourseInfoId).collect(toSet()); if(ObjectUtil.isNotEmpty(idSet)) { @@ -219,12 +222,12 @@ public class TeacherOpenCourseMergeCourseInfoService extends CoreBaseService questionSettingOptions, Map courseInfoIdPair) { + + getParentCourseIdIfTypeEquals2(mergeCourseInfoQuery); // 添加开课课程表 - JsonResult jsonResult = add(teacherOpenCourseMergeCourseInfoQuery); + JsonResult jsonResult = add(mergeCourseInfoQuery); // 开课课程:2 章节节点 - if(Integer.valueOf(2).equals(teacherOpenCourseMergeCourseInfoQuery.getCourseInfoType())) { + if(Integer.valueOf(2).equals(mergeCourseInfoQuery.getCourseInfoType())) { // 添加到题目配置和开课题目快照表,这里null 不拷贝题目 - teacherOpenCourseQuestionSettingService.addFrom(teacherOpenCourseMergeCourseInfoQuery, questionSettingOptions, FROM_OPEN_COURSE, courseInfoIdPair); + teacherOpenCourseQuestionSettingService.addFrom(mergeCourseInfoQuery, questionSettingOptions, FROM_OPEN_COURSE, courseInfoIdPair); } return jsonResult; } + /** + * 添加的对象如果是章节节点的话,那么查询他的上一级 + * @param mergeCourseInfoQuery + */ + public void getParentCourseIdIfTypeEquals2(TeacherOpenCourseMergeCourseInfoQuery mergeCourseInfoQuery) { + + if (mergeCourseInfoQuery != null) { + final Integer courseInfoType = mergeCourseInfoQuery.getCourseInfoType(); + final Long teacherOpenCourseId = mergeCourseInfoQuery.getTeacherOpenCourseId(); + + // 开课ID不为空,且课程类型 = 章节类型的,则查询归属的课程ID + if (ObjectUtil.isAllNotEmpty(courseInfoType, teacherOpenCourseId) && courseInfoType.equals(2)) { + + TeacherOpenCourseMergeCourseInfo courseTargetInfo = getCourseTargetInfoByTeacherOpenCourseId(teacherOpenCourseId); + + if (courseTargetInfo != null) { + mergeCourseInfoQuery.setCourseInfoParentId(courseTargetInfo.getTeacherOpenCourseMergeCourseInfoId()); + } + } + } + } + + /** + * 通过开课ID获取课程节点的信息 + * + * @param teacherOpenCourseId + * @return + */ + @Cacheable(value = CACHE_CORE_GET_COURSE_TARGET_INFO_BY_TEACHER_OPEN_COURSE_ID, key = "#root.args[0]", unless = "#result == null") + public TeacherOpenCourseMergeCourseInfo getCourseTargetInfoByTeacherOpenCourseId(Long teacherOpenCourseId) { + + if (teacherOpenCourseId == null) { + return null; + } + + LambdaQuery lambdaQuery = teacherOpenCourseMergeCourseInfoDao.createLambdaQuery(); + LambdaQuery.Property pIdpt = TeacherOpenCourseMergeCourseInfo::getCourseInfoParentId; + + // 课程节点的信息 + TeacherOpenCourseMergeCourseInfo courseTargetInfo = lambdaQuery + .andEq(TeacherOpenCourseMergeCourseInfo::getTeacherOpenCourseId, teacherOpenCourseId) + .andEq(TeacherOpenCourseMergeCourseInfo::getCourseInfoStatus, 1) + .andEq(TeacherOpenCourseMergeCourseInfo::getCourseInfoType, 1) + .and(lambdaQuery.condition().andEq(pIdpt, "").orIsNull(pIdpt)) + .single(); + return courseTargetInfo; + } + public String edit(TeacherOpenCourseMergeCourseInfoQuery teacherOpenCourseMergeCourseInfoQuery){ String msg = ""; diff --git a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseQuestionSettingService.java b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseQuestionSettingService.java index 6449ea75..ccee585d 100644 --- a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseQuestionSettingService.java +++ b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseQuestionSettingService.java @@ -354,11 +354,14 @@ public class TeacherOpenCourseQuestionSettingService extends CoreBaseService(questionSettingOptions)); + List optionList = null == questionSettingOptions ? Collections.emptyList() : new ArrayList<>(questionSettingOptions); + settingQuery.setQuestionSettingOptions(optionList); + // 拷贝题库 switch (copyFrom) { case FROM_OPEN_COURSE: addSettingByOpenCourse(settingQuery, courseInfoIdPair); + break; case FROM_SYSTEM: addSettingBySystemCourse(settingQuery, courseInfoIdPair); break;