|
@@ -1,41 +1,42 @@
|
|
|
package com.qmth.exam.reserve.service.impl;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.qmth.boot.core.exception.StatusException;
|
|
|
import com.qmth.boot.tools.excel.model.DataMap;
|
|
|
-import com.qmth.exam.reserve.bean.studentimport.StudentImportInfo;
|
|
|
import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
|
|
|
import com.qmth.exam.reserve.entity.CategoryEntity;
|
|
|
-import com.qmth.exam.reserve.entity.StudentCourseEntity;
|
|
|
import com.qmth.exam.reserve.entity.StudentEntity;
|
|
|
import com.qmth.exam.reserve.entity.StudentImportTaskEntity;
|
|
|
import com.qmth.exam.reserve.enums.CategoryLevel;
|
|
|
import com.qmth.exam.reserve.enums.ImportStatus;
|
|
|
-import com.qmth.exam.reserve.service.*;
|
|
|
-import org.apache.commons.codec.digest.DigestUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.function.Function;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import com.qmth.exam.reserve.service.CategoryService;
|
|
|
+import com.qmth.exam.reserve.service.StudentImportAsyncService;
|
|
|
+import com.qmth.exam.reserve.service.StudentImportTaskService;
|
|
|
+import com.qmth.exam.reserve.service.StudentService;
|
|
|
|
|
|
@Service
|
|
|
public class StudentImportAsyncServiceImpl implements StudentImportAsyncService {
|
|
|
|
|
|
private final static Logger log = LoggerFactory.getLogger(StudentImportAsyncServiceImpl.class);
|
|
|
|
|
|
- private static final String[] EXCEL_HEADER = new String[] { "学号", "姓名", "证件号", "所属教学点代码", "所属教学点名称", "科目名称", "科目代码" };
|
|
|
+ private static final String[] EXCEL_HEADER = new String[] { "学号", "姓名", "证件号", "所属教学点代码", "所属教学点名称", "可约时段数" };
|
|
|
|
|
|
@Autowired
|
|
|
private CategoryService categoryService;
|
|
@@ -49,20 +50,17 @@ public class StudentImportAsyncServiceImpl implements StudentImportAsyncService
|
|
|
@Autowired
|
|
|
private ApplyTaskCacheService cacheService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private StudentCourseService studentCourseService;
|
|
|
-
|
|
|
@Async
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public void asyncImportStudent(StudentImportTaskEntity task, Long orgId, List<DataMap> lineList) {
|
|
|
Map<String, CategoryEntity> teachingCache = getTeachingCache();
|
|
|
- List<StudentImportInfo> studentList = new ArrayList<>();
|
|
|
+ List<StudentEntity> studentList = new ArrayList<StudentEntity>();
|
|
|
List<Map<String, Object>> failRecords = new ArrayList<Map<String, Object>>();
|
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
|
DataMap line = lineList.get(i);
|
|
|
StringBuilder msg = new StringBuilder();
|
|
|
- StudentImportInfo student = new StudentImportInfo();
|
|
|
+ StudentEntity student = new StudentEntity();
|
|
|
String studentCode = trimAndNullIfBlank(line.get(EXCEL_HEADER[0]));
|
|
|
if (StringUtils.isBlank(studentCode)) {
|
|
|
msg.append(" 学号不能为空");
|
|
@@ -112,21 +110,16 @@ public class StudentImportAsyncServiceImpl implements StudentImportAsyncService
|
|
|
student.setOrgId(orgId);
|
|
|
student.setApplyTaskId(task.getApplyTaskId());
|
|
|
}
|
|
|
-
|
|
|
- String courseName = trimAndNullIfBlank(line.get(EXCEL_HEADER[5]));
|
|
|
- if (StringUtils.isBlank(courseName)) {
|
|
|
- msg.append(" 科目名称不能为空");
|
|
|
- } else {
|
|
|
- student.setCourseName(courseName);
|
|
|
- }
|
|
|
-
|
|
|
- String courseCode = trimAndNullIfBlank(line.get(EXCEL_HEADER[6]));
|
|
|
- if (StringUtils.isBlank(courseCode)) {
|
|
|
- msg.append(" 科目代码不能为空");
|
|
|
- } else {
|
|
|
- student.setCourseCode(courseCode);
|
|
|
+ try {
|
|
|
+ String applyNumber = trimAndNullIfBlank(line.get(EXCEL_HEADER[5]));
|
|
|
+ if (StringUtils.isBlank(applyNumber)) {
|
|
|
+ msg.append(" 可约时段数不能为空");
|
|
|
+ } else {
|
|
|
+ student.setApplyNumber(Integer.parseInt(applyNumber));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ msg.append(" 可约时段只能为数字");
|
|
|
}
|
|
|
-
|
|
|
if (msg.length() > 0) {
|
|
|
failRecords.add(newError(i + 1, msg.toString()));
|
|
|
} else {
|
|
@@ -138,67 +131,10 @@ public class StudentImportAsyncServiceImpl implements StudentImportAsyncService
|
|
|
updateStudentImportTask(task, ImportStatus.FAILURE.toString(), failRecords);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- //更新和保存考生以及考生的考试科目
|
|
|
- long start = System.currentTimeMillis();
|
|
|
for (int i = 0; i < studentList.size(); i++) {
|
|
|
- StudentImportInfo studentInfo = studentList.get(i);
|
|
|
+ StudentEntity studentEntity = studentList.get(i);
|
|
|
try {
|
|
|
- //考生信息
|
|
|
- StudentEntity studentEntity = new StudentEntity();
|
|
|
- BeanUtils.copyProperties(studentInfo, studentEntity);
|
|
|
-
|
|
|
- //考生的考试科目
|
|
|
- StudentCourseEntity studentCourseEntity = new StudentCourseEntity();
|
|
|
- studentCourseEntity.setCourseCode(studentInfo.getCourseCode());
|
|
|
- studentCourseEntity.setCourseName(studentInfo.getCourseName());
|
|
|
-
|
|
|
- LambdaQueryWrapper<StudentEntity> wrapper = new LambdaQueryWrapper<StudentEntity>()
|
|
|
- .eq(StudentEntity::getStudentCode, studentEntity.getStudentCode())
|
|
|
- .eq(StudentEntity::getApplyTaskId, studentEntity.getApplyTaskId());
|
|
|
- StudentEntity existStudent = studentService.getOne(wrapper);
|
|
|
-
|
|
|
- LambdaQueryWrapper<StudentCourseEntity> studentCourseQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- studentCourseQueryWrapper.eq(StudentCourseEntity::getCourseCode, studentCourseEntity.getCourseCode());
|
|
|
-
|
|
|
- Long studentId;
|
|
|
- if (existStudent != null) {
|
|
|
- studentId = existStudent.getId();
|
|
|
- existStudent.setName(studentEntity.getName());
|
|
|
- existStudent.setIdentityNumber(studentEntity.getIdentityNumber());
|
|
|
- existStudent.setCategoryId(studentEntity.getCategoryId());
|
|
|
- studentService.updateById(existStudent);
|
|
|
-
|
|
|
- studentCourseQueryWrapper.eq(StudentCourseEntity::getStudentId, studentId);
|
|
|
- StudentCourseEntity existStudentCourse = studentCourseService.getOne(studentCourseQueryWrapper);
|
|
|
-
|
|
|
- //更新考生的考试科目
|
|
|
- if(existStudentCourse != null) {
|
|
|
- existStudentCourse.setCourseName(studentCourseEntity.getCourseName());
|
|
|
- studentCourseService.updateById(existStudentCourse);
|
|
|
- } else {
|
|
|
- studentCourseEntity.setStudentId(existStudent.getId());
|
|
|
- studentCourseService.save(studentCourseEntity);
|
|
|
- }
|
|
|
- } else {
|
|
|
- studentEntity.setApplyFinished(Boolean.FALSE);
|
|
|
- studentEntity.setApplyNumber(0);
|
|
|
- studentEntity.setPhotoPath(studentEntity.getIdentityNumber()+".jpg");
|
|
|
- studentService.save(studentEntity);
|
|
|
-
|
|
|
- studentId = studentEntity.getId();
|
|
|
-
|
|
|
- //保存考生科目
|
|
|
- studentCourseEntity.setStudentId(studentId);
|
|
|
- studentCourseService.save(studentCourseEntity);
|
|
|
- }
|
|
|
-
|
|
|
- //更新考生的预约次数
|
|
|
- studentService.updateStudentApplyNumber(studentId);
|
|
|
-
|
|
|
- // 清空缓存
|
|
|
- cacheService.clearStudentApplyNumberCache(studentId);
|
|
|
-
|
|
|
+ saveStudent(studentEntity);
|
|
|
} catch (StatusException e) {
|
|
|
failRecords.add(newError(i + 1, e.getMessage()));
|
|
|
} catch (Exception e) {
|
|
@@ -208,13 +144,7 @@ public class StudentImportAsyncServiceImpl implements StudentImportAsyncService
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
- long end = System.currentTimeMillis();
|
|
|
- log.warn("[耗时]{}ms", end - start);
|
|
|
-
|
|
|
- //更新成功标志
|
|
|
- task.setMessage(failRecords.isEmpty() ? null : failRecords.toString());
|
|
|
- task.setStatus(ImportStatus.SUCCESS.toString());
|
|
|
- importTaskService.saveOrUpdate(task);
|
|
|
+ updateStudentImportTask(task, ImportStatus.SUCCESS.toString(), failRecords);
|
|
|
}
|
|
|
|
|
|
private void updateStudentImportTask(StudentImportTaskEntity task, String status,
|
|
@@ -224,6 +154,26 @@ public class StudentImportAsyncServiceImpl implements StudentImportAsyncService
|
|
|
importTaskService.saveOrUpdate(task);
|
|
|
}
|
|
|
|
|
|
+ private void saveStudent(StudentEntity studentEntity) {
|
|
|
+ LambdaQueryWrapper<StudentEntity> wrapper = new LambdaQueryWrapper<StudentEntity>()
|
|
|
+ .eq(StudentEntity::getStudentCode, studentEntity.getStudentCode())
|
|
|
+ .eq(StudentEntity::getApplyTaskId, studentEntity.getApplyTaskId());
|
|
|
+ StudentEntity existStudent = studentService.getOne(wrapper);
|
|
|
+ if (existStudent != null) {
|
|
|
+ existStudent.setName(studentEntity.getName());
|
|
|
+ existStudent.setIdentityNumber(studentEntity.getIdentityNumber());
|
|
|
+ existStudent.setCategoryId(studentEntity.getCategoryId());
|
|
|
+ existStudent.setApplyNumber(studentEntity.getApplyNumber());
|
|
|
+ studentService.updateById(existStudent);
|
|
|
+ // 清空缓存
|
|
|
+ cacheService.clearStudentApplyNumberCache(existStudent.getId());
|
|
|
+ } else {
|
|
|
+ studentEntity.setApplyFinished(Boolean.FALSE);
|
|
|
+ studentEntity.setPhotoPath(studentEntity.getIdentityNumber()+".JPG");
|
|
|
+ studentService.save(studentEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private String trimAndNullIfBlank(String s) {
|
|
|
if (StringUtils.isBlank(s)) {
|
|
|
return null;
|