onlyoffice回调函数controller方式实现

原文同步自作者博客:https://www.daxueyiwu.com/post/706

springboot实现的onlyoffice协同编辑网盘项目可以去作者博客。

上代码:

//新建报告@GetMapping("report/createReport")public String CreatReport(HttpServletRequest request,String memo,String reportName,Model model){String type = request.getParameter("type");String reportCategory = request.getParameter("reportCategory");String reportCategoryName = request.getParameter("reportCategoryName");String nowTime = DateUtil.getNowDateHm();model.addAttribute("type",type);model.addAttribute("reportCategory",reportCategory);model.addAttribute("reportCategoryName",reportCategoryName);model.addAttribute("memo",memo);model.addAttribute("reportName",reportName);model.addAttribute("nowTime",nowTime);return "report/newReport";}@Value("${xmleditor.onlyoffice_address}")private String docserviceApiUrl;//onlyoffice新建报告(空白|模板)@GetMapping(value = "/report/createReportForOnlyoffice")public String createReportForOnlyoffice(HttpServletRequest request, HttpServletResponse response,Model model) {String UserCode = SessionHelper.GetLoginUserCode();User loginUser = userRepository.getByName(UserCode);String fileName = UuidUtil.getUUID()+".docx";String reportName= request.getParameter("reportName");String HfsKey = request.getParameter("hfsKey");String baseUrl = request.getScheme()+"://"+ request.getServerName()+":"+request.getServerPort()+request.getContextPath();String getOnlyofficeUrl = baseUrl+"/report/getOfficeFile?filename=";OnlyofficeFileModel file = new OnlyofficeFileModel(loginUser,reportName,HfsKey,getOnlyofficeUrl,modelConf.getFileExistUrl(),modelConf.getUploadImgUrl(),"edit");String serverPath = request.getScheme() +"://"+ request.getServerName()+":" + request.getServerPort() + request.getContextPath();String query = null;try {query = "?type=track&fileName=" + URLEncoder.encode(fileName, java.nio.charset.StandardCharsets.UTF_8.toString())+"&reportName="+request.getParameter("reportName")+"&memo="+request.getParameter("memo")+"&doctype="+request.getParameter("type")+"&UserCode="+UserCode+"&hfsKey="+request.getParameter("hfsKey")+"&reportCategory="+request.getParameter("reportCategory");} catch (UnsupportedEncodingException e) {e.printStackTrace();}file.editorConfig.callbackUrl= serverPath + "/IndexServlet" + query;model.addAttribute("file",file);model.addAttribute("docserviceApiUrl",docserviceApiUrl);model.addAttribute("reportName",reportName);return "report/newReport1";}//查看报告@GetMapping(value = "/report/showReportForOnlyoffice")public String showReportForOnlyoffice(HttpServletRequest request, HttpServletResponse response,Model model) {String UserCode = SessionHelper.GetLoginUserCode();User loginUser = userRepository.getByName(UserCode);String fileName = request.getParameter("fileName");String HfsKey = request.getParameter("hfsKey");String baseUrl = request.getScheme()+"://"+ request.getServerName()+":"+request.getServerPort()+request.getContextPath();String getOnlyofficeUrl = baseUrl+"/report/getOfficeFile?filename=";OnlyofficeFileModel file = new OnlyofficeFileModel(loginUser,fileName,HfsKey,getOnlyofficeUrl,modelConf.getFileExistUrl(),modelConf.getUploadImgUrl(),"view");String serverPath = request.getScheme() +"://"+ request.getServerName()+":" + request.getServerPort() + request.getContextPath();String query = "?type=show";file.editorConfig.callbackUrl= serverPath + "/IndexServlet" + query;model.addAttribute("file",file);model.addAttribute("reportName",fileName);model.addAttribute("docserviceApiUrl",docserviceApiUrl);return "report/newReport1";}//编辑报告@GetMapping(value = "/report/editReportForOnlyoffice")public String editReportForOnlyoffice(HttpServletRequest request, HttpServletResponse response,Model model) {String id = request.getParameter("id");String HfsKey = request.getParameter("hfsKey");String fileName = request.getParameter("fileName");String UserCode = SessionHelper.GetLoginUserCode();User loginUser = userRepository.getByName(UserCode);String baseUrl = request.getScheme()+"://"+ request.getServerName()+":"+request.getServerPort()+request.getContextPath();String getOnlyofficeUrl = baseUrl+"/report/getOfficeFile?filename=";OnlyofficeFileModel file = new OnlyofficeFileModel(loginUser,fileName,HfsKey,getOnlyofficeUrl,modelConf.getFileExistUrl(),modelConf.getUploadImgUrl(),"edit");String serverPath = request.getScheme() +"://"+ request.getServerName()+":" + request.getServerPort() + request.getContextPath();String query = null;try {query = "?type=edit&fileName=" + URLEncoder.encode(fileName, java.nio.charset.StandardCharsets.UTF_8.toString())+"&doctype="+request.getParameter("type")+"&id="+id+"&UserCode="+UserCode+"&hfsKey="+HfsKey;} catch (UnsupportedEncodingException e) {e.printStackTrace();}file.editorConfig.callbackUrl= serverPath + "/IndexServlet" + query;model.addAttribute("file",file);model.addAttribute("reportName",fileName);model.addAttribute("docserviceApiUrl",docserviceApiUrl);return "report/newReport1";}@GetMapping("/report/getOfficeFile")public void getHfsFile(HttpServletRequest request, HttpServletResponse response) {String url = "";try {String fileName = request.getParameter("filename");url = modelConf.getGetImgUrl() + fileName;if (StringUtil.isNotBlank(fileName)) {HttpClientHelper.getInstance().httpDownloadOfficeFile(url, response);} else {OutputStream toClient = response.getOutputStream();toClient.write("the filename is empty".getBytes());toClient.flush();}} catch (Exception e) {e.printStackTrace();log.error("文件获取失败,url:{}", url);}}@Autowiredprivate FileUploadConfig fileUploadConfig;@RequestMapping(value = "/IndexServlet", method = RequestMethod.POST)@ResponseBodypublic void IndexServlet(HttpServletResponse response, HttpServletRequest request) throws IOException, ParseException {PrintWriter writer = null;JSONObject jsonObj=null;System.out.println("===saveeditedfile------------");try {writer = response.getWriter();Scanner scanner = new Scanner(request.getInputStream()).useDelimiter("\\A");String body = scanner.hasNext() ? scanner.next() : "";jsonObj = (JSONObject) new JSONParser().parse(body);System.out.println("===saveeditedfile:" + jsonObj.get("status")) ;if ((long) jsonObj.get("status") == 6) {//新建报告(long) jsonObj.get("status") == 2||String type = request.getParameter("type");if("track".equals(type)){String downloadUri = (String) jsonObj.get("url");System.out.println("====文档编辑完成,现在开始保存编辑后的文档,其下载地址为:" + downloadUri);String fileName = request.getParameter("fileName");System.out.println("====下载的文件名:" + fileName);String reportName = request.getParameter("reportName");String doctype = request.getParameter("doctype");String memo = request.getParameter("memo");String reportCategory = request.getParameter("reportCategory");String UserCode = request.getParameter("UserCode");URL url = new URL(downloadUri);java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();InputStream stream = connection.getInputStream();File savedFile = new File(fileUploadConfig.getSavePath()+fileName);try (FileOutputStream out = new FileOutputStream(savedFile)) {int read;final byte[] bytes = new byte[1024];while ((read = stream.read(bytes)) != -1) {out.write(bytes, 0, read);}out.flush();}connection.disconnect();//上传到hfsMap<String, String> map = new HashMap<String, String>();map.put("filename", fileName);try {HttpClientHelper.getInstance().uploadFileImpl(modelConf.getUploadImgUrl(), fileUploadConfig.getSavePath()+fileName, fileName, map);} catch (Exception e) {e.printStackTrace();throw new RuntimeException("上传文件失败");}//保存到表中 报告if("report".equals(doctype)){/*添加报告*/Report report = new Report();int flag_add = 0;//report.setReportContentID(bookId);report.setReportXML("");//预留字段report.setReportCode("");//预留字段report.setReportName(reportName);report.setReportCategoryID(Integer.parseInt(reportCategory));report.setStatus(1);report.setMemo(memo);report.setCreateUser(UserCode);Date day=new Date();report.setCreateTime(day);report.setHfsKey(fileName.substring(0,fileName.length()-5));flag_add = reportService.addReportOnlyoffice(report);}else if("reportTemplet".equals(doctype)){/*添加报告模板*/ReportTemplet reportT = new ReportTemplet();int flag_add = 0;//reportT.setReportContentID(bookId);reportT.setReportTempletXML("");//预留字段reportT.setReportTempletCode("");//预留字段reportT.setReportTempletName(reportName);reportT.setReportCategoryID(Integer.parseInt(reportCategory));reportT.setStatus(1);reportT.setMemo(memo);reportT.setCreateUser(UserCode);reportT.setHfsKey(fileName.substring(0,fileName.length()-5));Date day=new Date();reportT.setCreateTime(day);flag_add = reportTempletService.addReportTempletOnlyOffice(reportT);}}else if("show".equals(type)){//查看报告System.out.println("====只查看不保存:");}else if("edit".equals(type)){//修改报告String downloadUri = (String) jsonObj.get("url");System.out.println("====文档编辑完成,现在开始保存编辑后的文档,其下载地址为:" + downloadUri);String doctype = request.getParameter("doctype");String UserCode = request.getParameter("UserCode");String HfsKey = request.getParameter("hfsKey");String id = request.getParameter("id");String fileName = HfsKey+".docx";URL url = new URL(downloadUri);java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();InputStream stream = connection.getInputStream();File savedFile = new File(fileUploadConfig.getSavePath()+fileName);try (FileOutputStream out = new FileOutputStream(savedFile)) {int read;final byte[] bytes = new byte[1024];while ((read = stream.read(bytes)) != -1) {out.write(bytes, 0, read);}out.flush();}connection.disconnect();//上传到hfsMap<String, String> map = new HashMap<String, String>();map.put("filename", fileName);try {HttpClientHelper.getInstance().uploadFileImpl(modelConf.getUploadImgUrl(), fileUploadConfig.getSavePath()+fileName, fileName, map);} catch (Exception e) {e.printStackTrace();throw new RuntimeException("上传文件失败");}//保存到表中 报告if("report".equals(doctype)){/*添加报告*/Report report = reportService.getByID(Integer.valueOf(id));int flag_up = 0;report.setModifyUser(UserCode);Date day=new Date();report.setModifyTime(day);report.setStatus(1);//修改后需要重新发布flag_up = reportService.updateReportInfo(report);}else if("reportTemplet".equals(doctype)){/*添加报告模板*/ReportTemplet reportT = reportTempletService.getByID(Integer.valueOf(id));int flag_up = 0;reportT.setModifyUser(UserCode);Date day=new Date();reportT.setModifyTime(day);reportT.setStatus(1);//修改后需要重新发布flag_up = reportTempletService.updateReportTempletInfo(reportT);}}}}catch (IOException e) {e.printStackTrace();} catch (ParseException e) {e.printStackTrace();}if((long) jsonObj.get("status") == 3||(long) jsonObj.get("status") == 7) {System.out.println("====保存失败:");writer.write("{\"error\":1}");}else {writer.write("{\"error\":" + "0" + "}");}}

 

如有其他疑问可加入Q群,共同探讨:

onlyoffice交流群

1群将满可加2群【onlyoffice交流群2】:https://jq.qq.com/?_wv=1027&k=2uSJJPfr

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/281103.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

读Bilgin Ibryam 新作 《Dapr 是一种10倍数 平台》

Bilgin Ibryam 最近加入了开发者软件初创公司Diagrid Inc&#xff0c;他是Apache Software Foundation 的 committer 和成员。他也是一个开源的布道师&#xff0c;并且是书籍 Kubernetes设计模式 和 Camel Design Patterns 的作者。早在2020年初 提出的Multi-Runtime Microserv…

如何在iPhone或iPad上使用Safari下载文件

Khamosh PathakKhamosh PathakIn your work or personal life, you’ll sometimes need to download a file on your iPhone or iPad. Using the new feature introduced in iOS 13 and iPadOS 13, you can now do this directly in Safari. No third-party app needed! 在工作…

java版左右手桌面盯盘软件dstock V1.0

V1.0功能比较简陋&#xff0c;先满足自己桌面盯盘需要 V1.0 版本功能介绍&#xff1a; 1. 1s实时刷新盯盘数据 主要市面上的&#xff0c;符合我要求的桌面应用要VIP,穷啊&#xff0c;还是月月付&#xff0c;年年付&#xff0c;还是自己搞吧&#xff01; 2. 配置文件配置股票…

放大倍数超5万倍的Memcached DDoS反射攻击,怎么破?

欢迎大家前往腾讯云社区&#xff0c;获取更多腾讯海量技术实践干货哦~ 作者&#xff1a;腾讯游戏云 背景&#xff1a;Memcached攻击创造DDoS攻击流量纪录 近日&#xff0c;利用Memcached服务器实施反射DDoS攻击的事件呈大幅上升趋势。DDoS攻击流量首次过T&#xff0c;引发业界热…

C# WPF TabControl控件用法详解

概述TabControl我之前有讲过一节&#xff0c;内容详见&#xff1a;C# WPF TabControl用法指南(精品)&#xff0c;上节主要讲解了tabcontrol控件的左右翻页&#xff0c;以及页面筛选&#xff0c;以及数据绑定等内容&#xff0c;这节内容继续接续上节内容进行扩展讲解&#xff0c…

pixel 解锁_如何在Google Pixel 4和Pixel 4 XL上禁用面部解锁

pixel 解锁Justin Duino贾斯汀杜伊诺(Justin Duino)Face Unlock is one of the Google Pixel 4 and Pixel 4 XL’s flagship features. But if the facial recognition is a form of biometric security you’re uncomfortable with, you can delete your face data right off …

【实战】将多个不规则多级表头的工作表合并为一个规范的一维表数据结果表...

最近在项目里&#xff0c;有个临时的小需求&#xff0c;需要将一些行列交叉结构的表格进行汇总合并&#xff0c;转换成规范的一维表数据结构进行后续的分析使用。从一开始想到的使用VBA拼接字符串方式&#xff0c;完成PowerQuery的M语言查询字符串&#xff0c;然后转换成使用插…

happiness[国家集训队2011(吴确)]

【试题来源】 2011中国国家集训队命题答辩【问题描述】 高一一班的座位表是个n*m的矩阵&#xff0c;经过一个学期的相处&#xff0c;每个同学和前后左右相邻的同学互相成为了好朋友。这学期要分文理科了&#xff0c;每个同学对于选择文科与理科有着自己的喜悦值&#xff0c;而一…

sketch怎么移动图层_什么是Photoshop Express,Fix,Mix和Sketch移动应用程序?

sketch怎么移动图层Adobe’s approach to mobile apps seems to be “The More, The Better”. Right now, there are five Photoshop branded apps available for iOS and Android. Adobe的移动应用程序方法似乎是“越多越好”。 目前&#xff0c;有五个适用于iOS和Android的P…

imessage_如何在iPhone和iPad上的iMessage组中提及某人

imessageKhamosh PathakKhamosh PathakSometimes, it’s difficult to get someone’s attention in a large iMessage group chat on your iPhone or iPad. However, if you mention that person specifically in a message, your friend will receive a notification about i…

点击右侧导航栏,实现iframe嵌入子页面中div,滑动到最上面

2019独角兽企业重金招聘Python工程师标准>>> // 点击对应的nav里的li标签,页面就滚动到哪里 $(.title-list > li).click(function(event) {$(this).addClass(active).siblings().removeClass(active);//li标签里面有a标签,可以阻止到a标签的默认行为event.preven…

wepack环境配置1之node的安装

.向往已久的webpack终于配好了.. 1.要安装webpack&#xff0c;首先需要安装nodejs nodejs下载地址:https://nodejs.org/en/ 下载完成后,一步步安装即可,我是安装到D盘 新建一个nodejs的文件夹,装到这个文件夹里面即可. 安装完毕后检查自己是否安装成功.启动cmd,然后输入npm -v,…

【赏析】.NET跨平台框架-Avalonia UI

这是Avalonia UI官方的一个Demo&#xff0c;站长对部分Nuget包进行了升级&#xff0c;网友【小飞机MLA】对Linux版本修复了字体Bug得以正常运行、演示&#xff1a;Windows 11&#xff1a;macOS 13&#xff1a;可安装Rider&#xff08;EAP即要&#xff09;开发&#xff0c;站长一…

office自定义安装选项_如何自定义Office 2013中功能区上的现有选项卡

office自定义安装选项The Ribbon in Microsoft Office 2013 provides quick access to many features and options by default, but it can be further customized to fit the way you use it. You can add a custom tab to the ribbon or you can add commands to the existin…

Centos6.8 安装spark-2.3.1 以及 scala-2.12.2

一、Spark概述 Spark 是一个用来实现快速而通用的集群计算的平台。 在速度方面&#xff0c;Spark 扩展了广泛使用的 MapReduce 计算模型&#xff0c;而且高效地支持更多计算模式&#xff0c;包括交互式查询和流处理。 在处理大规模数据集时&#xff0c;速度是非常重要的。速…

聊一聊 WPF 程序的键盘是如何被窃听的?

一&#xff1a;背景 1.讲故事前几天群里很热闹&#xff0c;看了下在争论两个问题&#xff1a;电脑里要不要装杀毒软件 ?应该装什么杀毒软件 ?不管杀毒软件流氓不流氓&#xff0c;在如今病毒肆虐的当下互联网&#xff0c;装一个还是能帮我们拦截很多意想不到的东西&#xff0c…

httpclient 实现文件上传中转

开发功能&#xff1a; web前端提交上传文件 —> a服务器接收 —> 转发到b服务器进行文件处理 下面是简单实现的代码&#xff0c;具体细节优化根本自己的需求更改。 public String handleResponse(HttpServletRequest request, HttpServletResponse response)throws Unsup…

AngularJS $watch 性能杀手

双向绑定是AngularJS核心概念之一&#xff0c;它给我们带来了思维的转变&#xff0c;不再是以DOM为驱动&#xff0c;而是以Model为核心&#xff0c;View中写上声明式标签&#xff08;指令或{{}}&#xff09;,AngularJS会在后台默默同步View到Model,并将Model的变化更新到View。…

ipad和iphone切图_如何在iPhone和iPad上的Messages App中固定对话

ipad和iphone切图Khamosh PathakKhamosh PathakBetween updates from your bank and group chats, the Messages app on your iPhone or iPad can be a mess. Use the pinned conversations feature introduced in iOS 14 and iPadOS 14 to access your favorite conversations…

这个WPF的企业级MES项目爆火,就是UI争议大!

工业4.0时代&#xff0c;智能智造MES系统大行其道&#xff0c;然而基于.NET跨平台的罕见&#xff01;这里有一套《.NET6WPF企业级MES实战》教程&#xff0c;基于.NET6跨平台开发&#xff0c;实现了MES多核心功能&#xff0c;尤其是开发框架完整&#xff0c;非常适合复用。这里分…