wangliang 3 жил өмнө
parent
commit
7c15e1a6df

+ 3 - 23
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/TSyncExamStudentScoreResult.java

@@ -1,10 +1,12 @@
 package com.qmth.distributed.print.business.bean.result;
 
+import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import com.qmth.teachcloud.common.annotation.ExcelProperty;
 import io.swagger.annotations.ApiModelProperty;
 
+import java.io.File;
 import java.io.Serializable;
 import java.util.Objects;
 
@@ -15,6 +17,7 @@ import java.util.Objects;
  * @Author: wangliang
  * @Date: 2021/11/1
  */
+@JsonInclude(JsonInclude.Include.NON_NULL)
 public class TSyncExamStudentScoreResult implements Serializable {
 
     @ApiModelProperty(value = "主键")
@@ -36,10 +39,6 @@ public class TSyncExamStudentScoreResult implements Serializable {
     @ApiModelProperty(value = "云阅卷考试编码")
     String examCode;
 
-    @ApiModelProperty(value = "考生id")
-    @JsonSerialize(using = ToStringSerializer.class)
-    Long examStudentId;
-
     @ExcelProperty(name = "姓名", width = 30, index = 2)
     @ApiModelProperty(value = "考生姓名")
     String examStudentName;
@@ -107,9 +106,6 @@ public class TSyncExamStudentScoreResult implements Serializable {
     @ApiModelProperty(value = "主观题分数")
     private Double subjectiveScore;
 
-    @ApiModelProperty(value = "轨迹图是否生成,1:已生成,0:未生成")
-    private Boolean trajectory;
-
     public Long getExamId() {
         return examId;
     }
@@ -126,14 +122,6 @@ public class TSyncExamStudentScoreResult implements Serializable {
         this.examCode = examCode;
     }
 
-    public Long getExamStudentId() {
-        return examStudentId;
-    }
-
-    public void setExamStudentId(Long examStudentId) {
-        this.examStudentId = examStudentId;
-    }
-
     public String getSemesterName() {
         return semesterName;
     }
@@ -325,12 +313,4 @@ public class TSyncExamStudentScoreResult implements Serializable {
     public void setSubjectiveScore(Double subjectiveScore) {
         this.subjectiveScore = subjectiveScore;
     }
-
-    public Boolean getTrajectory() {
-        return trajectory;
-    }
-
-    public void setTrajectory(Boolean trajectory) {
-        this.trajectory = trajectory;
-    }
 }

+ 26 - 35
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TSyncExamStudentScore.java

@@ -1,10 +1,12 @@
 package com.qmth.distributed.print.business.entity;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
+import java.io.File;
 import java.io.Serializable;
 
 /**
@@ -32,14 +34,6 @@ public class TSyncExamStudentScore implements Serializable {
     @JsonSerialize(using = ToStringSerializer.class)
     private Long orgId;
 
-    @ApiModelProperty(value = "学生id")
-    @JsonSerialize(using = ToStringSerializer.class)
-    private Long studentId;
-
-    @ApiModelProperty(value = "考生id")
-    @JsonSerialize(using = ToStringSerializer.class)
-    private Long examStudentId;
-
     @ApiModelProperty(value = "学期id")
     @JsonSerialize(using = ToStringSerializer.class)
     private Long semesterId;
@@ -96,9 +90,6 @@ public class TSyncExamStudentScore implements Serializable {
     @ApiModelProperty(value = "同步数据json")
     private String syncData;
 
-    @ApiModelProperty(value = "轨迹图是否生成,1:已生成,0:未生成")
-    private Boolean trajectory;
-
     @ApiModelProperty(value = "轨迹图地址")
     private String trajectoryUrls;
 
@@ -109,6 +100,30 @@ public class TSyncExamStudentScore implements Serializable {
     @ApiModelProperty(value = "创建时间")
     private Long createTime;
 
+    @ApiModelProperty(value = "轨迹图路径")
+    @TableField(exist = false)
+    private String path;
+
+    @ApiModelProperty(value = "轨迹图文件")
+    @TableField(exist = false)
+    private File trajectoryFile;
+
+    public String getPath() {
+        return path;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    public File getTrajectoryFile() {
+        return trajectoryFile;
+    }
+
+    public void setTrajectoryFile(File trajectoryFile) {
+        this.trajectoryFile = trajectoryFile;
+    }
+
     public Long getSemesterId() {
         return semesterId;
     }
@@ -145,22 +160,6 @@ public class TSyncExamStudentScore implements Serializable {
         this.orgId = orgId;
     }
 
-    public Long getStudentId() {
-        return studentId;
-    }
-
-    public void setStudentId(Long studentId) {
-        this.studentId = studentId;
-    }
-
-    public Long getExamStudentId() {
-        return examStudentId;
-    }
-
-    public void setExamStudentId(Long examStudentId) {
-        this.examStudentId = examStudentId;
-    }
-
     public Long getExamId() {
         return examId;
     }
@@ -297,14 +296,6 @@ public class TSyncExamStudentScore implements Serializable {
         this.syncData = syncData;
     }
 
-    public Boolean getTrajectory() {
-        return trajectory;
-    }
-
-    public void setTrajectory(Boolean trajectory) {
-        this.trajectory = trajectory;
-    }
-
     public String getTrajectoryUrls() {
         return trajectoryUrls;
     }

+ 42 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/ImageTrajectoryEnum.java

@@ -0,0 +1,42 @@
+package com.qmth.distributed.print.business.enums;
+
+import java.util.Objects;
+
+/**
+ * @Description: 生成原卷动态轨迹图 enum
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/11/3
+ */
+public enum ImageTrajectoryEnum {
+
+    PREVIEW("预览"),
+
+    DOWNLOAD("下载");
+
+    private String title;
+
+    private ImageTrajectoryEnum(String title) {
+        this.title = title;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    /**
+     * 状态转换 toName
+     *
+     * @param title
+     * @return
+     */
+    public static String convertToName(String title) {
+        for (ImageTrajectoryEnum e : ImageTrajectoryEnum.values()) {
+            if (Objects.equals(title, e.getTitle())) {
+                return e.name();
+            }
+        }
+        return null;
+    }
+}

+ 10 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/TSyncExamStudentScoreService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 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 java.util.List;
 import java.util.Map;
@@ -53,4 +54,13 @@ public interface TSyncExamStudentScoreService extends IService<TSyncExamStudentS
                                                     Long majorId,
                                                     Long clazzId,
                                                     String courseCode);
+
+    /**
+     * 创建动态轨迹图
+     *
+     * @param tSyncExamStudentScore
+     * @param imageTrajectoryEnum
+     * @return
+     */
+    public TSyncExamStudentScore createImageTrajectory(TSyncExamStudentScore tSyncExamStudentScore, ImageTrajectoryEnum imageTrajectoryEnum);
 }

+ 2 - 3
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/PrintCommonServiceServiceImpl.java

@@ -1082,11 +1082,10 @@ public class PrintCommonServiceServiceImpl implements PrintCommonService {
                     .add(String.format("%02d", nowTime.getDayOfMonth()))
                     .add(File.separator).add(SystemConstant.getUuid()).add(".").add(SystemConstant.XLSX);
             jsonObject = new JSONObject();
+            String dirName = stringJoiner.toString().replaceAll("\\\\", "/");
             if (oss) {//上传至oss
-                String dirName = stringJoiner.toString().replaceAll("\\\\", "/");
                 fileStoreUtil.ossUpload(dirName, inputStream, DigestUtils.md5Hex(new ByteArrayInputStream(fos.toByteArray())), UploadFileEnum.FILE.getFssType());
                 jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
-                jsonObject.put(SystemConstant.PATH, dirName);
             } else {
                 File finalFile = new File(stringJoiner.toString());
                 if (!finalFile.exists()) {
@@ -1095,8 +1094,8 @@ public class PrintCommonServiceServiceImpl implements PrintCommonService {
                 }
                 FileUtils.copyInputStreamToFile(inputStream, finalFile);
                 jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
-                jsonObject.put(SystemConstant.PATH, stringJoiner.toString());
             }
+            jsonObject.put(SystemConstant.PATH, dirName);
             jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
         } catch (Exception e) {
             e.printStackTrace();

+ 118 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TSyncExamStudentScoreServiceImpl.java

@@ -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;
+    }
 }

+ 3 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -9,6 +9,8 @@ import com.aliyun.oss.common.utils.BinaryUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.google.common.collect.Lists;
+import com.google.common.reflect.TypeToken;
+import com.google.gson.Gson;
 import com.itextpdf.text.DocumentException;
 import com.qmth.boot.api.exception.ApiException;
 import com.qmth.distributed.print.business.bean.dto.*;
@@ -23,6 +25,7 @@ import com.qmth.distributed.print.business.util.CreatePdfUtil;
 import com.qmth.distributed.print.business.util.HtmlToPdfUtil;
 import com.qmth.teachcloud.common.annotation.ExcelDBFieldDesc;
 import com.qmth.teachcloud.common.bean.dto.excel.*;
+import com.qmth.teachcloud.common.bean.params.ApproveUserResult;
 import com.qmth.teachcloud.common.bean.params.ArraysParams;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.*;

+ 8 - 8
distributed-print-business/src/main/resources/mapper/TSyncExamStudentScoreMapper.xml

@@ -9,7 +9,6 @@
             bs.name as semesterName,
             tsess.exam_id as examId,
             tsess.exam_code as examCode,
-            tsess.exam_student_id as examStudentId,
             tsess.name as examStudentName,
             tsess.student_code as studentCode,
             so.id as orgId,
@@ -25,23 +24,18 @@
             tsess.subjective_score as subjectiveScore,
             tsess.sheet_urls as sheetUrls,
             tsess.status,
-            tsess.trajectory,
-            tsess.trajectory_urls as trajectoryUrls,
-            tsess.sync_data as trajectoryCoordinate,
             tsess.create_time as syncTime
-        from
-            t_sync_exam_student_score tsess
     </sql>
 
     <sql id="middleCommonSql">
         join basic_semester bs on
             bs.id = tsess.semester_id
         join basic_student bs2 on
-            bs2.id = tsess.student_id
+            bs2.student_code = tsess.student_code
         join basic_clazz bc on
             bc.id = bs2.clazz_id
         join exam_student es on
-            es.id = tsess.exam_student_id
+            es.student_code = tsess.student_code
         join basic_major bm on
             bm.id = bs2.major_id
         join sys_org so on
@@ -73,12 +67,18 @@
 
     <select id="list" resultType="com.qmth.distributed.print.business.bean.result.TSyncExamStudentScoreResult">
         <include refid="headCommonSql"/>
+        from
+        t_sync_exam_student_score tsess
         <include refid="middleCommonSql"/>
         <include refid="footCommonSql"/>
     </select>
 
     <select id="export" resultType="com.qmth.distributed.print.business.bean.result.TSyncExamStudentScoreResult">
         <include refid="headCommonSql"/>
+        ,tsess.trajectory_urls as trajectoryUrls,
+        tsess.sync_data as trajectoryCoordinate
+        from
+        t_sync_exam_student_score tsess
         <include refid="middleCommonSql"/>
         <include refid="footCommonSql"/>
     </select>

+ 16 - 47
distributed-print/src/main/java/com/qmth/distributed/print/api/TSyncExamStudentScoreController.java

@@ -1,7 +1,6 @@
 package com.qmth.distributed.print.api;
 
 
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.boot.api.annotation.Aac;
@@ -11,6 +10,7 @@ import com.qmth.distributed.print.business.bean.result.EditResult;
 import com.qmth.distributed.print.business.bean.result.TSyncExamStudentScoreResult;
 import com.qmth.distributed.print.business.entity.TBSyncTask;
 import com.qmth.distributed.print.business.entity.TSyncExamStudentScore;
+import com.qmth.distributed.print.business.enums.ImageTrajectoryEnum;
 import com.qmth.distributed.print.business.service.PrintCommonService;
 import com.qmth.distributed.print.business.service.TSyncExamStudentScoreService;
 import com.qmth.distributed.print.business.templete.execute.AsyncScoreBatchDownloadService;
@@ -18,18 +18,18 @@ import com.qmth.distributed.print.business.templete.execute.AsyncScoreExportServ
 import com.qmth.distributed.print.business.templete.execute.AsyncScorePushService;
 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.entity.TBTask;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.PushTypeEnum;
 import com.qmth.teachcloud.common.enums.TaskTypeEnum;
-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.ImageTrajectoryUtil;
 import com.qmth.teachcloud.common.util.Result;
 import com.qmth.teachcloud.common.util.ResultUtil;
+import com.qmth.teachcloud.common.util.ServletUtil;
 import io.swagger.annotations.*;
-import org.apache.commons.codec.digest.DigestUtils;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -39,13 +39,9 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.annotation.Resource;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
-import java.io.File;
-import java.io.FileInputStream;
-import java.time.LocalDateTime;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
-import java.util.StringJoiner;
 
 /**
  * <p>
@@ -138,50 +134,23 @@ public class TSyncExamStudentScoreController {
     }
 
     @ApiOperation(value = "成绩动态轨迹图下载")
-    @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = Result.class)})
+    @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = EditResult.class)})
     @RequestMapping(value = "/score/download", method = RequestMethod.POST)
-    public Result download(@ApiParam(value = "考试id", required = true) @RequestParam String examStudentId) throws Exception {
+    @Transactional
+    public Result download(@ApiParam(value = "学号", required = true) @RequestParam String studentCode) throws Exception {
+        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         QueryWrapper<TSyncExamStudentScore> tSyncExamStudentScoreQueryWrapper = new QueryWrapper<>();
-        tSyncExamStudentScoreQueryWrapper.lambda().eq(TSyncExamStudentScore::getExamStudentId, SystemConstant.convertIdToLong(examStudentId));
+        tSyncExamStudentScoreQueryWrapper.lambda().eq(TSyncExamStudentScore::getSchoolId, sysUser.getSchoolId())
+                .eq(TSyncExamStudentScore::getStudentCode, studentCode);
         TSyncExamStudentScore tSyncExamStudentScore = tSyncExamStudentScoreService.getOne(tSyncExamStudentScoreQueryWrapper);
         Optional.ofNullable(tSyncExamStudentScore).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("考生不存在"));
-
-        JSONObject jsonObject = null;
-        String path = null;
-        if (Objects.isNull(tSyncExamStudentScore.getTrajectoryUrls())) {
-            String format = tSyncExamStudentScore.getSheetUrls().substring(tSyncExamStudentScore.getSheetUrls().lastIndexOf("."), tSyncExamStudentScore.getSheetUrls().length());
-            boolean oss = dictionaryConfig.sysDomain().isOss();
-            LocalDateTime nowTime = LocalDateTime.now();
-            StringJoiner stringJoiner = new StringJoiner("");
-            stringJoiner.add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
-            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);
-            File fileTarget = new File(stringJoiner.toString() + dirJpgName.toString());
-            if (!fileTarget.exists()) {
-                fileTarget.getParentFile().mkdirs();
-                fileTarget.createNewFile();
-            }
-            File sheetFile = new File(tSyncExamStudentScore.getSheetUrls());
-            ImageTrajectoryUtil.createImage(sheetFile, fileTarget, 10, 10);
-            if (oss) {
-                fileStoreUtil.ossUpload(dirJpgName.toString(), fileTarget, DigestUtils.md5Hex(new FileInputStream(fileTarget)), UploadFileEnum.FILE.getFssType());
-                jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
-                jsonObject.put(SystemConstant.PATH, dirJpgName.toString());
-                path = teachcloudCommonService.filePreview(dirJpgName.toString());
-            } else {
-                jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
-                jsonObject.put(SystemConstant.PATH, stringJoiner.toString() + dirJpgName.toString());
-                path = stringJoiner.toString() + dirJpgName.toString();
-            }
-        } else {
-            jsonObject = JSONObject.parseObject(tSyncExamStudentScore.getTrajectoryUrls());
-            path = teachcloudCommonService.filePreview((String) jsonObject.get(SystemConstant.PATH));
+        boolean update = Objects.isNull(tSyncExamStudentScore.getTrajectoryUrls()) ? true : false;
+        tSyncExamStudentScore = tSyncExamStudentScoreService.createImageTrajectory(tSyncExamStudentScore, ImageTrajectoryEnum.PREVIEW);
+        Optional.ofNullable(tSyncExamStudentScore.getPath()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("资源未获取到,请稍候再试"));
+        if (update) {
+            tSyncExamStudentScoreService.updateById(tSyncExamStudentScore);
         }
-        return ResultUtil.ok(new EditResult(path));
+        return ResultUtil.ok(new EditResult(tSyncExamStudentScore.getPath()));
     }
 
     @ApiOperation(value = "成绩动态轨迹图一键下载")

+ 41 - 8
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/HttpUtil.java

@@ -1,9 +1,13 @@
 package com.qmth.teachcloud.common.util;
 
 import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+import org.apache.commons.io.FileUtils;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
 import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.entity.StringEntity;
@@ -15,16 +19,10 @@ import org.apache.tomcat.util.http.fileupload.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
+import java.io.*;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * @Description: http util
@@ -153,4 +151,39 @@ public class HttpUtil {
         }
         return in;
     }
+
+    /**
+     * 根据url下载文件,保存到filePath中
+     *
+     * @param url
+     * @param filePath
+     * @return
+     */
+    public static File httpDownload(String url, String filePath) throws IOException {
+        InputStream is = null;
+        File file = null;
+        try {
+            HttpClient client = HttpClients.createDefault();
+            HttpGet httpget = new HttpGet(url);
+            HttpResponse response = client.execute(httpget);
+
+            HttpEntity entity = response.getEntity();
+            is = entity.getContent();
+
+            Optional.ofNullable(is).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("所在路径不存在"));
+            file = new File(filePath);
+            if (!file.exists()) {
+                file.getParentFile().mkdirs();
+                file.createNewFile();
+            }
+            FileUtils.copyInputStreamToFile(is, file);
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (Objects.nonNull(is)) {
+                is.close();
+            }
+        }
+        return file;
+    }
 }