1.优化获取config配置接口
2.优化回调保存接口 3.优化文件保存信息的完善
This commit is contained in:
@@ -3,15 +3,19 @@ package com.oo.demo.service;
|
||||
import com.oo.demo.entity.OnFile;
|
||||
import com.oo.onlyoffice.config.OnlyProperties;
|
||||
import com.oo.onlyoffice.core.SaveFileProcessor;
|
||||
import com.oo.onlyoffice.dto.edit.FileUser;
|
||||
import com.oo.onlyoffice.tools.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @BelongsProject: onlyoffice-demo
|
||||
* @BelongsPackage: com.oo.demo.service
|
||||
*
|
||||
* @CreateTime: 2023-08-01 16:00
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
@@ -23,7 +27,9 @@ public class DemoService implements SaveFileProcessor {
|
||||
private OnlyProperties onlyProperties;
|
||||
@Autowired
|
||||
private OnFileService onFileService;
|
||||
|
||||
@Value("${filepath}")
|
||||
private String filepath;
|
||||
final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public void saveBeforeInitialization(Map<String, Object> map, byte[] bytes, String fileExtension) throws Exception {
|
||||
@@ -31,17 +37,17 @@ public class DemoService implements SaveFileProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> save(Map<String, Object> map, byte[] file, byte[] changes, String key){
|
||||
public Map<String, Object> save(Map<String, Object> map, byte[] file, byte[] changes, String key) {
|
||||
String fileId = "";
|
||||
try {
|
||||
fileId = onFileService.saveFile(file,map.get("fileType").toString());
|
||||
fileId = onFileService.saveFile(file, map.get("fileType").toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String version = map.get("version").toString();
|
||||
|
||||
String[] split = version.split("\\.");
|
||||
version = split[0]+"."+split[1]+"."+ (Integer.valueOf(split[2])+1);
|
||||
version = split[0] + "." + split[1] + "." + (Integer.valueOf(split[2]) + 1);
|
||||
|
||||
OnFile onFile = new OnFile();
|
||||
onFile.setFileId(fileId);
|
||||
@@ -49,6 +55,16 @@ public class DemoService implements SaveFileProcessor {
|
||||
onFile.setVersion(version);
|
||||
onFile.setFileSize((long) file.length);
|
||||
onFile.setFileType(map.get("fileType").toString());
|
||||
if (map.containsKey("caseId")) {
|
||||
onFile.setCaseId(map.get("caseId").toString());
|
||||
}
|
||||
onFile.setFilePath(filepath + "/" + fileId + "." + map.get("fileType").toString());
|
||||
FileUser userSession = SecurityUtils.getUserSession();
|
||||
if (userSession != null) {
|
||||
onFile.setUserId(userSession.getId());
|
||||
onFile.setUserName(userSession.getName());
|
||||
}
|
||||
onFile.setCreatedTime(sdf.format(new Date()));
|
||||
onFileService.save(onFile);
|
||||
|
||||
map.put("version", version);
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.oo.demo.service;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.oo.demo.dao.OnFileMapper;
|
||||
import com.oo.demo.entity.OnFile;
|
||||
import com.oo.demo.entity.WebsocketResult;
|
||||
import com.oo.onlyoffice.api.OnlyServiceAPI;
|
||||
@@ -31,10 +33,18 @@ public class FileService {
|
||||
private OnlyServiceAPI onlyServiceAPI;
|
||||
@Autowired
|
||||
private DemoService demoService;
|
||||
|
||||
@Autowired
|
||||
private OnFileService onFileService;
|
||||
|
||||
/**
|
||||
* 文档服务器 保存文件回调
|
||||
* Defines the status of the document. Can have the following values:
|
||||
* 1 - document is being edited,
|
||||
* 2 - document is ready for saving,
|
||||
* 3 - document saving error has occurred,
|
||||
* 4 - document is closed with no changes,
|
||||
* 6 - document is being edited, but the current document state is saved,
|
||||
* 7 - error has occurred while force saving the document.
|
||||
*
|
||||
* @param jsonObject
|
||||
*/
|
||||
@@ -61,6 +71,11 @@ public class FileService {
|
||||
//文件id
|
||||
String fileId = onlyServiceAPI.getFileId(key);
|
||||
log.info("fileId:" + JSON.toJSONString(fileId));
|
||||
if (fileId != null && !"".equals(fileId)) {
|
||||
//查询之前FileId对应的文件信息
|
||||
OnFile onfile = onFileService.getFileById(fileId);
|
||||
jsonObject.put("caseId", onfile.getCaseId());
|
||||
}
|
||||
//判断是否是最后一人进行保存
|
||||
int users = onlyServiceAPI.getUserNum(key);
|
||||
// if (users > 1) {
|
||||
@@ -77,6 +92,8 @@ public class FileService {
|
||||
}
|
||||
//处理文件的保存
|
||||
OnFile file = onlyServiceAPI.handlerStatus(jsonObject);
|
||||
//查询相同案件最新版本的文件信息
|
||||
file = getNewFileInofoByCaseId(file.getCaseId());
|
||||
result = WebsocketResult.builder().onFile(file).userId(SecurityUtils.getUserSession().getId()).build();
|
||||
log.info("处理文件的保存:" + JSON.toJSONString(jsonObject));
|
||||
log.info("保存文件结束");
|
||||
@@ -107,5 +124,25 @@ public class FileService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
OnFileMapper onFileMapper;
|
||||
|
||||
/**
|
||||
* 查询相同案件最新版本的文件信息
|
||||
*
|
||||
* @param caseId
|
||||
* @return
|
||||
*/
|
||||
private OnFile getNewFileInofoByCaseId(String caseId) {
|
||||
OnFile file = new OnFile();
|
||||
QueryWrapper<OnFile> fileQueryWrapper = new QueryWrapper<>();
|
||||
fileQueryWrapper.eq("case_id", caseId);
|
||||
fileQueryWrapper.orderByDesc("created_time");
|
||||
List<OnFile> onFiles = onFileMapper.selectList(fileQueryWrapper);
|
||||
if (onFiles != null && onFiles.size() > 0) {
|
||||
file = onFiles.get(0);
|
||||
}
|
||||
log.info("caseId:" + caseId + ":fileinfo:" + JSON.toJSONString(file));
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,27 @@ import java.io.File;
|
||||
|
||||
|
||||
public interface OnFileService extends IService<OnFile> {
|
||||
|
||||
/**
|
||||
* 保存onlyoffice文件
|
||||
* @param bytes
|
||||
* @param fileType
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
String saveFile(byte[] bytes, String fileType) throws Exception;
|
||||
|
||||
/**
|
||||
* 删除onlyoffice文件
|
||||
* @param id
|
||||
*/
|
||||
void removeFile(String id);
|
||||
|
||||
/**
|
||||
* 下载onlyoffice文件
|
||||
* @param id
|
||||
* @param isBrowser
|
||||
* @param response
|
||||
*/
|
||||
void download(String id, String isBrowser, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user