|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
package com.ibeetl.jlw.service;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.extra.validation.BeanValidationResult;
|
|
|
|
|
import cn.hutool.extra.validation.ValidationUtil;
|
|
|
|
|
import cn.jlw.util.ToolUtils;
|
|
|
|
@ -9,10 +11,13 @@ import com.ibeetl.admin.core.service.CoreBaseService;
|
|
|
|
|
import com.ibeetl.admin.core.util.PlatformException;
|
|
|
|
|
import com.ibeetl.admin.core.web.JsonResult;
|
|
|
|
|
import com.ibeetl.admin.core.web.JsonReturnCode;
|
|
|
|
|
import com.ibeetl.jlw.dao.ResourcesQuestionSnapshotDao;
|
|
|
|
|
import com.ibeetl.jlw.dao.TeacherOpenCourseHomeworkDao;
|
|
|
|
|
import com.ibeetl.jlw.entity.ResourcesQuestionSnapshot;
|
|
|
|
|
import com.ibeetl.jlw.entity.TeacherOpenCourseHomework;
|
|
|
|
|
import com.ibeetl.jlw.entity.TeacherOpenCourseHomeworkSetting;
|
|
|
|
|
import com.ibeetl.jlw.enums.FromTypeEnum;
|
|
|
|
|
import com.ibeetl.jlw.web.query.ResourcesQuestionSnapshotQuery;
|
|
|
|
|
import com.ibeetl.jlw.web.query.TeacherOpenCourseHomeworkQuery;
|
|
|
|
|
import com.ibeetl.jlw.web.query.TeacherOpenCourseHomeworkSettingQuery;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
@ -24,10 +29,14 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import static cn.hutool.json.JSONUtil.toJsonStr;
|
|
|
|
|
import static com.ibeetl.jlw.entity.ResourcesQuestionOptionEntity.shuffleOrderOptions;
|
|
|
|
|
import static com.ibeetl.jlw.web.query.TeacherOpenCourseHomeworkQuery.TeacherOpenCourseHomeworkTypeEnum.getClazzByEnum;
|
|
|
|
|
import static java.util.stream.Collectors.groupingBy;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 开课作业 Service
|
|
|
|
@ -40,6 +49,7 @@ public class TeacherOpenCourseHomeworkService extends CoreBaseService<TeacherOpe
|
|
|
|
|
|
|
|
|
|
@Resource private TeacherOpenCourseHomeworkDao teacherOpenCourseHomeworkDao;
|
|
|
|
|
@Resource private TeacherOpenCourseHomeworkSettingService teacherOpenCourseHomeworkSettingService;
|
|
|
|
|
@Resource private ResourcesQuestionSnapshotDao resourcesQuestionSnapshotDao;
|
|
|
|
|
|
|
|
|
|
public PageQuery<TeacherOpenCourseHomework>queryByCondition(PageQuery query){
|
|
|
|
|
PageQuery ret = teacherOpenCourseHomeworkDao.queryByCondition(query);
|
|
|
|
@ -183,12 +193,12 @@ public class TeacherOpenCourseHomeworkService extends CoreBaseService<TeacherOpe
|
|
|
|
|
* @param teacherOpenCourseHomeworkId 开课作业ID
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Object getHomeworkDetail(final Long teacherOpenCourseHomeworkId) {
|
|
|
|
|
public List<ResourcesQuestionSnapshot> homeworkDetail(final Long teacherOpenCourseHomeworkId) {
|
|
|
|
|
|
|
|
|
|
// 常量 True的Integer表现
|
|
|
|
|
final Integer TRUE_CONST = 1;
|
|
|
|
|
|
|
|
|
|
TeacherOpenCourseHomework homework = getInfo(teacherOpenCourseHomeworkId);
|
|
|
|
|
List<ResourcesQuestionSnapshot> resourcesQuestionSnapshots = new ArrayList<>();
|
|
|
|
|
TeacherOpenCourseHomework homework = getInfo(teacherOpenCourseHomeworkId);
|
|
|
|
|
cn.hutool.core.lang.Assert.notNull(homework, "未查询到");
|
|
|
|
|
|
|
|
|
|
TeacherOpenCourseHomeworkSettingQuery settingQuery = new TeacherOpenCourseHomeworkSettingQuery();
|
|
|
|
@ -197,29 +207,61 @@ public class TeacherOpenCourseHomeworkService extends CoreBaseService<TeacherOpe
|
|
|
|
|
|
|
|
|
|
// 作答次数
|
|
|
|
|
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseHomeworkSettingDoCount())) {
|
|
|
|
|
|
|
|
|
|
// TODO 逻辑不一定要在这里写
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 答卷后显示答案解析
|
|
|
|
|
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseHomeworkSettingEndShowQa())) {
|
|
|
|
|
|
|
|
|
|
// TODO 逻辑不一定要在这里写
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 答卷后显示答案对错
|
|
|
|
|
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseHomeworkSettingEndShowTrueFalse())) {
|
|
|
|
|
|
|
|
|
|
// TODO 逻辑不一定要在这里写
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 选项乱序(限单选、多选)
|
|
|
|
|
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseHomeworkSettingOptionNoOrder())) {
|
|
|
|
|
ResourcesQuestionSnapshotQuery questionSnapshotQuery = new ResourcesQuestionSnapshotQuery();
|
|
|
|
|
questionSnapshotQuery.setFromId(teacherOpenCourseHomeworkId);
|
|
|
|
|
resourcesQuestionSnapshots = resourcesQuestionSnapshotDao.getValuesByQuery(questionSnapshotQuery);
|
|
|
|
|
|
|
|
|
|
// 单题选项排序处理
|
|
|
|
|
resourcesQuestionSnapshots.forEach(value ->
|
|
|
|
|
shuffleOrderOptions(value, "questionAnswer","questionOption", true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 题目乱序(同一大题内)
|
|
|
|
|
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseHomeworkSettingQuestionNoOrder())) {
|
|
|
|
|
shuffleOrderQuestions(resourcesQuestionSnapshots);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resourcesQuestionSnapshots;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 同一个大题内,随机排序
|
|
|
|
|
* @param resourcesQuestionSnapshots
|
|
|
|
|
*/
|
|
|
|
|
private void shuffleOrderQuestions(List<ResourcesQuestionSnapshot> resourcesQuestionSnapshots) {
|
|
|
|
|
|
|
|
|
|
// 安全判空
|
|
|
|
|
if (ObjectUtil.isEmpty(resourcesQuestionSnapshots)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
// 题目根据类型分组
|
|
|
|
|
Map<Integer, List<ResourcesQuestionSnapshot>> questionTypeMap = resourcesQuestionSnapshots.stream()
|
|
|
|
|
.collect(groupingBy(ResourcesQuestionSnapshot::getQuestionType));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 同一道大题内,乱序
|
|
|
|
|
questionTypeMap.forEach((questionType, questionSnapshots) -> {
|
|
|
|
|
Collections.shuffle(questionSnapshots);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 大题数字升序
|
|
|
|
|
MapUtil.sort(questionTypeMap);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|