Browse Source

提交试卷

tags/正式版本
王宁 2 years ago
parent
commit
ff017f69b4

+ 32
- 1
sexam/src/main/java/com/xhkjedu/sexam/controller/paperstudent/EPaperStudentController.java View File

@@ -2,15 +2,16 @@ package com.xhkjedu.sexam.controller.paperstudent;
2 2
 
3 3
 import com.github.pagehelper.PageHelper;
4 4
 import com.github.pagehelper.PageInfo;
5
-import com.xhkjedu.sexam.model.paper.EPaperQtype;
6 5
 import com.xhkjedu.sexam.model.paperstudent.EPaperStudent;
7 6
 import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
8 7
 import com.xhkjedu.sexam.service.paperstudent.EPaperStudentService;
9 8
 import com.xhkjedu.sexam.vo.paperstudent.EPaperStudentVo;
9
+import com.xhkjedu.sexam.vo.paperstudent.PaperStudentWebVo;
10 10
 import com.xhkjedu.utils.N_Utils;
11 11
 import com.xhkjedu.utils.PageUtil;
12 12
 import com.xhkjedu.vo.PageResult;
13 13
 import com.xhkjedu.vo.ResultVo;
14
+import lombok.extern.slf4j.Slf4j;
14 15
 import org.springframework.web.bind.annotation.PostMapping;
15 16
 import org.springframework.web.bind.annotation.RequestBody;
16 17
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -27,6 +28,7 @@ import java.util.Map;
27 28
  **/
28 29
 @RestController
29 30
 @RequestMapping("/eps")
31
+@Slf4j
30 32
 public class EPaperStudentController {
31 33
     @Resource
32 34
     private EPaperStudentService ePaperStudentService;
@@ -76,6 +78,35 @@ public class EPaperStudentController {
76 78
            return new ResultVo(1,"提交试题失败");
77 79
        }
78 80
     }
81
+    //提交试卷
82
+    @PostMapping("/scp")
83
+    public ResultVo saveCommitPaper(@RequestBody EPaperStudent ps){
84
+        try {
85
+            N_Utils.validation(new Object[]{ps.getEpsid(),"试卷id",1});
86
+            ePaperStudentService.saveCommitPaper(ps.getEpsid());
87
+            return new ResultVo(0,"成功提交试卷");
88
+        }catch (Exception e){
89
+            log.error("提交试卷失败:"+e.getMessage());
90
+            return new ResultVo(1,"提交失败");
91
+        }
92
+    }
93
+
94
+    //提交试卷--网页端
95
+    @PostMapping("/scpw")
96
+    public ResultVo saveCommitPaperWeb(@RequestBody PaperStudentWebVo ps){
97
+        try {
98
+            N_Utils.validation(new Object[]{ps.getEpsid(),"试卷id",1});
99
+            List<EPaperStudentQuestion> qlist = ps.getQuestions();
100
+            if(N_Utils.isListEmpty(qlist)){
101
+                return new ResultVo(1,"试题");
102
+            }
103
+            ePaperStudentService.saveCommitPaperForWeb(ps);
104
+            return new ResultVo(0,"成功提交试卷");
105
+        }catch (Exception e){
106
+            log.error("提交试卷(web)失败:"+e.getMessage());
107
+            return new ResultVo(1,"提交失败");
108
+        }
109
+    }
79 110
 
80 111
 
81 112
 

+ 55
- 0
sexam/src/main/java/com/xhkjedu/sexam/listener/MessageConsumer.java View File

@@ -0,0 +1,55 @@
1
+package com.xhkjedu.sexam.listener;
2
+
3
+import com.alibaba.fastjson.JSON;
4
+import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentQuestionMapper;
5
+import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
6
+import com.xhkjedu.utils.N_Utils;
7
+import lombok.extern.slf4j.Slf4j;
8
+import org.springframework.amqp.core.Message;
9
+import org.springframework.amqp.rabbit.annotation.RabbitHandler;
10
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
11
+import org.springframework.stereotype.Component;
12
+
13
+import javax.annotation.Resource;
14
+import java.time.LocalDateTime;
15
+
16
+/**
17
+ * 消息到达消费者监听类
18
+ */
19
+@Component
20
+@Slf4j
21
+public class MessageConsumer {
22
+
23
+    @Resource
24
+    private EPaperStudentQuestionMapper ePaperStudentQuestionMapper;
25
+
26
+
27
+
28
+    /*
29
+     * 学生答案图片合并完处理转换状态
30
+     *
31
+     * @param [message]
32
+     * @return void
33
+     * @author ywx
34
+     * @date 2022/5/9 13:44
35
+     */
36
+
37
+    @RabbitHandler
38
+    @RabbitListener(queues = "${rabbitmq.examImgMergeHandleQueue}")
39
+    public void imgMergeHandleQueue(Message message) {
40
+        try {
41
+            String msg = new String(message.getBody(), "UTF-8");
42
+            System.out.println(LocalDateTime.now() + "学生试题答案合并接收消息内容:" + msg);
43
+            EPaperStudentQuestion psq = JSON.parseObject(msg, EPaperStudentQuestion.class);
44
+            psq.setDevice(null);
45
+            if (psq.getConverted() != 1) {//合并失败不修改学生答案
46
+                psq.setStuanswer(null);
47
+            } else {
48
+                psq.setStuanswer(JSON.toJSONString(new String[]{psq.getStuanswer()}));
49
+            }
50
+            ePaperStudentQuestionMapper.updateByPrimaryKeySelective(psq);
51
+        } catch (Exception e) {
52
+            log.error("学生试题答案合并失败:" + e.getMessage());
53
+        }
54
+    }
55
+}

+ 42
- 0
sexam/src/main/java/com/xhkjedu/sexam/listener/MessageSender.java View File

@@ -0,0 +1,42 @@
1
+package com.xhkjedu.sexam.listener;
2
+
3
+import com.alibaba.fastjson.JSON;
4
+import org.springframework.amqp.core.AmqpTemplate;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.beans.factory.annotation.Value;
7
+import org.springframework.stereotype.Component;
8
+
9
+import java.util.HashMap;
10
+import java.util.List;
11
+import java.util.Map;
12
+
13
+/**
14
+ * @author ywx
15
+ * @className MessageSender
16
+ * @description
17
+ * @date 2021/10/25 14:28
18
+ **/
19
+@Component
20
+public class MessageSender {
21
+    @Autowired
22
+    private AmqpTemplate rabbitTemplate;
23
+
24
+    @Value("${rabbitmq.examImgMergeQueue}")
25
+    private String examImgMergeQueue;
26
+
27
+
28
+    /**
29
+     * @Description 学生答案合并
30
+     * @Param [epsqid, userAnswers, device]
31
+     * @Return void
32
+     * @Author wn
33
+     * @Date 2022/7/28 16:46
34
+     **/
35
+    public void imgMerge(Integer epsqid, List<String> userAnswers, Integer device) {
36
+        Map map = new HashMap();
37
+        map.put("epsqid", epsqid);
38
+        map.put("userAnswers", userAnswers);
39
+        map.put("device", device);
40
+        rabbitTemplate.convertAndSend(examImgMergeQueue, JSON.toJSONString(map));
41
+    }
42
+}

+ 3
- 0
sexam/src/main/java/com/xhkjedu/sexam/mapper/paperstudent/EPaperStudentMapper.java View File

@@ -39,4 +39,7 @@ public interface EPaperStudentMapper extends TkMapper<EPaperStudent> {
39 39
 
40 40
     //学生试卷附件(web)
41 41
     List<EPaperQtype> listStuPaperFjQuestionsForWeb(@Param("epsid")Integer epsid);
42
+
43
+    //学生提交试卷
44
+    int updateStudentPaper(@Param("ps")EPaperStudent ps);
42 45
 }

+ 17
- 0
sexam/src/main/java/com/xhkjedu/sexam/mapper/paperstudent/EPaperStudentQuestionMapper.java View File

@@ -7,6 +7,8 @@ import com.xhkjedu.sexam.vo.paperstudent.PsqAnswerVo;
7 7
 import org.apache.ibatis.annotations.Param;
8 8
 import org.springframework.stereotype.Repository;
9 9
 
10
+import java.util.List;
11
+
10 12
 /**
11 13
  * @Description 学生试卷试题
12 14
  * @Author WN
@@ -20,4 +22,19 @@ public interface EPaperStudentQuestionMapper extends TkMapper<EPaperStudentQuest
20 22
 
21 23
     //提交单题
22 24
     void updateStuAnswer(@Param("q")EPaperStudentQuestion q);
25
+
26
+    //处理学生未提交试题
27
+    void updateStuQuesitonNoCommit(@Param("epsid")Integer epsid);
28
+
29
+    //学生作业未批改试题数量
30
+    Integer getStuQuestionNoCheckNum(@Param("epsid")Integer epsid);
31
+
32
+    //获取试卷中未合并图片
33
+    List<EPaperStudentQuestion> listStuQuesitonStuAnswerPic(@Param("epsid")Integer epsid);
34
+
35
+    //获取试卷中所有试题正确答案及分值
36
+    List<PsqAnswerVo> listPaperQuestionsAnswer(@Param("epsid")Integer epsid);
37
+
38
+    //批量提交试题
39
+    void updateBatchStuQuestion(@Param("list")List<EPaperStudentQuestion> list);
23 40
 }

+ 0
- 3
sexam/src/main/java/com/xhkjedu/sexam/model/paper/EPaperQtypeQuestion.java View File

@@ -56,9 +56,6 @@ public class EPaperQtypeQuestion extends BaseBean {
56 56
     //作文格数
57 57
     private Integer gnum;
58 58
 
59
-    //答题区
60
-    private String dtq;
61
-
62 59
     //难易度
63 60
     @Transient
64 61
     private Integer complexity;

+ 9
- 0
sexam/src/main/java/com/xhkjedu/sexam/service/paper/EPaperQtypeService.java View File

@@ -137,6 +137,15 @@ public class EPaperQtypeService {
137 137
                 if(q.getOptionnum()==null){
138 138
                     q.setOptionnum(0);
139 139
                 }
140
+                if(epaper.getPtype() == 1){
141
+                    q.setQn(q.getQorder().toString());
142
+                }
143
+                if(q.getCtype() == 14){
144
+                    q.setGnum(900);//语文作文格数
145
+                }else if(q.getCtype() == 15){
146
+                    q.setGnum(10);//英语作文行数
147
+                }
148
+
140 149
                 qtqs.add(q);
141 150
             }
142 151
         }

+ 177
- 88
sexam/src/main/java/com/xhkjedu/sexam/service/paperstudent/EPaperStudentService.java View File

@@ -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
 }

+ 31
- 0
sexam/src/main/java/com/xhkjedu/sexam/utils/ConvertUtil.java View File

@@ -0,0 +1,31 @@
1
+package com.xhkjedu.sexam.utils;
2
+
3
+import com.xhkjedu.sexam.listener.MessageSender;
4
+import org.springframework.beans.factory.annotation.Autowired;
5
+import org.springframework.stereotype.Component;
6
+import java.util.List;
7
+
8
+/**
9
+ * @author ywx
10
+ * @classname ConvertUtil
11
+ * @description 文件转换工具类
12
+ * @date 2021/10/27 9:32
13
+ **/
14
+@Component
15
+public class ConvertUtil {
16
+    @Autowired
17
+    private MessageSender messageSender;
18
+
19
+    /**
20
+     * 学生答案图片合并mq
21
+     *
22
+     * @param [psqid, userAnswers, device(1线上线下2答题卡)]
23
+     * @return void
24
+     * @author ywx
25
+     * @date 2022/5/9 14:57
26
+     */
27
+    public void imgMerge(Integer psqid, List<String> userAnswers, Integer device) {
28
+        messageSender.imgMerge(psqid, userAnswers, device);
29
+    }
30
+
31
+}

+ 23
- 0
sexam/src/main/java/com/xhkjedu/sexam/vo/paperstudent/PaperStudentWebVo.java View File

@@ -0,0 +1,23 @@
1
+package com.xhkjedu.sexam.vo.paperstudent;
2
+
3
+import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
4
+import lombok.Data;
5
+
6
+import java.util.List;
7
+
8
+/**
9
+ * @Description
10
+ * @Author WN
11
+ * Date 2022/7/28 17:15
12
+ **/
13
+@Data
14
+public class PaperStudentWebVo {
15
+    //试卷学生id
16
+    private Integer epsid;
17
+
18
+    //花费时间
19
+    private Integer costtime;
20
+
21
+    //试卷中试题
22
+    private List<EPaperStudentQuestion> questions;
23
+}

+ 4
- 0
sexam/src/main/resources/application.properties View File

@@ -51,6 +51,10 @@ spring.redis.jedis.pool.max-active=60000
51 51
 #缓存访问数据有效时长60*60*24*7
52 52
 redisdatatime=604800
53 53
 
54
+
55
+rabbitmq.examImgMergeQueue=xhkjedu.xhschool.examImgMergeQueue_dev
56
+rabbitmq.examImgMergeHandleQueue=xhkjedu.xhschool.examImgMergeHandleQueue_dev
57
+
54 58
 spring.rabbitmq.host=116.63.199.166
55 59
 spring.rabbitmq.port=5672
56 60
 spring.rabbitmq.username=xhkjedu

+ 2
- 8
sexam/src/main/resources/mapper/paper/EPaperQtypeMapper.xml View File

@@ -87,7 +87,6 @@
87 87
         where t.epid=#{epid} order by t.eptorder,q.qorder
88 88
     </select>
89 89
 
90
-
91 90
     <resultMap id="qtypesQuestionsForScan" type="java.util.Map">
92 91
         <result column="eptname" property="eptname"></result>
93 92
         <result column="ctype" property="ctype"></result>
@@ -99,10 +98,10 @@
99 98
             <result column="qctype" property="qctype"></result>
100 99
             <result column="score" property="score"></result>
101 100
             <result column="qorder" property="qorder"></result>
101
+            <result column="qn" property="qn"></result>
102 102
             <result column="optionnum" property="optionnum"></result>
103 103
             <result column="coord" property="coord"></result>
104 104
             <result column="gnum" property="gnum"></result>
105
-            <result column="dtq" property="dtq"></result>
106 105
             <result column="qoption" property="qoption"></result>
107 106
         </collection>
108 107
     </resultMap>
@@ -110,7 +109,7 @@
110 109
     <!--制作答题卡时获取试卷中试题-->
111 110
     <select id="listPaperqtypeQuestionsForScan" resultMap="qtypesQuestionsForScan">
112 111
         select t.eptname ,t.ctype,t.eptnum,t.eptorder,t.eptscore,
113
-        tq.eptqid,tq.ctype qctype,tq.score,tq.qorder,tq.optionnum,tq.coord,tq.gnum,tq.dtq,q.qoption
112
+        tq.eptqid,tq.ctype qctype,tq.score,tq.qorder,tq.qn,tq.optionnum,tq.coord,tq.gnum,q.qoption
114 113
         from e_paper_qtype_question tq  left join e_paper_qtype t on t.eptid=tq.eptid
115 114
         left join t_question q on tq.questionid=q.questionid
116 115
         where t.epid=#{epid} order by t.eptorder,tq.qorder,q.sorder
@@ -145,11 +144,6 @@
145 144
                     when eptqid=#{q.eptqid} then #{q.gnum}
146 145
                 </foreach>
147 146
             </trim>
148
-            <trim prefix="dtq = case" suffix="end,">
149
-                <foreach collection="list" item="q">
150
-                    when eptqid=#{q.eptqid} then #{q.dtq}
151
-                </foreach>
152
-            </trim>
153 147
         </trim>
154 148
         <where>
155 149
             <foreach collection="list" item="q" separator="or">

+ 8
- 0
sexam/src/main/resources/mapper/paperstudent/EPaperStudentMapper.xml View File

@@ -149,4 +149,12 @@
149 149
         left join e_paper_qtype pt on psq.epid=pt.epid
150 150
         where psq.epsid=#{epsid} order by pt.eptorder, psq.qorder
151 151
     </select>
152
+
153
+    <!--学生提交试卷-->
154
+    <update id="updateStudentPaper">
155
+        update t_paper_student set endtime=#{endtime},costtime=#{ps.costtime}
156
+         ,sstate=#{ps.sstate},checked=#{ps.checked}
157
+         ,stuscore=(SELECT SUM(IFNULL(q.stuscore,0)) FROM e_paper_student_question q WHERE q.epsid=#{ps.epsid})
158
+        where epsid=#{ps.epsid}
159
+    </update>
152 160
 </mapper>

+ 81
- 0
sexam/src/main/resources/mapper/paperstudent/EPaperStudentQuestionMapper.xml View File

@@ -16,4 +16,85 @@
16 16
         answertime=#{q.answertime},costtime=#{q.costtime},stuscore=#{q.stuscore},
17 17
         checked=#{q.checked},checkid=#{q.checkid},checktime=#{q.checktime} where epsqid=#{q.epsqid}
18 18
     </update>
19
+
20
+    <!--处理学生试卷中未提交试题-->
21
+    <update id="updateStuQuesitonNoCommit">
22
+        UPDATE e_paper_student_question SET costtime=0,checked=2,stuscore=0,checktime=UNIX_TIMESTAMP(NOW())
23
+        WHERE epsid=#{epsid} AND answered=0
24
+    </update>
25
+
26
+    <!--学生作业未批改试题数量-->
27
+    <select id="getStuQuestionNoCheckNum" resultType="java.lang.Integer">
28
+        SELECT count(*) FROM e_paper_student_question WHERE epsid=#{epsid} AND checked!=2
29
+    </select>
30
+
31
+    <!--获取试卷中未合并图片-->
32
+    <select id="listStuQuesitonStuAnswerPic" resultType="com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion">
33
+        select epsqid,stuanswer from e_paper_student_question
34
+        where epsid=#{epsid} and answertype=1 and converted=0
35
+    </select>
36
+
37
+    <!--获取试卷中所有试题正确答案及分值-->
38
+    <select id="listPaperQuestionsAnswer" resultType="com.xhkjedu.sexam.vo.paperstudent.PsqAnswerVo">
39
+        select distinct psq.eptqid,psq.costtime,ptq.ctype,ptq.score,ptq.answer,p.answered
40
+        from e_paper_student_question psq left join e_paper_qtype_question ptq on psq.eptqid=ptq.eptqid
41
+        left join e_paper p on psq.epid=p.epid where psq.epsid=#{epsid} order by ptq.qorder
42
+    </select>
43
+
44
+    <!--批量提交试题-->
45
+    <update id="updateBatchStuQuestion">
46
+        update e_paper_student_question
47
+        <trim prefix="set" suffixOverrides=",">
48
+            <trim prefix="answered = case" suffix="end,">
49
+                <foreach collection="list" item="q">
50
+                    when eptqid=#{q.eptqid} then #{q.answered}
51
+                </foreach>
52
+            </trim>
53
+            <trim prefix="answertype = case" suffix="end,">
54
+                <foreach collection="list" item="q">
55
+                    when eptqid=#{q.eptqid} then #{q.answertype}
56
+                </foreach>
57
+            </trim>
58
+            <trim prefix="stuanswer = case" suffix="end,">
59
+                <foreach collection="list" item="q">
60
+                    when eptqid=#{q.eptqid} then #{q.stuanswer}
61
+                </foreach>
62
+            </trim>
63
+            <trim prefix="stuanswertxt = case" suffix="end,">
64
+                <foreach collection="list" item="q">
65
+                    when eptqid=#{q.eptqid} then #{q.stuanswertxt}
66
+                </foreach>
67
+            </trim>
68
+            <trim prefix="converted = case" suffix="end,">
69
+                <foreach collection="list" item="q">
70
+                    when eptqid=#{q.eptqid} then #{q.converted}
71
+                </foreach>
72
+            </trim>
73
+            <trim prefix="answertime = case" suffix="end,">
74
+                <foreach collection="list" item="q">
75
+                    when eptqid=#{q.eptqid} then #{q.answertime}
76
+                </foreach>
77
+            </trim>
78
+            <trim prefix="stuscore = case" suffix="end,">
79
+                <foreach collection="list" item="q">
80
+                    when eptqid=#{q.eptqid} then #{q.stuscore}
81
+                </foreach>
82
+            </trim>
83
+            <trim prefix="checked = case" suffix="end,">
84
+                <foreach collection="list" item="q">
85
+                    when eptqid=#{q.eptqid} then #{q.checked}
86
+                </foreach>
87
+            </trim>
88
+            <trim prefix="checktime = case" suffix="end,">
89
+                <foreach collection="list" item="q">
90
+                    when eptqid=#{q.eptqid} then #{q.checktime}
91
+                </foreach>
92
+            </trim>
93
+        </trim>
94
+        <where>
95
+            <foreach collection="list" item="q" separator="or">
96
+                eptqid=#{q.eptqid}
97
+            </foreach>
98
+        </where>
99
+    </update>
19 100
 </mapper>

+ 3
- 2
sstudy/src/main/java/com/xhkjedu/sstudy/controller/question/QuestionController.java View File

@@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
21 21
 
22 22
 import javax.annotation.Resource;
23 23
 import java.util.List;
24
+import java.util.Map;
24 25
 
25 26
 /**
26 27
 * @author ywx
@@ -150,7 +151,7 @@ public class QuestionController {
150 151
                 question.getQstem(),"试题题干",2,question.getScore(),"试题分值",1
151 152
                 ,question.getComplexity(),"试题难易度",1,question.getQtypeid(),"试题题型id",2,question.getCreateid(),"教师id",1 });
152 153
 
153
-        String id = tQuestionService.saveUpdateQuestion(question);
154
-        return new ResultVo(0, "保存成功",id);
154
+        Map map = tQuestionService.saveUpdateQuestion(question);
155
+        return new ResultVo(0, "保存成功",map);
155 156
     }
156 157
 }

+ 16
- 4
sstudy/src/main/java/com/xhkjedu/sstudy/service/question/QuestionService.java View File

@@ -17,7 +17,9 @@ import org.springframework.util.CollectionUtils;
17 17
 
18 18
 import javax.annotation.Resource;
19 19
 import java.util.ArrayList;
20
+import java.util.HashMap;
20 21
 import java.util.List;
22
+import java.util.Map;
21 23
 
22 24
 /**
23 25
  * @author ywx
@@ -319,7 +321,7 @@ public class QuestionService {
319 321
      * @Date 2022/7/19 16:02
320 322
      **/
321 323
     @Transactional(rollbackFor = Exception.class)
322
-    public String saveUpdateQuestion(TQuestion question){
324
+    public Map saveUpdateQuestion(TQuestion question){
323 325
         QuestionVo oldQuestion = questionMapper.findById(question.getQuestionid());//原试题详细信息
324 326
         delQuestionATag(question);//优化试题内容
325 327
         question.setSubjectid(oldQuestion.getSubjectid());
@@ -328,7 +330,7 @@ public class QuestionService {
328 330
         List<TQuestionPoint> saveQPoints = new ArrayList<>();//试题知识集合
329 331
         List<TQuestionDirector> saveQDirs = new ArrayList<>();//试题章节集合
330 332
 
331
-        setSaveUpdateQuestion(question,saveQues,saveQPoints);
333
+        Map map = setSaveUpdateQuestion(question,saveQues,saveQPoints);
332 334
         setSaveUpdateQuesitonDirector(oldQuestion,question,saveQDirs);
333 335
         questionMapper.saveBathQuestion(saveQues);//保存试题
334 336
         questionPointMapper.batchSave(saveQPoints);//保存试题关联知识点信息
@@ -345,11 +347,13 @@ public class QuestionService {
345 347
         ub.setCreatetime(question.getCreatetime());
346 348
         userBasketMapper.insertSelective(ub);//保存新试题进入试题栏*/
347 349
 
348
-        return question.getQuestionid();
350
+        return map;
349 351
     }
350 352
 
351 353
     //处理试题试题和知识
352
-    private void setSaveUpdateQuestion(TQuestion question,List<TQuestion> saveQues,List<TQuestionPoint> saveQPoints){
354
+    private Map setSaveUpdateQuestion(TQuestion question,List<TQuestion> saveQues,List<TQuestionPoint> saveQPoints){
355
+        Map map = new HashMap();
356
+        List<Map> sonlist = new ArrayList<>();
353 357
         int timestamp = N_Utils.getSecondTimestamp();
354 358
         question.setCount(0);
355 359
         question.setQstate(1);
@@ -358,6 +362,8 @@ public class QuestionService {
358 362
         String questionid = StudyUtil.getId();
359 363
         question.setQuestionid(questionid);
360 364
         saveQues.add(question);
365
+        map.put("questionid",questionid);
366
+
361 367
         //qlevel试题类型1单体2母题3子题
362 368
         if(question.getQlevel() == 2){//是母体并且包含子题
363 369
             List<TQuestion> sonques = question.getQuestions();
@@ -373,6 +379,10 @@ public class QuestionService {
373 379
                 sq.setCreatetime(timestamp);
374 380
                 sq.setSchoolid(question.getSchoolid());
375 381
                 saveQues.add(sq);
382
+                Map sonmap = new HashMap();
383
+                sonmap.put("sorder",sq.getSorder());
384
+                sonmap.put("quesitonid",sqid);
385
+                sonlist.add(sonmap);
376 386
 
377 387
                 //知识点
378 388
                 List<TQuestionPoint> points = sq.getQuestionPoints();
@@ -413,6 +423,8 @@ public class QuestionService {
413 423
                 }
414 424
             }
415 425
         }
426
+        map.put("sonlist",sonlist);
427
+        return map;
416 428
     }
417 429
 
418 430
 

Loading…
Cancel
Save