OnlyofficeController.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. package com.cpms.project.office;
  2. import com.cpms.common.core.controller.BaseController;
  3. import org.springframework.stereotype.Component;
  4. import org.springframework.web.bind.annotation.RequestMapping;
  5. import org.springframework.web.bind.annotation.RequestMethod;
  6. import org.springframework.web.bind.annotation.RestController;
  7. @Component
  8. @RestController
  9. @RequestMapping(value = "/onlyoffice", method = RequestMethod.POST)
  10. public class OnlyofficeController extends BaseController {
  11. //
  12. // protected final Logger logger = LoggerFactory.getLogger(BaseController.class);
  13. // @Autowired
  14. // private ISysUserService sysUserService;
  15. //
  16. // @Autowired
  17. // private FileConfigurer<DefaultFileWrapper> fileConfigurer;
  18. //
  19. // @Value("${deployment.host}")
  20. // private String deploymentHost;
  21. // @Value("${server.port}")
  22. // private String port;
  23. //
  24. // @Value("${files.docservice.url.site}")
  25. // private String docserviceSite;
  26. //
  27. // @Value("${files.docservice.url.api}")
  28. // private String docserviceApiUrl;
  29. //
  30. // @Autowired
  31. // private ITFileService tFileService;
  32. //
  33. // @PostMapping("/previewFile")
  34. // public AjaxResult preview(HttpServletRequest request, @RequestBody PreviewOfficeFileDTO previewOfficeFileDTO) {
  35. // //获取当前用户
  36. // SysUser sysUser = sysUserService.selectUserById(getUserId());
  37. // Action action = Action.view;
  38. // Type type = Type.desktop;
  39. // Locale locale = new Locale("zh");
  40. //
  41. // User user = new User(sysUser);
  42. // //文件
  43. // UserFile userFile = new UserFile();
  44. // TFile rcfile = tFileService.selectTFileById(Long.parseLong(previewOfficeFileDTO.getUserFileId()));
  45. // userFile.setFileId(rcfile.getId().toString());
  46. // userFile.setFilePath(rcfile.getFileUrl());
  47. // userFile.setFileName(rcfile.getFileName());
  48. // userFile.setExtendName("");
  49. // userFile.setUserFileId(rcfile.getId().toString());
  50. // userFile.setUploadTime(String.valueOf(rcfile.getUploadDate().getTime()));
  51. //
  52. // //下载地址
  53. // String previewUrl = deploymentHost + rcfile.getFileUrl();
  54. //// String previewUrl = "/onlyoffice/download?filePath=" + rcfile.getFileUrl();
  55. //
  56. //
  57. // FileModel fileModel = fileConfigurer.getFileModel(
  58. // DefaultFileWrapper
  59. // .builder()
  60. // .userFile(userFile)
  61. // .type(type)
  62. // .lang(locale.toLanguageTag())
  63. // .action(action)
  64. // .user(user)
  65. // .actionData(previewUrl)
  66. // .build()
  67. // );
  68. // fileModel.setToken(null);
  69. // JSONObject jsonObject = new JSONObject();
  70. // jsonObject.put("file", fileModel);
  71. // jsonObject.put("docserviceApiUrl", docserviceSite + docserviceApiUrl);
  72. // jsonObject.put("reportName", userFile.getFileName());
  73. // return AjaxResult.success(jsonObject);
  74. // }
  75. //
  76. ///* @PostMapping("/editFile")
  77. //
  78. // public AjaxResult edit(HttpServletRequest request, @RequestBody PreviewOfficeFileDTO previewOfficeFileDTO) {
  79. //
  80. // //
  81. // SysUser sysUser = sysUserService.selectUserById(getUserId());
  82. // Action action = Action.edit;
  83. // Type type = Type.desktop;
  84. // Locale locale = new Locale("zh");
  85. //
  86. // User user = new User(sysUser);
  87. // //文件
  88. // UserFile userFile = new UserFile();
  89. // TRcfile rcfile = tRcfileService.selectTRcfileById(Long.parseLong(previewOfficeFileDTO.getUserFileId()));
  90. // userFile.setFileId(rcfile.getId().toString());
  91. // userFile.setFilePath(rcfile.getFileUrl());
  92. // userFile.setFileName(rcfile.getFileName());
  93. // userFile.setExtendName("");
  94. // userFile.setUserFileId(rcfile.getId().toString());
  95. // userFile.setUploadTime(String.valueOf(rcfile.getUpdatedate().getTime()));
  96. //
  97. // String previewUrl = "/onlyoffice/download?filePath=" + rcfile.getFileUrl();
  98. //
  99. //
  100. // FileModel fileModel = fileConfigurer.getFileModel(
  101. // DefaultFileWrapper
  102. // .builder()
  103. // .userFile(userFile)
  104. // .type(type)
  105. // .lang(locale.toLanguageTag())
  106. // .action(action)
  107. // .user(user)
  108. // .actionData(previewUrl)
  109. // .build()
  110. // );
  111. // fileModel.setToken(null);
  112. // JSONObject jsonObject = new JSONObject();
  113. // jsonObject.put("file",fileModel);
  114. // jsonObject.put("docserviceApiUrl", docserviceSite + docserviceApiUrl);
  115. // jsonObject.put("reportName",userFile.getFileName());
  116. // return AjaxResult.success(jsonObject);
  117. // }
  118. //*/
  119. //
  120. ///* @RequestMapping(value = "/IndexServlet", method = RequestMethod.POST)
  121. // @ResponseBody
  122. // public void IndexServlet(HttpServletResponse response, HttpServletRequest request) throws IOException {
  123. // logger.info(JSON.toJSONString(request.getParameterMap()));
  124. // String token = request.getParameter("token");
  125. //
  126. // PrintWriter writer = response.getWriter();
  127. // Scanner scanner = new Scanner(request.getInputStream()).useDelimiter("\\A");
  128. // String body = scanner.hasNext() ? scanner.next() : "";
  129. // JSONObject jsonObj = JSON.parseObject(body);
  130. // logger.info(jsonObj.toJSONString());
  131. // logger.info("===saveeditedfile:" + jsonObj.get("status"));
  132. // String status = jsonObj != null ? jsonObj.get("status").toString() : "";
  133. // if ("2".equals(status) || "6".equals(status)) {
  134. // String type = request.getParameter("type");
  135. // String downloadUri = (String) jsonObj.get("url");
  136. // if("edit".equals(type)){ //修改报告
  137. // String userFileId = request.getParameter("userFileId");
  138. // TRcfile rcfile = tRcfileService.selectTRcfileById(Long.parseLong( userFileId ));
  139. //
  140. // String pathForSave = RuoYiConfig.getProfile() + rcfile.getFileUrl().replace("/profile","");
  141. // URL url = new URL(downloadUri);
  142. // HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  143. //
  144. // InputStream stream = connection.getInputStream();
  145. //
  146. // File savedFile = new File(pathForSave);
  147. // try (FileOutputStream out = new FileOutputStream(savedFile)) {
  148. // int read;
  149. // final byte[] bytes = new byte[1024];
  150. // while ((read = stream.read(bytes)) != -1) {
  151. // out.write(bytes, 0, read);
  152. // }
  153. // out.flush();
  154. // }
  155. // connection.disconnect();
  156. // //更新文件时间
  157. // rcfile.setUpdatedate(new Date());
  158. // tRcfileService.updateTRcfile(rcfile);
  159. // }
  160. // }
  161. // writer.write("{\"error\":" + "0" + "}");
  162. // }*/
  163. //
  164. // /**
  165. // *
  166. // * @param response
  167. // */
  168. ///* @GetMapping("/download")
  169. // public void download(UserFile userFile, HttpServletResponse response) {
  170. // try {
  171. // String newFilePath = userFile.getFilePath().replace("/profile","");
  172. // // 需要转换的文件路径
  173. // String pathName = RuoYiConfig.getProfile()+newFilePath;
  174. // logger.info("pathName::::::::::" + pathName);
  175. // String fileName = pathName.substring(pathName.lastIndexOf("/") + 1);
  176. // logger.info("fileName::::::::::" + fileName);
  177. // FileUtils.downloadInline(pathName, fileName,response);
  178. // }catch (Exception e){
  179. // e.printStackTrace();
  180. // }
  181. //
  182. // }*/
  183. //
  184. }