Selaa lähdekoodia

补录成绩导入

tags/正式版本
雍文秀 2 vuotta sitten
vanhempi
commit
ebe353ec8d

+ 7
- 3
sexam/src/main/java/com/xhkjedu/sexam/service/paperstudent/EPsqbatchService.java Näytä tiedosto

@@ -1,6 +1,7 @@
1 1
 package com.xhkjedu.sexam.service.paperstudent;
2 2
 
3 3
 import com.xhkjedu.sexam.mapper.exam.EBaseMapper;
4
+import com.xhkjedu.sexam.mapper.exam.EClassMapper;
4 5
 import com.xhkjedu.sexam.mapper.exam.EClassStudentMapper;
5 6
 import com.xhkjedu.sexam.mapper.paper.EPaperQtypeQuestionMapper;
6 7
 import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentMapper;
@@ -48,6 +49,8 @@ public class EPsqbatchService {
48 49
     private EBaseMapper eBaseMapper;
49 50
     @Resource
50 51
     private EPsqbatchDetailMapper ePsqbatchDetailMapper;
52
+    @Resource
53
+    private EClassMapper eClassMapper;
51 54
 
52 55
     /**
53 56
      * @Description 获取考试科目
@@ -86,10 +89,11 @@ public class EPsqbatchService {
86 89
     public ResultVo importRecord(MultipartFile file, EPsqbatch batch) {
87 90
         Integer epid = batch.getEpid();
88 91
         Integer examid = batch.getExamid();
89
-        List<Map> students = eClassStudentMapper.listStuByExamId(examid);//考试学生列表
90
-        List<Map> qns = ePaperQtypeQuestionMapper.listQnByEpid(epid);
91 92
         try {
92
-            Map<String, Object> map = PoiUtils.readExcelRecord(file, qns, students);
93
+            List<Map> students = eClassStudentMapper.listStuByExamId(examid);//考试学生列表
94
+            List<Map> qns = ePaperQtypeQuestionMapper.listQnByEpid(epid);
95
+            List<Map> classes = eClassMapper.listByExamId(examid);
96
+            Map<String, Object> map = PoiUtils.readExcelRecord(file, qns, students, classes);
93 97
             Integer code = (Integer) map.get("code");
94 98
             if (code != 0) return new ResultVo(1, map.get("msg").toString());
95 99
             LinkedHashMap<Integer, List<String>> errMsg = (LinkedHashMap<Integer, List<String>>) map.get("errMsg");

+ 37
- 12
sexam/src/main/java/com/xhkjedu/sexam/utils/PoiUtils.java Näytä tiedosto

@@ -38,7 +38,8 @@ public class PoiUtils {
38 38
      * @Author ywx
39 39
      * @Date 2022/3/17 9:44
40 40
      **/
41
-    public static Map<String, Object> readExcelRecord(MultipartFile file, List<Map> qns, List<Map> students) throws Exception {
41
+    public static Map<String, Object> readExcelRecord(MultipartFile file, List<Map> qns, List<Map> students
42
+            , List<Map> classes) throws Exception {
42 43
         Map<String, Object> resultMap = new HashMap<>();
43 44
         Map<Integer, List<String>> errMsg = new LinkedHashMap<>();
44 45
         try {
@@ -66,7 +67,7 @@ public class PoiUtils {
66 67
                 questionMap.put(i + 2, (Integer) qns.get(i).get("eptqid"));
67 68
                 scoreMap.put(i + 2, (Double) qns.get(i).get("score"));
68 69
             }
69
-            String titleName = "姓名账号" + qn;//标题格式
70
+            String titleName = "姓名班级" + qn;//标题格式
70 71
             StringBuilder sb = new StringBuilder();
71 72
             for (int y = firstCellNum; y < lastCellNum; y++) {
72 73
                 sb.append(row.getCell(y));
@@ -75,9 +76,12 @@ public class PoiUtils {
75 76
             String importTitleName = sb.toString();
76 77
             if (!titleName.equals(importTitleName)) throw new Exception("标题格式不正确");
77 78
 
78
-            Map<String, Integer> stuMap = students.stream().collect(Collectors.toMap(
79
-                    s -> s.get("username").toString() + s.get("loginname").toString()
80
-                    , s -> (Integer) s.get("studentid")));
79
+            Map<Object, String> classMap = classes.stream().collect(Collectors.toMap(
80
+                    c -> c.get("classid"), c -> c.get("classname").toString()));
81
+
82
+            for (Map s : students) {
83
+                s.put("classname", classMap.get(s.get("classid")));
84
+            }
81 85
 
82 86
             // 导入记录信息
83 87
             List<EPsqbatchStuVo> stus = new ArrayList<>();
@@ -97,13 +101,34 @@ public class PoiUtils {
97 101
                 List<String> mrows = new ArrayList<>();
98 102
                 //遍历所有的列
99 103
                 String username = getCellValue(row.getCell(0));//姓名
100
-                String loginname = getCellValue(row.getCell(1));//账号
101
-                Integer studentid = stuMap.get(username + loginname);
102
-                if (N_Utils.isEmptyInteger(studentid)) {
103
-                    mrows.add("学生【" + username + "(" + loginname + ")】不存在");
104
-                    errMsg.put(x + 1, mrows);
105
-                    continue;//学生不存在处理下一行
104
+                String classname = getCellValue(row.getCell(1));//班级
105
+                Integer studentid = null;
106
+                List<Map> list;
107
+                if (N_Utils.isEmpty(classname)) {
108
+                    list = students.stream().filter(s -> username.equals(s.get("username").toString())).collect(Collectors.toList());
109
+                    if (N_Utils.isListEmpty(list) || list.size() > 1) {
110
+                        mrows.add("学生【" + username + "】班级不能为空");
111
+                        errMsg.put(x + 1, mrows);
112
+                        continue;//学生不存在处理下一行
113
+                    } else {
114
+                        studentid = (Integer) list.get(0).get("studentid");
115
+                    }
116
+                } else {
117
+                    list = students.stream().filter(s -> username.equals(s.get("username").toString())
118
+                            && classname.equals(s.get("classname").toString())).collect(Collectors.toList());
119
+                    if (N_Utils.isListEmpty(list)) {
120
+                        mrows.add("学生【" + username + "(" + classname + ")】不存在");
121
+                        errMsg.put(x + 1, mrows);
122
+                        continue;//学生不存在处理下一行
123
+                    } else if (list.size() > 1) {
124
+                        mrows.add("学生【" + username + "(" + classname + ")】存在多个");
125
+                        errMsg.put(x + 1, mrows);
126
+                        continue;//学生不存在处理下一行
127
+                    } else {
128
+                        studentid = (Integer) list.get(0).get("studentid");
129
+                    }
106 130
                 }
131
+
107 132
                 List<EPsqbatchDetail> details = new ArrayList<>();
108 133
                 for (int y = firstCellNum + 2; y < lastCellNum; y++) {
109 134
                     Cell cell = row.getCell(y);
@@ -140,7 +165,7 @@ public class PoiUtils {
140 165
         } catch (Exception e) {
141 166
             resultMap.put("code", 1);
142 167
             String msg = e.getMessage();
143
-            if(N_Utils.isEmpty(msg)) msg="读取报错";
168
+            if (N_Utils.isEmpty(msg)) msg = "读取报错";
144 169
             resultMap.put("msg", msg);
145 170
             if (msg.contains("Invalid ")) {
146 171
                 msg = "格式不正确";

+ 1
- 1
sexam/src/main/resources/mapper/exam/EClassStudentMapper.xml Näytä tiedosto

@@ -70,7 +70,7 @@
70 70
     </update>
71 71
     <!--考试学生列表-->
72 72
     <select id="listStuByExamId" resultType="java.util.Map">
73
-        select es.studentid,u.username,u.loginname
73
+        select es.studentid,u.username,u.loginname,es.classid
74 74
         from e_class_student es left join t_user u on es.studentid = u.userid
75 75
         where es.examid=#{examid}
76 76
     </select>

Loading…
Peruuta
Tallenna