|
@@ -19,8 +19,8 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -61,67 +61,72 @@ public class BatchImportExamStudentTask implements TaskService {
|
|
|
EasyExcel.read(dataFilePath, ExamStudentInfo.class, dataListener).sheet().doRead();
|
|
|
List<ExamStudentInfo> dataList = dataListener.getList();
|
|
|
|
|
|
+ int total = dataList.size();
|
|
|
+ log.info("共{}条数据!examId:{}", total, examId);
|
|
|
+
|
|
|
+ // 检验数据
|
|
|
Map<String, Long> orgMaps = new HashMap<>();
|
|
|
Map<String, Long> courseMaps = new HashMap<>();
|
|
|
-
|
|
|
- int total = dataList.size();
|
|
|
- boolean hasError = false;
|
|
|
+ List<String> errMessages = new ArrayList<>();
|
|
|
for (int i = 0; i < total; i++) {
|
|
|
ExamStudentInfo examStudent = dataList.get(i);
|
|
|
+ examStudent.setExamId(examId);
|
|
|
|
|
|
if (StringUtils.isBlank(examStudent.getStudentName())) {
|
|
|
- log.warn("共{}条 第{}条 姓名不能为空!", total, i + 1);
|
|
|
- hasError = true;
|
|
|
+ errMessages.add("第" + (i + 1) + "条 姓名不能为空!");
|
|
|
+ } else {
|
|
|
+ examStudent.setStudentName(examStudent.getStudentName().trim());
|
|
|
}
|
|
|
+
|
|
|
if (StringUtils.isBlank(examStudent.getStudentCode())) {
|
|
|
- log.warn("共{}条 第{}条 学号不能为空!", total, i + 1);
|
|
|
- hasError = true;
|
|
|
+ errMessages.add("第" + (i + 1) + "条 学号不能为空!");
|
|
|
+ } else {
|
|
|
+ examStudent.setStudentCode(examStudent.getStudentCode().trim());
|
|
|
}
|
|
|
+
|
|
|
if (StringUtils.isBlank(examStudent.getIdentityNumber())) {
|
|
|
- log.warn("共{}条 第{}条 身份证号不能为空!", total, i + 1);
|
|
|
- hasError = true;
|
|
|
+ errMessages.add("第" + (i + 1) + "条 身份证号不能为空!");
|
|
|
+ } else {
|
|
|
+ examStudent.setIdentityNumber(examStudent.getIdentityNumber().trim());
|
|
|
}
|
|
|
+
|
|
|
if (StringUtils.isBlank(examStudent.getOrgCode())) {
|
|
|
- log.warn("共{}条 第{}条 机构代码不能为空!", total, i + 1);
|
|
|
- hasError = true;
|
|
|
+ errMessages.add("第" + (i + 1) + "条 机构代码不能为空!");
|
|
|
+ } else {
|
|
|
+ examStudent.setOrgCode(examStudent.getOrgCode().trim());
|
|
|
}
|
|
|
+
|
|
|
if (StringUtils.isBlank(examStudent.getCourseCode())) {
|
|
|
- log.warn("共{}条 第{}条 课程代码不能为空!", total, i + 1);
|
|
|
- hasError = true;
|
|
|
+ errMessages.add("第" + (i + 1) + "条 课程代码不能为空!");
|
|
|
+ } else {
|
|
|
+ examStudent.setCourseCode(examStudent.getCourseCode().trim());
|
|
|
}
|
|
|
|
|
|
Long orgId = orgMaps.get(examStudent.getOrgCode());
|
|
|
if (orgId == null) {
|
|
|
- orgId = this.queryOrgIdByCode(loginUser, examStudent.getOrgCode());
|
|
|
+ orgId = commonService.queryOrgIdByCode(loginUser, examStudent.getOrgCode());
|
|
|
if (orgId == null) {
|
|
|
- log.warn("共{}条 第{}条 机构代码不正确!", total, i + 1);
|
|
|
- hasError = true;
|
|
|
+ errMessages.add("第" + (i + 1) + "条 机构代码不正确!");
|
|
|
+ } else {
|
|
|
+ orgMaps.put(examStudent.getOrgCode(), orgId);
|
|
|
}
|
|
|
- orgMaps.put(examStudent.getOrgCode(), orgId);
|
|
|
}
|
|
|
+ examStudent.setOrgId(orgId);
|
|
|
|
|
|
Long courseId = courseMaps.get(examStudent.getCourseCode());
|
|
|
if (courseId == null) {
|
|
|
- courseId = this.queryCourseIdByCode(loginUser, examStudent.getCourseCode());
|
|
|
+ courseId = commonService.queryCourseIdByCode(loginUser, examStudent.getCourseCode());
|
|
|
if (courseId == null) {
|
|
|
- log.warn("共{}条 第{}条 课程代码不正确!", total, i + 1);
|
|
|
- hasError = true;
|
|
|
+ errMessages.add("第" + (i + 1) + "条 课程代码不正确!");
|
|
|
+ } else {
|
|
|
+ courseMaps.put(examStudent.getCourseCode(), courseId);
|
|
|
}
|
|
|
- courseMaps.put(examStudent.getCourseCode(), courseId);
|
|
|
}
|
|
|
-
|
|
|
- examStudent.setExamId(examId);
|
|
|
- examStudent.setOrgId(orgId);
|
|
|
examStudent.setCourseId(courseId);
|
|
|
- examStudent.setStudentName(examStudent.getStudentName().trim());
|
|
|
- examStudent.setStudentCode(examStudent.getStudentCode().trim());
|
|
|
- examStudent.setIdentityNumber(examStudent.getIdentityNumber().trim());
|
|
|
- examStudent.setOrgCode(examStudent.getOrgCode().trim());
|
|
|
- examStudent.setCourseCode(examStudent.getCourseCode().trim());
|
|
|
}
|
|
|
|
|
|
- if (hasError) {
|
|
|
- return;
|
|
|
+ if (!errMessages.isEmpty()) {
|
|
|
+ throw new StatusException(StringUtils.join(errMessages, "\n"));
|
|
|
}
|
|
|
|
|
|
int failCount = 0;
|
|
@@ -138,68 +143,10 @@ public class BatchImportExamStudentTask implements TaskService {
|
|
|
}
|
|
|
|
|
|
String msg = String.format("共%s条 成功%s条 失败%s条!", total, total - failCount, failCount);
|
|
|
- log.warn(msg);
|
|
|
+ log.info(msg);
|
|
|
task.setDescription(msg);
|
|
|
}
|
|
|
|
|
|
- private Long queryCourseIdByCode(User loginUser, String courseCode) {
|
|
|
- String url = loginUser.getServerUrl() + "/api/ecs_core/course/byCode";
|
|
|
- Map<String, String> headers = new HashMap<>();
|
|
|
- headers.put("key", loginUser.getKey());
|
|
|
- headers.put("token", loginUser.getToken());
|
|
|
-
|
|
|
- Map<String, String> params = new HashMap<>();
|
|
|
- params.put("rootOrgId", String.valueOf(loginUser.getRootOrgId()));
|
|
|
- params.put("code", courseCode);
|
|
|
-
|
|
|
- String result = HttpHelper.get(url, headers, params);
|
|
|
- log.info(result);
|
|
|
-
|
|
|
- JsonNode value = new JsonMapper().getNode(result);
|
|
|
- if (value == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- String id = value.get("id").asText();
|
|
|
- if (StringUtils.isNotEmpty(id)) {
|
|
|
- return Long.parseLong(id);
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- private Long queryOrgIdByCode(User loginUser, String orgCode) {
|
|
|
- String url = loginUser.getServerUrl() + "/api/ecs_core/org/subOrgPage/0/5";
|
|
|
- Map<String, String> headers = new HashMap<>();
|
|
|
- headers.put("key", loginUser.getKey());
|
|
|
- headers.put("token", loginUser.getToken());
|
|
|
-
|
|
|
- Map<String, String> params = new HashMap<>();
|
|
|
- params.put("parentId", String.valueOf(loginUser.getRootOrgId()));
|
|
|
- params.put("code", orgCode);
|
|
|
-
|
|
|
- String result = HttpHelper.get(url, headers, params);
|
|
|
- log.info(result);
|
|
|
-
|
|
|
- JsonNode value = new JsonMapper().getNode(result);
|
|
|
- if (value == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- int total = value.get("total").asInt();
|
|
|
- if (total > 0) {
|
|
|
- Iterator<JsonNode> list = value.get("list").iterator();
|
|
|
- while (list.hasNext()) {
|
|
|
- JsonNode node = list.next();
|
|
|
- if (orgCode.equals(node.get("code").asText())) {
|
|
|
- return node.get("id").asLong();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
private void saveStudent(User loginUser, ExamStudentInfo examStudent) {
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
headers.put("key", loginUser.getKey());
|
|
@@ -213,6 +160,7 @@ public class BatchImportExamStudentTask implements TaskService {
|
|
|
params.put("studentCode", examStudent.getStudentCode());
|
|
|
params.put("identityNumber", examStudent.getIdentityNumber());
|
|
|
params.put("specialtyName", examStudent.getSpecialtyName());
|
|
|
+ // 其它字段 暂略...
|
|
|
|
|
|
String url = loginUser.getServerUrl() + "/api/ecs_exam_work/exam_student";
|
|
|
String result = HttpHelper.put(url, headers, params);
|
|
@@ -220,6 +168,7 @@ public class BatchImportExamStudentTask implements TaskService {
|
|
|
|
|
|
JsonNode value = new JsonMapper().getNode(result);
|
|
|
if (value == null || !value.has("id")) {
|
|
|
+ // 创建成功会返回ID,否则失败
|
|
|
throw new StatusException(result);
|
|
|
}
|
|
|
}
|