|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.ibeetl.jlw.service;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.jlw.util.ToolUtils;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
@ -12,6 +13,7 @@ import com.ibeetl.jlw.dao.ResourcesQuestionSnapshotDao;
|
|
|
|
|
import com.ibeetl.jlw.dao.StudentDao;
|
|
|
|
|
import com.ibeetl.jlw.dao.TeacherOpenCourseMergeResourcesQuestionDao;
|
|
|
|
|
import com.ibeetl.jlw.entity.*;
|
|
|
|
|
import com.ibeetl.jlw.entity.dto.TeacherOpenCourseQuestionSettingDTO;
|
|
|
|
|
import com.ibeetl.jlw.web.query.ResourcesQuestionSnapshotQuery;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.beetl.sql.core.SQLReady;
|
|
|
|
@ -26,11 +28,8 @@ import javax.validation.constraints.NotBlank;
|
|
|
|
|
import javax.validation.constraints.NotEmpty;
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUserId;
|
|
|
|
|
|
|
|
|
@ -165,23 +164,85 @@ public class ResourcesQuestionSnapshotService extends CoreBaseService<ResourcesQ
|
|
|
|
|
* 传入题目ID 批量导入到快照表中
|
|
|
|
|
*
|
|
|
|
|
* @param teacherOpenCourseQuestionSettingId 开课题目配置ID
|
|
|
|
|
* @param questionIds 支持单个字符逗号隔开,或者多个ID数组
|
|
|
|
|
* @param questionSettingOptions 根据题型动态分配题目
|
|
|
|
|
* @param questionIdPlural 支持单个字符逗号隔开,或者多个ID数组
|
|
|
|
|
*/
|
|
|
|
|
public void insertBatchByQuestionIds(@NotNull(message = "开课题目配置ID不能为空!") final Long teacherOpenCourseQuestionSettingId,
|
|
|
|
|
@NotEmpty(message = "题目ID不能为空!") String... questionIds) {
|
|
|
|
|
List<TeacherOpenCourseQuestionSettingDTO> questionSettingOptions,
|
|
|
|
|
String questionIdPlural) {
|
|
|
|
|
|
|
|
|
|
// 处理题目ID
|
|
|
|
|
String questionIdPlural = Arrays.stream(questionIds)
|
|
|
|
|
.distinct().flatMap(item -> Stream.of(item.split(",")))
|
|
|
|
|
.collect(Collectors.joining(","));
|
|
|
|
|
// 在插入之前,先清空列表。这种情况下,支持题目配置还在,重置题目列表的操作。
|
|
|
|
|
ResourcesQuestionSnapshot deleteCondition = new ResourcesQuestionSnapshot();
|
|
|
|
|
deleteCondition.setTeacherOpenCourseQuestionSettingId(teacherOpenCourseQuestionSettingId);
|
|
|
|
|
deleteCondition.setQuestionStatus(1);
|
|
|
|
|
deleteByCondition(deleteCondition);
|
|
|
|
|
|
|
|
|
|
List<ResourcesQuestionSnapshot> insertList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 题目设置,来动态获取题目
|
|
|
|
|
if(ObjectUtil.isNotEmpty(questionSettingOptions)) {
|
|
|
|
|
insertList = getResourcesQuestionSnapshotListByQuestionSettingOptions(teacherOpenCourseQuestionSettingId, questionSettingOptions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据题目ID集合获取题目
|
|
|
|
|
if(ObjectUtil.isNotEmpty(questionIdPlural)) {
|
|
|
|
|
insertList = getResourcesQuestionSnapshotListByQuestionIds(teacherOpenCourseQuestionSettingId, questionIdPlural);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resourcesQuestionSnapshotDao.insertBatch(insertList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据题目ID集合
|
|
|
|
|
* 获取题目快照列表。并配置题目配置ID
|
|
|
|
|
*
|
|
|
|
|
* @param teacherOpenCourseQuestionSettingId
|
|
|
|
|
* @param questionIdPlural
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<ResourcesQuestionSnapshot> getResourcesQuestionSnapshotListByQuestionIds(
|
|
|
|
|
@NotNull(message = "开课题目配置ID不能为空!") final Long teacherOpenCourseQuestionSettingId,
|
|
|
|
|
@NotBlank(message = "题目ID列表不能为空!") String questionIdPlural) {
|
|
|
|
|
// 批量插入快照表
|
|
|
|
|
List<TeacherOpenCourseMergeResourcesQuestion> byIds = teacherOpenCourseMergeResourcesQuestionDao.getByIds(questionIdPlural);
|
|
|
|
|
List<ResourcesQuestionSnapshot> snapshotList = BeanUtil.copyToList(byIds, ResourcesQuestionSnapshot.class);
|
|
|
|
|
snapshotList.forEach(snapshot -> {
|
|
|
|
|
snapshot.setTeacherOpenCourseQuestionSettingId(teacherOpenCourseQuestionSettingId);
|
|
|
|
|
});
|
|
|
|
|
resourcesQuestionSnapshotDao.insertBatch(snapshotList);
|
|
|
|
|
|
|
|
|
|
return snapshotList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据题目类型配置
|
|
|
|
|
* 获取题目快照列表。并配置题目配置ID
|
|
|
|
|
*
|
|
|
|
|
* @param teacherOpenCourseQuestionSettingId
|
|
|
|
|
* @param questionSettingOptions
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<ResourcesQuestionSnapshot> getResourcesQuestionSnapshotListByQuestionSettingOptions(
|
|
|
|
|
@NotNull(message = "开课题目配置ID不能为空!") final Long teacherOpenCourseQuestionSettingId,
|
|
|
|
|
@NotBlank(message = "题目设置不能为空!") List<TeacherOpenCourseQuestionSettingDTO> questionSettingOptions) {
|
|
|
|
|
|
|
|
|
|
List<ResourcesQuestionSnapshot> result = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (TeacherOpenCourseQuestionSettingDTO questionSettingOption : questionSettingOptions) {
|
|
|
|
|
// 根据配置随机出题
|
|
|
|
|
List<TeacherOpenCourseMergeResourcesQuestion> randomMergeResourcesQuestionList =
|
|
|
|
|
teacherOpenCourseMergeResourcesQuestionDao.getRandomMergeResourcesQuestionList(questionSettingOption);
|
|
|
|
|
|
|
|
|
|
// Copy到新对象中
|
|
|
|
|
List<ResourcesQuestionSnapshot> snapshotList = BeanUtil.copyToList(randomMergeResourcesQuestionList, ResourcesQuestionSnapshot.class);
|
|
|
|
|
snapshotList.forEach(snapshot -> {
|
|
|
|
|
snapshot.setTeacherOpenCourseQuestionSettingId(teacherOpenCourseQuestionSettingId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 放入最终的集合中
|
|
|
|
|
result.addAll(snapshotList);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|