|
|
|
@ -17,6 +17,8 @@ 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.dto.QuestionLogAddDTO;
|
|
|
|
|
import com.ibeetl.jlw.enums.QuestionLogAddTypeEnum;
|
|
|
|
|
import com.ibeetl.jlw.web.query.TeacherOpenCourseQuestionLogQuery;
|
|
|
|
|
import com.ibeetl.jlw.web.query.TeacherOpenCourseQuestionSettingQuery;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
@ -42,6 +44,7 @@ import static cn.hutool.core.date.DateUnit.MINUTE;
|
|
|
|
|
import static cn.hutool.core.util.ArrayUtil.join;
|
|
|
|
|
import static cn.jlw.util.CacheUserUtil.getStudent;
|
|
|
|
|
import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUserId;
|
|
|
|
|
import static com.ibeetl.jlw.enums.QuestionLogAddTypeEnum.FINALLY_SUBMIT;
|
|
|
|
|
import static com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum.EXAM;
|
|
|
|
|
import static java.util.stream.Collectors.groupingBy;
|
|
|
|
|
|
|
|
|
@ -275,12 +278,12 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
|
|
|
|
|
* 和题目有关的做题提交方法
|
|
|
|
|
* 直接计算出学生得分情况
|
|
|
|
|
*
|
|
|
|
|
* @param questionLogMap <题目ID, [数组:前端传递过来不需要考虑排序和重复问题]> 例: {"10086": ["D", "A", "B", "A"]}
|
|
|
|
|
* @param questionSettingId 题目配置ID
|
|
|
|
|
* @param questionLogAddDTO 题目信息
|
|
|
|
|
*/
|
|
|
|
|
public void insertQuestionLog(
|
|
|
|
|
@NotEmpty(message = "请上传题目快照ID和答案!") Map<String, TreeSet<String>> questionLogMap,
|
|
|
|
|
@NotNull(message = "开课题目配置ID不能为空!") final Long questionSettingId) {
|
|
|
|
|
public void insertQuestionLog(@NotNull(message = "提交题目信息不能为空") QuestionLogAddDTO questionLogAddDTO) {
|
|
|
|
|
|
|
|
|
|
Long questionSettingId = questionLogAddDTO.getQuestionSettingId();
|
|
|
|
|
Map<String, TreeSet<String>> questionLogMap = questionLogAddDTO.getQuestionLogMap();
|
|
|
|
|
|
|
|
|
|
// 查询学生身份
|
|
|
|
|
final Student student = getStudent();
|
|
|
|
@ -289,7 +292,7 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
|
|
|
|
|
TeacherOpenCourseQuestionSetting info = teacherOpenCourseQuestionSettingService.getInfo(questionSettingId);
|
|
|
|
|
Assert.notNull(info, "题目配置ID有误!");
|
|
|
|
|
|
|
|
|
|
// 校验时间
|
|
|
|
|
// 校验当前时间是否在考试的时间段
|
|
|
|
|
teacherOpenCourseQuestionSettingService.verifyQuestionStartAndEndTimeWithNowTimeThrow(questionSettingId);
|
|
|
|
|
|
|
|
|
|
switch(info.getTeacherOpenCourseQuestionSettingType()) {
|
|
|
|
@ -301,7 +304,7 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
|
|
|
|
|
case CHAPTER_EXERCISE:
|
|
|
|
|
case EXAM:
|
|
|
|
|
case HOMEWORK_QUESTION:{
|
|
|
|
|
addQuestionRelatedLog(questionLogMap, questionSettingId, student);
|
|
|
|
|
addQuestionRelatedLog(questionLogAddDTO, student);
|
|
|
|
|
} break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -320,6 +323,8 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
|
|
|
|
|
query.setTeacherOpenCourseQuestionSettingId(questionSettingId);
|
|
|
|
|
query.setTeacherOpenCourseQuestionLogUpdateTime(new Date());
|
|
|
|
|
query.setTeacherOpenCourseQuestionLogStatus(1);
|
|
|
|
|
// 附件作业,只有一题,所有默认是全部提交的方式
|
|
|
|
|
query.setQuestionLogAddType(FINALLY_SUBMIT);
|
|
|
|
|
query.setOrgId(student.getOrgId());
|
|
|
|
|
query.setUserId(student.getUserId());
|
|
|
|
|
query.setStudentId(student.getStudentId());
|
|
|
|
@ -330,11 +335,17 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
|
|
|
|
|
* 跟题目相关的题目日志提交方法
|
|
|
|
|
* 附件类型的需要单独,拆分除去
|
|
|
|
|
*
|
|
|
|
|
* @param questionLogMap
|
|
|
|
|
* @param questionSettingId
|
|
|
|
|
* @param student
|
|
|
|
|
* @param questionLogAddDTO 题目信息
|
|
|
|
|
* @param student 学生信息
|
|
|
|
|
*/
|
|
|
|
|
private void addQuestionRelatedLog(Map<String, TreeSet<String>> questionLogMap, Long questionSettingId, Student student) {
|
|
|
|
|
private void addQuestionRelatedLog(@NotNull(message = "提交题目信息不能为空") QuestionLogAddDTO questionLogAddDTO, final Student student) {
|
|
|
|
|
|
|
|
|
|
// 参数获取
|
|
|
|
|
QuestionLogAddTypeEnum addType = questionLogAddDTO.getQuestionLogAddType();
|
|
|
|
|
Date addTime = questionLogAddDTO.getAddTime(); Long studentId = student.getStudentId();
|
|
|
|
|
Long questionSettingId = questionLogAddDTO.getQuestionSettingId();
|
|
|
|
|
Map<String, TreeSet<String>> questionLogMap = questionLogAddDTO.getQuestionLogMap();
|
|
|
|
|
|
|
|
|
|
// 查询符合条件的日志表
|
|
|
|
|
String questionSnapshotIds = join(questionLogMap.keySet().toArray(), ",");
|
|
|
|
|
|
|
|
|
@ -350,33 +361,55 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(logList, "未查询到题目信息!");
|
|
|
|
|
|
|
|
|
|
// 当前时间
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
// 当前时间, 存储要更新的题目日志集合
|
|
|
|
|
Date now = new Date(); List<TeacherOpenCourseQuestionLog> updateList = new ArrayList<>();
|
|
|
|
|
// 处理答案和分数
|
|
|
|
|
logList.forEach(questionLog -> {
|
|
|
|
|
// 这里判断题目只允许做一次,禁止二次提交
|
|
|
|
|
Assert.isNull(questionLog.getTeacherOpenCourseQuestionLogUpdateTime(),
|
|
|
|
|
"题目名称:{} 题目禁止重复提交!", questionLog.getQuestionStem());
|
|
|
|
|
|
|
|
|
|
// 验证最新的提交时间,防止网络延迟
|
|
|
|
|
if (!validateQuestionLogAddTimeLatest(questionSettingId, questionLog.getResourcesQuestionSnapshotId().toString(), studentId, addTime)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Assert.isTrue(!questionLog.getQuestionLogAddType().equals(addType), "无法再次提交答案,题目已完成!");
|
|
|
|
|
// 学生提交的答案
|
|
|
|
|
String answersText = join(questionLogMap.get(questionLog.getResourcesQuestionSnapshotId()).toArray(), ",");
|
|
|
|
|
questionLog.setTeacherOpenCourseQuestionLogAnswer(answersText);
|
|
|
|
|
|
|
|
|
|
// 是否是正确答案
|
|
|
|
|
Boolean isCorrectAnswer = questionLog.getQuestionAnswer().equalsIgnoreCase(answersText);
|
|
|
|
|
// 完成时间
|
|
|
|
|
long finishTime = DateUtil.between(questionLog.getTeacherOpenCourseQuestionLogAddTime(), now, MINUTE);
|
|
|
|
|
|
|
|
|
|
// 填充属性
|
|
|
|
|
questionLog.setTeacherOpenCourseQuestionLogAnswer(answersText);
|
|
|
|
|
// 计算该题目学生的得分情况
|
|
|
|
|
questionLog.setStudentScore(isCorrectAnswer ? questionLog.getQuestionScore() : BigDecimal.valueOf(0));
|
|
|
|
|
questionLog.setTeacherOpenCourseQuestionLogUpdateTime(now);
|
|
|
|
|
long finishTime = DateUtil.between(questionLog.getTeacherOpenCourseQuestionLogAddTime(), now, MINUTE);
|
|
|
|
|
questionLog.setTeacherOpenCourseQuestionLogFinishTime(finishTime);
|
|
|
|
|
questionLog.setQuestionLogAddType(addType);
|
|
|
|
|
|
|
|
|
|
// 只添加可以更新的数据
|
|
|
|
|
updateList.add(questionLog);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 批量插入错题集(错题库),方法内部自带分数判断。内部方法更新log中的错题标记。
|
|
|
|
|
teacherOpenCourseQuestionLogWrongService.insertBatchByQuestionLogList(logList);
|
|
|
|
|
|
|
|
|
|
// 学生做的题目的答案与日志关联
|
|
|
|
|
updateBatchTemplate(logList);
|
|
|
|
|
updateBatchTemplate(updateList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 验证前端传递过来的添加时间是否是最新的
|
|
|
|
|
* @param questionSettingId 题目配置ID
|
|
|
|
|
* @param questionSnapshotIds 题目快照ID
|
|
|
|
|
* @param studentId 学生ID
|
|
|
|
|
* @param addTime 前端传递的添加时间
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private boolean validateQuestionLogAddTimeLatest(@NotNull(message = "开课题目配置ID不能为空!") Long questionSettingId,
|
|
|
|
|
@NotBlank(message = "题目快照IDs不能为空!") String questionSnapshotIds,
|
|
|
|
|
@NotNull(message = "学生ID不能为空!") Long studentId,
|
|
|
|
|
@NotNull(message = "提交时间不能为空!") Date addTime) {
|
|
|
|
|
return teacherOpenCourseQuestionLogDao.validateQuestionLogAddTimeLatest(questionSettingId, questionSnapshotIds, studentId, addTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|