Merge branch 'feature/REQ-2326' into 'master'
Feature/req 2326 See merge request universal/infrastructure/backend/oss!136
This commit is contained in:
commit
d5e228c9e6
@ -0,0 +1,37 @@
|
||||
package cn.axzo.oss.common.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* @Author xudawei
|
||||
* @Date 2024/4/8
|
||||
* @Description url处理
|
||||
**/
|
||||
public class UrlUtil {
|
||||
|
||||
|
||||
public static String HTTP = "http:";
|
||||
public static String HTTPS = "https:";
|
||||
|
||||
/**
|
||||
* http的url替换成https
|
||||
*/
|
||||
public static String httpToHttps(String str) {
|
||||
if (StringUtils.isBlank(str)) {
|
||||
return str;
|
||||
}
|
||||
if (str.startsWith(HTTP)) {
|
||||
return HTTPS + str.substring(str.indexOf(HTTP) + HTTP.length());
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String str = "http://axzo-test.oss-cn-chengdu.aliyuncs.com/reportCenter/reportCenter_test";
|
||||
String str1 = "https://baidu.com";
|
||||
System.out.println(httpToHttps(str));
|
||||
System.out.println(httpToHttps(str1));
|
||||
}
|
||||
|
||||
}
|
||||
@ -3,6 +3,7 @@ package cn.axzo.oss.dal.repository;
|
||||
import cn.axzo.oss.dal.entity.AppChannelBucket;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -32,5 +33,5 @@ public interface AppChannelBucketDao extends IService<AppChannelBucket> {
|
||||
/**
|
||||
* 通过appChannelBucketNo集合,获取文件渠道桶信息
|
||||
*/
|
||||
List<AppChannelBucket> getByAppChannelBucketNos(List<String> appChannelBucketNos);
|
||||
List<AppChannelBucket> getByAppChannelBucketNos(Set<String> appChannelBucketNos);
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import cn.axzo.oss.dal.entity.FileBusinessScene;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -28,5 +29,5 @@ public interface FileBusinessSceneDao extends IService<FileBusinessScene> {
|
||||
/**
|
||||
* 根据bucketNo与场景,获取批量FileBusinessScene对象
|
||||
*/
|
||||
List<FileBusinessScene> queryByBucketNoAndScene(List<String> bucketNoList, String bizScen);
|
||||
List<FileBusinessScene> queryByBucketNoAndScene(Set<String> bucketNoList, String bizScen);
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import cn.axzo.oss.dal.repository.AppChannelBucketDao;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -57,7 +58,7 @@ public class AppChannelBucketDaoImpl extends
|
||||
* 通过appChannelBucketNo集合,获取文件渠道桶信息
|
||||
*/
|
||||
@Override
|
||||
public List<AppChannelBucket> getByAppChannelBucketNos(List<String> appChannelBucketNos) {
|
||||
public List<AppChannelBucket> getByAppChannelBucketNos(Set<String> appChannelBucketNos) {
|
||||
if (CollectionUtils.isEmpty(appChannelBucketNos)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import org.springframework.stereotype.Repository;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -41,12 +42,12 @@ public class FileBusinessSceneDaoImpl extends
|
||||
* 根据bucketNo与场景,获取批量FileBusinessScene对象
|
||||
*/
|
||||
@Override
|
||||
public List<FileBusinessScene> queryByBucketNoAndScene(List<String> bucketNoList, String bizScene) {
|
||||
if (CollectionUtils.isEmpty(bucketNoList) || StringUtils.isBlank(bizScene)) {
|
||||
public List<FileBusinessScene> queryByBucketNoAndScene(Set<String> bucketNoList, String bizScene) {
|
||||
if (CollectionUtils.isEmpty(bucketNoList)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
return lambdaQuery().in(FileBusinessScene::getAppChannelBucketNo, bucketNoList)
|
||||
.eq(FileBusinessScene::getBusinessScene,bizScene)
|
||||
.eq(StringUtils.isNotBlank(bizScene), FileBusinessScene::getBusinessScene, StringUtils.isNotBlank(bizScene) ? bizScene : StringUtils.EMPTY)
|
||||
.eq(FileBusinessScene::getIsDelete, IsDeleteEnum.NO.getCode()).list();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package cn.axzo.oss.manager.api;
|
||||
|
||||
import cn.axzo.oss.dal.entity.AppChannelBucket;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author: zhangran
|
||||
@ -27,5 +28,5 @@ public interface AppChannelBucketManager {
|
||||
/**
|
||||
* 通过appChannelBucketNo集合,获取文件渠道桶信息
|
||||
*/
|
||||
List<AppChannelBucket> getByAppChannelBucketNos(List<String> appChannelBucketNos);
|
||||
List<AppChannelBucket> getByAppChannelBucketNos(Set<String> appChannelBucketNos);
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package cn.axzo.oss.manager.api;
|
||||
import cn.axzo.oss.dal.entity.FileBusinessScene;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author: zhangran
|
||||
@ -23,5 +24,5 @@ public interface FileBusinessSceneManager {
|
||||
/**
|
||||
* 指定appcode文件业务场景
|
||||
*/
|
||||
List<FileBusinessScene> queryByBucketNoAndScene(List<String> bucketNoList, String bizScene);
|
||||
List<FileBusinessScene> queryByBucketNoAndScene(Set<String> bucketNoList, String bizScene);
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ 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 java.util.Set;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -66,7 +67,7 @@ public class AppChannelBucketManagerImpl implements AppChannelBucketManager {
|
||||
* 通过appChannelBucketNo集合,获取文件渠道桶信息
|
||||
*/
|
||||
@Override
|
||||
public List<AppChannelBucket> getByAppChannelBucketNos(List<String> appChannelBucketNos) {
|
||||
public List<AppChannelBucket> getByAppChannelBucketNos(Set<String> appChannelBucketNos) {
|
||||
if (CollectionUtils.isEmpty(appChannelBucketNos)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author: zhangran
|
||||
@ -45,8 +46,8 @@ public class FileBusinessSceneManagerImpl implements FileBusinessSceneManager {
|
||||
* 根据bucketNo与场景,获取批量FileBusinessScene对象
|
||||
*/
|
||||
@Override
|
||||
public List<FileBusinessScene> queryByBucketNoAndScene(List<String> bucketNoList, String bizScene) {
|
||||
if (CollectionUtils.isEmpty(bucketNoList) || StringUtils.isBlank(bizScene)) {
|
||||
public List<FileBusinessScene> queryByBucketNoAndScene(Set<String> bucketNoList, String bizScene) {
|
||||
if (CollectionUtils.isEmpty(bucketNoList)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
return fileBusinessSceneDao
|
||||
|
||||
@ -7,6 +7,7 @@ import cn.axzo.oss.common.enums.FileUploadTypeEnum;
|
||||
import cn.axzo.oss.common.enums.StorageUnitEnum;
|
||||
import cn.axzo.oss.common.exception.BizException;
|
||||
import cn.axzo.oss.common.utils.BeanConvertUtil;
|
||||
import cn.axzo.oss.common.utils.UrlUtil;
|
||||
import cn.axzo.oss.integration.s3.AliOssService;
|
||||
import cn.axzo.oss.integration.s3.HuaWeiCloudService;
|
||||
import cn.axzo.oss.manager.api.FileManager;
|
||||
@ -171,17 +172,17 @@ public class FileManagerImpl implements FileManager {
|
||||
TemporarySignatureResponse response = huaWeiCloudService.uploadSignUrl(bucketName, key, expireSecond, contentType);
|
||||
|
||||
return SignUrlUploadVo.builder()
|
||||
.signUrl(response.getSignedUrl())
|
||||
.signUrl(UrlUtil.httpToHttps(response.getSignedUrl()))
|
||||
.host(response.getActualSignedRequestHeaders().get(HUAWEI_CLOUD_SIGNURL_UPLOAD_HOST_KEY))
|
||||
.contentType(response.getActualSignedRequestHeaders().get(HUAWEI_CLOUD_SIGNURL_UPLOAD_CONTENT_TYPE_KEY))
|
||||
.channelCode(channelCode)
|
||||
.downloadSignUrl(this.downloadHuaweiSignUrl(bucketName, key, expireSecond, bucketType, fileName))
|
||||
.downloadSignUrl(UrlUtil.httpToHttps(this.downloadHuaweiSignUrl(bucketName, key, expireSecond, bucketType, fileName)))
|
||||
.build();
|
||||
case OSS:// 阿里云
|
||||
return SignUrlUploadVo.builder()
|
||||
.signUrl(aliOssService.uploadSignUrl(bucketName, key, fileName,expireSecond))
|
||||
.signUrl(UrlUtil.httpToHttps(aliOssService.uploadSignUrl(bucketName, key, fileName,expireSecond)))
|
||||
.channelCode(channelCode)
|
||||
.downloadSignUrl(this.downloadAliyunSignUrl(bucketName, key, expireSecond, bucketType, fileName))
|
||||
.downloadSignUrl(UrlUtil.httpToHttps(this.downloadAliyunSignUrl(bucketName, key, expireSecond, bucketType, fileName)))
|
||||
.build();
|
||||
default:
|
||||
BizException.error(CodeEnum.CHANNEL_TYPE_NOT_EXIST);
|
||||
|
||||
@ -15,6 +15,7 @@ import cn.axzo.oss.common.enums.FileStatusEnum;
|
||||
import cn.axzo.oss.common.enums.FileUploadTypeEnum;
|
||||
import cn.axzo.oss.common.exception.BizException;
|
||||
import cn.axzo.oss.common.utils.JsonUtil;
|
||||
import cn.axzo.oss.common.utils.UrlUtil;
|
||||
import cn.axzo.oss.common.utils.Utility;
|
||||
import cn.axzo.oss.dal.entity.AppChannelBucket;
|
||||
import cn.axzo.oss.dal.entity.File;
|
||||
@ -464,7 +465,7 @@ public class FileServiceImpl implements FileService {
|
||||
private Map<String, String> buildBucketTypeMap(List<File> fileList) {
|
||||
Map<String, String> bucketTypeMap = Maps.newHashMap();
|
||||
if (!CollectionUtils.isEmpty(fileList)) {
|
||||
List<AppChannelBucket> appChannelBucketList = this.appChannelBucketManager.getByAppChannelBucketNos(fileList.stream().map(File::getAppChannelBucketNo).collect(Collectors.toList()));
|
||||
List<AppChannelBucket> appChannelBucketList = this.appChannelBucketManager.getByAppChannelBucketNos(fileList.stream().map(File::getAppChannelBucketNo).collect(Collectors.toSet()));
|
||||
if (!CollectionUtils.isEmpty(appChannelBucketList)) {
|
||||
bucketTypeMap = appChannelBucketList.stream().collect(Collectors.toMap(AppChannelBucket::getAppChannelBucketNo, AppChannelBucket::getBucketType));
|
||||
}
|
||||
@ -837,17 +838,18 @@ public class FileServiceImpl implements FileService {
|
||||
}
|
||||
|
||||
//通过appChannelBucketNo集合,获取文件渠道桶信息
|
||||
List<AppChannelBucket> appChannelBucketList = appChannelBucketManager.getByAppChannelBucketNos(fileList.stream().map(File::getAppChannelBucketNo).collect(Collectors.toList()));
|
||||
List<AppChannelBucket> appChannelBucketList = appChannelBucketManager.getByAppChannelBucketNos(fileList.stream().map(File::getAppChannelBucketNo).collect(Collectors.toSet()));
|
||||
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());
|
||||
List<FileBusinessScene> fileBusinessSceneList = fileBusinessSceneManager.queryByBucketNoAndScene(fileList.stream().map(File::getAppChannelBucketNo).collect(Collectors.toSet()), dto.getBizScene());
|
||||
Map<String, Long> bizSceneExpireMap = fileBusinessSceneList.stream().collect(Collectors.toMap(FileBusinessScene::getAppChannelBucketNo, FileBusinessScene::getDownloadExpiration, (x, y) -> y));
|
||||
|
||||
List<SignUrlDownloadResponse> responseList = fileList.stream().map(item -> {
|
||||
Long expire = bizSceneExpireMap.get(item.getAppChannelBucketNo());
|
||||
// bucket下的key
|
||||
String tgtFileKey = Utility.generateFileKey(item.getDirectory(), item.getFileUuid(), item.getFileFormat());
|
||||
switch (BucketTypeEnum.getByCode(bucketTypeMap.get(item.getAppChannelBucketNo()))) {
|
||||
String bucketType = StringUtils.isNotBlank(bucketTypeMap.get(item.getAppChannelBucketNo())) ? bucketTypeMap.get(item.getAppChannelBucketNo()) : BucketTypeEnum.PRIVATE_BUCKET.getCode();
|
||||
switch (BucketTypeEnum.getByCode(bucketType)) {
|
||||
case PUBLIC_BUCKET:
|
||||
String url = this.fileManager.fetchDownloadUrl(item.getBucketName(), tgtFileKey, item.getChannelCode());
|
||||
return SignUrlDownloadResponse.builder()
|
||||
@ -857,7 +859,7 @@ public class FileServiceImpl implements FileService {
|
||||
case PRIVATE_BUCKET:
|
||||
String signUrl = this.fileManager.signUrlDownload(item.getBucketName(), tgtFileKey, Objects.nonNull(expire) ? expire : SIGN_URL_DOWNLOAD_EXPIRE_SECOND , item.getChannelCode(), item.getFileName());
|
||||
return SignUrlDownloadResponse.builder()
|
||||
.signUrl(signUrl)
|
||||
.signUrl(UrlUtil.httpToHttps(signUrl))
|
||||
.fileKey(item.getFileUuid())
|
||||
.build();
|
||||
default:
|
||||
@ -945,12 +947,12 @@ public class FileServiceImpl implements FileService {
|
||||
this.saveOssFile(fileUploadConfig, dto.getFileName(), fileFormat, uuid,
|
||||
signUrlUpload.getDownloadSignUrl(), Utility.getMd5(signUrlUpload.getDownloadSignUrl()), expiration);
|
||||
return SignUrlUploadResponse.builder()
|
||||
.signUrl(signUrlUpload.getSignUrl())
|
||||
.signUrl(UrlUtil.httpToHttps(signUrlUpload.getSignUrl()))
|
||||
.fileKey(uuid)
|
||||
.contentType(signUrlUpload.getContentType())
|
||||
.host(signUrlUpload.getHost())
|
||||
.channelCode(signUrlUpload.getChannelCode())
|
||||
.downloadSignUrl(signUrlUpload.getDownloadSignUrl())
|
||||
.downloadSignUrl(UrlUtil.httpToHttps(signUrlUpload.getDownloadSignUrl()))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user