考核评估-我的考试 生成考试题和查看考试进行排序
This commit is contained in:
parent
fc9688e687
commit
8092599fbd
@ -36,4 +36,9 @@ public class ExamPaperQuestion {
|
|||||||
@Excel(name = "考生答案")
|
@Excel(name = "考生答案")
|
||||||
private String examineAnswer;
|
private String examineAnswer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private Integer sorted;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,4 +68,9 @@ public class ExamQuestionBank extends BaseEntity {
|
|||||||
*/
|
*/
|
||||||
@Excel(name = "状态", dictType = "sys_normal_disable")
|
@Excel(name = "状态", dictType = "sys_normal_disable")
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private Integer sorted;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.inspur.examine.dto;
|
|||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
@ -41,7 +42,7 @@ public class SubmitExamDTO {
|
|||||||
/**
|
/**
|
||||||
* 答案
|
* 答案
|
||||||
*/
|
*/
|
||||||
@NotEmpty
|
@Valid
|
||||||
private List<SubmitExamPaperQuestionDTO> answerList;
|
private List<SubmitExamPaperQuestionDTO> answerList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -78,4 +78,13 @@ public interface ExamPaperQuestionMapper
|
|||||||
* @Date 11:33 2024/5/10
|
* @Date 11:33 2024/5/10
|
||||||
*/
|
*/
|
||||||
void batchUpdatePaperQuestion(@Param("answerList") List<SubmitExamPaperQuestionDTO> answerList);
|
void batchUpdatePaperQuestion(@Param("answerList") List<SubmitExamPaperQuestionDTO> answerList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据考试id批量设置作答是否正确
|
||||||
|
*
|
||||||
|
* @param paperId 考试id
|
||||||
|
* @Author xusd
|
||||||
|
* @Date 10:22 2024/5/11
|
||||||
|
*/
|
||||||
|
void updateIsSureByPaperId(String paperId);
|
||||||
}
|
}
|
||||||
|
@ -77,4 +77,13 @@ public interface IExamPaperQuestionService
|
|||||||
* @Date 11:33 2024/5/10
|
* @Date 11:33 2024/5/10
|
||||||
*/
|
*/
|
||||||
void batchUpdatePaperQuestion(List<SubmitExamPaperQuestionDTO> answerList);
|
void batchUpdatePaperQuestion(List<SubmitExamPaperQuestionDTO> answerList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据考试id批量设置作答是否正确
|
||||||
|
*
|
||||||
|
* @param paperId 考试id
|
||||||
|
* @Author xusd
|
||||||
|
* @Date 10:22 2024/5/11
|
||||||
|
*/
|
||||||
|
void updateIsSureByPaperId(String paperId);
|
||||||
}
|
}
|
||||||
|
@ -116,4 +116,16 @@ public class ExamPaperQuestionServiceImpl implements IExamPaperQuestionService
|
|||||||
public void batchUpdatePaperQuestion(List<SubmitExamPaperQuestionDTO> answerList) {
|
public void batchUpdatePaperQuestion(List<SubmitExamPaperQuestionDTO> answerList) {
|
||||||
examPaperQuestionMapper.batchUpdatePaperQuestion(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,6 +144,7 @@ public class MyExamineServiceImpl implements IMyExamineService {
|
|||||||
paperQuestion.setId(IdUtils.fastSimpleUUID());
|
paperQuestion.setId(IdUtils.fastSimpleUUID());
|
||||||
paperQuestion.setPaperId(examPaperInfoId);
|
paperQuestion.setPaperId(examPaperInfoId);
|
||||||
paperQuestion.setQuestionId(item.getId());
|
paperQuestion.setQuestionId(item.getId());
|
||||||
|
paperQuestion.setSorted(item.getSorted());
|
||||||
paperQuestionList.add(paperQuestion);
|
paperQuestionList.add(paperQuestion);
|
||||||
});
|
});
|
||||||
//批量新增
|
//批量新增
|
||||||
@ -164,15 +165,25 @@ public class MyExamineServiceImpl implements IMyExamineService {
|
|||||||
*/
|
*/
|
||||||
private List<ExamQuestionBank> createRandoms(List<ExamQuestionBank> source, int n) {
|
private List<ExamQuestionBank> createRandoms(List<ExamQuestionBank> source, int n) {
|
||||||
Map<Integer,String> map = new HashMap<>();
|
Map<Integer,String> map = new HashMap<>();
|
||||||
|
int i = 0;
|
||||||
List<ExamQuestionBank> news = new ArrayList<>();
|
List<ExamQuestionBank> news = new ArrayList<>();
|
||||||
if (source.size() == n){
|
if (source.size() == n){
|
||||||
|
if (StringUtils.isNotEmpty(source)){
|
||||||
|
for (ExamQuestionBank item : source) {
|
||||||
|
i++;
|
||||||
|
item.setSorted(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
return source;
|
return source;
|
||||||
}else {
|
}else {
|
||||||
while (map.size() < n){
|
while (map.size() < n){
|
||||||
int random = (int) (Math.random() * source.size());
|
int random = (int) (Math.random() * source.size());
|
||||||
if (!map.containsKey(random)){
|
if (!map.containsKey(random)){
|
||||||
map.put(random,"");
|
map.put(random,"");
|
||||||
news.add(source.get(random));
|
i++;
|
||||||
|
ExamQuestionBank examQuestionBank = source.get(random);
|
||||||
|
examQuestionBank.setSorted(i);
|
||||||
|
news.add(examQuestionBank);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return news;
|
return news;
|
||||||
@ -215,18 +226,45 @@ public class MyExamineServiceImpl implements IMyExamineService {
|
|||||||
}
|
}
|
||||||
//考试题
|
//考试题
|
||||||
List<MyExamPaperQuestionVO> allPaperQuestionList = myExamineMapper.selectHistoryPaperQuestionNoAnswerListByPaperId(id);
|
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)){
|
if (StringUtils.isEmpty(allPaperQuestionList)){
|
||||||
throw new ServiceException("未查询到考试题目");
|
throw new ServiceException("未查询到考试题目");
|
||||||
}
|
}
|
||||||
//试题类型 0 单选,1 多选,2 判断
|
//试题类型 0 单选,1 多选,2 判断
|
||||||
Map<String, List<MyExamPaperQuestionVO>> allPaperQuestionMap = allPaperQuestionList.stream().collect(Collectors.groupingBy(MyExamPaperQuestionVO::getQuestionType));
|
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"));
|
List<MyExamPaperQuestionVO> judgeList = allPaperQuestionMap.get("2");
|
||||||
return myExam;
|
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);
|
List<MyExamPaperQuestionVO> allPaperQuestionList = myExamineMapper.selectPaperQuestionNoAnswerListByPaperId(id);
|
||||||
if (StringUtils.isEmpty(allPaperQuestionList)){
|
assembleQuestionList(allPaperQuestionList,myExam);
|
||||||
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"));
|
|
||||||
return myExam;
|
return myExam;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,16 +312,11 @@ public class MyExamineServiceImpl implements IMyExamineService {
|
|||||||
if (Objects.isNull(examInfo)){
|
if (Objects.isNull(examInfo)){
|
||||||
throw new ServiceException("未查询到考试信息");
|
throw new ServiceException("未查询到考试信息");
|
||||||
}
|
}
|
||||||
//计算成绩
|
|
||||||
//考生答案
|
|
||||||
List<SubmitExamPaperQuestionDTO> userAnswerList = submitExamDTO.getAnswerList();
|
|
||||||
//正确答案
|
//正确答案
|
||||||
List<CorrectAnswerDTO> correctAnswerList = myExamineMapper.selectPaperQuestionHaveAnswerListByPaperId(submitExamDTO.getPaperId());
|
List<CorrectAnswerDTO> correctAnswerList = myExamineMapper.selectPaperQuestionHaveAnswerListByPaperId(submitExamDTO.getPaperId());
|
||||||
if (StringUtils.isEmpty(correctAnswerList)){
|
if (StringUtils.isEmpty(correctAnswerList)){
|
||||||
throw new ServiceException("未查询到考试试题信息");
|
throw new ServiceException("未查询到考试试题信息");
|
||||||
}
|
}
|
||||||
//判断答案是否正确,未作答也是回答错误
|
|
||||||
Map<String, CorrectAnswerDTO> correctAnswerMap = correctAnswerList.stream().collect(Collectors.toMap(CorrectAnswerDTO::getId, item->item));
|
|
||||||
//考试关联证书
|
//考试关联证书
|
||||||
String attestationId = examInfo.getAttestationId();
|
String attestationId = examInfo.getAttestationId();
|
||||||
//通过分数
|
//通过分数
|
||||||
@ -310,35 +333,48 @@ public class MyExamineServiceImpl implements IMyExamineService {
|
|||||||
int multipleChoice = 0;
|
int multipleChoice = 0;
|
||||||
//判断题回答正确数量
|
//判断题回答正确数量
|
||||||
int judge = 0;
|
int judge = 0;
|
||||||
for (SubmitExamPaperQuestionDTO item : userAnswerList) {
|
//考生分数
|
||||||
//是否正确 0:正确,1:错误
|
BigDecimal score;
|
||||||
//试题类型 0 单选,1 多选,2 判断
|
//计算成绩
|
||||||
CorrectAnswerDTO correctAnswerDTO = correctAnswerMap.get(item.getId());
|
//考生答案
|
||||||
if (Objects.nonNull(correctAnswerDTO)){
|
List<SubmitExamPaperQuestionDTO> userAnswerList = submitExamDTO.getAnswerList();
|
||||||
String correctAnswer = correctAnswerDTO.getQuestionAnswer();
|
if (StringUtils.isNotEmpty(userAnswerList)){
|
||||||
String questionType = correctAnswerDTO.getQuestionType();
|
//判断答案是否正确,未作答也是回答错误
|
||||||
if (StringUtils.isEmpty(item.getExamineAnswer())){
|
Map<String, CorrectAnswerDTO> correctAnswerMap = correctAnswerList.stream().collect(Collectors.toMap(CorrectAnswerDTO::getId, item->item));
|
||||||
item.setIsSure("1");
|
for (SubmitExamPaperQuestionDTO item : userAnswerList) {
|
||||||
}else {
|
//是否正确 0:正确,1:错误
|
||||||
if (correctAnswer.replace("\\s","").equals(item.getExamineAnswer().replace("\\s",""))){
|
//试题类型 0 单选,1 多选,2 判断
|
||||||
item.setIsSure("0");
|
CorrectAnswerDTO correctAnswerDTO = correctAnswerMap.get(item.getId());
|
||||||
if ("0".equals(questionType)){
|
if (Objects.nonNull(correctAnswerDTO)){
|
||||||
singleChoice++;
|
String correctAnswer = correctAnswerDTO.getQuestionAnswer();
|
||||||
}else if ("1".equals(questionType)){
|
String questionType = correctAnswerDTO.getQuestionType();
|
||||||
multipleChoice++;
|
if (StringUtils.isEmpty(item.getExamineAnswer())){
|
||||||
}else if ("2".equals(questionType)){
|
|
||||||
judge++;
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
item.setIsSure("1");
|
item.setIsSure("1");
|
||||||
|
}else {
|
||||||
|
if (correctAnswer.replace("\\s","").equals(item.getExamineAnswer().replace("\\s",""))){
|
||||||
|
item.setIsSure("0");
|
||||||
|
if ("0".equals(questionType)){
|
||||||
|
singleChoice++;
|
||||||
|
}else if ("1".equals(questionType)){
|
||||||
|
multipleChoice++;
|
||||||
|
}else if ("2".equals(questionType)){
|
||||||
|
judge++;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
item.setIsSure("1");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//考生分数
|
||||||
|
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());
|
||||||
}
|
}
|
||||||
//考生分数
|
|
||||||
BigDecimal score = (singleChoiceScore.multiply(new BigDecimal(singleChoice))).add(multipleChoiceScore.multiply(new BigDecimal(multipleChoice))).add(judgeScore.multiply(new BigDecimal(judge)));
|
|
||||||
//批量设置答案和是否答对
|
|
||||||
examPaperQuestionService.batchUpdatePaperQuestion(userAnswerList);
|
|
||||||
ExamPaperInfo examPaperInfo = new ExamPaperInfo();
|
ExamPaperInfo examPaperInfo = new ExamPaperInfo();
|
||||||
examPaperInfo.setId(submitExamDTO.getPaperId());
|
examPaperInfo.setId(submitExamDTO.getPaperId());
|
||||||
examPaperInfo.setScore(score);
|
examPaperInfo.setScore(score);
|
||||||
|
@ -52,4 +52,9 @@ public class MyExamPaperQuestionVO {
|
|||||||
*/
|
*/
|
||||||
private String isSure;
|
private String isSure;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private Integer sorted;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -46,10 +46,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<insert id="batchInsertPaperQuestion">
|
<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
|
values
|
||||||
<foreach collection="paperQuestionList" index="index" item="item" separator=",">
|
<foreach collection="paperQuestionList" index="index" item="item" separator=",">
|
||||||
(#{item.id},#{item.paperId},#{item.questionId})
|
(#{item.id},#{item.paperId},#{item.questionId},#{item.sorted})
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
@ -84,6 +84,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</foreach>
|
</foreach>
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<update id="updateIsSureByPaperId">
|
||||||
|
update exam_paper_question set is_sure = '1' where paper_id = #{paperId}
|
||||||
|
</update>
|
||||||
|
|
||||||
<delete id="deleteExamPaperQuestionById" parameterType="String">
|
<delete id="deleteExamPaperQuestionById" parameterType="String">
|
||||||
delete from exam_paper_question where id = #{id}
|
delete from exam_paper_question where id = #{id}
|
||||||
</delete>
|
</delete>
|
||||||
|
@ -187,6 +187,7 @@
|
|||||||
<select id="selectPaperQuestionNoAnswerListByPaperId" resultType="com.inspur.examine.vo.MyExamPaperQuestionVO">
|
<select id="selectPaperQuestionNoAnswerListByPaperId" resultType="com.inspur.examine.vo.MyExamPaperQuestionVO">
|
||||||
SELECT
|
SELECT
|
||||||
epq.id,
|
epq.id,
|
||||||
|
epq.sorted,
|
||||||
eqb.question_type as questionType,
|
eqb.question_type as questionType,
|
||||||
eqb.question_title as questionTitle,
|
eqb.question_title as questionTitle,
|
||||||
eqb.question_options as questionOptions
|
eqb.question_options as questionOptions
|
||||||
@ -233,6 +234,7 @@
|
|||||||
resultType="com.inspur.examine.vo.MyExamPaperQuestionVO">
|
resultType="com.inspur.examine.vo.MyExamPaperQuestionVO">
|
||||||
SELECT
|
SELECT
|
||||||
epq.id,
|
epq.id,
|
||||||
|
epq.sorted,
|
||||||
epq.examine_answer AS examineAnswer,
|
epq.examine_answer AS examineAnswer,
|
||||||
epq.is_sure AS isSure,
|
epq.is_sure AS isSure,
|
||||||
eqb.question_type AS questionType,
|
eqb.question_type AS questionType,
|
||||||
|
Loading…
Reference in New Issue
Block a user