|
|
@@ -8,8 +8,12 @@ import com.doc.biz.service.IDocVersionService;
|
|
|
import com.doc.biz.service.IMongoService;
|
|
|
import com.doc.biz.vo.DocumentVO;
|
|
|
import com.doc.common.core.domain.entity.SysUser;
|
|
|
+import com.doc.common.enums.*;
|
|
|
import com.doc.common.utils.file.FileUtils;
|
|
|
+import com.doc.system.domain.SysOperLog;
|
|
|
+import com.doc.system.service.ISysOperLogService;
|
|
|
import com.doc.system.service.ISysUserService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
@@ -33,6 +37,7 @@ import java.util.Scanner;
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/only-office")
|
|
|
+@Slf4j
|
|
|
public class OnlyOfficeController {
|
|
|
@Resource
|
|
|
private IDocInfoService docInfoService;
|
|
|
@@ -42,6 +47,8 @@ public class OnlyOfficeController {
|
|
|
private IDocVersionService versionService;
|
|
|
@Resource
|
|
|
private ISysUserService userService;
|
|
|
+ @Resource
|
|
|
+ private ISysOperLogService operLogService;
|
|
|
|
|
|
/**
|
|
|
* only office修改回调
|
|
|
@@ -55,52 +62,59 @@ public class OnlyOfficeController {
|
|
|
public void save(@PathVariable("id") Long id, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
PrintWriter writer = null;
|
|
|
String body = "";
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
try (Scanner scanner = new Scanner(request.getInputStream());) {
|
|
|
writer = response.getWriter();
|
|
|
scanner.useDelimiter("\\A");
|
|
|
body = scanner.hasNext() ? scanner.next() : "";
|
|
|
} catch (Exception ex) {
|
|
|
+ log.error("get request.getInputStream error:{}", ex.getMessage());
|
|
|
writer.write("get request.getInputStream error:" + ex.getMessage());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (body.isEmpty()) {
|
|
|
+ log.error("ONLYOFFICE回调保存请求体为空");
|
|
|
throw new Exception("ONLYOFFICE回调保存请求体为空");
|
|
|
}
|
|
|
|
|
|
JSONObject jsonObj = JSONObject.parseObject(body);
|
|
|
int status = (Integer) jsonObj.get("status");
|
|
|
- /* 定义文档的状态。 可以有以下值:
|
|
|
- 1 - 正在编辑文档,
|
|
|
- 2 - 文档已准备好保存,
|
|
|
- 3 - 发生文档保存错误,
|
|
|
- 4 - 文档已关闭,没有任何更改,
|
|
|
- 6 - 正在编辑文档,但保存了当前文档状态,
|
|
|
- 7 - 强制保存文档时发生错误。*/
|
|
|
+ /* 定义文档的状态。 可以有以下值:
|
|
|
+ * 1 - 正在编辑文档,
|
|
|
+ * 2 - 文档已准备好保存,
|
|
|
+ * 3 - 发生文档保存错误,
|
|
|
+ * 4 - 文档已关闭,没有任何更改,
|
|
|
+ * 6 - 正在编辑文档,但保存了当前文档状态,
|
|
|
+ * 7 - 强制保存文档时发生错误。*/
|
|
|
+
|
|
|
int save = 2;
|
|
|
int saveError = 3;
|
|
|
int forceSave = 6;
|
|
|
int saved = 0;
|
|
|
- String key = jsonObj.get("key").toString();
|
|
|
+
|
|
|
+ /*这个key是 fileID,暂时不用的
|
|
|
+ * String key = jsonObj.get("key").toString();*/
|
|
|
+
|
|
|
if (status == save || status == saveError || status == forceSave) {
|
|
|
//获取用户信息
|
|
|
SysUser user = userService.selectUserById(jsonObj.getJSONArray("actions").getJSONObject(0).getLong("userid"));
|
|
|
-
|
|
|
String downloadUri = (String) jsonObj.get("url");
|
|
|
DocInfo info = docInfoService.selectDocInfoByDocId(id);
|
|
|
- //保存版本信息
|
|
|
- DocVersion version = new DocVersion();
|
|
|
- version.setDocId(id);
|
|
|
- version.setFileId(info.getFileId());
|
|
|
- version.setCreateBy(info.getCreateBy());
|
|
|
- version.setCreateTime(info.getCreateTime());
|
|
|
- versionService.insertDocVersion(version);
|
|
|
|
|
|
try {
|
|
|
URL url = new URL(downloadUri);
|
|
|
HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
|
|
|
|
|
|
MultipartFile multipartFile = FileUtils.getMultipartFile(connection.getInputStream(), info.getFileName());
|
|
|
+ //保存版本信息
|
|
|
+ DocVersion version = new DocVersion();
|
|
|
+ version.setDocId(id);
|
|
|
+ version.setFileId(info.getFileId());
|
|
|
+ version.setCreateBy(info.getCreateBy());
|
|
|
+ version.setCreateTime(info.getCreateTime());
|
|
|
+ versionService.insertDocVersion(version);
|
|
|
+
|
|
|
//保存新的文件信息
|
|
|
DocumentVO vo = mongoService.uploadFile(multipartFile);
|
|
|
info.setFileId(vo.getFileId());
|
|
|
@@ -108,14 +122,35 @@ public class OnlyOfficeController {
|
|
|
info.setCreateBy(user.getUserName());
|
|
|
info.setCreateTime(new Date());
|
|
|
info.setUpdateBy(user.getUserName());
|
|
|
- docInfoService.updateDocInfo(info);
|
|
|
+ docInfoService.updateDocInfoByOnlyOffice(info);
|
|
|
|
|
|
connection.disconnect();
|
|
|
} catch (Exception ex) {
|
|
|
+ log.error("OnlyOffice异常消息:{}", ex.getMessage());
|
|
|
saved = 1;
|
|
|
- ex.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- writer.write("{\"error\":" + saved + "}");
|
|
|
+ /*插入操作日志--start*/
|
|
|
+ String result = "{\"error\":" + saved + "}";
|
|
|
+ //设置操作日志
|
|
|
+ SysOperLog log = new SysOperLog();
|
|
|
+ // 设置action动作
|
|
|
+ log.setBusinessType(BusinessType.UPDATE.ordinal());
|
|
|
+ // 设置标题
|
|
|
+ log.setTitle("onlyoffice回调");
|
|
|
+ // 设置事件类型
|
|
|
+ log.setEventType(EventType.SYSTEM.ordinal());
|
|
|
+ // 设置事件级别
|
|
|
+ log.setEventLevel(EventLevel.HIGH.ordinal());
|
|
|
+ // 设置操作人类别
|
|
|
+ log.setOperatorType(OperatorType.MANAGE.ordinal());
|
|
|
+ log.setOperParam(body);
|
|
|
+ log.setJsonResult(result);
|
|
|
+ log.setStatus(BusinessStatus.SUCCESS.ordinal());
|
|
|
+ // 设置消耗时间
|
|
|
+ log.setCostTime(System.currentTimeMillis() - start);
|
|
|
+ operLogService.insertOperlog(log);
|
|
|
+ /*插入操作日志--end*/
|
|
|
+ writer.write(result);
|
|
|
}
|
|
|
}
|