瀏覽代碼

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

wangqiong 2 年之前
父節點
當前提交
bbfb6ea88d

+ 16
- 6
src/main/java/com/oo/onlyoffice/api/impl/OnlyServiceAPIImpl.java 查看文件

81
             return documentEdit(map, collaborativeEditing, clientType);
81
             return documentEdit(map, collaborativeEditing, clientType);
82
         }
82
         }
83
         if (VIEW.equals(mode)) {
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
         return null;
89
         return null;
87
     }
90
     }
88
 
91
 
89
     private Map documentEdit(Map<String, Object> map, boolean collaborativeEditing, String clientType) {
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
         String json = JSON.toJSONString(fileConfigDTO);
94
         String json = JSON.toJSONString(fileConfigDTO);
92
         Map<String, Object> config = JSON.parseObject(json, Map.class);
95
         Map<String, Object> config = JSON.parseObject(json, Map.class);
93
         config.put("type", clientType);
96
         config.put("type", clientType);
94
         return config;
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
         String json = JSON.toJSONString(fileConfigDTO);
110
         String json = JSON.toJSONString(fileConfigDTO);
101
         Map<String, Object> config = JSON.parseObject(json, Map.class);
111
         Map<String, Object> config = JSON.parseObject(json, Map.class);
102
         config.put("type", clientType);
112
         config.put("type", clientType);
103
         return config;
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
         try {
117
         try {
108
             map.put("mode", mode);
118
             map.put("mode", mode);
109
             log.info("开始生成文件信息");
119
             log.info("开始生成文件信息");
111
             FileMetadata tempFileInfo = fileHandler.handlerFile(map, collaborativeEditing);
121
             FileMetadata tempFileInfo = fileHandler.handlerFile(map, collaborativeEditing);
112
             //生成配置文件 TODO: 控制文件权限
122
             //生成配置文件 TODO: 控制文件权限
113
             log.info("开始生成编辑器配置信息");
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
             log.info("生成编辑器配置信息结束");
125
             log.info("生成编辑器配置信息结束");
116
             // TODO: 添加更多详细的自定义信息
126
             // TODO: 添加更多详细的自定义信息
117
             return fileConfigDTO;
127
             return fileConfigDTO;

+ 11
- 6
src/main/java/com/oo/onlyoffice/core/FileConfigFactory.java 查看文件

1
 package com.oo.onlyoffice.core;
1
 package com.oo.onlyoffice.core;
2
 
2
 
3
 import cn.hutool.core.date.DateUtil;
3
 import cn.hutool.core.date.DateUtil;
4
+import com.alibaba.fastjson2.JSONObject;
4
 import com.oo.onlyoffice.config.OnlyProperties;
5
 import com.oo.onlyoffice.config.OnlyProperties;
5
 import com.oo.onlyoffice.dto.DocumentConfig;
6
 import com.oo.onlyoffice.dto.DocumentConfig;
6
 import com.oo.onlyoffice.dto.EditorConfig;
7
 import com.oo.onlyoffice.dto.EditorConfig;
43
      * @return 配置信息
44
      * @return 配置信息
44
      */
45
      */
45
     @Override
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
         Map<String, Object> map = new HashMap<>();
49
         Map<String, Object> map = new HashMap<>();
49
 
50
 
74
         String callBackUrl = onlyProperties.getLocalhostAddress() + onlyProperties.getCallBackUrl();
75
         String callBackUrl = onlyProperties.getLocalhostAddress() + onlyProperties.getCallBackUrl();
75
 
76
 
76
         EditorConfig editorConfig = new EditorConfig(callBackUrl, mode);
77
         EditorConfig editorConfig = new EditorConfig(callBackUrl, mode);
77
-        editorConfig.setFileCustomization(getFileCustomization(mode,clientType));
78
+        editorConfig.setFileCustomization(getFileCustomization(mode, clientType));
78
         editorConfig.setFileUser(user);
79
         editorConfig.setFileUser(user);
79
         editorConfig.setPlugins(getPlugins());
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
         fileConfigDTO.setEditorConfig(editorConfig);
87
         fileConfigDTO.setEditorConfig(editorConfig);
83
         map.put("editorConfig", editorConfig);
88
         map.put("editorConfig", editorConfig);
84
 
89
 
112
         return LoadConfigUtil.getCustomization();
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
         FileCustomization customization = LoadConfigUtil.getCustomization();
121
         FileCustomization customization = LoadConfigUtil.getCustomization();
117
         if (mode != null && !(mode.trim()).equals("") && mode.equals("edit")) {
122
         if (mode != null && !(mode.trim()).equals("") && mode.equals("edit")) {
118
             customization.setAutosave(true);
123
             customization.setAutosave(true);
119
         }
124
         }
120
         customization.setMobileForceView(false);
125
         customization.setMobileForceView(false);
121
-        if(clientType!=null&&clientType!=""&&"mobile".equals(clientType)){
126
+        if (clientType != null && clientType != "" && "mobile".equals(clientType)) {
122
             customization.setMobileForceView(true);
127
             customization.setMobileForceView(true);
123
         }
128
         }
124
         return customization;
129
         return customization;

+ 17
- 2
src/main/java/com/oo/onlyoffice/core/handler/FileHandlerImpl.java 查看文件

77
                     cache.set(user.getId() + "_" + id, key);
77
                     cache.set(user.getId() + "_" + id, key);
78
                     cache.set("getID_" + key, id);
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