Parcourir la source

提交单题

tags/正式版本
王宁 il y a 2 ans
Parent
révision
901cac44b3

+ 15
- 0
sexam/src/main/java/com/xhkjedu/sexam/controller/paperstudent/EPaperStudentController.java Voir le fichier

@@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper;
4 4
 import com.github.pagehelper.PageInfo;
5 5
 import com.xhkjedu.sexam.model.paper.EPaperQtype;
6 6
 import com.xhkjedu.sexam.model.paperstudent.EPaperStudent;
7
+import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
7 8
 import com.xhkjedu.sexam.service.paperstudent.EPaperStudentService;
8 9
 import com.xhkjedu.sexam.vo.paperstudent.EPaperStudentVo;
9 10
 import com.xhkjedu.utils.N_Utils;
@@ -64,5 +65,19 @@ public class EPaperStudentController {
64 65
         return new ResultVo(0,"成功获取学生试卷",psvo);
65 66
     }
66 67
 
68
+    //提交单题
69
+    @PostMapping("/scq")
70
+    public ResultVo saveCommitQuestion(@RequestBody EPaperStudentQuestion sq){
71
+       try {
72
+           N_Utils.validation(new Object[]{sq.getEpsqid(),"试题id",1});
73
+           ePaperStudentService.saveCommitQuestion(sq);
74
+           return new ResultVo(0,"成功提交试题");
75
+       }catch (Exception e){
76
+           return new ResultVo(1,"提交试题失败");
77
+       }
78
+    }
79
+
80
+
81
+
67 82
 
68 83
 }

+ 3
- 0
sexam/src/main/java/com/xhkjedu/sexam/mapper/paperstudent/EPaperStudentQuestionMapper.java Voir le fichier

@@ -17,4 +17,7 @@ public interface EPaperStudentQuestionMapper extends TkMapper<EPaperStudentQuest
17 17
 
18 18
     //根据学生试题id获取试题正确答案
19 19
     PsqAnswerVo getPaperQuestionAnswer(@Param("epsqid")Integer epsqid);
20
+
21
+    //提交单题
22
+    void updateStuAnswer(@Param("q")EPaperStudentQuestion q);
20 23
 }

+ 1
- 1
sexam/src/main/java/com/xhkjedu/sexam/model/paperstudent/EPaperStudentQuestion.java Voir le fichier

@@ -40,7 +40,7 @@ public class EPaperStudentQuestion extends BaseBean {
40 40
     private Integer answered;
41 41
 
42 42
     //答案类型1选择题、图片2纯文本
43
-    private Integer ansertype;
43
+    private Integer answertype;
44 44
 
45 45
     //学生答案(选项、图片)
46 46
     private String stuanswer;

+ 3
- 22
sexam/src/main/java/com/xhkjedu/sexam/service/paper/EPaperQtypeService.java Voir le fichier

@@ -83,7 +83,7 @@ public class EPaperQtypeService {
83 83
         }
84 84
 
85 85
         //更加试卷状态是否需要生成分析和更改科目状态
86
-        if(espVo.getExammode() == 2 && paper.getPstate()!=null && paper.getPstate() == 1){
86
+        if(espVo.getExammode() == 1 && paper.getPstate()!=null && paper.getPstate() == 1){
87 87
             //如果提交试卷,更改科目状态
88 88
             eSubjectMapper.updateExamSubjectState(1,espVo.getEsid());
89 89
         }
@@ -112,6 +112,7 @@ public class EPaperQtypeService {
112 112
         paper.setCreatetime(timestamp);
113 113
         paper.setHandletime(timestamp);
114 114
         paper.setHandleid(paper.getCreateid());
115
+        paper.setCorrecttype(0);
115 116
         if(paper.getPtype() == 1){
116 117
             paper.setAnswered(1);//题库已设置正确答案
117 118
         }else{
@@ -398,7 +399,7 @@ public class EPaperQtypeService {
398 399
         }
399 400
 
400 401
         //更加试卷状态是否需要生成分析和更改科目状态
401
-        if(paper.getPstate()!=null && paper.getPstate() == 1){
402
+        if(espVo.getExammode() == 1 && paper.getPstate()!=null && paper.getPstate() == 1){
402 403
             //如果提交试卷,更改科目状态
403 404
             eSubjectMapper.updateExamSubjectState(1,espVo.getEsid());
404 405
         }
@@ -568,26 +569,6 @@ public class EPaperQtypeService {
568 569
     @Transactional(rollbackFor = Exception.class)
569 570
     public void savePaperScan(EPaper paper){
570 571
         List<EPaperQtypeQuestion> questions = paper.getQuestions();
571
-        for(EPaperQtypeQuestion q : questions){
572
-            List<String> coorlist = q.getCoordlist();
573
-            if(q.getCtype() == 3 || q.getCtype() == 14 || q.getCtype() == 15){
574
-                if(coorlist.size() > 1){
575
-                    //有多个坐标,合并为一个
576
-                    List<List> savecoor = new ArrayList<>();
577
-                    for(String str : coorlist){
578
-                        List lst = JSON.parseArray(str);
579
-                        for(int i=0;i<lst.size();i++){
580
-                            savecoor.add((List)lst.get(i));
581
-                        }
582
-                    }
583
-                    q.setCoord(JSON.toJSONString(savecoor));
584
-                }else{
585
-                    q.setCoord(coorlist.get(0));
586
-                }
587
-            }else{
588
-                q.setCoord(coorlist.get(0));
589
-            }
590
-        }
591 572
         ePaperMapper.updatePaperScantron(paper);
592 573
         ePaperQtypeMapper.updateBatchQuestionForScan(questions);
593 574
         if(paper.getPstate() == 1){

+ 103
- 49
sexam/src/main/java/com/xhkjedu/sexam/service/paperstudent/EPaperStudentService.java Voir le fichier

@@ -12,6 +12,7 @@ import com.xhkjedu.sexam.utils.ExamUtil;
12 12
 import com.xhkjedu.sexam.vo.paperstudent.EPaperStudentVo;
13 13
 import com.xhkjedu.sexam.vo.paperstudent.PsqAnswerVo;
14 14
 import com.xhkjedu.utils.N_Utils;
15
+import lombok.extern.slf4j.Slf4j;
15 16
 import org.springframework.stereotype.Service;
16 17
 
17 18
 import javax.annotation.Resource;
@@ -25,6 +26,7 @@ import java.util.Map;
25 26
  * Date 2022/7/26 14:00
26 27
  **/
27 28
 @Service
29
+@Slf4j
28 30
 public class EPaperStudentService {
29 31
     @Resource
30 32
     private EPaperStudentMapper ePaperStudentMapper;
@@ -153,75 +155,127 @@ public class EPaperStudentService {
153 155
         return psvo;
154 156
     }
155 157
 
156
-    public void saveCommitQuestion(EPaperStudentQuestion psq) {
157
-        //学生作答提交时先判断试卷是否设置的正确答案
158
-        PsqAnswerVo answerVo = ePaperStudentQuestionMapper.getPaperQuestionAnswer(psq.getEpsqid());
159
-        int timestamp = N_Utils.getSecondTimestamp();
160
-        psq.setAnswertime(timestamp);
161
-        //试卷已经设置了正确答案
162
-        if (answerVo.getAnswered() == 1){
163
-            Double stuscore = 0.0;
158
+    /**
159
+     * @Description 提交单题
160
+     * @Param [psq]
161
+     * @Return void
162
+     * @Author wn
163
+     * @Date 2022/7/28 13:47
164
+     **/
165
+    public void saveCommitQuestion(EPaperStudentQuestion psq) throws Exception {
166
+        try {
167
+            //学生作答提交时先判断试卷是否设置的正确答案
168
+            PsqAnswerVo answerVo = ePaperStudentQuestionMapper.getPaperQuestionAnswer(psq.getEpsqid());
169
+            int timestamp = N_Utils.getSecondTimestamp();
170
+            psq.setAnswertime(timestamp);
164 171
             int coverted = 1;//是否转换0未转换1已转换2转换失败
165 172
             String stuanswer = psq.getStuanswer();
166 173
             List<String> stuanswers = JSON.parseArray(stuanswer, String.class);
167
-            String qanswer = answerVo.getAnswer();
168
-            List<String> qanswers = JSON.parseArray(qanswer,String.class);
174
+            Double stuscore = 0.0;
175
+
169 176
             if(N_Utils.isListEmpty(stuanswers) && N_Utils.isEmpty(psq.getStuanswertxt())
170 177
                     && N_Utils.isEmpty(psq.getStuanswertxt())){
171 178
                 psq.setStuscore(stuscore);
172
-                psq.setChecked(1);
179
+                psq.setChecked(2);
173 180
                 psq.setChecktime(timestamp);
174 181
                 psq.setAnswered(0);
175 182
             }else{
176
-
177
-                int ctype = answerVo.getCtype();
178
-                if(N_Utils.isObjectiveQuestion(ctype)){
179
-                    //客观题进行批阅
180
-                    if(ctype == 1){//单选
181
-                        if(stuanswer.equalsIgnoreCase(qanswer)) {
182
-                            stuscore = answerVo.getScore();
183
-                        }
184
-                    }else if(ctype == 2){//多选
185
-                        //多选、选错不得分
186
-                        if(stuanswers.get(0).length() <= qanswer.length()){
187
-                            String[] qanswerList = qanswers.get(0).split("");
188
-                            String[] stuanswerList = stuanswers.get(0).split("");
189
-                            int rightNum = 0;//选对个数
190
-                            for(String sa : stuanswerList){
191
-                               int right = 0;
192
-                               for(String qa : qanswerList){
193
-                                   if(qa.equals(sa)){
194
-                                       right = 1;
195
-                                       rightNum ++;
196
-                                   }
197
-                               }
198
-                               if(right == 0){//说明选错
199
-                                   rightNum = 0;
200
-                                   break;
201
-                               }
202
-                            }
203
-                            if(rightNum>0){
204
-                                if(qanswerList.length == rightNum){
205
-                                    //全选对
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)) {
206 200
                                     stuscore = answerVo.getScore();
207
-                                }else if (qanswerList.length > rightNum){
208
-                                    //少选得半分
209
-                                    stuscore = ExamUtil.div(answerVo.getScore(),2,1);
210 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;
219
+                                        }
220
+                                    }
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
+                                        }
229
+                                    }
230
+                                }
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
+                                    }
239
+                                }
240
+                                stuscore = ExamUtil.round(stuScoreDouble,1);
241
+                            }
242
+                            if(stuscore.compareTo(answerVo.getScore()) == 1){
243
+                                stuscore = answerVo.getScore();
244
+                            }
245
+                            psq.setStuscore(stuscore);
246
+                            psq.setChecked(2);
247
+                            psq.setChecktime(timestamp);
248
+                        }else{
249
+
250
+                            if(stuanswers.size() > 0){
251
+                                coverted = 0;//上传的多张图片设为0未转换
211 252
                             }
212 253
                         }
254
+                        psq.setAnswered(1);
213 255
                     }
214
-
215
-                }else{
216
-
217 256
                 }
218
-                psq.setAnswered(1);
219 257
             }
220 258
 
221
-
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("提交试题失败");
222 269
         }
223 270
 
224 271
     }
225 272
 
273
+    public int saveCommitPaper(Integer epsid){
274
+        EPaperStudent ps = ePaperStudentMapper.selectByPrimaryKey(epsid);
275
+        if(ps == null || ps.getSstate() == 1){
276
+            return 1;
277
+        }
278
+        return 1;
279
+    }
226 280
 
227 281
 }

+ 55
- 0
sexam/src/main/java/com/xhkjedu/sexam/utils/ExamUtil.java Voir le fichier

@@ -45,4 +45,59 @@ public class ExamUtil {
45 45
         BigDecimal b2 = new BigDecimal(Double.toString(v2));
46 46
         return b1.divide(b2, scale, BigDecimal.ROUND_DOWN).doubleValue();
47 47
     }
48
+
49
+    /**
50
+     * 提供精确的加法运算。
51
+     *
52
+     * @param v1 被加数
53
+     * @param v2 加数
54
+     * @return 两个参数的和
55
+     */
56
+    public static double add(double v1, double v2) {
57
+        BigDecimal b1 = new BigDecimal(Double.toString(v1));
58
+        BigDecimal b2 = new BigDecimal(Double.toString(v2));
59
+        return b1.add(b2).doubleValue();
60
+    }
61
+
62
+    /**
63
+     * 提供精确的小数位四舍五入处理。
64
+     *
65
+     * @param v     需要四舍五入的数字
66
+     * @param scale 小数点后保留几位
67
+     * @return 四舍五入后的结果
68
+     */
69
+    public static double round(double v, int scale) {
70
+        if (scale < 0) {
71
+            throw new IllegalArgumentException("The   scale   must   be   a   positive   integer   or   zero");
72
+        }
73
+        BigDecimal b = new BigDecimal(Double.toString(v));
74
+        BigDecimal one = new BigDecimal("1");
75
+        return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
76
+    }
77
+
78
+    /**
79
+     * 提供精确的减法运算。
80
+     *
81
+     * @param v1 被减数
82
+     * @param v2 减数
83
+     * @return 两个参数的差
84
+     */
85
+    public static double sub(double v1, double v2) {
86
+        BigDecimal b1 = new BigDecimal(Double.toString(v1));
87
+        BigDecimal b2 = new BigDecimal(Double.toString(v2));
88
+        return b1.subtract(b2).doubleValue();
89
+    }
90
+
91
+    /**
92
+     * 提供精确的乘法运算。
93
+     *
94
+     * @param v1 被乘数
95
+     * @param v2 乘数
96
+     * @return 两个参数的积
97
+     */
98
+    public static double mul(double v1, double v2) {
99
+        BigDecimal b1 = new BigDecimal(Double.toString(v1));
100
+        BigDecimal b2 = new BigDecimal(Double.toString(v2));
101
+        return b1.multiply(b2).doubleValue();
102
+    }
48 103
 }

+ 2
- 0
sexam/src/main/java/com/xhkjedu/sexam/vo/paperstudent/PsqAnswerVo.java Voir le fichier

@@ -18,4 +18,6 @@ public class PsqAnswerVo {
18 18
     private String answer;//答案
19 19
 
20 20
     private Integer answered;//试卷是否设置正确答案1已设置0未设置
21
+
22
+    private Integer costtime;//话费时间
21 23
 }

+ 0
- 2
sexam/src/main/resources/mapper/paper/EPaperMapper.xml Voir le fichier

@@ -99,6 +99,4 @@
99 99
         from e_subject es left join e_paper ep on es.esid=ep.esid
100 100
         left join e_base e on es.examid=e.examid where es.esid=#{esid}
101 101
     </select>
102
-
103
-    <select id="getExamState"></select>
104 102
 </mapper>

+ 9
- 1
sexam/src/main/resources/mapper/paperstudent/EPaperStudentQuestionMapper.xml Voir le fichier

@@ -4,8 +4,16 @@
4 4
 
5 5
     <!--根据学生试题id获取试题正确答案-->
6 6
     <select id="getPaperQuestionAnswer" resultType="com.xhkjedu.sexam.vo.paperstudent.PsqAnswerVo">
7
-        select psq.eptqid,ptq.ctype,ptq.score,ptq.answer,p.answered
7
+        select psq.eptqid,psq.costtime,ptq.ctype,ptq.score,ptq.answer,p.answered
8 8
         from e_paper_student_question psq left join e_paper_qtype_question ptq on psq.eptqid=ptq.eptqid
9 9
         left join e_paper p on psq.epid=p.epid where psq.epsqid=#{epsqid}
10 10
     </select>
11
+
12
+    <!--提交单题-->
13
+    <update id="updateStuAnswer">
14
+        update e_paper_student_question set answered=#{q.answered},answertype=#{q.answertype},
15
+        stuanswer=#{q.stuanswer},stuanswertxt=#{q.stuanswertxt},converted=#{q.converted},
16
+        answertime=#{q.answertime},costtime=#{q.costtime},stuscore=#{q.stuscore},
17
+        checked=#{q.checked},checkid=#{q.checkid},checktime=#{q.checktime} where epsqid=#{q.epsqid}
18
+    </update>
11 19
 </mapper>

Chargement…
Annuler
Enregistrer