智慧保安后台管理-外网
钟日健
2022-02-25 afc2b4d2800d91c793523d14fbe2d6fbbd319fc0
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
 
package org.springblade.modules.simulateexam.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.redisson.misc.Hash;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Condition;
import org.springblade.modules.exam.entity.ExamAnswerRecord;
import org.springblade.modules.exam.entity.ExamScore;
import org.springblade.modules.exam.entity.ExamSubjectChoices;
import org.springblade.modules.exam.service.ExamPaperService;
import org.springblade.modules.exam.service.ExamSubjectChoicesService;
import org.springblade.modules.exam.vo.ExamSubjectChoicesVO;
import org.springblade.modules.simulateexam.entity.SimulateExamAnswerRecord;
import org.springblade.modules.simulateexam.entity.SimulateExamRecord;
import org.springblade.modules.simulateexam.mapper.SimulateExamRecordMapper;
import org.springblade.modules.simulateexam.service.SimulateExamAnswerRecordService;
import org.springblade.modules.simulateexam.service.SimulateExamRecordService;
import org.springblade.modules.simulateexam.vo.SimulateExamRecordVO;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IUserService;
import org.springblade.modules.training.entity.TrainingRegistration;
import org.springblade.modules.vip.entity.VipTopic;
import org.springblade.modules.vip.service.VipTopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 *  模拟考试记录服务实现类
 *
 * @author zhongrj
 * @since 2022-02-23
 */
@Service
public class SimulateExamRecordServiceImpl extends ServiceImpl<SimulateExamRecordMapper, SimulateExamRecord> implements SimulateExamRecordService {
 
    @Autowired
    private ExamSubjectChoicesService examSubjectChoicesService;
 
    @Autowired
    private VipTopicService vipTopicService;
 
    @Autowired
    private IUserService userService;
 
    @Autowired
    private ExamPaperService examPaperService;
 
    @Autowired
    private SimulateExamAnswerRecordService simulateExamAnswerRecordService;
 
    /**
     * 自定义分页查询模拟考试记录数据
     * @param page
     * @param simulateExamRecord
     * @return
     */
    @Override
    public IPage<SimulateExamRecordVO> selectSimulateExamRecordPage(IPage<SimulateExamRecordVO> page, SimulateExamRecordVO simulateExamRecord) {
        return page.setRecords(baseMapper.selectSimulateExamRecordPage(page, simulateExamRecord));
    }
 
    /**
     * 首次点击开始考试,创建模拟考试,并返回考试
     * @param simulateExamRecord 模拟考试记录对象信息
     * @return
     */
    @Override
    public Object insertSimulateExamRecord(SimulateExamRecord simulateExamRecord) {
        //创建返回信息map
        Map<String, Object> map = new HashMap<>();
        //使用身份证号码匹配人员信息(user_id)
        User user = new User();
        user.setIsDeleted(0);
        user.setStatus(1);
        user.setCardid(simulateExamRecord.getIdCardNo());
        List<User> list = userService.list(Condition.getQueryWrapper(user));
        List<ExamSubjectChoicesVO> choicesVOList = new ArrayList<>();
        if (list.size()>0){
            User user1 = list.get(0);
            //查询当前人员的考试题库,已缴费id
            VipTopic vipTopic = new VipTopic();
            vipTopic.setUserId(user1.getId());
            VipTopic topic = vipTopicService.getOne(Condition.getQueryWrapper(vipTopic));
            //从当前人员考试题库随机取60题存入
            if (null!=topic){
                List<String> list1 = Arrays.asList(topic.getTopicIds().split(","));
                //获取随机的题目
                List<String> radio = list1.subList(0, 49);
                List<String> checkbox = list1.subList(50, 69);
                List<String> judge = list1.subList(70, 109);
                List<String> sort = list1.subList(110, 119);
                //随机题目
                List<ExamSubjectChoicesVO> radioRandomSubjectList = examPaperService.queryRandomSubjectList(radio,25);
                List<ExamSubjectChoicesVO> checkboxRandomSubjectList = examPaperService.queryRandomSubjectList(checkbox,10);
                List<ExamSubjectChoicesVO> judgeRandomSubjectList = examPaperService.queryRandomSubjectList(judge,20);
//                List<ExamSubjectChoicesVO> sortRandomSubjectList = examPaperService.queryRandomSubjectList(sort,5);
 
                //合并集合数据
                choicesVOList.addAll(radioRandomSubjectList);
                choicesVOList.addAll(checkboxRandomSubjectList);
                choicesVOList.addAll(judgeRandomSubjectList);
//                choicesVOList.addAll(sortRandomSubjectList);
 
                //取出考试id
                List<Long> longList = choicesVOList.stream().map(ExamSubjectChoicesVO::getId).collect(Collectors.toList());
                //装换为字符串
                List<String> list2 = new ArrayList<>();
                for (Long aLong : longList) {
                    list2.add(aLong.toString());
                }
                String collect = list2.stream().collect(Collectors.joining(","));
                //设置题目信息
                simulateExamRecord.setSubjectIds(collect);
                simulateExamRecord.setStartTime(new Date());
                //考试剩余时长初始值为60分钟
                simulateExamRecord.setAnswerTime(60*60*1000L);
                //考试中,开始计时
                simulateExamRecord.setStatus(1);
                //新增模拟考试记录信息
                boolean status = this.save(simulateExamRecord);
 
                ExamSubjectChoices examSubjectChoices = new ExamSubjectChoices();
                examSubjectChoices.setId(choicesVOList.get(0).getId());
                ExamSubjectChoicesVO examSubjectChoicesVO = examSubjectChoicesService.selectExamSubjectChoicesInfo(examSubjectChoices);
                if (status){
                    map.put("simulateExamRecord",simulateExamRecord);
                    map.put("examSubjectInfo",choicesVOList);
                    map.put("examSubjectChoicesVO",examSubjectChoicesVO);
                    //返回信息
                    return map;
                }
            }else {
                throw new ServiceException("未查询到该人员缴费信息");
            }
        }else {
            throw new ServiceException("未查询到该人员信息");
        }
        //返回数据
        return map;
    }
 
    /**
     * 暂停模拟考试
     * @param simulateExamRecord
     * @return
     */
    @Override
    public Object pauseExam(SimulateExamRecord simulateExamRecord) {
        simulateExamRecord.setStatus(2);
        //计算时长
        return this.updateById(simulateExamRecord);
    }
 
    /**
     * 模拟考试开始页面,查询是否有暂停中的模拟考试
     * @param simulateExamRecord 模拟考试记录对象信息(必须包含 idCardNo)
     * @return
     */
    @Override
    public Object getSimulateExamRecordInfo(SimulateExamRecord simulateExamRecord) {
        simulateExamRecord.setStatus(2);
        return this.getOne(Condition.getQueryWrapper(simulateExamRecord));
    }
 
    /**
     * 考试暂停后继续,1查询所有的答题信息,2查询所有的已答信息  3其他信息
     * @param simulateExamRecord 必须包含 模拟考试id,, type 1: 继续考试  2: 放弃之前的考试,重新生成题目考试
     * @return
     */
    @Override
    public Object getSimulateExamRefreshInfo(SimulateExamRecordVO simulateExamRecord) {
        if (null!=simulateExamRecord.getId()) {
            Map<String, Object> map = new HashMap<>();
            //1. 继续考试
            if (simulateExamRecord.getType().equals(1)){
                //其他信息
                SimulateExamRecord simulateExamRecord1 = this.getById(simulateExamRecord.getId());
                List<String> list = Arrays.asList(simulateExamRecord1.getSubjectIds().split(","));
                List<Long> list1 = new ArrayList<>();
                //装换为Long 类型,不然返回的题目顺序会乱
                for (String s : list) {
                    list1.add(Long.parseLong(s));
                }
 
                //修改信息,修改回考试中的状态
                simulateExamRecord1.setStatus(1);
                this.updateById(simulateExamRecord1);
 
                //1.查询当前人员当前模拟考试的考试题目信息
                List<ExamSubjectChoicesVO> examSubjectChoicesVOSList = baseMapper.getSimulateExamRefreshList(list1);
 
                //2.查询当前人员已答的题目信息
                SimulateExamAnswerRecord simulateExamAnswerRecord = new SimulateExamAnswerRecord();
                simulateExamAnswerRecord.setSimulateExamId(simulateExamRecord.getId());
                List<SimulateExamAnswerRecord> simulateExamAnswerRecordList = simulateExamAnswerRecordService.list(Condition.getQueryWrapper(simulateExamAnswerRecord));
 
                //3.查询正在答题的信息
                int count  = simulateExamAnswerRecordList.size();
                //查询下一题题目信息
                ExamSubjectChoicesVO examSubjectChoicesVO = new ExamSubjectChoicesVO();
                ExamSubjectChoices examSubjectChoices = new ExamSubjectChoices();
                if (count>0) {
                    examSubjectChoices.setId(examSubjectChoicesVOSList.get(count).getId());
                    examSubjectChoicesVO = examSubjectChoicesService.selectExamSubjectChoicesInfo(examSubjectChoices);
                }
                if (count==0) {
                    examSubjectChoices.setId(examSubjectChoicesVOSList.get(0).getId());
                    examSubjectChoicesVO = examSubjectChoicesService.selectExamSubjectChoicesInfo(examSubjectChoices);
                }
 
                //5.数据封装
                map.put("simulateExamRecord",simulateExamRecord1);
                map.put("examSubjectInfo",examSubjectChoicesVOSList);
                map.put("simulateExamAnswerRecordList",simulateExamAnswerRecordList);
                map.put("examSubjectChoicesVO",examSubjectChoicesVO);
 
                //6.返回数据
                return map;
            }
 
            //2. 放弃之前的考试,重新获取题目返回
            if (simulateExamRecord.getType().equals(2)){
                SimulateExamRecord examRecord = this.getById(simulateExamRecord.getId());
                //修改当前模拟考试状态为废弃
                examRecord.setStatus(4);
                //修改信息
                this.updateById(examRecord);
                //重新获取题目
                SimulateExamRecord simulateExamRecord1 = new SimulateExamRecord();
                simulateExamRecord1.setIdCardNo(examRecord.getIdCardNo());
                //去获取题目
                return insertSimulateExamRecord(simulateExamRecord1);
            }
        }
        return null;
    }
}