|
@@ -1,18 +1,33 @@
|
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.qmth.distributed.print.business.bean.result.TSyncExamStudentScoreResult;
|
|
|
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.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.UploadFileEnum;
|
|
|
+import com.qmth.teachcloud.common.service.TeachcloudCommonService;
|
|
|
+import com.qmth.teachcloud.common.util.FileStoreUtil;
|
|
|
+import com.qmth.teachcloud.common.util.HttpUtil;
|
|
|
+import com.qmth.teachcloud.common.util.ImageTrajectoryUtil;
|
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.StringJoiner;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -28,6 +43,15 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
|
|
|
@Resource
|
|
|
TSyncExamStudentScoreMapper tSyncExamStudentScoreMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ DictionaryConfig dictionaryConfig;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ FileStoreUtil fileStoreUtil;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TeachcloudCommonService teachcloudCommonService;
|
|
|
+
|
|
|
/**
|
|
|
* 同步成绩查询列表
|
|
|
*
|
|
@@ -60,4 +84,98 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
|
|
|
public List<TSyncExamStudentScoreResult> export(Long schoolId, Long semesterId, Long orgId, Long majorId, Long clazzId, String courseCode) {
|
|
|
return tSyncExamStudentScoreMapper.export(schoolId, semesterId, orgId, majorId, clazzId, courseCode);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建动态轨迹图
|
|
|
+ *
|
|
|
+ * @param tSyncExamStudentScore
|
|
|
+ * @param imageTrajectoryEnum
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TSyncExamStudentScore createImageTrajectory(TSyncExamStudentScore tSyncExamStudentScore, ImageTrajectoryEnum imageTrajectoryEnum) {
|
|
|
+ File fileSource = null, fileTarget = null;
|
|
|
+ String ossType = null;
|
|
|
+ JSONObject jsonObject = null;
|
|
|
+ try {
|
|
|
+ StringJoiner stringJoiner = new StringJoiner("");
|
|
|
+ stringJoiner.add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
|
|
|
+ if (Objects.isNull(tSyncExamStudentScore.getTrajectoryUrls())) {
|
|
|
+ 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 = new JSONObject();
|
|
|
+ jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
|
+ if (oss) {
|
|
|
+ fileStoreUtil.ossUpload(dirTargetJpgName.toString(), fileTarget, DigestUtils.md5Hex(new FileInputStream(fileTarget)), UploadFileEnum.FILE.getFssType());
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
+ jsonObject.put(SystemConstant.PATH, dirTargetJpgName.toString());
|
|
|
+ tSyncExamStudentScore.setPath(teachcloudCommonService.filePreview(jsonObject.toJSONString()));
|
|
|
+ } else {
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
+ jsonObject.put(SystemConstant.PATH, dirTargetJpgName.toString());
|
|
|
+ tSyncExamStudentScore.setPath(stringJoiner.toString() + dirTargetJpgName.toString());
|
|
|
+ }
|
|
|
+ tSyncExamStudentScore.setTrajectoryUrls(jsonObject.toJSONString());
|
|
|
+ tSyncExamStudentScore.setTrajectoryFile(fileTarget);
|
|
|
+ } else {
|
|
|
+ jsonObject = JSONObject.parseObject(tSyncExamStudentScore.getTrajectoryUrls());
|
|
|
+ ossType = (String) jsonObject.get(SystemConstant.TYPE);
|
|
|
+ if (Objects.equals(ossType, SystemConstant.OSS)) {
|
|
|
+ tSyncExamStudentScore.setPath(teachcloudCommonService.filePreview(jsonObject.toJSONString()));
|
|
|
+ } else {
|
|
|
+ tSyncExamStudentScore.setPath(stringJoiner.toString() + jsonObject.get(SystemConstant.PATH));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (imageTrajectoryEnum == ImageTrajectoryEnum.DOWNLOAD && Objects.isNull(fileTarget)) {
|
|
|
+ ossType = (String) jsonObject.get(SystemConstant.TYPE);
|
|
|
+ if (Objects.equals(ossType, SystemConstant.OSS)) {
|
|
|
+ fileTarget = fileStoreUtil.ossDownload(jsonObject.get(SystemConstant.PATH).toString(), stringJoiner.toString() + jsonObject.get(SystemConstant.PATH).toString(), UploadFileEnum.FILE.getFssType());
|
|
|
+ } else {
|
|
|
+ fileTarget = new File(stringJoiner.toString() + jsonObject.get(SystemConstant.PATH).toString());
|
|
|
+ }
|
|
|
+ tSyncExamStudentScore.setTrajectoryFile(fileTarget);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ if (Objects.nonNull(fileTarget)) {
|
|
|
+ fileTarget.delete();
|
|
|
+ }
|
|
|
+ tSyncExamStudentScore.setPath(null);
|
|
|
+ } finally {
|
|
|
+ if (Objects.nonNull(fileSource)) {
|
|
|
+ fileSource.delete();
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(fileTarget) && imageTrajectoryEnum == ImageTrajectoryEnum.PREVIEW) {
|
|
|
+ fileTarget.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return tSyncExamStudentScore;
|
|
|
+ }
|
|
|
}
|