diff --git a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/domain/ExamPaperQuestion.java b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/domain/ExamPaperQuestion.java new file mode 100644 index 0000000..ac44309 --- /dev/null +++ b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/domain/ExamPaperQuestion.java @@ -0,0 +1,39 @@ +package com.inspur.examine.domain; + +import com.inspur.common.annotation.Excel; +import lombok.Data; + +/** + * 试卷试题对象 exam_paper_question + * + * @author inspur + * @date 2024-05-09 + */ +@Data +public class ExamPaperQuestion { + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + private String id; + + /** + * 试卷id + */ + @Excel(name = "试卷id") + private String paperId; + + /** + * 试题id + */ + @Excel(name = "试题id") + private String questionId; + + /** + * 考生答案 + */ + @Excel(name = "考生答案") + private String examineAnswer; + +} diff --git a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/mapper/ExamPaperQuestionMapper.java b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/mapper/ExamPaperQuestionMapper.java new file mode 100644 index 0000000..0510c85 --- /dev/null +++ b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/mapper/ExamPaperQuestionMapper.java @@ -0,0 +1,71 @@ +package com.inspur.examine.mapper; + +import java.util.List; +import com.inspur.examine.domain.ExamPaperQuestion; +import org.apache.ibatis.annotations.Param; + +/** + * 试卷试题Mapper接口 + * + * @author inspur + * @date 2024-05-09 + */ +public interface ExamPaperQuestionMapper +{ + /** + * 查询试卷试题 + * + * @param id 试卷试题主键 + * @return 试卷试题 + */ + public ExamPaperQuestion selectExamPaperQuestionById(String id); + + /** + * 查询试卷试题列表 + * + * @param examPaperQuestion 试卷试题 + * @return 试卷试题集合 + */ + public List selectExamPaperQuestionList(ExamPaperQuestion examPaperQuestion); + + /** + * 新增试卷试题 + * + * @param examPaperQuestion 试卷试题 + * @return 结果 + */ + public int insertExamPaperQuestion(ExamPaperQuestion examPaperQuestion); + + /** + * 修改试卷试题 + * + * @param examPaperQuestion 试卷试题 + * @return 结果 + */ + public int updateExamPaperQuestion(ExamPaperQuestion examPaperQuestion); + + /** + * 删除试卷试题 + * + * @param id 试卷试题主键 + * @return 结果 + */ + public int deleteExamPaperQuestionById(String id); + + /** + * 批量删除试卷试题 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteExamPaperQuestionByIds(String[] ids); + + /** + * 批量新增试卷试题信息 + * + * @Author xusd + * @Date 16:53 2024/5/9 + * @param paperQuestionList 数据 + */ + void batchInsertPaperQuestion(@Param("paperQuestionList") List paperQuestionList); +} diff --git a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/IExamPaperQuestionService.java b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/IExamPaperQuestionService.java new file mode 100644 index 0000000..901a4c3 --- /dev/null +++ b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/IExamPaperQuestionService.java @@ -0,0 +1,70 @@ +package com.inspur.examine.service; + +import java.util.List; +import com.inspur.examine.domain.ExamPaperQuestion; + +/** + * 试卷试题Service接口 + * + * @author inspur + * @date 2024-05-09 + */ +public interface IExamPaperQuestionService +{ + /** + * 查询试卷试题 + * + * @param id 试卷试题主键 + * @return 试卷试题 + */ + public ExamPaperQuestion selectExamPaperQuestionById(String id); + + /** + * 查询试卷试题列表 + * + * @param examPaperQuestion 试卷试题 + * @return 试卷试题集合 + */ + public List selectExamPaperQuestionList(ExamPaperQuestion examPaperQuestion); + + /** + * 新增试卷试题 + * + * @param examPaperQuestion 试卷试题 + * @return 结果 + */ + public int insertExamPaperQuestion(ExamPaperQuestion examPaperQuestion); + + /** + * 修改试卷试题 + * + * @param examPaperQuestion 试卷试题 + * @return 结果 + */ + public int updateExamPaperQuestion(ExamPaperQuestion examPaperQuestion); + + /** + * 批量删除试卷试题 + * + * @param ids 需要删除的试卷试题主键集合 + * @return 结果 + */ + public int deleteExamPaperQuestionByIds(String[] ids); + + /** + * 删除试卷试题信息 + * + * @param id 试卷试题主键 + * @return 结果 + */ + public int deleteExamPaperQuestionById(String id); + + /** + * 批量新增试卷试题信息 + * + * @Author xusd + * @Date 16:53 2024/5/9 + * @param paperQuestionList 数据 + */ + void batchInsertPaperQuestion(List paperQuestionList); +} diff --git a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/ExamPaperInfoServiceImpl.java b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/ExamPaperInfoServiceImpl.java index ab5b929..adf7b8f 100644 --- a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/ExamPaperInfoServiceImpl.java +++ b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/ExamPaperInfoServiceImpl.java @@ -56,7 +56,6 @@ public class ExamPaperInfoServiceImpl implements IExamPaperInfoService @Override public int insertExamPaperInfo(ExamPaperInfo examPaperInfo) { - examPaperInfo.setId(IdUtils.fastSimpleUUID()); examPaperInfo.setTenantId(SecurityUtils.getLoginUser().getTenantId()); return examPaperInfoMapper.insertExamPaperInfo(examPaperInfo); } diff --git a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/ExamPaperQuestionServiceImpl.java b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/ExamPaperQuestionServiceImpl.java new file mode 100644 index 0000000..d75a1bb --- /dev/null +++ b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/ExamPaperQuestionServiceImpl.java @@ -0,0 +1,105 @@ +package com.inspur.examine.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.inspur.examine.mapper.ExamPaperQuestionMapper; +import com.inspur.examine.domain.ExamPaperQuestion; +import com.inspur.examine.service.IExamPaperQuestionService; + +/** + * 试卷试题Service业务层处理 + * + * @author inspur + * @date 2024-05-09 + */ +@Service +public class ExamPaperQuestionServiceImpl implements IExamPaperQuestionService +{ + @Autowired + private ExamPaperQuestionMapper examPaperQuestionMapper; + + /** + * 查询试卷试题 + * + * @param id 试卷试题主键 + * @return 试卷试题 + */ + @Override + public ExamPaperQuestion selectExamPaperQuestionById(String id) + { + return examPaperQuestionMapper.selectExamPaperQuestionById(id); + } + + /** + * 查询试卷试题列表 + * + * @param examPaperQuestion 试卷试题 + * @return 试卷试题 + */ + @Override + public List selectExamPaperQuestionList(ExamPaperQuestion examPaperQuestion) + { + return examPaperQuestionMapper.selectExamPaperQuestionList(examPaperQuestion); + } + + /** + * 新增试卷试题 + * + * @param examPaperQuestion 试卷试题 + * @return 结果 + */ + @Override + public int insertExamPaperQuestion(ExamPaperQuestion examPaperQuestion) + { + return examPaperQuestionMapper.insertExamPaperQuestion(examPaperQuestion); + } + + /** + * 修改试卷试题 + * + * @param examPaperQuestion 试卷试题 + * @return 结果 + */ + @Override + public int updateExamPaperQuestion(ExamPaperQuestion examPaperQuestion) + { + return examPaperQuestionMapper.updateExamPaperQuestion(examPaperQuestion); + } + + /** + * 批量删除试卷试题 + * + * @param ids 需要删除的试卷试题主键 + * @return 结果 + */ + @Override + public int deleteExamPaperQuestionByIds(String[] ids) + { + return examPaperQuestionMapper.deleteExamPaperQuestionByIds(ids); + } + + /** + * 删除试卷试题信息 + * + * @param id 试卷试题主键 + * @return 结果 + */ + @Override + public int deleteExamPaperQuestionById(String id) + { + return examPaperQuestionMapper.deleteExamPaperQuestionById(id); + } + + /** + * 批量新增试卷试题信息 + * + * @Author xusd + * @Date 16:53 2024/5/9 + * @param paperQuestionList 数据 + */ + @Override + public void batchInsertPaperQuestion(List paperQuestionList) { + examPaperQuestionMapper.batchInsertPaperQuestion(paperQuestionList); + } +} diff --git a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/MyExamineServiceImpl.java b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/MyExamineServiceImpl.java index 7611b49..f18e2e1 100644 --- a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/MyExamineServiceImpl.java +++ b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/MyExamineServiceImpl.java @@ -1,21 +1,18 @@ package com.inspur.examine.service.impl; +import com.inspur.common.exception.ServiceException; import com.inspur.common.utils.SecurityUtils; import com.inspur.common.utils.StringUtils; -import com.inspur.examine.domain.ExamAttestation; -import com.inspur.examine.domain.ExamInfo; -import com.inspur.examine.domain.ExamPaperInfo; +import com.inspur.common.utils.uuid.IdUtils; +import com.inspur.examine.domain.*; import com.inspur.examine.mapper.MyExamineMapper; -import com.inspur.examine.service.IExamInfoService; -import com.inspur.examine.service.IExamPaperInfoService; -import com.inspur.examine.service.IMyExamineService; +import com.inspur.examine.service.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Collections; -import java.util.List; -import java.util.Objects; +import java.util.*; +import java.util.stream.Collectors; /** * 我的考试 @@ -32,6 +29,15 @@ public class MyExamineServiceImpl implements IMyExamineService { @Autowired private IExamPaperInfoService examPaperInfoService; + @Autowired + private IExamInfoService examInfoService; + + @Autowired + private IExamQuestionBankService examQuestionBankService; + + @Autowired + private IExamPaperQuestionService examPaperQuestionService; + /** * 查询考试信息列表 */ @@ -55,17 +61,115 @@ public class MyExamineServiceImpl implements IMyExamineService { @Override @Transactional(rollbackFor = Exception.class) public int generateExam(String id) { + ExamInfo examInfo = examInfoService.selectExamInfoById(id); + if (Objects.isNull(examInfo)){ + throw new ServiceException("未查询到考试信息"); + } + + //获取所有该类型和等级的试题 + ExamQuestionBank examQuestionBank = new ExamQuestionBank(); + examQuestionBank.setExamType(examInfo.getExamType()); + examQuestionBank.setExamLevel(examInfo.getExamLevel()); + //启用的试题 + examQuestionBank.setStatus("0"); + List examQuestionBanks = examQuestionBankService.selectExamQuestionBankList(examQuestionBank); + Map> questionTypeMap = examQuestionBanks.stream().collect(Collectors.groupingBy(ExamQuestionBank::getQuestionType)); + + //判断考题数量是否充足 + //单选题 + if (examInfo.getSingleChoice() > 0){ + if (StringUtils.isEmpty(questionTypeMap.get("0")) || examInfo.getSingleChoice() > questionTypeMap.get("0").size()){ + throw new ServiceException("单选题数量不足"); + } + } + //多选题 + if (examInfo.getMultipleChoice() > 0){ + if (StringUtils.isEmpty(questionTypeMap.get("1")) || examInfo.getMultipleChoice() > questionTypeMap.get("1").size()){ + throw new ServiceException("多选题数量不足"); + } + } + //判断题 + if (examInfo.getJudge() > 0){ + if (StringUtils.isEmpty(questionTypeMap.get("2")) || examInfo.getJudge() > questionTypeMap.get("2").size()){ + throw new ServiceException("判断题数量不足"); + } + } + + //新增考生考试信息 ExamPaperInfo examPaperInfo = new ExamPaperInfo(); + String examPaperInfoId = IdUtils.fastSimpleUUID(); + examPaperInfo.setId(examPaperInfoId); examPaperInfo.setExamId(id); examPaperInfo.setExamineId(SecurityUtils.getUserId()); examPaperInfo.setStatus("0"); int i = examPaperInfoService.insertExamPaperInfo(examPaperInfo); if (i > 0){ - //todo:生成考试试题等 + //根据考试各类型试题条数出题 + List questionList = new ArrayList<>(); + //单选题 + if (examInfo.getSingleChoice() > 0){ + List singleChoiceList = questionTypeMap.get("0"); + //随机题目 + List insertSingleChoiceList = createRandoms(singleChoiceList, examInfo.getSingleChoice()); + questionList.addAll(insertSingleChoiceList); + } + //多选题 + if (examInfo.getMultipleChoice() > 0){ + List multipleChoiceList = questionTypeMap.get("1"); + //随机题目 + List insertMultipleChoiceListList = createRandoms(multipleChoiceList, examInfo.getMultipleChoice()); + questionList.addAll(insertMultipleChoiceListList); + } + //判断题 + if (examInfo.getJudge() > 0){ + List judgeList = questionTypeMap.get("2"); + //随机题目 + List insertJudgeList = createRandoms(judgeList, examInfo.getJudge()); + questionList.addAll(insertJudgeList); + } + //新增试卷试题关联 + if (StringUtils.isNotEmpty(questionList)){ + List paperQuestionList = new ArrayList<>(); + questionList.forEach(item->{ + ExamPaperQuestion paperQuestion = new ExamPaperQuestion(); + paperQuestion.setId(IdUtils.fastSimpleUUID()); + paperQuestion.setPaperId(examPaperInfoId); + paperQuestion.setQuestionId(item.getId()); + paperQuestionList.add(paperQuestion); + }); + //批量新增 + examPaperQuestionService.batchInsertPaperQuestion(paperQuestionList); + } } return i; } + /** + * 从源数据中取出随机数量的不重复数据 + * + * @param source 源数据 + * @param n 随机获取数量 + * @return java.util.List + * @Author xusd + * @Date 16:17 2024/5/9 + */ + private List createRandoms(List source, int n) { + Map map = new HashMap<>(); + List news = new ArrayList<>(); + if (source.size() == n){ + 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)); + } + } + return news; + } + } + /** * 待考试列表 */ diff --git a/inspur-service/inspur-examine/src/main/resources/mapper/ExamPaperQuestionMapper.xml b/inspur-service/inspur-examine/src/main/resources/mapper/ExamPaperQuestionMapper.xml new file mode 100644 index 0000000..69ad96f --- /dev/null +++ b/inspur-service/inspur-examine/src/main/resources/mapper/ExamPaperQuestionMapper.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + select id, paper_id, question_id, examine_answer from exam_paper_question + + + + + + + + insert into exam_paper_question + + id, + paper_id, + question_id, + examine_answer, + + + #{id}, + #{paperId}, + #{questionId}, + #{examineAnswer}, + + + + + insert into exam_paper_question(id,paper_id,question_id) + values + + (#{item.id},#{item.paperId},#{item.questionId}) + + + + + update exam_paper_question + + paper_id = #{paperId}, + question_id = #{questionId}, + examine_answer = #{examineAnswer}, + + where id = #{id} + + + + delete from exam_paper_question where id = #{id} + + + + delete from exam_paper_question where id in + + #{id} + + + \ No newline at end of file diff --git a/inspur-ui/src/views/examine/myExamine/index.vue b/inspur-ui/src/views/examine/myExamine/index.vue index c39d1db..e0af438 100644 --- a/inspur-ui/src/views/examine/myExamine/index.vue +++ b/inspur-ui/src/views/examine/myExamine/index.vue @@ -332,10 +332,8 @@ export default { }) }, generateExam(row){ - this.examLoading = true generateExam(row.id).then(()=>{ this.$modal.msgSuccess("参与成功"); - this.examLoading = false; this.getExamList(); }) },