|
@@ -3,17 +3,20 @@ package cn.com.qmth.examcloud.tool.service.export_student_photo;
|
|
import cn.com.qmth.examcloud.tool.config.SysProperty;
|
|
import cn.com.qmth.examcloud.tool.config.SysProperty;
|
|
import cn.com.qmth.examcloud.tool.service.CommonService;
|
|
import cn.com.qmth.examcloud.tool.service.CommonService;
|
|
import cn.com.qmth.examcloud.tool.service.export_student_photo.vo.StudentVO;
|
|
import cn.com.qmth.examcloud.tool.service.export_student_photo.vo.StudentVO;
|
|
|
|
+import cn.com.qmth.examcloud.tool.utils.FileHelper;
|
|
import cn.com.qmth.examcloud.tool.utils.HttpHelper;
|
|
import cn.com.qmth.examcloud.tool.utils.HttpHelper;
|
|
import cn.com.qmth.examcloud.tool.utils.JsonMapper;
|
|
import cn.com.qmth.examcloud.tool.utils.JsonMapper;
|
|
import cn.com.qmth.examcloud.tool.vo.PageInfo;
|
|
import cn.com.qmth.examcloud.tool.vo.PageInfo;
|
|
import cn.com.qmth.examcloud.tool.vo.user.User;
|
|
import cn.com.qmth.examcloud.tool.vo.user.User;
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -28,10 +31,12 @@ public class ExportStudentPhotoTask {
|
|
@Autowired
|
|
@Autowired
|
|
private CommonService commonService;
|
|
private CommonService commonService;
|
|
|
|
|
|
|
|
+ private static final String EXPORT_DIR = "D:/home/captures/photo/";
|
|
|
|
+
|
|
public void start(User user, Long rootOrgId) {
|
|
public void start(User user, Long rootOrgId) {
|
|
this.execute(user, rootOrgId);
|
|
this.execute(user, rootOrgId);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private void execute(User user, Long rootOrgId) {
|
|
private void execute(User user, Long rootOrgId) {
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, String> headers = new HashMap<>();
|
|
headers.put("key", user.getKey());
|
|
headers.put("key", user.getKey());
|
|
@@ -54,13 +59,33 @@ public class ExportStudentPhotoTask {
|
|
|
|
|
|
for (StudentVO student : page.getList()) {
|
|
for (StudentVO student : page.getList()) {
|
|
// 下载底照
|
|
// 下载底照
|
|
-
|
|
|
|
|
|
+ this.downloadPhoto(student);
|
|
}
|
|
}
|
|
|
|
|
|
pageNo++;
|
|
pageNo++;
|
|
sum += page.getList().size();
|
|
sum += page.getList().size();
|
|
float rate = sum * 100f / page.getTotal();
|
|
float rate = sum * 100f / page.getTotal();
|
|
- log.info("rootOrgId:{} 已下载学生底照数:{} 进度:{}%", rootOrgId, sum, rate);
|
|
|
|
|
|
+ log.info("rootOrgId:{} 已下载学生底照数:{} 总数:{} 进度:{}%", rootOrgId, sum, page.getTotal(), rate);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void downloadPhoto(StudentVO student) {
|
|
|
|
+ if (StringUtils.isEmpty(student.getPhotoPath())) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ FileHelper.saveImageToFile(student.getPhotoPath(), filePath);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|