需求:知识库文件操作增加审批电子流
This commit is contained in:
@@ -2,6 +2,7 @@ package com.sdm.data.controller;
|
||||
|
||||
import com.sdm.common.common.SdmResponse;
|
||||
import com.sdm.common.entity.req.data.CreateDirReq;
|
||||
import com.sdm.common.entity.req.system.LaunchApproveReq;
|
||||
import com.sdm.common.entity.resp.data.FileMetadataInfoResp;
|
||||
import com.sdm.common.feign.inter.data.IDataFeignClient;
|
||||
import com.sdm.data.model.entity.FileMetadataInfo;
|
||||
@@ -45,6 +46,12 @@ public class DataFileController implements IDataFeignClient {
|
||||
return IDataFileService.createDir(req);
|
||||
}
|
||||
|
||||
@PostMapping("/approveDataFile")
|
||||
@Operation(summary = "知识库文件审批状态修改", description = "知识库文件审批状态修改")
|
||||
public SdmResponse approveDataFile(@RequestBody @Validated LaunchApproveReq req) {
|
||||
return IDataFileService.approveDataFile(req);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件夹
|
||||
*
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.sdm.data.model.bo;
|
||||
|
||||
import com.sdm.data.model.entity.FileMetadataInfo;
|
||||
import lombok.Data;
|
||||
|
||||
/* 知识库文件增加审批流程,传递给电子流平台内容变化的数据 */
|
||||
@Data
|
||||
public class ApprovalFileDataContentsModel {
|
||||
private Long id; //待审批的原始数据
|
||||
|
||||
private String contents;//变更的描述
|
||||
|
||||
private int approveAction;// approveAction-- 1:新增 2:修改 3:删除
|
||||
|
||||
private FileMetadataInfo beforeData;// 知识库文件变更的原始数据
|
||||
|
||||
private FileMetadataInfo afterData;// 知识库文件变后的数据,只有 approveAction为2的时候,才会有值
|
||||
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.sdm.data.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@@ -129,6 +126,14 @@ public class FileMetadataInfo implements Serializable {
|
||||
@TableField("fileSize")
|
||||
private Long fileSize;
|
||||
|
||||
@ApiModelProperty(value = "任务ID")
|
||||
@TableField("taskId")
|
||||
private String taskId;
|
||||
|
||||
@ApiModelProperty(value = "算列ID")
|
||||
@TableField("runId")
|
||||
private String runId;
|
||||
|
||||
@ApiModelProperty(value = "tag1")
|
||||
@TableField("tag1")
|
||||
private String tag1;
|
||||
@@ -168,4 +173,18 @@ public class FileMetadataInfo implements Serializable {
|
||||
@ApiModelProperty(value = "tag10")
|
||||
@TableField("tag10")
|
||||
private String tag10;
|
||||
|
||||
@ApiModelProperty(value = "approvalStatus")
|
||||
@TableField(value = "approvalStatus", updateStrategy = FieldStrategy.IGNORED)
|
||||
private String approvalStatus;
|
||||
|
||||
// 返回前端 approveType 非0的,前端禁止下载、编辑、删除
|
||||
@ApiModelProperty(value = "审核类型:0-审核完成,1-文件上传审核中,2-文件修改审核中,3-文件删除审核中")
|
||||
@TableField("approveType")
|
||||
private Integer approveType;
|
||||
|
||||
@ApiModelProperty(value = "tempMetadata")
|
||||
@TableField(value = "tempMetadata", updateStrategy = FieldStrategy.IGNORED)
|
||||
private String tempMetadata;
|
||||
|
||||
}
|
||||
|
||||
@@ -18,4 +18,11 @@ public class DelFileReq {
|
||||
// 0相对路径,1绝对路径
|
||||
@Schema(description = "路径类型: 0相对路径,1绝对路径", defaultValue = "0")
|
||||
private Integer type = 0;
|
||||
|
||||
@Schema(description = "知识库文件审批模板id")
|
||||
private String templateId;
|
||||
|
||||
@Schema(description = "知识库文件审批模板名称")
|
||||
private String templateName;
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.sdm.data.model.req;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -13,6 +14,7 @@ public class UpdateFileReq {
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "文件传输对象")
|
||||
@JSONField(serialize = false)
|
||||
private MultipartFile file;
|
||||
|
||||
|
||||
@@ -41,6 +43,13 @@ public class UpdateFileReq {
|
||||
@Schema(description = "备注信息")
|
||||
private String remarks;
|
||||
|
||||
@Schema(description = "知识库文件审批模板id")
|
||||
private String templateId;
|
||||
|
||||
@Schema(description = "知识库文件审批模板名称")
|
||||
private String templateName;
|
||||
|
||||
|
||||
/**
|
||||
* 扩展信息
|
||||
*/
|
||||
|
||||
@@ -78,6 +78,12 @@ public class UploadFilesReq {
|
||||
@Schema(description = "备注信息")
|
||||
private String remarks;
|
||||
|
||||
@Schema(description = "知识库文件审批模板id")
|
||||
private String templateId;
|
||||
|
||||
@Schema(description = "知识库文件审批模板名称")
|
||||
private String templateName;
|
||||
|
||||
/**
|
||||
* 扩展信息
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.sdm.data.service;
|
||||
|
||||
import com.sdm.common.common.SdmResponse;
|
||||
import com.sdm.common.entity.req.data.CreateDirReq;
|
||||
import com.sdm.common.entity.req.system.LaunchApproveReq;
|
||||
import com.sdm.common.entity.resp.data.FileMetadataInfoResp;
|
||||
import com.sdm.data.model.req.*;
|
||||
import com.sdm.data.model.resp.KKFileViewURLFromMinioResp;
|
||||
@@ -287,4 +288,11 @@ public interface IDataFileService {
|
||||
SdmResponse zipFiles(ZipFilesReq req);
|
||||
|
||||
|
||||
/**
|
||||
* 知识库审批结果回调
|
||||
* @param req 知识库审批结果回调请求参数
|
||||
* @return 知识库审批结果回调响应
|
||||
*/
|
||||
default SdmResponse approveDataFile(LaunchApproveReq req){return null;};
|
||||
|
||||
}
|
||||
@@ -9,23 +9,32 @@ import com.github.pagehelper.PageInfo;
|
||||
import com.sdm.common.common.Constants;
|
||||
import com.sdm.common.common.SdmResponse;
|
||||
import com.sdm.common.common.ThreadLocalContext;
|
||||
import com.sdm.common.entity.constants.NumberConstants;
|
||||
import com.sdm.common.entity.enums.ApprovalFileDataStatusEnum;
|
||||
import com.sdm.common.entity.enums.ApproveFileDataTypeEnum;
|
||||
import com.sdm.common.entity.req.data.CreateDirReq;
|
||||
import com.sdm.common.entity.req.project.DelNodeReq;
|
||||
import com.sdm.common.entity.req.project.RenameNodeReq;
|
||||
import com.sdm.common.entity.req.system.LaunchApproveReq;
|
||||
import com.sdm.common.entity.req.system.UserListReq;
|
||||
import com.sdm.common.entity.resp.PageDataResp;
|
||||
import com.sdm.common.entity.resp.data.FileMetadataInfoResp;
|
||||
import com.sdm.common.entity.resp.system.CIDUserResp;
|
||||
import com.sdm.common.feign.impl.project.SimulationNodeFeignClientImpl;
|
||||
import com.sdm.common.utils.PageUtils;
|
||||
import com.sdm.common.feign.impl.system.SysUserFeignClientImpl;
|
||||
import com.sdm.common.feign.inter.system.IApproveFeignClient;
|
||||
import com.sdm.common.utils.PageUtils;
|
||||
import com.sdm.data.model.bo.ApprovalFileDataContentsModel;
|
||||
import com.sdm.data.model.entity.FileMetadataExtension;
|
||||
import com.sdm.data.model.entity.FileMetadataInfo;
|
||||
import com.sdm.data.model.entity.FileStorage;
|
||||
import com.sdm.data.model.entity.FileUserPermission;
|
||||
import com.sdm.data.model.req.*;
|
||||
import com.sdm.common.entity.resp.data.FileMetadataInfoResp;
|
||||
import com.sdm.data.model.resp.KKFileViewURLFromMinioResp;
|
||||
import com.sdm.data.service.*;
|
||||
import com.sdm.data.service.impl.dataFileHandle.ApproveContext;
|
||||
import com.sdm.data.service.impl.dataFileHandle.ApproveStrategy;
|
||||
import com.sdm.data.service.impl.dataFileHandle.ApproveStrategyFactory;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
@@ -87,6 +96,11 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
@Autowired
|
||||
private DataStorageAnalysis dataStorageAnalysis;
|
||||
|
||||
@Autowired
|
||||
private ApproveStrategyFactory approveStrategyFactory;
|
||||
|
||||
@Autowired
|
||||
private IApproveFeignClient approveFeignClient;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
@@ -99,7 +113,6 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
if (req == null || !StringUtils.hasText(req.getDirName())) {
|
||||
return SdmResponse.failed("目录名称不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
// 处理根目录创建逻辑(知识库根目录创建逻辑和项目节点目录创建)
|
||||
if (ObjectUtils.isNull(req.getParDirId()) && ObjectUtils.isNull(req.getParentUuId())) {
|
||||
@@ -114,6 +127,102 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdmResponse approveDataFile(LaunchApproveReq req) {
|
||||
// 审批状态
|
||||
int approveStatus = req.approveStatus;
|
||||
// 前置校验
|
||||
validateApproveRequest(req);
|
||||
// id获取
|
||||
Long id = parseAndValidateMetaId(req);
|
||||
// 查询待审批的db里的数据
|
||||
FileMetadataInfo approveMetadataInfo = fileMetadataInfoService.lambdaQuery().eq(FileMetadataInfo::getId,id).one();
|
||||
if(Objects.isNull(approveMetadataInfo)){
|
||||
log.error("approveDataFile approveMetadataInfo null,param:{}", JSONObject.toJSONString(req));
|
||||
throw new RuntimeException("仿真知识库审批回调修改失败,未找到待审批数据");
|
||||
}
|
||||
|
||||
// 处理审批
|
||||
try {
|
||||
// 创建上下文
|
||||
ApproveContext context = new ApproveContext(
|
||||
approveMetadataInfo,
|
||||
approveStatus,
|
||||
minioService,
|
||||
fileMetadataInfoService,
|
||||
fileMetadataExtensionService,
|
||||
fileUserPermissionService
|
||||
);
|
||||
|
||||
// 获取并执行审批结果
|
||||
ApproveStrategy strategy = approveStrategyFactory.getStrategy(approveMetadataInfo.getApproveType());
|
||||
boolean result = strategy.handle(context);
|
||||
|
||||
return result ? SdmResponse.success("审批状态修改成功") :
|
||||
SdmResponse.failed("审批状态修改失败");
|
||||
} catch (Exception e) {
|
||||
log.error("approveDataFile handle error", e);
|
||||
return SdmResponse.failed("审批处理异常:" + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验审批回调请求参数的合法性
|
||||
* @param req 审批回调请求对象
|
||||
*/
|
||||
private void validateApproveRequest(LaunchApproveReq req) {
|
||||
// 校验审批类型(排除知识库审批)
|
||||
if (!Objects.equals(NumberConstants.TWO, req.approveType)) {
|
||||
String errorMsg = "仿真知识库审批回调修改失败,审批类型非法";
|
||||
log.error("{},param:{}", errorMsg, JSONObject.toJSONString(req));
|
||||
throw new RuntimeException(errorMsg);
|
||||
}
|
||||
|
||||
// 校验审批状态有效性
|
||||
if (!ApprovalFileDataStatusEnum.isValidCode(req.approveStatus)) {
|
||||
String errorMsg = "仿真知识库审批回调修改失败,审批状态非法";
|
||||
log.error("{},param:{}", errorMsg, JSONObject.toJSONString(req));
|
||||
throw new RuntimeException(errorMsg);
|
||||
}
|
||||
|
||||
// 校验审批内容不为空
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(req.approveContents)) {
|
||||
String errorMsg = "仿真知识库审批回调修改失败,审批内容非法";
|
||||
log.error("{},param:{}", errorMsg, JSONObject.toJSONString(req));
|
||||
throw new RuntimeException(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从审批内容中解析并校验 metaId(确保返回非 null 的 Long 类型)
|
||||
* @param req 审批请求对象(包含 approveContents)
|
||||
* @return 解析后的有效 metaId(Long 类型,非 null)
|
||||
* @throws RuntimeException 若 id 为空、格式非法则抛出异常
|
||||
*/
|
||||
private Long parseAndValidateMetaId(LaunchApproveReq req) {
|
||||
// 1. 解析审批内容为 Map
|
||||
String approveContents = req.approveContents;
|
||||
ApprovalFileDataContentsModel approvalModel=null;
|
||||
try {
|
||||
approvalModel = JSONObject.parseObject(approveContents, ApprovalFileDataContentsModel.class);
|
||||
} catch (Exception e) {
|
||||
String errorMsg = "仿真知识库审批回调修改失败,审批内容格式非法";
|
||||
log.error("{},param:{}", errorMsg, JSONObject.toJSONString(req), e);
|
||||
throw new RuntimeException(errorMsg);
|
||||
}
|
||||
|
||||
// 2. 提取 "id" 字段并校验非空
|
||||
Long metaId = approvalModel.getId();
|
||||
if (Objects.isNull(metaId)) {
|
||||
String errorMsg = "仿真知识库审批回调修改失败,审批参数id为空";
|
||||
log.error("{},param:{}", errorMsg, JSONObject.toJSONString(req));
|
||||
throw new RuntimeException(errorMsg);
|
||||
}
|
||||
return metaId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建根目录
|
||||
*
|
||||
@@ -122,7 +231,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
*/
|
||||
|
||||
public SdmResponse<?> createRootDir(CreateDirReq req) {
|
||||
if (ObjectUtils.isNull(req.getDirType())) {
|
||||
if(ObjectUtils.isNull(req.getDirType())){
|
||||
return SdmResponse.failed("请选择目录类型:1 知识库文件夹,2 项目节点文件夹,3 头像库文件夹,4 仿真参数库文件夹,5 训练模型文件夹");
|
||||
}
|
||||
|
||||
@@ -428,12 +537,22 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
if (!hasDeletePermission) {
|
||||
return SdmResponse.failed("没有删除权限");
|
||||
}
|
||||
|
||||
fileMetadataInfoService.removeById(delFileId);
|
||||
fileMetadataExtensionService.remove(new LambdaQueryWrapper<FileMetadataExtension>().eq(FileMetadataExtension::getTFilemetaId, delFileId));
|
||||
fileUserPermissionService.remove(new LambdaQueryWrapper<FileUserPermission>().eq(FileUserPermission::getTFilemetaId, delFileId));
|
||||
minioService.deleteFile(deleteFileMinioObejctKey);
|
||||
return SdmResponse.success("删除成功");
|
||||
// 发送审批电子流,成功继续西面操作,失败直接返回
|
||||
// String templateId, String templateName,String approveContents,int approveAction:1:新增 2:修改 3:删除
|
||||
String approveContents = getApproveContents(delFileId, "知识库文件删除", NumberConstants.THREE, deleteFileMetadataInfo, null);
|
||||
boolean approveResult = launchFileDataApprove(req.getTemplateId(), req.getTemplateName(), approveContents, NumberConstants.THREE);
|
||||
if(!approveResult) {
|
||||
log.error("delFile approveInit failed, params :{}", JSONObject.toJSONString(req));
|
||||
throw new RuntimeException("文件删除,创建审批流失败");
|
||||
}
|
||||
deleteFileMetadataInfo.setApprovalStatus(ApprovalFileDataStatusEnum.PENDING.getKey());
|
||||
deleteFileMetadataInfo.setApproveType(ApproveFileDataTypeEnum.DELETE_REVIEWING.getCode());
|
||||
fileMetadataInfoService.updateById(deleteFileMetadataInfo);
|
||||
// fileMetadataInfoService.removeById(delFileId);
|
||||
// fileMetadataExtensionService.remove(new LambdaQueryWrapper<FileMetadataExtension>().eq(FileMetadataExtension::getTFilemetaId, delFileId));
|
||||
// fileUserPermissionService.remove(new LambdaQueryWrapper<FileUserPermission>().eq(FileUserPermission::getTFilemetaId, delFileId));
|
||||
// minioService.deleteFile(deleteFileMinioObejctKey);
|
||||
return SdmResponse.success("操作成功,删除文件待审批");
|
||||
} catch (Exception e) {
|
||||
log.error("删除文件失败", e);
|
||||
throw new RuntimeException("删除文件失败: " + e.getMessage(), e);
|
||||
@@ -453,7 +572,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
}
|
||||
|
||||
if (fileMetadataInfo != null) {
|
||||
return SdmResponse.success();
|
||||
return SdmResponse.success();
|
||||
}
|
||||
|
||||
QueryBigFileReq queryBigFileReq = new QueryBigFileReq();
|
||||
@@ -799,7 +918,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
FileMetadataInfo fileMetadataInfo = fileMetadataInfoService.lambdaQuery().eq(FileMetadataInfo::getId, fileId).one();
|
||||
if (ObjectUtils.isEmpty(fileMetadataInfo)) {
|
||||
log.error("文件不存在");
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
String fileObjectKey = fileMetadataInfo.getObjectKey();
|
||||
|
||||
@@ -853,11 +972,24 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
// 创建目录元数据并保存到数据库
|
||||
FileMetadataInfo fileInfo = createFileMetadata(fileMinioObjectKey, req.getFileName(), req.getFileType(),
|
||||
req.getProjectId(), req.getAnalysisDirectionId(), req.getRemarks(), dirMetadataInfo.getId(), req.getFile().getSize());
|
||||
fileInfo.setApprovalStatus(ApprovalFileDataStatusEnum.PENDING.getKey());
|
||||
fileInfo.setApproveType(ApproveFileDataTypeEnum.UPLOAD_REVIEWING.getCode());
|
||||
fileMetadataInfoService.save(fileInfo);
|
||||
|
||||
fileInfo.setFileGroupId(fileInfo.getId());
|
||||
fileMetadataInfoService.updateById(fileInfo);
|
||||
|
||||
// 调用审批流,开启审批; 上面先入库拿到主键id,审批流创建失败后再回退数据
|
||||
// String templateId, String templateName,String approveContents,int approveAction:1:新增 2:修改 3:删除
|
||||
String approveContents = getApproveContents(fileInfo.getId(), "知识库文件新增", NumberConstants.ONE, fileInfo, null);
|
||||
boolean approveResult = launchFileDataApprove(req.getTemplateId(), req.getTemplateName(), approveContents, NumberConstants.ONE);
|
||||
if(!approveResult){
|
||||
log.error("uploadFiles create approveInit failed, params :{}", JSONObject.toJSONString(req));
|
||||
fileMetadataInfoService.removeById(fileInfo.getId());
|
||||
// - 回退MinIO中已上传的文件(删除该文件)。catch 里统一操作了
|
||||
//- 新增 file_metadata_info 信息不入表。
|
||||
//- 向前端返回“上传文件失败”。
|
||||
throw new RuntimeException("文件上传,创建审批流失败");
|
||||
}
|
||||
|
||||
// 创建文件扩展信息并保存到数据库
|
||||
List<FileMetadataExtension> fileMetadataExtensionList = new ArrayList<>();
|
||||
@@ -961,13 +1093,40 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
String oldFileMinioObjectKey = fileMetadataInfo.getObjectKey();
|
||||
Long fileGroupId = fileMetadataInfo.getFileGroupId();
|
||||
Long versionNo = fileMetadataInfo.getVersionNo();
|
||||
|
||||
// 修改待审批的元数据主键id
|
||||
if (ObjectUtils.isNull(req.getFile())) {
|
||||
FileMetadataInfo tempFileMetadataInfo = new FileMetadataInfo();
|
||||
BeanUtils.copyProperties(fileMetadataInfo, tempFileMetadataInfo);
|
||||
// 不需要上传minio新文件,只更新文件元数据
|
||||
fileMetadataInfo.setProjectId(req.getProjectId());
|
||||
fileMetadataInfo.setAnalysisDirectionId(req.getAnalysisDirectionId());
|
||||
fileMetadataInfo.setRemarks(req.getRemarks());
|
||||
tempFileMetadataInfo.setProjectId(req.getProjectId());
|
||||
tempFileMetadataInfo.setAnalysisDirectionId(req.getAnalysisDirectionId());
|
||||
tempFileMetadataInfo.setRemarks(req.getRemarks());
|
||||
|
||||
// fileMetadataInfo.setProjectId(req.getProjectId());
|
||||
// fileMetadataInfo.setAnalysisDirectionId(req.getAnalysisDirectionId());
|
||||
// fileMetadataInfo.setRemarks(req.getRemarks());
|
||||
// 增加审批的逻辑,先将原始数据改成待审核状态
|
||||
fileMetadataInfo.setApprovalStatus(ApprovalFileDataStatusEnum.PENDING.getKey());
|
||||
fileMetadataInfo.setApproveType(ApproveFileDataTypeEnum.MODIFY_METADATA_REVIEWING.getCode());
|
||||
// 获取前后变化的file信息
|
||||
String approveContents = getApproveContents(fileMetadataInfo.getId(), "知识库文件元数据修改",
|
||||
NumberConstants.TWO, fileMetadataInfo, tempFileMetadataInfo);
|
||||
// 本次待审核的数据
|
||||
fileMetadataInfo.setTempMetadata(JSONObject.toJSONString(tempFileMetadataInfo));
|
||||
|
||||
fileMetadataInfoService.updateById(fileMetadataInfo);
|
||||
// String templateId, String templateName,String approveContents,int approveAction:1:新增 2:修改 3:删除
|
||||
boolean approveResult = launchFileDataApprove(req.getTemplateId(), req.getTemplateName(), approveContents, NumberConstants.TWO);
|
||||
if(!approveResult){
|
||||
log.error("updateFile meteData approveInit failed, params :{}", JSONObject.toJSONString(req));
|
||||
// 失败数据回退
|
||||
fileMetadataInfo.setTempMetadata(null);
|
||||
fileMetadataInfo.setApprovalStatus(null);
|
||||
// 回退到已完成
|
||||
fileMetadataInfo.setApproveType(ApproveFileDataTypeEnum.COMPLETED.getCode());
|
||||
fileMetadataInfoService.updateById(fileMetadataInfo);
|
||||
throw new RuntimeException("文件元数据修改失败,创建审批流失败");
|
||||
}
|
||||
} else {
|
||||
// 需要上传minio新文件,更新文件元数据
|
||||
uploadAndUpdateFile(req, oldFileMinioObjectKey, fileMetadataInfo, versionNo, fileGroupId);
|
||||
@@ -1004,7 +1163,22 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
req.getProjectId(), req.getAnalysisDirectionId(), req.getRemarks(), fileMetadataInfo.getParentId(), req.getFile().getSize());
|
||||
fileInfo.setFileGroupId(fileGroupId);
|
||||
fileInfo.setVersionNo(versionNo + 1);
|
||||
// 修改了文件,增加审批相关字段
|
||||
// 增加审批的逻辑,先将原始数据改成待审核状态
|
||||
fileInfo.setApprovalStatus(ApprovalFileDataStatusEnum.PENDING.getKey());
|
||||
fileInfo.setApproveType(ApproveFileDataTypeEnum.MODIFY_REVIEWING.getCode());
|
||||
|
||||
fileMetadataInfoService.save(fileInfo);
|
||||
// 获取前后变化的file信息
|
||||
String approveContents = getApproveContents(fileInfo.getId(), "知识库文件修改",
|
||||
NumberConstants.TWO,fileMetadataInfo , fileInfo);
|
||||
boolean approveResult = launchFileDataApprove(req.getTemplateId(), req.getTemplateName(), approveContents, NumberConstants.TWO);
|
||||
if(!approveResult){
|
||||
log.error("uploadAndUpdateFile updateFile approveInit failed, params :{}", JSONObject.toJSONString(req));
|
||||
// 失败数据回退删除
|
||||
fileMetadataInfoService.removeById(fileInfo.getId());
|
||||
throw new RuntimeException("文件修改失败,创建审批流失败");
|
||||
}
|
||||
|
||||
// 创建文件扩展信息并保存到数据库
|
||||
List<FileMetadataExtension> fileMetadataExtensionList = new ArrayList<>();
|
||||
@@ -1318,5 +1492,59 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
}
|
||||
}
|
||||
|
||||
// 发起仿真知识库文件审核 true 成功 false失败
|
||||
private boolean launchFileDataApprove(String templateId, String templateName,String approveContents,int approveAction)
|
||||
{
|
||||
try {
|
||||
LaunchApproveReq req = new LaunchApproveReq();
|
||||
// 评审流程模版ID 前端传过来
|
||||
req.templateId = templateId;
|
||||
// req.templateId = "P202511041416483446SFON";
|
||||
// 模版名称 前端传过来
|
||||
req.templateName = templateName;
|
||||
// req.templateName = "仿真知识文档评审";
|
||||
// 审批内容 拼接json str {"id": "111","contents": "用户xx于YYYY-MM-dd hh:mm:ss 提交 xx 新增知识库文件"}
|
||||
req.approveContents = approveContents;
|
||||
// 评审动作 1:新增 2:修改 3:删除
|
||||
req.approveAction = approveAction;
|
||||
// 审批类型 1:仿真地图审批 2:知识库审批
|
||||
req.approveType = 2;
|
||||
// 审批主题
|
||||
req.approveTitle = "仿真知识库评审";
|
||||
// 租户ID
|
||||
req.tenantId = ThreadLocalContext.getTenantId();
|
||||
// req.tenantId = 1979091834410176514l;
|
||||
// 用户ID
|
||||
req.userId = ThreadLocalContext.getUserId();
|
||||
// req.userId = 1979078323595476993l;
|
||||
// 审批创建者
|
||||
req.creator = ThreadLocalContext.getUserId();
|
||||
// req.creator = 1979078323595476993l;
|
||||
SdmResponse response = approveFeignClient.launchApproval(req);
|
||||
return response.isSuccess();
|
||||
} catch (Exception e) {
|
||||
log.error("launchFileDataApprove error :{}",e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成包含 id 和 contents 的 JSON 字符串--审批创建的 approveContents
|
||||
*/
|
||||
public String getApproveContents(Long id, String contents,Integer approveAction,FileMetadataInfo beforeData,FileMetadataInfo afterData) {
|
||||
|
||||
ApprovalFileDataContentsModel contentsModel = new ApprovalFileDataContentsModel();
|
||||
contentsModel.setId(id);
|
||||
contentsModel.setContents(contents);
|
||||
contentsModel.setApproveAction(approveAction);
|
||||
contentsModel.setBeforeData(beforeData);
|
||||
// 只有修改有 afterData 值
|
||||
if(Objects.equals(NumberConstants.TWO,approveAction)){
|
||||
contentsModel.setAfterData(afterData);
|
||||
}
|
||||
// 转换为 JSON 字符串并返回
|
||||
return JSONObject.toJSONString(contentsModel);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.sdm.data.service.impl.dataFileHandle;
|
||||
|
||||
import com.sdm.data.model.entity.FileMetadataInfo;
|
||||
import com.sdm.data.service.IFileMetadataExtensionService;
|
||||
import com.sdm.data.service.IFileMetadataInfoService;
|
||||
import com.sdm.data.service.IFileUserPermissionService;
|
||||
import com.sdm.data.service.IMinioService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ApproveContext {
|
||||
private FileMetadataInfo approveMetadataInfo;
|
||||
private int approveStatus;
|
||||
private IMinioService minioService;
|
||||
private IFileMetadataInfoService fileMetadataInfoService;
|
||||
private IFileMetadataExtensionService fileMetadataExtensionService;
|
||||
private IFileUserPermissionService fileUserPermissionService;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.sdm.data.service.impl.dataFileHandle;
|
||||
|
||||
public interface ApproveStrategy {
|
||||
/**
|
||||
* 处理审批逻辑
|
||||
* approveMetadataInfo 待审批的元数据
|
||||
* approveStatus 审批状态(2-通过,3-不通过)
|
||||
* @return 处理结果
|
||||
*/
|
||||
boolean handle(ApproveContext context);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.sdm.data.service.impl.dataFileHandle;
|
||||
|
||||
import com.sdm.common.entity.constants.NumberConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ApproveStrategyFactory {
|
||||
|
||||
private final Map<Integer, ApproveStrategy> strategyMap;
|
||||
|
||||
// 构造函数注入所有策略实现
|
||||
public ApproveStrategyFactory(List<ApproveStrategy> strategies) {
|
||||
this.strategyMap = new HashMap<>();
|
||||
// 手动绑定策略类型与实现类(也可通过注解+反射实现自动绑定)
|
||||
for (ApproveStrategy strategy : strategies) {
|
||||
if (strategy instanceof UploadApproveStrategy) {
|
||||
strategyMap.put(NumberConstants.ONE, strategy);
|
||||
} else if (strategy instanceof ModifyFileApproveStrategy) {
|
||||
strategyMap.put(NumberConstants.TWO, strategy);
|
||||
} else if (strategy instanceof DeleteApproveStrategy) {
|
||||
strategyMap.put(NumberConstants.THREE, strategy);
|
||||
} else if (strategy instanceof ModifyMetadataApproveStrategy) {
|
||||
strategyMap.put(NumberConstants.FOUR, strategy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取策略
|
||||
public ApproveStrategy getStrategy(int approveType) {
|
||||
ApproveStrategy strategy = strategyMap.get(approveType);
|
||||
if (strategy == null) {
|
||||
log.error("ApproveStrategy not found for approveType: {}" ,approveType);
|
||||
throw new RuntimeException("未找到对应的审批策略,类型:" + approveType);
|
||||
}
|
||||
return strategy;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.sdm.data.service.impl.dataFileHandle;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.sdm.common.entity.constants.NumberConstants;
|
||||
import com.sdm.common.entity.enums.ApproveFileDataTypeEnum;
|
||||
import com.sdm.data.model.entity.FileMetadataExtension;
|
||||
import com.sdm.data.model.entity.FileMetadataInfo;
|
||||
import com.sdm.data.model.entity.FileUserPermission;
|
||||
import com.sdm.data.service.IFileMetadataExtensionService;
|
||||
import com.sdm.data.service.IFileMetadataInfoService;
|
||||
import com.sdm.data.service.IFileUserPermissionService;
|
||||
import com.sdm.data.service.IMinioService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DeleteApproveStrategy implements ApproveStrategy {
|
||||
@Override
|
||||
public boolean handle(ApproveContext context) {
|
||||
FileMetadataInfo metadata = context.getApproveMetadataInfo();
|
||||
int status = context.getApproveStatus();
|
||||
IFileMetadataInfoService service = context.getFileMetadataInfoService();
|
||||
IMinioService minioService = context.getMinioService();
|
||||
IFileMetadataExtensionService fileMetadataExtensionService = context.getFileMetadataExtensionService();
|
||||
IFileUserPermissionService fileUserPermissionService = context.getFileUserPermissionService();
|
||||
|
||||
// 审批通过
|
||||
if (NumberConstants.TWO == status) {
|
||||
// 删除MinIO文件
|
||||
minioService.deleteFile(metadata.getObjectKey());
|
||||
// 删除数据库记录
|
||||
service.removeById(metadata.getId());
|
||||
fileMetadataExtensionService.remove(new LambdaQueryWrapper<FileMetadataExtension>().eq(FileMetadataExtension::getTFilemetaId, metadata.getId()));
|
||||
fileUserPermissionService.remove(new LambdaQueryWrapper<FileUserPermission>().eq(FileUserPermission::getTFilemetaId, metadata.getId()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 审批不通过
|
||||
if (NumberConstants.THREE == status) {
|
||||
// 恢复状态
|
||||
metadata.setTempMetadata(null);
|
||||
metadata.setApprovalStatus(null);
|
||||
metadata.setApproveType(ApproveFileDataTypeEnum.COMPLETED.getCode());
|
||||
metadata.setUpdateTime(LocalDateTime.now());
|
||||
service.updateById(metadata);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.sdm.data.service.impl.dataFileHandle;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.sdm.common.entity.constants.NumberConstants;
|
||||
import com.sdm.common.entity.enums.ApproveFileDataTypeEnum;
|
||||
import com.sdm.data.model.entity.FileMetadataExtension;
|
||||
import com.sdm.data.model.entity.FileMetadataInfo;
|
||||
import com.sdm.data.model.entity.FileUserPermission;
|
||||
import com.sdm.data.service.IFileMetadataExtensionService;
|
||||
import com.sdm.data.service.IFileMetadataInfoService;
|
||||
import com.sdm.data.service.IFileUserPermissionService;
|
||||
import com.sdm.data.service.IMinioService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ModifyFileApproveStrategy implements ApproveStrategy {
|
||||
@Override
|
||||
public boolean handle(ApproveContext context) {
|
||||
FileMetadataInfo metadata = context.getApproveMetadataInfo();
|
||||
int status = context.getApproveStatus();
|
||||
IFileMetadataInfoService service = context.getFileMetadataInfoService();
|
||||
IMinioService minioService = context.getMinioService();
|
||||
IFileMetadataExtensionService fileMetadataExtensionService = context.getFileMetadataExtensionService();
|
||||
IFileUserPermissionService fileUserPermissionService = context.getFileUserPermissionService();
|
||||
|
||||
|
||||
// 审批通过
|
||||
if (NumberConstants.TWO == status) {
|
||||
metadata.setApprovalStatus(null);
|
||||
metadata.setApproveType(ApproveFileDataTypeEnum.COMPLETED.getCode());
|
||||
service.updateById(metadata);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 审批不通过
|
||||
if (NumberConstants.THREE == status) {
|
||||
// 删除MinIO中修改的文件
|
||||
minioService.deleteFile(metadata.getObjectKey());
|
||||
// 删除修改产生的新记录
|
||||
service.removeById(metadata.getId());
|
||||
fileMetadataExtensionService.remove(new LambdaQueryWrapper<FileMetadataExtension>().eq(FileMetadataExtension::getTFilemetaId, metadata.getId()));
|
||||
fileUserPermissionService.remove(new LambdaQueryWrapper<FileUserPermission>().eq(FileUserPermission::getTFilemetaId, metadata.getId()));
|
||||
|
||||
|
||||
// 恢复历史版本为最新
|
||||
FileMetadataInfo historyMetaData = service.lambdaQuery()
|
||||
.eq(FileMetadataInfo::getFileGroupId, metadata.getFileGroupId())
|
||||
.orderByDesc(FileMetadataInfo::getUpdateTime)
|
||||
.last("limit 1")
|
||||
.one();
|
||||
|
||||
if (historyMetaData != null) {
|
||||
historyMetaData.setTempMetadata(null);
|
||||
historyMetaData.setIsLatest(true);
|
||||
historyMetaData.setApprovalStatus(null);
|
||||
historyMetaData.setApproveType(ApproveFileDataTypeEnum.COMPLETED.getCode());
|
||||
historyMetaData.setUpdateTime(LocalDateTime.now());
|
||||
service.updateById(historyMetaData);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.sdm.data.service.impl.dataFileHandle;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.sdm.common.entity.constants.NumberConstants;
|
||||
import com.sdm.common.entity.enums.ApproveFileDataTypeEnum;
|
||||
import com.sdm.data.model.entity.FileMetadataInfo;
|
||||
import com.sdm.data.service.IFileMetadataInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ModifyMetadataApproveStrategy implements ApproveStrategy {
|
||||
@Override
|
||||
public boolean handle(ApproveContext context) {
|
||||
FileMetadataInfo metadata = context.getApproveMetadataInfo();
|
||||
int status = context.getApproveStatus();
|
||||
IFileMetadataInfoService service = context.getFileMetadataInfoService();
|
||||
|
||||
// 审批通过
|
||||
if (NumberConstants.TWO == status) {
|
||||
// 从临时字段获取修改内容并更新
|
||||
String tempMetadata = metadata.getTempMetadata();
|
||||
FileMetadataInfo updateInfo = JSONObject.parseObject(tempMetadata, FileMetadataInfo.class);
|
||||
updateInfo.setTempMetadata(null);
|
||||
updateInfo.setApprovalStatus(null);
|
||||
updateInfo.setApproveType(ApproveFileDataTypeEnum.COMPLETED.getCode());
|
||||
service.updateById(updateInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 审批不通过
|
||||
if (NumberConstants.THREE == status) {
|
||||
// 清除临时数据
|
||||
metadata.setTempMetadata(null);
|
||||
metadata.setApprovalStatus(null);
|
||||
metadata.setApproveType(ApproveFileDataTypeEnum.COMPLETED.getCode());
|
||||
service.updateById(metadata);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.sdm.data.service.impl.dataFileHandle;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.sdm.common.entity.constants.NumberConstants;
|
||||
import com.sdm.common.entity.enums.ApproveFileDataTypeEnum;
|
||||
import com.sdm.data.model.entity.FileMetadataExtension;
|
||||
import com.sdm.data.model.entity.FileMetadataInfo;
|
||||
import com.sdm.data.model.entity.FileUserPermission;
|
||||
import com.sdm.data.service.IFileMetadataExtensionService;
|
||||
import com.sdm.data.service.IFileMetadataInfoService;
|
||||
import com.sdm.data.service.IFileUserPermissionService;
|
||||
import com.sdm.data.service.IMinioService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UploadApproveStrategy implements ApproveStrategy {
|
||||
@Override
|
||||
public boolean handle(ApproveContext context) {
|
||||
FileMetadataInfo metadata = context.getApproveMetadataInfo();
|
||||
int status = context.getApproveStatus();
|
||||
IFileMetadataInfoService service = context.getFileMetadataInfoService();
|
||||
IMinioService minioService = context.getMinioService();
|
||||
IFileMetadataExtensionService fileMetadataExtensionService = context.getFileMetadataExtensionService();
|
||||
IFileUserPermissionService fileUserPermissionService = context.getFileUserPermissionService();
|
||||
|
||||
|
||||
// 审批通过
|
||||
if (NumberConstants.TWO == status) {
|
||||
metadata.setApprovalStatus(null);
|
||||
metadata.setApproveType(ApproveFileDataTypeEnum.COMPLETED.getCode());
|
||||
service.updateById(metadata);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 审批不通过
|
||||
if (NumberConstants.THREE == status) {
|
||||
// 删除MinIO文件
|
||||
minioService.deleteFile(metadata.getObjectKey());
|
||||
// 删除数据库记录
|
||||
service.removeById(metadata.getId());
|
||||
fileMetadataExtensionService.remove(new LambdaQueryWrapper<FileMetadataExtension>().eq(FileMetadataExtension::getTFilemetaId, metadata.getId()));
|
||||
fileUserPermissionService.remove(new LambdaQueryWrapper<FileUserPermission>().eq(FileUserPermission::getTFilemetaId, metadata.getId()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user