Просмотр исходного кода

优化协同编辑查看功能,只读用户可以查看在线编辑用户编辑的内容

wangqiong 2 лет назад
Родитель
Сommit
bbfb6ea88d

+ 16
- 6
src/main/java/com/oo/onlyoffice/api/impl/OnlyServiceAPIImpl.java Просмотреть файл

@@ -81,29 +81,39 @@ public class OnlyServiceAPIImpl implements OnlyServiceAPI {
81 81
             return documentEdit(map, collaborativeEditing, clientType);
82 82
         }
83 83
         if (VIEW.equals(mode)) {
84
-            return documentView(map, clientType);
84
+            return documentView(map, collaborativeEditing, clientType);
85 85
         }
86
+//        if (VIEW.equals(mode)) {
87
+//            return documentView(map, clientType);
88
+//        }
86 89
         return null;
87 90
     }
88 91
 
89 92
     private Map documentEdit(Map<String, Object> map, boolean collaborativeEditing, String clientType) {
90
-        FileConfig fileConfigDTO = openEditConfig(map, "edit", collaborativeEditing,clientType);
93
+        FileConfig fileConfigDTO = openEditConfig(map, "edit", collaborativeEditing, clientType);
91 94
         String json = JSON.toJSONString(fileConfigDTO);
92 95
         Map<String, Object> config = JSON.parseObject(json, Map.class);
93 96
         config.put("type", clientType);
94 97
         return config;
95 98
     }
96 99
 
100
+    private Map documentView(Map<String, Object> map, boolean collaborativeEditing, String clientType) {
101
+        FileConfig fileConfigDTO = openEditConfig(map, "view", collaborativeEditing, clientType);
102
+        String json = JSON.toJSONString(fileConfigDTO);
103
+        Map<String, Object> config = JSON.parseObject(json, Map.class);
104
+        config.put("type", clientType);
105
+        return config;
106
+    }
97 107
 
98
-    private Map documentView(Map<String, Object> map,String clientType) {
99
-        FileConfig fileConfigDTO = openEditConfig(map, "view", false,clientType);
108
+    private Map documentView(Map<String, Object> map, String clientType) {
109
+        FileConfig fileConfigDTO = openEditConfig(map, "view", false, clientType);
100 110
         String json = JSON.toJSONString(fileConfigDTO);
101 111
         Map<String, Object> config = JSON.parseObject(json, Map.class);
102 112
         config.put("type", clientType);
103 113
         return config;
104 114
     }
105 115
 
106
-    private FileConfig openEditConfig(Map<String, Object> map, String mode, boolean collaborativeEditing,String clientType) {
116
+    private FileConfig openEditConfig(Map<String, Object> map, String mode, boolean collaborativeEditing, String clientType) {
107 117
         try {
108 118
             map.put("mode", mode);
109 119
             log.info("开始生成文件信息");
@@ -111,7 +121,7 @@ public class OnlyServiceAPIImpl implements OnlyServiceAPI {
111 121
             FileMetadata tempFileInfo = fileHandler.handlerFile(map, collaborativeEditing);
112 122
             //生成配置文件 TODO: 控制文件权限
113 123
             log.info("开始生成编辑器配置信息");
114
-            FileConfig fileConfigDTO = onlyOfficeConfigFactory.buildInitConfig(tempFileInfo.getUrl(), mode, tempFileInfo.getKey(), tempFileInfo.getOldName(),clientType);
124
+            FileConfig fileConfigDTO = onlyOfficeConfigFactory.buildInitConfig(tempFileInfo.getUrl(), mode, tempFileInfo.getKey(), tempFileInfo.getOldName(), clientType);
115 125
             log.info("生成编辑器配置信息结束");
116 126
             // TODO: 添加更多详细的自定义信息
117 127
             return fileConfigDTO;

+ 11
- 6
src/main/java/com/oo/onlyoffice/core/FileConfigFactory.java Просмотреть файл

@@ -1,6 +1,7 @@
1 1
 package com.oo.onlyoffice.core;
2 2
 
3 3
 import cn.hutool.core.date.DateUtil;
4
+import com.alibaba.fastjson2.JSONObject;
4 5
 import com.oo.onlyoffice.config.OnlyProperties;
5 6
 import com.oo.onlyoffice.dto.DocumentConfig;
6 7
 import com.oo.onlyoffice.dto.EditorConfig;
@@ -43,7 +44,7 @@ public class FileConfigFactory implements OnlyOfficeConfigFactory {
43 44
      * @return 配置信息
44 45
      */
45 46
     @Override
46
-    public FileConfig buildInitConfig(String fileUrl, String mode, String key, String fileName,String clientType) {
47
+    public FileConfig buildInitConfig(String fileUrl, String mode, String key, String fileName, String clientType) {
47 48
 
48 49
         Map<String, Object> map = new HashMap<>();
49 50
 
@@ -74,11 +75,15 @@ public class FileConfigFactory implements OnlyOfficeConfigFactory {
74 75
         String callBackUrl = onlyProperties.getLocalhostAddress() + onlyProperties.getCallBackUrl();
75 76
 
76 77
         EditorConfig editorConfig = new EditorConfig(callBackUrl, mode);
77
-        editorConfig.setFileCustomization(getFileCustomization(mode,clientType));
78
+        editorConfig.setFileCustomization(getFileCustomization(mode, clientType));
78 79
         editorConfig.setFileUser(user);
79 80
         editorConfig.setPlugins(getPlugins());
80
-
81
-
81
+        //共同编辑"coEditing"配置:
82
+        //        "coEditing": {           "mode": "fast","change": true}
83
+        JSONObject coEditing = new JSONObject();
84
+        coEditing.put("mode", "fast");
85
+        coEditing.put("change", "true");
86
+        editorConfig.setCoEditing(coEditing);
82 87
         fileConfigDTO.setEditorConfig(editorConfig);
83 88
         map.put("editorConfig", editorConfig);
84 89
 
@@ -112,13 +117,13 @@ public class FileConfigFactory implements OnlyOfficeConfigFactory {
112 117
         return LoadConfigUtil.getCustomization();
113 118
     }
114 119
 
115
-    private FileCustomization getFileCustomization(String mode,String clientType) {
120
+    private FileCustomization getFileCustomization(String mode, String clientType) {
116 121
         FileCustomization customization = LoadConfigUtil.getCustomization();
117 122
         if (mode != null && !(mode.trim()).equals("") && mode.equals("edit")) {
118 123
             customization.setAutosave(true);
119 124
         }
120 125
         customization.setMobileForceView(false);
121
-        if(clientType!=null&&clientType!=""&&"mobile".equals(clientType)){
126
+        if (clientType != null && clientType != "" && "mobile".equals(clientType)) {
122 127
             customization.setMobileForceView(true);
123 128
         }
124 129
         return customization;

+ 17
- 2
src/main/java/com/oo/onlyoffice/core/handler/FileHandlerImpl.java Просмотреть файл

@@ -77,8 +77,23 @@ public class FileHandlerImpl implements FileHandler {
77 77
                     cache.set(user.getId() + "_" + id, key);
78 78
                     cache.set("getID_" + key, id);
79 79
                 }
80
-            } else {//查看模式
81
-                key = id;
80
+            } else {
81
+                //查看模式
82
+                if (collaborativeEditing) {
83
+                    if (cache.get("collaborativeEditing_" + id) != null) {
84
+                        key = (String) cache.get("collaborativeEditing_" + id);
85
+                    } else {
86
+                        key = IdUtil.simpleUUID();
87
+                        cache.set("collaborativeEditing_" + id, key);
88
+                        cache.set("getID_" + key, id);
89
+                    }
90
+                } else {
91
+                    key = IdUtil.simpleUUID();
92
+                    FileUser user = SecurityUtils.getUserSession();
93
+                    cache.set(user.getId() + "_" + id, key);
94
+                    cache.set("getID_" + key, id);
95
+                }
96
+              //  key = id;
82 97
             }
83 98
 
84 99