deason 1 年之前
父节点
当前提交
e9178b05a1

+ 37 - 8
src/main/java/cn/com/qmth/examcloud/tool/service/export_student_photo/ExportStudentPhotoTask.java

@@ -17,7 +17,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 @Component
@@ -34,10 +36,12 @@ public class ExportStudentPhotoTask {
     private static final String EXPORT_DIR = "D:/home/captures/photo/";
 
     public void start(User user) {
-        this.execute(user);
+        // List<StudentVO> hasPhotoStudents = this.loadStudentFromUrl(user);
+        List<StudentVO> hasPhotoStudents = this.loadStudentFromExcel();
+        this.downloadStudents(hasPhotoStudents);
     }
 
-    private void execute(User user) {
+    private List<StudentVO> loadStudentFromUrl(User user) {
         Map<String, String> headers = new HashMap<>();
         headers.put("key", user.getKey());
         headers.put("token", user.getToken());
@@ -45,8 +49,10 @@ public class ExportStudentPhotoTask {
         JsonMapper jsonMapper = new JsonMapper();
         long pageNo = 0, pageSize = 100, total = 0, finishedCount = 0, noPhotoCount = 0;
 
-        String url = user.getServerUrl()
+        final String url = user.getServerUrl()
                 + "/api/ecs_core/student/studentPage/%s/%s?rootOrgId=%s&identityNumber=&studentCode=&name=";
+
+        List<StudentVO> hasPhotoStudents = new ArrayList<>();
         while (true) {
             String json = HttpHelper.get(String.format(url, pageNo, pageSize, user.getRootOrgId()), headers, null);
 
@@ -63,22 +69,45 @@ public class ExportStudentPhotoTask {
                     continue;
                 }
 
-                // 下载底照
-                this.downloadPhoto(student);
+                student.setPhotoPath(this.fixPhotoUrl(student.getPhotoPath()));
+                hasPhotoStudents.add(student);
             }
 
             pageNo++;
             total = page.getTotal();
             finishedCount += page.getList().size();
             float finishedRate = finishedCount * 100f / total;
-            log.info("【{}】 总数:{} 已处理学生数:{} 无底照学生数:{} 进度:{}%", pageNo, total, finishedCount,
+            log.info("【{}】 总数:{} 已获取学生数:{} 无底照学生数:{} 进度:{}%", pageNo, total, finishedCount,
                     noPhotoCount, finishedRate);
         }
+
+        return hasPhotoStudents;
+    }
+
+    private List<StudentVO> loadStudentFromExcel() {
+        List<StudentVO> hasPhotoStudents = new ArrayList<>();
+        //todo
+        return hasPhotoStudents;
+    }
+
+    private void downloadStudents(List<StudentVO> students) {
+        for (StudentVO student : students) {
+            // 下载底照
+            this.downloadPhoto(student);
+        }
     }
 
     private void downloadPhoto(StudentVO student) {
         String identityNumber = student.getIdentityNumber();
-        String studentCode = student.getStudentCodeList().get(0);
+
+        String studentCode;
+        if (CollectionUtils.isNotEmpty(student.getStudentCodeList())) {
+            studentCode = student.getStudentCodeList().get(0);
+        } else {
+            log.warn("【无学号】 studentCode:{} identityNumber:{}", student.getStudentCodesStr(),
+                    student.getIdentityNumber());
+            studentCode = "IDCard_" + student.getIdentityNumber();
+        }
 
         String filePath = EXPORT_DIR + "/" + student.getRootOrgId() + "/" + studentCode + ".jpg";
         if (new File(filePath).exists()) {
@@ -87,7 +116,7 @@ public class ExportStudentPhotoTask {
         }
 
         try {
-            FileHelper.saveImageToFile(this.fixPhotoUrl(student.getPhotoPath()), filePath);
+            FileHelper.saveImageToFile(student.getPhotoPath(), filePath);
         } catch (Exception e) {
             log.error("studentCode:{} identityNumber:{} err:{}", studentCode, identityNumber, e.getMessage());
         }