소스 검색

Merge remote-tracking branch 'origin/master' into ywx

tags/正式版本
雍文秀 2 년 전
부모
커밋
66acc33690

+ 1
- 1
sexam/src/main/java/com/xhkjedu/sexam/controller/paper/EPaperQtypeController.java 파일 보기

@@ -53,7 +53,7 @@ public class EPaperQtypeController {
53 53
      **/
54 54
     @PostMapping("/up")
55 55
     public ResultVo updatePaperQtype(@RequestBody EPaper paper){
56
-        N_Utils.validation(new Object[]{paper.getEsid(),"考试科目id",1,paper.getEpid(),"试卷id",1});
56
+        N_Utils.validation(new Object[]{paper.getEsid(),"考试科目id",1});
57 57
         List<EPaperQtype> qtypes = paper.getQtypelist();
58 58
         if(qtypes == null || qtypes.size() == 0){
59 59
             return new ResultVo(1,"未设置试题");

+ 1
- 0
sexam/src/main/java/com/xhkjedu/sexam/controller/paperstudent/EPaperStudentController.java 파일 보기

@@ -64,4 +64,5 @@ public class EPaperStudentController {
64 64
         return new ResultVo(0,"成功获取学生试卷",psvo);
65 65
     }
66 66
 
67
+
67 68
 }

+ 2
- 0
sexam/src/main/java/com/xhkjedu/sexam/mapper/paper/EPaperMapper.java 파일 보기

@@ -47,7 +47,9 @@ public interface EPaperMapper extends TkMapper<EPaper> {
47 47
     //根据试卷id获取考试科目基本信息
48 48
     Map getESubjectByEpId(@Param("epid") Integer epid);
49 49
 
50
+    //试科目获取试卷信息
50 51
     EExamSubjectPaperVo getPaperParamsByEsid(@Param("esid") Integer esid);
52
+
51 53
     //获取考试试卷题量和分值
52 54
     List<EPaper> listNumAndScoreByExamId(@Param("examid") Integer examid);
53 55
 }

+ 6
- 1
sexam/src/main/java/com/xhkjedu/sexam/mapper/paperstudent/EPaperStudentQuestionMapper.java 파일 보기

@@ -3,13 +3,18 @@ package com.xhkjedu.sexam.mapper.paperstudent;
3 3
 import com.xhkjedu.sexam.base.TkMapper;
4 4
 import com.xhkjedu.sexam.model.paperstudent.EPaperStudent;
5 5
 import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
6
+import com.xhkjedu.sexam.vo.paperstudent.PsqAnswerVo;
7
+import org.apache.ibatis.annotations.Param;
6 8
 import org.springframework.stereotype.Repository;
7 9
 
8 10
 /**
9
- * @Description
11
+ * @Description 学生试卷试题
10 12
  * @Author WN
11 13
  * Date 2022/7/27 15:07
12 14
  **/
13 15
 @Repository
14 16
 public interface EPaperStudentQuestionMapper extends TkMapper<EPaperStudentQuestion> {
17
+
18
+    //根据学生试题id获取试题正确答案
19
+    PsqAnswerVo getPaperQuestionAnswer(@Param("epsqid")Integer epsqid);
15 20
 }

+ 6
- 7
sexam/src/main/java/com/xhkjedu/sexam/service/paper/EPaperQtypeService.java 파일 보기

@@ -54,11 +54,10 @@ public class EPaperQtypeService {
54 54
         EExamSubjectPaperVo espVo = ePaperMapper.getPaperParamsByEsid(paper.getEsid());
55 55
         if(espVo.getExamstate() > 0){
56 56
             return new ResultVo(1,"不能进行操作");
57
-        }else{
58
-            if(espVo.getEpid()!=null){
59
-                //说明已经有改考试对应的试卷,删除原试卷,重新保存
60
-                ePaperMapper.deletePaperByEpid(paper.getEpid());
61
-            }
57
+        }
58
+        if(espVo.getEpid()!=null){
59
+            //说明已经有改考试对应的试卷,删除原试卷,重新保存
60
+            ePaperMapper.deletePaperByEpid(paper.getEpid());
62 61
         }
63 62
 
64 63
         List<EPaperQtype> qtypelist = paper.getQtypelist();
@@ -373,7 +372,7 @@ public class EPaperQtypeService {
373 372
         }
374 373
 
375 374
         //删除原试卷
376
-        ePaperMapper.deletePaperByEpid(paper.getEpid());
375
+        ePaperMapper.deletePaperByEpid(espVo.getEpid());
377 376
 
378 377
         List<EPaperQtype> qtypelist = paper.getQtypelist();
379 378
         List<EPaperQtypeQuestion> queslist = new ArrayList<>();//存放试题
@@ -403,7 +402,7 @@ public class EPaperQtypeService {
403 402
             //如果提交试卷,更改科目状态
404 403
             eSubjectMapper.updateExamSubjectState(1,espVo.getEsid());
405 404
         }
406
-        return new ResultVo(0,"保存成功");
405
+        return new ResultVo(0,"保存成功",epid);
407 406
     }
408 407
 
409 408
     /**

+ 95
- 19
sexam/src/main/java/com/xhkjedu/sexam/service/paperstudent/EPaperStudentService.java 파일 보기

@@ -1,5 +1,6 @@
1 1
 package com.xhkjedu.sexam.service.paperstudent;
2 2
 
3
+import com.alibaba.fastjson.JSON;
3 4
 import com.xhkjedu.sexam.mapper.paper.EPaperQtypeMapper;
4 5
 import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentMapper;
5 6
 import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentQuestionMapper;
@@ -7,12 +8,14 @@ import com.xhkjedu.sexam.model.paper.EPaperQtype;
7 8
 import com.xhkjedu.sexam.model.paper.EPaperQtypeQuestion;
8 9
 import com.xhkjedu.sexam.model.paperstudent.EPaperStudent;
9 10
 import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
11
+import com.xhkjedu.sexam.utils.ExamUtil;
10 12
 import com.xhkjedu.sexam.vo.paperstudent.EPaperStudentVo;
13
+import com.xhkjedu.sexam.vo.paperstudent.PsqAnswerVo;
14
+import com.xhkjedu.utils.N_Utils;
11 15
 import org.springframework.stereotype.Service;
12 16
 
13 17
 import javax.annotation.Resource;
14 18
 import java.util.ArrayList;
15
-import java.util.HashMap;
16 19
 import java.util.List;
17 20
 import java.util.Map;
18 21
 
@@ -31,24 +34,26 @@ public class EPaperStudentService {
31 34
     private EPaperStudentQuestionMapper ePaperStudentQuestionMapper;
32 35
 
33 36
     /**
34
-     * @Description  学生进行中考试列表
37
+     * @Description 学生进行中考试列表
35 38
      * @Param [eps]
36 39
      * @Return java.util.List<java.util.Map>
37 40
      * @Author wn
38 41
      * @Date 2022/7/27 10:35
39 42
      **/
40
-    public List<Map> listExamPapersForStudent(EPaperStudent eps){
43
+    public List<Map> listExamPapersForStudent(EPaperStudent eps) {
41 44
         return ePaperStudentMapper.listExamPapersForStudent(eps.getStudentid());
42 45
     }
43 46
 
44
-    /** 学生已结束考试列表
47
+    /**
48
+     * 学生已结束考试列表
49
+     *
45 50
      * @Description
46 51
      * @Param [eps]
47 52
      * @Return java.util.List<java.util.Map>
48 53
      * @Author wn
49 54
      * @Date 2022/7/27 11:34
50 55
      **/
51
-    public List<Map> listExamsEndForStudent(EPaperStudent eps){
56
+    public List<Map> listExamsEndForStudent(EPaperStudent eps) {
52 57
         return ePaperStudentMapper.listExamsEndForStudent(eps.getStudentid());
53 58
     }
54 59
 
@@ -59,28 +64,28 @@ public class EPaperStudentService {
59 64
      * @Author wn
60 65
      * @Date 2022/7/27 11:48
61 66
      **/
62
-    public List<Map> startPaperForAndroid(EPaperStudent eps){
67
+    public List<Map> startPaperForAndroid(EPaperStudent eps) {
63 68
         Integer epsid = eps.getEpsid();
64 69
         //获取试卷基本信息
65 70
         EPaperStudentVo psvo = ePaperStudentMapper.getExamSubjectByEpsid(epsid);
66 71
         Integer ptype = psvo.getPtype();
67 72
 
68 73
         List<Map> questions = null;
69
-        if(ptype == 1){
74
+        if (ptype == 1) {
70 75
             //题库试卷试题
71 76
             questions = ePaperStudentMapper.listStuPaperQuestionsForAndroid(epsid);
72
-        }else{
77
+        } else {
73 78
             questions = ePaperStudentMapper.listStuPaperFjQuestionsForAndroid(epsid);
74 79
         }
75 80
         //判断是否生成学生试卷,未生成则需要生成,如果已生成直接返回
76
-        if(questions == null || questions.size() == 0){
81
+        if (questions == null || questions.size() == 0) {
77 82
 
78 83
             //保存试卷关联信息
79 84
             savePaperStudentQuestion(psvo);
80 85
             //保存后重新获取返回
81
-            if(ptype == 1){
86
+            if (ptype == 1) {
82 87
                 questions = ePaperStudentMapper.listStuPaperQuestionsForAndroid(epsid);
83
-            }else{
88
+            } else {
84 89
                 questions = ePaperStudentMapper.listStuPaperFjQuestionsForAndroid(epsid);
85 90
             }
86 91
         }
@@ -88,12 +93,12 @@ public class EPaperStudentService {
88 93
     }
89 94
 
90 95
     //保存学生试卷关联信息
91
-    private void savePaperStudentQuestion(EPaperStudentVo psvo){
96
+    private void savePaperStudentQuestion(EPaperStudentVo psvo) {
92 97
         //生成学生试卷
93 98
         List<EPaperQtypeQuestion> pqlist = ePaperQtypeMapper.listQuestionsByEpid(psvo.getEpid());
94 99
 
95 100
         List<EPaperStudentQuestion> psqlist = new ArrayList<>();
96
-        for(EPaperQtypeQuestion q : pqlist){
101
+        for (EPaperQtypeQuestion q : pqlist) {
97 102
             EPaperStudentQuestion sq = new EPaperStudentQuestion();
98 103
             sq.setClassid(psvo.getClassid());
99 104
             sq.setStudentid(psvo.getStudentid());
@@ -120,27 +125,27 @@ public class EPaperStudentService {
120 125
      * @Author wn
121 126
      * @Date 2022/7/27 15:36
122 127
      **/
123
-    public EPaperStudentVo startPaperForWeb(EPaperStudent eps){
128
+    public EPaperStudentVo startPaperForWeb(EPaperStudent eps) {
124 129
         Integer epsid = eps.getEpsid();
125 130
         //获取试卷基本信息
126 131
         EPaperStudentVo psvo = ePaperStudentMapper.getExamSubjectByEpsid(epsid);
127 132
         Integer ptype = psvo.getPtype();
128 133
 
129 134
         List<EPaperQtype> questions = null;
130
-        if(ptype == 1){
135
+        if (ptype == 1) {
131 136
             //题库试卷试题
132 137
             questions = ePaperStudentMapper.listStuPaperQuestionsForWeb(epsid);
133
-        }else{
138
+        } else {
134 139
             questions = ePaperStudentMapper.listStuPaperFjQuestionsForWeb(epsid);
135 140
         }
136 141
         //判断是否生成学生试卷,未生成则需要生成,如果已生成直接返回
137
-        if(questions == null || questions.size() == 0){
142
+        if (questions == null || questions.size() == 0) {
138 143
             //保存试卷关联信息
139 144
             savePaperStudentQuestion(psvo);
140 145
             //保存后重新获取返回
141
-            if(ptype == 1){
146
+            if (ptype == 1) {
142 147
                 questions = ePaperStudentMapper.listStuPaperQuestionsForWeb(epsid);
143
-            }else{
148
+            } else {
144 149
                 questions = ePaperStudentMapper.listStuPaperFjQuestionsForWeb(epsid);
145 150
             }
146 151
         }
@@ -148,4 +153,75 @@ public class EPaperStudentService {
148 153
         return psvo;
149 154
     }
150 155
 
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;
164
+            int coverted = 1;//是否转换0未转换1已转换2转换失败
165
+            String stuanswer = psq.getStuanswer();
166
+            List<String> stuanswers = JSON.parseArray(stuanswer, String.class);
167
+            String qanswer = answerVo.getAnswer();
168
+            List<String> qanswers = JSON.parseArray(qanswer,String.class);
169
+            if(N_Utils.isListEmpty(stuanswers) && N_Utils.isEmpty(psq.getStuanswertxt())
170
+                    && N_Utils.isEmpty(psq.getStuanswertxt())){
171
+                psq.setStuscore(stuscore);
172
+                psq.setChecked(1);
173
+                psq.setChecktime(timestamp);
174
+                psq.setAnswered(0);
175
+            }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
+                                    //全选对
206
+                                    stuscore = answerVo.getScore();
207
+                                }else if (qanswerList.length > rightNum){
208
+                                    //少选得半分
209
+                                    stuscore = ExamUtil.div(answerVo.getScore(),2,1);
210
+                                }
211
+                            }
212
+                        }
213
+                    }
214
+
215
+                }else{
216
+
217
+                }
218
+                psq.setAnswered(1);
219
+            }
220
+
221
+
222
+        }
223
+
224
+    }
225
+
226
+
151 227
 }

+ 31
- 0
sexam/src/main/java/com/xhkjedu/sexam/utils/ExamUtil.java 파일 보기

@@ -2,6 +2,7 @@ package com.xhkjedu.sexam.utils;
2 2
 
3 3
 import lombok.extern.slf4j.Slf4j;
4 4
 
5
+import java.math.BigDecimal;
5 6
 import java.util.Map;
6 7
 import java.util.concurrent.ConcurrentHashMap;
7 8
 
@@ -14,4 +15,34 @@ import java.util.concurrent.ConcurrentHashMap;
14 15
 @Slf4j
15 16
 public class ExamUtil {
16 17
     public static Map<String, String> uriMap = new ConcurrentHashMap<>();
18
+    // 默认除法运算精度
19
+    private static final int DEF_DIV_SCALE = 2;
20
+
21
+    /**
22
+     * 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到 小数点以后2位,以后的数字舍弃。
23
+     *
24
+     * @param v1 被除数
25
+     * @param v2 除数
26
+     * @return 两个参数的商
27
+     */
28
+    public static double div(double v1, double v2) {
29
+        return div(v1, v2, DEF_DIV_SCALE);
30
+    }
31
+
32
+    /**
33
+     * 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指 定精度,以后的数字舍弃。
34
+     *
35
+     * @param v1    被除数
36
+     * @param v2    除数
37
+     * @param scale 表示表示需要精确到小数点以后几位。
38
+     * @return 两个参数的商
39
+     */
40
+    public static double div(double v1, double v2, int scale) {
41
+        if (scale < 0) {
42
+            throw new IllegalArgumentException("The   scale   must   be   a   positive   integer   or   zero");
43
+        }
44
+        BigDecimal b1 = new BigDecimal(Double.toString(v1));
45
+        BigDecimal b2 = new BigDecimal(Double.toString(v2));
46
+        return b1.divide(b2, scale, BigDecimal.ROUND_DOWN).doubleValue();
47
+    }
17 48
 }

+ 21
- 0
sexam/src/main/java/com/xhkjedu/sexam/vo/paperstudent/PsqAnswerVo.java 파일 보기

@@ -0,0 +1,21 @@
1
+package com.xhkjedu.sexam.vo.paperstudent;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * @Description 试题答案
7
+ * @Author WN
8
+ * Date 2022/7/28 9:42
9
+ **/
10
+@Data
11
+public class PsqAnswerVo {
12
+    private Integer eptqid;//试卷中试题id
13
+
14
+    private Integer ctype;//处理题型
15
+
16
+    private Double score;//试题分值
17
+
18
+    private String answer;//答案
19
+
20
+    private Integer answered;//试卷是否设置正确答案1已设置0未设置
21
+}

+ 2
- 2
sexam/src/main/resources/mapper/paperstudent/EPaperStudentMapper.xml 파일 보기

@@ -5,10 +5,10 @@
5 5
     <!--学生进行中考试列表-->
6 6
     <select id="listExamPapersForStudent" resultType="java.util.Map">
7 7
         select eps.epsid, es.esid,es.examid,es.subjectid,es.subjectname,es.sdate,es.begintime,es.endtime,
8
-        e.examname,e.gradeid,e.examtype,ep.epid
8
+        e.examname,e.gradeid,e.examtype,ep.epid,ep.ptype
9 9
         from e_paper_student eps left join e_subject es on eps.esid=es.esid
10 10
          left join e_paper ep on eps.epid=ep.epid left join e_base e on eps.examid=e.examid
11
-        where e.deleted=1 and eps.studentid=#{studentid} and e.examstate=1 GROUP BY eps.epsid
11
+        where e.deleted=1 and e.monitored=1 and eps.studentid=#{studentid} and e.examstate=1 GROUP BY eps.epsid
12 12
         order by abs(UNIX_TIMESTAMP(concat(es.sdate,' ',es.begintime))-UNIX_TIMESTAMP())
13 13
     </select>
14 14
 

+ 11
- 0
sexam/src/main/resources/mapper/paperstudent/EPaperStudentQuestionMapper.xml 파일 보기

@@ -0,0 +1,11 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentQuestionMapper">
4
+
5
+    <!--根据学生试题id获取试题正确答案-->
6
+    <select id="getPaperQuestionAnswer" resultType="com.xhkjedu.sexam.vo.paperstudent.PsqAnswerVo">
7
+        select psq.eptqid,ptq.ctype,ptq.score,ptq.answer,p.answered
8
+        from e_paper_student_question psq left join e_paper_qtype_question ptq on psq.eptqid=ptq.eptqid
9
+        left join e_paper p on psq.epid=p.epid where psq.epsqid=#{epsqid}
10
+    </select>
11
+</mapper>

Loading…
취소
저장