|
@@ -10,8 +10,10 @@ import com.xhkjedu.smarking.model.exam.*;
|
10
|
10
|
import com.xhkjedu.smarking.model.paper.MsPaper;
|
11
|
11
|
import com.xhkjedu.smarking.model.paper.MsPaperQtypeQuestion;
|
12
|
12
|
import com.xhkjedu.smarking.model.stupaper.*;
|
|
13
|
+import com.xhkjedu.smarking.utils.MarkingUtil;
|
13
|
14
|
import com.xhkjedu.smarking.vo.exam.EBaseVo;
|
14
|
15
|
import com.xhkjedu.utils.N_Utils;
|
|
16
|
+import com.xhkjedu.vo.ResultVo;
|
15
|
17
|
import com.xhkjedu.vo.system.UserVo;
|
16
|
18
|
import lombok.extern.slf4j.Slf4j;
|
17
|
19
|
import org.springframework.stereotype.Service;
|
|
@@ -76,8 +78,46 @@ public class MsExamService {
|
76
|
78
|
|
77
|
79
|
//保存考试基本信息
|
78
|
80
|
private void saveExam(MsExam model, Integer examid) {
|
79
|
|
- List<Integer> classids = model.getClassids();
|
80
|
81
|
List<MsSubject> subjects = model.getSubjects();
|
|
82
|
+ List<String> subjectids = subjects.stream().map(MsSubject::getSubjectid).collect(Collectors.toList());
|
|
83
|
+ saveClassAndStudent(model, examid, subjectids);//保存考试班级和学生
|
|
84
|
+
|
|
85
|
+ //考试科目
|
|
86
|
+ Integer schoolid = model.getSchoolid();
|
|
87
|
+ List<MsPaper> papers = new ArrayList<>();//考试试卷
|
|
88
|
+ for (MsSubject s : subjects) {
|
|
89
|
+ s.setSchoolid(schoolid);
|
|
90
|
+ s.setExamid(examid);
|
|
91
|
+ s.setMsstate(0);
|
|
92
|
+
|
|
93
|
+ MsPaper p = new MsPaper();
|
|
94
|
+ p.setExamid(examid);
|
|
95
|
+ p.setSubjectid(s.getSubjectid());
|
|
96
|
+ p.setPtype(0);
|
|
97
|
+ p.setPnum(0);
|
|
98
|
+ p.setMergepnum(0);
|
|
99
|
+ p.setPscore(0.0);
|
|
100
|
+ p.setAnswered(0);
|
|
101
|
+ p.setHasfile(0);
|
|
102
|
+ p.setHearnum(0);
|
|
103
|
+ papers.add(p);
|
|
104
|
+ }
|
|
105
|
+ msSubjectMapper.insertList(subjects);//考试科目
|
|
106
|
+
|
|
107
|
+ Integer createid = model.getCreateid();
|
|
108
|
+ Integer createtime = model.getCreatetime();
|
|
109
|
+ for (int i = 0; i < papers.size(); i++) {
|
|
110
|
+ MsPaper ePaper = papers.get(i);
|
|
111
|
+ ePaper.setMsid(subjects.get(i).getId());
|
|
112
|
+ ePaper.setCreateid(createid);
|
|
113
|
+ ePaper.setCreatetime(createtime);
|
|
114
|
+ }
|
|
115
|
+ msPaperMapper.insertList(papers);//考试试卷
|
|
116
|
+ }
|
|
117
|
+
|
|
118
|
+ //保存考试班级和学生
|
|
119
|
+ private void saveClassAndStudent(MsExam model, Integer examid, List<String> subjectids) {
|
|
120
|
+ List<Integer> classids = model.getClassids();
|
81
|
121
|
if (N_Utils.isListNotEmpty(classids)) {
|
82
|
122
|
if (!model.getExammode().equals(3)) {//线下考试必须有考号
|
83
|
123
|
Integer num = msClassStudentMapper.getNoExamNoNumByClassIds(classids);//根据班级ids获取没有考号学生数量
|
|
@@ -94,10 +134,7 @@ public class MsExamService {
|
94
|
134
|
List<MsClassStudent> studentList = msClassStudentMapper.listByClassIds(classids);
|
95
|
135
|
List<MsClass> classes = new ArrayList<>();
|
96
|
136
|
List<MsClassStudent> students = new ArrayList<>();
|
97
|
|
- Integer schoolid = model.getSchoolid();
|
98
|
|
- for (MsSubject s : subjects) {
|
99
|
|
- s.setSchoolid(schoolid);
|
100
|
|
- String subjectid = s.getSubjectid();
|
|
137
|
+ for (String subjectid : subjectids) {
|
101
|
138
|
for (MsClass c : classList) {
|
102
|
139
|
MsClass c1 = new MsClass();
|
103
|
140
|
c1.setExamid(examid);
|
|
@@ -122,36 +159,6 @@ public class MsExamService {
|
122
|
159
|
//考试学生
|
123
|
160
|
if (N_Utils.isListNotEmpty(students)) msClassStudentMapper.insertList(students);
|
124
|
161
|
}
|
125
|
|
-
|
126
|
|
- //考试科目
|
127
|
|
- List<MsPaper> papers = new ArrayList<>();//考试试卷
|
128
|
|
- for (MsSubject s : subjects) {
|
129
|
|
- s.setExamid(examid);
|
130
|
|
- s.setMsstate(0);
|
131
|
|
-
|
132
|
|
- MsPaper p = new MsPaper();
|
133
|
|
- p.setExamid(examid);
|
134
|
|
- p.setSubjectid(s.getSubjectid());
|
135
|
|
- p.setPtype(0);
|
136
|
|
- p.setPnum(0);
|
137
|
|
- p.setMergepnum(0);
|
138
|
|
- p.setPscore(0.0);
|
139
|
|
- p.setAnswered(0);
|
140
|
|
- p.setHasfile(0);
|
141
|
|
- p.setHearnum(0);
|
142
|
|
- papers.add(p);
|
143
|
|
- }
|
144
|
|
- msSubjectMapper.insertList(subjects);//考试科目
|
145
|
|
-
|
146
|
|
- Integer createid = model.getCreateid();
|
147
|
|
- Integer createtime = model.getCreatetime();
|
148
|
|
- for (int i = 0; i < papers.size(); i++) {
|
149
|
|
- MsPaper ePaper = papers.get(i);
|
150
|
|
- ePaper.setMsid(subjects.get(i).getId());
|
151
|
|
- ePaper.setCreateid(createid);
|
152
|
|
- ePaper.setCreatetime(createtime);
|
153
|
|
- }
|
154
|
|
- msPaperMapper.insertList(papers);//考试试卷
|
155
|
162
|
}
|
156
|
163
|
|
157
|
164
|
/**
|
|
@@ -302,4 +309,68 @@ public class MsExamService {
|
302
|
309
|
}
|
303
|
310
|
return msClassMapper.listSchoolClass(schoolid, year, teacherid);
|
304
|
311
|
}
|
|
312
|
+
|
|
313
|
+ /**
|
|
314
|
+ * @Description 删除
|
|
315
|
+ * @Date 2024/11/25 16:46
|
|
316
|
+ * @Author YWX
|
|
317
|
+ * @Param [examid]
|
|
318
|
+ * @Return void
|
|
319
|
+ **/
|
|
320
|
+ public void deleteById(Integer examid) {
|
|
321
|
+ msExamMapper.deleteById(examid);
|
|
322
|
+ }
|
|
323
|
+
|
|
324
|
+ /**
|
|
325
|
+ * @Description 取消发布
|
|
326
|
+ * @Date 2024/11/25 17:33
|
|
327
|
+ * @Author YWX
|
|
328
|
+ * @Param [examid]
|
|
329
|
+ * @Return void
|
|
330
|
+ **/
|
|
331
|
+ @Transactional(rollbackFor = Exception.class)
|
|
332
|
+ public void qxFb(Integer examid) {
|
|
333
|
+ EBaseVo exam = msExamMapper.getExamStateById(examid);
|
|
334
|
+ Long timestamp = Long.valueOf(N_Utils.getSecondTimestamp() + 30 * 60);
|
|
335
|
+ Long begintime = MarkingUtil.strToTimestamp(exam.getStrtime());
|
|
336
|
+ if (begintime != 0 && begintime.compareTo(timestamp) != 1) throw new ServiceException("开考前30分钟禁止取消发布");
|
|
337
|
+ msPaperStudentMapper.deleteByExamId(examid);//删除考试学生信息
|
|
338
|
+ msExamMapper.updateExamState(examid, 0);//更新考试状态
|
|
339
|
+ }
|
|
340
|
+
|
|
341
|
+ /**
|
|
342
|
+ * @Description 修改
|
|
343
|
+ * @Date 2024/11/25 17:13
|
|
344
|
+ * @Author YWX
|
|
345
|
+ * @Param [model]
|
|
346
|
+ * @Return com.xhkjedu.vo.ResultVo
|
|
347
|
+ **/
|
|
348
|
+ @Transactional(rollbackFor = Exception.class)
|
|
349
|
+ public ResultVo update(MsExam model) {
|
|
350
|
+ EBaseVo exam = msExamMapper.getExamStateById(model.getExamid());
|
|
351
|
+ if (0 != exam.getExamstate()) return new ResultVo(1, "考试已发布禁止操作");
|
|
352
|
+ Long timestamp = Long.valueOf(N_Utils.getSecondTimestamp() + 30 * 60);
|
|
353
|
+ Long begintime = MarkingUtil.strToTimestamp(exam.getStrtime());
|
|
354
|
+ if (begintime != 0 && begintime.compareTo(timestamp) != 1) return new ResultVo(1, "开考前30分钟禁止编辑");
|
|
355
|
+ //禁止修改年级、科目、考试模式
|
|
356
|
+ model.setGradeid(null);
|
|
357
|
+ model.setExammode(null);
|
|
358
|
+ msExamMapper.updateByPrimaryKeySelective(model);
|
|
359
|
+ Integer examid = model.getExamid();
|
|
360
|
+ List<Integer> classids = model.getClassids();
|
|
361
|
+ //班级集合为空不处理班级
|
|
362
|
+ if (N_Utils.isListEmpty(classids)) return new ResultVo(0, "修改成功");
|
|
363
|
+ msExamMapper.deleteClassById(examid);//删除关联的班级
|
|
364
|
+ List<String> subjectids = msSubjectMapper.listSubjectIdsByExamId(examid);
|
|
365
|
+ saveClassAndStudent(model, examid, subjectids);//保存考试班级和学生
|
|
366
|
+
|
|
367
|
+ return new ResultVo(0, "修改成功");
|
|
368
|
+ }
|
|
369
|
+
|
|
370
|
+ public Map findById(Integer examid) {
|
|
371
|
+ Map map = msExamMapper.findById(examid);
|
|
372
|
+ map.put("subjects", msSubjectMapper.listByExamId(examid));
|
|
373
|
+ map.put("classes", msClassMapper.listByExamId(examid,null));
|
|
374
|
+ return map;
|
|
375
|
+ }
|
305
|
376
|
}
|