ソースを参照

补录成绩导入

tags/正式版本
雍文秀 2年前
コミット
45e390b032

+ 2
- 1
sexam/src/main/java/com/xhkjedu/sexam/controller/paperstudent/EPsqbatchController.java ファイルの表示

@@ -95,7 +95,8 @@ public class EPsqbatchController {
95 95
      **/
96 96
     @PostMapping("/import")
97 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 100
         return ePsqbatchService.importRecord(file, batch);
100 101
     }
101 102
 

+ 3
- 0
sexam/src/main/java/com/xhkjedu/sexam/mapper/paperstudent/EPaperStudentQuestionMapper.java ファイルの表示

@@ -67,4 +67,7 @@ public interface EPaperStudentQuestionMapper extends TkMapper<EPaperStudentQuest
67 67
 
68 68
     //获取学生试题列表
69 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 ファイルの表示

@@ -0,0 +1,9 @@
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 ファイルの表示

@@ -3,7 +3,9 @@ package com.xhkjedu.sexam.service.paperstudent;
3 3
 import com.xhkjedu.sexam.mapper.exam.EBaseMapper;
4 4
 import com.xhkjedu.sexam.mapper.exam.EClassStudentMapper;
5 5
 import com.xhkjedu.sexam.mapper.paper.EPaperQtypeQuestionMapper;
6
+import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentMapper;
6 7
 import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentQuestionMapper;
8
+import com.xhkjedu.sexam.mapper.paperstudent.EPsqbatchDetailMapper;
7 9
 import com.xhkjedu.sexam.mapper.paperstudent.EPsqbatchMapper;
8 10
 import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
9 11
 import com.xhkjedu.sexam.model.paperstudent.EPsqbatch;
@@ -41,7 +43,11 @@ public class EPsqbatchService {
41 43
     @Resource
42 44
     private EPaperStudentQuestionMapper ePaperStudentQuestionMapper;
43 45
     @Resource
46
+    private EPaperStudentMapper ePaperStudentMapper;
47
+    @Resource
44 48
     private EBaseMapper eBaseMapper;
49
+    @Resource
50
+    private EPsqbatchDetailMapper ePsqbatchDetailMapper;
45 51
 
46 52
     /**
47 53
      * @Description 获取考试科目
@@ -88,29 +94,32 @@ public class EPsqbatchService {
88 94
             if (code != 0) return new ResultVo(1, map.get("msg").toString());
89 95
             LinkedHashMap<Integer, List<String>> errMsg = (LinkedHashMap<Integer, List<String>>) map.get("errMsg");
90 96
             if (errMsg.size() != 0) return new ResultVo(1, null, errMsg);
91
-            ePsqbatchMapper.insertUseGeneratedKeys(batch);
92 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 101
             for (EPsqbatchStuVo stu : stus) {
94 102
                 new Thread(()->{
95 103
                     try {
96 104
                         saveEPsqbatchDetail(stu,batch);
97 105
                     }catch (Exception e){
98
-                        log.error("保存学生试题重试:" + e.getMessage());
106
+                        log.error("补录学生成绩重试:" + e.getMessage());
99 107
                         try {
100 108
                             saveEPsqbatchDetail(stu,batch);
101 109
                         }catch (Exception se){
102
-                            log.error("保存学生试题重试出错:" + se.getMessage());
110
+                            log.error("补录学生成绩重试出错:" + se.getMessage());
103 111
                         }
104 112
                     }
105 113
                 }).start();
106 114
             }
107 115
         } catch (Exception e) {
108
-            e.printStackTrace();
116
+            log.error("导入补录学生成绩失败",e);
117
+            return new ResultVo(1,e.getMessage());
109 118
         }
110 119
         return new ResultVo(0,"导入成功");
111 120
     }
112 121
 
113
-    //保存学生试题
122
+    //补录学生成绩
114 123
     @Transactional(rollbackFor = Exception.class)
115 124
     public void saveEPsqbatchDetail(EPsqbatchStuVo stu, EPsqbatch batch) {
116 125
         try {
@@ -127,16 +136,23 @@ public class EPsqbatchService {
127 136
                 EPsqbatchDetail detail = details.get(i);
128 137
                 EPaperStudentQuestion question = questions.get(i);
129 138
                 question.setStuscore(detail.getNewscore());
130
-                detail.setStuscore(question.getStuscore());
131
-                detail.setEpid(epid);
132 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 145
                 detail.setTeacherid(teacherid);
134 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 152
         } catch (Exception e) {
137
-            log.error("保存学生试题失败:" + e.getMessage());
153
+            log.error("补录学生成绩失败:" + e.getMessage());
138 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 ファイルの表示

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

+ 17
- 1
sexam/src/main/resources/mapper/paperstudent/EPaperStudentQuestionMapper.xml ファイルの表示

@@ -232,9 +232,25 @@
232 232
     </select>
233 233
     <!--/获取学生试题列表-->
234 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 236
         from e_paper_student_question where studentid=#{studentid} and eptqid in
237 237
         <foreach collection="eptqids" item="eptqid" open="(" separator="," close=")">${eptqid}</foreach>
238 238
         order by epsqid
239 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 256
 </mapper>

読み込み中…
キャンセル
保存