1. 新增根据 fileId 获取 onlyoffice token 接口
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.zt.plat.framework.mybatis.core.handler;
|
package com.zt.plat.framework.mybatis.core.handler;
|
||||||
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||||
import com.zt.plat.framework.common.biz.system.sequence.SequenceCommonApi;
|
import com.zt.plat.framework.common.biz.system.sequence.SequenceCommonApi;
|
||||||
import com.zt.plat.framework.common.pojo.CommonResult;
|
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||||
import com.zt.plat.framework.mybatis.core.annotation.BusinessCode;
|
import com.zt.plat.framework.mybatis.core.annotation.BusinessCode;
|
||||||
@@ -9,11 +10,9 @@ import com.zt.plat.framework.mybatis.core.dataobject.BusinessBaseDO;
|
|||||||
import com.zt.plat.framework.security.core.LoginUser;
|
import com.zt.plat.framework.security.core.LoginUser;
|
||||||
import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils;
|
import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils;
|
||||||
import com.zt.plat.framework.web.core.util.WebFrameworkUtils;
|
import com.zt.plat.framework.web.core.util.WebFrameworkUtils;
|
||||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.ibatis.reflection.MetaObject;
|
import org.apache.ibatis.reflection.MetaObject;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@@ -28,7 +27,6 @@ import static com.zt.plat.framework.security.core.util.SecurityFrameworkUtils.ge
|
|||||||
*
|
*
|
||||||
* @author hexiaowu
|
* @author hexiaowu
|
||||||
*/
|
*/
|
||||||
@Component
|
|
||||||
public class DefaultDBFieldHandler implements MetaObjectHandler {
|
public class DefaultDBFieldHandler implements MetaObjectHandler {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
|
|||||||
@@ -263,6 +263,15 @@ public class DocFileController {
|
|||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get-file-token")
|
||||||
|
@Operation(summary = "根据fileId获取文件访问Token")
|
||||||
|
@PreAuthorize("@ss.hasPermission('infra:doc:query')")
|
||||||
|
public CommonResult<String> getFileToken(@RequestParam("fileId") Long fileId) {
|
||||||
|
// 使用service中的公共方法生成文件访问token
|
||||||
|
String fileToken = docFileService.generateFileToken(fileId);
|
||||||
|
return success(fileToken);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取客户端真实IP地址
|
* 获取客户端真实IP地址
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -169,4 +169,12 @@ public interface DocFileService {
|
|||||||
*/
|
*/
|
||||||
void restoreDocFileToVersion(Long docFileId, Long versionId);
|
void restoreDocFileToVersion(Long docFileId, Long versionId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成文件访问Token
|
||||||
|
*
|
||||||
|
* @param fileId 文件编号
|
||||||
|
* @return JWT token
|
||||||
|
*/
|
||||||
|
String generateFileToken(Long fileId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -285,17 +285,7 @@ public class DocFileServiceImpl implements DocFileService {
|
|||||||
respVO.setFileSize(fileInfo.getSize().longValue());
|
respVO.setFileSize(fileInfo.getSize().longValue());
|
||||||
|
|
||||||
// 生成文件访问的JWT token
|
// 生成文件访问的JWT token
|
||||||
String fileToken = "";
|
String fileToken = generateFileToken(doc.getFileId());
|
||||||
if (StrUtil.isNotBlank(onlyOfficeJwtSecret)) {
|
|
||||||
// 创建文件访问token,包含fileId和过期时间(1小时后过期)
|
|
||||||
long expTime = System.currentTimeMillis() / 1000 + 3600; // 1小时后过期
|
|
||||||
fileToken = JWT.create()
|
|
||||||
.setPayload("fileId", doc.getFileId())
|
|
||||||
.setPayload("exp", expTime)
|
|
||||||
.setPayload("iat", System.currentTimeMillis() / 1000)
|
|
||||||
.setKey(onlyOfficeJwtSecret.getBytes())
|
|
||||||
.sign();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用新的接口生成文件URL,包含JWT token
|
// 使用新的接口生成文件URL,包含JWT token
|
||||||
String fileUrl = StrUtil.removeSuffix(onlyOfficeCallbackBaseUrl, "/") + "/admin-api/infra/doc-file/file-content?fileId=" + doc.getFileId();
|
String fileUrl = StrUtil.removeSuffix(onlyOfficeCallbackBaseUrl, "/") + "/admin-api/infra/doc-file/file-content?fileId=" + doc.getFileId();
|
||||||
@@ -422,17 +412,7 @@ public class DocFileServiceImpl implements DocFileService {
|
|||||||
String fileUrl = "";
|
String fileUrl = "";
|
||||||
if (doc.getFileId() != null) {
|
if (doc.getFileId() != null) {
|
||||||
// 生成文件访问的JWT token
|
// 生成文件访问的JWT token
|
||||||
String fileToken = "";
|
String fileToken = generateFileToken(doc.getFileId());
|
||||||
if (StrUtil.isNotBlank(onlyOfficeJwtSecret)) {
|
|
||||||
// 创建文件访问token,包含fileId和过期时间(1小时后过期)
|
|
||||||
long expTime = System.currentTimeMillis() / 1000 + 3600; // 1小时后过期
|
|
||||||
fileToken = JWT.create()
|
|
||||||
.setPayload("fileId", doc.getFileId())
|
|
||||||
.setPayload("exp", expTime)
|
|
||||||
.setPayload("iat", System.currentTimeMillis() / 1000)
|
|
||||||
.setKey(onlyOfficeJwtSecret.getBytes())
|
|
||||||
.sign();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 生成通过新接口访问文件的URL,包含JWT token
|
// 生成通过新接口访问文件的URL,包含JWT token
|
||||||
fileUrl = StrUtil.removeSuffix(onlyOfficeCallbackBaseUrl, "/") + "/admin-api/infra/doc-file/file-content?fileId=" + doc.getFileId();
|
fileUrl = StrUtil.removeSuffix(onlyOfficeCallbackBaseUrl, "/") + "/admin-api/infra/doc-file/file-content?fileId=" + doc.getFileId();
|
||||||
@@ -845,5 +825,21 @@ public class DocFileServiceImpl implements DocFileService {
|
|||||||
log.info("文档版本恢复完成: docId={}, 恢复到版本={}, 新版本={}",
|
log.info("文档版本恢复完成: docId={}, 恢复到版本={}, 新版本={}",
|
||||||
docFileId, version.getVersionNo(), newVersionNo);
|
docFileId, version.getVersionNo(), newVersionNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generateFileToken(Long fileId) {
|
||||||
|
String fileToken = "";
|
||||||
|
if (StrUtil.isNotBlank(onlyOfficeJwtSecret)) {
|
||||||
|
// 创建文件访问token,包含fileId和过期时间(1小时后过期)
|
||||||
|
long expTime = System.currentTimeMillis() / 1000 + 3600; // 1小时后过期
|
||||||
|
fileToken = JWT.create()
|
||||||
|
.setPayload("fileId", fileId)
|
||||||
|
.setPayload("exp", expTime)
|
||||||
|
.setPayload("iat", System.currentTimeMillis() / 1000)
|
||||||
|
.setKey(onlyOfficeJwtSecret.getBytes())
|
||||||
|
.sign();
|
||||||
|
}
|
||||||
|
return fileToken;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,4 +92,18 @@ public class SyncLogController {
|
|||||||
return success(count);
|
return success(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/batch-rerun/process")
|
||||||
|
@Operation(summary = "处理批量重跑(处理重试中状态的记录)")
|
||||||
|
@PreAuthorize("@ss.hasPermission('system:sync-log:batch-rerun')")
|
||||||
|
public CommonResult<Integer> processBatchRerun(
|
||||||
|
@RequestParam(value = "batchSize", defaultValue = "50") Integer batchSize) {
|
||||||
|
// 参数校验
|
||||||
|
if (batchSize <= 0 || batchSize > 500) {
|
||||||
|
throw new IllegalArgumentException("批次大小必须在1-500之间");
|
||||||
|
}
|
||||||
|
|
||||||
|
int processedCount = syncLogService.processBatchRerun(batchSize);
|
||||||
|
return success(processedCount);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import com.zt.plat.module.system.dal.mysql.sync.SyncLogMapper;
|
|||||||
import com.zt.plat.module.system.enums.sync.SyncLogStatusEnum;
|
import com.zt.plat.module.system.enums.sync.SyncLogStatusEnum;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -426,12 +427,23 @@ public class SyncLogServiceImpl implements SyncLogService {
|
|||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getBatchRerunProgress(String serviceName) {
|
public Map<String, Object> getBatchRerunProgress(String serviceName) {
|
||||||
// 统计各状态的记录数量
|
// 统计各状态的记录数量
|
||||||
Map<Integer, Long> statusCounts = syncLogMapper.selectList(
|
// 使用MyBatis-Plus的聚合查询方式,避免DM8数据库GROUP BY语法问题
|
||||||
new LambdaQueryWrapper<SyncLogDO>()
|
List<Map<String, Object>> statusCountsList = syncLogMapper.selectMaps(
|
||||||
.eq(SyncLogDO::getServiceName, serviceName)
|
new QueryWrapper<SyncLogDO>()
|
||||||
.groupBy(SyncLogDO::getStatus))
|
.select("status, COUNT(*) as count")
|
||||||
.stream()
|
.eq("service_name", serviceName)
|
||||||
.collect(Collectors.groupingBy(SyncLogDO::getStatus, Collectors.counting()));
|
.groupBy("status"));
|
||||||
|
|
||||||
|
// 转换为Map结构
|
||||||
|
Map<Integer, Long> statusCounts = statusCountsList.stream()
|
||||||
|
.filter(map -> map.get("status") != null && map.get("count") != null)
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
map -> (Integer) map.get("status"),
|
||||||
|
map -> {
|
||||||
|
Object countObj = map.get("count");
|
||||||
|
return countObj instanceof Number ? ((Number) countObj).longValue() : 0L;
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
Map<String, Object> progress = new HashMap<>();
|
Map<String, Object> progress = new HashMap<>();
|
||||||
progress.put("serviceName", serviceName);
|
progress.put("serviceName", serviceName);
|
||||||
|
|||||||
Reference in New Issue
Block a user