diff --git a/byd-structuredplugins-serve/laws-modules/src/main/java/com/jero/modules/onlyoffice/controller/OnlyOfficeController.java b/byd-structuredplugins-serve/laws-modules/src/main/java/com/jero/modules/onlyoffice/controller/OnlyOfficeController.java index 0e03659..e6e3de0 100644 --- a/byd-structuredplugins-serve/laws-modules/src/main/java/com/jero/modules/onlyoffice/controller/OnlyOfficeController.java +++ b/byd-structuredplugins-serve/laws-modules/src/main/java/com/jero/modules/onlyoffice/controller/OnlyOfficeController.java @@ -1,6 +1,7 @@ package com.jero.modules.onlyoffice.controller; import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -21,7 +22,9 @@ import com.jero.modules.oss.entity.OSSFile; import com.jero.modules.oss.service.IOSSFileService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,6 +42,8 @@ import java.net.URL; import java.net.URLConnection; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; +import java.time.Duration; +import java.time.Instant; import java.util.*; /** @@ -369,7 +374,11 @@ public class OnlyOfficeController { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(OnlineFileLog::getHisId, fileId); - wrapper.eq(OnlineFileLog::getDataType, dataType); + if (StringUtils.equals(dataType,"0")) { + wrapper.isNull(OnlineFileLog::getDataType); + } else if (StringUtils.equals(dataType,"1")) { + wrapper.eq(OnlineFileLog::getDataType, dataType); + } wrapper.eq(OnlineFileLog::getValidFlag, "0"); wrapper.orderByDesc(OnlineFileLog::getCreateTime); List onlineFileLogList = onlineFileLogDao.selectList(wrapper); @@ -486,5 +495,67 @@ public class OnlyOfficeController { } return fileName; } + @ApiOperation(value = "更新基线信息") + @PostMapping("/updateOnlineFileLogJxInfo") + public Result updateOnlineFileLogJxInfo(@RequestBody JSONObject json){ + String jxFileName = json.getString("jxFileName"); + String fileId = json.getString("fileId"); + String dataType = "1"; + + Date now = new Date(); + OnlineFileLog createTimeLatestOnlineFileLog = this.getCreateTimeLatestOnlineFileLog(fileId,now); + createTimeLatestOnlineFileLog.setJxFileName(jxFileName); + createTimeLatestOnlineFileLog.setDataType(dataType); + + this.onlineFileLogDao.updateById(createTimeLatestOnlineFileLog); + return Result.OK(); + } + + /** + * 获取在线编辑文件保存历史,更新基线信息使用。 + * @return + */ + public OnlineFileLog getCreateTimeLatestOnlineFileLog(String fileId,Date now){ + QueryWrapper ofLogQueryWrap = new QueryWrapper<>(); + ofLogQueryWrap.lambda().eq(OnlineFileLog::getHisId,fileId); + ofLogQueryWrap.lambda().orderByDesc(OnlineFileLog::getCreateTime); + List onlineFileLogs = this.onlineFileLogDao.selectList(ofLogQueryWrap); + + OnlineFileLog result = null; + if (CollectionUtils.isNotEmpty(onlineFileLogs)) { + result = onlineFileLogs.get(0); + } + if (ObjectUtils.isNotEmpty(result)) { + long nowTime = now.getTime(); + long createTime = result.getCreateTime().getTime(); + + // 如果数据的创建时间大于当前时间,直接返回 + if (createTime > nowTime) { + return result; + } + + // 计算时间差 + long diff = Math.abs(nowTime - createTime); + + // 判断时间差是否小于等于10秒 + if (diff <= 10 * 1000) { + System.out.println("两个日期在十秒内"); + } else { + System.out.println("两个日期不在十秒内"); + + result = null; + } + } + + if (ObjectUtils.isEmpty(result)){ + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + result = this.getCreateTimeLatestOnlineFileLog(fileId,now); + } + return result; + } }