新版onlyoffice

This commit is contained in:
wangqiong
2024-03-14 17:59:11 +08:00
parent 7c9681b236
commit 1ae3b82282
78 changed files with 475 additions and 3079 deletions
@@ -1,26 +1,24 @@
package com.oo.demo.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.oo.demo.entity.OnFile;
import com.oo.demo.entity.WebsocketResult;
import com.oo.onlyoffice.api.OnlyServiceAPI;
import com.oo.onlyoffice.dto.edit.FileUser;
import com.oo.onlyoffice.tools.SecurityUtils;
import com.oo.demo.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
//import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @BelongsProject: onlyoffice-demo
* @BelongsPackage: com.oo.demo.service
* @Author: TongHui
* @CreateTime: 2023-08-02 09:57
* @Description: TODO
* @Version: 1.0
@@ -41,51 +39,48 @@ public class FileService {
* @param jsonObject
*/
@Transactional(rollbackFor = Exception.class)
public Object documentSave(JSONObject jsonObject) {
JSONObject result = new JSONObject();
public WebsocketResult documentSave(JSONObject jsonObject) {
WebsocketResult result = new WebsocketResult();
String key = "";
try {
int status = jsonObject.getIntValue("status");
log.info("status[{}]", status);
if (6 == status) {
log.info("开始保存文件");
log.info("dayin:" + JSON.toJSONString(jsonObject));
JSONArray jsonArray = jsonObject.getJSONObject("history").getJSONArray("changes");
log.info("历史版本:" + JSON.toJSONString(jsonArray));
JSONObject object = jsonArray.getJSONObject(0);
String userId = object.getJSONObject("user").getString("id");
FileUser fileUser = new FileUser();
fileUser.setId(userId);
SecurityUtils.setUserSession(fileUser);
log.info("fileuser:" + JSON.toJSONString(fileUser));
key = jsonObject.getString("key");
log.info("key:" + JSON.toJSONString(key));
//文件id
String id = onlyServiceAPI.getFileId(key);
String fileId = onlyServiceAPI.getFileId(key);
log.info("fileId:" + JSON.toJSONString(fileId));
//判断是否是最后一人进行保存
int users = onlyServiceAPI.getUserNum(key);
if (users > 1) {
return null;
}
// if (users > 1) {
// return null;
// }
//历史版本最大个数 获取当前文件的历史版本数量
Integer histNum = onlyServiceAPI.getHistNum();
log.info("历史版本最大个数" + histNum);
/**
* 如果有需要保存历史记录 可以进行相关操作
*/
if (null != histNum) {
}
//处理文件的保存
onlyServiceAPI.handlerStatus(jsonObject);
OnFile file = onlyServiceAPI.handlerStatus(jsonObject);
result = WebsocketResult.builder().onFile(file).userId(SecurityUtils.getUserSession().getId()).build();
log.info("处理文件的保存:" + JSON.toJSONString(jsonObject));
log.info("保存文件结束");
SecurityUtils.removeUserSession();
result.put("key", key);
result.put("fileId", id);
return result;
} else if (0 == status || 2 == status || 4 == status) {
onlyServiceAPI.close(jsonObject);
@@ -108,7 +103,7 @@ public class FileService {
e.printStackTrace();
throw new RuntimeException(e);
}
result.put("key", key);
return result;
}