瀏覽代碼

3.1.0-归档管理bug,批量下载bug

xiaof 3 年之前
父節點
當前提交
b6aa52f252

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

@@ -110,6 +110,9 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
             StringJoiner stringJoiner = new StringJoiner("");
             stringJoiner.add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
             List<String> trailUrlsList = tSyncExamStudentScore.getTrailUrls();
+
+            String hostUrl = SystemConstant.getLocalFileHost(dictionaryConfig.sysDomain().getFileHost());
+
             if (Objects.isNull(tSyncExamStudentScore.getTrajectoryUrls())) {
                 JSONArray jsonArray = JSONArray.parseArray(tSyncExamStudentScore.getSheetUrls());
                 JSONObject syncDataJson = JSONObject.parseObject(tSyncExamStudentScore.getSyncData());
@@ -130,7 +133,7 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
                         continue;
                     }
                     String url = (String) jsonArray.get(i);
-                    String format = url.substring(url.lastIndexOf("."), url.length());
+                    String sheetName = url.substring(url.lastIndexOf("/"));
                     LocalDateTime nowTime = LocalDateTime.now();
                     StringJoiner dirJpgName = new StringJoiner("");
                     dirJpgName.add(UploadFileEnum.FILE.getTitle()).add(File.separator)
@@ -139,7 +142,7 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
                             .add(String.format("%02d", nowTime.getDayOfMonth()))
                             .add(File.separator)
                             .add(tSyncExamStudentScore.getExamNumber())
-                            .add(File.separator).add(SystemConstant.getUuid()).add(format);
+                            .add(File.separator).add("sheet").add(File.separator).add(sheetName);
                     File fileSource = new File(stringJoiner.toString() + dirJpgName.toString());
                     if (!fileSource.exists()) {
                         fileSource.getParentFile().mkdirs();
@@ -155,7 +158,7 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
                             .add(String.format("%02d", nowTime.getDayOfMonth()))
                             .add(File.separator)
                             .add(tSyncExamStudentScore.getExamNumber())
-                            .add(File.separator).add(SystemConstant.getUuid()).add(format);
+                            .add(File.separator).add("trail").add(File.separator).add(sheetName);
                     File fileTarget = new File(stringJoiner.toString() + dirTargetJpgName.toString());
                     if (!fileTarget.exists()) {
                         fileTarget.getParentFile().mkdirs();
@@ -171,7 +174,14 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
                         }
                     } else {
                         if (imageTrajectoryEnum == ImageTrajectoryEnum.PREVIEW) {
-                            trailUrlsList.add(fileTarget.getPath());
+                            String filePath = fileTarget.getPath();
+                            String trailUrl;
+                            if (filePath.startsWith("/")) {
+                                trailUrl = hostUrl +  filePath;
+                            } else {
+                                trailUrl = hostUrl + File.separator + filePath;
+                            }
+                            trailUrlsList.add(trailUrl);
                         }
                     }
                     jsonImageTrajectoryPathArray.add(dirTargetJpgName.toString());
@@ -201,7 +211,6 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
                         if (imageTrajectoryEnum == ImageTrajectoryEnum.DOWNLOAD) {
                             fileTargetList.add(new File(stringJoiner.toString() + url));
                         } else {
-                            String hostUrl = SystemConstant.getLocalFileHost(dictionaryConfig.sysDomain().getFileHost());
                             String trailUrl;
                             String filePath = stringJoiner + url;
                             if (filePath.startsWith("/")) {
@@ -262,24 +271,23 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
                     zipFile.getParentFile().mkdirs();
                     zipFile.createNewFile();
                 }
-                File[] files = tSyncExamStudentScore.getTrajectoryFileList().get(0).getParentFile().listFiles();
-                if(files == null || files.length == 0){
+
+                List<File> fileList = tSyncExamStudentScore.getTrajectoryFileList();
+                if(fileList.isEmpty()){
                     throw ExceptionResultEnum.ERROR.exception("没有可下载文件");
                 }
-                List<File> fileList = new ArrayList<>(Arrays.asList(files));
-                fileList.removeAll(tSyncExamStudentScore.getTrajectoryFileList());
+
+                FileUtil.doZip(zipFile, fileList);
+
                 if (Objects.nonNull(dictionaryConfig.sysDomain()) && dictionaryConfig.sysDomain().isOss()) {
                     for (File file : fileList) {
                         file.delete();
                     }
                 }
-                FileUtil.doZip(zipFile, Arrays.asList(tSyncExamStudentScore.getTrajectoryFileList().get(0).getParentFile()));
+
                 HttpServletResponse response = ServletUtil.getResponse();
-//                response.setContentType("image/jpeg");
-//                outputStream = new BufferedOutputStream(response.getOutputStream());
-//                IOUtils.copy(new FileInputStream(zipFile), outputStream);
                 response.reset();
-                response.setHeader("Content-Disposition", "attachment;fileName=" + zipFile.getName());
+                response.setHeader("Content-Disposition", "attachment;filename=" + zipFile.getName());
                 response.addHeader("Content-Length", "" + zipFile.length());
                 response.setContentType("application/octet-stream;charset=UTF-8");
                 outputStream = new BufferedOutputStream(response.getOutputStream());
@@ -294,7 +302,7 @@ public class TSyncExamStudentScoreServiceImpl extends ServiceImpl<TSyncExamStude
                 outputStream.close();
             }
             if (Objects.nonNull(zipFile)) {
-                zipFile.delete();
+                System.out.println(zipFile.delete());
             }
         }
     }

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/export/AsyncExportTaskTemplete.java

@@ -103,7 +103,7 @@ public abstract class AsyncExportTaskTemplete {
 //                ossUtil.ossUpload(stringJoiner.toString(), inputStream, null);
                 fileStoreUtil.ossUpload(stringJoiner.toString(), inputStream, DigestUtils.md5Hex(new ByteArrayInputStream(bookByteAry)), fileStoreUtil.getUploadEnumByPath(stringJoiner.toString()).getFssType());
             } else {//上传至服务器
-                path = path.substring(0, path.lastIndexOf(File.separator) + 1);
+                path = path.substring(0, path.lastIndexOf("/") + 1);
                 stringJoiner.add(path).add(SystemConstant.getUuid()).add(TXT_PREFIX).toString();
                 File finalFile = new File(stringJoiner.toString());
                 if (!finalFile.exists()) {

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

@@ -36,6 +36,7 @@ import com.qmth.teachcloud.common.service.*;
 import com.qmth.teachcloud.common.util.*;
 import com.qmth.teachcloud.common.util.excel.ExcelError;
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.Cell;
@@ -639,6 +640,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 //        UploadFileEnum.FILE/
         LocalDateTime nowTime = LocalDateTime.now();
         StringJoiner stringJoiner = new StringJoiner("");
+        stringJoiner.add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
         stringJoiner.add(UploadFileEnum.FILE.getTitle()).add(File.separator);
 
         stringJoiner.add(String.valueOf(nowTime.getYear())).add(File.separator)
@@ -650,14 +652,15 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 
         String dirName = stringJoiner.toString().replaceAll("\\\\", "/");
 
-        boolean oss = (boolean) map.get(SystemConstant.OSS);
+        boolean oss = dictionaryConfig.sysDomain().isOss();
         if (oss) {//上传至oss
             fileStoreUtil.ossUpload(dirName, in, DigestUtils.md5Hex(new ByteArrayInputStream(outputStream.toByteArray())), fileStoreUtil.getUploadEnumByPath(dirName).getFssType());
             jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
             jsonObject.put(SystemConstant.PATH, dirName);
         } else {
+            FileUtils.copyInputStreamToFile(in, new File(stringJoiner.toString()));
             jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
-            jsonObject.put(SystemConstant.PATH, stringJoiner + dirName);
+            jsonObject.put(SystemConstant.PATH, dirName);
         }
         jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
         map.put(SystemConstant.PATH, jsonObject.toString());
@@ -1632,15 +1635,14 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         boolean update = Objects.isNull(t.getTrajectoryUrls()) ? true : false;
                         t = tSyncExamStudentScoreService.createImageTrajectory(t, ImageTrajectoryEnum.DOWNLOAD);
                         if (Objects.nonNull(t.getTrajectoryFileList())) {
-                            File[] files = t.getTrajectoryFileList().get(0).getParentFile().listFiles();
-                            List<File> fileList = new ArrayList<>(Arrays.asList(files));
-                            fileList.removeAll(t.getTrajectoryFileList());
+                            List<File> fileList = t.getTrajectoryFileList();
+//                            fileList.removeAll(t.getTrajectoryFileList());
                             if (Objects.nonNull(dictionaryConfig.sysDomain()) && dictionaryConfig.sysDomain().isOss()) {
                                 for (File file : fileList) {
                                     file.delete();
                                 }
                             }
-                            sourceFiles.add(t.getTrajectoryFileList().get(0).getParentFile());
+                            sourceFiles.addAll(t.getTrajectoryFileList());
                         } else {
                             errorTSyncExamStudentScoreList.add(t);
                         }
@@ -1654,7 +1656,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 }
                 tSyncExamStudentScoreService.saveOrUpdateBatch(updateTSyncExamStudentScoreList);
                 if (Objects.nonNull(sourceFiles) && sourceFiles.size() > 0) {
-                    FileUtil.doZip(zipFile, sourceFiles);
+                    ZipUtil.zip(zipFile, false, sourceFiles.toArray(new File[sourceFiles.size()]));
                     boolean oss = (boolean) map.get(SystemConstant.OSS);
                     JSONObject jsonObject = new JSONObject();
                     if (oss) {//上传至oss
@@ -1682,9 +1684,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
         } finally {
-            if (Objects.nonNull(zipFile)) {
-                zipFile.delete();
-            }
+//            if (Objects.nonNull(zipFile)) {
+//                zipFile.delete();
+//            }
         }
         return map;
     }

+ 1 - 2
distributed-print/src/main/java/com/qmth/distributed/print/api/ExamDetailController.java

@@ -218,8 +218,7 @@ public class ExamDetailController {
         map.put("startDate", startDate);
         map.put("endDate", endDate);
         map.put("orgIds", orgIds);
-        asyncExaminationExportTemplateService
-                .exportTask(map);
+        asyncExaminationExportTemplateService.exportTask(map);
         TBTask tbTask = Objects.nonNull(map.get(SystemConstant.TASK)) ? (TBTask) map.get(SystemConstant.TASK) : null;
         return Objects.nonNull(tbTask) ? ResultUtil.ok(tbTask.getId()) : ResultUtil.error("创建任务失败");
     }

+ 0 - 4
distributed-print/src/main/java/com/qmth/distributed/print/api/TSyncExamStudentScoreController.java

@@ -201,12 +201,8 @@ public class TSyncExamStudentScoreController {
     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());
         tSyncExamStudentScore = tSyncExamStudentScoreService.createImageTrajectory(tSyncExamStudentScore, imageTrajectoryEnum);
         Optional.ofNullable(tSyncExamStudentScore.getTrajectoryUrls()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("阅卷方式未使用轨迹阅卷,无轨迹图"));
-        if (update || Objects.isNull(tSyncExamStudentScore.getTrajectoryUrls())) {
-            tSyncExamStudentScoreService.updateById(tSyncExamStudentScore);
-        }
         return tSyncExamStudentScore;
     }
 }