Browse Source

补录成绩导入

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

+ 7
- 3
sexam/src/main/java/com/xhkjedu/sexam/service/paperstudent/EPsqbatchService.java View File

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

38
      * @Author ywx
38
      * @Author ywx
39
      * @Date 2022/3/17 9:44
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
         Map<String, Object> resultMap = new HashMap<>();
43
         Map<String, Object> resultMap = new HashMap<>();
43
         Map<Integer, List<String>> errMsg = new LinkedHashMap<>();
44
         Map<Integer, List<String>> errMsg = new LinkedHashMap<>();
44
         try {
45
         try {
66
                 questionMap.put(i + 2, (Integer) qns.get(i).get("eptqid"));
67
                 questionMap.put(i + 2, (Integer) qns.get(i).get("eptqid"));
67
                 scoreMap.put(i + 2, (Double) qns.get(i).get("score"));
68
                 scoreMap.put(i + 2, (Double) qns.get(i).get("score"));
68
             }
69
             }
69
-            String titleName = "姓名账号" + qn;//标题格式
70
+            String titleName = "姓名班级" + qn;//标题格式
70
             StringBuilder sb = new StringBuilder();
71
             StringBuilder sb = new StringBuilder();
71
             for (int y = firstCellNum; y < lastCellNum; y++) {
72
             for (int y = firstCellNum; y < lastCellNum; y++) {
72
                 sb.append(row.getCell(y));
73
                 sb.append(row.getCell(y));
75
             String importTitleName = sb.toString();
76
             String importTitleName = sb.toString();
76
             if (!titleName.equals(importTitleName)) throw new Exception("标题格式不正确");
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
             List<EPsqbatchStuVo> stus = new ArrayList<>();
87
             List<EPsqbatchStuVo> stus = new ArrayList<>();
97
                 List<String> mrows = new ArrayList<>();
101
                 List<String> mrows = new ArrayList<>();
98
                 //遍历所有的列
102
                 //遍历所有的列
99
                 String username = getCellValue(row.getCell(0));//姓名
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
                 List<EPsqbatchDetail> details = new ArrayList<>();
132
                 List<EPsqbatchDetail> details = new ArrayList<>();
108
                 for (int y = firstCellNum + 2; y < lastCellNum; y++) {
133
                 for (int y = firstCellNum + 2; y < lastCellNum; y++) {
109
                     Cell cell = row.getCell(y);
134
                     Cell cell = row.getCell(y);
140
         } catch (Exception e) {
165
         } catch (Exception e) {
141
             resultMap.put("code", 1);
166
             resultMap.put("code", 1);
142
             String msg = e.getMessage();
167
             String msg = e.getMessage();
143
-            if(N_Utils.isEmpty(msg)) msg="读取报错";
168
+            if (N_Utils.isEmpty(msg)) msg = "读取报错";
144
             resultMap.put("msg", msg);
169
             resultMap.put("msg", msg);
145
             if (msg.contains("Invalid ")) {
170
             if (msg.contains("Invalid ")) {
146
                 msg = "格式不正确";
171
                 msg = "格式不正确";

+ 1
- 1
sexam/src/main/resources/mapper/exam/EClassStudentMapper.xml View File

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

Loading…
Cancel
Save