Переглянути джерело

feat: onlyoffice 对接

1.更改报告生成文件存储
2.提供onlyoffice 所需参数
3.编写onlyoffice 回调函数
4.放行 word 开头链接
32197351@qq.com 2 роки тому
батько
коміт
6707c3921d

+ 1 - 0
itdmServer/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -100,6 +100,7 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/sys/checkAuth", "anon"); //授权接口排除
 
         filterChainDefinitionMap.put("/word/**", "anon"); //word 下载排除
+        filterChainDefinitionMap.put("/temp/**", "anon"); //word 下载排除
 
         filterChainDefinitionMap.put("/", "anon");
         filterChainDefinitionMap.put("/doc.html", "anon");

+ 1 - 5
itdmServer/module-iTDM/src/main/java/org/jeecg/modules/baogao/service/impl/ItdmBaogaoServiceImpl.java

@@ -274,15 +274,11 @@ public class ItdmBaogaoServiceImpl extends ServiceImpl<ItdmBaogaoMapper, ItdmBao
     @Override
     public ItdmBaogaoVO wordById(String id) {
         ItdmBaogao baoVo = this.baseMapper.selectById(id);
-
         String filepath = baoVo.getFilePath();
-
-        String key = FileUtil.mainName(filepath) + "_" + System.currentTimeMillis();
+        String key = FileUtil.mainName(filepath) + "="+filepath.substring(0, filepath.lastIndexOf("/")).replaceAll("/", "=")+"=" + System.currentTimeMillis();
         String fileType = FileUtil.extName(filepath);
         String url = filepath;
         String title = FileUtil.getName(filepath);
-
-
         return new ItdmBaogaoVO(key, url,fileType, title);
     }
 

+ 32 - 27
itdmServer/module-iTDM/src/main/java/org/jeecg/modules/moban/controller/ItdmMobanController.java

@@ -1,40 +1,25 @@
 package org.jeecg.modules.moban.controller;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.jeecg.common.api.vo.Result;
-import org.jeecg.common.system.query.QueryGenerator;
-import org.jeecg.common.util.oConvertUtils;
-import org.jeecg.modules.moban.entity.ItdmMoban;
-import org.jeecg.modules.moban.service.IItdmMobanService;
-
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-
-import org.jeecgframework.poi.excel.ExcelImportUtil;
-import org.jeecgframework.poi.excel.def.NormalExcelConstants;
-import org.jeecgframework.poi.excel.entity.ExportParams;
-import org.jeecgframework.poi.excel.entity.ImportParams;
-import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.system.base.controller.JeecgController;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.modules.moban.entity.ItdmMoban;
+import org.jeecg.modules.moban.service.IItdmMobanService;
+import org.jeecg.modules.moban.vo.IItdmMobanVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
-import com.alibaba.fastjson.JSON;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import org.jeecg.common.aspect.annotation.AutoLog;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Arrays;
 
  /**
  * @Description: 模板
@@ -174,4 +159,24 @@ public class ItdmMobanController extends JeecgController<ItdmMoban, IItdmMobanSe
         return super.importExcel(request, response, ItdmMoban.class);
     }
 
+
+
+
+
+
+
+
+	 @ApiOperation(value = "onlyoffice 所需数据", notes = "onlyoffice 所需数据")
+
+
+	 @GetMapping(value = "/wordById")
+	 public  Result<IItdmMobanVO>  wordById(@RequestParam(name = "id", required = true) String id) {
+		 IItdmMobanVO itdmBaogao = itdmMobanService.wordById(id);
+
+		 if (itdmBaogao == null) {
+			 return Result.error("未找到对应数据");
+		 }
+		 return Result.OK(itdmBaogao);
+	 }
+
 }

+ 6 - 0
itdmServer/module-iTDM/src/main/java/org/jeecg/modules/moban/service/IItdmMobanService.java

@@ -1,7 +1,9 @@
 package org.jeecg.modules.moban.service;
 
+import org.jeecg.modules.baogao.vo.ItdmBaogaoVO;
 import org.jeecg.modules.moban.entity.ItdmMoban;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.moban.vo.IItdmMobanVO;
 
 /**
  * @Description: 模板
@@ -11,4 +13,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IItdmMobanService extends IService<ItdmMoban> {
 
+
+    IItdmMobanVO wordById(String id);
+
+
 }

+ 27 - 0
itdmServer/module-iTDM/src/main/java/org/jeecg/modules/moban/service/impl/ItdmMobanServiceImpl.java

@@ -1,8 +1,12 @@
 package org.jeecg.modules.moban.service.impl;
 
+import cn.hutool.core.io.FileUtil;
+import org.jeecg.modules.baogao.entity.ItdmBaogao;
+import org.jeecg.modules.baogao.vo.ItdmBaogaoVO;
 import org.jeecg.modules.moban.entity.ItdmMoban;
 import org.jeecg.modules.moban.mapper.ItdmMobanMapper;
 import org.jeecg.modules.moban.service.IItdmMobanService;
+import org.jeecg.modules.moban.vo.IItdmMobanVO;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -16,4 +20,27 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 @Service
 public class ItdmMobanServiceImpl extends ServiceImpl<ItdmMobanMapper, ItdmMoban> implements IItdmMobanService {
 
+
+    @Override
+    public IItdmMobanVO wordById(String id) {
+        ItdmMoban baoVo = this.baseMapper.selectById(id);
+
+        String filepath = baoVo.getFilePath();
+
+
+        String key = FileUtil.mainName(filepath) + "="+filepath.substring(0, filepath.lastIndexOf("/")).replaceAll("/", "=")+"=" + System.currentTimeMillis();
+        String fileType = FileUtil.extName(filepath);
+        String url = filepath;
+        String title = FileUtil.getName(filepath);
+
+
+        return new IItdmMobanVO(key, url,fileType, title);
+    }
+
+
+    public static void main(String[] args) {
+        String filepath = "temp/报告模板中文1_1684804499341.docx";
+
+
+    }
 }

+ 24 - 0
itdmServer/module-iTDM/src/main/java/org/jeecg/modules/moban/vo/IItdmMobanVO.java

@@ -0,0 +1,24 @@
+package org.jeecg.modules.moban.vo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * @Description: 报告生成
+ * @Author: jeecg-boot
+ * @Date: 2023-05-19
+ * @Version: V1.0
+ */
+@Data
+@NoArgsConstructor
+
+@AllArgsConstructor
+public class IItdmMobanVO implements Serializable {
+    private  String key;
+    private  String url;
+    private String fileType;
+    private String title;
+}

+ 2 - 2
itdmServer/module-iTDM/src/main/java/org/jeecg/modules/word/WordController.java

@@ -49,12 +49,12 @@ public class WordController {
 
             String key = map.get("key").toString();
 
-            String fileName =  key.split("_")[0] + "." + map.get("filetype");
+            String fileName =  key.split("=")[0] + "." + map.get("filetype");
 
             URL url = new URL(downloadUri);
             java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
             InputStream stream = connection.getInputStream();
-            String pathForSave = jeecgBaseConfig.getPath().getUpload() + File.separator + "word" + File.separator + fileName;
+            String pathForSave = jeecgBaseConfig.getPath().getUpload() + File.separator + key.split("=")[1] + File.separator + fileName;
 
             File savedFile = new File(pathForSave);
             try (FileOutputStream out = new FileOutputStream(savedFile)) {