|
@@ -8,12 +8,16 @@ import com.xhkjedu.sexam.model.paper.EPaperQtype;
|
8
|
8
|
import com.xhkjedu.sexam.model.paper.EPaperQtypeQuestion;
|
9
|
9
|
import com.xhkjedu.sexam.model.paperstudent.EPaperStudent;
|
10
|
10
|
import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
|
|
11
|
+import com.xhkjedu.sexam.utils.ConvertUtil;
|
11
|
12
|
import com.xhkjedu.sexam.utils.ExamUtil;
|
12
|
13
|
import com.xhkjedu.sexam.vo.paperstudent.EPaperStudentVo;
|
|
14
|
+import com.xhkjedu.sexam.vo.paperstudent.PaperStudentWebVo;
|
13
|
15
|
import com.xhkjedu.sexam.vo.paperstudent.PsqAnswerVo;
|
14
|
16
|
import com.xhkjedu.utils.N_Utils;
|
15
|
17
|
import lombok.extern.slf4j.Slf4j;
|
|
18
|
+import org.springframework.beans.factory.annotation.Autowired;
|
16
|
19
|
import org.springframework.stereotype.Service;
|
|
20
|
+import org.springframework.transaction.annotation.Transactional;
|
17
|
21
|
|
18
|
22
|
import javax.annotation.Resource;
|
19
|
23
|
import java.util.ArrayList;
|
|
@@ -34,6 +38,8 @@ public class EPaperStudentService {
|
34
|
38
|
private EPaperQtypeMapper ePaperQtypeMapper;
|
35
|
39
|
@Resource
|
36
|
40
|
private EPaperStudentQuestionMapper ePaperStudentQuestionMapper;
|
|
41
|
+ @Autowired
|
|
42
|
+ private ConvertUtil convertUtil;
|
37
|
43
|
|
38
|
44
|
/**
|
39
|
45
|
* @Description 学生进行中考试列表
|
|
@@ -166,116 +172,199 @@ public class EPaperStudentService {
|
166
|
172
|
try {
|
167
|
173
|
//学生作答提交时先判断试卷是否设置的正确答案
|
168
|
174
|
PsqAnswerVo answerVo = ePaperStudentQuestionMapper.getPaperQuestionAnswer(psq.getEpsqid());
|
169
|
|
- int timestamp = N_Utils.getSecondTimestamp();
|
170
|
|
- psq.setAnswertime(timestamp);
|
171
|
|
- int coverted = 1;//是否转换0未转换1已转换2转换失败
|
172
|
|
- String stuanswer = psq.getStuanswer();
|
173
|
|
- List<String> stuanswers = JSON.parseArray(stuanswer, String.class);
|
174
|
|
- Double stuscore = 0.0;
|
|
175
|
+ setCommitQuestion(psq,answerVo,1);
|
|
176
|
+ ePaperStudentQuestionMapper.updateStuAnswer(psq);
|
|
177
|
+ }catch (Exception e){
|
|
178
|
+ log.error("提交试题失败:"+e.getMessage());
|
|
179
|
+ throw new Exception("提交试题失败");
|
|
180
|
+ }
|
175
|
181
|
|
176
|
|
- if(N_Utils.isListEmpty(stuanswers) && N_Utils.isEmpty(psq.getStuanswertxt())
|
177
|
|
- && N_Utils.isEmpty(psq.getStuanswertxt())){
|
178
|
|
- psq.setStuscore(stuscore);
|
179
|
|
- psq.setChecked(2);
|
180
|
|
- psq.setChecktime(timestamp);
|
181
|
|
- psq.setAnswered(0);
|
182
|
|
- }else{
|
183
|
|
- //试卷已经设置了正确答案
|
184
|
|
- if (answerVo.getAnswered() == 1){
|
185
|
|
- String qanswer = answerVo.getAnswer();
|
186
|
|
- List<String> qanswers = JSON.parseArray(qanswer,String.class);
|
187
|
|
- if(N_Utils.isListEmpty(stuanswers) && N_Utils.isEmpty(psq.getStuanswertxt())
|
188
|
|
- && N_Utils.isEmpty(psq.getStuanswertxt())){
|
189
|
|
- psq.setStuscore(stuscore);
|
190
|
|
- psq.setChecked(1);
|
191
|
|
- psq.setChecktime(timestamp);
|
192
|
|
- psq.setAnswered(0);
|
193
|
|
- }else{
|
194
|
|
- int ctype = answerVo.getCtype();
|
195
|
|
- if(N_Utils.isObjectiveQuestion(ctype)){
|
196
|
|
- //客观题进行批阅
|
197
|
|
- if(ctype == 1 || ctype == 4 || ctype == 5 || ctype == 6){
|
198
|
|
- //单选、判断
|
199
|
|
- if(stuanswer.equalsIgnoreCase(qanswer)) {
|
200
|
|
- stuscore = answerVo.getScore();
|
201
|
|
- }
|
202
|
|
- }else if(ctype == 2){//多选
|
203
|
|
- //多选、选错不得分
|
204
|
|
- if(stuanswers.get(0).length() <= qanswer.length()){
|
205
|
|
- String[] qanswerList = qanswers.get(0).split("");
|
206
|
|
- String[] stuanswerList = stuanswers.get(0).split("");
|
207
|
|
- int rightNum = 0;//选对个数
|
208
|
|
- for(String sa : stuanswerList){
|
209
|
|
- int right = 0;
|
210
|
|
- for(String qa : qanswerList){
|
211
|
|
- if(qa.equals(sa)){
|
212
|
|
- right = 1;
|
213
|
|
- rightNum ++;
|
214
|
|
- }
|
215
|
|
- }
|
216
|
|
- if(right == 0){//说明选错
|
217
|
|
- rightNum = 0;
|
218
|
|
- break;
|
|
182
|
+ }
|
|
183
|
+
|
|
184
|
+ //判断但道题情况
|
|
185
|
+ private void setCommitQuestion(EPaperStudentQuestion psq,PsqAnswerVo answerVo,Integer type){
|
|
186
|
+ int timestamp = N_Utils.getSecondTimestamp();
|
|
187
|
+ psq.setAnswertime(timestamp);
|
|
188
|
+ int coverted = 1;//是否转换0未转换1已转换2转换失败
|
|
189
|
+ String stuanswer = psq.getStuanswer();
|
|
190
|
+ List<String> stuanswers = JSON.parseArray(stuanswer, String.class);
|
|
191
|
+ Double stuscore = 0D;
|
|
192
|
+
|
|
193
|
+ if(N_Utils.isListEmpty(stuanswers) && N_Utils.isEmpty(psq.getStuanswertxt())
|
|
194
|
+ && N_Utils.isEmpty(psq.getStuanswertxt())){
|
|
195
|
+ psq.setStuscore(stuscore);
|
|
196
|
+ psq.setChecked(2);
|
|
197
|
+ psq.setChecktime(timestamp);
|
|
198
|
+ psq.setAnswered(0);
|
|
199
|
+ }else{
|
|
200
|
+ //试卷已经设置了正确答案
|
|
201
|
+ if (answerVo.getAnswered() == 1){
|
|
202
|
+ String qanswer = answerVo.getAnswer();
|
|
203
|
+ List<String> qanswers = JSON.parseArray(qanswer,String.class);
|
|
204
|
+ if(N_Utils.isListEmpty(stuanswers) && N_Utils.isEmpty(psq.getStuanswertxt())
|
|
205
|
+ && N_Utils.isEmpty(psq.getStuanswertxt())){
|
|
206
|
+ psq.setStuscore(stuscore);
|
|
207
|
+ psq.setChecked(1);
|
|
208
|
+ psq.setChecktime(timestamp);
|
|
209
|
+ psq.setAnswered(0);
|
|
210
|
+ }else{
|
|
211
|
+ int ctype = answerVo.getCtype();
|
|
212
|
+ if(N_Utils.isObjectiveQuestion(ctype)){
|
|
213
|
+ //客观题进行批阅
|
|
214
|
+ if(ctype == 1 || ctype == 4 || ctype == 5 || ctype == 6){
|
|
215
|
+ //单选、判断
|
|
216
|
+ if(stuanswer.equalsIgnoreCase(qanswer)) {
|
|
217
|
+ stuscore = answerVo.getScore();
|
|
218
|
+ }
|
|
219
|
+ }else if(ctype == 2){//多选
|
|
220
|
+ //多选、选错不得分
|
|
221
|
+ if(stuanswers.get(0).length() <= qanswer.length()){
|
|
222
|
+ String[] qanswerList = qanswers.get(0).split("");
|
|
223
|
+ String[] stuanswerList = stuanswers.get(0).split("");
|
|
224
|
+ int rightNum = 0;//选对个数
|
|
225
|
+ for(String sa : stuanswerList){
|
|
226
|
+ int right = 0;
|
|
227
|
+ for(String qa : qanswerList){
|
|
228
|
+ if(qa.equals(sa)){
|
|
229
|
+ right = 1;
|
|
230
|
+ rightNum ++;
|
219
|
231
|
}
|
220
|
232
|
}
|
221
|
|
- if(rightNum>0){
|
222
|
|
- if(qanswerList.length == rightNum){
|
223
|
|
- //全选对
|
224
|
|
- stuscore = answerVo.getScore();
|
225
|
|
- }else if (qanswerList.length > rightNum){
|
226
|
|
- //少选得半分
|
227
|
|
- stuscore = ExamUtil.div(answerVo.getScore(),2,1);
|
228
|
|
- }
|
|
233
|
+ if(right == 0){//说明选错
|
|
234
|
+ rightNum = 0;
|
|
235
|
+ break;
|
229
|
236
|
}
|
230
|
237
|
}
|
231
|
|
- }else if(ctype == 7 || ctype == 8 || ctype == 10){
|
232
|
|
- //完形填空、阅读理解、任务型阅读
|
233
|
|
- Double qscore = ExamUtil.div(answerVo.getScore(),qanswers.size());
|
234
|
|
- Double stuScoreDouble = 0d;
|
235
|
|
- for(int i=0;i<qanswers.size();i++){
|
236
|
|
- if(qanswers.get(i).equalsIgnoreCase(stuanswers.get(i))){
|
237
|
|
- stuScoreDouble = ExamUtil.add(stuScoreDouble,qscore);
|
|
238
|
+ if(rightNum>0){
|
|
239
|
+ if(qanswerList.length == rightNum){
|
|
240
|
+ //全选对
|
|
241
|
+ stuscore = answerVo.getScore();
|
|
242
|
+ }else if (qanswerList.length > rightNum){
|
|
243
|
+ //少选得半分
|
|
244
|
+ stuscore = ExamUtil.div(answerVo.getScore(),2,1);
|
238
|
245
|
}
|
239
|
246
|
}
|
240
|
|
- stuscore = ExamUtil.round(stuScoreDouble,1);
|
241
|
247
|
}
|
242
|
|
- if(stuscore.compareTo(answerVo.getScore()) == 1){
|
243
|
|
- stuscore = answerVo.getScore();
|
|
248
|
+ }else if(ctype == 7 || ctype == 8 || ctype == 10){
|
|
249
|
+ //完形填空、阅读理解、任务型阅读
|
|
250
|
+ Double qscore = ExamUtil.div(answerVo.getScore(),qanswers.size());
|
|
251
|
+ Double stuScoreDouble = 0d;
|
|
252
|
+ for(int i=0;i<qanswers.size();i++){
|
|
253
|
+ if(qanswers.get(i).equalsIgnoreCase(stuanswers.get(i))){
|
|
254
|
+ stuScoreDouble = ExamUtil.add(stuScoreDouble,qscore);
|
|
255
|
+ }
|
244
|
256
|
}
|
245
|
|
- psq.setStuscore(stuscore);
|
246
|
|
- psq.setChecked(2);
|
247
|
|
- psq.setChecktime(timestamp);
|
248
|
|
- }else{
|
|
257
|
+ stuscore = ExamUtil.round(stuScoreDouble,1);
|
|
258
|
+ }
|
|
259
|
+ if(stuscore.compareTo(answerVo.getScore()) == 1){
|
|
260
|
+ stuscore = answerVo.getScore();
|
|
261
|
+ }
|
|
262
|
+ psq.setStuscore(stuscore);
|
|
263
|
+ psq.setChecked(2);
|
|
264
|
+ psq.setChecktime(timestamp);
|
|
265
|
+ }else{
|
249
|
266
|
|
250
|
|
- if(stuanswers.size() > 0){
|
251
|
|
- coverted = 0;//上传的多张图片设为0未转换
|
|
267
|
+ if(stuanswers.size() > 0){
|
|
268
|
+ coverted = 0;//上传的多张图片设为0未转换
|
|
269
|
+ if(type == 2){
|
|
270
|
+ //网页端提交试卷时直接合并多张图片试题
|
|
271
|
+ convertUtil.imgMerge(psq.getEptqid(),stuanswers,1);
|
252
|
272
|
}
|
253
|
273
|
}
|
254
|
|
- psq.setAnswered(1);
|
255
|
274
|
}
|
|
275
|
+ psq.setAnswered(1);
|
256
|
276
|
}
|
257
|
277
|
}
|
258
|
|
-
|
259
|
|
- Integer costtime = answerVo.getCosttime();
|
260
|
|
- if(costtime == null){
|
261
|
|
- costtime = 0;
|
262
|
|
- }
|
263
|
|
- psq.setCosttime(psq.getCosttime() + costtime);
|
264
|
|
- psq.setConverted(coverted);
|
265
|
|
- ePaperStudentQuestionMapper.updateStuAnswer(psq);
|
266
|
|
- }catch (Exception e){
|
267
|
|
- log.error("提交试题失败:"+e.getMessage());
|
268
|
|
- throw new Exception("提交试题失败");
|
269
|
278
|
}
|
270
|
279
|
|
|
280
|
+ Integer costtime = answerVo.getCosttime();
|
|
281
|
+ if(costtime == null){
|
|
282
|
+ costtime = 0;
|
|
283
|
+ }
|
|
284
|
+ psq.setCosttime(psq.getCosttime() + costtime);
|
|
285
|
+ psq.setConverted(coverted);
|
271
|
286
|
}
|
272
|
287
|
|
273
|
|
- public int saveCommitPaper(Integer epsid){
|
|
288
|
+ /**
|
|
289
|
+ * @Description 提交试卷
|
|
290
|
+ * @Param [epsid]
|
|
291
|
+ * @Return int
|
|
292
|
+ * @Author wn
|
|
293
|
+ * @Date 2022/7/28 16:59
|
|
294
|
+ **/
|
|
295
|
+ @Transactional(rollbackFor = Exception.class)
|
|
296
|
+ public void saveCommitPaper(Integer epsid){
|
274
|
297
|
EPaperStudent ps = ePaperStudentMapper.selectByPrimaryKey(epsid);
|
275
|
298
|
if(ps == null || ps.getSstate() == 1){
|
276
|
|
- return 1;
|
|
299
|
+ return;
|
|
300
|
+ }
|
|
301
|
+ EPaperStudent paperStudent = new EPaperStudent();
|
|
302
|
+ paperStudent.setEpsid(epsid);
|
|
303
|
+ paperStudent.setSstate(2);
|
|
304
|
+
|
|
305
|
+ //更改试卷中学生未提交的试题设置为0分,标记为已批改
|
|
306
|
+ ePaperStudentQuestionMapper.updateStuQuesitonNoCommit(epsid);
|
|
307
|
+ //获取试卷中未批阅试题数量
|
|
308
|
+ int noCheckNum = ePaperStudentQuestionMapper.getStuQuestionNoCheckNum(epsid);
|
|
309
|
+ int checked = 0;
|
|
310
|
+ if(noCheckNum == 0){
|
|
311
|
+ checked = 1;//试卷中所有试题都批完后标识试卷已批改
|
|
312
|
+ }
|
|
313
|
+ paperStudent.setChecked(checked);
|
|
314
|
+ ePaperStudentMapper.updateStudentPaper(paperStudent);//修改试卷信息
|
|
315
|
+ List<EPaperStudentQuestion> psqlist = ePaperStudentQuestionMapper.listStuQuesitonStuAnswerPic(epsid);
|
|
316
|
+ if(N_Utils.isListNotEmpty(psqlist)){
|
|
317
|
+ for(EPaperStudentQuestion sq : psqlist){
|
|
318
|
+ List<String> stuanswer = JSON.parseArray(sq.getStuanswer(),String.class);
|
|
319
|
+ if(N_Utils.isListNotEmpty(stuanswer) && stuanswer.size()>1){
|
|
320
|
+ convertUtil.imgMerge(sq.getEpsqid(),stuanswer,1);
|
|
321
|
+ }
|
|
322
|
+ }
|
|
323
|
+ }
|
|
324
|
+ }
|
|
325
|
+
|
|
326
|
+ /**
|
|
327
|
+ * @Description 提交试卷、试题(网页端)
|
|
328
|
+ * @Param [pswvo]
|
|
329
|
+ * @Return void
|
|
330
|
+ * @Author wn
|
|
331
|
+ * @Date 2022/7/28 19:18
|
|
332
|
+ **/
|
|
333
|
+ public void saveCommitPaperForWeb(PaperStudentWebVo pswvo){
|
|
334
|
+ List<EPaperStudentQuestion> sqlist = pswvo.getQuestions();//学生提交试卷中试题
|
|
335
|
+ EPaperStudent ps = ePaperStudentMapper.selectByPrimaryKey(pswvo.getEpsid());
|
|
336
|
+ //试卷不存在或者已提交
|
|
337
|
+ if(ps == null || ps.getSstate() == 1){
|
|
338
|
+ return;
|
277
|
339
|
}
|
278
|
|
- return 1;
|
|
340
|
+ //获取试卷中所有试题答案及分值
|
|
341
|
+ List<PsqAnswerVo> anvolist = ePaperStudentQuestionMapper.listPaperQuestionsAnswer(pswvo.getEpsid());
|
|
342
|
+ Integer checknum = 0;//记录试卷中试题批阅数量
|
|
343
|
+ Double paperscore = 0D;//学生试卷得分
|
|
344
|
+ for(EPaperStudentQuestion q : sqlist){
|
|
345
|
+
|
|
346
|
+ //获取该试题正确答案
|
|
347
|
+ PsqAnswerVo anvo = anvolist.stream().filter(a -> a.getEptqid().equals(q.getEptqid())).findFirst().orElse(null);
|
|
348
|
+
|
|
349
|
+ setCommitQuestion(q,anvo,2);
|
|
350
|
+ if(q.getChecked() == 2){
|
|
351
|
+ checknum ++;
|
|
352
|
+ }
|
|
353
|
+ paperscore = ExamUtil.add(paperscore, q.getStuscore());
|
|
354
|
+ }
|
|
355
|
+ EPaperStudent paperStudent = new EPaperStudent();
|
|
356
|
+ paperStudent.setEpsid(pswvo.getEpsid());
|
|
357
|
+ paperStudent.setEndtime(N_Utils.getSecondTimestamp());
|
|
358
|
+ paperStudent.setSstate(2);
|
|
359
|
+ paperStudent.setStuscore(paperscore);
|
|
360
|
+ int checked = 0;
|
|
361
|
+ if(checknum == sqlist.size()){
|
|
362
|
+ checked = 1;
|
|
363
|
+ }
|
|
364
|
+ paperStudent.setChecked(checked);
|
|
365
|
+
|
|
366
|
+ ePaperStudentQuestionMapper.updateBatchStuQuestion(sqlist);
|
|
367
|
+ ePaperStudentMapper.updateStudentPaper(paperStudent);
|
279
|
368
|
}
|
280
|
369
|
|
281
|
370
|
}
|