临时授权-私有桶与公有桶返回路径处理

This commit is contained in:
xudawei 2024-03-25 14:30:53 +08:00
parent 4a20517829
commit f3cc4cfa1e
11 changed files with 101 additions and 3 deletions

View File

@ -0,0 +1,39 @@
package cn.axzo.oss.common.enums;
import lombok.Getter;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* 桶类型,public:公有桶;private:私有桶
*
* @author xudawei
* @since 2024/3/25
**/
@Getter
public enum BucketTypeEnum {
PUBLIC_BUCKET("public", "公有桶"),
PRIVATE_BUCKET("private", "私有桶"),
;
private final String code;
private final String message;
private final static Map<String, BucketTypeEnum> channelCodeMap = Arrays.stream(BucketTypeEnum.values()).collect(Collectors.toMap(BucketTypeEnum::getCode, Function.identity()));
BucketTypeEnum(String code, String message) {
this.code = code;
this.message = message;
}
/**
* 通过code获取枚举
*/
public static BucketTypeEnum getByCode(String channelCode) {
return channelCodeMap.get(channelCode);
}
}

View File

@ -102,6 +102,12 @@ public class AppChannelBucket extends Model<AppChannelBucket> {
@TableField("is_delete")
private Integer isDelete;
/**
* 桶类型,public:公有桶;private:私有桶
*/
@TableField("bucket_type")
private String bucketType;
@Override
protected Serializable pkVal() {

View File

@ -27,4 +27,10 @@ public interface AppChannelBucketDao extends IService<AppChannelBucket> {
* appCode+channelCode+bucketName唯一索引
*/
List<AppChannelBucket> getByAppCodeChannelCodeBucket(String appCode, String channelCode, String bucketName);
/**
* 通过appChannelBucketNo集合获取文件渠道桶信息
*/
List<AppChannelBucket> getByAppChannelBucketNos(List<String> appChannelBucketNos);
}

View File

@ -9,8 +9,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import java.util.Objects;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
/**
* <p>
@ -50,4 +52,15 @@ public class AppChannelBucketDaoImpl extends
.eq(StringUtils.isNotBlank(bucketName), AppChannelBucket::getBucketName, bucketName)
.eq(AppChannelBucket::getIsDelete, IsDeleteEnum.NO.getCode()).list();
}
/**
* 通过appChannelBucketNo集合获取文件渠道桶信息
*/
@Override
public List<AppChannelBucket> getByAppChannelBucketNos(List<String> appChannelBucketNos) {
if (CollectionUtils.isEmpty(appChannelBucketNos)) {
return Lists.newArrayList();
}
return lambdaQuery().in(AppChannelBucket::getAppChannelBucketNo, appChannelBucketNos).list();
}
}

View File

@ -42,12 +42,12 @@ public class FileBusinessSceneDaoImpl extends
* 根据bucketNo与场景获取批量FileBusinessScene对象
*/
@Override
public List<FileBusinessScene> queryByBucketNoAndScene(List<String> bucketNoList, String bizScen) {
if (CollectionUtils.isEmpty(bucketNoList) || StringUtils.isBlank(bizScen)) {
public List<FileBusinessScene> queryByBucketNoAndScene(List<String> bucketNoList, String bizScene) {
if (CollectionUtils.isEmpty(bucketNoList) || StringUtils.isBlank(bizScene)) {
return Lists.newArrayList();
}
return lambdaQuery().in(FileBusinessScene::getAppChannelBucketNo, bucketNoList)
.eq(FileBusinessScene::getBusinessScene,bizScen)
.eq(FileBusinessScene::getBusinessScene,bizScene)
.eq(FileBusinessScene::getIsDelete, IsDeleteEnum.NO.getCode()).list();
}
}

View File

@ -6,6 +6,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;
import java.util.List;
/**
@ -23,6 +24,7 @@ public class ApiSignUrlDownloadRequest {
* 文件uuid
*/
@NotEmpty(message = "fileKeys not empty")
@Size(min = 1, max = 1000, message = "超过指定范围1-1000")
private List<String> fileKeys;
/**

View File

@ -23,4 +23,9 @@ public interface AppChannelBucketManager {
* 通过appcode获取文件渠道桶信息
*/
AppChannelBucket getByAppCodeChannelCodeBucket(String appCode, Integer channelType, String bucketName);
/**
* 通过appChannelBucketNo集合获取文件渠道桶信息
*/
List<AppChannelBucket> getByAppChannelBucketNos(List<String> appChannelBucketNos);
}

View File

@ -8,6 +8,7 @@ import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
/**
@ -25,6 +26,7 @@ public class SignUrlDownloadDto {
* 文件uuid
*/
@NotEmpty(message = "fileKeys not empty")
@Size(min = 1, max = 1000, message = "超过指定范围1-1000")
private List<String> fileKeys;
/**

View File

@ -9,9 +9,12 @@ import cn.axzo.oss.dal.repository.AppChannelBucketDao;
import cn.axzo.oss.manager.api.AppChannelBucketManager;
import cn.axzo.oss.manager.api.FileChannelManager;
import java.util.List;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
/**
* @author: zhangran
@ -58,4 +61,15 @@ public class AppChannelBucketManagerImpl implements AppChannelBucketManager {
return appChannelBuckets.get(0);
}
/**
* 通过appChannelBucketNo集合获取文件渠道桶信息
*/
@Override
public List<AppChannelBucket> getByAppChannelBucketNos(List<String> appChannelBucketNos) {
if (CollectionUtils.isEmpty(appChannelBucketNos)) {
return Lists.newArrayList();
}
return appChannelBucketDao.getByAppChannelBucketNos(appChannelBucketNos);
}
}

View File

@ -5,9 +5,12 @@ import cn.axzo.oss.common.exception.BizException;
import cn.axzo.oss.dal.entity.FileBusinessScene;
import cn.axzo.oss.dal.repository.FileBusinessSceneDao;
import cn.axzo.oss.manager.api.FileBusinessSceneManager;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
@ -43,6 +46,9 @@ public class FileBusinessSceneManagerImpl implements FileBusinessSceneManager {
*/
@Override
public List<FileBusinessScene> queryByBucketNoAndScene(List<String> bucketNoList, String bizScene) {
if (CollectionUtils.isEmpty(bucketNoList) || StringUtils.isBlank(bizScene)) {
return Lists.newArrayList();
}
return fileBusinessSceneDao
.queryByBucketNoAndScene(bucketNoList, bizScene);
}

View File

@ -740,6 +740,11 @@ public class FileServiceImpl implements FileService {
if (CollectionUtils.isEmpty(fileList)) {
return Lists.newArrayList();
}
//通过appChannelBucketNo集合获取文件渠道桶信息
List<AppChannelBucket> appChannelBucketList = appChannelBucketManager.getByAppChannelBucketNos(fileList.stream().map(File::getAppChannelBucketNo).collect(Collectors.toList()));
Map<String, String> bucketTypeMap = appChannelBucketList.stream().collect(Collectors.toMap(AppChannelBucket::getAppChannelBucketNo, AppChannelBucket::getBucketType, (x, y) -> y));
List<FileBusinessScene> fileBusinessSceneList = fileBusinessSceneManager.queryByBucketNoAndScene(fileList.stream().map(File::getAppChannelBucketNo).collect(Collectors.toList()), dto.getBizScene());
Map<String, Long> bizSceneExpireMap = fileBusinessSceneList.stream().collect(Collectors.toMap(FileBusinessScene::getAppChannelBucketNo, FileBusinessScene::getDownloadExpiration, (x, y) -> y));