@ -1,8 +1,7 @@
package com.ibeetl.jlw.service ;
package com.ibeetl.jlw.service ;
import cn.hutool.core.bean.BeanUtil ;
import cn.hutool.core.lang.func.Func1 ;
import cn.hutool.core.lang.func.Func1 ;
import cn.hutool.core.util.EnumUtil ;
import cn.hutool.core.util.NumberUtil ;
import cn.hutool.core.util.ObjectUtil ;
import cn.hutool.core.util.ObjectUtil ;
import cn.jlw.util.ToolUtils ;
import cn.jlw.util.ToolUtils ;
import cn.jlw.validate.ValidateConfig ;
import cn.jlw.validate.ValidateConfig ;
@ -13,18 +12,15 @@ import com.ibeetl.admin.core.util.PlatformException;
import com.ibeetl.admin.core.web.JsonResult ;
import com.ibeetl.admin.core.web.JsonResult ;
import com.ibeetl.admin.core.web.JsonReturnCode ;
import com.ibeetl.admin.core.web.JsonReturnCode ;
import com.ibeetl.jlw.dao.TeacherOpenCourseQuestionSettingDao ;
import com.ibeetl.jlw.dao.TeacherOpenCourseQuestionSettingDao ;
import com.ibeetl.jlw.entity.CourseInfo ;
import com.ibeetl.jlw.entity.* ;
import com.ibeetl.jlw.entity.ResourcesQuestion ;
import com.ibeetl.jlw.entity.TeacherOpenCourseMergeCourseInfo ;
import com.ibeetl.jlw.entity.TeacherOpenCourseQuestionSetting ;
import com.ibeetl.jlw.entity.dto.TeacherOpenCourseQuestionSettingDTO ;
import com.ibeetl.jlw.entity.dto.TeacherOpenCourseQuestionSettingDTO ;
import com.ibeetl.jlw.enums.CopyFromEnum ;
import com.ibeetl.jlw.enums.ResourcesQuestionTypeEnum ;
import com.ibeetl.jlw.enums.ResourcesQuestionTypeEnum ;
import com.ibeetl.jlw.web.query.ResourcesQuestionQuery ;
import com.ibeetl.jlw.web.query.TeacherOpenCourseMergeCourseInfoQuery ;
import com.ibeetl.jlw.web.query.TeacherOpenCourseMergeCourseInfoQuery ;
import com.ibeetl.jlw.web.query.TeacherOpenCourseMergeResourcesQuestionQuery ;
import com.ibeetl.jlw.web.query.TeacherOpenCourseQuestionSettingQuery ;
import com.ibeetl.jlw.web.query.TeacherOpenCourseQuestionSettingQuery ;
import lombok.extern.slf4j.Slf4j ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.lang3.StringUtils ;
import org.apache.commons.lang3.StringUtils ;
import org.assertj.core.util.Lists ;
import org.beetl.sql.core.SqlId ;
import org.beetl.sql.core.SqlId ;
import org.beetl.sql.core.engine.PageQuery ;
import org.beetl.sql.core.engine.PageQuery ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
@ -35,14 +31,10 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Nullable ;
import javax.annotation.Nullable ;
import javax.validation.constraints.NotEmpty ;
import javax.validation.constraints.NotEmpty ;
import javax.validation.constraints.NotNull ;
import javax.validation.constraints.NotNull ;
import java.math.BigDecimal ;
import java.util.* ;
import java.util.* ;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.function.Function ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
import static cn.hutool.core.text.CharSequenceUtil.join ;
import static cn.hutool.core.text.CharSequenceUtil.join ;
import static java.util.stream.Collectors.groupingBy ;
import static java.util.stream.Collectors.joining ;
import static java.util.stream.Collectors.joining ;
/ * *
/ * *
@ -61,6 +53,8 @@ public class TeacherOpenCourseQuestionSettingService extends CoreBaseService<Tea
@Autowired private TeacherOpenCourseQuestionLogWrongService teacherOpenCourseQuestionLogWrongService ;
@Autowired private TeacherOpenCourseQuestionLogWrongService teacherOpenCourseQuestionLogWrongService ;
@Autowired private ResourcesQuestionService resourcesQuestionService ;
@Autowired private ResourcesQuestionService resourcesQuestionService ;
@Autowired private CourseInfoService courseInfoService ;
@Autowired private CourseInfoService courseInfoService ;
@Autowired private TeacherOpenCourseMergeResourcesQuestionService teacherOpenCourseMergeResourcesQuestionService ;
@Autowired private TeacherOpenCourseMergeCourseInfoService teacherOpenCourseMergeCourseInfoService ;
public PageQuery < TeacherOpenCourseQuestionSetting > queryByCondition ( PageQuery query ) {
public PageQuery < TeacherOpenCourseQuestionSetting > queryByCondition ( PageQuery query ) {
PageQuery ret = teacherOpenCourseQuestionSettingDao . queryByCondition ( query ) ;
PageQuery ret = teacherOpenCourseQuestionSettingDao . queryByCondition ( query ) ;
@ -214,14 +208,44 @@ public class TeacherOpenCourseQuestionSettingService extends CoreBaseService<Tea
}
}
/ * *
/ * *
* 增 加 题 目 类 型 的 数 据
* 根 据 开 课 的 课 程 信 息 , 添 加 题 目 配 置 和 题 目
* 这 里 不 区 分 节 点 是 什 么 类 型 的 。
* 严 格 要 求 :
*
* 添 加 主 表
* 任 务 一 : 添 加 主 表
* 任 务 二 : 添 加 到 题 目 配 置 主 表 ;
* 任 务 二 : 也 可 以 添 加 题 目 快 照 ( 非 必 选 )
* /
public void addFrom ( @Validated ( ValidateConfig . ADD . class ) TeacherOpenCourseMergeCourseInfoQuery teacherOpenCourseMergeCourseInfoQuery ,
@Nullable Collection < TeacherOpenCourseQuestionSettingDTO > questionSettingOptions , CopyFromEnum copyFrom , Map < Long , Long > courseInfoIdPair ) {
Long teacherOpenCourseId = teacherOpenCourseMergeCourseInfoQuery . getTeacherOpenCourseId ( ) ;
TeacherOpenCourseQuestionSettingQuery settingQuery = new TeacherOpenCourseQuestionSettingQuery ( ) ;
// 设置章节练习的默认配置, 并设置开课ID
settingQuery . setCourseTestDefault ( ) . setTeacherOpenCourseId ( teacherOpenCourseId ) ;
settingQuery . setTeacherOpenCourseQuestionSettingName ( teacherOpenCourseMergeCourseInfoQuery . getCourseInfoName ( ) ) ;
settingQuery . setQuestionSettingOptions ( new ArrayList < > ( questionSettingOptions ) ) ;
switch ( copyFrom ) {
case FROM_OPEN_COURSE :
addSettingByOpenCourse ( settingQuery , courseInfoIdPair ) ;
case FROM_SYSTEM :
addSettingBySystemCourse ( settingQuery , courseInfoIdPair ) ;
break ;
}
}
/ * *
* 增 加 题 目 类 型 的 数 据 从 开 课 端 拉 取
*
*
* 任 务 一 ; 添 加 题 目 配 置 主 表
* 任 务 一 ; 添 加 题 目 配 置 主 表
* 任 务 二 : 添 加 题 目 快 照 表
* 任 务 二 : 添 加 题 目 快 照 表
* @param settingQuery
* @param settingQuery
* @return
* @return
* /
* /
public void addByMergeQuestion ( @Validated ( ValidateConfig . ADD . class ) TeacherOpenCourseQuestionSettingQuery settingQuery , Map < Long , Long > courseInfoIdPair ) {
public void add SettingByOpenCourse ( @Validated ( ValidateConfig . ADD . class ) TeacherOpenCourseQuestionSettingQuery settingQuery , Map < Long , Long > courseInfoIdPair ) {
if ( null = = settingQuery . getTeacherOpenCourseQuestionSettingStatus ( ) ) {
if ( null = = settingQuery . getTeacherOpenCourseQuestionSettingStatus ( ) ) {
settingQuery . setTeacherOpenCourseQuestionSettingStatus ( 1 ) ;
settingQuery . setTeacherOpenCourseQuestionSettingStatus ( 1 ) ;
@ -233,10 +257,38 @@ public class TeacherOpenCourseQuestionSettingService extends CoreBaseService<Tea
// 添加到作业主表中
// 添加到作业主表中
add ( settingQuery ) ;
add ( settingQuery ) ;
// 插入快照
// 主表ID
Long teacherOpenCourseQuestionSettingId = settingQuery . getTeacherOpenCourseQuestionSettingId ( ) ;
Long teacherOpenCourseQuestionSettingId = settingQuery . getTeacherOpenCourseQuestionSettingId ( ) ;
List < TeacherOpenCourseQuestionSettingDTO > questionSettingOptions = settingQuery . getQuestionSettingOptions ( ) ;
// 传入的开课题目IDS
resourcesQuestionSnapshotService . insertBatchByMergeResourcesQuestion ( teacherOpenCourseQuestionSettingId , questionSettingOptions , courseInfoIdPair ) ;
String resourcesQuestionIdPlural = settingQuery . getResourcesQuestionIdPlural ( ) ;
// 题目类型区分
Collection < TeacherOpenCourseQuestionSettingDTO > settingDTOList = null ;
if ( ObjectUtil . isNotEmpty ( resourcesQuestionIdPlural ) ) {
TeacherOpenCourseMergeResourcesQuestionQuery questionQuery = new TeacherOpenCourseMergeResourcesQuestionQuery ( ) ;
questionQuery . setQuestionStatus ( 1 ) ;
questionQuery . setTeacherOpenCourseMergeResourcesQuestionIdPlural ( resourcesQuestionIdPlural ) ;
List < TeacherOpenCourseMergeResourcesQuestion > list =
teacherOpenCourseMergeResourcesQuestionService . getValuesByQueryNotWithPermission ( questionQuery ) ;
// 无差别题目IDS转换成类型区分的集合
Map < ResourcesQuestionTypeEnum , TeacherOpenCourseQuestionSettingDTO > map =
teacherOpenCourseMergeResourcesQuestionService . buildSettingDtoListByNoDiffQuestionList ( list ) ;
// 设置分值
settingQuery . getQuestionSettingOptions ( ) . forEach ( item - > {
TeacherOpenCourseQuestionSettingDTO settingDTO = map . get ( item . getQuestionType ( ) ) ;
if ( ObjectUtil . isAllNotEmpty ( settingDTO , item . getSingleScore ( ) ) ) {
settingDTO . setSingleScore ( item . getSingleScore ( ) ) ;
}
} ) ;
if ( ObjectUtil . isNotEmpty ( map ) ) { settingDTOList = map . values ( ) ; }
} else {
settingDTOList = settingQuery . getQuestionSettingOptions ( ) ;
}
resourcesQuestionSnapshotService . insertBatchByOpenResourcesQuestion ( teacherOpenCourseQuestionSettingId , settingDTOList , courseInfoIdPair ) ;
}
}
@ -250,7 +302,7 @@ public class TeacherOpenCourseQuestionSettingService extends CoreBaseService<Tea
* @param settingQuery
* @param settingQuery
* @return
* @return
* /
* /
public void add QuestionByTypeFromSystem ( @Validated ( ValidateConfig . ADD . class ) TeacherOpenCourseQuestionSettingQuery settingQuery , Map < Long , Long > courseInfoIdPair ) {
public void add SettingBySystemCourse ( @Validated ( ValidateConfig . ADD . class ) TeacherOpenCourseQuestionSettingQuery settingQuery , Map < Long , Long > courseInfoIdPair ) {
if ( null = = settingQuery . getTeacherOpenCourseQuestionSettingStatus ( ) ) {
if ( null = = settingQuery . getTeacherOpenCourseQuestionSettingStatus ( ) ) {
settingQuery . setTeacherOpenCourseQuestionSettingStatus ( 1 ) ;
settingQuery . setTeacherOpenCourseQuestionSettingStatus ( 1 ) ;
@ -269,81 +321,6 @@ public class TeacherOpenCourseQuestionSettingService extends CoreBaseService<Tea
}
}
/ * *
* 通 过 无 类 别 区 分 的 题 目 ID , 对 题 目 进 行 分 组 。 并 构 建 需 要 的 数 据
* 只 适 用 于 手 动 出 题 这 块 。
*
* @param noDiffResourcesQuestionIdPlural 题 目 ID 来 自 ResourcesQuestion 表 。
* @return
* /
public Map < ResourcesQuestionTypeEnum , TeacherOpenCourseQuestionSettingDTO > buildSettingDtoListByNoDiffQuestionIds (
@NotEmpty ( message = "系统题目ID不能为空! " ) String noDiffResourcesQuestionIdPlural ) {
// 只查询正常状态的题目列表
ResourcesQuestionQuery resourcesQuestionQuery = new ResourcesQuestionQuery ( ) ;
resourcesQuestionQuery . setQuestionStatus ( 1 ) ;
resourcesQuestionQuery . setResourcesQuestionIds ( noDiffResourcesQuestionIdPlural ) ;
List < ResourcesQuestion > valuesByQuery = resourcesQuestionService . getValuesByQuery ( resourcesQuestionQuery ) ;
return buildSettingDtoListByNoDiffQuestionList ( valuesByQuery ) ;
}
/ * *
* 处 理 章 节 节 点 , 下 面 所 有 的 题 目
* 并 保 存 到 题 目 配 置 和 题 目 快 照 表
* 从 系 统 题 库 表 拷 贝 ! ! !
*
* @param teacherOpenCourseId 开 课 ID
* @param courseInfos 当 前 课 程 下 的 子 节 点
* @param courseInfoIdPair 课 程 的 新 旧 ID 片 段 集 合
* /
public void processGroupChapterListToQuestionSetting ( @NotNull ( message = "开课ID不能为空! " ) Long teacherOpenCourseId ,
Collection < CourseInfo > courseInfos , Map < Long , Long > courseInfoIdPair ) {
// 章节对应下面的所有子集
Map < CourseInfo , List < CourseInfo > > courseChapterInfoIdsWithChildren = courseInfoService . getCourseChapterInfoIdsWithChildren ( courseInfos ) ;
courseChapterInfoIdsWithChildren . forEach ( ( courseInfo , chapterInfoList ) - > {
// 该列表下的所有ID合并
String allCourseInfoIds = chapterInfoList . stream ( ) . map ( item - > item . getCourseInfoId ( ) . toString ( ) ) . collect ( joining ( "," ) ) ;
List < ResourcesQuestion > questionList = resourcesQuestionService . getByCourseInfoIds ( allCourseInfoIds ) ;
// 有题目才继续执行
if ( ObjectUtil . isNotEmpty ( questionList ) ) {
Map < ResourcesQuestionTypeEnum , TeacherOpenCourseQuestionSettingDTO > map = buildSettingDtoListByNoDiffQuestionList ( questionList ) ;
Map < CourseInfo , Collection < TeacherOpenCourseQuestionSettingDTO > > courseInfoIdWithQuestionSettingOptions = new HashMap < > ( 1 ) ;
courseInfoIdWithQuestionSettingOptions . put ( courseInfo , map . values ( ) ) ;
addTeacherOpenCourseQuestionBySystemCourseInfo ( teacherOpenCourseId , courseInfoIdWithQuestionSettingOptions , courseInfoIdPair ) ;
}
} ) ;
}
/ * *
* 根 据 开 课 的 课 程 信 息 , 添 加 题 目 配 置 和 题 目
* 这 里 不 区 分 节 点 是 什 么 类 型 的 。
* 严 格 要 求 :
*
* 添 加 主 表
* 任 务 一 : 添 加 主 表
* 任 务 二 : 添 加 到 题 目 配 置 主 表 ;
* 任 务 二 : 也 可 以 添 加 题 目 快 照 ( 非 必 选 )
* /
public void addTeacherOpenCourseQuestionByCourseInfo ( @Validated ( ValidateConfig . ADD . class ) TeacherOpenCourseMergeCourseInfoQuery teacherOpenCourseMergeCourseInfoQuery ,
@Nullable Collection < TeacherOpenCourseQuestionSettingDTO > questionSettingOptions , Map < Long , Long > courseInfoIdPair ) {
Long teacherOpenCourseId = teacherOpenCourseMergeCourseInfoQuery . getTeacherOpenCourseId ( ) ;
TeacherOpenCourseQuestionSettingQuery settingQuery = new TeacherOpenCourseQuestionSettingQuery ( ) ;
// 设置章节练习的默认配置, 并设置开课ID
settingQuery . setCourseTestDefault ( ) . setTeacherOpenCourseId ( teacherOpenCourseId ) ;
settingQuery . setTeacherOpenCourseQuestionSettingName ( teacherOpenCourseMergeCourseInfoQuery . getCourseInfoName ( ) ) ;
settingQuery . setQuestionSettingOptions ( new ArrayList < > ( questionSettingOptions ) ) ;
addQuestionByTypeFromSystem ( settingQuery , courseInfoIdPair ) ;
}
/ * *
/ * *
* 根 据 开 课 的 课 程 信 息 , 添 加 题 目 配 置 和 题 目
* 根 据 开 课 的 课 程 信 息 , 添 加 题 目 配 置 和 题 目
*
*
@ -354,10 +331,10 @@ public class TeacherOpenCourseQuestionSettingService extends CoreBaseService<Tea
* @param teacherOpenCourseId 开 课 ID
* @param teacherOpenCourseId 开 课 ID
* @param courseInfoIdWithQuestionSettingOptions Key : 课 程 名 称 , Value : 题 型 和 题 目 ID 的 组 合 列 表
* @param courseInfoIdWithQuestionSettingOptions Key : 课 程 名 称 , Value : 题 型 和 题 目 ID 的 组 合 列 表
* /
* /
public void add TeacherOpenCourseQuestionByCourseInfo ( @NotNull ( message = "开课ID不能为空! " ) Long teacherOpenCourseId ,
public void add SettingByOpenCourse ( @NotNull ( message = "开课ID不能为空! " ) Long teacherOpenCourseId ,
@Nullable Map < TeacherOpenCourseMergeCourseInfo , Collection < TeacherOpenCourseQuestionSettingDTO > > courseInfoIdWithQuestionSettingOptions ,
@Nullable Map < TeacherOpenCourseMergeCourseInfo , Collection < TeacherOpenCourseQuestionSettingDTO > > courseInfoIdWithQuestionSettingOptions ,
@NotNull Map < Long , Long > courseInfoIdPair ) {
@NotNull Map < Long , Long > courseInfoIdPair ) {
add TeacherOpenCourseQuestionByCourseInfo ( teacherOpenCourseId , courseInfoIdWithQuestionSettingOptions , Integer . valueOf ( 2 ) , TeacherOpenCourseMergeCourseInfo : : getCourseInfoType , courseInfoIdPair ) ;
add SettingByOpenCourse ( teacherOpenCourseId , courseInfoIdWithQuestionSettingOptions , Integer . valueOf ( 2 ) , TeacherOpenCourseMergeCourseInfo : : getCourseInfoType , courseInfoIdPair ) ;
}
}
@ -375,9 +352,9 @@ public class TeacherOpenCourseQuestionSettingService extends CoreBaseService<Tea
* @param func1 比 对 的 字 段 取 值 接 口
* @param func1 比 对 的 字 段 取 值 接 口
* @param courseInfoIdPair
* @param courseInfoIdPair
* /
* /
public void add TeacherOpenCourseQuestionByCourseInfo ( @NotNull ( message = "开课ID不能为空! " ) Long teacherOpenCourseId ,
public void add SettingByOpenCourse ( @NotNull ( message = "开课ID不能为空! " ) Long teacherOpenCourseId ,
@Nullable Map < TeacherOpenCourseMergeCourseInfo , Collection < TeacherOpenCourseQuestionSettingDTO > > courseInfoIdWithQuestionSettingOptions ,
@Nullable Map < TeacherOpenCourseMergeCourseInfo , Collection < TeacherOpenCourseQuestionSettingDTO > > courseInfoIdWithQuestionSettingOptions ,
@NotNull Object eq , @NotNull Func1 < TeacherOpenCourseMergeCourseInfo , Integer > func1 , @NotNull Map < Long , Long > courseInfoIdPair ) {
@NotNull Object eq , @NotNull Func1 < TeacherOpenCourseMergeCourseInfo , Integer > func1 , @NotNull Map < Long , Long > courseInfoIdPair ) {
TeacherOpenCourseQuestionSettingQuery settingQuery = new TeacherOpenCourseQuestionSettingQuery ( ) ;
TeacherOpenCourseQuestionSettingQuery settingQuery = new TeacherOpenCourseQuestionSettingQuery ( ) ;
// 设置章节练习的默认配置, 并设置开课ID
// 设置章节练习的默认配置, 并设置开课ID
settingQuery . setCourseTestDefault ( ) . setTeacherOpenCourseId ( teacherOpenCourseId ) ;
settingQuery . setCourseTestDefault ( ) . setTeacherOpenCourseId ( teacherOpenCourseId ) ;
@ -388,7 +365,7 @@ public class TeacherOpenCourseQuestionSettingService extends CoreBaseService<Tea
if ( eq . equals ( func1 . call ( courseInfo ) ) ) {
if ( eq . equals ( func1 . call ( courseInfo ) ) ) {
settingQuery . setQuestionSettingOptions ( new ArrayList < > ( settingDtoList ) ) ;
settingQuery . setQuestionSettingOptions ( new ArrayList < > ( settingDtoList ) ) ;
settingQuery . setTeacherOpenCourseQuestionSettingName ( courseInfo . getCourseInfoName ( ) ) ;
settingQuery . setTeacherOpenCourseQuestionSettingName ( courseInfo . getCourseInfoName ( ) ) ;
add ByMergeQuestion ( settingQuery , courseInfoIdPair ) ;
add SettingByOpenCourse ( settingQuery , courseInfoIdPair ) ;
}
}
} catch ( Exception e ) { }
} catch ( Exception e ) { }
} ) ;
} ) ;
@ -405,10 +382,10 @@ public class TeacherOpenCourseQuestionSettingService extends CoreBaseService<Tea
* @param teacherOpenCourseId 开 课 ID
* @param teacherOpenCourseId 开 课 ID
* @param courseInfoIdWithQuestionSettingOptions Key : 课 程 名 称 , Value : 题 型 和 题 目 ID 的 组 合 列 表
* @param courseInfoIdWithQuestionSettingOptions Key : 课 程 名 称 , Value : 题 型 和 题 目 ID 的 组 合 列 表
* /
* /
public void add TeacherOpenCourseQuestionBySystemCourseInfo ( @NotNull ( message = "开课ID不能为空! " ) Long teacherOpenCourseId ,
public void add SettingBySystemCourse ( @NotNull ( message = "开课ID不能为空! " ) Long teacherOpenCourseId ,
@Nullable Map < CourseInfo , Collection < TeacherOpenCourseQuestionSettingDTO > > courseInfoIdWithQuestionSettingOptions ,
@Nullable Map < CourseInfo , Collection < TeacherOpenCourseQuestionSettingDTO > > courseInfoIdWithQuestionSettingOptions ,
@NotNull Map < Long , Long > courseInfoIdPair ) {
@NotNull Map < Long , Long > courseInfoIdPair ) {
add TeacherOpenCourseQuestionBySystemCourseInfo ( teacherOpenCourseId , courseInfoIdWithQuestionSettingOptions , Integer . valueOf ( 2 ) , CourseInfo : : getCourseInfoType , courseInfoIdPair ) ;
add SettingBySystemCourse ( teacherOpenCourseId , courseInfoIdWithQuestionSettingOptions , Integer . valueOf ( 2 ) , CourseInfo : : getCourseInfoType , courseInfoIdPair ) ;
}
}
/ * *
/ * *
@ -425,9 +402,9 @@ public class TeacherOpenCourseQuestionSettingService extends CoreBaseService<Tea
* @param func1 比 对 的 字 段 取 值 接 口
* @param func1 比 对 的 字 段 取 值 接 口
* @param courseInfoIdPair
* @param courseInfoIdPair
* /
* /
public void add TeacherOpenCourseQuestionBySystemCourseInfo ( @NotNull ( message = "开课ID不能为空! " ) Long teacherOpenCourseId ,
public void add SettingBySystemCourse ( @NotNull ( message = "开课ID不能为空! " ) Long teacherOpenCourseId ,
@Nullable Map < CourseInfo , Collection < TeacherOpenCourseQuestionSettingDTO > > courseInfoIdWithQuestionSettingOptions ,
@Nullable Map < CourseInfo , Collection < TeacherOpenCourseQuestionSettingDTO > > courseInfoIdWithQuestionSettingOptions ,
@NotNull Object eq , @NotNull Func1 < CourseInfo , Integer > func1 , @NotNull Map < Long , Long > courseInfoIdPair ) {
@NotNull Object eq , @NotNull Func1 < CourseInfo , Integer > func1 , @NotNull Map < Long , Long > courseInfoIdPair ) {
TeacherOpenCourseQuestionSettingQuery settingQuery = new TeacherOpenCourseQuestionSettingQuery ( ) ;
TeacherOpenCourseQuestionSettingQuery settingQuery = new TeacherOpenCourseQuestionSettingQuery ( ) ;
// 设置章节练习的默认配置, 并设置开课ID
// 设置章节练习的默认配置, 并设置开课ID
settingQuery . setCourseTestDefault ( ) . setTeacherOpenCourseId ( teacherOpenCourseId ) ;
settingQuery . setCourseTestDefault ( ) . setTeacherOpenCourseId ( teacherOpenCourseId ) ;
@ -438,67 +415,12 @@ public class TeacherOpenCourseQuestionSettingService extends CoreBaseService<Tea
if ( eq . equals ( func1 . call ( courseInfo ) ) ) {
if ( eq . equals ( func1 . call ( courseInfo ) ) ) {
settingQuery . setQuestionSettingOptions ( new ArrayList < > ( settingDtoList ) ) ;
settingQuery . setQuestionSettingOptions ( new ArrayList < > ( settingDtoList ) ) ;
settingQuery . setTeacherOpenCourseQuestionSettingName ( courseInfo . getCourseInfoName ( ) ) ;
settingQuery . setTeacherOpenCourseQuestionSettingName ( courseInfo . getCourseInfoName ( ) ) ;
add QuestionByTypeFromSystem ( settingQuery , courseInfoIdPair ) ;
add SettingBySystemCourse ( settingQuery , courseInfoIdPair ) ;
}
}
} catch ( Exception e ) { }
} catch ( Exception e ) { }
} ) ;
} ) ;
}
}
/ * *
* 通 过 无 类 别 区 分 的 题 目 列 表 , 对 题 目 进 行 分 组 。 并 构 建 需 要 的 数 据
* 只 适 用 于 手 动 出 题 这 块 。
*
* @param resourcesQuestionList
* @return
* /
public Map < ResourcesQuestionTypeEnum , TeacherOpenCourseQuestionSettingDTO > buildSettingDtoListByNoDiffQuestionList (
List < ResourcesQuestion > resourcesQuestionList ) {
if ( ObjectUtil . isEmpty ( resourcesQuestionList ) ) {
return null ;
}
// 先构建初始的属性
Function < ResourcesQuestion , TeacherOpenCourseQuestionSettingDTO > buildFunc =
item - > TeacherOpenCourseQuestionSettingDTO . builder ( )
. questionType ( EnumUtil . likeValueOf ( ResourcesQuestionTypeEnum . class , item . getQuestionType ( ) ) )
. resourcesQuestionIdPlural ( item . getResourcesQuestionId ( ) . toString ( ) )
. singleScore ( item . getQuestionScore ( ) )
. build ( ) ;
// 根据类型分组
Map < ResourcesQuestionTypeEnum , List < TeacherOpenCourseQuestionSettingDTO > > groupMap =
resourcesQuestionList . stream ( ) . map ( buildFunc ) . collect ( groupingBy ( TeacherOpenCourseQuestionSettingDTO : : getQuestionType ) ) ;
Map < ResourcesQuestionTypeEnum , TeacherOpenCourseQuestionSettingDTO > result = new ConcurrentHashMap < > ( 5 ) ;
// 分组后的数据,再处理
groupMap . forEach ( ( key , value ) - > {
// resourcesQuestionIdPlural 上面暂存的是单个题目ID, 这里将所有的题目ID处理成逗号隔开的字符
String questionIds = value . stream ( )
. map ( TeacherOpenCourseQuestionSettingDTO : : getResourcesQuestionIdPlural ) . collect ( joining ( "," ) ) ;
// 查询到的题目的数量
Integer selectCount = ObjectUtil . defaultIfNull ( value , Lists . emptyList ( ) ) . size ( ) ;
// 设置其他属性,如果集合长度不为空的话
if ( selectCount > 0 ) {
TeacherOpenCourseQuestionSettingDTO teacherOpenCourseQuestionSettingDTO = value . get ( 0 ) ;
// 该类型下,单个题目的分数
BigDecimal singleScore = teacherOpenCourseQuestionSettingDTO . getSingleScore ( ) ;
teacherOpenCourseQuestionSettingDTO . setResourcesQuestionIdPlural ( questionIds )
. setSingleTypeTotalScore ( NumberUtil . mul ( singleScore , selectCount ) )
. setSelectCount ( selectCount ) ;
// 放入结果集中
result . put ( key , teacherOpenCourseQuestionSettingDTO ) ;
}
} ) ;
return result ;
}
@Override
@Override
public void resetOperationByTeacherOpenCourseId ( Long teacherOpenCourseId ) {
public void resetOperationByTeacherOpenCourseId ( Long teacherOpenCourseId ) {
log . info ( "重置开课题目配置" ) ;
log . info ( "重置开课题目配置" ) ;
@ -550,4 +472,89 @@ public class TeacherOpenCourseQuestionSettingService extends CoreBaseService<Tea
}
}
}
}
/ * *
* 处 理 章 节 节 点 , 下 面 所 有 的 题 目
* 并 保 存 到 题 目 配 置 和 题 目 快 照 表
* 从 系 统 题 库 表 拷 贝 ! ! !
*
* @param teacherOpenCourseId 开 课 ID
* @param courseInfos 当 前 课 程 下 的 子 节 点
* @param courseInfoIdPair 课 程 的 新 旧 ID 片 段 集 合
* /
public void copySystemQuestionChapterTestQuestionToOpenCourse ( @NotNull ( message = "开课ID不能为空! " ) Long teacherOpenCourseId ,
Collection < CourseInfo > courseInfos , Map < Long , Long > courseInfoIdPair ) {
// 章节对应下面的所有子集
Map < CourseInfo , List < CourseInfo > > courseChapterInfoIdsWithChildren = courseInfoService . getCourseChapterInfoIdsWithChildren ( courseInfos ) ;
courseChapterInfoIdsWithChildren . forEach ( ( courseInfo , chapterInfoList ) - > {
// 该列表下的所有ID合并
String allCourseInfoIds = chapterInfoList . stream ( ) . map ( item - > item . getCourseInfoId ( ) . toString ( ) ) . collect ( joining ( "," ) ) ;
List < ResourcesQuestion > questionList = resourcesQuestionService . getByCourseInfoIds ( allCourseInfoIds ) ;
// 有题目才继续执行
if ( ObjectUtil . isNotEmpty ( questionList ) ) {
Map < ResourcesQuestionTypeEnum , TeacherOpenCourseQuestionSettingDTO > map = resourcesQuestionService . buildSettingDtoListByNoDiffQuestionList ( questionList ) ;
Map < CourseInfo , Collection < TeacherOpenCourseQuestionSettingDTO > > courseInfoIdWithQuestionSettingOptions = new HashMap < > ( 1 ) ;
courseInfoIdWithQuestionSettingOptions . put ( courseInfo , map . values ( ) ) ;
addSettingBySystemCourse ( teacherOpenCourseId , courseInfoIdWithQuestionSettingOptions , courseInfoIdPair ) ;
}
} ) ;
}
/ * *
* 复 制 开 课 题 库 中 的 章 节 节 点 题 目 , 到 章 节 练 习 中
*
* @param teacherOpenCourseId
* @param courseInfoIdPair
* /
public void copyOpenQuestionChapterTestQuestionToOpenCourse ( @NotNull ( message = "开课ID不能为空! " ) Long teacherOpenCourseId , Map < Long , Long > courseInfoIdPair ) {
TeacherOpenCourseMergeCourseInfoQuery query = new TeacherOpenCourseMergeCourseInfoQuery ( ) ;
query . setTeacherOpenCourseId ( teacherOpenCourseId ) ;
query . setCourseInfoStatus ( 1 ) ;
// 获取这个开课下的所有的课程章节信息
List < TeacherOpenCourseMergeCourseInfo > list =
teacherOpenCourseMergeCourseInfoService . getValuesByQueryNotWithPermission ( query ) ;
if ( ObjectUtil . isEmpty ( list ) ) {
return ;
}
// 章节点
Set < TeacherOpenCourseMergeCourseInfo > chapterSet = list . stream ( )
. filter ( item - > Integer . valueOf ( 2 ) . equals ( item . getCourseInfoType ( ) ) ) . collect ( Collectors . toSet ( ) ) ;
// 章下面所有小节,包含章节点
Set < TeacherOpenCourseMergeCourseInfo > result = new HashSet < > ( 12 ) ;
for ( TeacherOpenCourseMergeCourseInfo chapter : chapterSet ) {
result . clear ( ) ;
Long teacherOpenCourseMergeCourseInfoId = chapter . getTeacherOpenCourseMergeCourseInfoId ( ) ;
teacherOpenCourseMergeCourseInfoService . getCourseResourcesByList ( list , teacherOpenCourseMergeCourseInfoId , result ) ;
result . add ( chapter ) ;
// 单个章节下的所有小节的ID。包含章节
String ids = result . stream ( ) . map ( item - > item . getTeacherOpenCourseMergeCourseInfoId ( ) . toString ( ) ) . collect ( joining ( "," ) ) ;
TeacherOpenCourseMergeResourcesQuestionQuery questionQuery = new TeacherOpenCourseMergeResourcesQuestionQuery ( ) ;
questionQuery . setTeacherOpenCourseMergeCourseInfoIdPlural ( ids ) ;
// 获取章下面的所有题目
List < TeacherOpenCourseMergeResourcesQuestion > resourcesQuestionList =
teacherOpenCourseMergeResourcesQuestionService . getValuesByQueryNotWithPermission ( questionQuery ) ;
TeacherOpenCourseQuestionSettingQuery questionSettingQuery = new TeacherOpenCourseQuestionSettingQuery ( ) ;
questionSettingQuery . setCourseTestDefault ( )
. setTeacherOpenCourseQuestionSettingName ( chapter . getCourseInfoName ( ) )
. setTeacherOpenCourseId ( teacherOpenCourseId ) ;
// 添加到章节练习题目配置主表
add ( questionSettingQuery ) ;
// 如果有关联的题目,则添加到题目快照表
if ( ObjectUtil . isNotEmpty ( resourcesQuestionList ) ) {
// 构造章节练习的题目快照
List < ResourcesQuestionSnapshot > resourcesQuestionSnapshots = BeanUtil . copyToList ( resourcesQuestionList , ResourcesQuestionSnapshot . class ) ;
resourcesQuestionSnapshots . forEach ( item - > item . setTeacherOpenCourseQuestionSettingId ( questionSettingQuery . getTeacherOpenCourseQuestionSettingId ( ) ) ) ;
// 批量添加题目快照
resourcesQuestionSnapshotService . insertBatch ( resourcesQuestionSnapshots ) ;
}
}
}
}
}