forked from toolchaintechnologycenter/spdm-backend
数据总览 前端按钮权限设置
This commit is contained in:
@@ -98,6 +98,10 @@ public class FileMetadataInfo implements Serializable {
|
||||
@TableField(value = "creatorName", insertStrategy = FieldStrategy.NEVER,select = false,updateStrategy = FieldStrategy.NEVER)
|
||||
private String creatorName;
|
||||
|
||||
@Schema(description= "更新者名称,列表展示使用")
|
||||
@TableField(value = "updaterName", insertStrategy = FieldStrategy.NEVER,select = false,updateStrategy = FieldStrategy.NEVER)
|
||||
private String updaterName;
|
||||
|
||||
@Schema(description= "创建时间")
|
||||
@TableField("createTime")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
|
||||
@@ -21,4 +21,12 @@ public interface IFileUserPermissionService extends IService<FileUserPermission>
|
||||
* @return 是否有权限
|
||||
*/
|
||||
boolean hasFilePermission(Long fileId, Long userId, FilePermissionEnum permission);
|
||||
|
||||
/**
|
||||
* 获取文件权限位掩码
|
||||
* @param fileId 文件ID
|
||||
* @param userId 用户ID
|
||||
* @return 权限位掩码
|
||||
*/
|
||||
Integer getMergedPermission(Long fileId, Long userId);
|
||||
}
|
||||
|
||||
@@ -83,4 +83,48 @@ public class FileUserPermissionServiceImpl extends ServiceImpl<FileUserPermissio
|
||||
|
||||
return validPermission(parentId, userId, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getMergedPermission(Long fileId, Long userId) {
|
||||
if (fileId == null || userId == null) return (int) FilePermissionEnum.ZERO.getValue();
|
||||
|
||||
FileMetadataInfo fileInfo = fileMetadataInfoService.getById(fileId);
|
||||
if (fileInfo == null) return (int) FilePermissionEnum.ZERO.getValue();
|
||||
|
||||
// 1. 系统内置基础文件夹,通常给满权限
|
||||
for (DirTypeEnum dirType : DirTypeEnum.getInitSpmdDir()) {
|
||||
if (fileInfo.getOriginalName().equals(dirType.getDirName())) {
|
||||
return (int) FilePermissionEnum.ALL.getValue(); // 1|2|4|8|16 = 31 (全权限)
|
||||
}
|
||||
}
|
||||
|
||||
// 开始递归计算合并权限
|
||||
return calculateRecursiveMergedPermission(fileId, userId);
|
||||
}
|
||||
|
||||
private int calculateRecursiveMergedPermission(Long fileId, Long userId) {
|
||||
// 默认只读权限
|
||||
byte currentPerm = FilePermissionEnum.READ.getValue();
|
||||
|
||||
// 查询当前节点该用户的显式权限记录
|
||||
FileUserPermission userPermRecord = this.lambdaQuery()
|
||||
.eq(FileUserPermission::getTFilemetaId, fileId)
|
||||
.eq(FileUserPermission::getUserId, userId)
|
||||
.one();
|
||||
|
||||
if (userPermRecord != null) {
|
||||
currentPerm = userPermRecord.getPermission();
|
||||
}
|
||||
|
||||
// 获取父节点
|
||||
FileMetadataInfo currentFile = fileMetadataInfoService.getById(fileId);
|
||||
|
||||
// 如果有父级且不是根目录,则继续向上合并
|
||||
if (currentFile != null && currentFile.getParentId() != null && currentFile.getParentId() > 0) {
|
||||
// 使用 | (按位或) 合并当前权限与父级权限
|
||||
return (byte) (currentPerm | calculateRecursiveMergedPermission(currentFile.getParentId(), userId));
|
||||
}
|
||||
|
||||
return currentPerm;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,13 +57,11 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.assertj.core.util.DateUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
@@ -644,7 +642,20 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
setAnalysisDirectionName(files);
|
||||
setSimulationPoolAndTaskInfo(files);
|
||||
PageInfo<FileMetadataInfo> page = new PageInfo<>(files);
|
||||
return PageUtils.getJsonObjectSdmResponse(files, page);
|
||||
|
||||
long total = page.getTotal();
|
||||
List<FileMetadataInfoResp> dtoList = files.stream().map(entity -> {
|
||||
FileMetadataInfoResp dto = new FileMetadataInfoResp();
|
||||
BeanUtils.copyProperties(entity, dto);
|
||||
|
||||
//计算当前用户对该文件的综合权限位
|
||||
// 对于列表查询,如果层级很深,频繁递归会有性能问题。
|
||||
dto.setPermissionValue(fileUserPermissionService.getMergedPermission(entity.getId(), ThreadLocalContext.getUserId()));
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
PageInfo<FileMetadataInfoResp> page1 = new PageInfo<>(dtoList);
|
||||
page1.setTotal(total);
|
||||
return PageUtils.getJsonObjectSdmResponse(dtoList, page1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -661,6 +672,8 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
FileMetadataInfoResp fileMetadataInfoResp = new FileMetadataInfoResp();
|
||||
BeanUtils.copyProperties(fileMetadataInfo, fileMetadataInfoResp);
|
||||
|
||||
fileMetadataInfoResp.setPermissionValue(fileUserPermissionService.getMergedPermission(fileMetadataInfo.getId(), ThreadLocalContext.getUserId()));
|
||||
|
||||
return SdmResponse.success(fileMetadataInfoResp);
|
||||
}
|
||||
|
||||
@@ -707,6 +720,10 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
List<FileMetadataInfoResp> dtoList = list.stream().map(entity -> {
|
||||
FileMetadataInfoResp dto = new FileMetadataInfoResp();
|
||||
BeanUtils.copyProperties(entity, dto);
|
||||
|
||||
//计算当前用户对该文件的综合权限位
|
||||
// 对于列表查询,如果层级很深,频繁递归会有性能问题。
|
||||
dto.setPermissionValue(fileUserPermissionService.getMergedPermission(entity.getId(), ThreadLocalContext.getUserId()));
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
PageInfo<FileMetadataInfoResp> page1 = new PageInfo<>(dtoList);
|
||||
@@ -784,7 +801,12 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
newObjectKey = oldObjectKey.substring(0, oldObjectKey.lastIndexOf("/") + 1) + newName;
|
||||
|
||||
minioService.renameFile(oldObjectKey, newObjectKey,bucketName);
|
||||
fileMetadataInfoService.lambdaUpdate().set(FileMetadataInfo::getObjectKey, newObjectKey).set(FileMetadataInfo::getOriginalName, newName).eq(FileMetadataInfo::getId, fileId).update();
|
||||
fileMetadataInfoService.lambdaUpdate()
|
||||
.set(FileMetadataInfo::getObjectKey, newObjectKey)
|
||||
.set(FileMetadataInfo::getOriginalName, newName)
|
||||
.set(FileMetadataInfo::getUpdateTime, new Date())
|
||||
.set(FileMetadataInfo::getUpdaterId, ThreadLocalContext.getUserId())
|
||||
.eq(FileMetadataInfo::getId, fileId).update();
|
||||
return SdmResponse.success("重命名成功");
|
||||
} catch (Exception e) {
|
||||
log.error("重命名文件失败", e);
|
||||
@@ -944,7 +966,12 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
|
||||
try {
|
||||
minioService.renameFile(oldDirMinioObjectKey, newDirMinioObjectKey,dirMetadataInfo.getBucketName());
|
||||
fileMetadataInfoService.lambdaUpdate().set(FileMetadataInfo::getObjectKey, newDirMinioObjectKey).set(FileMetadataInfo::getOriginalName, req.getNewName()).eq(FileMetadataInfo::getId, dirMetadataInfo.getId()).update();
|
||||
fileMetadataInfoService.lambdaUpdate()
|
||||
.set(FileMetadataInfo::getObjectKey, newDirMinioObjectKey)
|
||||
.set(FileMetadataInfo::getOriginalName, req.getNewName())
|
||||
.set(FileMetadataInfo::getUpdateTime, new Date())
|
||||
.set(FileMetadataInfo::getUpdaterId, ThreadLocalContext.getUserId())
|
||||
.eq(FileMetadataInfo::getId, dirMetadataInfo.getId()).update();
|
||||
return SdmResponse.success("重命名目录成功");
|
||||
} catch (Exception e) {
|
||||
log.error("重命名目录失败", e);
|
||||
@@ -1522,13 +1549,14 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
fileMetadataInfoLambdaQueryChainWrapper.eq(FileMetadataInfo::getParentId, parentDirId);
|
||||
}
|
||||
List<FileMetadataInfo> list = fileMetadataInfoLambdaQueryChainWrapper.eq(FileMetadataInfo::getTenantId, ThreadLocalContext.getTenantId()).eq(FileMetadataInfo::getDataType, DataTypeEnum.DIRECTORY.getValue()).orderByDesc(FileMetadataInfo::getCreateTime).list();
|
||||
setCreatorNames(list);
|
||||
|
||||
List<FileMetadataInfoResp> dtoList = list.stream().map(entity -> {
|
||||
FileMetadataInfoResp dto = new FileMetadataInfoResp();
|
||||
BeanUtils.copyProperties(entity, dto);
|
||||
|
||||
// todo 后面接入用户系统设置
|
||||
dto.setCreatorName("");
|
||||
//计算当前用户对该文件的综合权限位
|
||||
// 对于列表查询,如果层级很深,频繁递归会有性能问题。
|
||||
dto.setPermissionValue(fileUserPermissionService.getMergedPermission(entity.getId(), ThreadLocalContext.getUserId()));
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
@@ -1577,10 +1605,11 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
tempFileMetadataInfo.setRemarks(req.getRemarks());
|
||||
tempFileMetadataInfo.setSimulationPoolInfoList(req.getSimulationPoolInfoList());
|
||||
tempFileMetadataInfo.setCreateTime(fileMetadataInfo.getCreateTime());
|
||||
tempFileMetadataInfo.setUpdateTime(fileMetadataInfo.getCreateTime());
|
||||
tempFileMetadataInfo.setUpdaterId(ThreadLocalContext.getUserId());
|
||||
tempFileMetadataInfo.setUpdateTime(LocalDateTime.now());
|
||||
fileMetadataInfo.setTempMetadata(JSONObject.toJSONString(tempFileMetadataInfo));
|
||||
fileMetadataInfo.setUpdateTime(LocalDateTime.now());
|
||||
fileMetadataInfo.setUpdaterId(ThreadLocalContext.getUserId());
|
||||
|
||||
//发起审批
|
||||
FileApproveRequestBuilder updateFileMetaIntoApproveRequestBuilder = FileApproveRequestBuilder.builder()
|
||||
@@ -1615,6 +1644,8 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
fileMetadataInfo.setProjectId(req.getProjectId());
|
||||
fileMetadataInfo.setAnalysisDirectionId(req.getAnalysisDirectionId());
|
||||
fileMetadataInfo.setRemarks(req.getRemarks());
|
||||
fileMetadataInfo.setUpdateTime(LocalDateTime.now());
|
||||
fileMetadataInfo.setUpdaterId(ThreadLocalContext.getUserId());
|
||||
}
|
||||
|
||||
fileMetadataInfoService.updateById(fileMetadataInfo);
|
||||
@@ -2172,12 +2203,20 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
try {
|
||||
if (ObjectUtils.isNotEmpty(list)) {
|
||||
// 提取去重的 creatorId
|
||||
List<Long> creatorIds = list.stream()
|
||||
List<Long> creatorIds = new ArrayList<>(list.stream()
|
||||
.map(FileMetadataInfo::getCreatorId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.toList());
|
||||
|
||||
List<Long> updaterIds = list.stream()
|
||||
.map(FileMetadataInfo::getUpdaterId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.toList();
|
||||
|
||||
creatorIds.addAll(updaterIds);
|
||||
|
||||
// 远程查询用户信息
|
||||
SdmResponse<List<CIDUserResp>> userListSdmRsp = sysUserFeignClient.listUserByIds(
|
||||
UserQueryReq.builder().userIds(creatorIds).build()
|
||||
@@ -2194,6 +2233,15 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
cidUser.getRealName()
|
||||
);
|
||||
fileMetadataInfo.setCreatorName(username);
|
||||
|
||||
Long updaterId = fileMetadataInfo.getUpdaterId();
|
||||
CIDUserResp cidUser1 = cidUserMap.get(updaterId);
|
||||
String username1 = Objects.isNull(cidUser1) ? "" : org.apache.commons.lang3.StringUtils.firstNonBlank(
|
||||
cidUser1.getNickname(),
|
||||
cidUser1.getUsername(),
|
||||
cidUser1.getRealName()
|
||||
);
|
||||
fileMetadataInfo.setUpdaterName(username1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user