fix:文件更新,复制原文件标签
This commit is contained in:
8
.idea/compiler.xml
generated
8
.idea/compiler.xml
generated
@@ -24,10 +24,10 @@
|
|||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
<processorPath useClasspath="false">
|
<processorPath useClasspath="false">
|
||||||
<entry name="$PROJECT_DIR$/../../mvn_repository/org/mapstruct/mapstruct-processor/1.5.2.Final/mapstruct-processor-1.5.2.Final.jar" />
|
<entry name="$MAVEN_REPOSITORY$/org/mapstruct/mapstruct-processor/1.5.2.Final/mapstruct-processor-1.5.2.Final.jar" />
|
||||||
<entry name="$PROJECT_DIR$/../../mvn_repository/org/mapstruct/mapstruct/1.5.2.Final/mapstruct-1.5.2.Final.jar" />
|
<entry name="$MAVEN_REPOSITORY$/org/mapstruct/mapstruct/1.5.2.Final/mapstruct-1.5.2.Final.jar" />
|
||||||
<entry name="$PROJECT_DIR$/../../mvn_repository/org/projectlombok/lombok/1.18.30/lombok-1.18.30.jar" />
|
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.30/lombok-1.18.30.jar" />
|
||||||
<entry name="$PROJECT_DIR$/../../mvn_repository/org/projectlombok/lombok-mapstruct-binding/0.2.0/lombok-mapstruct-binding-0.2.0.jar" />
|
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok-mapstruct-binding/0.2.0/lombok-mapstruct-binding-0.2.0.jar" />
|
||||||
</processorPath>
|
</processorPath>
|
||||||
<module name="data" />
|
<module name="data" />
|
||||||
</profile>
|
</profile>
|
||||||
|
|||||||
@@ -25,9 +25,28 @@ public class DictTagHelper {
|
|||||||
@Resource
|
@Resource
|
||||||
private ISysConfigFeignClient sysConfigFeignClient;
|
private ISysConfigFeignClient sysConfigFeignClient;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从对象中提取字典标签并查询,同时将结果缓存到对象的dictTagIdsCache字段
|
||||||
|
*
|
||||||
|
* @param obj 包含dictTags和dictTagIdsCache字段的对象
|
||||||
|
* @return Map<dictClass, Map<dictValue, dictId>>
|
||||||
|
*/
|
||||||
|
public Map<String, Map<String, Integer>> queryAndCacheDictTagIds(Object obj) {
|
||||||
|
Map<String, Map<String, Integer>> result = queryDictTagIds(obj);
|
||||||
|
|
||||||
|
// 将结果缓存到对象的dictTagIdsCache字段
|
||||||
|
if (!result.isEmpty()) {
|
||||||
|
setDictTagIdsCache(obj, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从对象中提取字典标签并查询对应的字典ID
|
* 从对象中提取字典标签并查询对应的字典ID
|
||||||
*
|
*
|
||||||
* @param obj 包含dictTags字段的对象
|
* @param obj 包含dictTags字段的对象
|
||||||
* @return Map<dictClass, Map<dictValue, dictId>>,查询失败或无数据返回空Map
|
* @return Map<dictClass, Map<dictValue, dictId>>,查询失败或无数据返回空Map
|
||||||
*/
|
*/
|
||||||
@@ -52,22 +71,6 @@ public class DictTagHelper {
|
|||||||
return queryDictIds(tagReqList);
|
return queryDictIds(tagReqList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 从对象中提取字典标签并查询,同时将结果缓存到对象的dictTagIdsCache字段
|
|
||||||
*
|
|
||||||
* @param obj 包含dictTags和dictTagIdsCache字段的对象
|
|
||||||
* @return Map<dictClass, Map<dictValue, dictId>>
|
|
||||||
*/
|
|
||||||
public Map<String, Map<String, Integer>> queryAndCacheDictTagIds(Object obj) {
|
|
||||||
Map<String, Map<String, Integer>> result = queryDictTagIds(obj);
|
|
||||||
|
|
||||||
// 将结果缓存到对象的dictTagIdsCache字段
|
|
||||||
if (!result.isEmpty()) {
|
|
||||||
setDictTagIdsCache(obj, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从对象获取dictTags字段值
|
* 从对象获取dictTags字段值
|
||||||
|
|||||||
@@ -32,6 +32,75 @@ public class FileDictTagQueryServiceImpl implements IFileDictTagQueryService {
|
|||||||
private final IFileTagRelService fileTagRelService;
|
private final IFileTagRelService fileTagRelService;
|
||||||
private final ISysConfigFeignClient sysConfigFeignClient;
|
private final ISysConfigFeignClient sysConfigFeignClient;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> void fillFileTagsForRespList(List<T> respList, Function<T, Long> idGetter) {
|
||||||
|
if (CollectionUtils.isEmpty(respList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 收集文件ID
|
||||||
|
List<Long> fileIds = respList.stream()
|
||||||
|
.map(idGetter)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
if (CollectionUtils.isEmpty(fileIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询聚合标签
|
||||||
|
Map<Long, FileDictTagsAggDTO> fileIdToTagsMap = queryByFileIds(fileIds);
|
||||||
|
if (MapUtils.isEmpty(fileIdToTagsMap)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 通过反射,将标签字段填充到 Resp 对象中(基于 FileDictTagEnum 的配置)
|
||||||
|
for (T resp : respList) {
|
||||||
|
Long fileId = idGetter.apply(resp);
|
||||||
|
if (fileId == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
FileDictTagsAggDTO tags = fileIdToTagsMap.get(fileId);
|
||||||
|
if (tags == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (FileDictTagEnum tagEnum : FileDictTagEnum.values()) {
|
||||||
|
String dictValues = getDictValuesByEnum(tags, tagEnum);
|
||||||
|
String dictNames = getDictNamesByEnum(tags, tagEnum);
|
||||||
|
if (dictValues == null && dictNames == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String dictClass = tagEnum.getDictClass();
|
||||||
|
String dictClassFieldName = tagEnum.getDictClassFieldName();
|
||||||
|
String dictValueFieldName = tagEnum.getDictValueFieldName();
|
||||||
|
String dictNameFieldName = tagEnum.getDictNameFieldName();
|
||||||
|
try {
|
||||||
|
// setXxxDictClass
|
||||||
|
String classSetterName = "set" + Character.toUpperCase(dictClassFieldName.charAt(0)) + dictClassFieldName.substring(1);
|
||||||
|
resp.getClass().getMethod(classSetterName, String.class)
|
||||||
|
.invoke(resp, dictClass);
|
||||||
|
// setXxxDictValue
|
||||||
|
if (dictValues != null) {
|
||||||
|
String valueSetterName = "set" + Character.toUpperCase(dictValueFieldName.charAt(0)) + dictValueFieldName.substring(1);
|
||||||
|
resp.getClass().getMethod(valueSetterName, String.class)
|
||||||
|
.invoke(resp, dictValues);
|
||||||
|
}
|
||||||
|
// setXxxDictName(如果存在)
|
||||||
|
if (dictNames != null) {
|
||||||
|
String nameSetterName = "set" + Character.toUpperCase(dictNameFieldName.charAt(0)) + dictNameFieldName.substring(1);
|
||||||
|
resp.getClass().getMethod(nameSetterName, String.class)
|
||||||
|
.invoke(resp, dictNames);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("填充文件标签信息失败, fileId: {}, respClass: {}, dictClass: {}, error: {}",
|
||||||
|
fileId, resp.getClass().getName(), dictClass, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Map<Long, FileDictTagsAggDTO> queryByFileIds(List<Long> fileIds) {
|
private Map<Long, FileDictTagsAggDTO> queryByFileIds(List<Long> fileIds) {
|
||||||
if (CollectionUtils.isEmpty(fileIds)) {
|
if (CollectionUtils.isEmpty(fileIds)) {
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
@@ -149,73 +218,6 @@ public class FileDictTagQueryServiceImpl implements IFileDictTagQueryService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> void fillFileTagsForRespList(List<T> respList, Function<T, Long> idGetter) {
|
|
||||||
if (CollectionUtils.isEmpty(respList)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 收集文件ID
|
|
||||||
List<Long> fileIds = respList.stream()
|
|
||||||
.map(idGetter)
|
|
||||||
.filter(Objects::nonNull)
|
|
||||||
.distinct()
|
|
||||||
.toList();
|
|
||||||
if (CollectionUtils.isEmpty(fileIds)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询聚合标签
|
|
||||||
Map<Long, FileDictTagsAggDTO> fileIdToTagsMap = queryByFileIds(fileIds);
|
|
||||||
if (MapUtils.isEmpty(fileIdToTagsMap)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 通过反射,将标签字段填充到 Resp 对象中(基于 FileDictTagEnum 的配置)
|
|
||||||
for (T resp : respList) {
|
|
||||||
Long fileId = idGetter.apply(resp);
|
|
||||||
if (fileId == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
FileDictTagsAggDTO tags = fileIdToTagsMap.get(fileId);
|
|
||||||
if (tags == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (FileDictTagEnum tagEnum : FileDictTagEnum.values()) {
|
|
||||||
String dictValues = getDictValuesByEnum(tags, tagEnum);
|
|
||||||
String dictNames = getDictNamesByEnum(tags, tagEnum);
|
|
||||||
if (dictValues == null && dictNames == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String dictClass = tagEnum.getDictClass();
|
|
||||||
String dictClassFieldName = tagEnum.getDictClassFieldName();
|
|
||||||
String dictValueFieldName = tagEnum.getDictValueFieldName();
|
|
||||||
String dictNameFieldName = tagEnum.getDictNameFieldName();
|
|
||||||
try {
|
|
||||||
// setXxxDictClass
|
|
||||||
String classSetterName = "set" + Character.toUpperCase(dictClassFieldName.charAt(0)) + dictClassFieldName.substring(1);
|
|
||||||
resp.getClass().getMethod(classSetterName, String.class)
|
|
||||||
.invoke(resp, dictClass);
|
|
||||||
// setXxxDictValue
|
|
||||||
if (dictValues != null) {
|
|
||||||
String valueSetterName = "set" + Character.toUpperCase(dictValueFieldName.charAt(0)) + dictValueFieldName.substring(1);
|
|
||||||
resp.getClass().getMethod(valueSetterName, String.class)
|
|
||||||
.invoke(resp, dictValues);
|
|
||||||
}
|
|
||||||
// setXxxDictName(如果存在)
|
|
||||||
if (dictNames != null) {
|
|
||||||
String nameSetterName = "set" + Character.toUpperCase(dictNameFieldName.charAt(0)) + dictNameFieldName.substring(1);
|
|
||||||
resp.getClass().getMethod(nameSetterName, String.class)
|
|
||||||
.invoke(resp, dictNames);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("填充文件标签信息失败, fileId: {}, respClass: {}, dictClass: {}, error: {}",
|
|
||||||
fileId, resp.getClass().getName(), dictClass, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据枚举类型,从聚合结果中取出对应的字典值
|
* 根据枚举类型,从聚合结果中取出对应的字典值
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2443,6 +2443,27 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果未传递新的字典标签,则从原有文件获取并填充
|
||||||
|
if (CollectionUtils.isEmpty(req.getDictTags())) {
|
||||||
|
fileDictTagQueryService.fillFileTagsForRespList(List.of(req), UpdateFileReq::getId);
|
||||||
|
|
||||||
|
// 如果成功填充了标签值,则设置 dictTags 列表,以便 dictTagHelper 能够识别
|
||||||
|
List<String> dictTags = buildDictTagsFromEnum(req);
|
||||||
|
|
||||||
|
if (!dictTags.isEmpty()) {
|
||||||
|
req.setDictTags(dictTags);
|
||||||
|
// 强制刷新缓存,确保后续逻辑能获取到ID
|
||||||
|
// 保存标签缓存到 tempFileMetadataInfo(如果有)
|
||||||
|
if (CollectionUtils.isNotEmpty(req.getDictTags())) {
|
||||||
|
Map<String, Map<String, Integer>> dictIdMap = req.getDictTagIdsCache();
|
||||||
|
if (dictIdMap == null || dictIdMap.isEmpty()) {
|
||||||
|
dictIdMap = dictTagHelper.queryAndCacheDictTagIds(req);
|
||||||
|
}
|
||||||
|
req.setDictTagIdsCache(dictIdMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FileMetadataInfo fileMetadataInfo = fileMetadataInfoService.lambdaQuery().eq(FileMetadataInfo::getId, req.getId()).one();
|
FileMetadataInfo fileMetadataInfo = fileMetadataInfoService.lambdaQuery().eq(FileMetadataInfo::getId, req.getId()).one();
|
||||||
if (fileMetadataInfo == null) {
|
if (fileMetadataInfo == null) {
|
||||||
return SdmResponse.failed("文件不存在");
|
return SdmResponse.failed("文件不存在");
|
||||||
@@ -2480,7 +2501,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
|||||||
tempFileMetadataInfo.setDictTagIdsCache(dictIdMap);
|
tempFileMetadataInfo.setDictTagIdsCache(dictIdMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fileMetadataInfo.setTempMetadata(JSONObject.toJSONString(tempFileMetadataInfo));
|
fileMetadataInfo.setTempMetadata(JSONObject.toJSONString(tempFileMetadataInfo));
|
||||||
fileMetadataInfo.setUpdateTime(LocalDateTime.now());
|
fileMetadataInfo.setUpdateTime(LocalDateTime.now());
|
||||||
fileMetadataInfo.setUpdaterId(ThreadLocalContext.getUserId());
|
fileMetadataInfo.setUpdaterId(ThreadLocalContext.getUserId());
|
||||||
@@ -2581,6 +2602,9 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
|||||||
FileMetadataInfo newFileInfo = createFileMetadata(newFileMinioObjectKey, req.getFileName(),
|
FileMetadataInfo newFileInfo = createFileMetadata(newFileMinioObjectKey, req.getFileName(),
|
||||||
req.getProjectId(), req.getAnalysisDirectionId(), req.getRemarks(), oldFileMetadataInfo.getParentId(), req.getFile().getSize()
|
req.getProjectId(), req.getAnalysisDirectionId(), req.getRemarks(), oldFileMetadataInfo.getParentId(), req.getFile().getSize()
|
||||||
);
|
);
|
||||||
|
newFileInfo.setRemarks(oldFileMetadataInfo.getRemarks());
|
||||||
|
newFileInfo.setProjectId(oldFileMetadataInfo.getProjectId());
|
||||||
|
newFileInfo.setAnalysisDirectionName(oldFileMetadataInfo.getAnalysisDirectionName());
|
||||||
newFileInfo.setFileGroupId(fileGroupId);
|
newFileInfo.setFileGroupId(fileGroupId);
|
||||||
newFileInfo.setVersionNo(versionNo + 1);
|
newFileInfo.setVersionNo(versionNo + 1);
|
||||||
|
|
||||||
@@ -2690,6 +2714,35 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> buildDictTagsFromEnum(UpdateFileReq req) {
|
||||||
|
List<String> dictTags = new ArrayList<>();
|
||||||
|
for (FileDictTagEnum tagEnum : FileDictTagEnum.values()) {
|
||||||
|
String classFieldName = tagEnum.getDictClassFieldName();
|
||||||
|
String valueFieldName = tagEnum.getDictValueFieldName();
|
||||||
|
|
||||||
|
String classValue = getFieldValue(req, classFieldName);
|
||||||
|
String valueValue = getFieldValue(req, valueFieldName);
|
||||||
|
|
||||||
|
if (StringUtils.hasText(classValue) && StringUtils.hasText(valueValue)) {
|
||||||
|
dictTags.add(classFieldName);
|
||||||
|
dictTags.add(valueFieldName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dictTags;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getFieldValue(Object obj, String fieldName) {
|
||||||
|
try {
|
||||||
|
Field field = obj.getClass().getDeclaredField(fieldName);
|
||||||
|
field.setAccessible(true);
|
||||||
|
Object value = field.get(obj);
|
||||||
|
return value != null ? value.toString() : null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Failed to get field value for {}", fieldName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public SdmResponse uploadAvatar(MultipartFile avatar) {
|
public SdmResponse uploadAvatar(MultipartFile avatar) {
|
||||||
@@ -3535,6 +3588,9 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
|||||||
fileSimulationMappingService.lambdaUpdate()
|
fileSimulationMappingService.lambdaUpdate()
|
||||||
.in(FileSimulationMapping::getFileId, failBusinessIds)
|
.in(FileSimulationMapping::getFileId, failBusinessIds)
|
||||||
.remove();
|
.remove();
|
||||||
|
|
||||||
|
// 6. 删除文件标签关系表
|
||||||
|
fileTagRelService.lambdaUpdate().in(FileTagRel::getFileId, failBusinessIds).remove();
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
CoreLogger.error("handleFailFiles error:{}", e.getMessage());
|
CoreLogger.error("handleFailFiles error:{}", e.getMessage());
|
||||||
@@ -4712,7 +4768,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
|||||||
metadata.setUpdateTime(LocalDateTime.now());
|
metadata.setUpdateTime(LocalDateTime.now());
|
||||||
fileMetadataInfoService.updateById(metadata);
|
fileMetadataInfoService.updateById(metadata);
|
||||||
|
|
||||||
// 6. 如果是文件,更新 Storage fullPath
|
// 6. 如果是文件,更新 fileStorage
|
||||||
if (Objects.equals(metadata.getDataType(), DataTypeEnum.FILE.getValue())) {
|
if (Objects.equals(metadata.getDataType(), DataTypeEnum.FILE.getValue())) {
|
||||||
fileStorageService.lambdaUpdate()
|
fileStorageService.lambdaUpdate()
|
||||||
.eq(FileStorage::getFileId, metadata.getId())
|
.eq(FileStorage::getFileId, metadata.getId())
|
||||||
|
|||||||
Reference in New Issue
Block a user