瀏覽代碼

完善保存

ywx
王宁 7 月之前
父節點
當前提交
b715c93b21

+ 11
- 0
src/main/java/com/xhkjedu/controller/EPaperVerifyController.java 查看文件

@@ -4,6 +4,7 @@ import com.xhkjedu.model.EClassStudent;
4 4
 import com.xhkjedu.model.EPaperStudent0608;
5 5
 import com.xhkjedu.service.EPaperVerifyService;
6 6
 import com.xhkjedu.utils.N_Utils;
7
+import com.xhkjedu.vo.PaperStudentParams;
7 8
 import com.xhkjedu.vo.ResultVo;
8 9
 import org.springframework.web.bind.annotation.PostMapping;
9 10
 import org.springframework.web.bind.annotation.RequestBody;
@@ -53,4 +54,14 @@ public class EPaperVerifyController {
53 54
         return new ResultVo(0, "识别成功!");
54 55
     }
55 56
 
57
+    //识别保存
58
+    @PostMapping("/correct_save")
59
+    public ResultVo correctSave(@RequestBody PaperStudentParams ps) {
60
+        Integer epid = ps.getEpid();
61
+        Integer studentid = ps.getStudentid();
62
+        N_Utils.validation(new Object[]{epid, "试卷id", 1,studentid, "学生id", 1});
63
+        ePaperVerifyService.correctSave(ps);
64
+        return new ResultVo(0, "保存成功!");
65
+    }
66
+
56 67
 }

+ 53
- 0
src/main/java/com/xhkjedu/interceptors/RequestInterceptor.java 查看文件

@@ -0,0 +1,53 @@
1
+package com.xhkjedu.interceptors;
2
+
3
+import lombok.extern.slf4j.Slf4j;
4
+import org.springframework.context.annotation.Configuration;
5
+import org.springframework.web.servlet.HandlerInterceptor;
6
+import org.springframework.web.servlet.ModelAndView;
7
+
8
+import javax.servlet.http.HttpServletRequest;
9
+import javax.servlet.http.HttpServletResponse;
10
+
11
+@Configuration
12
+@Slf4j
13
+public class RequestInterceptor implements HandlerInterceptor {
14
+    @Override
15
+    public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) {
16
+    }
17
+
18
+    @Override
19
+    public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3) {
20
+
21
+    }
22
+
23
+    /**
24
+     * 在调用controller具体方法前拦截
25
+     */
26
+    @Override
27
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
28
+        //log.info("请求的uri:" + request.getRequestURI());
29
+        //response.setHeader("Access-Control-Allow-Origin", "*");//WebMvcConfg已经设置了跨越,重复设置失效
30
+        response.setContentType("application/json;charset=UTF-8");
31
+
32
+        // 记录请求开始时间
33
+        /*request.setAttribute("_startTime", System.currentTimeMillis());
34
+        String requestURI = request.getRequestURI();
35
+        String key = request.getHeader("Token-Key");
36
+        String token = request.getHeader("Token-Value");
37
+        if (!requestURI.contains("user/login") && !requestURI.endsWith("/get_new")
38
+                && ToolUtils.isNotEmpty(key) && ToolUtils.isNotEmpty(token)) {//非登录和获取最新版本相关接口验证token
39
+            String redis_token = get(key);//系统缓存中保存的token
40
+            if (!token.equals(redis_token)) {
41
+                ResultVo result = new ResultVo();
42
+                result.setCode(2);
43
+                result.setMsg("登录失效");
44
+
45
+                response.getWriter().print(JSON.toJSONString(result));
46
+                return false;
47
+            } else {
48
+                refreshToken(key, redis_token);//刷新token
49
+            }
50
+        }*/
51
+        return true;
52
+    }
53
+}

+ 54
- 0
src/main/java/com/xhkjedu/interceptors/WebMvcConfg.java 查看文件

@@ -0,0 +1,54 @@
1
+package com.xhkjedu.interceptors;
2
+
3
+import org.springframework.context.annotation.Configuration;
4
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
5
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
6
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
7
+
8
+import javax.annotation.Resource;
9
+
10
+/**
11
+ * @Author WN
12
+ * @Description 跨域(协议、域名、端口、子域名不一致)解决方案
13
+ * 1、返回新的CorsFilter
14
+ * 2、重写WebMvcConfigurer
15
+ * 3、使用注解@CrossOrigin
16
+ * 4、手动设置响应头(HttpServletResponse)
17
+ * 前两种属于全局设置,后两种属于局部设置;如果使用了局部设置会覆盖全局的设置,可以通过@CrossOrigin进行细粒度控制
18
+ * 2.4.0之前用allowedOrigins("*"),之后用allowedOriginPatterns("*")
19
+ * @Date 2019/4/3 15:50
20
+ **/
21
+@Configuration
22
+public class WebMvcConfg implements WebMvcConfigurer {
23
+
24
+    @Resource
25
+    private RequestInterceptor requestInterceptor;
26
+
27
+    /**
28
+     * 拦截器addPathPatterns用于添加拦截规则 excludePathPatterns 用于排除拦截
29
+     * @Param registry
30
+     * @Return void
31
+     * @Author wn
32
+     * @Date 2019/4/8
33
+     */
34
+    @Override
35
+    public void addInterceptors(InterceptorRegistry registry) {
36
+        registry.addInterceptor(requestInterceptor).addPathPatterns("/**");
37
+    }
38
+
39
+    /**
40
+     * 允许跨域
41
+     * @Param registry
42
+     * @Return void
43
+     * @Author wn
44
+     * @Date 2019/4/8
45
+     */
46
+    @Override
47
+    public void addCorsMappings(CorsRegistry registry){
48
+        registry.addMapping("/**")
49
+                .allowedOriginPatterns("*")
50
+                .allowCredentials(true)
51
+                .allowedMethods("GET","POST")
52
+                .maxAge(3600);
53
+    }
54
+}

+ 11
- 0
src/main/java/com/xhkjedu/mapper/EPaperVerifyMapper.java 查看文件

@@ -41,4 +41,15 @@ public interface EPaperVerifyMapper {
41 41
 
42 42
     //修改新表试卷状态
43 43
     void updateStuPaper0608(@Param("p")EPaperStudent0608 p);
44
+
45
+    //获取试卷中主观题
46
+    List<EPaperStudentQuestion> listQuestionZGT(@Param("epid") Integer epid,@Param("studentid") Integer studentid);
47
+
48
+    //获取学生试卷
49
+    EPaperStudent getStuPaperInfo(@Param("epid") Integer epid,@Param("studentid") Integer studentid);
50
+
51
+    //清空学生试卷
52
+    void clearPaperStu(@Param("epid") Integer epid,@Param("studentid") Integer studentid);
53
+    //清空学生试卷试题
54
+    void clearPaperStuQues(@Param("epid") Integer epid,@Param("studentid") Integer studentid);
44 55
 }

+ 63
- 58
src/main/java/com/xhkjedu/service/EPaperVerifyService.java 查看文件

@@ -47,67 +47,78 @@ public class EPaperVerifyService {
47 47
     public void correctSave(PaperStudentParams psParams){
48 48
         Integer epid = psParams.getEpid();
49 49
         Integer studentid = psParams.getStudentid();
50
-
51
-        //是否验证0待验证1验证通过2验证不通过
52
-        if(psParams.getVerified() == 2){
53
-            EPaperStudent paperStudent = new EPaperStudent();
54
-            paperStudent.setEpid(epid);
55
-            paperStudent.setStudentid(studentid);
56
-            paperStudent.setVerified(2);
57
-            ePaperVerifyMapper.updateStuPaperVerified(paperStudent);
58
-
59
-            //验证不通过,更改状态
60
-            EPaperStudent0608 ps0608 = new EPaperStudent0608();
61
-            ps0608.setEpid(epid);
62
-            ps0608.setStudentid(studentid);
63
-            ps0608.setVerified(2);
64
-            ps0608.setSamed(0);
65
-            ePaperVerifyMapper.updateStuPaper0608(ps0608);
66
-        }else{
67
-            //获取原试卷答案,
68
-            List<EPaperQtypeQuestion> questions = ePaperVerifyMapper.listPaperAnswer(psParams.getEpid());
69
-            List<EPaperStudentQuestion> stuQues = psParams.getQuestions();
70
-
71
-            Double paperscore = 0D;//学生试卷得分
72
-
73
-            for(EPaperStudentQuestion psq : stuQues){
74
-                EPaperQtypeQuestion pqtypeQues = questions.stream().filter(a -> a.getEptqid().equals(psq.getEptqid())).findFirst().orElse(null);
75
-                setCommitQuestion(psq,pqtypeQues);
76
-
77
-                paperscore = N_Utils.add(paperscore, psq.getStuscore());
78
-                psq.setStudentid(studentid);
79
-                psq.setEpid(epid);
80
-            }
81
-            ePaperVerifyMapper.updateBatchStuQuestion(stuQues);
82
-
83
-            EPaperStudent paperStudent = new EPaperStudent();
84
-            paperStudent.setEpid(epid);
85
-            paperStudent.setStudentid(studentid);
86
-            paperStudent.setStuscore(paperscore);
87
-            paperStudent.setStupic(psParams.getStupic());
88
-            paperStudent.setPagenum(psParams.getPagenum());
89
-            paperStudent.setSstate(2);
90
-            paperStudent.setChecked(2);
91
-            paperStudent.setVerified(1);
92
-            ePaperVerifyMapper.updateStuPaper(paperStudent);
93
-
94
-            EPaperStudent0608 ps0608 = new EPaperStudent0608();
95
-            ps0608.setEpid(epid);
96
-            ps0608.setStudentid(studentid);
97
-            ps0608.setVerified(1);
98
-            ps0608.setSamed(psParams.getSamed());
99
-            ePaperVerifyMapper.updateStuPaper0608(ps0608);
50
+        Integer newstudentid = psParams.getNewstudentid();
51
+        Integer samed = 2; //是否和以前一致1一致2不一致
52
+        if(N_Utils.isTrueInteger(newstudentid) && studentid.equals(newstudentid)){
53
+            samed = 1;
54
+            newstudentid = studentid;
100 55
         }
56
+        //获取原试卷答案,
57
+        List<EPaperQtypeQuestion> questions = ePaperVerifyMapper.listPaperAnswer(psParams.getEpid());
58
+
59
+        List<EPaperStudentQuestion> stuQues = psParams.getQuestions();//仅包含客观题
60
+
61
+        List<EPaperStudentQuestion> saveQues = new ArrayList<>();
101 62
 
63
+        Double paperscore = 0D;//学生试卷得分
64
+
65
+        for(EPaperStudentQuestion psq : stuQues){
66
+            EPaperQtypeQuestion pqtypeQues = questions.stream().filter(a -> a.getEptqid().equals(psq.getEptqid())).findFirst().orElse(null);
67
+            setCommitQuestion(psq,pqtypeQues);
68
+
69
+            paperscore = N_Utils.add(paperscore, psq.getStuscore());
70
+            psq.setStudentid(newstudentid);
71
+            psq.setEpid(epid);
72
+            saveQues.add(psq);
73
+        }
102 74
 
75
+        //获取试卷中主观题
76
+        List<EPaperStudentQuestion> stuQuesZgt = ePaperVerifyMapper.listQuestionZGT(epid,studentid);
77
+        for(EPaperStudentQuestion psqZgt : stuQuesZgt){
78
+            psqZgt.setStudentid(newstudentid);
79
+            paperscore = N_Utils.add(paperscore, psqZgt.getStuscore());
80
+            saveQues.add(psqZgt);
81
+        }
103 82
 
83
+        ePaperVerifyMapper.updateBatchStuQuestion(saveQues);
84
+
85
+        //获取原试卷信息
86
+        EPaperStudent ps = ePaperVerifyMapper.getStuPaperInfo(epid,studentid);
87
+
88
+        //更改新学生信息
89
+        EPaperStudent paperStudent = new EPaperStudent();
90
+        paperStudent.setEpid(epid);
91
+        paperStudent.setStudentid(newstudentid);
92
+        paperStudent.setStuscore(paperscore);
93
+        paperStudent.setStupic(ps.getStupic());
94
+        paperStudent.setPagenum(ps.getPagenum());
95
+        paperStudent.setBatchid(ps.getBatchid());
96
+        paperStudent.setSstate(2);
97
+        paperStudent.setChecked(2);
98
+        paperStudent.setVerified(1);
99
+        ePaperVerifyMapper.updateStuPaper(paperStudent);
100
+
101
+        EPaperStudent0608 ps0608 = new EPaperStudent0608();
102
+        ps0608.setEpid(epid);
103
+        ps0608.setStudentid(newstudentid);
104
+        ps0608.setVerified(1);
105
+        ps0608.setSamed(samed);
106
+        ePaperVerifyMapper.updateStuPaper0608(ps0608);
107
+
108
+        if(samed == 2){
109
+            //说明学生信息布一致,清空表中原学生试卷及试题信息
110
+            ePaperVerifyMapper.clearPaperStuQues(epid,studentid);
111
+            ePaperVerifyMapper.clearPaperStu(epid,studentid);
112
+        }
104 113
     }
105 114
 
106 115
     //判断单道题情况
107 116
     private void setCommitQuestion(EPaperStudentQuestion psq, EPaperQtypeQuestion answerVo) {
108 117
         int timestamp = N_Utils.getSecondTimestamp();
109
-        psq.setAnswertime(timestamp);
110
-        int coverted = 1;//是否转换0未转换1已转换2转换失败
118
+        if(!N_Utils.isTrueInteger(psq.getAnswertime())){
119
+            psq.setAnswertime(timestamp);
120
+        }
121
+
111 122
         String stuanswer = psq.getStuanswer();
112 123
         String stuanswertxt = psq.getStuanswertxt();
113 124
         Double stuscore = 0D;
@@ -164,13 +175,9 @@ public class EPaperVerifyService {
164 175
                             }
165 176
                         }
166 177
                     }
167
-
168 178
                     psq.setChecked(2);
169 179
                     psq.setChecktime(timestamp);
170 180
                 } else {
171
-                    if (stuanswers.size() > 1) {
172
-                        coverted = 0;//上传的多张图片设为0未转换
173
-                    }
174 181
                     psq.setChecked(0);
175 182
                 }
176 183
             } else {
@@ -198,8 +205,6 @@ public class EPaperVerifyService {
198 205
             }
199 206
             psq.setStuscore(stuscore);
200 207
         }
201
-
202
-        psq.setConverted(coverted);
203 208
     }
204 209
 
205 210
 

+ 2
- 0
src/main/java/com/xhkjedu/vo/PaperStudentParams.java 查看文件

@@ -17,6 +17,8 @@ public class PaperStudentParams {
17 17
 
18 18
     private Integer studentid;//学生id
19 19
 
20
+    private Integer newstudentid;//新选择学生id
21
+
20 22
     //试卷学生id
21 23
     private Integer epsid;
22 24
 

+ 26
- 1
src/main/resources/EPaperVerifyMapper.xml 查看文件

@@ -67,7 +67,10 @@
67 67
     <update id="updateBatchStuQuestion">
68 68
         <foreach collection="list" item="q" separator=";">
69 69
             update e_paper_student_question set answered=#{q.answered},answertype=#{q.answertype},stuanswer=#{q.stuanswer}
70
-            ,stuanswertxt=#{q.stuanswertxt},converted=#{q.converted}
70
+            ,stuanswertxt=#{q.stuanswertxt}
71
+            <if test="q.converted!=null">
72
+                ,converted=#{q.converted}
73
+            </if>
71 74
             <if test="q.answertime!=null">
72 75
                 ,answertime=#{q.answertime}
73 76
             </if>
@@ -95,4 +98,26 @@
95 98
     <update id="updateStuPaper0608">
96 99
         update e_paper_student0608 set verified=#{p.verified},samed=#{p.samed} where epid=#{p.epid} and studentid=#{p.studentid}
97 100
     </update>
101
+
102
+    <!--获取试卷中主观题-->
103
+    <select id="listQuestionZGT" resultType="com.xhkjedu.model.EPaperStudentQuestion">
104
+        select * from e_paper_student_question0608 where epid=#{epid} and studentid=#{studentid}
105
+    </select>
106
+
107
+    <!--获取学生试卷-->
108
+    <select id="getStuPaperInfo" resultType="com.xhkjedu.model.EPaperStudent">
109
+        select epid,epsid,studentid,classid,stupic,pagenum,batchid from e_paper_student0608 where epid=#{epid} and studentid=#{studentid} limit 1
110
+    </select>
111
+
112
+    <!--清空学生作答信息-->
113
+    <update id="clearPaperStu">
114
+        update e_paper_student set sstate=0,checked=0,checkid=null,stuscore=0,batchid=null,
115
+        stupic=null,pagenum=0,verified=0 where epid=#{epid} and studentid=#{studentid}
116
+    </update>
117
+    <!--清空学生作答信息-->
118
+    <update id="clearPaperStuQues">
119
+        update e_paper_student_question set answered=0,answertype=0,stuanswer=null,
120
+        converted=0,answertime=null,stuscore=0,checked=0,checkid=null,checktime=null,
121
+        good=0,bad=0 where epid=#{epid} and studentid=#{studentid}
122
+    </update>
98 123
 </mapper>

Loading…
取消
儲存