|
@@ -1,5 +1,6 @@
|
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -8,15 +9,18 @@ import com.qmth.distributed.print.business.bean.result.TSyncExamStudentScoreResu
|
|
|
import com.qmth.distributed.print.business.entity.TSyncExamStudentScore;
|
|
|
import com.qmth.distributed.print.business.enums.ImageTrajectoryEnum;
|
|
|
import com.qmth.distributed.print.business.mapper.TSyncExamStudentScoreMapper;
|
|
|
+import com.qmth.distributed.print.business.service.PrintCommonService;
|
|
|
import com.qmth.distributed.print.business.service.TSyncExamStudentScoreService;
|
|
|
import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
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.service.TeachcloudCommonService;
|
|
|
import com.qmth.teachcloud.common.util.*;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -24,6 +28,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -45,13 +50,14 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
|
|
|
@Resource
|
|
|
FileStoreUtil fileStoreUtil;
|
|
|
|
|
|
+ @Resource
|
|
|
+ TeachcloudCommonService teachcloudCommonService;
|
|
|
+
|
|
|
/**
|
|
|
* 同步成绩查询列表
|
|
|
*
|
|
|
* @param iPage
|
|
|
* @param semesterId
|
|
|
- * @param orgId
|
|
|
- * @param majorId
|
|
|
* @param clazzId
|
|
|
* @param courseCode
|
|
|
* @return
|
|
@@ -59,7 +65,21 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
|
|
|
@Override
|
|
|
public IPage<TSyncExamStudentScoreResult> list(IPage<Map> iPage, Long semesterId, Long examId, Long clazzId, String courseCode) {
|
|
|
SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
- return tSyncExamStudentScoreMapper.list(iPage, sysUser.getSchoolId(), semesterId, examId, clazzId, courseCode);
|
|
|
+ IPage<TSyncExamStudentScoreResult> list = tSyncExamStudentScoreMapper.list(iPage, sysUser.getSchoolId(), semesterId, examId, clazzId, courseCode);
|
|
|
+ List<String> trailUrlsList = new ArrayList<>();
|
|
|
+ list.getRecords().stream().map(m->{
|
|
|
+ String localSheetUrls = m.getLocalSheetUrls();
|
|
|
+ if(StringUtils.isNotBlank(localSheetUrls)) {
|
|
|
+ List<String> jsonArray = JSON.parseArray(localSheetUrls, String.class);
|
|
|
+ for (String s : jsonArray) {
|
|
|
+ trailUrlsList.add(teachcloudCommonService.filePreview(s));
|
|
|
+ }
|
|
|
+ m.setSheetUrls(JSON.toJSONString(trailUrlsList));
|
|
|
+ }
|
|
|
+ return m;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -67,8 +87,6 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
|
|
|
*
|
|
|
* @param schoolId
|
|
|
* @param semesterId
|
|
|
- * @param orgId
|
|
|
- * @param majorId
|
|
|
* @param clazzId
|
|
|
* @param courseCode
|
|
|
* @return
|
|
@@ -83,8 +101,6 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
|
|
|
*
|
|
|
* @param schoolId
|
|
|
* @param semesterId
|
|
|
- * @param orgId
|
|
|
- * @param majorId
|
|
|
* @param clazzId
|
|
|
* @param courseCode
|
|
|
* @return
|
|
@@ -104,6 +120,7 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
|
|
|
@Override
|
|
|
public TSyncExamStudentScore createImageTrajectory(TSyncExamStudentScore tSyncExamStudentScore, ImageTrajectoryEnum imageTrajectoryEnum) {
|
|
|
List<File> fileSourceList = new ArrayList<>(), fileTargetList = new ArrayList<>();
|
|
|
+ boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
try {
|
|
|
Optional.ofNullable(tSyncExamStudentScore.getSheetUrls()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未获取到考生原卷地址"));
|
|
|
Optional.ofNullable(tSyncExamStudentScore.getSyncData()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未获取到考生作答数据"));
|
|
@@ -113,83 +130,114 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
|
|
|
|
|
|
String hostUrl = SystemConstant.getLocalFileHost(dictionaryConfig.sysDomain().getFileHost());
|
|
|
|
|
|
- if (Objects.isNull(tSyncExamStudentScore.getTrajectoryUrls())) {
|
|
|
+ if (Objects.isNull(tSyncExamStudentScore.getLocalSheetUrls()) || Objects.isNull(tSyncExamStudentScore.getTrajectoryUrls())) {
|
|
|
JSONArray jsonArray = JSONArray.parseArray(tSyncExamStudentScore.getSheetUrls());
|
|
|
- JSONObject syncDataJson = JSONObject.parseObject(tSyncExamStudentScore.getSyncData());
|
|
|
- Optional.ofNullable(syncDataJson.get("markTags")).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未获取到考生轨迹坐标数据"));
|
|
|
- JSONObject markTagsJson = JSONObject.parseObject(syncDataJson.get("markTags").toString());
|
|
|
- boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
|
- if (oss) {
|
|
|
- jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
- } else {
|
|
|
- jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
- }
|
|
|
- JSONArray jsonImageTrajectoryPathArray = new JSONArray();
|
|
|
- for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
- JSONArray markTagJsonArray = (JSONArray) markTagsJson.get(i + 1);
|
|
|
- if (Objects.isNull(markTagJsonArray) || markTagJsonArray.size() == 0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- String url = (String) jsonArray.get(i);
|
|
|
- String sheetName = url.substring(url.lastIndexOf("/"));
|
|
|
- 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("sheet").add(File.separator).add(sheetName);
|
|
|
- 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);
|
|
|
+ if (!jsonArray.isEmpty()) {
|
|
|
+ JSONObject syncDataJson = JSON.parseObject(tSyncExamStudentScore.getSyncData());
|
|
|
+ Optional.ofNullable(syncDataJson.get("markTags")).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未获取到考生轨迹坐标数据"));
|
|
|
+ JSONObject markTagsJson = JSON.parseObject(syncDataJson.get("markTags").toString());
|
|
|
|
|
|
- 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("trail").add(File.separator).add(sheetName);
|
|
|
- File fileTarget = new File(stringJoiner.toString() + dirTargetJpgName.toString());
|
|
|
- if (!fileTarget.exists()) {
|
|
|
- fileTarget.getParentFile().mkdirs();
|
|
|
- fileTarget.createNewFile();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
|
+ if (oss) {
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
+ } else {
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
}
|
|
|
+ JSONArray jsonImageSourcePathArray = new JSONArray();
|
|
|
+ JSONArray jsonImageTrajectoryPathArray = new JSONArray();
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JSONArray markTagJsonArray = (JSONArray) markTagsJson.get(i + 1);
|
|
|
+ if (Objects.isNull(markTagJsonArray) || markTagJsonArray.size() == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String url = (String) jsonArray.get(i);
|
|
|
+ String sheetName = url.substring(url.lastIndexOf("/") +1 );
|
|
|
+ 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("sheet").add(File.separator).add(sheetName);
|
|
|
+ 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);
|
|
|
+ JSONObject sheetObject = new JSONObject();
|
|
|
+ if (oss) {
|
|
|
+ sheetObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
+ fileStoreUtil.ossUpload(dirJpgName.toString(), fileSource, DigestUtils.md5Hex(new FileInputStream(fileSource)), UploadFileEnum.FILE.getFssType());
|
|
|
+ if (imageTrajectoryEnum == ImageTrajectoryEnum.PREVIEW) {
|
|
|
+ trailUrlsList.add(fileStoreUtil.getPrivateUrl(dirJpgName.toString(), UploadFileEnum.FILE.getFssType()));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ sheetObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
+ if (imageTrajectoryEnum == ImageTrajectoryEnum.PREVIEW) {
|
|
|
+ String filePath = fileSource.getPath();
|
|
|
+ String trailUrl;
|
|
|
+ if (filePath.startsWith("/")) {
|
|
|
+ trailUrl = hostUrl + filePath;
|
|
|
+ } else {
|
|
|
+ trailUrl = hostUrl + File.separator + filePath;
|
|
|
+ }
|
|
|
+ trailUrlsList.add(trailUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sheetObject.put(SystemConstant.PATH, (stringJoiner.toString() + dirJpgName.toString()).replaceAll("\\\\", "/"));
|
|
|
+ jsonImageSourcePathArray.add(sheetObject);
|
|
|
|
|
|
- ImageTrajectoryUtil.createImage(fileSource, fileTarget, markTagJsonArray);
|
|
|
- fileTargetList.add(fileTarget);
|
|
|
- if (oss) {
|
|
|
- fileStoreUtil.ossUpload(dirTargetJpgName.toString(), fileTarget, DigestUtils.md5Hex(new FileInputStream(fileTarget)), UploadFileEnum.FILE.getFssType());
|
|
|
- if (imageTrajectoryEnum == ImageTrajectoryEnum.PREVIEW) {
|
|
|
- trailUrlsList.add(fileStoreUtil.getPrivateUrl(dirTargetJpgName.toString(), UploadFileEnum.FILE.getFssType()));
|
|
|
+ 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("trail").add(File.separator).add(sheetName);
|
|
|
+ File fileTarget = new File(stringJoiner.toString() + dirTargetJpgName.toString());
|
|
|
+ if (!fileTarget.exists()) {
|
|
|
+ fileTarget.getParentFile().mkdirs();
|
|
|
+ fileTarget.createNewFile();
|
|
|
}
|
|
|
- } else {
|
|
|
- if (imageTrajectoryEnum == ImageTrajectoryEnum.PREVIEW) {
|
|
|
- String filePath = fileTarget.getPath();
|
|
|
- String trailUrl;
|
|
|
- if (filePath.startsWith("/")) {
|
|
|
- trailUrl = hostUrl + filePath;
|
|
|
- } else {
|
|
|
- trailUrl = hostUrl + File.separator + filePath;
|
|
|
+
|
|
|
+ ImageTrajectoryUtil.createImage(fileSource, fileTarget, markTagJsonArray);
|
|
|
+ fileTargetList.add(fileTarget);
|
|
|
+ JSONObject trialObject = new JSONObject();
|
|
|
+ if (oss) {
|
|
|
+ trialObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
+ fileStoreUtil.ossUpload(dirTargetJpgName.toString(), fileTarget, DigestUtils.md5Hex(new FileInputStream(fileTarget)), UploadFileEnum.FILE.getFssType());
|
|
|
+ if (imageTrajectoryEnum == ImageTrajectoryEnum.PREVIEW) {
|
|
|
+ trailUrlsList.add(fileStoreUtil.getPrivateUrl(dirTargetJpgName.toString(), UploadFileEnum.FILE.getFssType()));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ trialObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
+ if (imageTrajectoryEnum == ImageTrajectoryEnum.PREVIEW) {
|
|
|
+ String filePath = fileTarget.getPath();
|
|
|
+ String trailUrl;
|
|
|
+ if (filePath.startsWith("/")) {
|
|
|
+ trailUrl = hostUrl + filePath;
|
|
|
+ } else {
|
|
|
+ trailUrl = hostUrl + File.separator + filePath;
|
|
|
+ }
|
|
|
+ trailUrlsList.add(trailUrl);
|
|
|
}
|
|
|
- trailUrlsList.add(trailUrl);
|
|
|
}
|
|
|
+ trialObject.put(SystemConstant.PATH, (stringJoiner.toString() + dirTargetJpgName.toString()).replaceAll("\\\\", "/"));
|
|
|
+ jsonImageTrajectoryPathArray.add(trialObject);
|
|
|
+ }
|
|
|
+ if(!jsonImageSourcePathArray.isEmpty()){
|
|
|
+ tSyncExamStudentScore.setLocalSheetUrls(jsonImageSourcePathArray.toJSONString());
|
|
|
+ }
|
|
|
+ if (!jsonImageTrajectoryPathArray.isEmpty()) {
|
|
|
+ jsonObject.put(SystemConstant.PATH, jsonImageTrajectoryPathArray.toJSONString());
|
|
|
+ tSyncExamStudentScore.setTrajectoryUrls(jsonObject.toJSONString());
|
|
|
}
|
|
|
- jsonImageTrajectoryPathArray.add(dirTargetJpgName.toString());
|
|
|
- }
|
|
|
- if (!jsonImageTrajectoryPathArray.isEmpty()) {
|
|
|
- jsonObject.put(SystemConstant.PATH, jsonImageTrajectoryPathArray.toJSONString());
|
|
|
- tSyncExamStudentScore.setTrajectoryUrls(jsonObject.toJSONString());
|
|
|
-
|
|
|
this.updateById(tSyncExamStudentScore);
|
|
|
}
|
|
|
} else {
|
|
@@ -214,7 +262,7 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
|
|
|
String trailUrl;
|
|
|
String filePath = stringJoiner + url;
|
|
|
if (filePath.startsWith("/")) {
|
|
|
- trailUrl = hostUrl + filePath;
|
|
|
+ trailUrl = hostUrl + filePath;
|
|
|
} else {
|
|
|
trailUrl = hostUrl + File.separator + filePath;
|
|
|
}
|
|
@@ -273,7 +321,7 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
|
|
|
}
|
|
|
|
|
|
List<File> fileList = tSyncExamStudentScore.getTrajectoryFileList();
|
|
|
- if(fileList.isEmpty()){
|
|
|
+ if (fileList.isEmpty()) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("没有可下载文件");
|
|
|
}
|
|
|
|