Преглед изворни кода

add:
1.考生导入逻辑更改

caozixuan пре 1 година
родитељ
комит
d8e3a07037

+ 56 - 35
src/main/java/cn/com/qmth/print/manage/service/impl/ExamStudentServiceImpl.java

@@ -12,7 +12,6 @@ import cn.com.qmth.print.manage.entity.ExamEntity;
 import cn.com.qmth.print.manage.entity.ExamStudentEntity;
 import cn.com.qmth.print.manage.enums.GroupType;
 import cn.com.qmth.print.manage.enums.RecordStatus;
-import cn.com.qmth.print.manage.service.BreakRecordService;
 import cn.com.qmth.print.manage.service.CheckRecordService;
 import cn.com.qmth.print.manage.service.ExamStudentService;
 import cn.com.qmth.print.manage.service.query.ExamStudentQuery;
@@ -53,9 +52,6 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
     @Resource
     private CheckRecordService checkRecordService;
 
-    @Resource
-    private BreakRecordService breakRecordService;
-
     @Resource
     private ExamDao examDao;
 
@@ -139,7 +135,6 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
         ExamEntity examEntity = examDao.selectById(examId);
         List<ExamStudentEntity> studentList = new ArrayList<>();
         ExcelReader excelReader = new ExcelReader(StudentDTO.class);
-        AtomicLong aLong = new AtomicLong(1L);
         List<ExcelError> excelErrors = excelReader.reader(file.getInputStream(), obj -> {
             try {
                 StudentDTO dto = (StudentDTO) obj;
@@ -180,7 +175,6 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
                 examStudentEntity.setCourseCode(subjectCode.concat(PmConstants.LING_SIGN).concat(subjectName));
                 examStudentEntity.setExamSite(examSite);
                 examStudentEntity.setExamRoom(dto.getExamRoom());
-                examStudentEntity.setSortNo(aLong.getAndIncrement());
                 examStudentEntity.setExamUnit(dto.getExamUnit());
                 examStudentEntity.setCreateTime(new Date());
                 examStudentEntity.setUpdateTime(new Date());
@@ -242,7 +236,6 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
             ExamEntity examEntity = examDao.selectById(examId);
             List<ExamStudentEntity> studentList = new ArrayList<>();
             ExcelReader excelReader = new ExcelReader(ExamStudentImportDTO.class);
-            AtomicLong sort = new AtomicLong(1L);
             List<ExcelError> excelErrors = excelReader.reader(FileUtil.getInputStream(studentExcel), obj -> {
                 try {
                     String nullError = "";
@@ -280,7 +273,6 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
                     examStudentEntity.setName(name);
                     examStudentEntity.setCourseCode(subjectCode.concat(PmConstants.LING_SIGN).concat(subjectName));
                     examStudentEntity.setExamSite(dto.getExamPlaceCode());
-                    examStudentEntity.setSortNo(sort.getAndIncrement());
                     examStudentEntity.setExamUnit(dto.getExamUnit());
                     examStudentEntity.setCreateTime(new Date());
                     examStudentEntity.setUpdateTime(new Date());
@@ -328,21 +320,61 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
 
     @Transactional
     public void insertData(ExamEntity examEntity, List<ExamStudentEntity> studentList) {
-        // 有校验数据不能删除
-        if (checkRecordService.count(new QueryWrapper<CheckRecordEntity>().lambda()
-                .eq(CheckRecordEntity::getExamId, examEntity.getId())
-                .ne(CheckRecordEntity::getStatus, RecordStatus.NONE)) > 0) {
-            throw new StatusException("已有校验数据,不可重复导入");
-        }
+        // 考试批次的分组字段
+        GroupType groupType = examEntity.getGroupType();
 
-        // 删除考生表
-        this.deleteByExamId(examEntity.getId());
-        // 删除校验记录
-        checkRecordService.deleteByExamId(examEntity.getId());
-        // 删除中断记录
-        breakRecordService.deleteByExamId(examEntity.getId());
+        List<ExamStudentEntity> dbStudentList = this.list(new QueryWrapper<ExamStudentEntity>()
+                .lambda()
+                .eq(ExamStudentEntity::getExamId, examEntity.getId()));
+
+        Map<String, List<ExamStudentEntity>> groupCollection = null;
+        switch (groupType) {
+            case COURSE:
+                // 导入的新考生数据不能包含有之前科目的
+                List<String> dbCourseList = dbStudentList
+                        .stream()
+                        .filter(e -> e.getCourseCode() != null && e.getCourseCode().length() > 0)
+                        .map(ExamStudentEntity::getCourseCode)
+                        .distinct()
+                        .collect(Collectors.toList());
+                if (studentList.stream().anyMatch(e -> dbCourseList.contains(e.getCourseCode()))) {
+                    throw new StatusException(String.format("分组字段[%s]重复导入考生", GroupType.COURSE.getName()));
+                }
+                groupCollection = studentList.stream().collect(Collectors.groupingBy(ExamStudentEntity::getCourseCode));
+                break;
+            case EXAM_SITE:
+                // 导入的新考生数据不能包含有之前考点
+                List<String> dbExamSiteList = dbStudentList
+                        .stream()
+                        .filter(e -> e.getExamSite() != null && e.getExamSite().length() > 0)
+                        .map(ExamStudentEntity::getExamSite)
+                        .distinct()
+                        .collect(Collectors.toList());
+                if (studentList.stream().anyMatch(e -> dbExamSiteList.contains(e.getExamSite()))) {
+                    throw new StatusException(String.format("分组字段[%s]重复导入考生", GroupType.EXAM_SITE.getName()));
+                }
+                groupCollection = studentList.stream().collect(Collectors.groupingBy(ExamStudentEntity::getExamSite));
+                break;
+            case EXAM_ROOM:
+                // 导入的新考生数据不能包含有之前烤成
+                List<String> dbExamRoomList = dbStudentList
+                        .stream()
+                        .filter(e -> e.getExamRoom() != null && e.getExamRoom().length() > 0)
+                        .map(ExamStudentEntity::getExamSite)
+                        .distinct()
+                        .collect(Collectors.toList());
+                if (studentList.stream().anyMatch(e -> dbExamRoomList.contains(e.getExamRoom()))) {
+                    throw new StatusException(String.format("分组字段[%s]重复导入考生", GroupType.EXAM_ROOM.getName()));
+                }
+                groupCollection = studentList.stream().collect(Collectors.groupingBy(ExamStudentEntity::getExamRoom));
+                break;
+        }
 
         // 添加考生
+        Long sort = dbStudentList.stream().map(ExamStudentEntity::getSortNo).max(Long::compare).orElse(0L);
+        AtomicLong aLong = new AtomicLong(sort);
+        studentList = studentList.stream().peek(e -> e.setSortNo(aLong.incrementAndGet())).collect(Collectors.toList());
+
         List<ExamStudentEntity> data = new ArrayList<>();
         for (ExamStudentEntity stu : studentList) {
             if (data.size() == 2000) {
@@ -355,17 +387,8 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
         if (!data.isEmpty()) {
             this.saveBatch(data);
         }
-        Map<String, List<ExamStudentEntity>> groupCollection = null;
 
-        if (examEntity.getGroupType().equals(GroupType.COURSE)) {
-            groupCollection = studentList.stream().collect(Collectors.groupingBy(ExamStudentEntity::getCourseCode));
-        } else if (examEntity.getGroupType().equals(GroupType.EXAM_SITE)) {
-            groupCollection = studentList.stream().collect(Collectors.groupingBy(ExamStudentEntity::getExamSite));
-        } else if (examEntity.getGroupType().equals(GroupType.EXAM_ROOM)) {
-            groupCollection = studentList.stream().collect(Collectors.groupingBy(ExamStudentEntity::getExamRoom));
-        }
         // 添加校验数据
-
         List<CheckRecordEntity> checkRecordEntities = new ArrayList<>();
         for (Map.Entry<String, List<ExamStudentEntity>> entry : groupCollection.entrySet()) {
             CheckRecordEntity checkRecordEntity = new CheckRecordEntity();
@@ -384,18 +407,16 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
     /**
      * 拼接导入异常信息
      *
-     * @param excelErrors
-     * @return
+     * @param excelErrors 错误信息
+     * @return 结果
      */
     private String errorsString(List<ExcelError> excelErrors) {
         StringJoiner sj = new StringJoiner(";");
-        if (!excelErrors.isEmpty() && excelErrors.size() > 0) {
+        if (!excelErrors.isEmpty()) {
             int forint = excelErrors.size() < 10 ? excelErrors.size() : 9;
             for (int i = 0; i < forint; i++) {
                 ExcelError excelError = excelErrors.get(i);
-                StringBuffer sb = new StringBuffer();
-                sb.append("第").append(excelError.getRow()).append("行,").append(excelError.getExcelErrorType());
-                sj.add(sb.toString());
+                sj.add("第" + excelError.getRow() + "行," + excelError.getExcelErrorType());
             }
         }
         return sj.toString();