|
|
|
@ -1,7 +1,9 @@
|
|
|
|
|
package com.ibeetl.jlw.service;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
|
import cn.hutool.core.util.BooleanUtil;
|
|
|
|
|
import cn.jlw.util.EnumUtil;
|
|
|
|
|
import cn.jlw.util.ToolUtils;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
@ -12,26 +14,32 @@ import com.ibeetl.admin.core.web.JsonReturnCode;
|
|
|
|
|
import com.ibeetl.jlw.dao.ResourcesQuestionSnapshotDao;
|
|
|
|
|
import com.ibeetl.jlw.dao.StudentDao;
|
|
|
|
|
import com.ibeetl.jlw.dao.TeacherOpenCourseQuestionLogDao;
|
|
|
|
|
import com.ibeetl.jlw.entity.*;
|
|
|
|
|
import com.ibeetl.jlw.entity.ResourcesQuestionSnapshot;
|
|
|
|
|
import com.ibeetl.jlw.entity.Student;
|
|
|
|
|
import com.ibeetl.jlw.entity.TeacherOpenCourseQuestionLog;
|
|
|
|
|
import com.ibeetl.jlw.entity.TeacherOpenCourseQuestionSetting;
|
|
|
|
|
import com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum;
|
|
|
|
|
import com.ibeetl.jlw.web.query.ResourcesQuestionSnapshotQuery;
|
|
|
|
|
import com.ibeetl.jlw.web.query.TeacherOpenCourseHomeworkSettingQuery;
|
|
|
|
|
import com.ibeetl.jlw.web.query.TeacherOpenCourseQuestionLogQuery;
|
|
|
|
|
import com.ibeetl.jlw.web.query.TeacherOpenCourseQuestionSettingQuery;
|
|
|
|
|
import com.sun.istack.internal.Nullable;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.beetl.sql.core.SqlId;
|
|
|
|
|
import org.beetl.sql.core.engine.PageQuery;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.validation.constraints.NotEmpty;
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
import static cn.hutool.core.util.ArrayUtil.join;
|
|
|
|
|
import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUserId;
|
|
|
|
|
import static com.ibeetl.jlw.entity.ResourcesQuestionOptionEntity.shuffleOrderOptions;
|
|
|
|
|
import static com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum.CHAPTER_EXERCISE;
|
|
|
|
|
import static java.util.stream.Collectors.groupingBy;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -41,13 +49,13 @@ import static java.util.stream.Collectors.groupingBy;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@Transactional
|
|
|
|
|
@Validated
|
|
|
|
|
public class TeacherOpenCourseQuestionLogService extends CoreBaseService<TeacherOpenCourseQuestionLog>{
|
|
|
|
|
|
|
|
|
|
@Resource private TeacherOpenCourseQuestionLogDao teacherOpenCourseQuestionLogDao;
|
|
|
|
|
@Resource private StudentDao studentDao;
|
|
|
|
|
@Resource private ResourcesQuestionSnapshotDao resourcesQuestionSnapshotDao;
|
|
|
|
|
@Resource private TeacherOpenCourseHomeworkService teacherOpenCourseHomeworkService;
|
|
|
|
|
@Resource private TeacherOpenCourseHomeworkSettingService teacherOpenCourseHomeworkSettingService;
|
|
|
|
|
@Resource private TeacherOpenCourseQuestionSettingService teacherOpenCourseQuestionSettingSettingService;
|
|
|
|
|
|
|
|
|
|
public PageQuery<TeacherOpenCourseQuestionLog>queryByCondition(PageQuery query){
|
|
|
|
|
PageQuery ret = teacherOpenCourseQuestionLogDao.queryByCondition(query);
|
|
|
|
@ -167,17 +175,16 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
|
|
|
|
|
* 和题目有关的做题提交方法
|
|
|
|
|
*
|
|
|
|
|
* @param questionLogMap <题目ID, [数组:前端传递过来不需要考虑排序和重复问题]> 例: {"10086": ["D", "A", "B", "A"]}
|
|
|
|
|
* @param fromType 来源类型
|
|
|
|
|
* @param questionSettingId 题目配置ID
|
|
|
|
|
*/
|
|
|
|
|
public void addQuestionLog(Map<Long, TreeSet<String>> questionLogMap, final ResourcesQuestionSnapshotFromTypeEnum fromType) {
|
|
|
|
|
@Deprecated
|
|
|
|
|
public void addQuestionLog(
|
|
|
|
|
@NotEmpty(message = "请上传题目快照ID和答案!") Map<Long, TreeSet<String>> questionLogMap,
|
|
|
|
|
@NotNull(message = "开课题目配置ID不能为空!") final Long questionSettingId) {
|
|
|
|
|
|
|
|
|
|
// 查询学生身份
|
|
|
|
|
final Student student = studentDao.getByUserId(getUserId());
|
|
|
|
|
|
|
|
|
|
ResourcesQuestionSnapshot entity = new ResourcesQuestionSnapshot();
|
|
|
|
|
entity.setResourcesQuestionSnapshotId(CollectionUtils.firstElement(questionLogMap.keySet()));
|
|
|
|
|
ResourcesQuestionSnapshot resourcesQuestionSnapshot = resourcesQuestionSnapshotDao.templateOne(entity);
|
|
|
|
|
|
|
|
|
|
List<TeacherOpenCourseQuestionLog> list = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 不需要判断空,控制类层已经用@NotEmpty判断过了。
|
|
|
|
@ -186,8 +193,7 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
|
|
|
|
|
String answersText = join(answerSet.toArray(), ",");
|
|
|
|
|
// 构建实体
|
|
|
|
|
TeacherOpenCourseQuestionLog questionLog = new TeacherOpenCourseQuestionLog();
|
|
|
|
|
questionLog.setTeacherOpenCourseQuestionLogFromType(fromType);
|
|
|
|
|
questionLog.setTeacherOpenCourseQuestionLogFromId(resourcesQuestionSnapshot.getResourcesQuestionSnapshotFromId());
|
|
|
|
|
questionLog.setTeacherOpenCourseQuestionSettingId(questionSettingId);
|
|
|
|
|
questionLog.setTeacherOpenCourseQuestionLogStatus(1);
|
|
|
|
|
questionLog.setOrgId(student.getOrgId());
|
|
|
|
|
questionLog.setUserId(student.getUserId());
|
|
|
|
@ -212,12 +218,59 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
|
|
|
|
|
insertBatch(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 和题目有关的做题提交方法
|
|
|
|
|
*
|
|
|
|
|
* @param questionLogMap <题目ID, [数组:前端传递过来不需要考虑排序和重复问题]> 例: {"10086": ["D", "A", "B", "A"]}
|
|
|
|
|
* @param questionSettingId 题目配置ID
|
|
|
|
|
*/
|
|
|
|
|
public void insertQuestionLog(
|
|
|
|
|
@NotEmpty(message = "请上传题目快照ID和答案!") Map<Long, TreeSet<String>> questionLogMap,
|
|
|
|
|
@NotNull(message = "开课题目配置ID不能为空!") final Long questionSettingId) {
|
|
|
|
|
|
|
|
|
|
// 查询学生身份
|
|
|
|
|
final Student student = studentDao.getByUserId(getUserId());
|
|
|
|
|
|
|
|
|
|
// 查询符合条件的日志表
|
|
|
|
|
String questionSnapshotIds = join(questionLogMap.keySet().toArray(), ",");
|
|
|
|
|
TeacherOpenCourseQuestionLogQuery teacherOpenCourseQuestionLogQuery = new TeacherOpenCourseQuestionLogQuery();
|
|
|
|
|
teacherOpenCourseQuestionLogQuery.setResourcesQuestionSnapshotIdPlural(questionSnapshotIds);
|
|
|
|
|
teacherOpenCourseQuestionLogQuery.setTeacherOpenCourseQuestionLogStatus(1);
|
|
|
|
|
teacherOpenCourseQuestionLogQuery.setStudentId(student.getStudentId());
|
|
|
|
|
teacherOpenCourseQuestionLogQuery.setTeacherOpenCourseQuestionSettingId(questionSettingId);
|
|
|
|
|
List<TeacherOpenCourseQuestionLog> valuesByQuery = teacherOpenCourseQuestionLogDao.getValuesByQuery(teacherOpenCourseQuestionLogQuery);
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(valuesByQuery, "未查询到题目!");
|
|
|
|
|
// 处理答案和分数
|
|
|
|
|
valuesByQuery.forEach(questionLog -> {
|
|
|
|
|
// 学生提交的答案
|
|
|
|
|
String answersText = join(questionLogMap.get(questionLog.getResourcesQuestionSnapshotId()).toArray(), ",");
|
|
|
|
|
// 包含/字符,代表是路径地址,是附件类型
|
|
|
|
|
if(answersText.contains("/")) {
|
|
|
|
|
questionLog.setTeacherOpenCourseQuestionLogUploadFile(answersText);
|
|
|
|
|
}
|
|
|
|
|
// 否则就是普通选择题的答案
|
|
|
|
|
else {
|
|
|
|
|
questionLog.setTeacherOpenCourseQuestionLogAnswer(answersText);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 是否是正确答案
|
|
|
|
|
Boolean isTrue = (questionLog.getQuestionAnswer() + ",").equals(answersText);
|
|
|
|
|
questionLog.setStudentScore(isTrue ? questionLog.getQuestionScore() : BigDecimal.valueOf(0));
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
updateBatch(valuesByQuery);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取作业
|
|
|
|
|
* @param resourcesQuestionSnapshotFromId 开课作业ID
|
|
|
|
|
*
|
|
|
|
|
* @param teacherOpenCourseQuestionSettingId 开课作业ID
|
|
|
|
|
* @param fromTypeEnum
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<ResourcesQuestionSnapshot> questionDetail(final Long resourcesQuestionSnapshotFromId) {
|
|
|
|
|
public List<ResourcesQuestionSnapshot> questionDetail(@NotNull(message = "题目配置ID不能为空!") final Long teacherOpenCourseQuestionSettingId,
|
|
|
|
|
@NotNull(message = "类型不能为空!") ResourcesQuestionSnapshotFromTypeEnum fromTypeEnum) {
|
|
|
|
|
|
|
|
|
|
// 获取学生ID
|
|
|
|
|
final Student student = studentDao.getByUserId(getUserId());
|
|
|
|
@ -225,47 +278,48 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
|
|
|
|
|
// 常量 True的Integer表现
|
|
|
|
|
final Integer TRUE_CONST = 1;
|
|
|
|
|
List<ResourcesQuestionSnapshot> resourcesQuestionSnapshots = new ArrayList<>();
|
|
|
|
|
TeacherOpenCourseHomework homework = teacherOpenCourseHomeworkService.getInfo(resourcesQuestionSnapshotFromId);
|
|
|
|
|
TeacherOpenCourseQuestionSetting homework = teacherOpenCourseQuestionSettingSettingService.getInfo(teacherOpenCourseQuestionSettingId);
|
|
|
|
|
Assert.notNull(homework, "未查询到来源ID对应的题目!");
|
|
|
|
|
|
|
|
|
|
TeacherOpenCourseHomeworkSettingQuery settingQuery = new TeacherOpenCourseHomeworkSettingQuery();
|
|
|
|
|
settingQuery.setTeacherOpenCourseHomeworkId(resourcesQuestionSnapshotFromId);
|
|
|
|
|
TeacherOpenCourseHomeworkSetting hwSetting = teacherOpenCourseHomeworkSettingService.getInfo(settingQuery);
|
|
|
|
|
TeacherOpenCourseQuestionSettingQuery settingQuery = new TeacherOpenCourseQuestionSettingQuery();
|
|
|
|
|
settingQuery.setTeacherOpenCourseQuestionSettingId(teacherOpenCourseQuestionSettingId);
|
|
|
|
|
TeacherOpenCourseQuestionSetting hwSetting = teacherOpenCourseQuestionSettingSettingService.getInfo(settingQuery);
|
|
|
|
|
|
|
|
|
|
ResourcesQuestionSnapshotQuery questionSnapshotQuery = new ResourcesQuestionSnapshotQuery();
|
|
|
|
|
questionSnapshotQuery.setResourcesQuestionSnapshotFromId(resourcesQuestionSnapshotFromId);
|
|
|
|
|
questionSnapshotQuery.setTeacherOpenCourseQuestionSettingId(teacherOpenCourseQuestionSettingId);
|
|
|
|
|
|
|
|
|
|
// 章节练习,则跳过次数验证
|
|
|
|
|
if (!EnumUtil.contains(fromTypeEnum, CHAPTER_EXERCISE)) {
|
|
|
|
|
// 作答次数
|
|
|
|
|
Integer teacherOpenCourseHomeworkSettingDoCount = hwSetting.getTeacherOpenCourseHomeworkSettingDoCount();
|
|
|
|
|
Assert.isTrue(teacherOpenCourseHomeworkSettingDoCount > 1, "作答次数设置有误,请联系管理员!");
|
|
|
|
|
Integer teacherOpenCourseQuestionSettingSettingDoCount = hwSetting.getTeacherOpenCourseQuestionSettingDoCount();
|
|
|
|
|
Assert.isTrue(teacherOpenCourseQuestionSettingSettingDoCount > 1, "作答次数设置有误,请联系管理员!");
|
|
|
|
|
// 数据库查询该学生已经做过的次数
|
|
|
|
|
TeacherOpenCourseQuestionLogQuery teacherOpenCourseQuestionLogQuery = new TeacherOpenCourseQuestionLogQuery();
|
|
|
|
|
teacherOpenCourseQuestionLogQuery.setStudentId(student.getStudentId());
|
|
|
|
|
// 作业ID
|
|
|
|
|
teacherOpenCourseQuestionLogQuery.setResourcesQuestionSnapshotFromId(resourcesQuestionSnapshotFromId);
|
|
|
|
|
Integer doCount = teacherOpenCourseQuestionLogDao.doCount(teacherOpenCourseQuestionLogQuery);
|
|
|
|
|
// 断言判断最大作答次数
|
|
|
|
|
Assert.isTrue(doCount < teacherOpenCourseHomeworkSettingDoCount, "已超过最大作答次数!");
|
|
|
|
|
Assert.isTrue(doCount < teacherOpenCourseQuestionSettingSettingDoCount, "已超过最大作答次数!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 答卷后显示答案解析
|
|
|
|
|
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseHomeworkSettingEndShowQa())) {
|
|
|
|
|
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseQuestionSettingEndShowQa())) {
|
|
|
|
|
// TODO 逻辑不要在这里写
|
|
|
|
|
/** 实现 {@link TeacherOpenCourseQuestionLogService#questionAnalysis(TreeSet)} */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 答卷后显示答案对错
|
|
|
|
|
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseHomeworkSettingEndShowTrueFalse())) {
|
|
|
|
|
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseQuestionSettingEndShowTrueFalse())) {
|
|
|
|
|
// TODO 逻辑不要在这里写
|
|
|
|
|
/** 实现 {@link TeacherOpenCourseQuestionLogService#questionAnalysis(TreeSet)} */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 题目乱序(同一大题内)
|
|
|
|
|
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseHomeworkSettingQuestionNoOrder())) {
|
|
|
|
|
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseQuestionSettingQuestionNoOrder())) {
|
|
|
|
|
questionSnapshotQuery.setRand(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 选项乱序(限单选、多选)
|
|
|
|
|
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseHomeworkSettingOptionNoOrder())) {
|
|
|
|
|
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseQuestionSettingOptionNoOrder())) {
|
|
|
|
|
resourcesQuestionSnapshots = resourcesQuestionSnapshotDao.getValuesByQuery(questionSnapshotQuery);
|
|
|
|
|
|
|
|
|
|
// 单题选项排序处理
|
|
|
|
@ -276,6 +330,16 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<TeacherOpenCourseQuestionLog> logs = BeanUtil.copyToList(resourcesQuestionSnapshots, TeacherOpenCourseQuestionLog.class);
|
|
|
|
|
|
|
|
|
|
// 设计个单表,后面进行修改操作
|
|
|
|
|
logs.forEach(logPo -> {
|
|
|
|
|
logPo.setTeacherOpenCourseQuestionSettingId(teacherOpenCourseQuestionSettingId);
|
|
|
|
|
logPo.setTeacherOpenCourseQuestionLogStatus(1);
|
|
|
|
|
logPo.setStudentId(student.getStudentId());
|
|
|
|
|
logPo.setTeacherOpenCourseQuestionLogAddTime(new Date());
|
|
|
|
|
});
|
|
|
|
|
insertBatch(logs);
|
|
|
|
|
return resourcesQuestionSnapshots;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -291,15 +355,15 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(questionSnapshots, "未查询到题目列表!");
|
|
|
|
|
|
|
|
|
|
TeacherOpenCourseHomeworkSettingQuery settingQuery = new TeacherOpenCourseHomeworkSettingQuery();
|
|
|
|
|
settingQuery.setTeacherOpenCourseHomeworkId(questionSnapshots.get(0).getResourcesQuestionSnapshotFromId());
|
|
|
|
|
TeacherOpenCourseQuestionSettingQuery settingQuery = new TeacherOpenCourseQuestionSettingQuery();
|
|
|
|
|
settingQuery.setTeacherOpenCourseQuestionSettingId(questionSnapshots.get(0).getTeacherOpenCourseQuestionSettingId());
|
|
|
|
|
@Nullable
|
|
|
|
|
final TeacherOpenCourseHomeworkSetting hwSetting = teacherOpenCourseHomeworkSettingService.getInfo(settingQuery);
|
|
|
|
|
final TeacherOpenCourseQuestionSetting hwSetting = teacherOpenCourseQuestionSettingSettingService.getInfo(settingQuery);
|
|
|
|
|
|
|
|
|
|
// 答卷后显示答案解析
|
|
|
|
|
final Boolean isEndShowQa = BooleanUtil.toBoolean(String.valueOf(hwSetting.getTeacherOpenCourseHomeworkSettingEndShowQa()));
|
|
|
|
|
final Boolean isEndShowQa = BooleanUtil.toBoolean(String.valueOf(hwSetting.getTeacherOpenCourseQuestionSettingEndShowQa()));
|
|
|
|
|
// 答卷后显示答案对错
|
|
|
|
|
final Boolean isEndShowTrueFalse = BooleanUtil.toBoolean(String.valueOf(hwSetting.getTeacherOpenCourseHomeworkSettingEndShowTrueFalse()));
|
|
|
|
|
final Boolean isEndShowTrueFalse = BooleanUtil.toBoolean(String.valueOf(hwSetting.getTeacherOpenCourseQuestionSettingEndShowTrueFalse()));
|
|
|
|
|
|
|
|
|
|
return questionSnapshots.stream().map(item -> {
|
|
|
|
|
ResourcesQuestionSnapshot resourcesQuestionSnapshot = new ResourcesQuestionSnapshot();
|
|
|
|
|