Jelajahi Sumber

update studentImport

deason 8 bulan lalu
induk
melakukan
3b657d1151

+ 4 - 2
src/main/java/cn/com/qmth/scancentral/controller/admin/StudentImportController.java

@@ -48,7 +48,9 @@ public class StudentImportController extends BaseController {
 
     @ApiOperation(value = "考生导入")
     @PostMapping("/import")
-    public Map<String, Object> studentImport(@RequestParam Long examId, @RequestParam MultipartFile file) throws Exception {
+    public Map<String, Object> studentImport(@RequestParam Long examId,
+                                             @RequestParam(required = false) String subjectCode,
+                                             @RequestParam MultipartFile file) throws Exception {
         if (studentImportService.existRunningStudentImportTask()) {
             throw new StatusException("有正在运行的考生导入任务,请稍后再试!");
         }
@@ -81,7 +83,7 @@ public class StudentImportController extends BaseController {
             throw new StatusException("读取导入数据文件失败!");
         }
 
-        studentImportService.studentImport(taskId, lines, examId, exam.getYear(), exam.getYearHalf());
+        studentImportService.studentImport(taskId, lines, examId, subjectCode, exam.getYear(), exam.getYearHalf());
 
         Map<String, Object> result = new HashMap<>();
         result.put("taskId", taskId);

+ 1 - 1
src/main/java/cn/com/qmth/scancentral/service/StudentImportService.java

@@ -8,7 +8,7 @@ public interface StudentImportService {
 
     boolean existRunningStudentImportTask();
 
-    void studentImport(String taskId, List<String> lines, Long examId, Integer yearConfig, Integer yearHalfConfig);
+    void studentImport(String taskId, List<String> lines, Long examId, String subjectCode, Integer yearConfig, Integer yearHalfConfig);
 
     ImportTaskVo studentImportProgress(String taskId);
 

+ 20 - 33
src/main/java/cn/com/qmth/scancentral/service/impl/StudentImportServiceImpl.java

@@ -1,14 +1,13 @@
 package cn.com.qmth.scancentral.service.impl;
 
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.regex.Pattern;
-
+import cn.com.qmth.scancentral.bean.ImportStudentDomain;
 import cn.com.qmth.scancentral.enums.AsyncTaskStatus;
+import cn.com.qmth.scancentral.service.StudentImportService;
+import cn.com.qmth.scancentral.service.StudentService;
+import cn.com.qmth.scancentral.service.SubjectService;
+import cn.com.qmth.scancentral.vo.studentimport.ImportTaskVo;
+import cn.com.qmth.scancentral.vo.studentimport.StudentImportInfo;
+import com.qmth.boot.core.exception.ParameterException;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -16,14 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 
-import com.qmth.boot.core.exception.ParameterException;
-
-import cn.com.qmth.scancentral.bean.ImportStudentDomain;
-import cn.com.qmth.scancentral.service.StudentImportService;
-import cn.com.qmth.scancentral.service.StudentService;
-import cn.com.qmth.scancentral.service.SubjectService;
-import cn.com.qmth.scancentral.vo.studentimport.ImportTaskVo;
-import cn.com.qmth.scancentral.vo.studentimport.StudentImportInfo;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.regex.Pattern;
 
 @Component
 public class StudentImportServiceImpl implements StudentImportService {
@@ -59,8 +53,8 @@ public class StudentImportServiceImpl implements StudentImportService {
 
     @Async
     @Override
-    public void studentImport(String taskId, List<String> lines, Long examId, Integer yearConfig,
-            Integer yearHalfConfig) {
+    public void studentImport(String taskId, List<String> lines, Long examId, String subjectCode, Integer yearConfig,
+                              Integer yearHalfConfig) {
         ImportTaskVo task = new ImportTaskVo();
         task.setTaskId(taskId);
         task.setProgress(0d);
@@ -69,7 +63,7 @@ public class StudentImportServiceImpl implements StudentImportService {
 
         List<StudentImportInfo> list = new ArrayList<>();
         try {
-            this.parseValues(lines, list, examId, yearConfig, yearHalfConfig);
+            this.parseValues(lines, list, examId, subjectCode, yearConfig, yearHalfConfig);
             log.warn("【考生导入】解析考生数据,有效共{}条! taskId:{}", list.size(), taskId);
         } catch (Exception e) {
             log.error("【考生导入】解析考生数据错误! taskId:{} {}", taskId, e.getMessage());
@@ -135,8 +129,8 @@ public class StudentImportServiceImpl implements StudentImportService {
         return data;
     }
 
-    private void parseValues(List<String> lines, List<StudentImportInfo> list, Long examId, Integer yearConfig,
-            Integer yearHalfConfig) {
+    private void parseValues(List<String> lines, List<StudentImportInfo> list, Long examId, String subjectCodeConfig,
+                             Integer yearConfig, Integer yearHalfConfig) {
         Set<String> subjectCodes = new HashSet<>();
         Set<String> examNumbers = new HashSet<>();
         Pattern examNumberPattern = Pattern.compile("^[0-9]{15}$");
@@ -186,8 +180,12 @@ public class StudentImportServiceImpl implements StudentImportService {
                 throw new RuntimeException(String.format("【第%s行】考次不正确", n + 1));
             }
 
-            String province = examNumber.substring(0, 3);
             String subjectCode = examNumber.substring(9, 10);
+            if (StringUtils.isNotBlank(subjectCodeConfig) && !subjectCodeConfig.equals(subjectCode)) {
+                throw new RuntimeException(String.format("【第%s行】科目代码不正确", n + 1));
+            }
+
+            String province = examNumber.substring(0, 3);
             String examSite = examNumber.substring(0, 5);
             String campusCode = examNumber.substring(5, 6);
             String examRoom = examNumber.substring(10, 13);
@@ -220,15 +218,4 @@ public class StudentImportServiceImpl implements StudentImportService {
         }
     }
 
-    // private void writeLogFile(File logFile, String content) {
-    // if (StringUtils.isEmpty(content)) {
-    // return;
-    // }
-    // try {
-    // FileUtils.writeStringToFile(logFile, "\n" + content, "UTF-8", true);
-    // } catch (IOException e) {
-    // log.error(e.getMessage(), e);
-    // }
-    // }
-
 }