package org.springblade.modules.exam.service.impl; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.AllArgsConstructor; import org.springblade.modules.exam.entity.ExamExaminationSubject; import org.springblade.modules.exam.entity.ExamPaper; import org.springblade.modules.exam.entity.ExamScore; import org.springblade.modules.exam.excel.ExportExamScoreExcel; import org.springblade.modules.exam.mapper.ExamScoreMapper; import org.springblade.modules.exam.service.ExamPaperService; import org.springblade.modules.exam.service.ExamScoreService; import org.springblade.modules.exam.vo.ExamResultVO; import org.springblade.modules.exam.vo.ExamScoreVO; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Arrays; import java.util.List; /** * 考试成绩服务实现类 * @author zhongrj */ @Service @AllArgsConstructor public class ExamScoreServiceImpl extends ServiceImpl implements ExamScoreService { private final ExamPaperService examPaperService; /** * 自定义分页数据 * @param page 分页条件 * @param examScore 考试成绩对象 * @return */ @Override public IPage selectExamScorePage(IPage page, ExamScoreVO examScore) { return page.setRecords(baseMapper.selectExamScorePage(page, examScore)); } /** * 详情 * @param examScore 考试成绩信息对象 */ @Override public ExamScoreVO selectExamScoreInfo(ExamScore examScore) { return baseMapper.selectExamScoreInfo(examScore); } /** * 保存考试成绩 * @param examScore 考试成绩信息对象 * @return */ @Override @Transactional(rollbackFor = Exception.class) public Boolean saveExamScore(ExamScoreVO examScore) { //取出考试结果 if (examScore.getExamResultVOS().size()>0){ List examResultVOS = examScore.getExamResultVOS(); //获取试卷的内容(题号,答案) ExamPaper examPaper = new ExamPaper(); examPaper.setId(examScore.getPapersId()); List examExaminationSubjects = examPaperService.PagerSubject(examPaper).getExamExaminationSubjects(); //比对考试结果 //声明理论得分 int theoryGrade = 0; for (ExamResultVO examResultVO : examResultVOS) { for (ExamExaminationSubject examExaminationSubject : examExaminationSubjects) { //对比题目id if (examResultVO.getSubjectChoicesId().equals(examExaminationSubject.getExamSubjectChoices().getId())) { //对比答案 if (examExaminationSubject.getExamSubjectChoices().getChoicesType() == 2 || examExaminationSubject.getExamSubjectChoices().getChoicesType() == 3){ //判断题逻辑 if (examResultVO.getValue().equals(examExaminationSubject.getExamSubjectChoices().getAnswer())) { theoryGrade += examResultVO.getGrade(); } }else if(examExaminationSubject.getExamSubjectChoices().getChoicesType() == 0 || examExaminationSubject.getExamSubjectChoices().getChoicesType() == 1){ //处理多选题的答案排序 String[] split = examResultVO.getValue().split(","); StringBuilder builder = new StringBuilder(); for (String s : split) { builder.append(s); } char[] arrayCh = builder.toString().toCharArray(); //利用数组帮助类自动排序 Arrays.sort(arrayCh); String sub0 = Arrays.toString(arrayCh); String sub = sub0.substring(1,sub0.length()-1).replaceAll(" ",""); if (sub.equals(examExaminationSubject.getExamSubjectChoices().getAnswer())) { theoryGrade += examResultVO.getGrade(); } } //移除当前试卷题目答案对象 examExaminationSubjects.remove(examExaminationSubject); break; } } } //设置理论得分 examScore.setTheoryGrade(theoryGrade); //计算总成绩,此时没有实操成绩,总成绩为实操成绩和理论成绩和的一半 examScore.setAllGrade(Math.round(theoryGrade/2)); //设置状态 if (theoryGrade>=60){ examScore.setQualified(2); }else { examScore.setQualified(1); } //保存成绩数据 int i = baseMapper.insert(examScore); //修改考试状态为已考试,当前报名已考试,无法再考 if (i>0){ //返回结果 return true; } } //返回结果 return false; } /** * 按条件查询成绩数据 * @param examScoreVO * @return */ @Override public List exportExamScoreList(ExamScoreVO examScoreVO) { return baseMapper.exportExamScoreList(examScoreVO); } /** * 根据时间查看考试成绩 * @param candidateNo * @param time * @return */ @Override public List getExamScoreInfoByIdCardNo(String candidateNo, String time) { return baseMapper.getExamScoreInfoByIdCardNo(candidateNo,time); } }