考核评估-我的考试 生成考试题和查看考试进行排序

This commit is contained in:
xusd 2024-05-11 11:17:24 +08:00
parent fc9688e687
commit 8092599fbd
10 changed files with 136 additions and 48 deletions

View File

@ -36,4 +36,9 @@ public class ExamPaperQuestion {
@Excel(name = "考生答案")
private String examineAnswer;
/**
* 排序
*/
private Integer sorted;
}

View File

@ -68,4 +68,9 @@ public class ExamQuestionBank extends BaseEntity {
*/
@Excel(name = "状态", dictType = "sys_normal_disable")
private String status;
/**
* 排序
*/
private Integer sorted;
}

View File

@ -3,6 +3,7 @@ package com.inspur.examine.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@ -41,7 +42,7 @@ public class SubmitExamDTO {
/**
* 答案
*/
@NotEmpty
@Valid
private List<SubmitExamPaperQuestionDTO> answerList;
}

View File

@ -78,4 +78,13 @@ public interface ExamPaperQuestionMapper
* @Date 11:33 2024/5/10
*/
void batchUpdatePaperQuestion(@Param("answerList") List<SubmitExamPaperQuestionDTO> answerList);
/**
* 根据考试id批量设置作答是否正确
*
* @param paperId 考试id
* @Author xusd
* @Date 10:22 2024/5/11
*/
void updateIsSureByPaperId(String paperId);
}

View File

@ -77,4 +77,13 @@ public interface IExamPaperQuestionService
* @Date 11:33 2024/5/10
*/
void batchUpdatePaperQuestion(List<SubmitExamPaperQuestionDTO> answerList);
/**
* 根据考试id批量设置作答是否正确
*
* @param paperId 考试id
* @Author xusd
* @Date 10:22 2024/5/11
*/
void updateIsSureByPaperId(String paperId);
}

View File

@ -116,4 +116,16 @@ public class ExamPaperQuestionServiceImpl implements IExamPaperQuestionService
public void batchUpdatePaperQuestion(List<SubmitExamPaperQuestionDTO> answerList) {
examPaperQuestionMapper.batchUpdatePaperQuestion(answerList);
}
/**
* 根据考试id批量设置作答是否正确
*
* @param paperId 考试id
* @Author xusd
* @Date 10:22 2024/5/11
*/
@Override
public void updateIsSureByPaperId(String paperId) {
examPaperQuestionMapper.updateIsSureByPaperId(paperId);
}
}

View File

@ -144,6 +144,7 @@ public class MyExamineServiceImpl implements IMyExamineService {
paperQuestion.setId(IdUtils.fastSimpleUUID());
paperQuestion.setPaperId(examPaperInfoId);
paperQuestion.setQuestionId(item.getId());
paperQuestion.setSorted(item.getSorted());
paperQuestionList.add(paperQuestion);
});
//批量新增
@ -164,15 +165,25 @@ public class MyExamineServiceImpl implements IMyExamineService {
*/
private List<ExamQuestionBank> createRandoms(List<ExamQuestionBank> source, int n) {
Map<Integer,String> map = new HashMap<>();
int i = 0;
List<ExamQuestionBank> news = new ArrayList<>();
if (source.size() == n){
if (StringUtils.isNotEmpty(source)){
for (ExamQuestionBank item : source) {
i++;
item.setSorted(i);
}
}
return source;
}else {
while (map.size() < n){
int random = (int) (Math.random() * source.size());
if (!map.containsKey(random)){
map.put(random,"");
news.add(source.get(random));
i++;
ExamQuestionBank examQuestionBank = source.get(random);
examQuestionBank.setSorted(i);
news.add(examQuestionBank);
}
}
return news;
@ -215,18 +226,45 @@ public class MyExamineServiceImpl implements IMyExamineService {
}
//考试题
List<MyExamPaperQuestionVO> allPaperQuestionList = myExamineMapper.selectHistoryPaperQuestionNoAnswerListByPaperId(id);
assembleQuestionList(allPaperQuestionList, myExam);
return myExam;
}
/**
* 组装考试题并排序
*
* @Author xusd
* @Date 9:50 2024/5/11
* @param allPaperQuestionList 考试题
* @param myExam 考试信息
*/
private static void assembleQuestionList(List<MyExamPaperQuestionVO> allPaperQuestionList, MyExamVO myExam) {
if (StringUtils.isEmpty(allPaperQuestionList)){
throw new ServiceException("未查询到考试题目");
}
//试题类型 0 单选1 多选2 判断
Map<String, List<MyExamPaperQuestionVO>> allPaperQuestionMap = allPaperQuestionList.stream().collect(Collectors.groupingBy(MyExamPaperQuestionVO::getQuestionType));
//单选
myExam.setSingleChoiceList(allPaperQuestionMap.get("0"));
List<MyExamPaperQuestionVO> singleChoiceList = allPaperQuestionMap.get("0");
if (StringUtils.isNotEmpty(singleChoiceList)){
//排序
List<MyExamPaperQuestionVO> collect = singleChoiceList.stream().sorted(Comparator.comparingInt(MyExamPaperQuestionVO::getSorted)).collect(Collectors.toList());
myExam.setSingleChoiceList(collect);
}
//多选
myExam.setMultiChoiceList(allPaperQuestionMap.get("1"));
List<MyExamPaperQuestionVO> multiChoiceList = allPaperQuestionMap.get("1");
if (StringUtils.isNotEmpty(multiChoiceList)){
//排序
List<MyExamPaperQuestionVO> collect = multiChoiceList.stream().sorted(Comparator.comparingInt(MyExamPaperQuestionVO::getSorted)).collect(Collectors.toList());
myExam.setMultiChoiceList(collect);
}
//判断
myExam.setJudgeList(allPaperQuestionMap.get("2"));
return myExam;
List<MyExamPaperQuestionVO> judgeList = allPaperQuestionMap.get("2");
if (StringUtils.isNotEmpty(judgeList)){
//排序
List<MyExamPaperQuestionVO> collect = judgeList.stream().sorted(Comparator.comparingInt(MyExamPaperQuestionVO::getSorted)).collect(Collectors.toList());
myExam.setJudgeList(collect);
}
}
/**
@ -250,17 +288,7 @@ public class MyExamineServiceImpl implements IMyExamineService {
}
//考试题
List<MyExamPaperQuestionVO> allPaperQuestionList = myExamineMapper.selectPaperQuestionNoAnswerListByPaperId(id);
if (StringUtils.isEmpty(allPaperQuestionList)){
throw new ServiceException("未查询到考试题目");
}
//试题类型 0 单选1 多选2 判断
Map<String, List<MyExamPaperQuestionVO>> allPaperQuestionMap = allPaperQuestionList.stream().collect(Collectors.groupingBy(MyExamPaperQuestionVO::getQuestionType));
//单选
myExam.setSingleChoiceList(allPaperQuestionMap.get("0"));
//多选
myExam.setMultiChoiceList(allPaperQuestionMap.get("1"));
//判断
myExam.setJudgeList(allPaperQuestionMap.get("2"));
assembleQuestionList(allPaperQuestionList,myExam);
return myExam;
}
@ -284,16 +312,11 @@ public class MyExamineServiceImpl implements IMyExamineService {
if (Objects.isNull(examInfo)){
throw new ServiceException("未查询到考试信息");
}
//计算成绩
//考生答案
List<SubmitExamPaperQuestionDTO> userAnswerList = submitExamDTO.getAnswerList();
//正确答案
List<CorrectAnswerDTO> correctAnswerList = myExamineMapper.selectPaperQuestionHaveAnswerListByPaperId(submitExamDTO.getPaperId());
if (StringUtils.isEmpty(correctAnswerList)){
throw new ServiceException("未查询到考试试题信息");
}
//判断答案是否正确未作答也是回答错误
Map<String, CorrectAnswerDTO> correctAnswerMap = correctAnswerList.stream().collect(Collectors.toMap(CorrectAnswerDTO::getId, item->item));
//考试关联证书
String attestationId = examInfo.getAttestationId();
//通过分数
@ -310,6 +333,14 @@ public class MyExamineServiceImpl implements IMyExamineService {
int multipleChoice = 0;
//判断题回答正确数量
int judge = 0;
//考生分数
BigDecimal score;
//计算成绩
//考生答案
List<SubmitExamPaperQuestionDTO> userAnswerList = submitExamDTO.getAnswerList();
if (StringUtils.isNotEmpty(userAnswerList)){
//判断答案是否正确未作答也是回答错误
Map<String, CorrectAnswerDTO> correctAnswerMap = correctAnswerList.stream().collect(Collectors.toMap(CorrectAnswerDTO::getId, item->item));
for (SubmitExamPaperQuestionDTO item : userAnswerList) {
//是否正确 0正确1错误
//试题类型 0 单选1 多选2 判断
@ -336,9 +367,14 @@ public class MyExamineServiceImpl implements IMyExamineService {
}
}
//考生分数
BigDecimal score = (singleChoiceScore.multiply(new BigDecimal(singleChoice))).add(multipleChoiceScore.multiply(new BigDecimal(multipleChoice))).add(judgeScore.multiply(new BigDecimal(judge)));
score = (singleChoiceScore.multiply(new BigDecimal(singleChoice))).add(multipleChoiceScore.multiply(new BigDecimal(multipleChoice))).add(judgeScore.multiply(new BigDecimal(judge)));
//批量设置答案和是否答对
examPaperQuestionService.batchUpdatePaperQuestion(userAnswerList);
}else {
score = BigDecimal.ZERO;
//无任何作答时设置全部为回答错误
examPaperQuestionService.updateIsSureByPaperId(submitExamDTO.getPaperId());
}
ExamPaperInfo examPaperInfo = new ExamPaperInfo();
examPaperInfo.setId(submitExamDTO.getPaperId());
examPaperInfo.setScore(score);

View File

@ -52,4 +52,9 @@ public class MyExamPaperQuestionVO {
*/
private String isSure;
/**
* 排序
*/
private Integer sorted;
}

View File

@ -46,10 +46,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</insert>
<insert id="batchInsertPaperQuestion">
insert into exam_paper_question(id,paper_id,question_id)
insert into exam_paper_question(id,paper_id,question_id,sorted)
values
<foreach collection="paperQuestionList" index="index" item="item" separator=",">
(#{item.id},#{item.paperId},#{item.questionId})
(#{item.id},#{item.paperId},#{item.questionId},#{item.sorted})
</foreach>
</insert>
@ -84,6 +84,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</update>
<update id="updateIsSureByPaperId">
update exam_paper_question set is_sure = '1' where paper_id = #{paperId}
</update>
<delete id="deleteExamPaperQuestionById" parameterType="String">
delete from exam_paper_question where id = #{id}
</delete>

View File

@ -187,6 +187,7 @@
<select id="selectPaperQuestionNoAnswerListByPaperId" resultType="com.inspur.examine.vo.MyExamPaperQuestionVO">
SELECT
epq.id,
epq.sorted,
eqb.question_type as questionType,
eqb.question_title as questionTitle,
eqb.question_options as questionOptions
@ -233,6 +234,7 @@
resultType="com.inspur.examine.vo.MyExamPaperQuestionVO">
SELECT
epq.id,
epq.sorted,
epq.examine_answer AS examineAnswer,
epq.is_sure AS isSure,
eqb.question_type AS questionType,