Browse Source

补录成绩导入

tags/正式版本
雍文秀 2 years ago
parent
commit
45e390b032

+ 2
- 1
sexam/src/main/java/com/xhkjedu/sexam/controller/paperstudent/EPsqbatchController.java View File

95
      **/
95
      **/
96
     @PostMapping("/import")
96
     @PostMapping("/import")
97
     public ResultVo importRecord(MultipartFile file, EPsqbatch batch) {
97
     public ResultVo importRecord(MultipartFile file, EPsqbatch batch) {
98
-        N_Utils.validation(new Object[]{batch.getEpid(), "试卷id", 1, batch.getTeacherid(), "教师id", 1});
98
+        N_Utils.validation(new Object[]{batch.getExamid(), "考试id", 1, batch.getSubjectname(), "科目名称", 2
99
+                , batch.getEpid(), "试卷id", 1, batch.getTeacherid(), "教师id", 1});
99
         return ePsqbatchService.importRecord(file, batch);
100
         return ePsqbatchService.importRecord(file, batch);
100
     }
101
     }
101
 
102
 

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

67
 
67
 
68
     //获取学生试题列表
68
     //获取学生试题列表
69
     List<EPaperStudentQuestion> listQuestionByStu(@Param("studentid") Integer studentid,@Param("eptqids") List<Integer> eptqids);
69
     List<EPaperStudentQuestion> listQuestionByStu(@Param("studentid") Integer studentid,@Param("eptqids") List<Integer> eptqids);
70
+
71
+    //批量更新学生试题得分
72
+    void updateBatchStuQuestionSore(@Param("list") List<EPaperStudentQuestion> questions);
70
 }
73
 }

+ 9
- 0
sexam/src/main/java/com/xhkjedu/sexam/mapper/paperstudent/EPsqbatchDetailMapper.java View File

1
+package com.xhkjedu.sexam.mapper.paperstudent;
2
+
3
+import com.xhkjedu.sexam.base.TkMapper;
4
+import com.xhkjedu.sexam.model.paperstudent.EPsqbatchDetail;
5
+import org.springframework.stereotype.Repository;
6
+
7
+@Repository
8
+public interface EPsqbatchDetailMapper extends TkMapper<EPsqbatchDetail> {
9
+}

+ 25
- 9
sexam/src/main/java/com/xhkjedu/sexam/service/paperstudent/EPsqbatchService.java View File

3
 import com.xhkjedu.sexam.mapper.exam.EBaseMapper;
3
 import com.xhkjedu.sexam.mapper.exam.EBaseMapper;
4
 import com.xhkjedu.sexam.mapper.exam.EClassStudentMapper;
4
 import com.xhkjedu.sexam.mapper.exam.EClassStudentMapper;
5
 import com.xhkjedu.sexam.mapper.paper.EPaperQtypeQuestionMapper;
5
 import com.xhkjedu.sexam.mapper.paper.EPaperQtypeQuestionMapper;
6
+import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentMapper;
6
 import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentQuestionMapper;
7
 import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentQuestionMapper;
8
+import com.xhkjedu.sexam.mapper.paperstudent.EPsqbatchDetailMapper;
7
 import com.xhkjedu.sexam.mapper.paperstudent.EPsqbatchMapper;
9
 import com.xhkjedu.sexam.mapper.paperstudent.EPsqbatchMapper;
8
 import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
10
 import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
9
 import com.xhkjedu.sexam.model.paperstudent.EPsqbatch;
11
 import com.xhkjedu.sexam.model.paperstudent.EPsqbatch;
41
     @Resource
43
     @Resource
42
     private EPaperStudentQuestionMapper ePaperStudentQuestionMapper;
44
     private EPaperStudentQuestionMapper ePaperStudentQuestionMapper;
43
     @Resource
45
     @Resource
46
+    private EPaperStudentMapper ePaperStudentMapper;
47
+    @Resource
44
     private EBaseMapper eBaseMapper;
48
     private EBaseMapper eBaseMapper;
49
+    @Resource
50
+    private EPsqbatchDetailMapper ePsqbatchDetailMapper;
45
 
51
 
46
     /**
52
     /**
47
      * @Description 获取考试科目
53
      * @Description 获取考试科目
88
             if (code != 0) return new ResultVo(1, map.get("msg").toString());
94
             if (code != 0) return new ResultVo(1, map.get("msg").toString());
89
             LinkedHashMap<Integer, List<String>> errMsg = (LinkedHashMap<Integer, List<String>>) map.get("errMsg");
95
             LinkedHashMap<Integer, List<String>> errMsg = (LinkedHashMap<Integer, List<String>>) map.get("errMsg");
90
             if (errMsg.size() != 0) return new ResultVo(1, null, errMsg);
96
             if (errMsg.size() != 0) return new ResultVo(1, null, errMsg);
91
-            ePsqbatchMapper.insertUseGeneratedKeys(batch);
92
             List<EPsqbatchStuVo> stus = (List<EPsqbatchStuVo>) map.get("stus");
97
             List<EPsqbatchStuVo> stus = (List<EPsqbatchStuVo>) map.get("stus");
98
+            batch.setStunum(stus.size());
99
+            batch.setCreatetime(N_Utils.getSecondTimestamp());
100
+            ePsqbatchMapper.insertUseGeneratedKeys(batch);
93
             for (EPsqbatchStuVo stu : stus) {
101
             for (EPsqbatchStuVo stu : stus) {
94
                 new Thread(()->{
102
                 new Thread(()->{
95
                     try {
103
                     try {
96
                         saveEPsqbatchDetail(stu,batch);
104
                         saveEPsqbatchDetail(stu,batch);
97
                     }catch (Exception e){
105
                     }catch (Exception e){
98
-                        log.error("保存学生试题重试:" + e.getMessage());
106
+                        log.error("补录学生成绩重试:" + e.getMessage());
99
                         try {
107
                         try {
100
                             saveEPsqbatchDetail(stu,batch);
108
                             saveEPsqbatchDetail(stu,batch);
101
                         }catch (Exception se){
109
                         }catch (Exception se){
102
-                            log.error("保存学生试题重试出错:" + se.getMessage());
110
+                            log.error("补录学生成绩重试出错:" + se.getMessage());
103
                         }
111
                         }
104
                     }
112
                     }
105
                 }).start();
113
                 }).start();
106
             }
114
             }
107
         } catch (Exception e) {
115
         } catch (Exception e) {
108
-            e.printStackTrace();
116
+            log.error("导入补录学生成绩失败",e);
117
+            return new ResultVo(1,e.getMessage());
109
         }
118
         }
110
         return new ResultVo(0,"导入成功");
119
         return new ResultVo(0,"导入成功");
111
     }
120
     }
112
 
121
 
113
-    //保存学生试题
122
+    //补录学生成绩
114
     @Transactional(rollbackFor = Exception.class)
123
     @Transactional(rollbackFor = Exception.class)
115
     public void saveEPsqbatchDetail(EPsqbatchStuVo stu, EPsqbatch batch) {
124
     public void saveEPsqbatchDetail(EPsqbatchStuVo stu, EPsqbatch batch) {
116
         try {
125
         try {
127
                 EPsqbatchDetail detail = details.get(i);
136
                 EPsqbatchDetail detail = details.get(i);
128
                 EPaperStudentQuestion question = questions.get(i);
137
                 EPaperStudentQuestion question = questions.get(i);
129
                 question.setStuscore(detail.getNewscore());
138
                 question.setStuscore(detail.getNewscore());
130
-                detail.setStuscore(question.getStuscore());
131
-                detail.setEpid(epid);
132
                 detail.setBatchid(batchId);
139
                 detail.setBatchid(batchId);
140
+                detail.setStudentid(studentid);
141
+                detail.setEpid(epid);
142
+                detail.setEpsqid(question.getEpsqid());
143
+                detail.setQn(question.getQn());
144
+                detail.setStuscore(question.getStuscore());
133
                 detail.setTeacherid(teacherid);
145
                 detail.setTeacherid(teacherid);
134
                 detail.setCreatetime(timestamp);
146
                 detail.setCreatetime(timestamp);
135
             }
147
             }
148
+            ePsqbatchDetailMapper.insertList(details);//保存考试补录成绩详情
149
+            ePaperStudentQuestionMapper.updateBatchStuQuestionSore(questions);//更改单个学生试题分值
150
+            Integer epsid = questions.get(0).getEpsid();
151
+            ePaperStudentMapper.updateStuPaperscoreEpsid(epsid);//更改单个学生试卷分值
136
         } catch (Exception e) {
152
         } catch (Exception e) {
137
-            log.error("保存学生试题失败:" + e.getMessage());
153
+            log.error("补录学生成绩失败:" + e.getMessage());
138
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
154
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
139
-            throw new RuntimeException("保存学生试题失败");
155
+            throw new RuntimeException("补录学生成绩失败");
140
         }
156
         }
141
     }
157
     }
142
 
158
 

+ 8
- 3
sexam/src/main/java/com/xhkjedu/sexam/utils/PoiUtils.java View File

100
                 String loginname = getCellValue(row.getCell(1));//账号
100
                 String loginname = getCellValue(row.getCell(1));//账号
101
                 Integer studentid = stuMap.get(username + loginname);
101
                 Integer studentid = stuMap.get(username + loginname);
102
                 if (N_Utils.isEmptyInteger(studentid)) {
102
                 if (N_Utils.isEmptyInteger(studentid)) {
103
-                    mrows.add("第" + (x + 1) + "行学生【" + username + "(" + loginname + ")】不存在");
103
+                    mrows.add("学生【" + username + "(" + loginname + ")】不存在");
104
+                    errMsg.put(x + 1, mrows);
104
                     continue;//学生不存在处理下一行
105
                     continue;//学生不存在处理下一行
105
                 }
106
                 }
106
                 List<EPsqbatchDetail> details = new ArrayList<>();
107
                 List<EPsqbatchDetail> details = new ArrayList<>();
107
                 for (int y = firstCellNum + 2; y < lastCellNum; y++) {
108
                 for (int y = firstCellNum + 2; y < lastCellNum; y++) {
108
                     Cell cell = row.getCell(y);
109
                     Cell cell = row.getCell(y);
109
                     String score = getCellValue(cell);
110
                     String score = getCellValue(cell);
110
-                    if (N_Utils.isEmpty(score)) {
111
+                    if (N_Utils.isEmpty(score) && y == maxIndex && N_Utils.isListNotEmpty(mrows)) {
112
+                        errMsg.put(x + 1, mrows);
113
+                        continue;
114
+                    } else if (N_Utils.isEmpty(score)) {
111
                         continue;//学生分值为空处理下一列
115
                         continue;//学生分值为空处理下一列
112
                     }
116
                     }
113
                     EPsqbatchDetail detail = new EPsqbatchDetail();
117
                     EPsqbatchDetail detail = new EPsqbatchDetail();
114
-                    detail.setStudentid(studentid);
115
                     Double stuscore = Double.valueOf(score);
118
                     Double stuscore = Double.valueOf(score);
116
                     Double qscore = scoreMap.get(y);
119
                     Double qscore = scoreMap.get(y);
117
                     if (Double.compare(stuscore, qscore) == 1) {
120
                     if (Double.compare(stuscore, qscore) == 1) {
137
         } catch (Exception e) {
140
         } catch (Exception e) {
138
             resultMap.put("code", 1);
141
             resultMap.put("code", 1);
139
             String msg = e.getMessage();
142
             String msg = e.getMessage();
143
+            if(N_Utils.isEmpty(msg)) msg="读取报错";
140
             resultMap.put("msg", msg);
144
             resultMap.put("msg", msg);
141
             if (msg.contains("Invalid ")) {
145
             if (msg.contains("Invalid ")) {
142
                 msg = "格式不正确";
146
                 msg = "格式不正确";
198
      **/
202
      **/
199
     public static String getCellValue(Cell cell) {
203
     public static String getCellValue(Cell cell) {
200
         String value = null;
204
         String value = null;
205
+        if (cell == null) return value;
201
         DecimalFormat df = new DecimalFormat("0");  //格式化number String字符
206
         DecimalFormat df = new DecimalFormat("0");  //格式化number String字符
202
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");  //日期格式化
207
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");  //日期格式化
203
         DecimalFormat df2 = new DecimalFormat("0");  //格式化数字
208
         DecimalFormat df2 = new DecimalFormat("0");  //格式化数字

+ 17
- 1
sexam/src/main/resources/mapper/paperstudent/EPaperStudentQuestionMapper.xml View File

232
     </select>
232
     </select>
233
     <!--/获取学生试题列表-->
233
     <!--/获取学生试题列表-->
234
     <select id="listQuestionByStu" resultType="com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion">
234
     <select id="listQuestionByStu" resultType="com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion">
235
-        select epsqid,eptqid,qn,stuscore
235
+        select epsqid,eptqid,qn,stuscore,epsid
236
         from e_paper_student_question where studentid=#{studentid} and eptqid in
236
         from e_paper_student_question where studentid=#{studentid} and eptqid in
237
         <foreach collection="eptqids" item="eptqid" open="(" separator="," close=")">${eptqid}</foreach>
237
         <foreach collection="eptqids" item="eptqid" open="(" separator="," close=")">${eptqid}</foreach>
238
         order by epsqid
238
         order by epsqid
239
     </select>
239
     </select>
240
+    <!--批量更新学生试题得分-->
241
+    <update id="updateBatchStuQuestionSore">
242
+        update e_paper_student_question
243
+        <trim prefix="set" suffixOverrides=",">
244
+            <trim prefix="stuscore = case" suffix="end,">
245
+                <foreach collection="list" item="q">
246
+                    when epsqid=#{q.epsqid} then #{q.stuscore}
247
+                </foreach>
248
+            </trim>
249
+        </trim>
250
+        <where>
251
+            <foreach collection="list" item="q" separator="or">
252
+                epsqid=#{q.epsqid}
253
+            </foreach>
254
+        </where>
255
+    </update>
240
 </mapper>
256
 </mapper>

Loading…
Cancel
Save