| | |
| | | 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.entity.ExamSubjectChoices; |
| | | import org.springblade.modules.exam.excel.ExamScoreExcel; |
| | | 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.service.ExamSubjectChoicesService; |
| | | import org.springblade.modules.exam.util.SecurityPaperUtil; |
| | | import org.springblade.modules.exam.vo.ExamResultVO; |
| | | import org.springblade.modules.exam.vo.ExamScoreVO; |
| | | import org.springblade.modules.system.entity.User; |
| | | import org.springblade.modules.system.service.IUserService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.text.DecimalFormat; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | @AllArgsConstructor |
| | | public class ExamScoreServiceImpl extends ServiceImpl<ExamScoreMapper, ExamScore> implements ExamScoreService { |
| | | |
| | | private final ExamPaperService examPaperService; |
| | | private final IUserService userService; |
| | | |
| | | private final ExamSubjectChoicesService examSubjectChoicesService; |
| | | |
| | | /** |
| | | * 自定义分页数据 |
| | |
| | | if (examScore.getExamResultVOS().size()>0){ |
| | | List<ExamResultVO> examResultVOS = examScore.getExamResultVOS(); |
| | | //获取试卷的内容(题号,答案) |
| | | ExamPaper examPaper = new ExamPaper(); |
| | | examPaper.setId(examScore.getPapersId()); |
| | | List<ExamExaminationSubject> examExaminationSubjects |
| | | = examPaperService.PagerSubject(examPaper).getExamExaminationSubjects(); |
| | | // ExamPaper examPaper = new ExamPaper(); |
| | | // examPaper.setId(examScore.getPapersId()); |
| | | // List<ExamExaminationSubject> examExaminationSubjects |
| | | // = examPaperService.PagerSubject(examPaper).getExamExaminationSubjects(); |
| | | List<ExamSubjectChoices> list = examSubjectChoicesService.list(); |
| | | //比对考试结果 |
| | | //声明理论得分 |
| | | int theoryGrade = 0; |
| | | for (ExamResultVO examResultVO : examResultVOS) { |
| | | for (ExamExaminationSubject examExaminationSubject : examExaminationSubjects) { |
| | | for (ExamSubjectChoices es: list) { |
| | | //对比题目id |
| | | if (examResultVO.getSubjectChoicesId().equals(examExaminationSubject.getExamSubjectChoices().getId())) { |
| | | if (examResultVO.getSubjectChoicesId().equals(es.getId())) { |
| | | //对比答案 |
| | | |
| | | if (examExaminationSubject.getExamSubjectChoices().getChoicesType() == 2 || examExaminationSubject.getExamSubjectChoices().getChoicesType() == 3){ |
| | | if (es.getChoicesType() == 2 || es.getChoicesType() == 3){ |
| | | //判断题逻辑 |
| | | if (examResultVO.getValue().equals(examExaminationSubject.getExamSubjectChoices().getAnswer())) { |
| | | if (examResultVO.getValue().equals(es.getAnswer())) { |
| | | theoryGrade += examResultVO.getGrade(); |
| | | } |
| | | }else if(examExaminationSubject.getExamSubjectChoices().getChoicesType() == 0 || examExaminationSubject.getExamSubjectChoices().getChoicesType() == 1){ |
| | | }else if(es.getChoicesType() == 0 || es.getChoicesType() == 1){ |
| | | //处理多选题的答案排序 |
| | | String[] split = examResultVO.getValue().split(","); |
| | | StringBuilder builder = new StringBuilder(); |
| | |
| | | Arrays.sort(arrayCh); |
| | | String sub0 = Arrays.toString(arrayCh); |
| | | String sub = sub0.substring(1,sub0.length()-1).replaceAll(" ",""); |
| | | if (sub.equals(examExaminationSubject.getExamSubjectChoices().getAnswer())) { |
| | | if (sub.equals(es.getAnswer())) { |
| | | theoryGrade += examResultVO.getGrade(); |
| | | } |
| | | } |
| | | //移除当前试卷题目答案对象 |
| | | examExaminationSubjects.remove(examExaminationSubject); |
| | | list.remove(es); |
| | | break; |
| | | } |
| | | } |
| | |
| | | } |
| | | //保存成绩数据 |
| | | int i = baseMapper.insert(examScore); |
| | | //内网新增 |
| | | try { |
| | | arg.test01(arg.url+"/examScore/save",examScore); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | //修改考试状态 |
| | | |
| | | if (i>0){ |
| | | //返回结果 |
| | | return true; |
| | |
| | | if (examScore.getTheoryGrade() >= 60 && examScore.getLearnGrade() >= 60) { |
| | | //合格 |
| | | examScore.setQualified(0); |
| | | //去生成保安证编号 |
| | | //查询当前保安信息 |
| | | User user = userService.getById(examScore.getUserId()); |
| | | String pre = SecurityPaperUtil.getSecurityPaper(); |
| | | //查询当前年份已有的保安证编号 |
| | | int count = userService.getSecurityPaperCount(pre); |
| | | String result = null; |
| | | if (count==0){ |
| | | result = pre + "00000"; |
| | | }else { |
| | | //格式化 |
| | | DecimalFormat decimalFormat = new DecimalFormat("00000"); |
| | | result = pre + (decimalFormat.format(count++)); |
| | | } |
| | | user.setSecuritynumber(result); |
| | | //更新保安数据 |
| | | userService.updateById(user); |
| | | } else { |
| | | //不合格 |
| | | examScore.setQualified(1); |
| | | } |
| | | //总成绩 |
| | | examScore.setAllGrade(Math.round((examScore.getTheoryGrade()+examScoreExcel.getLearnGrade())/2)); |
| | | //更新成绩数据 |
| | | baseMapper.updateById(examScore); |
| | | } |