题目相关

beetlsql3-dev
Mlxa0324 2 years ago
parent 7f73af4dab
commit 82fd563308

@ -0,0 +1,26 @@
package com.ibeetl.admin.core.util.beetl;
import org.beetl.core.Context;
import org.beetl.core.Function;
import org.springframework.stereotype.Component;
/**
*
*/
@Component
public class EqualsIgnoreCaseFunction implements Function {
@Override
public Object call(Object[] objects, Context context) {
try{
if(objects != null && objects.length == 2){
String left = objects[0].toString();
String right = objects[1].toString();
return left.equalsIgnoreCase(right);
}
}catch (Exception e){
e.printStackTrace();
}
return false;
}
}

@ -1,7 +1,9 @@
package com.ibeetl.jlw.service; package com.ibeetl.jlw.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.BooleanUtil;
import cn.jlw.util.EnumUtil;
import cn.jlw.util.ToolUtils; import cn.jlw.util.ToolUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; 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.ResourcesQuestionSnapshotDao;
import com.ibeetl.jlw.dao.StudentDao; import com.ibeetl.jlw.dao.StudentDao;
import com.ibeetl.jlw.dao.TeacherOpenCourseQuestionLogDao; 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.enums.ResourcesQuestionSnapshotFromTypeEnum;
import com.ibeetl.jlw.web.query.ResourcesQuestionSnapshotQuery; 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.TeacherOpenCourseQuestionLogQuery;
import com.ibeetl.jlw.web.query.TeacherOpenCourseQuestionSettingQuery;
import com.sun.istack.internal.Nullable; import com.sun.istack.internal.Nullable;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
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.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
import static cn.hutool.core.util.ArrayUtil.join; import static cn.hutool.core.util.ArrayUtil.join;
import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUserId; import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUserId;
import static com.ibeetl.jlw.entity.ResourcesQuestionOptionEntity.shuffleOrderOptions; import static com.ibeetl.jlw.entity.ResourcesQuestionOptionEntity.shuffleOrderOptions;
import static com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum.CHAPTER_EXERCISE;
import static java.util.stream.Collectors.groupingBy; import static java.util.stream.Collectors.groupingBy;
/** /**
@ -41,13 +49,13 @@ import static java.util.stream.Collectors.groupingBy;
@Service @Service
@Transactional @Transactional
@Validated
public class TeacherOpenCourseQuestionLogService extends CoreBaseService<TeacherOpenCourseQuestionLog>{ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<TeacherOpenCourseQuestionLog>{
@Resource private TeacherOpenCourseQuestionLogDao teacherOpenCourseQuestionLogDao; @Resource private TeacherOpenCourseQuestionLogDao teacherOpenCourseQuestionLogDao;
@Resource private StudentDao studentDao; @Resource private StudentDao studentDao;
@Resource private ResourcesQuestionSnapshotDao resourcesQuestionSnapshotDao; @Resource private ResourcesQuestionSnapshotDao resourcesQuestionSnapshotDao;
@Resource private TeacherOpenCourseHomeworkService teacherOpenCourseHomeworkService; @Resource private TeacherOpenCourseQuestionSettingService teacherOpenCourseQuestionSettingSettingService;
@Resource private TeacherOpenCourseHomeworkSettingService teacherOpenCourseHomeworkSettingService;
public PageQuery<TeacherOpenCourseQuestionLog>queryByCondition(PageQuery query){ public PageQuery<TeacherOpenCourseQuestionLog>queryByCondition(PageQuery query){
PageQuery ret = teacherOpenCourseQuestionLogDao.queryByCondition(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 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()); 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<>(); List<TeacherOpenCourseQuestionLog> list = new ArrayList<>();
// 不需要判断空,控制类层已经用@NotEmpty判断过了。 // 不需要判断空,控制类层已经用@NotEmpty判断过了。
@ -186,8 +193,7 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
String answersText = join(answerSet.toArray(), ","); String answersText = join(answerSet.toArray(), ",");
// 构建实体 // 构建实体
TeacherOpenCourseQuestionLog questionLog = new TeacherOpenCourseQuestionLog(); TeacherOpenCourseQuestionLog questionLog = new TeacherOpenCourseQuestionLog();
questionLog.setTeacherOpenCourseQuestionLogFromType(fromType); questionLog.setTeacherOpenCourseQuestionSettingId(questionSettingId);
questionLog.setTeacherOpenCourseQuestionLogFromId(resourcesQuestionSnapshot.getResourcesQuestionSnapshotFromId());
questionLog.setTeacherOpenCourseQuestionLogStatus(1); questionLog.setTeacherOpenCourseQuestionLogStatus(1);
questionLog.setOrgId(student.getOrgId()); questionLog.setOrgId(student.getOrgId());
questionLog.setUserId(student.getUserId()); questionLog.setUserId(student.getUserId());
@ -212,12 +218,59 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
insertBatch(list); 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 * @return
*/ */
public List<ResourcesQuestionSnapshot> questionDetail(final Long resourcesQuestionSnapshotFromId) { public List<ResourcesQuestionSnapshot> questionDetail(@NotNull(message = "题目配置ID不能为空") final Long teacherOpenCourseQuestionSettingId,
@NotNull(message = "类型不能为空!") ResourcesQuestionSnapshotFromTypeEnum fromTypeEnum) {
// 获取学生ID // 获取学生ID
final Student student = studentDao.getByUserId(getUserId()); final Student student = studentDao.getByUserId(getUserId());
@ -225,47 +278,48 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
// 常量 True的Integer表现 // 常量 True的Integer表现
final Integer TRUE_CONST = 1; final Integer TRUE_CONST = 1;
List<ResourcesQuestionSnapshot> resourcesQuestionSnapshots = new ArrayList<>(); List<ResourcesQuestionSnapshot> resourcesQuestionSnapshots = new ArrayList<>();
TeacherOpenCourseHomework homework = teacherOpenCourseHomeworkService.getInfo(resourcesQuestionSnapshotFromId); TeacherOpenCourseQuestionSetting homework = teacherOpenCourseQuestionSettingSettingService.getInfo(teacherOpenCourseQuestionSettingId);
Assert.notNull(homework, "未查询到来源ID对应的题目"); Assert.notNull(homework, "未查询到来源ID对应的题目");
TeacherOpenCourseHomeworkSettingQuery settingQuery = new TeacherOpenCourseHomeworkSettingQuery(); TeacherOpenCourseQuestionSettingQuery settingQuery = new TeacherOpenCourseQuestionSettingQuery();
settingQuery.setTeacherOpenCourseHomeworkId(resourcesQuestionSnapshotFromId); settingQuery.setTeacherOpenCourseQuestionSettingId(teacherOpenCourseQuestionSettingId);
TeacherOpenCourseHomeworkSetting hwSetting = teacherOpenCourseHomeworkSettingService.getInfo(settingQuery); TeacherOpenCourseQuestionSetting hwSetting = teacherOpenCourseQuestionSettingSettingService.getInfo(settingQuery);
ResourcesQuestionSnapshotQuery questionSnapshotQuery = new ResourcesQuestionSnapshotQuery(); ResourcesQuestionSnapshotQuery questionSnapshotQuery = new ResourcesQuestionSnapshotQuery();
questionSnapshotQuery.setResourcesQuestionSnapshotFromId(resourcesQuestionSnapshotFromId); questionSnapshotQuery.setTeacherOpenCourseQuestionSettingId(teacherOpenCourseQuestionSettingId);
// 作答次数 // 章节练习,则跳过次数验证
Integer teacherOpenCourseHomeworkSettingDoCount = hwSetting.getTeacherOpenCourseHomeworkSettingDoCount(); if (!EnumUtil.contains(fromTypeEnum, CHAPTER_EXERCISE)) {
Assert.isTrue(teacherOpenCourseHomeworkSettingDoCount > 1, "作答次数设置有误,请联系管理员!"); // 作答次数
// 数据库查询该学生已经做过的次数 Integer teacherOpenCourseQuestionSettingSettingDoCount = hwSetting.getTeacherOpenCourseQuestionSettingDoCount();
TeacherOpenCourseQuestionLogQuery teacherOpenCourseQuestionLogQuery = new TeacherOpenCourseQuestionLogQuery(); Assert.isTrue(teacherOpenCourseQuestionSettingSettingDoCount > 1, "作答次数设置有误,请联系管理员!");
teacherOpenCourseQuestionLogQuery.setStudentId(student.getStudentId()); // 数据库查询该学生已经做过的次数
// 作业ID TeacherOpenCourseQuestionLogQuery teacherOpenCourseQuestionLogQuery = new TeacherOpenCourseQuestionLogQuery();
teacherOpenCourseQuestionLogQuery.setResourcesQuestionSnapshotFromId(resourcesQuestionSnapshotFromId); teacherOpenCourseQuestionLogQuery.setStudentId(student.getStudentId());
Integer doCount = teacherOpenCourseQuestionLogDao.doCount(teacherOpenCourseQuestionLogQuery); 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 逻辑不要在这里写 // TODO 逻辑不要在这里写
/** 实现 {@link TeacherOpenCourseQuestionLogService#questionAnalysis(TreeSet)} */ /** 实现 {@link TeacherOpenCourseQuestionLogService#questionAnalysis(TreeSet)} */
} }
// 答卷后显示答案对错 // 答卷后显示答案对错
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseHomeworkSettingEndShowTrueFalse())) { if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseQuestionSettingEndShowTrueFalse())) {
// TODO 逻辑不要在这里写 // TODO 逻辑不要在这里写
/** 实现 {@link TeacherOpenCourseQuestionLogService#questionAnalysis(TreeSet)} */ /** 实现 {@link TeacherOpenCourseQuestionLogService#questionAnalysis(TreeSet)} */
} }
// 题目乱序(同一大题内) // 题目乱序(同一大题内)
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseHomeworkSettingQuestionNoOrder())) { if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseQuestionSettingQuestionNoOrder())) {
questionSnapshotQuery.setRand(true); questionSnapshotQuery.setRand(true);
} }
// 选项乱序(限单选、多选) // 选项乱序(限单选、多选)
if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseHomeworkSettingOptionNoOrder())) { if (TRUE_CONST.equals(hwSetting.getTeacherOpenCourseQuestionSettingOptionNoOrder())) {
resourcesQuestionSnapshots = resourcesQuestionSnapshotDao.getValuesByQuery(questionSnapshotQuery); 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; return resourcesQuestionSnapshots;
} }
@ -291,15 +355,15 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
Assert.notEmpty(questionSnapshots, "未查询到题目列表!"); Assert.notEmpty(questionSnapshots, "未查询到题目列表!");
TeacherOpenCourseHomeworkSettingQuery settingQuery = new TeacherOpenCourseHomeworkSettingQuery(); TeacherOpenCourseQuestionSettingQuery settingQuery = new TeacherOpenCourseQuestionSettingQuery();
settingQuery.setTeacherOpenCourseHomeworkId(questionSnapshots.get(0).getResourcesQuestionSnapshotFromId()); settingQuery.setTeacherOpenCourseQuestionSettingId(questionSnapshots.get(0).getTeacherOpenCourseQuestionSettingId());
@Nullable @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 -> { return questionSnapshots.stream().map(item -> {
ResourcesQuestionSnapshot resourcesQuestionSnapshot = new ResourcesQuestionSnapshot(); ResourcesQuestionSnapshot resourcesQuestionSnapshot = new ResourcesQuestionSnapshot();

Loading…
Cancel
Save