|
@@ -416,10 +416,19 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
List<StudentVo> studentVos = studentDao.selectPage(PageUtil.getPage(studentSearch), studentSearch);
|
|
|
Map<String, StudentVo> mapStudentByPhone = studentVos.stream().collect(Collectors.toMap(StudentVo::getPhone, Function.identity()));
|
|
|
|
|
|
- Map<Integer,List<String>> errMsgMap = new LinkedHashMap<>();
|
|
|
+// Map<Integer,List<String>> errMsgMap = new LinkedHashMap<>();
|
|
|
Map<String, Integer> codeRowMap = new HashMap<>();
|
|
|
|
|
|
- String errTemplate = "第%s行%s";
|
|
|
+
|
|
|
+ String phone_err = "手机号错误或已注册成为其他机构";
|
|
|
+ List<Integer> phone_err_lines = new ArrayList<>();
|
|
|
+ String code_send = "激活码已被发放";
|
|
|
+ List<Integer> code_send_lines = new ArrayList<>();
|
|
|
+ String code_not_exist = "激活码不存在";
|
|
|
+ List<Integer> code_not_exist_lines = new ArrayList<>();
|
|
|
+ String code_repeat = "激活码重复";
|
|
|
+ Map<String,List<Integer>> code_repeat_lines = new LinkedHashMap<>();
|
|
|
+
|
|
|
int rowIndex = 1;
|
|
|
// 校验数据格式是否错误 第二行开始取数据
|
|
|
for (TenantActivationCodeWrapper.ImportTemplate template : importTemplates) {
|
|
@@ -430,40 +439,81 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
continue;
|
|
|
}
|
|
|
int msgRowNo = rowIndex;
|
|
|
- List<String> errList = errMsgMap.getOrDefault(msgRowNo, new ArrayList<>());
|
|
|
+// List<String> errList = errMsgMap.getOrDefault(msgRowNo, new ArrayList<>());
|
|
|
String code = template.getCode();
|
|
|
if (codeRowMap.containsKey(code)) {
|
|
|
- errList.add(String.format(errTemplate, msgRowNo, "激活码重复"));
|
|
|
+ List<Integer> lines = code_repeat_lines.getOrDefault(code, new ArrayList<>());
|
|
|
+ Integer repeatLine = codeRowMap.get(code);
|
|
|
+ if (!lines.contains(repeatLine)) {
|
|
|
+ lines.add(repeatLine);
|
|
|
+ }
|
|
|
+ lines.add(msgRowNo);
|
|
|
} else {
|
|
|
codeRowMap.put(acCode, msgRowNo);
|
|
|
}
|
|
|
|
|
|
if (!mapByCode.containsKey(code)) {
|
|
|
- errList.add(String.format(errTemplate, msgRowNo, "激活码不存在"));
|
|
|
+ code_not_exist_lines.add(msgRowNo);
|
|
|
} else {
|
|
|
TenantActivationCode tenantActivationCode = mapByCode.get(code);
|
|
|
if (tenantActivationCode.getActivationStatus() || EActivationCode.SEND.equals(tenantActivationCode.getSendStatus())) {
|
|
|
- errList.add(String.format(errTemplate, msgRowNo, "激活码已被发放/激活"));
|
|
|
+ code_send_lines.add(msgRowNo);
|
|
|
}
|
|
|
}
|
|
|
String phone = template.getPhone();
|
|
|
if (StringUtils.isNotEmpty(phone)) {
|
|
|
if (!Pattern.matches(PHONE_REG, phone.trim()) ||
|
|
|
(mapStudentByPhone.containsKey(phone) && !mapStudentByPhone.get(phone).getTenantId().equals(tenantId))) {
|
|
|
- errList.add(String.format(errTemplate, msgRowNo, "手机号错误或已注册成为其他机构学员"));
|
|
|
+ phone_err_lines.add(msgRowNo);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- errMsgMap.put(msgRowNo, errList);
|
|
|
+// errMsgMap.put(msgRowNo, errList);
|
|
|
}
|
|
|
|
|
|
- List<String> errMsg = errMsgMap.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
- if (!errMsg.isEmpty()) {
|
|
|
- String errLines = errMsgMap.entrySet().stream().filter(next -> CollectionUtils.isNotEmpty(next.getValue()))
|
|
|
- .map(next -> String.valueOf(next.getKey())).collect(Collectors.joining("、"));
|
|
|
- errMsg.add(0, "第" + errLines + "行存在错误");
|
|
|
- throw new BizException(String.join(",", errMsg));
|
|
|
+
|
|
|
+ int totalErrSize = phone_err_lines.size() + code_send_lines.size() + code_not_exist_lines.size() + code_repeat_lines.values().size();
|
|
|
+ if (totalErrSize > 0) {
|
|
|
+ StringBuilder errMsg = new StringBuilder("");
|
|
|
+ errMsg.append("导入失败,共").append(totalErrSize).append("条错误信息~");
|
|
|
+ if (!phone_err_lines.isEmpty()) {
|
|
|
+ errMsg.append("\n");
|
|
|
+ String errLines = phone_err_lines.stream().map(String::valueOf).collect(Collectors.joining("、"));
|
|
|
+ errMsg.append("第").append(errLines).append("行错误,").append(phone_err);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!code_send_lines.isEmpty()) {
|
|
|
+ errMsg.append("\n");
|
|
|
+ String errLines = code_send_lines.stream().map(String::valueOf).collect(Collectors.joining("、"));
|
|
|
+ errMsg.append("第").append(errLines).append("行错误,").append(errLines).append(code_send);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!code_not_exist_lines.isEmpty()) {
|
|
|
+ errMsg.append("\n");
|
|
|
+ String errLines = code_not_exist_lines.stream().map(String::valueOf).collect(Collectors.joining("、"));
|
|
|
+ errMsg.append("第").append(errLines).append("行错误,").append(code_not_exist);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!code_repeat_lines.isEmpty()) {
|
|
|
+ errMsg.append("\n");
|
|
|
+ List<String> lineErr = new ArrayList<>();
|
|
|
+ for (List<Integer> value : code_repeat_lines.values()) {
|
|
|
+ String errLines = value.stream().map(String::valueOf).collect(Collectors.joining("、"));
|
|
|
+ lineErr.add("第" + errLines + "行");
|
|
|
+ }
|
|
|
+ errMsg.append(String.join(",", lineErr)).append("行错误,").append(code_repeat);
|
|
|
+ }
|
|
|
+ throw new BizException(errMsg.toString());
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+// List<String> errMsg = errMsgMap.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
+// if (!errMsg.isEmpty()) {
|
|
|
+// String errLines = errMsgMap.entrySet().stream().filter(next -> CollectionUtils.isNotEmpty(next.getValue()))
|
|
|
+// .map(next -> String.valueOf(next.getKey())).collect(Collectors.joining("、"));
|
|
|
+// errMsg.add(0, "第" + errLines + "行存在错误");
|
|
|
+// throw new BizException(String.join(",", errMsg));
|
|
|
+// }
|
|
|
List<TenantActivationCode> tenantActivationCodes = importTemplates.stream()
|
|
|
.filter(next -> StringUtils.isNotEmpty(next.getCode()) && StringUtils.isNotBlank(next.getPhone()))
|
|
|
.map(next -> {
|