|
@@ -33,22 +33,22 @@ public class ExportStudentPhotoTask {
|
|
|
|
|
|
private static final String EXPORT_DIR = "D:/home/captures/photo/";
|
|
|
|
|
|
- public void start(User user, Long rootOrgId) {
|
|
|
- this.execute(user, rootOrgId);
|
|
|
+ public void start(User user) {
|
|
|
+ this.execute(user);
|
|
|
}
|
|
|
|
|
|
- private void execute(User user, Long rootOrgId) {
|
|
|
+ private void execute(User user) {
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
headers.put("key", user.getKey());
|
|
|
headers.put("token", user.getToken());
|
|
|
|
|
|
JsonMapper jsonMapper = new JsonMapper();
|
|
|
- int sum = 0, pageNo = 0, pageSize = 100;
|
|
|
+ long pageNo = 0, pageSize = 100, total = 0, finishedCount = 0, noPhotoCount = 0;
|
|
|
|
|
|
String url = user.getServerUrl()
|
|
|
+ "/api/ecs_core/student/studentPage/%s/%s?rootOrgId=%s&identityNumber=&studentCode=&name=";
|
|
|
while (true) {
|
|
|
- String json = HttpHelper.get(String.format(url, pageNo, pageSize, rootOrgId), headers, null);
|
|
|
+ String json = HttpHelper.get(String.format(url, pageNo, pageSize, user.getRootOrgId()), headers, null);
|
|
|
|
|
|
PageInfo<StudentVO> page = jsonMapper.parseJson(json, new TypeReference<PageInfo<StudentVO>>() {
|
|
|
|
|
@@ -58,35 +58,48 @@ public class ExportStudentPhotoTask {
|
|
|
}
|
|
|
|
|
|
for (StudentVO student : page.getList()) {
|
|
|
+ if (StringUtils.isEmpty(student.getPhotoPath())) {
|
|
|
+ noPhotoCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
// 下载底照
|
|
|
this.downloadPhoto(student);
|
|
|
}
|
|
|
|
|
|
pageNo++;
|
|
|
- sum += page.getList().size();
|
|
|
- float rate = sum * 100f / page.getTotal();
|
|
|
- log.info("rootOrgId:{} 已下载学生底照数:{} 总数:{} 进度:{}%", rootOrgId, sum, page.getTotal(), rate);
|
|
|
+ total = page.getTotal();
|
|
|
+ finishedCount += page.getList().size();
|
|
|
+ float finishedRate = finishedCount * 100f / total;
|
|
|
+ log.info("【{}】 总数:{} 已处理学生数:{} 无底照学生数:{} 进度:{}%", pageNo, total, finishedCount,
|
|
|
+ noPhotoCount, finishedRate);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void downloadPhoto(StudentVO student) {
|
|
|
- if (StringUtils.isEmpty(student.getPhotoPath())) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
+ String identityNumber = student.getIdentityNumber();
|
|
|
String studentCode = student.getStudentCodeList().get(0);
|
|
|
|
|
|
String filePath = EXPORT_DIR + "/" + student.getRootOrgId() + "/" + studentCode + ".jpg";
|
|
|
if (new File(filePath).exists()) {
|
|
|
- log.info("Photo has download! filePath:{}", filePath);
|
|
|
+ log.info("【已下载】 studentCode:{} identityNumber:{} filePath:{}", studentCode, identityNumber, filePath);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- FileHelper.saveImageToFile(student.getPhotoPath(), filePath);
|
|
|
+ FileHelper.saveImageToFile(this.fixPhotoUrl(student.getPhotoPath()), filePath);
|
|
|
} catch (Exception e) {
|
|
|
- log.error(e.getMessage());
|
|
|
+ log.error("studentCode:{} identityNumber:{} err:{}", studentCode, identityNumber, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public String fixPhotoUrl(String url) {
|
|
|
+ if (StringUtils.isEmpty(url)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ // ecs-static-upyun.qmth.com.cn 去掉 -upyun
|
|
|
+ return url.replace("-upyun.qmth.com.cn", ".qmth.com.cn");
|
|
|
+ }
|
|
|
+
|
|
|
}
|