|
@@ -10,7 +10,11 @@ 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.alibaba.excel.EasyExcel;
|
|
|
|
+import com.alibaba.excel.context.AnalysisContext;
|
|
|
|
+import com.alibaba.excel.event.AnalysisEventListener;
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
+import com.google.common.collect.Lists;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -42,8 +46,8 @@ public class ExportStudentPhotoTask implements TaskService {
|
|
|
|
|
|
public void execute(User loginUser, String exportDir) {
|
|
public void execute(User loginUser, String exportDir) {
|
|
// List<StudentVO> hasPhotoStudents = this.loadStudentFromUrl(loginUser);
|
|
// List<StudentVO> hasPhotoStudents = this.loadStudentFromUrl(loginUser);
|
|
- List<StudentVO> hasPhotoStudents = this.loadStudentFromExcel();
|
|
|
|
- this.downloadStudents(exportDir, hasPhotoStudents);
|
|
|
|
|
|
+ List<StudentVO> hasPhotoStudents = this.loadStudentFromExcel(exportDir + "/students.xlsx");
|
|
|
|
+ this.downloadStudents(hasPhotoStudents, exportDir, false);
|
|
}
|
|
}
|
|
|
|
|
|
private List<StudentVO> loadStudentFromUrl(User loginUser) {
|
|
private List<StudentVO> loadStudentFromUrl(User loginUser) {
|
|
@@ -52,17 +56,15 @@ public class ExportStudentPhotoTask implements TaskService {
|
|
headers.put("token", loginUser.getToken());
|
|
headers.put("token", loginUser.getToken());
|
|
|
|
|
|
JsonMapper jsonMapper = new JsonMapper();
|
|
JsonMapper jsonMapper = new JsonMapper();
|
|
- long pageNo = 0, pageSize = 100, total = 0, finishedCount = 0, noPhotoCount = 0;
|
|
|
|
|
|
+ long pageNo = 0, pageSize = 100, finishedCount = 0, noPhotoCount = 0;
|
|
|
|
|
|
final String url = loginUser.getServerUrl()
|
|
final String url = loginUser.getServerUrl()
|
|
- + "/api/ecs_core/student/studentPage/%s/%s?rootOrgId=%s&identityNumber=&studentCode=&name=";
|
|
|
|
|
|
+ + "/api/ecs_core/student/studentPage/%s/%s?rootOrgId=%s&hasPhoto=TRUE";
|
|
|
|
|
|
List<StudentVO> hasPhotoStudents = new ArrayList<>();
|
|
List<StudentVO> hasPhotoStudents = new ArrayList<>();
|
|
while (true) {
|
|
while (true) {
|
|
String json = HttpHelper.get(String.format(url, pageNo, pageSize, loginUser.getRootOrgId()), headers, null);
|
|
String json = HttpHelper.get(String.format(url, pageNo, pageSize, loginUser.getRootOrgId()), headers, null);
|
|
-
|
|
|
|
PageInfo<StudentVO> page = jsonMapper.parseJson(json, new TypeReference<PageInfo<StudentVO>>() {
|
|
PageInfo<StudentVO> page = jsonMapper.parseJson(json, new TypeReference<PageInfo<StudentVO>>() {
|
|
-
|
|
|
|
});
|
|
});
|
|
if (page == null || CollectionUtils.isEmpty(page.getList())) {
|
|
if (page == null || CollectionUtils.isEmpty(page.getList())) {
|
|
break;
|
|
break;
|
|
@@ -79,52 +81,94 @@ public class ExportStudentPhotoTask implements TaskService {
|
|
}
|
|
}
|
|
|
|
|
|
pageNo++;
|
|
pageNo++;
|
|
- total = page.getTotal();
|
|
|
|
|
|
+ long total = page.getTotal();
|
|
finishedCount += page.getList().size();
|
|
finishedCount += page.getList().size();
|
|
float finishedRate = finishedCount * 100f / total;
|
|
float finishedRate = finishedCount * 100f / total;
|
|
- log.info("【{}】 总数:{} 已获取学生数:{} 无底照学生数:{} 进度:{}%", pageNo, total, finishedCount,
|
|
|
|
- noPhotoCount, finishedRate);
|
|
|
|
|
|
+ log.info("总数:{} 已获取学生数:{} 无底照学生数:{} pageNo:{} 进度:{}%", total, finishedCount, noPhotoCount, pageNo, finishedRate);
|
|
}
|
|
}
|
|
|
|
|
|
return hasPhotoStudents;
|
|
return hasPhotoStudents;
|
|
}
|
|
}
|
|
|
|
|
|
- private List<StudentVO> loadStudentFromExcel() {
|
|
|
|
|
|
+ private List<StudentVO> loadStudentFromExcel(String dataFilePath) {
|
|
|
|
+ /*
|
|
|
|
+ select stu.id, stu.root_org_id 学校ID, stu.name 学生姓名, stu.identity_number 身份证号, sc.student_code 学号, stu.photo_path 照片
|
|
|
|
+ from ec_b_student stu left join ec_b_student_code sc on sc.student_id = stu.id
|
|
|
|
+ where stu.root_org_id = 0 and stu.photo_path is not null;
|
|
|
|
+ */
|
|
|
|
+ List<StudentVO> list = new ArrayList<>();
|
|
|
|
+ try {
|
|
|
|
+ EasyExcel.read(dataFilePath, StudentVO.class, new AnalysisEventListener<StudentVO>() {
|
|
|
|
+ @Override
|
|
|
|
+ public void invoke(StudentVO data, AnalysisContext analysisContext) {
|
|
|
|
+ list.add(data);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
|
|
|
+ // ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ).sheet().doRead();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
|
+ throw new RuntimeException("Excel内容解析错误,请使用标准模板!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int noPhotoCount = 0;
|
|
List<StudentVO> hasPhotoStudents = new ArrayList<>();
|
|
List<StudentVO> hasPhotoStudents = new ArrayList<>();
|
|
- //todo
|
|
|
|
|
|
+ for (StudentVO student : list) {
|
|
|
|
+ if (StringUtils.isEmpty(student.getPhotoPath())) {
|
|
|
|
+ noPhotoCount++;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ student.setPhotoPath(this.fixPhotoUrl(student.getPhotoPath()));
|
|
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(student.getStudentCodesStr())) {
|
|
|
|
+ student.setStudentCodeList(Lists.newArrayList(student.getStudentCodesStr()));
|
|
|
|
+ }
|
|
|
|
+ hasPhotoStudents.add(student);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ log.info("总数:{} 已获取学生数:{} 无底照学生数:{}", list.size(), hasPhotoStudents.size(), noPhotoCount);
|
|
return hasPhotoStudents;
|
|
return hasPhotoStudents;
|
|
}
|
|
}
|
|
|
|
|
|
- private void downloadStudents(String exportDir, List<StudentVO> students) {
|
|
|
|
|
|
+ private void downloadStudents(List<StudentVO> students, String exportDir, boolean fileNameByStudentCode) {
|
|
for (StudentVO student : students) {
|
|
for (StudentVO student : students) {
|
|
- // 下载底照
|
|
|
|
- this.downloadPhoto(exportDir, student);
|
|
|
|
|
|
+ String photoSuffix = FileHelper.getFileSuffix(student.getPhotoPath());
|
|
|
|
+ if (fileNameByStudentCode) {
|
|
|
|
+ if (CollectionUtils.isNotEmpty(student.getStudentCodeList())) {
|
|
|
|
+ if (student.getStudentCodeList().size() > 1) {
|
|
|
|
+ log.warn("identityNumber:{} 多个学号!", student.getIdentityNumber());
|
|
|
|
+ }
|
|
|
|
+ for (String studentCode : student.getStudentCodeList()) {
|
|
|
|
+ String photoPath = String.format("%s/%s/%s%s", exportDir, student.getRootOrgId(), studentCode, photoSuffix);
|
|
|
|
+ this.downloadPhoto(student.getPhotoPath(), photoPath);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ log.warn("identityNumber:{} 无学号!", student.getIdentityNumber());
|
|
|
|
+ String photoPath = String.format("%s/%s/%s%s", exportDir, student.getRootOrgId(), student.getIdentityNumber(), photoSuffix);
|
|
|
|
+ this.downloadPhoto(student.getPhotoPath(), photoPath);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ String photoPath = String.format("%s/%s/%s%s", exportDir, student.getRootOrgId(), student.getIdentityNumber(), photoSuffix);
|
|
|
|
+ this.downloadPhoto(student.getPhotoPath(), photoPath);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void downloadPhoto(String exportDir, StudentVO student) {
|
|
|
|
- String identityNumber = student.getIdentityNumber();
|
|
|
|
-
|
|
|
|
- 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 = exportDir + "/" + student.getRootOrgId() + "/" + studentCode + ".jpg";
|
|
|
|
- if (new File(filePath).exists()) {
|
|
|
|
- log.info("【已下载】 studentCode:{} identityNumber:{} filePath:{}", studentCode, identityNumber, filePath);
|
|
|
|
|
|
+ private void downloadPhoto(String photoUrl, String photoPath) {
|
|
|
|
+ if (new File(photoPath).exists()) {
|
|
|
|
+ log.info("【已下载】 photoUrl:{} photoPath:{}", photoUrl, photoPath);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
try {
|
|
try {
|
|
- FileHelper.saveImageToFile(student.getPhotoPath(), filePath);
|
|
|
|
|
|
+ FileHelper.saveImageToFile(photoUrl, photoPath);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("studentCode:{} identityNumber:{} err:{}", studentCode, identityNumber, e.getMessage());
|
|
|
|
|
|
+ log.error("【错误】 photoUrl:{} photoPath:{} err:{}", photoUrl, photoPath, e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|