From 81737962f32a82abcf1d9c201eebcb88cc87d9fa Mon Sep 17 00:00:00 2001
From: wanggeng <450292408@qq.com>
Date: Mon, 25 Jul 2022 23:30:24 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E4=BE=9D=E8=B5=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
module-form/pom.xml | 6 +
.../controller/api/design/FormController.java | 2 +
.../onlyoffice/OnlyOfficeAppController.java | 52 +++++
.../onlyoffice/OnlyOfficeRouteController.java | 44 ++++
.../dtos/onlyoffice/config/DocumentDTO.java | 57 ++++++
.../dtos/onlyoffice/config/EditConfigDTO.java | 78 +++++++
.../onlyoffice/config/PermissionsDTO.java | 129 ++++++++++++
.../pojo/vos/onlyoffice/OnlyOfficeSaveVO.java | 190 ++++++++++++++++++
.../onlyoffice/IOnlyOfficeService.java | 39 ++++
.../impl/OnlyOfficeServiceImpl.java | 166 +++++++++++++++
.../resources/templates/only-office/edit.html | 21 ++
11 files changed, 784 insertions(+)
create mode 100644 module-form/src/main/java/ink/wgink/module/form/controller/app/api/onlyoffice/OnlyOfficeAppController.java
create mode 100644 module-form/src/main/java/ink/wgink/module/form/controller/route/onlyoffice/OnlyOfficeRouteController.java
create mode 100644 module-form/src/main/java/ink/wgink/module/form/pojo/dtos/onlyoffice/config/DocumentDTO.java
create mode 100644 module-form/src/main/java/ink/wgink/module/form/pojo/dtos/onlyoffice/config/EditConfigDTO.java
create mode 100644 module-form/src/main/java/ink/wgink/module/form/pojo/dtos/onlyoffice/config/PermissionsDTO.java
create mode 100644 module-form/src/main/java/ink/wgink/module/form/pojo/vos/onlyoffice/OnlyOfficeSaveVO.java
create mode 100644 module-form/src/main/java/ink/wgink/module/form/service/onlyoffice/IOnlyOfficeService.java
create mode 100644 module-form/src/main/java/ink/wgink/module/form/service/onlyoffice/impl/OnlyOfficeServiceImpl.java
create mode 100644 module-form/src/main/resources/templates/only-office/edit.html
diff --git a/module-form/pom.xml b/module-form/pom.xml
index d287ec49..faefec06 100644
--- a/module-form/pom.xml
+++ b/module-form/pom.xml
@@ -17,6 +17,12 @@
common
1.0-SNAPSHOT
+
+ ink.wgink
+ module-file
+ 1.0-SNAPSHOT
+ provided
+
\ No newline at end of file
diff --git a/module-form/src/main/java/ink/wgink/module/form/controller/api/design/FormController.java b/module-form/src/main/java/ink/wgink/module/form/controller/api/design/FormController.java
index 4f366cee..ba0a007d 100644
--- a/module-form/src/main/java/ink/wgink/module/form/controller/api/design/FormController.java
+++ b/module-form/src/main/java/ink/wgink/module/form/controller/api/design/FormController.java
@@ -344,4 +344,6 @@ public class FormController extends DefaultBaseController {
return formService.listPageHistoryByFormId(formId, page);
}
+
+
}
diff --git a/module-form/src/main/java/ink/wgink/module/form/controller/app/api/onlyoffice/OnlyOfficeAppController.java b/module-form/src/main/java/ink/wgink/module/form/controller/app/api/onlyoffice/OnlyOfficeAppController.java
new file mode 100644
index 00000000..227c6360
--- /dev/null
+++ b/module-form/src/main/java/ink/wgink/module/form/controller/app/api/onlyoffice/OnlyOfficeAppController.java
@@ -0,0 +1,52 @@
+package ink.wgink.module.form.controller.app.api.onlyoffice;
+
+import ink.wgink.annotation.CheckRequestBodyAnnotation;
+import ink.wgink.common.base.DefaultBaseController;
+import ink.wgink.interfaces.consts.ISystemConstant;
+import ink.wgink.module.form.pojo.vos.onlyoffice.OnlyOfficeSaveVO;
+import ink.wgink.module.form.service.onlyoffice.IOnlyOfficeService;
+import ink.wgink.pojo.result.ErrorResult;
+import io.swagger.annotations.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @ClassName: OnlyOfficeController
+ * @Description: OnlyOffice
+ * @Author: CodeFactory
+ * @Date: 2022-06-24 15:06:48
+ * @Version: 3.0
+ **/
+@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "OnlyOffice")
+@RestController
+@RequestMapping(ISystemConstant.APP_PREFIX + "/only-office")
+public class OnlyOfficeAppController extends DefaultBaseController {
+
+ @Autowired
+ private IOnlyOfficeService onlyOfficeService;
+
+ @ApiOperation(value = "保存文件", notes = "保存文件接口")
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "fileId", value = "文件ID", paramType = "path")
+ })
+ @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
+ @PostMapping("save-release/code/{formCode}/version/{formVersion}/uid/{uid}/file-id/{fileId}")
+ @CheckRequestBodyAnnotation
+ public Map save(@PathVariable("formCode") String formCode,
+ @PathVariable("formVersion") Integer formVersion,
+ @PathVariable("uid") String uid,
+ @PathVariable("fileId") String fileId,
+ @RequestBody OnlyOfficeSaveVO onlyOfficeSaveVO) {
+ if(onlyOfficeSaveVO.getStatus() == 2) {
+ onlyOfficeService.save(formCode, formVersion, uid, fileId, onlyOfficeSaveVO);
+ }
+ Map result = new HashMap<>();
+ result.put("error", 0);
+ return result;
+ }
+
+
+}
\ No newline at end of file
diff --git a/module-form/src/main/java/ink/wgink/module/form/controller/route/onlyoffice/OnlyOfficeRouteController.java b/module-form/src/main/java/ink/wgink/module/form/controller/route/onlyoffice/OnlyOfficeRouteController.java
new file mode 100644
index 00000000..fa8f5349
--- /dev/null
+++ b/module-form/src/main/java/ink/wgink/module/form/controller/route/onlyoffice/OnlyOfficeRouteController.java
@@ -0,0 +1,44 @@
+package ink.wgink.module.form.controller.route.onlyoffice;
+
+import ink.wgink.interfaces.consts.ISystemConstant;
+import ink.wgink.module.form.service.onlyoffice.IOnlyOfficeService;
+import ink.wgink.properties.onlyoffice.OnlyOfficeProperties;
+import io.swagger.annotations.Api;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.servlet.ModelAndView;
+
+/**
+ * @ClassName: OnlyOfficeRouteController
+ * @Description: OnlyOffice
+ * @Author: wanggeng
+ * @Date: 2022/7/24 14:45
+ * @Version: 1.0
+ */
+@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "OnlyOffice")
+@Controller
+@RequestMapping(ISystemConstant.ROUTE_PREFIX + "/only-office")
+public class OnlyOfficeRouteController {
+
+ @Autowired
+ private OnlyOfficeProperties onlyOfficeProperties;
+ @Autowired
+ private IOnlyOfficeService onlyOfficeService;
+
+ @GetMapping("edit/code/{formCode}/version/{formVersion}/uid/{uid}/file-id/{fileId}")
+ public ModelAndView edit(@PathVariable("formCode") String formCode,
+ @PathVariable("formVersion") Integer formVersion,
+ @PathVariable("uid") String uid,
+ @PathVariable("fileId") String fileId) {
+ ModelAndView modelAndView = new ModelAndView("only-office/edit");
+ modelAndView.addObject("fileId", fileId);
+ modelAndView.addObject("server", onlyOfficeProperties.getServer());
+ modelAndView.addObject("config", onlyOfficeService.getConfig(formCode, formVersion, uid, fileId));
+ return modelAndView;
+ }
+
+
+}
diff --git a/module-form/src/main/java/ink/wgink/module/form/pojo/dtos/onlyoffice/config/DocumentDTO.java b/module-form/src/main/java/ink/wgink/module/form/pojo/dtos/onlyoffice/config/DocumentDTO.java
new file mode 100644
index 00000000..be2c6670
--- /dev/null
+++ b/module-form/src/main/java/ink/wgink/module/form/pojo/dtos/onlyoffice/config/DocumentDTO.java
@@ -0,0 +1,57 @@
+package ink.wgink.module.form.pojo.dtos.onlyoffice.config;
+
+/**
+ * @ClassName: DocumentDTO
+ * @Description: 配置
+ * @Author: wanggeng
+ * @Date: 2022/7/24 16:26
+ * @Version: 1.0
+ */
+public class DocumentDTO {
+
+ private String fileType;
+ private String key;
+ private String title;
+ private String url;
+ private PermissionsDTO permissionsDTO;
+
+ public String getFileType() {
+ return fileType == null ? "" : fileType.trim();
+ }
+
+ public void setFileType(String fileType) {
+ this.fileType = fileType;
+ }
+
+ public String getKey() {
+ return key == null ? "" : key.trim();
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getTitle() {
+ return title == null ? "" : title.trim();
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getUrl() {
+ return url == null ? "" : url.trim();
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public PermissionsDTO getPermissionsDTO() {
+ return permissionsDTO;
+ }
+
+ public void setPermissionsDTO(PermissionsDTO permissionsDTO) {
+ this.permissionsDTO = permissionsDTO;
+ }
+}
diff --git a/module-form/src/main/java/ink/wgink/module/form/pojo/dtos/onlyoffice/config/EditConfigDTO.java b/module-form/src/main/java/ink/wgink/module/form/pojo/dtos/onlyoffice/config/EditConfigDTO.java
new file mode 100644
index 00000000..67e2ee38
--- /dev/null
+++ b/module-form/src/main/java/ink/wgink/module/form/pojo/dtos/onlyoffice/config/EditConfigDTO.java
@@ -0,0 +1,78 @@
+package ink.wgink.module.form.pojo.dtos.onlyoffice.config;
+
+/**
+ * @ClassName: EditConfigDTO
+ * @Description: 编辑配置
+ * @Author: wanggeng
+ * @Date: 2022/7/24 20:01
+ * @Version: 1.0
+ */
+public class EditConfigDTO {
+
+ private String callbackUrl;
+ private String lang;
+ private String location;
+ private String region;
+ private User user;
+
+ public String getCallbackUrl() {
+ return callbackUrl == null ? "" : callbackUrl.trim();
+ }
+
+ public void setCallbackUrl(String callbackUrl) {
+ this.callbackUrl = callbackUrl;
+ }
+
+ public String getLang() {
+ return lang == null ? "" : lang.trim();
+ }
+
+ public void setLang(String lang) {
+ this.lang = lang;
+ }
+
+ public String getLocation() {
+ return location == null ? "" : location.trim();
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public String getRegion() {
+ return region == null ? "" : region.trim();
+ }
+
+ public void setRegion(String region) {
+ this.region = region;
+ }
+
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(User user) {
+ this.user = user;
+ }
+
+ public static class User {
+ private String id;
+ private String name;
+
+ public String getId() {
+ return id == null ? "" : id.trim();
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name == null ? "" : name.trim();
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+ }
+}
diff --git a/module-form/src/main/java/ink/wgink/module/form/pojo/dtos/onlyoffice/config/PermissionsDTO.java b/module-form/src/main/java/ink/wgink/module/form/pojo/dtos/onlyoffice/config/PermissionsDTO.java
new file mode 100644
index 00000000..324eb4e5
--- /dev/null
+++ b/module-form/src/main/java/ink/wgink/module/form/pojo/dtos/onlyoffice/config/PermissionsDTO.java
@@ -0,0 +1,129 @@
+package ink.wgink.module.form.pojo.dtos.onlyoffice.config;
+
+/**
+ * @ClassName: permissions
+ * @Description: 权限
+ * @Author: wanggeng
+ * @Date: 2022/7/24 16:29
+ * @Version: 1.0
+ */
+public class PermissionsDTO {
+
+ private Boolean chat;
+ private Boolean comment;
+ private Boolean copy;
+ private Boolean deleteCommentAuthorOnly;
+ private Boolean download;
+ private Boolean edit;
+ private Boolean editCommentAuthorOnly;
+ private Boolean fillForms;
+ private Boolean modifyContentControl;
+ private Boolean modifyFilter;
+ private Boolean print;
+ private Boolean protect;
+ private Boolean review;
+
+ public Boolean getChat() {
+ return chat;
+ }
+
+ public void setChat(Boolean chat) {
+ this.chat = chat;
+ }
+
+ public Boolean getComment() {
+ return comment;
+ }
+
+ public void setComment(Boolean comment) {
+ this.comment = comment;
+ }
+
+ public Boolean getCopy() {
+ return copy;
+ }
+
+ public void setCopy(Boolean copy) {
+ this.copy = copy;
+ }
+
+ public Boolean getDeleteCommentAuthorOnly() {
+ return deleteCommentAuthorOnly;
+ }
+
+ public void setDeleteCommentAuthorOnly(Boolean deleteCommentAuthorOnly) {
+ this.deleteCommentAuthorOnly = deleteCommentAuthorOnly;
+ }
+
+ public Boolean getDownload() {
+ return download;
+ }
+
+ public void setDownload(Boolean download) {
+ this.download = download;
+ }
+
+ public Boolean getEdit() {
+ return edit;
+ }
+
+ public void setEdit(Boolean edit) {
+ this.edit = edit;
+ }
+
+ public Boolean getEditCommentAuthorOnly() {
+ return editCommentAuthorOnly;
+ }
+
+ public void setEditCommentAuthorOnly(Boolean editCommentAuthorOnly) {
+ this.editCommentAuthorOnly = editCommentAuthorOnly;
+ }
+
+ public Boolean getFillForms() {
+ return fillForms;
+ }
+
+ public void setFillForms(Boolean fillForms) {
+ this.fillForms = fillForms;
+ }
+
+ public Boolean getModifyContentControl() {
+ return modifyContentControl;
+ }
+
+ public void setModifyContentControl(Boolean modifyContentControl) {
+ this.modifyContentControl = modifyContentControl;
+ }
+
+ public Boolean getModifyFilter() {
+ return modifyFilter;
+ }
+
+ public void setModifyFilter(Boolean modifyFilter) {
+ this.modifyFilter = modifyFilter;
+ }
+
+ public Boolean getPrint() {
+ return print;
+ }
+
+ public void setPrint(Boolean print) {
+ this.print = print;
+ }
+
+ public Boolean getProtect() {
+ return protect;
+ }
+
+ public void setProtect(Boolean protect) {
+ this.protect = protect;
+ }
+
+ public Boolean getReview() {
+ return review;
+ }
+
+ public void setReview(Boolean review) {
+ this.review = review;
+ }
+}
diff --git a/module-form/src/main/java/ink/wgink/module/form/pojo/vos/onlyoffice/OnlyOfficeSaveVO.java b/module-form/src/main/java/ink/wgink/module/form/pojo/vos/onlyoffice/OnlyOfficeSaveVO.java
new file mode 100644
index 00000000..850677c0
--- /dev/null
+++ b/module-form/src/main/java/ink/wgink/module/form/pojo/vos/onlyoffice/OnlyOfficeSaveVO.java
@@ -0,0 +1,190 @@
+package ink.wgink.module.form.pojo.vos.onlyoffice;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @ClassName: OnlyOfficeSaveVO
+ * @Description: 保存
+ * @Author: wanggeng
+ * @Date: 2022/7/24 20:20
+ * @Version: 1.0
+ */
+public class OnlyOfficeSaveVO {
+
+ private String key;
+ private Integer status;
+ private String url;
+ private String changeUrl;
+ private List users;
+ private String lastsave;
+ private Boolean notmodified;
+ private String filetype;
+ private History history;
+ private List actions;
+
+ public String getKey() {
+ return key == null ? "" : key.trim();
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public Integer getStatus() {
+ return status == null ? 0 : status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+
+ public String getUrl() {
+ return url == null ? "" : url.trim();
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getChangeUrl() {
+ return changeUrl == null ? "" : changeUrl.trim();
+ }
+
+ public void setChangeUrl(String changeUrl) {
+ this.changeUrl = changeUrl;
+ }
+
+ public List getUsers() {
+ return users == null ? new ArrayList() : users;
+ }
+
+ public void setUsers(List users) {
+ this.users = users;
+ }
+
+ public String getLastsave() {
+ return lastsave == null ? "" : lastsave.trim();
+ }
+
+ public void setLastsave(String lastsave) {
+ this.lastsave = lastsave;
+ }
+
+ public Boolean getNotmodified() {
+ return notmodified;
+ }
+
+ public void setNotmodified(Boolean notmodified) {
+ this.notmodified = notmodified;
+ }
+
+ public String getFiletype() {
+ return filetype == null ? "" : filetype.trim();
+ }
+
+ public void setFiletype(String filetype) {
+ this.filetype = filetype;
+ }
+
+ public History getHistory() {
+ return history;
+ }
+
+ public void setHistory(History history) {
+ this.history = history;
+ }
+
+ public List getActions() {
+ return actions == null ? new ArrayList() : actions;
+ }
+
+ public void setActions(List actions) {
+ this.actions = actions;
+ }
+
+ public static class History {
+ private String serverVersion;
+ private List changes;
+
+ public String getServerVersion() {
+ return serverVersion == null ? "" : serverVersion.trim();
+ }
+
+ public void setServerVersion(String serverVersion) {
+ this.serverVersion = serverVersion;
+ }
+
+ public List getChanges() {
+ return changes == null ? new ArrayList() : changes;
+ }
+
+ public void setChanges(List changes) {
+ this.changes = changes;
+ }
+
+ public static class Change {
+ private String created;
+ private User user;
+
+ public String getCreated() {
+ return created == null ? "" : created.trim();
+ }
+
+ public void setCreated(String created) {
+ this.created = created;
+ }
+
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(User user) {
+ this.user = user;
+ }
+
+ public static class User {
+ private String id;
+ private String name;
+
+ public String getId() {
+ return id == null ? "" : id.trim();
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name == null ? "" : name.trim();
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+ }
+ }
+ }
+
+ public static class Action {
+ private Integer type;
+ private String userid;
+
+ public Integer getType() {
+ return type == null ? 0 : type;
+ }
+
+ public void setType(Integer type) {
+ this.type = type;
+ }
+
+ public String getUserid() {
+ return userid == null ? "" : userid.trim();
+ }
+
+ public void setUserid(String userid) {
+ this.userid = userid;
+ }
+ }
+
+}
diff --git a/module-form/src/main/java/ink/wgink/module/form/service/onlyoffice/IOnlyOfficeService.java b/module-form/src/main/java/ink/wgink/module/form/service/onlyoffice/IOnlyOfficeService.java
new file mode 100644
index 00000000..3e4b685d
--- /dev/null
+++ b/module-form/src/main/java/ink/wgink/module/form/service/onlyoffice/IOnlyOfficeService.java
@@ -0,0 +1,39 @@
+package ink.wgink.module.form.service.onlyoffice;
+
+import com.alibaba.fastjson2.JSONObject;
+import ink.wgink.module.form.pojo.vos.onlyoffice.OnlyOfficeSaveVO;
+
+/**
+ * @ClassName: IOnlyOfficeService
+ * @Description: OnlyOffice
+ * @Author: wanggeng
+ * @Date: 2022/7/24 15:32
+ * @Version: 1.0
+ */
+public interface IOnlyOfficeService {
+
+ /**
+ * 保存
+ *
+ * @param formCode 表单编码
+ * @param formVersion 表单版本
+ * @param uid 上报id
+ * @param fileId 文件ID
+ * @param onlyOfficeSaveVO 文档内容
+ */
+ void save(String formCode, Integer formVersion, String uid, String fileId, OnlyOfficeSaveVO onlyOfficeSaveVO);
+
+
+ /**
+ * 获取配置
+ *
+ * @param formCode
+ * @param formVersion
+ * @param uid
+ * @param fileId
+ * @return
+ */
+ JSONObject getConfig(String formCode, Integer formVersion, String uid, String fileId);
+
+
+}
diff --git a/module-form/src/main/java/ink/wgink/module/form/service/onlyoffice/impl/OnlyOfficeServiceImpl.java b/module-form/src/main/java/ink/wgink/module/form/service/onlyoffice/impl/OnlyOfficeServiceImpl.java
new file mode 100644
index 00000000..6b861360
--- /dev/null
+++ b/module-form/src/main/java/ink/wgink/module/form/service/onlyoffice/impl/OnlyOfficeServiceImpl.java
@@ -0,0 +1,166 @@
+package ink.wgink.module.form.service.onlyoffice.impl;
+
+import com.alibaba.fastjson2.JSONObject;
+import ink.wgink.common.base.DefaultBaseService;
+import ink.wgink.exceptions.ParamsException;
+import ink.wgink.exceptions.SearchException;
+import ink.wgink.module.file.enums.UploadTypeEnum;
+import ink.wgink.module.file.pojo.dtos.v2.FileUploadSuccessDTO;
+import ink.wgink.module.file.pojo.vos.v2.FileUpdateVO;
+import ink.wgink.module.file.service.v2.IFileService;
+import ink.wgink.module.form.pojo.dtos.onlyoffice.config.DocumentDTO;
+import ink.wgink.module.form.pojo.dtos.onlyoffice.config.EditConfigDTO;
+import ink.wgink.module.form.pojo.dtos.onlyoffice.config.PermissionsDTO;
+import ink.wgink.module.form.pojo.vos.onlyoffice.OnlyOfficeSaveVO;
+import ink.wgink.module.form.service.onlyoffice.IOnlyOfficeService;
+import ink.wgink.pojo.bos.UserInfoBO;
+import ink.wgink.pojo.pos.FilePO;
+import ink.wgink.properties.ServerProperties;
+import ink.wgink.util.UUIDUtil;
+import ink.wgink.util.string.WStringUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+/**
+ * @ClassName: OnlyOfficeServiceImpl
+ * @Description: onlyoffice
+ * @Author: wanggeng
+ * @Date: 2022/7/24 15:33
+ * @Version: 1.0
+ */
+@Service
+public class OnlyOfficeServiceImpl extends DefaultBaseService implements IOnlyOfficeService {
+
+ public static final String[] WORD_FILE_TYPE_ARRAY = new String[]{
+ "doc", "docx", "docm", "docxf", "dot", "dotm", "dotx", "epub", "fodt", "fb2", "htm", "html", "mht", "odt",
+ "oform", "ott", "oxps", "pdf", "rtf", "txt", "djvu", "xml", "xps"};
+ public static final String[] CELL_FILE_TYPE_ARRAY = new String[]{
+ "csv", "fods", "ods", "ots", "xls", "xlsb", "xlsm", "xlsx", "xlt", "xltm", "xltx"};
+ public static final String[] SLIDE_FILE_TYPE_ARRAY = new String[]{
+ "fodp", "odp", "otp", "pot", "potm", "potx", "pps", "ppsm", "ppsx", "ppt", "pptm", "pptx"};
+
+ @Autowired
+ private ServerProperties serverProperties;
+ @Autowired
+ private IFileService fileV2Service;
+
+
+ @Override
+ public void save(String formCode, Integer formVersion, String uid, String fileId, OnlyOfficeSaveVO onlyOfficeSaveVO) {
+ FilePO filePO = fileV2Service.getPO(fileId);
+ if (filePO == null) {
+ throw new SearchException("文件不存在");
+ }
+ try {
+ URL url = new URL(onlyOfficeSaveVO.getUrl());
+ HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
+ InputStream inputStream = httpURLConnection.getInputStream();
+ FileUploadSuccessDTO uploadSuccessDTO = fileV2Service.uploadSingleByUserId(onlyOfficeSaveVO.getUsers().get(0), inputStream, UploadTypeEnum.FILE, filePO.getFileName());
+ // 调换文件信息,保留原来的ID不变
+ String newFileId = uploadSuccessDTO.getFileId();
+ FilePO newFilePO = fileV2Service.getPO(newFileId);
+
+ // 新文件信息 -> 旧文件
+ FileUpdateVO fileUpdateVO = new FileUpdateVO();
+ BeanUtils.copyProperties(newFilePO, fileUpdateVO);
+ fileUpdateVO.setUploadPath(newFilePO.getFilePath());
+ fileUpdateVO.setFileId(filePO.getFileId());
+ fileV2Service.update(fileUpdateVO);
+
+ // 旧的文件信息 -> 新文件
+ BeanUtils.copyProperties(filePO, fileUpdateVO);
+ fileUpdateVO.setUploadPath(filePO.getFilePath());
+ fileUpdateVO.setFileId(newFilePO.getFileId());
+ fileV2Service.update(fileUpdateVO);
+ } catch (RuntimeException | IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public JSONObject getConfig(String formCode, Integer formVersion, String uid, String fileId) {
+ FilePO filePO = fileV2Service.getPO(fileId);
+ if (filePO == null) {
+ throw new SearchException("文件不存在");
+ }
+ DocumentDTO documentDTO = new DocumentDTO();
+ documentDTO.setFileType(filePO.getFileType());
+ documentDTO.setTitle(filePO.getFileName());
+ documentDTO.setKey(WStringUtil.randomSubStr(UUIDUtil.get32UUID(), 20));
+ documentDTO.setUrl(serverProperties.getUrl() + "/route/file/download/false/" + fileId);
+ // 权限
+ PermissionsDTO permissionsDTO = new PermissionsDTO();
+ permissionsDTO.setChat(false);
+ permissionsDTO.setComment(true);
+ permissionsDTO.setCopy(true);
+ permissionsDTO.setDeleteCommentAuthorOnly(false);
+ permissionsDTO.setDownload(true);
+ permissionsDTO.setEdit(true);
+ permissionsDTO.setEditCommentAuthorOnly(false);
+ permissionsDTO.setFillForms(true);
+ permissionsDTO.setModifyContentControl(true);
+ permissionsDTO.setModifyFilter(true);
+ permissionsDTO.setPrint(true);
+ permissionsDTO.setProtect(true);
+ permissionsDTO.setReview(true);
+ documentDTO.setPermissionsDTO(permissionsDTO);
+ // 编辑配置
+ EditConfigDTO editConfigDTO = new EditConfigDTO();
+ editConfigDTO.setCallbackUrl(String.format("%s/app/only-office/save-release/code/%s/version/%d/uid/%s/file-id/%s",
+ serverProperties.getUrl(),
+ formCode,
+ formVersion,
+ uid,
+ fileId));
+ // 菜单语言
+ editConfigDTO.setLang("zh");
+ // 文档语言
+ editConfigDTO.setRegion("zh-CN");
+
+ EditConfigDTO.User user = new EditConfigDTO.User();
+ UserInfoBO currentUser = securityComponent.getCurrentUser();
+ user.setId(currentUser.getUserId());
+ user.setName(currentUser.getUserName());
+ editConfigDTO.setUser(user);
+
+ JSONObject config = new JSONObject();
+ config.put("document", documentDTO);
+ config.put("documentType", getDocumentType(filePO.getFileType()));
+ config.put("editorConfig", editConfigDTO);
+ return config;
+ }
+
+ /**
+ * 获取文件类型
+ *
+ * @param fileType
+ * @return
+ */
+ private String getDocumentType(String fileType) {
+ // 打开excel时会有问题,目前只支持word
+ for (String wordFileType : WORD_FILE_TYPE_ARRAY) {
+ if (StringUtils.equals(fileType, wordFileType)) {
+ return "word";
+ }
+ }
+ for (String cellFileType : CELL_FILE_TYPE_ARRAY) {
+ if (StringUtils.equals(fileType, cellFileType)) {
+ return "cell";
+ }
+ }
+ for (String slideFileType : SLIDE_FILE_TYPE_ARRAY) {
+ if (StringUtils.equals(fileType, slideFileType)) {
+ return "slide";
+ }
+ }
+ throw new ParamsException("文件类型不支持");
+ }
+
+}
diff --git a/module-form/src/main/resources/templates/only-office/edit.html b/module-form/src/main/resources/templates/only-office/edit.html
new file mode 100644
index 00000000..bbf4ce89
--- /dev/null
+++ b/module-form/src/main/resources/templates/only-office/edit.html
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file