fix:文件打标签重构
This commit is contained in:
@@ -3,6 +3,7 @@ package com.sdm.data.model.entity;
|
||||
import java.time.LocalDateTime;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.sdm.common.entity.req.data.SimulationPoolInfo;
|
||||
@@ -225,4 +226,8 @@ public class FileMetadataInfo implements Serializable {
|
||||
@Schema(description= "仿真任务池信息列表")
|
||||
@TableField(exist = false)
|
||||
private List<PoolInfo> poolInfos;
|
||||
|
||||
@Schema(description = "字典标签查询结果缓存(用于审批流程)", hidden = true)
|
||||
@TableField(exist = false)
|
||||
private Map<String, Map<String, Integer>> dictTagIdsCache;
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Schema(description = "更新文件请求参数")
|
||||
@@ -56,7 +57,7 @@ public class UpdateFileReq {
|
||||
// 很重要,用于设置标签
|
||||
@Schema(description = "字典标签查询结果缓存", hidden = true)
|
||||
@JSONField(serialize = false)
|
||||
private java.util.Map<String, java.util.Map<String, Integer>> dictTagIdsCache;
|
||||
private Map<String, Map<String, Integer>> dictTagIdsCache;
|
||||
|
||||
@Schema(description = "字典标签查询列表,格式:['fileTypeDictClass','fileTypeDictValue','disciplineTypeDictClass','disciplineDictValue']")
|
||||
private List<String> dictTags;
|
||||
|
||||
@@ -1499,7 +1499,8 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
fileUserPermissionService,
|
||||
fileStorageService,
|
||||
fileSimulationMappingService,
|
||||
paramObjectService
|
||||
paramObjectService,
|
||||
fileTagRelService // 新增:文件标签关系服务
|
||||
);
|
||||
|
||||
// 获取并执行审批结果
|
||||
@@ -2498,6 +2499,12 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
tempFileMetadataInfo.setCreateTime(fileMetadataInfo.getCreateTime());
|
||||
tempFileMetadataInfo.setUpdaterId(ThreadLocalContext.getUserId());
|
||||
tempFileMetadataInfo.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
// 保存标签缓存到 tempFileMetadataInfo(如果有)
|
||||
if (CollectionUtils.isNotEmpty(req.getDictTags()) && req.getDictTagIdsCache() != null) {
|
||||
tempFileMetadataInfo.setDictTagIdsCache(req.getDictTagIdsCache());
|
||||
}
|
||||
|
||||
fileMetadataInfo.setTempMetadata(JSONObject.toJSONString(tempFileMetadataInfo));
|
||||
fileMetadataInfo.setUpdateTime(LocalDateTime.now());
|
||||
fileMetadataInfo.setUpdaterId(ThreadLocalContext.getUserId());
|
||||
@@ -2586,6 +2593,11 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
|
||||
fileMetadataInfoService.save(newFileInfo);
|
||||
|
||||
// 创建文件标签关系(如果有)
|
||||
if (CollectionUtils.isNotEmpty(req.getDictTags())) {
|
||||
updateFileTags(req, newFileInfo, dirMetadataInfo);
|
||||
}
|
||||
|
||||
//绑定文件和工况库的关系
|
||||
if (CollectionUtils.isNotEmpty(req.getSimulationPoolInfoList())) {
|
||||
for (SimulationPoolInfo simulationPoolInfo : req.getSimulationPoolInfoList()) {
|
||||
|
||||
@@ -20,4 +20,5 @@ public class ApproveContext {
|
||||
private IFileStorageService fileStorageService;
|
||||
private IFileSimulationMappingService fileSimulationMappingService;
|
||||
private ISimulationParameterLibraryCategoryObjectService paramObjectService;
|
||||
private IFileTagRelService fileTagRelService; // 新增:用于标签关系管理
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public class ModifyFileApproveStrategy implements ApproveStrategy {
|
||||
IFileUserPermissionService fileUserPermissionService = context.getFileUserPermissionService();
|
||||
IFileStorageService fileStorageService = context.getFileStorageService();
|
||||
IFileSimulationMappingService fileSimulationMappingService = context.getFileSimulationMappingService();
|
||||
IFileTagRelService fileTagRelService = context.getFileTagRelService();
|
||||
|
||||
// 最新的历史版本为
|
||||
FileMetadataInfo historyMetaData = service.lambdaQuery()
|
||||
@@ -61,6 +62,9 @@ public class ModifyFileApproveStrategy implements ApproveStrategy {
|
||||
fileUserPermissionService.remove(new LambdaQueryWrapper<FileUserPermission>().eq(FileUserPermission::getTFilemetaId, metadata.getId()));
|
||||
fileStorageService.remove(new LambdaQueryWrapper<FileStorage>().eq(FileStorage::getFileId, metadata.getId()));
|
||||
fileSimulationMappingService.remove(new LambdaQueryWrapper<FileSimulationMapping>().eq(FileSimulationMapping::getFileId, metadata.getId()));
|
||||
// 删除文件标签关系
|
||||
fileTagRelService.remove(new LambdaQueryWrapper<FileTagRel>().eq(FileTagRel::getFileId, metadata.getId()));
|
||||
|
||||
if (historyMetaData != null) {
|
||||
historyMetaData.setTempMetadata(null);
|
||||
historyMetaData.setIsLatest(true);
|
||||
|
||||
@@ -7,13 +7,17 @@ import com.sdm.common.entity.enums.ApproveFileDataTypeEnum;
|
||||
import com.sdm.common.entity.req.data.SimulationPoolInfo;
|
||||
import com.sdm.data.model.entity.FileMetadataInfo;
|
||||
import com.sdm.data.model.entity.FileSimulationMapping;
|
||||
import com.sdm.data.model.entity.FileTagRel;
|
||||
import com.sdm.data.service.IFileMetadataInfoService;
|
||||
import com.sdm.data.service.IFileSimulationMappingService;
|
||||
import com.sdm.data.service.IFileTagRelService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -25,6 +29,7 @@ public class ModifyMetadataApproveStrategy implements ApproveStrategy {
|
||||
int status = context.getApproveStatus();
|
||||
IFileMetadataInfoService service = context.getFileMetadataInfoService();
|
||||
IFileSimulationMappingService fileSimulationMappingService = context.getFileSimulationMappingService();
|
||||
IFileTagRelService fileTagRelService = context.getFileTagRelService();
|
||||
|
||||
// 审批通过
|
||||
if (NumberConstants.TWO == status) {
|
||||
@@ -57,6 +62,12 @@ public class ModifyMetadataApproveStrategy implements ApproveStrategy {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理标签更新(如果 tempMetadata 中包含标签信息)
|
||||
if (updateInfo.getDictTagIdsCache() != null && !updateInfo.getDictTagIdsCache().isEmpty()) {
|
||||
updateFileTagsAfterApproval(metadata, updateInfo, fileTagRelService);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -71,4 +82,66 @@ public class ModifyMetadataApproveStrategy implements ApproveStrategy {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 审批通过后更新文件标签
|
||||
* 从 updateInfo 中获取标签信息并更新到 file_tag_rel 表
|
||||
*/
|
||||
private void updateFileTagsAfterApproval(FileMetadataInfo metadata, FileMetadataInfo updateInfo,
|
||||
IFileTagRelService fileTagRelService) {
|
||||
try {
|
||||
Long tenantId = metadata.getTenantId();
|
||||
Long creatorId = metadata.getCreatorId();
|
||||
Long fileId = metadata.getId();
|
||||
|
||||
// 从 updateInfo 中获取标签缓存
|
||||
Map<String, Map<String, Integer>> dictTagIdsCache = updateInfo.getDictTagIdsCache();
|
||||
if (dictTagIdsCache == null || dictTagIdsCache.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 删除旧标签关系(只删除当前租户的)
|
||||
fileTagRelService.lambdaUpdate()
|
||||
.eq(FileTagRel::getTenantId, tenantId)
|
||||
.eq(FileTagRel::getFileId, fileId)
|
||||
.remove();
|
||||
|
||||
// 构建新标签关系
|
||||
List<FileTagRel> newTagRelList = new ArrayList<>();
|
||||
Long dirId = updateInfo.getParentId();
|
||||
Long fileSize = updateInfo.getFileSize() != null ? updateInfo.getFileSize() : 0L;
|
||||
|
||||
for (Map.Entry<String, Map<String, Integer>> classEntry : dictTagIdsCache.entrySet()) {
|
||||
Map<String, Integer> valueMap = classEntry.getValue();
|
||||
|
||||
for (Integer dictId : valueMap.values()) {
|
||||
if (dictId == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 注意:这里只为当前文件所在目录创建标签关系
|
||||
// 如果需要为祖先目录也创建,需要从 metadata 中获取 parentId 并递归查询
|
||||
if (dirId != null) {
|
||||
FileTagRel tagRel = new FileTagRel();
|
||||
tagRel.setFileId(fileId);
|
||||
tagRel.setTagId(dictId);
|
||||
tagRel.setDirId(dirId);
|
||||
tagRel.setTenantId(tenantId);
|
||||
tagRel.setCreatorId(creatorId);
|
||||
tagRel.setFileSize(fileSize);
|
||||
newTagRelList.add(tagRel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 批量插入新标签关系
|
||||
if (CollectionUtils.isNotEmpty(newTagRelList)) {
|
||||
fileTagRelService.saveBatch(newTagRelList);
|
||||
log.info("Approved and updated file tags for fileId: {}, total: {} tags", fileId, newTagRelList.size());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to update file tags after approval for fileId: {}", metadata.getId(), e);
|
||||
// 不抛出异常,避免影响审批流程
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user