wangliang 1 жил өмнө
parent
commit
8fc3636bc2

+ 16 - 6
sop-api/src/main/java/com/qmth/sop/server/api/SysController.java

@@ -22,10 +22,7 @@ import com.qmth.sop.business.service.*;
 import com.qmth.sop.business.util.ImportExportUtil;
 import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.*;
-import com.qmth.sop.common.util.GsonUtil;
-import com.qmth.sop.common.util.Result;
-import com.qmth.sop.common.util.ResultUtil;
-import com.qmth.sop.common.util.ServletUtil;
+import com.qmth.sop.common.util.*;
 import io.swagger.annotations.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -36,9 +33,11 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 import java.security.NoSuchAlgorithmException;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -91,6 +90,9 @@ public class SysController {
     @Resource
     TBServiceService tbServiceService;
 
+    @Resource
+    FileStoreUtil fileStoreUtil;
+
     @ApiOperation(value = "登录")
     @RequestMapping(value = "/login", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "用户信息", response = LoginResult.class)})
@@ -200,13 +202,21 @@ public class SysController {
                                @ApiParam(value = "下载文件类型", required = true) @RequestParam DownloadFileEnum type) throws Exception {
         TBTask tbTask = tbTaskService.getById(taskId);
         Optional.ofNullable(tbTask).orElseThrow(() -> ExceptionResultEnum.TASK_NO_DATA.exception());
-        String path = null;
+        String path = null, content = null;
         switch (type) {
             case IMPORT_FILE:
                 path = tbTask.getImportFilePath();
                 break;
             case REPORT_FILE:
                 path = tbTask.getReportFilePath();
+                JSONObject jsonObject = JSONObject.parseObject(path);
+                UploadFileEnum uploadFileEnum = Enum.valueOf(UploadFileEnum.class, (String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
+                String filePath = (String) jsonObject.get(SystemConstant.PATH);
+                HttpServletResponse response = ServletUtil.getResponse();
+                byte[] bytes = fileStoreUtil.ossDownload(filePath, uploadFileEnum.getFssType());
+                content = new String(bytes, StandardCharsets.UTF_8);
+//                response.setContentType("text/html; charset=utf-8");
+//                response.getWriter().print(string);
                 break;
             case EXPORT_FILE:
                 path = tbTask.getResultFilePath();
@@ -215,7 +225,7 @@ public class SysController {
                 break;
         }
         Optional.ofNullable(path).orElseThrow(() -> ExceptionResultEnum.PATH_NO_DATA.exception());
-        return ResultUtil.ok(new EditResult(basicAttachmentService.filePreview(path)));
+        return ResultUtil.ok(new EditResult(basicAttachmentService.filePreview(path), content));
     }
 
     @ApiOperation(value = "小程序签名预览接口")

+ 13 - 1
sop-business/src/main/java/com/qmth/sop/business/bean/result/EditResult.java

@@ -32,6 +32,17 @@ public class EditResult implements Serializable {
     @ApiModelProperty(value = "小程序签名key")
     String key;
 
+    @ApiModelProperty(value = "txt文件内容")
+    String content;
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+
     public String getKey() {
         return key;
     }
@@ -96,8 +107,9 @@ public class EditResult implements Serializable {
         this.key = key;
     }
 
-    public EditResult(String url) {
+    public EditResult(String url, String content) {
         this.url = url;
+        this.content = content;
     }
 
     public EditResult() {