|
@@ -1,5 +1,6 @@
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -11,6 +12,7 @@ import com.qmth.distributed.print.business.service.TSyncExamStudentScoreService;
|
|
import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
|
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
import com.qmth.teachcloud.common.enums.UploadFileEnum;
|
|
import com.qmth.teachcloud.common.enums.UploadFileEnum;
|
|
import com.qmth.teachcloud.common.service.TeachcloudCommonService;
|
|
import com.qmth.teachcloud.common.service.TeachcloudCommonService;
|
|
import com.qmth.teachcloud.common.util.FileStoreUtil;
|
|
import com.qmth.teachcloud.common.util.FileStoreUtil;
|
|
@@ -24,10 +26,7 @@ import javax.annotation.Resource;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileInputStream;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.Objects;
|
|
|
|
-import java.util.StringJoiner;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -94,74 +93,94 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public TSyncExamStudentScore createImageTrajectory(TSyncExamStudentScore tSyncExamStudentScore, ImageTrajectoryEnum imageTrajectoryEnum) {
|
|
public TSyncExamStudentScore createImageTrajectory(TSyncExamStudentScore tSyncExamStudentScore, ImageTrajectoryEnum imageTrajectoryEnum) {
|
|
- File fileSource = null, fileTarget = null;
|
|
|
|
|
|
+ List<File> fileSourceList = new ArrayList<>(), fileTargetList = new ArrayList<>();
|
|
try {
|
|
try {
|
|
|
|
+ Optional.ofNullable(tSyncExamStudentScore.getSheetUrls()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未获取到考生原卷地址"));
|
|
StringJoiner stringJoiner = new StringJoiner("");
|
|
StringJoiner stringJoiner = new StringJoiner("");
|
|
stringJoiner.add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
|
|
stringJoiner.add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
|
|
if (Objects.isNull(tSyncExamStudentScore.getTrajectoryUrls())) {
|
|
if (Objects.isNull(tSyncExamStudentScore.getTrajectoryUrls())) {
|
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(tSyncExamStudentScore.getSheetUrls());
|
|
boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
- String format = tSyncExamStudentScore.getSheetUrls().substring(tSyncExamStudentScore.getSheetUrls().lastIndexOf("."), tSyncExamStudentScore.getSheetUrls().length());
|
|
|
|
- LocalDateTime nowTime = LocalDateTime.now();
|
|
|
|
- StringJoiner dirJpgName = new StringJoiner("");
|
|
|
|
- dirJpgName.add(UploadFileEnum.FILE.getTitle()).add(File.separator)
|
|
|
|
- .add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
|
- .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
|
- .add(String.format("%02d", nowTime.getDayOfMonth()))
|
|
|
|
- .add(File.separator).add(SystemConstant.getUuid()).add(format);
|
|
|
|
- fileSource = new File(stringJoiner.toString() + dirJpgName.toString());
|
|
|
|
- if (!fileSource.exists()) {
|
|
|
|
- fileSource.getParentFile().mkdirs();
|
|
|
|
- fileSource.createNewFile();
|
|
|
|
- }
|
|
|
|
- fileSource = HttpUtil.httpDownload(tSyncExamStudentScore.getSheetUrls(), fileSource.getPath());
|
|
|
|
-
|
|
|
|
- StringJoiner dirTargetJpgName = new StringJoiner("");
|
|
|
|
- dirTargetJpgName.add(UploadFileEnum.FILE.getTitle()).add(File.separator)
|
|
|
|
- .add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
|
- .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
|
- .add(String.format("%02d", nowTime.getDayOfMonth()))
|
|
|
|
- .add(File.separator).add(SystemConstant.getUuid()).add(format);
|
|
|
|
- fileTarget = new File(stringJoiner.toString() + dirTargetJpgName.toString());
|
|
|
|
- if (!fileTarget.exists()) {
|
|
|
|
- fileTarget.getParentFile().mkdirs();
|
|
|
|
- fileTarget.createNewFile();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- ImageTrajectoryUtil.createImage(fileSource, fileTarget, 10, 10);
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
JSONObject jsonObject = new JSONObject();
|
|
jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
if (oss) {
|
|
if (oss) {
|
|
- fileStoreUtil.ossUpload(dirTargetJpgName.toString(), fileTarget, DigestUtils.md5Hex(new FileInputStream(fileTarget)), UploadFileEnum.FILE.getFssType());
|
|
|
|
jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
- jsonObject.put(SystemConstant.PATH, dirTargetJpgName.toString());
|
|
|
|
- tSyncExamStudentScore.setPath(teachcloudCommonService.filePreview(jsonObject.toJSONString()));
|
|
|
|
} else {
|
|
} else {
|
|
jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
- jsonObject.put(SystemConstant.PATH, dirTargetJpgName.toString());
|
|
|
|
- tSyncExamStudentScore.setPath(stringJoiner.toString() + dirTargetJpgName.toString());
|
|
|
|
}
|
|
}
|
|
|
|
+ JSONArray jsonImageTrajectoryPathArray = new JSONArray();
|
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
|
+ String url = (String) jsonArray.get(i);
|
|
|
|
+ String format = url.substring(url.lastIndexOf("."), url.length());
|
|
|
|
+ LocalDateTime nowTime = LocalDateTime.now();
|
|
|
|
+ StringJoiner dirJpgName = new StringJoiner("");
|
|
|
|
+ dirJpgName.add(UploadFileEnum.FILE.getTitle()).add(File.separator)
|
|
|
|
+ .add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
|
+ .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
|
+ .add(String.format("%02d", nowTime.getDayOfMonth()))
|
|
|
|
+ .add(File.separator)
|
|
|
|
+ .add(tSyncExamStudentScore.getExamNumber())
|
|
|
|
+ .add(File.separator).add(SystemConstant.getUuid()).add(format);
|
|
|
|
+ File fileSource = new File(stringJoiner.toString() + dirJpgName.toString());
|
|
|
|
+ if (!fileSource.exists()) {
|
|
|
|
+ fileSource.getParentFile().mkdirs();
|
|
|
|
+ fileSource.createNewFile();
|
|
|
|
+ }
|
|
|
|
+ fileSource = HttpUtil.httpDownload(url, fileSource.getPath());
|
|
|
|
+ fileSourceList.add(fileSource);
|
|
|
|
+
|
|
|
|
+ StringJoiner dirTargetJpgName = new StringJoiner("");
|
|
|
|
+ dirTargetJpgName.add(UploadFileEnum.FILE.getTitle()).add(File.separator)
|
|
|
|
+ .add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
|
+ .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
|
+ .add(String.format("%02d", nowTime.getDayOfMonth()))
|
|
|
|
+ .add(File.separator)
|
|
|
|
+ .add(tSyncExamStudentScore.getExamNumber())
|
|
|
|
+ .add(File.separator).add(SystemConstant.getUuid()).add(format);
|
|
|
|
+ File fileTarget = new File(stringJoiner.toString() + dirTargetJpgName.toString());
|
|
|
|
+ if (!fileTarget.exists()) {
|
|
|
|
+ fileTarget.getParentFile().mkdirs();
|
|
|
|
+ fileTarget.createNewFile();
|
|
|
|
+ }
|
|
|
|
+ ImageTrajectoryUtil.createImage(fileSource, fileTarget, 10, 10);
|
|
|
|
+ fileTargetList.add(fileTarget);
|
|
|
|
+ if (oss) {
|
|
|
|
+ fileStoreUtil.ossUpload(dirTargetJpgName.toString(), fileTarget, DigestUtils.md5Hex(new FileInputStream(fileTarget)), UploadFileEnum.FILE.getFssType());
|
|
|
|
+ }
|
|
|
|
+ jsonImageTrajectoryPathArray.add(dirTargetJpgName.toString());
|
|
|
|
+ }
|
|
|
|
+ jsonObject.put(SystemConstant.PATH, jsonImageTrajectoryPathArray.toJSONString());
|
|
tSyncExamStudentScore.setTrajectoryUrls(jsonObject.toJSONString());
|
|
tSyncExamStudentScore.setTrajectoryUrls(jsonObject.toJSONString());
|
|
} else {
|
|
} else {
|
|
JSONObject jsonObject = JSONObject.parseObject(tSyncExamStudentScore.getTrajectoryUrls());
|
|
JSONObject jsonObject = JSONObject.parseObject(tSyncExamStudentScore.getTrajectoryUrls());
|
|
String ossType = (String) jsonObject.get(SystemConstant.TYPE);
|
|
String ossType = (String) jsonObject.get(SystemConstant.TYPE);
|
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(jsonObject.get(SystemConstant.PATH).toString());
|
|
if (Objects.equals(ossType, SystemConstant.OSS)) {
|
|
if (Objects.equals(ossType, SystemConstant.OSS)) {
|
|
- tSyncExamStudentScore.setPath(teachcloudCommonService.filePreview(jsonObject.toJSONString()));
|
|
|
|
- fileTarget = fileStoreUtil.ossDownload(jsonObject.get(SystemConstant.PATH).toString(), stringJoiner.toString() + jsonObject.get(SystemConstant.PATH).toString(), UploadFileEnum.FILE.getFssType());
|
|
|
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
|
+ String url = (String) jsonArray.get(i);
|
|
|
|
+ fileTargetList.add(fileStoreUtil.ossDownload(url, stringJoiner.toString() + url, UploadFileEnum.FILE.getFssType()));
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- tSyncExamStudentScore.setPath(stringJoiner.toString() + jsonObject.get(SystemConstant.PATH));
|
|
|
|
- fileTarget = new File(stringJoiner.toString() + jsonObject.get(SystemConstant.PATH).toString());
|
|
|
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
|
+ String url = (String) jsonArray.get(i);
|
|
|
|
+ fileTargetList.add(new File(stringJoiner.toString() + url));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- tSyncExamStudentScore.setTrajectoryFile(fileTarget);
|
|
|
|
|
|
+ tSyncExamStudentScore.setTrajectoryFileList(fileTargetList);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
tSyncExamStudentScore.setErrorInfo();
|
|
tSyncExamStudentScore.setErrorInfo();
|
|
- if (Objects.nonNull(fileTarget)) {
|
|
|
|
- fileTarget.delete();
|
|
|
|
|
|
+ if (Objects.nonNull(fileTargetList)) {
|
|
|
|
+ for (File f : fileTargetList) {
|
|
|
|
+ f.delete();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} finally {
|
|
} finally {
|
|
- if (Objects.nonNull(fileSource)) {
|
|
|
|
- fileSource.delete();
|
|
|
|
|
|
+ if (Objects.nonNull(fileSourceList)) {
|
|
|
|
+ for (File f : fileSourceList) {
|
|
|
|
+ f.delete();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return tSyncExamStudentScore;
|
|
return tSyncExamStudentScore;
|