新版onlyoffice
This commit is contained in:
@@ -8,7 +8,7 @@ import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
||||
/**
|
||||
* @BelongsProject: leaf-onlyoffice
|
||||
* @BelongsPackage: com.ideayp.leaf.config
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2022-12-01 17:37
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* MybatisPlusConfig.java
|
||||
* @Author TongHui MybatisPlusConfig.java
|
||||
* @Description 配置分页插件
|
||||
* @Date 2022/3/24 9:51
|
||||
* @Version 1.0
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.oo.demo.config;
|
||||
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||
|
||||
@Configuration
|
||||
public class WebSocketConfig {
|
||||
@Bean
|
||||
public ServerEndpointExporter serverEndpointExporter() {
|
||||
return new ServerEndpointExporter();
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.oo.demo.entity.OnFile;
|
||||
import com.oo.demo.entity.Result;
|
||||
import com.oo.demo.entity.SysUser;
|
||||
import com.oo.demo.entity.WebsocketResult;
|
||||
import com.oo.demo.service.FileService;
|
||||
import com.oo.demo.service.OnFileService;
|
||||
import com.oo.demo.service.TempUser;
|
||||
import com.oo.demo.service.Oprator;
|
||||
import com.oo.demo.service.WebSocketServer;
|
||||
import com.oo.onlyoffice.api.OnlyServiceAPI;
|
||||
import com.oo.onlyoffice.dto.edit.FileUser;
|
||||
import com.oo.onlyoffice.tools.FileUtil;
|
||||
@@ -16,6 +19,7 @@ import com.oo.onlyoffice.tools.SecurityUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -31,7 +35,6 @@ import java.util.*;
|
||||
/**
|
||||
* @BelongsProject: leaf-onlyoffice
|
||||
* @BelongsPackage: com.ideayp.leaf.onlyoffice.controller
|
||||
* @Author: TongHui
|
||||
* @CreateTime: 2022-11-08 18:11
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
@@ -78,7 +81,7 @@ public class OnlyOfficeController {
|
||||
|
||||
@PostMapping("/files/upload")
|
||||
@ResponseBody
|
||||
public Object upload(@RequestParam("file") MultipartFile[] file) {
|
||||
public Object upload(@RequestParam("file") MultipartFile[] file, @RequestParam(name = "caseId") String caseId) {
|
||||
List<OnFile> result = new ArrayList<>();
|
||||
int i = 0;
|
||||
for (MultipartFile multipartFile : file) {
|
||||
@@ -101,6 +104,7 @@ public class OnlyOfficeController {
|
||||
onFile.setFileSize(commonsMultipartFile.getSize());
|
||||
onFile.setFileType(suffix);
|
||||
onFile.setFilePath(filepath + "/" + fileId + "." + suffix);
|
||||
onFile.setCaseId(caseId);
|
||||
onFileService.save(onFile);
|
||||
result.add(onFile);
|
||||
i++;
|
||||
@@ -112,13 +116,16 @@ public class OnlyOfficeController {
|
||||
return Result.error("文件上传失败");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
StringRedisTemplate stringRedisTemplate;
|
||||
final static String REDISUSERPREFIX = "user_key:";
|
||||
|
||||
/**
|
||||
* 打开编辑
|
||||
*/
|
||||
@RequestMapping("/onlyOfficeConfig/{mode}/{id}")
|
||||
@RequestMapping("/onlyOfficeConfig/{mode}/{id}/{userId}")
|
||||
@ResponseBody
|
||||
public Object openDocument(@PathVariable(required = false) String mode, @PathVariable(required = false) String id, Model model) {//@RequestParam("url") String url,
|
||||
public Object openDocument(@PathVariable(required = false) String mode, @PathVariable(required = false) String id, @PathVariable(required = true) Integer userId, Model model) {//@RequestParam("url") String url,
|
||||
log.info("only office file:" + id);
|
||||
OnFile onFile = onFileService.getById(id);
|
||||
if (onFile == null) {
|
||||
@@ -128,9 +135,20 @@ public class OnlyOfficeController {
|
||||
* 必要步骤
|
||||
*/
|
||||
FileUser user = new FileUser();
|
||||
user.setId(TempUser.getUserId());
|
||||
user.setName(TempUser.getUserName());
|
||||
SecurityUtils.setUserSession(user);
|
||||
//获取缓存Redis中的用户信息
|
||||
String userString = stringRedisTemplate.opsForValue().get(REDISUSERPREFIX + userId);
|
||||
if (userString != null && !"".equals(userString)) {
|
||||
JSONObject userObj = JSON.parseObject(userString);
|
||||
String userId1 = userObj.getString("userId");
|
||||
String userName1 = userObj.getString("userName");
|
||||
String nickName1 = userObj.getString("nickName");
|
||||
user.setId(userId1);
|
||||
user.setName(userName1);
|
||||
user.setNickname(nickName1);
|
||||
SecurityUtils.setUserSession(user);
|
||||
} else {
|
||||
return Result.error("当前用户不存在");
|
||||
}
|
||||
/**
|
||||
* 必要步骤
|
||||
*/
|
||||
@@ -197,7 +215,7 @@ public class OnlyOfficeController {
|
||||
*/
|
||||
@RequestMapping("/onlyOffice/save")
|
||||
@ResponseBody
|
||||
public Object saveFile(HttpServletRequest request, HttpServletResponse response) {
|
||||
public void saveFile(HttpServletRequest request, HttpServletResponse response) {
|
||||
PrintWriter writer = null;
|
||||
try {
|
||||
writer = response.getWriter();
|
||||
@@ -206,24 +224,19 @@ public class OnlyOfficeController {
|
||||
String body = scanner.hasNext() ? scanner.next() : "";
|
||||
JSONObject jsonObject = JSONObject.parseObject(body);
|
||||
log.info("{}", jsonObject);
|
||||
|
||||
Object result = fileService.documentSave(jsonObject);
|
||||
WebsocketResult result = fileService.documentSave(jsonObject);
|
||||
/*
|
||||
* status = 1,我们给onlyOffice的服务返回{"error":"0"}的信息。
|
||||
* 这样onlyOffice会认为回调接口是没问题的,这样就可以在线编辑文档了,否则的话会弹出窗口说明
|
||||
*/
|
||||
if (Objects.nonNull(writer)) {
|
||||
writer.write("{\"error\":0}");
|
||||
}
|
||||
return result;
|
||||
WebSocketServer.sendInfo(JSON.toJSONString(result.getOnFile()),result.getUserId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
writer.write("{\"error\":-1}");
|
||||
return Result.error("保存出错");
|
||||
}
|
||||
/*
|
||||
* status = 1,我们给onlyOffice的服务返回{"error":"0"}的信息。
|
||||
* 这样onlyOffice会认为回调接口是没问题的,这样就可以在线编辑文档了,否则的话会弹出窗口说明
|
||||
*/
|
||||
// if (Objects.nonNull(writer)) {
|
||||
// writer.write("{\"error\":0}");
|
||||
// }
|
||||
}
|
||||
|
||||
@PostMapping("/save/{id}")
|
||||
@@ -238,11 +251,11 @@ public class OnlyOfficeController {
|
||||
*/
|
||||
try {
|
||||
FileUser user = new FileUser();
|
||||
user.setId(TempUser.getUserId());
|
||||
user.setName(TempUser.getUserName());
|
||||
user.setId(Oprator.getUserId());
|
||||
user.setName(Oprator.getUserName());
|
||||
SecurityUtils.setUserSession(user);
|
||||
String key = onlyServiceAPI.getKey(onFile.getFileId());
|
||||
String msg = onlyServiceAPI.save(key, TempUser.getUserId());
|
||||
String msg = onlyServiceAPI.save(key, Oprator.getUserId());
|
||||
SecurityUtils.removeUserSession();
|
||||
OnFile fileInfo = new OnFile();
|
||||
fileInfo.setFileId(id);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.oo.demo.controller;
|
||||
|
||||
import com.oo.demo.service.WebSocketServer;
|
||||
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.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller("web_Socket_system")
|
||||
@RequestMapping("/socket")
|
||||
public class WebSocketController {
|
||||
//页面请求
|
||||
@GetMapping("/index/{userId}")
|
||||
public ModelAndView socket(@PathVariable String userId) {
|
||||
ModelAndView mav = new ModelAndView("/socket1");
|
||||
mav.addObject("userId", userId);
|
||||
return mav;
|
||||
}
|
||||
//推送数据接口
|
||||
@ResponseBody
|
||||
@RequestMapping("/push/{cid}")
|
||||
public Map pushToWeb(@PathVariable String cid, String message) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
WebSocketServer.sendInfo(message, cid);
|
||||
result.put("code", cid);
|
||||
result.put("msg", message);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author tonghui
|
||||
* @since 2022-03-10
|
||||
*/
|
||||
@Mapper
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
package com.oo.demo.entity;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @BelongsProject: leaf-onlyoffice
|
||||
* @BelongsPackage: com.ideayp.leaf.entity
|
||||
* @Author: TongHui
|
||||
* @CreateTime: 2022-11-14 10:20
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
@@ -32,6 +25,7 @@ public class OnFile {
|
||||
private String fileName;
|
||||
private String fileType;
|
||||
private String filePath;
|
||||
private String caseId;
|
||||
private Long fileSize;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.oo.demo.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @BelongsProject: leaf-onlyoffice
|
||||
* @BelongsPackage: com.ideayp.leaf.entity
|
||||
* @CreateTime: 2022-11-14 10:20
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class WebsocketResult {
|
||||
private OnFile onFile;
|
||||
private String userId;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.Map;
|
||||
/**
|
||||
* @BelongsProject: onlyoffice-demo
|
||||
* @BelongsPackage: com.oo.demo.service
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2023-08-01 16:00
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,5 +13,12 @@ public interface OnFileService extends IService<OnFile> {
|
||||
|
||||
void removeFile(String id);
|
||||
|
||||
void download(String id,String isBrowser, HttpServletResponse response);
|
||||
void download(String id, String isBrowser, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* 根据文件id查找文件信息
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
OnFile getFileById(String id);
|
||||
}
|
||||
|
||||
@@ -7,14 +7,12 @@ import com.oo.demo.dao.OnFileMapper;
|
||||
import com.oo.demo.entity.OnFile;
|
||||
import com.oo.onlyoffice.tools.FileUtil;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
|
||||
/**
|
||||
@@ -22,7 +20,6 @@ import java.nio.file.Files;
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @since 2022-03-10
|
||||
*/
|
||||
@Service
|
||||
@@ -42,6 +39,12 @@ public class OnFileServiceImpl extends ServiceImpl<OnFileMapper, OnFile> impleme
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OnFile getFileById(String id) {
|
||||
OnFile file = baseMapper.selectById(id);
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFile(String id) {
|
||||
OnFile byId = baseMapper.selectById(id);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.oo.demo.service;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @BelongsProject: onlyoffice-demo
|
||||
* @BelongsPackage: com.oo.demo.service
|
||||
* @CreateTime: 2023-08-05 17:14
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class Oprator {
|
||||
private static Logger logger = LoggerFactory.getLogger(Oprator.class);
|
||||
private static List<Map<String, String>> cache1 = new ArrayList<>();
|
||||
private static Integer index;
|
||||
|
||||
static {
|
||||
for (int i = 0; i < 1; i++) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
// map.put("userId", IdUtil.simpleUUID().substring(0,6));
|
||||
// map.put("userName","TongHui"+map.get("userId"));
|
||||
map.put("userId", "0");
|
||||
map.put("userName", "OnlyOfficeUser1");
|
||||
cache1.add(map);
|
||||
}
|
||||
logger.info("用户初始完毕");
|
||||
// Random random = new Random();
|
||||
// index = random.nextInt(10);
|
||||
index = 0;
|
||||
logger.info("获取用户完毕" + index);
|
||||
}
|
||||
|
||||
public static String getUserName() {
|
||||
return cache1.get(index).get("userName");
|
||||
}
|
||||
|
||||
public static String getUserId() {
|
||||
return cache1.get(index).get("userId");
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.oo.demo.service;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @BelongsProject: onlyoffice-demo
|
||||
* @BelongsPackage: com.oo.demo.service
|
||||
* @Author: TongHui
|
||||
* @CreateTime: 2023-08-05 17:14
|
||||
* @Description: TODO 用户信息
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class TempUser {
|
||||
private static Logger logger = LoggerFactory.getLogger(TempUser.class);
|
||||
private static List<Map<String,String>> cache1 = new ArrayList<>();
|
||||
private static Integer index;
|
||||
|
||||
static {
|
||||
for (int i = 0; i < 1; i++) {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("userId", "1");
|
||||
map.put("userName","OnlyOfficeUserName"+map.get("userId"));
|
||||
cache1.add(map);
|
||||
}
|
||||
logger.info("用户初始完毕");
|
||||
Random random = new Random();
|
||||
// index = random.nextInt(10);
|
||||
index = 0;
|
||||
logger.info("获取用户完毕"+index);
|
||||
}
|
||||
public static String getUserName(){
|
||||
return cache1.get(index).get("userName");
|
||||
}
|
||||
public static String getUserId(){
|
||||
return cache1.get(index).get("userId");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.oo.demo.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.websocket.*;
|
||||
import javax.websocket.server.PathParam;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
/**
|
||||
* @ Description:
|
||||
* @ ServerEndpoint 注解是一个类层次的注解,它的功能主要是将目前的类定义成一个websocket服务器端,
|
||||
* 注解的值将被用于监听用户连接的终端访问URL地址,客户端可以通过这个URL来连接到WebSocket服务器端
|
||||
* @author ym
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@Service
|
||||
@ServerEndpoint("/api/websocket/{userid}")
|
||||
public class WebSocketServer {
|
||||
//静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
|
||||
private static int onlineCount = 0;
|
||||
//concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
|
||||
private static CopyOnWriteArraySet<WebSocketServer> webSocketSet = new CopyOnWriteArraySet<WebSocketServer>();
|
||||
|
||||
//与某个客户端的连接会话,需要通过它来给客户端发送数据
|
||||
private Session session;
|
||||
|
||||
//接收userid
|
||||
private String userid = "";
|
||||
|
||||
/**
|
||||
* 连接建立成功调用的方法
|
||||
*/
|
||||
@OnOpen
|
||||
public void onOpen(Session session, @PathParam("userid") String userid) {
|
||||
this.session = session;
|
||||
webSocketSet.add(this); //加入set中
|
||||
this.userid = userid;
|
||||
addOnlineCount(); //在线数加1
|
||||
try {
|
||||
sendMessage("conn_success");
|
||||
log.info("有新窗口开始监听:" + userid + ",当前在线人数为:" + getOnlineCount());
|
||||
} catch (IOException e) {
|
||||
log.error("websocket IO Exception");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接关闭调用的方法
|
||||
*/
|
||||
@OnClose
|
||||
public void onClose() {
|
||||
//从set中删除
|
||||
webSocketSet.remove(this);
|
||||
//在线数减1
|
||||
subOnlineCount();
|
||||
//断开连接情况下,更新主板占用情况为释放
|
||||
log.info("释放的userid为:" + userid);
|
||||
//这里写你 释放的时候,要处理的业务
|
||||
log.info("有一连接关闭!当前在线人数为" + getOnlineCount());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 收到客户端消息后调用的方法
|
||||
*
|
||||
* @ Param message 客户端发送过来的消息
|
||||
*/
|
||||
@OnMessage
|
||||
public void onMessage(String message, Session session) {
|
||||
log.info("收到来自窗口" + userid + "的信息:" + message);
|
||||
//群发消息
|
||||
for (WebSocketServer item : webSocketSet) {
|
||||
try {
|
||||
item.sendMessage(message);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ Param session
|
||||
* @ Param error
|
||||
*/
|
||||
@OnError
|
||||
public void onError(Session session, Throwable error) {
|
||||
log.error("发生错误");
|
||||
error.printStackTrace();
|
||||
}
|
||||
|
||||
/**
|
||||
* 实现服务器主动推送
|
||||
*/
|
||||
public void sendMessage(String message) throws IOException {
|
||||
this.session.getBasicRemote().sendText(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 群发自定义消息
|
||||
*/
|
||||
public static void sendInfo(String message, @PathParam("userid") String userid) throws IOException {
|
||||
log.info("推送消息到窗口" + userid + ",推送内容:" + message);
|
||||
|
||||
for (WebSocketServer item : webSocketSet) {
|
||||
try {
|
||||
//这里可以设定只推送给这个userid的,为null则全部推送
|
||||
if (userid == null) {
|
||||
// item.sendMessage(message);
|
||||
} else if (item.userid.equals(userid)) {
|
||||
item.sendMessage(message);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized int getOnlineCount() {
|
||||
return onlineCount;
|
||||
}
|
||||
|
||||
public static synchronized void addOnlineCount() {
|
||||
WebSocketServer.onlineCount++;
|
||||
}
|
||||
|
||||
public static synchronized void subOnlineCount() {
|
||||
WebSocketServer.onlineCount--;
|
||||
}
|
||||
|
||||
public static CopyOnWriteArraySet<WebSocketServer> getWebSocketSet() {
|
||||
return webSocketSet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.oo.onlyoffice.api;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.oo.demo.entity.OnFile;
|
||||
import com.oo.onlyoffice.core.context.FileMetadata;
|
||||
|
||||
|
||||
@@ -33,7 +34,7 @@ public interface OnlyServiceAPI {
|
||||
*
|
||||
* @param jsonObject 信息
|
||||
*/
|
||||
void handlerStatus(JSONObject jsonObject) throws Exception;
|
||||
OnFile handlerStatus(JSONObject jsonObject) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,27 +2,30 @@ package com.oo.onlyoffice.api.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.oo.demo.entity.OnFile;
|
||||
import com.oo.demo.service.OnFileService;
|
||||
import com.oo.onlyoffice.api.OnlyServiceAPI;
|
||||
import com.oo.onlyoffice.config.OnlyProperties;
|
||||
import com.oo.onlyoffice.core.Cache;
|
||||
import com.oo.onlyoffice.core.SaveFileProcessor;
|
||||
import com.oo.onlyoffice.core.context.FileMetadata;
|
||||
import com.oo.onlyoffice.tools.DocumentKey;
|
||||
import com.oo.onlyoffice.tools.JWTUtil;
|
||||
import com.oo.onlyoffice.vo.FileConfig;
|
||||
import com.oo.onlyoffice.core.FileHandler;
|
||||
import com.oo.onlyoffice.core.OnlyOfficeConfigFactory;
|
||||
import com.oo.onlyoffice.core.SaveFileProcessor;
|
||||
import com.oo.onlyoffice.core.context.FileContext;
|
||||
import com.oo.onlyoffice.core.context.FileMetadata;
|
||||
import com.oo.onlyoffice.dto.convert.ConvertBody;
|
||||
import com.oo.onlyoffice.dto.edit.FileUser;
|
||||
import com.oo.onlyoffice.core.context.FileContext;
|
||||
import com.oo.onlyoffice.core.FileHandler;
|
||||
import com.oo.onlyoffice.tools.DocumentKey;
|
||||
import com.oo.onlyoffice.tools.FileUtil;
|
||||
import com.oo.onlyoffice.tools.JWTUtil;
|
||||
import com.oo.onlyoffice.tools.SecurityUtils;
|
||||
import com.oo.onlyoffice.vo.FileConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -34,7 +37,8 @@ import java.util.*;
|
||||
@Service
|
||||
@Slf4j
|
||||
public class OnlyServiceAPIImpl implements OnlyServiceAPI {
|
||||
|
||||
@Autowired
|
||||
OnFileService onFileService;
|
||||
@Autowired
|
||||
private OnlyOfficeConfigFactory onlyOfficeConfigFactory;
|
||||
@Autowired
|
||||
@@ -54,13 +58,12 @@ public class OnlyServiceAPIImpl implements OnlyServiceAPI {
|
||||
|
||||
/**
|
||||
* @param map 文件信息
|
||||
* @param map{
|
||||
* 必填 fileId
|
||||
* 必填 fileName
|
||||
* 必填 fileType
|
||||
* 必填 fileSize
|
||||
* 可用携带其它信息
|
||||
* }
|
||||
* @param map{ 必填 fileId
|
||||
* 必填 fileName
|
||||
* 必填 fileType
|
||||
* 必填 fileSize
|
||||
* 可用携带其它信息
|
||||
* }
|
||||
* @param mode 打开方式 edit/view
|
||||
* @param collaborativeEditing 是否协同编辑
|
||||
* @return
|
||||
@@ -71,11 +74,11 @@ public class OnlyServiceAPIImpl implements OnlyServiceAPI {
|
||||
|
||||
if (fileSize > onlyProperties.getMaxSize()) {
|
||||
// 添加操作日志
|
||||
throw new RuntimeException("文件超过【"+onlyProperties.getMaxSize()/1024/1024+"MB】无法打开");
|
||||
throw new RuntimeException("文件超过【" + onlyProperties.getMaxSize() / 1024 / 1024 + "MB】无法打开");
|
||||
}
|
||||
|
||||
if (EDIT.equals(mode)) {
|
||||
return documentEdit(map,collaborativeEditing);
|
||||
return documentEdit(map, collaborativeEditing);
|
||||
}
|
||||
if (VIEW.equals(mode)) {
|
||||
return documentView(map);
|
||||
@@ -83,7 +86,7 @@ public class OnlyServiceAPIImpl implements OnlyServiceAPI {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map documentEdit(Map<String, Object> map,boolean collaborativeEditing) {
|
||||
private Map documentEdit(Map<String, Object> map, boolean collaborativeEditing) {
|
||||
FileConfig fileConfigDTO = openEditConfig(map, "edit", collaborativeEditing);
|
||||
String json = JSON.toJSONString(fileConfigDTO);
|
||||
|
||||
@@ -94,7 +97,7 @@ public class OnlyServiceAPIImpl implements OnlyServiceAPI {
|
||||
}
|
||||
|
||||
|
||||
private Map documentView(Map<String, Object> map) {
|
||||
private Map documentView(Map<String, Object> map) {
|
||||
FileConfig fileConfigDTO = openEditConfig(map, "view", false);
|
||||
String json = JSON.toJSONString(fileConfigDTO);
|
||||
Map<String, Object> config = JSON.parseObject(json, Map.class);
|
||||
@@ -107,7 +110,7 @@ public class OnlyServiceAPIImpl implements OnlyServiceAPI {
|
||||
map.put("mode", mode);
|
||||
log.info("开始生成文件信息");
|
||||
//在编辑模式 生成临时文件,保存原文件信息
|
||||
FileMetadata tempFileInfo = fileHandler.handlerFile(map,collaborativeEditing) ;
|
||||
FileMetadata tempFileInfo = fileHandler.handlerFile(map, collaborativeEditing);
|
||||
//生成配置文件 TODO: 控制文件权限
|
||||
log.info("开始生成编辑器配置信息");
|
||||
FileConfig fileConfigDTO = onlyOfficeConfigFactory.buildInitConfig(tempFileInfo.getUrl(), mode, tempFileInfo.getKey(), tempFileInfo.getOldName());
|
||||
@@ -121,8 +124,6 @@ public class OnlyServiceAPIImpl implements OnlyServiceAPI {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取规定历史文件数量
|
||||
*
|
||||
@@ -159,7 +160,9 @@ public class OnlyServiceAPIImpl implements OnlyServiceAPI {
|
||||
|
||||
|
||||
@Override
|
||||
public void handlerStatus(JSONObject jsonObject) throws Exception {
|
||||
public OnFile handlerStatus(JSONObject jsonObject) throws Exception {
|
||||
OnFile file = new OnFile();
|
||||
String fileId = null;
|
||||
log.info("开始下载编辑器文件");
|
||||
int status = jsonObject.getIntValue("status");
|
||||
log.info("status[{}]:{}", status, jsonObject);
|
||||
@@ -183,23 +186,49 @@ public class OnlyServiceAPIImpl implements OnlyServiceAPI {
|
||||
|
||||
Optional<FileMetadata> tempFile = tempFileHandler.getTempFile(key);
|
||||
|
||||
if (!tempFile.isPresent()){
|
||||
if (!tempFile.isPresent()) {
|
||||
throw new RuntimeException("文件元信息不存在");
|
||||
}
|
||||
|
||||
|
||||
saveFileProcessor.saveBeforeInitialization(tempFile.get().getFileInfo(),fileByte,fileExtension);
|
||||
saveFileProcessor.saveBeforeInitialization(tempFile.get().getFileInfo(), fileByte, fileExtension);
|
||||
|
||||
// 保存文件
|
||||
Map<String, Object> map = saveFileProcessor.save(tempFile.get().getFileInfo(),fileByte,changes, key);
|
||||
|
||||
saveFileProcessor.saveAfterInitialization(tempFile.get().getFileInfo(),fileByte,fileExtension);
|
||||
Map<String, Object> map = saveFileProcessor.save(tempFile.get().getFileInfo(), fileByte, changes, key);
|
||||
log.info("文件信息1:" + JSON.toJSONString(tempFile.get().getFileInfo()));
|
||||
log.info("文件信息2:" + JSON.toJSONString(map));
|
||||
saveFileProcessor.saveAfterInitialization(tempFile.get().getFileInfo(), fileByte, fileExtension);
|
||||
//更新内存文件信息
|
||||
tempFileContext.updateCacheFileInfo(key,map);
|
||||
tempFileContext.updateCacheFileInfo(key, map);
|
||||
//构建文件信息
|
||||
fileId = map.get("fileId").toString();
|
||||
//将map转化为OnFile对象
|
||||
// file = mapToEntity(map);
|
||||
if (fileId != null) {
|
||||
//查询文件信息
|
||||
file = onFileService.getFileById(fileId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将map转化成对象
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
* @throws NoSuchFieldException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public OnFile mapToEntity(Map<String, Object> map) throws NoSuchFieldException, IllegalAccessException {
|
||||
OnFile entity = new OnFile();
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
Field field = OnFile.class.getDeclaredField(entry.getKey());
|
||||
field.setAccessible(true);
|
||||
field.set(entity, entry.getValue());
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void removeTempFile(JSONObject jsonObject) {
|
||||
@@ -244,14 +273,14 @@ public class OnlyServiceAPIImpl implements OnlyServiceAPI {
|
||||
public void close(JSONObject jsonObject) {
|
||||
// 判断临时信息是否存在
|
||||
FileMetadata tempFile = getTempFile(jsonObject.getString("key"));
|
||||
if (tempFile == null){
|
||||
if (tempFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
//判断 删除时间 是否大于 文件打开时间
|
||||
//如果 删除时间 小于 文件打开时间 不执行删除
|
||||
log.info("打开时间:"+tempFile.getOpenTime()+",回调时间:"+ new Date().getTime());
|
||||
if (new Date().getTime() < tempFile.getOpenTime()){
|
||||
log.info("打开时间:" + tempFile.getOpenTime() + ",回调时间:" + new Date().getTime());
|
||||
if (new Date().getTime() < tempFile.getOpenTime()) {
|
||||
return;
|
||||
}
|
||||
// 减少文档的使用人数
|
||||
@@ -278,8 +307,8 @@ public class OnlyServiceAPIImpl implements OnlyServiceAPI {
|
||||
cache.set(key, users);
|
||||
i = users;
|
||||
} else {
|
||||
i = ((int)cache.get(key)) - 1;
|
||||
cache.set(key, (i>=0 ? i : 0));
|
||||
i = ((int) cache.get(key)) - 1;
|
||||
cache.set(key, (i >= 0 ? i : 0));
|
||||
}
|
||||
log.info("[" + key + "]文档使用人数:" + i);
|
||||
return i;
|
||||
@@ -287,7 +316,7 @@ public class OnlyServiceAPIImpl implements OnlyServiceAPI {
|
||||
|
||||
@Override
|
||||
public int getUserNum(String key) {
|
||||
return (int)(cache.get(key));
|
||||
return (int) (cache.get(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -308,12 +337,12 @@ public class OnlyServiceAPIImpl implements OnlyServiceAPI {
|
||||
map.put("c", "forcesave");
|
||||
map.put("key", key);
|
||||
map.put("userdata", userId);
|
||||
if (null != onlyProperties.getSecret()){
|
||||
String token = JWTUtil.createToken(map,onlyProperties.getSecret());
|
||||
map.put("token",token);
|
||||
if (null != onlyProperties.getSecret()) {
|
||||
String token = JWTUtil.createToken(map, onlyProperties.getSecret());
|
||||
map.put("token", token);
|
||||
}
|
||||
String bodyString = JSON.toJSONString(map);
|
||||
log.info("forcesave:"+bodyString);
|
||||
log.info("forcesave:" + bodyString);
|
||||
byte[] bodyByte = bodyString.getBytes(StandardCharsets.UTF_8);
|
||||
try {
|
||||
URL url = new URL(onlyProperties.getDocService() + onlyProperties.SAVE);
|
||||
@@ -414,16 +443,16 @@ public class OnlyServiceAPIImpl implements OnlyServiceAPI {
|
||||
* }
|
||||
*/
|
||||
@Override
|
||||
public String converted(String filetype, String key, String outputtype, String title,String password) {
|
||||
public String converted(String filetype, String key, String outputtype, String title, String password) {
|
||||
log.debug("文件开始转化{}->{}", filetype, outputtype);
|
||||
|
||||
String fileUrl = onlyProperties.getDownloadFile()+key;
|
||||
String fileUrl = onlyProperties.getDownloadFile() + key;
|
||||
|
||||
ConvertBody body = new ConvertBody(filetype, DocumentKey.SnowflakeId(), outputtype, fileUrl, title,password);
|
||||
ConvertBody body = new ConvertBody(filetype, DocumentKey.SnowflakeId(), outputtype, fileUrl, title, password);
|
||||
String bodyString = JSON.toJSONString(body);
|
||||
|
||||
if (null != onlyProperties.getSecret()){
|
||||
String token = JWTUtil.createToken(JSON.parseObject(bodyString,Map.class),onlyProperties.getSecret());
|
||||
if (null != onlyProperties.getSecret()) {
|
||||
String token = JWTUtil.createToken(JSON.parseObject(bodyString, Map.class), onlyProperties.getSecret());
|
||||
body.setToken(token);
|
||||
bodyString = JSON.toJSONString(body);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.oo.onlyoffice.core.cache.InsideCache;
|
||||
import com.oo.onlyoffice.core.cache.RedisCache;
|
||||
import com.oo.onlyoffice.tools.LoadConfigUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -23,7 +22,6 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
/**
|
||||
* @BelongsProject: onlyoffice-demo
|
||||
* @BelongsPackage: com.oo.onlyoffice.config
|
||||
* @Author: TongHui
|
||||
* @CreateTime: 2023-08-01 16:17
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
package com.oo.onlyoffice.core;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.oo.onlyoffice.core.OnlyOfficeConfigFactory;
|
||||
import com.oo.onlyoffice.config.OnlyProperties;
|
||||
import com.oo.onlyoffice.dto.DocumentConfig;
|
||||
import com.oo.onlyoffice.dto.EditorConfig;
|
||||
import com.oo.onlyoffice.dto.Plugins;
|
||||
import com.oo.onlyoffice.tools.*;
|
||||
import com.oo.onlyoffice.config.OnlyProperties;
|
||||
import com.oo.onlyoffice.dto.document.DocumentInfo;
|
||||
import com.oo.onlyoffice.dto.document.DocumentPermission;
|
||||
import com.oo.onlyoffice.dto.document.SharingSettings;
|
||||
import com.oo.onlyoffice.dto.edit.FileCustomization;
|
||||
import com.oo.onlyoffice.dto.edit.FileUser;
|
||||
import com.oo.onlyoffice.tools.*;
|
||||
import com.oo.onlyoffice.vo.FileConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @BelongsProject: leaf-onlyoffice
|
||||
* @BelongsPackage: com.ideayp.leaf.onlyoffice.dto
|
||||
* @Author: TongHui
|
||||
* @CreateTime: 2022-11-16 17:00
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -8,7 +8,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
/**
|
||||
* @BelongsProject: onlyoffice-demo
|
||||
* @BelongsPackage: com.oo.onlyoffice.tools
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2023-07-30 17:11
|
||||
* @Description: 内部缓存
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.concurrent.TimeUnit;
|
||||
/**
|
||||
* @BelongsProject: onlyoffice-demo
|
||||
* @BelongsPackage: com.oo.onlyoffice.core.cache
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2023-08-01 18:06
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -6,7 +6,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
/**
|
||||
* @BelongsProject: self-study
|
||||
* @BelongsPackage: com.project.dto
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2022-12-23 16:23
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -11,7 +11,7 @@ import lombok.Data;
|
||||
/**
|
||||
* @BelongsProject: leaf-onlyoffice
|
||||
* @BelongsPackage: com.ideayp.leaf.onlyoffice.dto.convert
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2022-11-23 09:41
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -5,7 +5,7 @@ import lombok.Data;
|
||||
/**
|
||||
* @BelongsProject: leaf-onlyoffice
|
||||
* @BelongsPackage: com.ideayp.leaf.onlyoffice.dto.convert
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2022-11-23 09:44
|
||||
* @Description: 文档布局
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -5,7 +5,7 @@ import lombok.Data;
|
||||
/**
|
||||
* @BelongsProject: leaf-onlyoffice
|
||||
* @BelongsPackage: com.ideayp.leaf.onlyoffice.dto.convert
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2022-11-23 09:46
|
||||
* @Description: 文档渲染器
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -6,7 +6,7 @@ import lombok.Data;
|
||||
/**
|
||||
* @BelongsProject: leaf-onlyoffice
|
||||
* @BelongsPackage: com.ideayp.leaf.onlyoffice.dto.convert.sheet
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2022-11-23 09:55
|
||||
* @Description: 边距
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -6,7 +6,7 @@ import lombok.Data;
|
||||
/**
|
||||
* @BelongsProject: leaf-onlyoffice
|
||||
* @BelongsPackage: com.ideayp.leaf.onlyoffice.dto.convert.sheet
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2022-11-23 09:58
|
||||
* @Description: 页面大小
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -5,7 +5,7 @@ import lombok.Data;
|
||||
/**
|
||||
* @BelongsProject: leaf-onlyoffice
|
||||
* @BelongsPackage: com.ideayp.leaf.onlyoffice.dto.convert
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2022-11-23 09:50
|
||||
* @Description: 电子表格布局
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -5,7 +5,7 @@ import lombok.Data;
|
||||
/**
|
||||
* @BelongsProject: leaf-onlyoffice
|
||||
* @BelongsPackage: com.ideayp.leaf.onlyoffice.dto.convert.thumbnail
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2022-11-23 10:18
|
||||
* @Description: 缩略图 定义将图像格式(bmp,gif,jpg,png)指定为输出类型时缩略图的设置。
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -5,7 +5,7 @@ import lombok.Data;
|
||||
/**
|
||||
* @BelongsProject: leaf-onlyoffice
|
||||
* @BelongsPackage: com.ideayp.leaf.onlyoffice.dto.document
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2022-11-09 13:53
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*@Author TongHui
|
||||
*@Date 2022/11/16
|
||||
*@ClassName FileCustomer
|
||||
*@Version 1.0
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*@Author TongHui
|
||||
*@Date 2022/11/16
|
||||
*@ClassName FileCustomization
|
||||
*@Version 1.0
|
||||
|
||||
@@ -19,6 +19,7 @@ public class FileUser implements Serializable {
|
||||
* 用户 全称
|
||||
*/
|
||||
private String name;
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 组
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.Random;
|
||||
/**
|
||||
* @BelongsProject: office-demo
|
||||
* @BelongsPackage: com.doc.utils
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2022-11-04 18:25
|
||||
* @Description: 生成ID
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.net.URLEncoder;
|
||||
/**
|
||||
* @BelongsProject: onlyoffice-demo
|
||||
* @BelongsPackage: com.oo.onlyoffice.tools
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2023-07-30 17:26
|
||||
* @Description: 文件操作
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.Map;
|
||||
/**
|
||||
* @BelongsProject: onlyoffice-demo
|
||||
* @BelongsPackage: com.oo.onlyoffice.tools
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2023-07-30 18:39
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -7,18 +7,15 @@ import com.oo.onlyoffice.dto.document.DocumentPermission;
|
||||
import com.oo.onlyoffice.dto.edit.FileCustomization;
|
||||
import com.oo.onlyoffice.dto.edit.FileEmbedded;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* @BelongsProject: onlyoffice-demo
|
||||
* @BelongsPackage: com.oo.onlyoffice.tools
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2023-07-30 18:30
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
@@ -35,39 +32,40 @@ public class LoadConfigUtil {
|
||||
private static String YML_NAME = "onlyOffice.yml";
|
||||
|
||||
static {
|
||||
loadYml();
|
||||
loadYml();
|
||||
}
|
||||
private static void loadYml() {
|
||||
|
||||
private static void loadYml(){
|
||||
log.info("--------加载【onlyOffice.yml】配置文件-------");
|
||||
InputStream inputStream = LoadConfigUtil.class.getClassLoader().getResourceAsStream(YML_NAME);
|
||||
//解析配置文件
|
||||
map = new Yaml().loadAs(inputStream, JSONObject.class);
|
||||
JSONObject oo = map.getJSONObject("oo");
|
||||
JSONObject document = oo.getJSONObject("document");
|
||||
if (null != document || null != document.getJSONObject("permissions")) {
|
||||
JSONObject permissions = document.getJSONObject("permissions");
|
||||
if (null != permissions.getJSONObject("edit")) {
|
||||
editPermission = JSONUtil.toBean(permissions.getJSONObject("edit").toString(), DocumentPermission.class);
|
||||
if (null != document || null != document.getJSONObject("permissions")){
|
||||
JSONObject permissions = document.getJSONObject("permissions");
|
||||
if (null != permissions.getJSONObject("edit")){
|
||||
editPermission = JSONUtil.toBean(permissions.getJSONObject("edit").toString(),DocumentPermission.class);
|
||||
editPermission.setEdit(true);
|
||||
}
|
||||
if (null != permissions.getJSONObject("view")) {
|
||||
viewPermission = JSONUtil.toBean(permissions.getJSONObject("view").toString(), DocumentPermission.class);
|
||||
if (null != permissions.getJSONObject("view")){
|
||||
viewPermission = JSONUtil.toBean(permissions.getJSONObject("view").toString(),DocumentPermission.class);
|
||||
viewPermission.setEdit(false);
|
||||
}
|
||||
}
|
||||
JSONObject editor = oo.getJSONObject("editor");
|
||||
if (null != editor) {
|
||||
customization = JSONUtil.toBean(editor.getJSONObject("customization").toString(), FileCustomization.class);
|
||||
if (null != editor){
|
||||
customization = JSONUtil.toBean(editor.getJSONObject("customization").toString(),FileCustomization.class);
|
||||
}
|
||||
|
||||
JSONObject embeddedJson = editor.getJSONObject("embedded");
|
||||
if (null != embeddedJson) {
|
||||
embedded = JSONUtil.toBean(embeddedJson.toString(), FileEmbedded.class);
|
||||
if (null != embeddedJson){
|
||||
embedded = JSONUtil.toBean(embeddedJson.toString(),FileEmbedded.class);
|
||||
}
|
||||
|
||||
JSONObject pluginsJson = editor.getJSONObject("plugins");
|
||||
if (null != pluginsJson) {
|
||||
plugins = JSONUtil.toBean(pluginsJson.toString(), Plugins.class);
|
||||
if (null != pluginsJson){
|
||||
plugins = JSONUtil.toBean(pluginsJson.toString(),Plugins.class);
|
||||
}
|
||||
log.info("--------【onlyOffice.yml】配置文件加载完成-------");
|
||||
}
|
||||
@@ -92,20 +90,20 @@ public class LoadConfigUtil {
|
||||
return plugins;
|
||||
}
|
||||
|
||||
public static JSONObject getConvert() {
|
||||
public static JSONObject getConvert(){
|
||||
JSONObject oo = map.getJSONObject("oo");
|
||||
JSONObject convert = oo.getJSONObject("convert");
|
||||
return convert;
|
||||
}
|
||||
|
||||
public static JSONObject getMap() {
|
||||
public static JSONObject getMap(){
|
||||
return map.getJSONObject("oo");
|
||||
}
|
||||
|
||||
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// JSONObject convert = LoadConfigUtil.getConvert();
|
||||
// System.out.println(convert.toString());
|
||||
// }
|
||||
public static void main(String[] args) {
|
||||
|
||||
JSONObject convert = LoadConfigUtil.getConvert();
|
||||
System.out.println(convert.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.io.Serializable;
|
||||
/**
|
||||
* @BelongsProject: jeecg-boot-parent
|
||||
* @BelongsPackage: com.waysoft.tools
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2023-02-06 09:12
|
||||
* @Description: 存储当前登录的用户信息
|
||||
* @Version: 1.0
|
||||
|
||||
@@ -25,6 +25,10 @@ spring:
|
||||
url: jdbc:mysql://121.40.189.20:3306/onlyoffice?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai&useSSL=false
|
||||
username: root
|
||||
password: YMzc157#
|
||||
redis:
|
||||
host: 121.40.189.20
|
||||
port: 6389
|
||||
database: 0
|
||||
|
||||
mybatis-plus:
|
||||
# global-config:
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.Map;
|
||||
/**
|
||||
* @BelongsProject: onlyoffice-demo
|
||||
* @BelongsPackage: com.oo.demo
|
||||
* @Author: TongHui
|
||||
*
|
||||
* @CreateTime: 2023-08-01 15:50
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
|
||||
Reference in New Issue
Block a user