|
@@ -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 = "格式不正确";
|