智慧保安后台管理-外网项目备份
zengh
2021-07-19 748bd2dff7201eea3adaa1adbd459be4f0cc75d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
 
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.mapper.ExamScoreMapper;
import org.springblade.modules.exam.service.ExamPaperService;
import org.springblade.modules.exam.service.ExamScoreService;
import org.springblade.modules.exam.vo.ExamPaperSubjectVO;
import org.springblade.modules.exam.vo.ExamResultVO;
import org.springblade.modules.exam.vo.ExamScoreVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
/**
 * 考试成绩服务实现类
 * @author zhongrj
 */
@Service
@AllArgsConstructor
public class ExamScoreServiceImpl extends ServiceImpl<ExamScoreMapper, ExamScore> implements ExamScoreService {
 
    private final ExamPaperService examPaperService;
 
    /**
     * 自定义分页数据
     * @param page 分页条件
     * @param examScore 考试成绩对象
     * @return
     */
    @Override
    public IPage<ExamScoreVO> selectExamScorePage(IPage<ExamScoreVO> 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<ExamResultVO> examResultVOS = examScore.getExamResultVOS();
            //获取试卷的内容(题号,答案)
            ExamPaper examPaper = new ExamPaper();
            examPaper.setId(examScore.getPapersId());
            List<ExamExaminationSubject> 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){
                            //判断题逻辑
                            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;
    }
}