wangliang 3 лет назад
Родитель
Сommit
ed1ff244ec

+ 17 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TSyncExamStudentScore.java

@@ -11,6 +11,7 @@ import io.swagger.annotations.ApiModelProperty;
 
 import java.io.File;
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -118,6 +119,10 @@ public class TSyncExamStudentScore implements Serializable {
     @TableField(exist = false)
     private List<File> trajectoryFileList;
 
+    @ApiModelProperty(value = "轨迹图url")
+    @TableField(exist = false)
+    private List<String> trailUrls;
+
     public void setErrorInfo() {
         this.trajectoryFileList = null;
         this.trajectoryUrls = null;
@@ -175,6 +180,18 @@ public class TSyncExamStudentScore implements Serializable {
         }
     }
 
+    public List<String> getTrailUrls() {
+        if (Objects.isNull(trailUrls)) {
+            return new ArrayList<>();
+        } else {
+            return trailUrls;
+        }
+    }
+
+    public void setTrailUrls(List<String> trailUrls) {
+        this.trailUrls = trailUrls;
+    }
+
     public Long getClazzId() {
         return clazzId;
     }

+ 23 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TSyncExamStudentScoreServiceImpl.java

@@ -14,6 +14,7 @@ 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;
@@ -45,6 +46,9 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
     @Resource
     FileStoreUtil fileStoreUtil;
 
+    @Resource
+    TeachcloudCommonService teachcloudCommonService;
+
     /**
      * 同步成绩查询列表
      *
@@ -109,6 +113,7 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
             Optional.ofNullable(tSyncExamStudentScore.getSyncData()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未获取到考生作答数据"));
             StringJoiner stringJoiner = new StringJoiner("");
             stringJoiner.add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
+            List<String> trailUrlsList = tSyncExamStudentScore.getTrailUrls();
             if (Objects.isNull(tSyncExamStudentScore.getTrajectoryUrls())) {
                 JSONArray jsonArray = JSONArray.parseArray(tSyncExamStudentScore.getSheetUrls());
                 JSONObject syncDataJson = JSONObject.parseObject(tSyncExamStudentScore.getSyncData());
@@ -165,6 +170,13 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
                     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()));
+                        }
+                    } else {
+                        if (imageTrajectoryEnum == ImageTrajectoryEnum.PREVIEW) {
+                            trailUrlsList.add(fileTarget.getPath());
+                        }
                     }
                     jsonImageTrajectoryPathArray.add(dirTargetJpgName.toString());
                 }
@@ -179,15 +191,24 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
                 if (Objects.equals(ossType, SystemConstant.OSS)) {
                     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()));
+                        if (imageTrajectoryEnum == ImageTrajectoryEnum.DOWNLOAD) {
+                            fileTargetList.add(fileStoreUtil.ossDownload(url, stringJoiner.toString() + url, UploadFileEnum.FILE.getFssType()));
+                        } else {
+                            trailUrlsList.add(fileStoreUtil.getPrivateUrl(url, UploadFileEnum.convertToFssType((String) jsonObject.get(SystemConstant.UPLOAD_TYPE))));
+                        }
                     }
                 } else {
                     for (int i = 0; i < jsonArray.size(); i++) {
                         String url = (String) jsonArray.get(i);
-                        fileTargetList.add(new File(stringJoiner.toString() + url));
+                        if (imageTrajectoryEnum == ImageTrajectoryEnum.DOWNLOAD) {
+                            fileTargetList.add(new File(stringJoiner.toString() + url));
+                        } else {
+                            trailUrlsList.add(stringJoiner.toString() + url);
+                        }
                     }
                 }
             }
+            tSyncExamStudentScore.setTrailUrls(trailUrlsList);
             if (Objects.nonNull(fileTargetList) && fileTargetList.size() > 0) {
                 tSyncExamStudentScore.setTrajectoryFileList(fileTargetList);
             }

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

@@ -41,6 +41,8 @@
             bm.id = tsess.major_id
         join sys_org so on
             so.id = tsess.org_id
+        join exam_detail_course edc on
+		    edc.school_id = tsess.school_id and concat(edc.paper_number,edc.paper_type) = tsess.subject_code
     </sql>
 
     <sql id="footCommonSql">
@@ -61,7 +63,7 @@
                 and tsess.clazz_id = #{clazzId}
             </if>
             <if test="courseCode != null and courseCode != ''">
-                and tsess.subject_code LIKE CONCAT('%',#{courseCode},'%')
+                and edc.course_code = #{courseCode}
             </if>
             order by tsess.exam_id
         </where>

+ 29 - 8
distributed-print/src/main/java/com/qmth/distributed/print/api/TSyncExamStudentScoreController.java

@@ -131,17 +131,19 @@ public class TSyncExamStudentScoreController {
     @RequestMapping(value = "/score/download", method = RequestMethod.POST)
     @Transactional
     public void download(@ApiParam(value = "主键", required = true) @RequestParam String id) throws Exception {
-        TSyncExamStudentScore tSyncExamStudentScore = tSyncExamStudentScoreService.getById(SystemConstant.convertIdToLong(id));
-        Optional.ofNullable(tSyncExamStudentScore).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未找到此考生信息"));
-        boolean update = Objects.isNull(tSyncExamStudentScore.getTrajectoryUrls()) ? true : false;
-        tSyncExamStudentScore = tSyncExamStudentScoreService.createImageTrajectory(tSyncExamStudentScore, ImageTrajectoryEnum.PREVIEW);
-        Optional.ofNullable(tSyncExamStudentScore.getTrajectoryUrls()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("资源未获取到,请稍候再试"));
-        if (update || Objects.isNull(tSyncExamStudentScore.getTrajectoryUrls())) {
-            tSyncExamStudentScoreService.updateById(tSyncExamStudentScore);
-        }
+        TSyncExamStudentScore tSyncExamStudentScore = downloadOrPreview(id, ImageTrajectoryEnum.DOWNLOAD);
         tSyncExamStudentScoreService.createZipFile(tSyncExamStudentScore);
     }
 
+    @ApiOperation(value = "成绩归档查看原卷")
+    @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = EditResult.class)})
+    @RequestMapping(value = "/score/preview", method = RequestMethod.POST)
+    @Transactional
+    public Result preview(@ApiParam(value = "主键", required = true) @RequestParam String id) throws Exception {
+        TSyncExamStudentScore tSyncExamStudentScore = downloadOrPreview(id, ImageTrajectoryEnum.PREVIEW);
+        return ResultUtil.ok(tSyncExamStudentScore.getTrailUrls());
+    }
+
     @ApiOperation(value = "成绩动态轨迹图一键下载")
     @ApiResponses({@ApiResponse(code = 200, message = "同步信息", response = TBTask.class)})
     @RequestMapping(value = "/score/batch_download", method = RequestMethod.POST)
@@ -183,4 +185,23 @@ public class TSyncExamStudentScoreController {
         TBTask tbTask = Objects.nonNull(map.get(SystemConstant.TASK)) ? (TBTask) map.get(SystemConstant.TASK) : null;
         return Objects.nonNull(tbTask) ? ResultUtil.ok(tbTask.getId()) : ResultUtil.error("创建任务失败");
     }
+
+    /**
+     * 下载或预览
+     *
+     * @param id
+     * @param imageTrajectoryEnum
+     * @return
+     */
+    private TSyncExamStudentScore downloadOrPreview(String id, ImageTrajectoryEnum imageTrajectoryEnum) {
+        TSyncExamStudentScore tSyncExamStudentScore = tSyncExamStudentScoreService.getById(SystemConstant.convertIdToLong(id));
+        Optional.ofNullable(tSyncExamStudentScore).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未找到此考生信息"));
+        boolean update = Objects.isNull(tSyncExamStudentScore.getTrajectoryUrls()) ? true : false;
+        tSyncExamStudentScore = tSyncExamStudentScoreService.createImageTrajectory(tSyncExamStudentScore, imageTrajectoryEnum);
+        Optional.ofNullable(tSyncExamStudentScore.getTrajectoryUrls()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("资源未获取到,请稍候再试"));
+        if (update || Objects.isNull(tSyncExamStudentScore.getTrajectoryUrls())) {
+            tSyncExamStudentScoreService.updateById(tSyncExamStudentScore);
+        }
+        return tSyncExamStudentScore;
+    }
 }

+ 15 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/enums/UploadFileEnum.java

@@ -58,4 +58,19 @@ public enum UploadFileEnum {
         }
         return null;
     }
+
+    /**
+     * 状态转换 toName
+     *
+     * @param title
+     * @return
+     */
+    public static String convertToFssType(String title) {
+        for (UploadFileEnum e : UploadFileEnum.values()) {
+            if (Objects.equals(title.toLowerCase(), e.getTitle())) {
+                return e.getFssType();
+            }
+        }
+        return null;
+    }
 }

+ 10 - 10
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/TeachcloudCommonServiceImpl.java

@@ -527,13 +527,13 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
         if (Objects.equals(attachmentType, SystemConstant.LOCAL)) {
             url = SystemConstant.HTTP + dictionaryConfig.sysDomain().getFileHost() + File.separator + filePath;
         } else {
-            if (uploadFileEnum == UploadFileEnum.PAPER) {
+//            if (uploadFileEnum == UploadFileEnum.PAPER) {
 //                url = ossUtil.getPrivateUrl(filePath);
-                url = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
-            } else {
+            url = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
+//            } else {
 //                url = dictionaryConfig.aliYunOssDomain().getUrl() + File.separator + filePath;
-                url = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
-            }
+//                url = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
+//            }
         }
         return url;
     }
@@ -593,13 +593,13 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
         if (Objects.equals(attachmentType, SystemConstant.LOCAL)) {
             pathUrl = SystemConstant.HTTP + dictionaryConfig.sysDomain().getFileHost() + File.separator + filePath;
         } else {
-            if (isExpire) {
+//            if (isExpire) {
 //                pathUrl = ossUtil.getPrivateUrl(filePath);
-                pathUrl = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
-            } else {
+            pathUrl = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
+//            } else {
 //                pathUrl = dictionaryConfig.aliYunOssDomain().getUrl() + File.separator + filePath;
-                pathUrl = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
-            }
+//                pathUrl = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
+//            }
 
         }
         map.put("url", pathUrl);