feat: 对象存储oss服务完善
This commit is contained in:
@@ -74,34 +74,5 @@
|
||||
<artifactId>schisandra-cloud-storage-oss-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!--minio-->
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
<version>8.2.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- 阿里云 -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<scope>provided</scope>
|
||||
<version>3.14.0</version>
|
||||
</dependency>
|
||||
<!-- 亚马逊 -->
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>s3</artifactId>
|
||||
<version>2.17.160</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- 百度云对象存储 -->
|
||||
<dependency>
|
||||
<groupId>com.baidubce</groupId>
|
||||
<artifactId>bce-java-sdk</artifactId>
|
||||
<version>0.10.196</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@@ -30,8 +30,6 @@ public class AliOssConfiguration {
|
||||
|
||||
@Resource
|
||||
SchisandraOssAliDomainService schisandraOssAliDomainService;
|
||||
@Resource
|
||||
AliOssClient aliOssClient;
|
||||
|
||||
public StandardOssClient aliOssClient(String userId) {
|
||||
CompletableFuture<SchisandraOssAliDTO> futurePrice = CompletableFuture.supplyAsync(() -> {
|
||||
@@ -79,9 +77,7 @@ public class AliOssConfiguration {
|
||||
}
|
||||
|
||||
public StandardOssClient aliOssClient(AliOssConfig aliOssConfig) {
|
||||
aliOssClient.setAliOssConfig(aliOssConfig);
|
||||
aliOssClient.setOss(ossClient(aliOssConfig));
|
||||
return aliOssClient;
|
||||
return new AliOssClient(ossClient(aliOssConfig), aliOssConfig);
|
||||
}
|
||||
|
||||
public OSS ossClient(AliOssConfig aliOssConfig) {
|
||||
|
@@ -43,7 +43,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* https://docs.aws.amazon.com/s3/
|
||||
* @author 陈敏
|
||||
* @author landaiqing
|
||||
* @version AwsOssClient.java, v 1.0 2022/4/1 18:05 chenmin Exp $
|
||||
* Created on 2022/4/1
|
||||
*/
|
||||
|
@@ -18,7 +18,7 @@ import software.amazon.awssdk.services.s3.S3Client;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author 陈敏
|
||||
* @author landaiqing
|
||||
* @version AwsOssConfiguration.java, v 1.0 2022/4/1 18:02 chenmin Exp $
|
||||
* Created on 2022/4/1
|
||||
*/
|
||||
|
@@ -3,7 +3,7 @@ package com.schisandra.oss.application.oss.core.aws.constant;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
|
||||
/**
|
||||
* @author 陈敏
|
||||
* @author landaiqing
|
||||
* @version Region.java, v 1.0 2022/4/1 23:05 chenmin Exp $
|
||||
* Created on 2022/4/1
|
||||
*/
|
||||
|
@@ -3,7 +3,7 @@ package com.schisandra.oss.application.oss.core.aws.model;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author 陈敏
|
||||
* @author landaiqing
|
||||
* @version AwsOssClientConfig.java, v 1.0 2022/4/2 16:05 chenmin Exp $
|
||||
* Created on 2022/4/2
|
||||
*/
|
||||
|
@@ -8,7 +8,7 @@ import lombok.Data;
|
||||
import software.amazon.awssdk.awscore.defaultsmode.DefaultsMode;
|
||||
|
||||
/**
|
||||
* @author 陈敏
|
||||
* @author landaiqing
|
||||
* @version AwsOssConfig.java, v 1.0 2022/4/1 18:05 chenmin Exp $
|
||||
* Created on 2022/4/1
|
||||
*/
|
||||
|
@@ -1,63 +0,0 @@
|
||||
package com.schisandra.oss.application.oss.core.baidu;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baidubce.auth.DefaultBceCredentials;
|
||||
import com.baidubce.services.bos.BosClient;
|
||||
import com.baidubce.services.bos.BosClientConfiguration;
|
||||
import com.schisandra.oss.application.convert.SchisandraOssBaiduDTOConverter;
|
||||
import com.schisandra.oss.application.dto.SchisandraOssBaiduDTO;
|
||||
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||
import com.schisandra.oss.application.oss.core.baidu.model.BaiduOssClientConfig;
|
||||
import com.schisandra.oss.application.oss.core.baidu.model.BaiduOssConfig;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssBaiduBO;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssBaiduDomainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author 陈敏
|
||||
* @version BaiduConfiguration.java, v 1.1 2021/11/24 15:26 chenmin Exp $
|
||||
* Created on 2021/11/24
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class BaiduOssConfiguration {
|
||||
|
||||
@Resource
|
||||
private SchisandraOssBaiduDomainService schisandraOssBaiduDomainService;
|
||||
|
||||
|
||||
public StandardOssClient baiduOssClient(String userId) {
|
||||
SchisandraOssBaiduBO schisandraOssBaiduBO = schisandraOssBaiduDomainService.getBaiduOssConfig(userId);
|
||||
SchisandraOssBaiduDTO schisandraOssBaiduDTO = SchisandraOssBaiduDTOConverter.INSTANCE.convertBOToDTO(schisandraOssBaiduBO);
|
||||
if (ObjectUtil.isEmpty(schisandraOssBaiduDTO)) {
|
||||
log.error("Baidu oss配置信息获取失败");
|
||||
return null;
|
||||
}
|
||||
String accessKeyId = schisandraOssBaiduDTO.getAccessKeyId();
|
||||
String secretAccessKey = schisandraOssBaiduDTO.getSecretAccessKey();
|
||||
BaiduOssConfig baiduOssConfig = new BaiduOssConfig();
|
||||
baiduOssConfig.setAccessKeyId(accessKeyId);
|
||||
baiduOssConfig.setSecretAccessKey(secretAccessKey);
|
||||
return baiduOssClient(baiduOssConfig);
|
||||
}
|
||||
|
||||
public StandardOssClient baiduOssClient(BaiduOssConfig baiduOssConfig) {
|
||||
return new BaiduOssClient(bosClient(bosClientConfiguration(baiduOssConfig)), baiduOssConfig);
|
||||
}
|
||||
|
||||
public BosClientConfiguration bosClientConfiguration(BaiduOssConfig baiduOssConfig) {
|
||||
BaiduOssClientConfig clientConfig = Optional.ofNullable(baiduOssConfig.getClientConfig()).orElse(new BaiduOssClientConfig());
|
||||
BosClientConfiguration bosClientConfiguration = clientConfig.toClientConfig();
|
||||
bosClientConfiguration.setCredentials(new DefaultBceCredentials(baiduOssConfig.getAccessKeyId(), baiduOssConfig.getSecretAccessKey()));
|
||||
return bosClientConfiguration;
|
||||
}
|
||||
|
||||
public BosClient bosClient(BosClientConfiguration config) {
|
||||
return new BosClient(config);
|
||||
}
|
||||
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
package com.schisandra.oss.application.oss.core.baidu.constant;
|
||||
|
||||
/**
|
||||
* @author 陈敏
|
||||
* @version BaiduOssConstant.java, v 1.0 2022/4/20 16:19 chenmin Exp $
|
||||
* Created on 2022/4/20
|
||||
*/
|
||||
public class BaiduOssConstant {
|
||||
public static final String DEFAULT_ENDPOINT = "bj.bcebos.com";
|
||||
}
|
@@ -1,140 +0,0 @@
|
||||
package com.schisandra.oss.application.oss.core.baidu.model;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baidubce.BceClientConfiguration;
|
||||
import com.baidubce.Protocol;
|
||||
import com.baidubce.Region;
|
||||
import com.baidubce.http.DefaultRetryPolicy;
|
||||
import com.baidubce.http.RetryPolicy;
|
||||
import com.baidubce.services.bos.BosClientConfiguration;
|
||||
import com.schisandra.oss.application.oss.core.baidu.constant.BaiduOssConstant;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import static com.baidubce.BceClientConfiguration.*;
|
||||
import static com.baidubce.services.bos.BosClientConfiguration.DEFAULT_STREAM_BUFFER_SIZE;
|
||||
|
||||
/**
|
||||
* @author 陈敏
|
||||
* @version BaiduOssClientConfig.java, v 1.0 2022/4/20 16:19 chenmin Exp $
|
||||
* Created on 2022/4/20
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class BaiduOssClientConfig {
|
||||
/**
|
||||
* 使用cname访问BOS资源
|
||||
*/
|
||||
private boolean cnameEnabled;
|
||||
/**
|
||||
* 异步put
|
||||
*/
|
||||
private boolean enableHttpAsyncPut = true;
|
||||
/**
|
||||
* 建立连接的超时时间(单位:毫秒)
|
||||
*/
|
||||
private int connectionTimeoutInMillis = DEFAULT_CONNECTION_TIMEOUT_IN_MILLIS;
|
||||
/**
|
||||
* 允许打开的最大HTTP连接数
|
||||
*/
|
||||
private int maxConnections = DEFAULT_MAX_CONNECTIONS;
|
||||
/**
|
||||
* 连接协议类型
|
||||
*/
|
||||
private Protocol protocol = DEFAULT_PROTOCOL;
|
||||
/**
|
||||
* 访问NTLM验证的代理服务器的Windows域名
|
||||
*/
|
||||
private String proxyDomain;
|
||||
/**
|
||||
* 代理服务器主机地址
|
||||
*/
|
||||
private String proxyHost;
|
||||
/**
|
||||
* 代理服务器验证的密码
|
||||
*/
|
||||
private String proxyPassword;
|
||||
/**
|
||||
* 代理服务器端口
|
||||
*/
|
||||
private int proxyPort = -1;
|
||||
/**
|
||||
* 代理服务器验证的用户名
|
||||
*/
|
||||
private String proxyUsername;
|
||||
/**
|
||||
* NTLM代理服务器的Windows工作站名称
|
||||
*/
|
||||
private String proxyWorkstation;
|
||||
/**
|
||||
* 是否设置用户代理认证
|
||||
*/
|
||||
private boolean proxyPreemptiveAuthenticationEnabled;
|
||||
/**
|
||||
* 通过打开的连接传输数据的超时时间(单位:毫秒)
|
||||
*/
|
||||
private int socketTimeoutInMillis = DEFAULT_SOCKET_TIMEOUT_IN_MILLIS;
|
||||
/**
|
||||
* Socket缓冲区大小
|
||||
*/
|
||||
private int socketBufferSizeInBytes = 0;
|
||||
/**
|
||||
* 访问域名
|
||||
*/
|
||||
private String endpoint = BaiduOssConstant.DEFAULT_ENDPOINT;
|
||||
/**
|
||||
* 地域
|
||||
*/
|
||||
private Region region = DEFAULT_REGION;
|
||||
/**
|
||||
* 是否开启HTTP重定向。默认开启
|
||||
*/
|
||||
private boolean redirectsEnabled = true;
|
||||
/**
|
||||
* 本地地址
|
||||
*/
|
||||
private String localAddress;
|
||||
/**
|
||||
* 请求失败最大重试次数
|
||||
*/
|
||||
private int maxErrorRetry = RetryPolicy.DEFAULT_MAX_ERROR_RETRY;
|
||||
/**
|
||||
* 最大延迟时间,单位:毫秒
|
||||
*/
|
||||
private long maxDelayInMillis = RetryPolicy.DEFAULT_MAX_DELAY_IN_MILLIS;
|
||||
/**
|
||||
* 流文件缓冲区大小
|
||||
*/
|
||||
private int streamBufferSize = DEFAULT_STREAM_BUFFER_SIZE;
|
||||
/**
|
||||
* 用户代理,指HTTP的User-Agent头
|
||||
*/
|
||||
private String userAgent = BceClientConfiguration.DEFAULT_USER_AGENT;
|
||||
|
||||
public BosClientConfiguration toClientConfig() {
|
||||
BosClientConfiguration clientConfig = new BosClientConfiguration();
|
||||
BeanUtil.copyProperties(this, clientConfig, "proxyPort", "socketBufferSizeInBytes",
|
||||
"localAddress", "maxErrorRetry", "maxDelayInMillis");
|
||||
if (this.proxyPort != -1) {
|
||||
clientConfig.setProxyPort(this.proxyPort);
|
||||
}
|
||||
if (this.socketBufferSizeInBytes != 0) {
|
||||
clientConfig.setSocketBufferSizeInBytes(this.socketBufferSizeInBytes);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(this.localAddress)) {
|
||||
try {
|
||||
clientConfig.setLocalAddress(InetAddress.getByName(this.localAddress));
|
||||
} catch (UnknownHostException e) {
|
||||
log.error("localAddress配置有误,请检查!", e);
|
||||
}
|
||||
}
|
||||
clientConfig.setRetryPolicy(new DefaultRetryPolicy(maxErrorRetry, maxDelayInMillis));
|
||||
return clientConfig;
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
package com.schisandra.oss.application.oss.core.ftp;
|
||||
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
@@ -36,7 +37,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 陈敏
|
||||
* @author landaiqing
|
||||
* @version FtpOssClient.java, v 1.1 2021/11/15 11:11 chenmin Exp $
|
||||
* Created on 2021/11/15
|
||||
*/
|
||||
|
@@ -10,14 +10,13 @@ import com.schisandra.oss.application.oss.core.ftp.model.FtpOssConfig;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssFtpBO;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssFtpDomainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author 陈敏
|
||||
* @author landaiqing
|
||||
* @version FtpOssConfiguration.java, v 1.1 2021/11/16 15:29 chenmin Exp $
|
||||
* Created on 2021/11/16
|
||||
*/
|
||||
|
@@ -5,7 +5,7 @@ import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @author 陈敏
|
||||
* @author landaiqing
|
||||
* @version FtpOssClientConfig.java, v 1.0 2022/4/25 17:26 chenmin Exp $
|
||||
* Created on 2022/4/25
|
||||
*/
|
||||
|
@@ -10,7 +10,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* @author 陈敏
|
||||
* @author landaiqing
|
||||
* @version FtpOssConfig.java, v 1.1 2022/2/19 18:29 chenmin Exp $
|
||||
* Created on 2022/2/19
|
||||
*/
|
||||
|
@@ -0,0 +1,210 @@
|
||||
package com.schisandra.oss.application.oss.core.huawei;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.obs.services.ObsClient;
|
||||
import com.obs.services.model.*;
|
||||
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||
import com.schisandra.oss.application.oss.core.huawei.model.HuaweiOssConfig;
|
||||
import com.schisandra.oss.application.oss.model.DirectoryOssInfo;
|
||||
import com.schisandra.oss.application.oss.model.FileOssInfo;
|
||||
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||
import com.schisandra.oss.application.oss.model.SliceConfig;
|
||||
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* https://support.huaweicloud.com/obs/index.html
|
||||
*
|
||||
* @author landaiqing
|
||||
* @version HuaWeiOssClient.java, v 1.1 2021/11/25 10:01 chenmin Exp $
|
||||
* Created on 2021/11/25
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class HuaWeiOssClient implements StandardOssClient {
|
||||
|
||||
public static final String OBS_OBJECT_NAME = "obsClient";
|
||||
|
||||
private ObsClient obsClient;
|
||||
private HuaweiOssConfig huaweiOssConfig;
|
||||
|
||||
@Override
|
||||
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
||||
String bucket = getBucket();
|
||||
String key = getKey(targetName, false);
|
||||
if (isOverride || !obsClient.doesObjectExist(bucket, key)) {
|
||||
obsClient.putObject(bucket, key, is);
|
||||
}
|
||||
return getInfo(targetName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OssInfo upLoadCheckPoint(File file, String targetName) {
|
||||
String bucket = getBucket();
|
||||
String key = getKey(targetName, false);
|
||||
UploadFileRequest request = new UploadFileRequest(bucket, key);
|
||||
String upLoadFile = file.getPath();
|
||||
request.setUploadFile(upLoadFile);
|
||||
|
||||
SliceConfig slice = huaweiOssConfig.getSliceConfig();
|
||||
|
||||
request.setTaskNum(slice.getTaskNum());
|
||||
request.setPartSize(slice.getPartSize());
|
||||
request.setEnableCheckpoint(true);
|
||||
|
||||
String checkpointFile = upLoadFile + StrUtil.DOT + OssConstant.OssType.HUAWEI;
|
||||
|
||||
request.setCheckpointFile(checkpointFile);
|
||||
obsClient.uploadFile(request);
|
||||
return getInfo(targetName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downLoad(OutputStream os, String targetName) {
|
||||
ObsObject obsObject = obsClient.getObject(getBucket(), getKey(targetName, false));
|
||||
IoUtil.copy(obsObject.getObjectContent(), os);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downLoadCheckPoint(File localFile, String targetName) {
|
||||
String downloadFile = localFile.getPath();
|
||||
DownloadFileRequest request = new DownloadFileRequest(getBucket(), getKey(targetName, false));
|
||||
request.setEnableCheckpoint(true);
|
||||
SliceConfig sliceConfig = huaweiOssConfig.getSliceConfig();
|
||||
request.setTaskNum(sliceConfig.getTaskNum());
|
||||
request.setPartSize(sliceConfig.getPartSize());
|
||||
|
||||
String checkpointFile = downloadFile + StrUtil.DOT + OssConstant.OssType.HUAWEI;
|
||||
request.setCheckpointFile(checkpointFile);
|
||||
request.setDownloadFile(downloadFile);
|
||||
obsClient.downloadFile(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String targetName) {
|
||||
obsClient.deleteObject(getBucket(), getKey(targetName, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy(String sourceName, String targetName, Boolean isOverride) {
|
||||
String bucket = getBucket();
|
||||
String newTargetName = getKey(targetName, false);
|
||||
if (isOverride || !obsClient.doesObjectExist(bucket, newTargetName)) {
|
||||
obsClient.copyObject(bucket, getKey(sourceName, false), bucket, newTargetName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OssInfo getInfo(String targetName, Boolean isRecursion) {
|
||||
String key = getKey(targetName, false);
|
||||
|
||||
OssInfo ossInfo = getBaseInfo(key);
|
||||
ossInfo.setName(StrUtil.equals(targetName, StrUtil.SLASH) ? targetName : FileNameUtil.getName(targetName));
|
||||
ossInfo.setPath(OssPathUtil.replaceKey(targetName, ossInfo.getName(), true));
|
||||
|
||||
if (isRecursion && isDirectory(key)) {
|
||||
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(getBucket());
|
||||
listObjectsRequest.setDelimiter(StrUtil.SLASH);
|
||||
String prefix = OssPathUtil.convertPath(key, false);
|
||||
listObjectsRequest.setPrefix(prefix.endsWith(StrUtil.SLASH) ? prefix : prefix + StrUtil.SLASH);
|
||||
|
||||
ObjectListing listObjects = obsClient.listObjects(listObjectsRequest);
|
||||
|
||||
List<OssInfo> fileOssInfos = new ArrayList<>();
|
||||
List<OssInfo> directoryInfos = new ArrayList<>();
|
||||
for (ObsObject obsObject : listObjects.getObjects()) {
|
||||
if (FileNameUtil.getName(obsObject.getObjectKey()).equals(FileNameUtil.getName(key))) {
|
||||
ossInfo.setLastUpdateTime(DateUtil.date(obsObject.getMetadata().getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||
ossInfo.setCreateTime(DateUtil.date(obsObject.getMetadata().getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||
ossInfo.setLength(Convert.toStr(obsObject.getMetadata().getContentLength()));
|
||||
} else {
|
||||
fileOssInfos.add(getInfo(OssPathUtil.replaceKey(obsObject.getObjectKey(), getBasePath(), false), false));
|
||||
}
|
||||
}
|
||||
|
||||
for (String commonPrefix : listObjects.getCommonPrefixes()) {
|
||||
String target = OssPathUtil.replaceKey(commonPrefix, getBasePath(), false);
|
||||
if (isDirectory(commonPrefix)) {
|
||||
directoryInfos.add(getInfo(target, true));
|
||||
} else {
|
||||
fileOssInfos.add(getInfo(target, false));
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(fileOssInfos) && fileOssInfos.get(0) instanceof FileOssInfo) {
|
||||
ReflectUtil.setFieldValue(ossInfo, "fileInfos", fileOssInfos);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(directoryInfos) && directoryInfos.get(0) instanceof DirectoryOssInfo) {
|
||||
ReflectUtil.setFieldValue(ossInfo, "directoryInfos", directoryInfos);
|
||||
}
|
||||
}
|
||||
|
||||
return ossInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isExist(String targetName) {
|
||||
return obsClient.doesObjectExist(getBucket(), getKey(targetName, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBasePath() {
|
||||
return huaweiOssConfig.getBasePath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getClientObject() {
|
||||
return new HashMap<String, Object>() {
|
||||
{
|
||||
put(OBS_OBJECT_NAME, getObsClient());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private String getBucket() {
|
||||
String bucketName = huaweiOssConfig.getBucketName();
|
||||
if (!obsClient.headBucket(bucketName)) {
|
||||
obsClient.createBucket(bucketName);
|
||||
}
|
||||
return bucketName;
|
||||
}
|
||||
|
||||
public OssInfo getBaseInfo(String key) {
|
||||
OssInfo ossInfo;
|
||||
|
||||
if (isFile(key)) {
|
||||
ossInfo = new FileOssInfo();
|
||||
try {
|
||||
ObjectMetadata objectMetadata = obsClient.getObjectMetadata(getBucket(), key);
|
||||
ossInfo.setLastUpdateTime(DateUtil.date(objectMetadata.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||
ossInfo.setCreateTime(DateUtil.date(objectMetadata.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||
ossInfo.setLength(Convert.toStr(objectMetadata.getContentLength()));
|
||||
} catch (Exception e) {
|
||||
log.error("获取{}文件属性失败", key, e);
|
||||
}
|
||||
} else {
|
||||
ossInfo = new DirectoryOssInfo();
|
||||
}
|
||||
return ossInfo;
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
package com.schisandra.oss.application.oss.core.huawei;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.obs.services.ObsClient;
|
||||
import com.obs.services.ObsConfiguration;
|
||||
import com.schisandra.oss.application.convert.SchisandraOssHuaweiDTOConverter;
|
||||
import com.schisandra.oss.application.dto.SchisandraOssHuaweiDTO;
|
||||
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||
import com.schisandra.oss.application.oss.core.huawei.model.HuaweiOssClientConfig;
|
||||
import com.schisandra.oss.application.oss.core.huawei.model.HuaweiOssConfig;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssHuaweiBO;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssHuaweiDomainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author landaiqing
|
||||
* @version HuaWeiOssConfiguration.java, v 1.1 2021/11/25 9:58 chenmin Exp $
|
||||
* Created on 2021/11/25
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class HuaWeiOssConfiguration {
|
||||
|
||||
@Resource
|
||||
private SchisandraOssHuaweiDomainService schisandraOssHuaweiDomainService;
|
||||
|
||||
public StandardOssClient huaWeiOssClient(String userId) {
|
||||
SchisandraOssHuaweiBO schisandraOssHuaweiBO = schisandraOssHuaweiDomainService.getHuaweiOssConfig(userId);
|
||||
SchisandraOssHuaweiDTO schisandraOssHuaweiDTO = SchisandraOssHuaweiDTOConverter.INSTANCE.convertBOToDTO(schisandraOssHuaweiBO);
|
||||
if (ObjectUtil.isEmpty(schisandraOssHuaweiDTO)) {
|
||||
log.error("huawei oss配置信息获取失败");
|
||||
return null;
|
||||
}
|
||||
String accessKey = schisandraOssHuaweiDTO.getAccessKey();
|
||||
String secretKey = schisandraOssHuaweiDTO.getSecretKey();
|
||||
String endPoint = schisandraOssHuaweiDTO.getEndPoint();
|
||||
HuaweiOssConfig huaweiOssConfig = new HuaweiOssConfig();
|
||||
huaweiOssConfig.setAccessKey(accessKey);
|
||||
huaweiOssConfig.setSecretKey(secretKey);
|
||||
huaweiOssConfig.setEndPoint(endPoint);
|
||||
return huaWeiOssClient(huaweiOssConfig);
|
||||
}
|
||||
|
||||
public StandardOssClient huaWeiOssClient(HuaweiOssConfig huaweiOssConfig) {
|
||||
return new HuaWeiOssClient(obsClient(huaweiOssConfig), huaweiOssConfig);
|
||||
}
|
||||
|
||||
public ObsClient obsClient(HuaweiOssConfig huaweiOssConfig) {
|
||||
HuaweiOssClientConfig clientConfig = Optional.ofNullable(huaweiOssConfig.getClientConfig()).orElse(new HuaweiOssClientConfig());
|
||||
ObsConfiguration obsConfiguration = clientConfig.toClientConfig();
|
||||
obsConfiguration.setEndPoint(huaweiOssConfig.getEndPoint());
|
||||
return new ObsClient(huaweiOssConfig.getAccessKey(), huaweiOssConfig.getSecretKey(), obsConfiguration);
|
||||
}
|
||||
}
|
@@ -0,0 +1,158 @@
|
||||
package com.schisandra.oss.application.oss.core.huawei.model;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.obs.services.HttpProxyConfiguration;
|
||||
import com.obs.services.ObsConfiguration;
|
||||
import com.obs.services.internal.ext.ExtObsConfiguration;
|
||||
import com.obs.services.model.AuthTypeEnum;
|
||||
import com.obs.services.model.HttpProtocolTypeEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import static com.obs.services.internal.ObsConstraint.*;
|
||||
import static com.obs.services.internal.ext.ExtObsConstraint.DEFAULT_MAX_RETRY_ON_UNEXPECTED_END_EXCEPTION;
|
||||
import static com.obs.services.internal.ext.ExtObsConstraint.DEFAULT_RETRY_ON_CONNECTION_FAILURE_IN_OKHTTP;
|
||||
|
||||
/**
|
||||
* @author landaiqing
|
||||
* @version HuaweiOssClientConfig.java, v 1.0 2022/4/20 16:48 chenmin Exp $
|
||||
* Created on 2022/4/20
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class HuaweiOssClientConfig {
|
||||
/**
|
||||
* 建立HTTP/HTTPS连接的超时时间(单位:毫秒)。默认为60000毫秒。
|
||||
*/
|
||||
private int connectionTimeout = HTTP_CONNECT_TIMEOUT_VALUE;
|
||||
/**
|
||||
* 如果空闲时间超过此参数的设定值,则关闭连接(单位:毫秒)。默认为30000毫秒。
|
||||
*/
|
||||
private int idleConnectionTime = DEFAULT_IDLE_CONNECTION_TIME;
|
||||
/**
|
||||
* 连接池中最大空闲连接数,默认值:1000。
|
||||
*/
|
||||
private int maxIdleConnections = DEFAULT_MAX_IDLE_CONNECTIONS;
|
||||
/**
|
||||
* 最大允许的HTTP并发请求数。默认为1000。
|
||||
*/
|
||||
private int maxConnections = HTTP_MAX_CONNECT_VALUE;
|
||||
/**
|
||||
* 请求失败(请求异常、服务端报500或503错误等)后最大的重试次数。默认3次。
|
||||
*/
|
||||
private int maxErrorRetry = HTTP_RETRY_MAX_VALUE;
|
||||
/**
|
||||
* Socket层传输数据的超时时间(单位:毫秒)。默认为60000毫秒。
|
||||
*/
|
||||
private int socketTimeout = HTTP_SOCKET_TIMEOUT_VALUE;
|
||||
/**
|
||||
* 设置HTTP请求的端口号 (默认为80)。
|
||||
*/
|
||||
private int endpointHttpPort = HTTP_PORT_VALUE;
|
||||
/**
|
||||
* 设置HTTPS请求的端口号 (默认443)。
|
||||
*/
|
||||
private int endpointHttpsPort = HTTPS_PORT_VALUE;
|
||||
/**
|
||||
* 指定是否使用HTTPS连接OBS (默认为 “true”)。
|
||||
*/
|
||||
private boolean httpsOnly = true;
|
||||
/**
|
||||
* 指定是否启用对OBS的路径样式访问。“true” 表示启用了路径样式的访问,而 “false” (默认) 表示启用了虚拟托管样式的访问。
|
||||
* 注意: 如果启用了路径样式访问,则不支持OBS 3.0的新bucket功能。
|
||||
*/
|
||||
private boolean pathStyle = false;
|
||||
/**
|
||||
* HTTP代理配置。默认为空。
|
||||
*/
|
||||
private HttpProxyConfiguration httpProxy;
|
||||
/**
|
||||
* 上传流对象时使用的缓存大小(单位:字节)。默认为512KB。
|
||||
*/
|
||||
private int uploadStreamRetryBufferSize;
|
||||
/**
|
||||
* 是否验证服务端证书。默认为false。
|
||||
*/
|
||||
private boolean validateCertificate = false;
|
||||
/**
|
||||
* 是否验证响应头信息的ContentType。默认为true。
|
||||
*/
|
||||
private boolean verifyResponseContentType = true;
|
||||
/**
|
||||
* 从Socket流下载对象的缓存大小(单位:字节),-1表示不设置缓存。默认为-1。
|
||||
*/
|
||||
private int readBufferSize = -1;
|
||||
/**
|
||||
* 上传对象到Socket流时的缓存大小(单位:字节),-1表示不设置缓存。默认为-1。
|
||||
*/
|
||||
private int writeBufferSize = -1;
|
||||
/**
|
||||
* 是否严格验证服务端主机名。默认为false。
|
||||
*/
|
||||
private boolean isStrictHostnameVerification = false;
|
||||
/**
|
||||
* 设置身份验证类型。
|
||||
*/
|
||||
private AuthTypeEnum authType = AuthTypeEnum.OBS;
|
||||
/**
|
||||
* Socket发送缓冲区大小(单位:字节),对应java.net.SocketOptions.SO_SNDBUF参数。默认为-1表示不设置。
|
||||
*/
|
||||
private int socketWriteBufferSize = -1;
|
||||
/**
|
||||
* Socket接收缓冲区大小(单位:字节),对应java.net.SocketOptions.SO_RCVBUF参数。默认为-1表示不设置。
|
||||
*/
|
||||
private int socketReadBufferSize = -1;
|
||||
/**
|
||||
* 是否使用长连接访问OBS服务。默认为true。
|
||||
*/
|
||||
private boolean keepAlive = true;
|
||||
/**
|
||||
* 指定是否使用协议协商。
|
||||
*/
|
||||
private boolean authTypeNegotiation = true;
|
||||
/**
|
||||
* 是否通过自定义域名访问OBS服务。默认为false。
|
||||
*/
|
||||
private boolean cname = false;
|
||||
/**
|
||||
* 将文件夹隔离器设置为斜线。
|
||||
*/
|
||||
private String delimiter = StrUtil.SLASH;
|
||||
/**
|
||||
* SSLContext的Provider,默认使用JDK提供的SSLContext。
|
||||
*/
|
||||
private String sslProvider;
|
||||
/**
|
||||
* 访问OBS服务端时使用的HTTP协议类型。默认为HTTP1.1协议。
|
||||
*/
|
||||
private HttpProtocolTypeEnum httpProtocolType = HttpProtocolTypeEnum.HTTP1_1;
|
||||
|
||||
/**
|
||||
* 是否开启Okhttp中的连接失败重试,默认关闭
|
||||
*/
|
||||
private boolean retryOnConnectionFailureInOkhttp = DEFAULT_RETRY_ON_CONNECTION_FAILURE_IN_OKHTTP;
|
||||
/**
|
||||
* 发生异常时最大重试次数
|
||||
*/
|
||||
private int maxRetryOnUnexpectedEndException = DEFAULT_MAX_RETRY_ON_UNEXPECTED_END_EXCEPTION;
|
||||
|
||||
public ObsConfiguration toClientConfig() {
|
||||
ExtObsConfiguration obsConfiguration = new ExtObsConfiguration();
|
||||
BeanUtil.copyProperties(this, obsConfiguration,
|
||||
"readBufferSize", "writeBufferSize", "socketWriteBufferSize", "socketReadBufferSize");
|
||||
if (this.readBufferSize != -1) {
|
||||
obsConfiguration.setReadBufferSize(this.readBufferSize);
|
||||
}
|
||||
if (this.writeBufferSize != -1) {
|
||||
obsConfiguration.setWriteBufferSize(this.writeBufferSize);
|
||||
}
|
||||
if (this.socketWriteBufferSize != -1) {
|
||||
obsConfiguration.setSocketReadBufferSize(this.socketWriteBufferSize);
|
||||
}
|
||||
if (this.socketReadBufferSize != -1) {
|
||||
obsConfiguration.setSocketReadBufferSize(this.socketReadBufferSize);
|
||||
}
|
||||
return obsConfiguration;
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package com.schisandra.oss.application.oss.core.huawei.model;
|
||||
|
||||
|
||||
import com.schisandra.oss.application.oss.model.SliceConfig;
|
||||
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author landaiqing
|
||||
* @version HuaweiOssConfig.java, v 1.1 2022/2/19 18:33 chenmin Exp $
|
||||
* Created on 2022/2/19
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
public class HuaweiOssConfig {
|
||||
|
||||
private String basePath;
|
||||
|
||||
private String accessKey;
|
||||
private String secretKey;
|
||||
/**
|
||||
* 连接OBS的服务地址。可包含协议类型、域名、端口号。示例:https://your-endpoint:443。
|
||||
* (出于安全性考虑,建议使用https协议)
|
||||
*/
|
||||
private String endPoint;
|
||||
private String bucketName;
|
||||
|
||||
private HuaweiOssClientConfig clientConfig;
|
||||
|
||||
/**
|
||||
* 断点续传参数
|
||||
*/
|
||||
private SliceConfig sliceConfig = new SliceConfig();
|
||||
|
||||
public void init() {
|
||||
this.sliceConfig.init();
|
||||
basePath = OssPathUtil.valid(basePath);
|
||||
}
|
||||
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package com.schisandra.oss.application.oss.core.baidu;
|
||||
package com.schisandra.oss.application.oss.core.jd;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
@@ -10,18 +10,21 @@ import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baidubce.services.bos.BosClient;
|
||||
import com.baidubce.services.bos.model.*;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.model.*;
|
||||
import com.amazonaws.services.s3.transfer.TransferManager;
|
||||
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||
import com.schisandra.oss.application.oss.core.baidu.model.BaiduOssConfig;
|
||||
import com.schisandra.oss.application.oss.core.jd.model.JdOssConfig;
|
||||
import com.schisandra.oss.application.oss.model.DirectoryOssInfo;
|
||||
import com.schisandra.oss.application.oss.model.FileOssInfo;
|
||||
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||
import com.schisandra.oss.application.oss.model.SliceConfig;
|
||||
import com.schisandra.oss.application.oss.model.download.DownloadCheckPoint;
|
||||
import com.schisandra.oss.application.oss.model.download.DownloadObjectStat;
|
||||
import com.schisandra.oss.application.oss.model.upload.*;
|
||||
import com.schisandra.oss.application.oss.model.upload.UpLoadCheckPoint;
|
||||
import com.schisandra.oss.application.oss.model.upload.UpLoadPartEntityTag;
|
||||
import com.schisandra.oss.application.oss.model.upload.UpLoadPartResult;
|
||||
import com.schisandra.oss.application.oss.model.upload.UploadPart;
|
||||
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -35,89 +38,59 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* https://cloud.baidu.com/doc/BOS/index.html
|
||||
* https://docs.jdcloud.com/cn/object-storage-service/product-overview
|
||||
*
|
||||
* @author 陈敏
|
||||
* @version BaiduOssClient.java, v 1.1 2021/11/24 15:34 chenmin Exp $
|
||||
* Created on 2021/11/24
|
||||
* @author landaiqing
|
||||
* @version JdOssClient.java, v 1.1 2021/11/25 10:44 chenmin Exp $
|
||||
* Created on 2021/11/25
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class BaiduOssClient implements StandardOssClient {
|
||||
public class JdOssClient implements StandardOssClient {
|
||||
|
||||
public static final String BOS_OBJECT_NAME = "bosClient";
|
||||
public static final String AMAZONS3_OBJECT_NAME = "amazonS3";
|
||||
public static final String TRANSFER_OBJECT_NAME = "transferManager";
|
||||
|
||||
private BosClient bosClient;
|
||||
private BaiduOssConfig baiduOssConfig;
|
||||
private AmazonS3 amazonS3;
|
||||
private TransferManager transferManager;
|
||||
private JdOssConfig jdOssConfig;
|
||||
|
||||
@Override
|
||||
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
||||
String bucket = getBucket();
|
||||
String bucketName = getBucket();
|
||||
String key = getKey(targetName, false);
|
||||
if (isOverride || !bosClient.doesObjectExist(bucket, key)) {
|
||||
bosClient.putObject(bucket, key, is);
|
||||
|
||||
if (isOverride || !amazonS3.doesObjectExist(bucketName, key)) {
|
||||
amazonS3.putObject(bucketName, key, is, new ObjectMetadata());
|
||||
}
|
||||
return getInfo(targetName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OssInfo upLoadCheckPoint(File file, String targetName) {
|
||||
return uploadFile(file, targetName, baiduOssConfig.getSliceConfig(), OssConstant.OssType.BAIDU);
|
||||
return uploadFile(file, targetName, jdOssConfig.getSliceConfig(), OssConstant.OssType.JD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeUpload(UpLoadCheckPoint upLoadCheckPoint, List<UpLoadPartEntityTag> partEntityTags) {
|
||||
List<PartETag> eTags = partEntityTags.stream().sorted(Comparator.comparingInt(UpLoadPartEntityTag::getPartNumber))
|
||||
.map(partEntityTag -> {
|
||||
PartETag p = new PartETag();
|
||||
p.setETag(partEntityTag.getETag());
|
||||
p.setPartNumber(partEntityTag.getPartNumber());
|
||||
return p;
|
||||
}).collect(Collectors.toList());
|
||||
.map(partEntityTag -> new PartETag(partEntityTag.getPartNumber(), partEntityTag.getETag())).collect(Collectors.toList());
|
||||
|
||||
CompleteMultipartUploadRequest completeMultipartUploadRequest =
|
||||
new CompleteMultipartUploadRequest(upLoadCheckPoint.getBucket(), upLoadCheckPoint.getKey(), upLoadCheckPoint.getUploadId(), eTags);
|
||||
bosClient.completeMultipartUpload(completeMultipartUploadRequest);
|
||||
amazonS3.completeMultipartUpload(completeMultipartUploadRequest);
|
||||
|
||||
FileUtil.del(upLoadCheckPoint.getCheckpointFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareUpload(UpLoadCheckPoint uploadCheckPoint, File upLoadFile, String targetName, String checkpointFile, SliceConfig slice) {
|
||||
String bucket = getBucket();
|
||||
String key = getKey(targetName, false);
|
||||
|
||||
uploadCheckPoint.setMagic(UpLoadCheckPoint.UPLOAD_MAGIC);
|
||||
uploadCheckPoint.setUploadFile(upLoadFile.getPath());
|
||||
uploadCheckPoint.setKey(key);
|
||||
uploadCheckPoint.setBucket(bucket);
|
||||
uploadCheckPoint.setCheckpointFile(checkpointFile);
|
||||
uploadCheckPoint.setUploadFileStat(UpLoadFileStat.getFileStat(uploadCheckPoint.getUploadFile()));
|
||||
|
||||
long partSize = slice.getPartSize();
|
||||
long fileLength = upLoadFile.length();
|
||||
int parts = (int) (fileLength / partSize);
|
||||
if (fileLength % partSize > 0) {
|
||||
parts++;
|
||||
}
|
||||
|
||||
uploadCheckPoint.setUploadParts(splitUploadFile(uploadCheckPoint.getUploadFileStat().getSize(), partSize));
|
||||
uploadCheckPoint.setPartEntityTags(new ArrayList<>());
|
||||
uploadCheckPoint.setOriginPartSize(parts);
|
||||
|
||||
InitiateMultipartUploadResponse initiateMultipartUploadResponse =
|
||||
bosClient.initiateMultipartUpload(new InitiateMultipartUploadRequest(bucket, key));
|
||||
|
||||
uploadCheckPoint.setUploadId(initiateMultipartUploadResponse.getUploadId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpLoadPartResult uploadPart(UpLoadCheckPoint upLoadCheckPoint, int partNum, InputStream inputStream) {
|
||||
UpLoadPartResult partResult = null;
|
||||
UploadPart uploadPart = upLoadCheckPoint.getUploadParts().get(partNum);
|
||||
long partSize = uploadPart.getSize();
|
||||
UpLoadPartResult partResult = new UpLoadPartResult(partNum + 1, uploadPart.getOffset(), partSize);
|
||||
|
||||
partResult = new UpLoadPartResult(partNum + 1, uploadPart.getOffset(), partSize);
|
||||
try {
|
||||
inputStream.skip(uploadPart.getOffset());
|
||||
|
||||
@@ -127,12 +100,13 @@ public class BaiduOssClient implements StandardOssClient {
|
||||
uploadPartRequest.setUploadId(upLoadCheckPoint.getUploadId());
|
||||
uploadPartRequest.setInputStream(inputStream);
|
||||
uploadPartRequest.setPartSize(partSize);
|
||||
uploadPartRequest.setPartNumber(partNum + 1);
|
||||
UploadPartResponse uploadPartResponse = bosClient.uploadPart(uploadPartRequest);
|
||||
uploadPartRequest.setPartNumber(uploadPart.getNumber());
|
||||
|
||||
UploadPartResult uploadPartResponse = amazonS3.uploadPart(uploadPartRequest);
|
||||
|
||||
partResult.setNumber(uploadPartResponse.getPartNumber());
|
||||
PartETag eTag = uploadPartResponse.getPartETag();
|
||||
partResult.setEntityTag(new UpLoadPartEntityTag().setETag(eTag.getETag()).setPartNumber(eTag.getPartNumber()));
|
||||
partResult.setEntityTag(new UpLoadPartEntityTag().setETag(uploadPartResponse.getETag())
|
||||
.setPartNumber(uploadPartResponse.getPartNumber()));
|
||||
} catch (Exception e) {
|
||||
partResult.setFailed(true);
|
||||
partResult.setException(e);
|
||||
@@ -145,18 +119,18 @@ public class BaiduOssClient implements StandardOssClient {
|
||||
|
||||
@Override
|
||||
public void downLoad(OutputStream os, String targetName) {
|
||||
BosObject bosObject = bosClient.getObject(getBucket(), getKey(targetName, false));
|
||||
IoUtil.copy(bosObject.getObjectContent(), os);
|
||||
S3Object s3Object = amazonS3.getObject(getBucket(), getKey(targetName, false));
|
||||
IoUtil.copy(s3Object.getObjectContent(), os);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downLoadCheckPoint(File localFile, String targetName) {
|
||||
downLoadFile(localFile, targetName, baiduOssConfig.getSliceConfig(), OssConstant.OssType.BAIDU);
|
||||
downLoadFile(localFile, targetName, jdOssConfig.getSliceConfig(), OssConstant.OssType.BAIDU);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DownloadObjectStat getDownloadObjectStat(String targetName) {
|
||||
ObjectMetadata objectMetadata = bosClient.getObjectMetadata(getBucket(), getKey(targetName, false));
|
||||
ObjectMetadata objectMetadata = amazonS3.getObjectMetadata(getBucket(), getKey(targetName, false));
|
||||
DateTime date = DateUtil.date(objectMetadata.getLastModified());
|
||||
long contentLength = objectMetadata.getContentLength();
|
||||
String eTag = objectMetadata.getETag();
|
||||
@@ -175,11 +149,12 @@ public class BaiduOssClient implements StandardOssClient {
|
||||
|
||||
long downloadSize;
|
||||
if (downloadCheckPoint.getObjectStat().getSize() > 0) {
|
||||
Long partSize = baiduOssConfig.getSliceConfig().getPartSize();
|
||||
Long partSize = jdOssConfig.getSliceConfig().getPartSize();
|
||||
long[] slice = getDownloadSlice(new long[0], downloadCheckPoint.getObjectStat().getSize());
|
||||
downloadCheckPoint.setDownloadParts(splitDownloadFile(slice[0], slice[1], partSize));
|
||||
downloadSize = slice[1];
|
||||
} else {
|
||||
//download whole file
|
||||
downloadSize = 0;
|
||||
downloadCheckPoint.setDownloadParts(splitDownloadOneFile());
|
||||
}
|
||||
@@ -189,25 +164,23 @@ public class BaiduOssClient implements StandardOssClient {
|
||||
|
||||
@Override
|
||||
public InputStream downloadPart(String key, long start, long end) {
|
||||
GetObjectRequest request = new GetObjectRequest();
|
||||
request.setKey(key);
|
||||
request.setBucketName(getBucket());
|
||||
GetObjectRequest request = new GetObjectRequest(getBucket(), key);
|
||||
request.setRange(start, end);
|
||||
BosObject object = bosClient.getObject(request);
|
||||
S3Object object = amazonS3.getObject(request);
|
||||
return object.getObjectContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String targetName) {
|
||||
bosClient.deleteObject(getBucket(), getKey(targetName, false));
|
||||
amazonS3.deleteObject(getBucket(), getKey(targetName, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy(String sourceName, String targetName, Boolean isOverride) {
|
||||
String bucket = getBucket();
|
||||
String newTargetName = getKey(targetName, false);
|
||||
if (isOverride || !bosClient.doesObjectExist(bucket, newTargetName)) {
|
||||
bosClient.copyObject(bucket, getKey(sourceName, false), bucket, newTargetName);
|
||||
String bucketName = getBucket();
|
||||
String targetKey = getKey(targetName, false);
|
||||
if (isOverride || !amazonS3.doesObjectExist(bucketName, targetKey)) {
|
||||
amazonS3.copyObject(getBucket(), getKey(sourceName, false), getBucket(), targetKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,30 +194,26 @@ public class BaiduOssClient implements StandardOssClient {
|
||||
|
||||
if (isRecursion && isDirectory(key)) {
|
||||
String prefix = OssPathUtil.convertPath(key, false);
|
||||
ListObjectsResponse listObjects = bosClient.listObjects(getBucket(), prefix.endsWith(StrUtil.SLASH) ? prefix : prefix + StrUtil.SLASH);
|
||||
ObjectListing listObjects = amazonS3.listObjects(getBucket(), prefix.endsWith(StrUtil.SLASH) ? prefix : prefix + StrUtil.SLASH);
|
||||
|
||||
List<OssInfo> fileOssInfos = new ArrayList<>();
|
||||
List<OssInfo> directoryInfos = new ArrayList<>();
|
||||
if (ObjectUtil.isNotEmpty(listObjects.getContents())) {
|
||||
for (BosObjectSummary bosObjectSummary : listObjects.getContents()) {
|
||||
if (FileNameUtil.getName(bosObjectSummary.getKey()).equals(FileNameUtil.getName(key))) {
|
||||
ossInfo.setLastUpdateTime(DateUtil.date(bosObjectSummary.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||
ossInfo.setCreateTime(DateUtil.date(bosObjectSummary.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||
ossInfo.setLength(Convert.toStr(bosObjectSummary.getSize()));
|
||||
} else {
|
||||
fileOssInfos.add(getInfo(OssPathUtil.replaceKey(bosObjectSummary.getKey(), getBasePath(), false), false));
|
||||
}
|
||||
for (S3ObjectSummary s3ObjectSummary : listObjects.getObjectSummaries()) {
|
||||
if (FileNameUtil.getName(s3ObjectSummary.getKey()).equals(FileNameUtil.getName(key))) {
|
||||
ossInfo.setLastUpdateTime(DateUtil.date(s3ObjectSummary.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||
ossInfo.setCreateTime(DateUtil.date(s3ObjectSummary.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||
ossInfo.setLength(Convert.toStr(s3ObjectSummary.getSize()));
|
||||
} else {
|
||||
fileOssInfos.add(getInfo(OssPathUtil.replaceKey(s3ObjectSummary.getKey(), getBasePath(), false), false));
|
||||
}
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotEmpty(listObjects.getCommonPrefixes())) {
|
||||
for (String commonPrefix : listObjects.getCommonPrefixes()) {
|
||||
String target = OssPathUtil.replaceKey(commonPrefix, getBasePath(), false);
|
||||
if (isDirectory(commonPrefix)) {
|
||||
directoryInfos.add(getInfo(target, true));
|
||||
} else {
|
||||
fileOssInfos.add(getInfo(target, false));
|
||||
}
|
||||
for (String commonPrefix : listObjects.getCommonPrefixes()) {
|
||||
String target = OssPathUtil.replaceKey(commonPrefix, getBasePath(), false);
|
||||
if (isDirectory(commonPrefix)) {
|
||||
directoryInfos.add(getInfo(target, true));
|
||||
} else {
|
||||
fileOssInfos.add(getInfo(target, false));
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(fileOssInfos) && fileOssInfos.get(0) instanceof FileOssInfo) {
|
||||
@@ -260,27 +229,28 @@ public class BaiduOssClient implements StandardOssClient {
|
||||
|
||||
@Override
|
||||
public Boolean isExist(String targetName) {
|
||||
return bosClient.doesObjectExist(getBucket(), getKey(targetName, false));
|
||||
return amazonS3.doesObjectExist(getBucket(), getKey(targetName, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBasePath() {
|
||||
return baiduOssConfig.getBasePath();
|
||||
return jdOssConfig.getBasePath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getClientObject() {
|
||||
return new HashMap<String, Object>() {
|
||||
{
|
||||
put(BOS_OBJECT_NAME, getBosClient());
|
||||
put(AMAZONS3_OBJECT_NAME, getAmazonS3());
|
||||
put(TRANSFER_OBJECT_NAME, getTransferManager());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private String getBucket() {
|
||||
String bucketName = baiduOssConfig.getBucketName();
|
||||
if (!bosClient.doesBucketExist(bucketName)) {
|
||||
bosClient.createBucket(bucketName);
|
||||
String bucketName = jdOssConfig.getBucketName();
|
||||
if (!amazonS3.doesBucketExistV2(bucketName)) {
|
||||
amazonS3.createBucket(bucketName);
|
||||
}
|
||||
return bucketName;
|
||||
}
|
||||
@@ -291,7 +261,7 @@ public class BaiduOssClient implements StandardOssClient {
|
||||
if (isFile(key)) {
|
||||
ossInfo = new FileOssInfo();
|
||||
try {
|
||||
ObjectMetadata objectMetadata = bosClient.getObjectMetadata(getBucket(), key);
|
||||
ObjectMetadata objectMetadata = amazonS3.getObjectMetadata(getBucket(), OssPathUtil.replaceKey(key, "", false));
|
||||
ossInfo.setLastUpdateTime(DateUtil.date(objectMetadata.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||
ossInfo.setCreateTime(DateUtil.date(objectMetadata.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||
ossInfo.setLength(Convert.toStr(objectMetadata.getContentLength()));
|
@@ -0,0 +1,100 @@
|
||||
package com.schisandra.oss.application.oss.core.jd;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.amazonaws.ClientConfiguration;
|
||||
import com.amazonaws.auth.AWSCredentials;
|
||||
import com.amazonaws.auth.AWSCredentialsProvider;
|
||||
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
||||
import com.amazonaws.auth.BasicAWSCredentials;
|
||||
import com.amazonaws.client.builder.AwsClientBuilder;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3Client;
|
||||
import com.amazonaws.services.s3.transfer.TransferManager;
|
||||
import com.amazonaws.services.s3.transfer.TransferManagerBuilder;
|
||||
import com.schisandra.oss.application.convert.SchisandraOssJdDTOConverter;
|
||||
import com.schisandra.oss.application.dto.SchisandraOssJdDTO;
|
||||
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||
import com.schisandra.oss.application.oss.core.jd.model.JdOssClientConfig;
|
||||
import com.schisandra.oss.application.oss.core.jd.model.JdOssConfig;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssJdBO;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssJdDomainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author landaiqing
|
||||
* @version JdOssConfiguration.java, v 1.1 2021/11/25 10:44 chenmin Exp $
|
||||
* Created on 2021/11/25
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class JdOssConfiguration {
|
||||
|
||||
|
||||
@Resource
|
||||
private SchisandraOssJdDomainService schisandraOssJdDomainService;
|
||||
|
||||
public StandardOssClient jdOssClient(String userId) {
|
||||
SchisandraOssJdBO schisandraOssJdBO = schisandraOssJdDomainService.getJdOssConfig(userId);
|
||||
SchisandraOssJdDTO schisandraOssJdDTO = SchisandraOssJdDTOConverter.INSTANCE.convertBOToDTO(schisandraOssJdBO);
|
||||
if (ObjectUtil.isEmpty(schisandraOssJdDTO)) {
|
||||
log.error("jd oss配置信息获取失败");
|
||||
return null;
|
||||
}
|
||||
String endpoint = schisandraOssJdDTO.getEndpoint();
|
||||
String accessKey = schisandraOssJdDTO.getAccessKey();
|
||||
String secretKey = schisandraOssJdDTO.getSecretKey();
|
||||
String region = schisandraOssJdDTO.getRegion();
|
||||
JdOssConfig jdOssConfig = new JdOssConfig();
|
||||
jdOssConfig.setEndpoint(endpoint);
|
||||
jdOssConfig.setAccessKey(accessKey);
|
||||
jdOssConfig.setSecretKey(secretKey);
|
||||
jdOssConfig.setRegion(region);
|
||||
return jdOssClient(jdOssConfig);
|
||||
}
|
||||
|
||||
private StandardOssClient jdOssClient(JdOssConfig jdOssConfig) {
|
||||
JdOssClientConfig clientConfig = Optional.ofNullable(jdOssConfig.getClientConfig()).orElse(new JdOssClientConfig());
|
||||
AwsClientBuilder.EndpointConfiguration endpointConfig = endpointConfig(jdOssConfig);
|
||||
AWSCredentials awsCredentials = awsCredentials(jdOssConfig);
|
||||
AWSCredentialsProvider awsCredentialsProvider = awsCredentialsProvider(awsCredentials);
|
||||
AmazonS3 amazonS3 = amazonS3(endpointConfig, clientConfig.toClientConfig(), awsCredentialsProvider);
|
||||
TransferManager transferManager = transferManager(amazonS3);
|
||||
return jdOssClient(amazonS3, transferManager, jdOssConfig);
|
||||
}
|
||||
|
||||
public StandardOssClient jdOssClient(AmazonS3 amazonS3, TransferManager transferManager, JdOssConfig jdOssConfig) {
|
||||
return new JdOssClient(amazonS3, transferManager, jdOssConfig);
|
||||
}
|
||||
|
||||
public AwsClientBuilder.EndpointConfiguration endpointConfig(JdOssConfig jdOssConfig) {
|
||||
return new AwsClientBuilder.EndpointConfiguration(jdOssConfig.getEndpoint(), jdOssConfig.getRegion());
|
||||
}
|
||||
|
||||
public AWSCredentials awsCredentials(JdOssConfig jdOssConfig) {
|
||||
return new BasicAWSCredentials(jdOssConfig.getAccessKey(), jdOssConfig.getSecretKey());
|
||||
}
|
||||
|
||||
public AWSCredentialsProvider awsCredentialsProvider(AWSCredentials awsCredentials) {
|
||||
return new AWSStaticCredentialsProvider(awsCredentials);
|
||||
}
|
||||
|
||||
public AmazonS3 amazonS3(AwsClientBuilder.EndpointConfiguration endpointConfig, ClientConfiguration clientConfig,
|
||||
AWSCredentialsProvider awsCredentialsProvider) {
|
||||
return AmazonS3Client.builder()
|
||||
.withEndpointConfiguration(endpointConfig)
|
||||
.withClientConfiguration(clientConfig)
|
||||
.withCredentials(awsCredentialsProvider)
|
||||
.disableChunkedEncoding()
|
||||
.build();
|
||||
}
|
||||
|
||||
public TransferManager transferManager(AmazonS3 amazonS3) {
|
||||
return TransferManagerBuilder.standard()
|
||||
.withS3Client(amazonS3)
|
||||
.build();
|
||||
}
|
||||
}
|
@@ -0,0 +1,181 @@
|
||||
package com.schisandra.oss.application.oss.core.jd.model;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.amazonaws.ClientConfiguration;
|
||||
import com.amazonaws.Protocol;
|
||||
import com.amazonaws.retry.RetryMode;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.amazonaws.ClientConfiguration.*;
|
||||
|
||||
/**
|
||||
* @author landaiqing
|
||||
* @version JdOssClientConfig.java, v 1.0 2022/4/20 17:19 chenmin Exp $
|
||||
* Created on 2022/4/20
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class JdOssClientConfig {
|
||||
/**
|
||||
* 建立连接的超时时间(单位:毫秒)。默认为50000毫秒
|
||||
*/
|
||||
private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
|
||||
/**
|
||||
* 允许打开的最大HTTP连接数。默认为1024
|
||||
*/
|
||||
private int maxConnections = DEFAULT_MAX_CONNECTIONS;
|
||||
/**
|
||||
* 请求失败后最大的重试次数
|
||||
*/
|
||||
private int maxErrorRetry = -1;
|
||||
/**
|
||||
* 是否限制重试的默认值。
|
||||
*/
|
||||
private boolean throttleRetries = DEFAULT_THROTTLE_RETRIES;
|
||||
/**
|
||||
* 连接协议类型
|
||||
*/
|
||||
private Protocol protocol = Protocol.HTTPS;
|
||||
/**
|
||||
* 连接到HTTP代理时要使用的协议。
|
||||
*/
|
||||
private Protocol proxyProtocol = Protocol.HTTP;
|
||||
/**
|
||||
* 访问NTLM验证的代理服务器的Windows域名
|
||||
*/
|
||||
private String proxyDomain;
|
||||
/**
|
||||
* 代理服务器主机地址
|
||||
*/
|
||||
private String proxyHost;
|
||||
/**
|
||||
* 代理服务器验证的密码
|
||||
*/
|
||||
private String proxyPassword;
|
||||
/**
|
||||
* 代理服务器端口
|
||||
*/
|
||||
private int proxyPort = -1;
|
||||
/**
|
||||
* 代理服务器验证的用户名
|
||||
*/
|
||||
private String proxyUsername;
|
||||
/**
|
||||
* NTLM代理服务器的Windows工作站名称
|
||||
*/
|
||||
private String proxyWorkstation;
|
||||
/**
|
||||
* 指定不通过代理应访问的主机。
|
||||
*/
|
||||
private String nonProxyHosts;
|
||||
/**
|
||||
* 是否禁用Socket代理
|
||||
*/
|
||||
private boolean disableSocketProxy = DEFAULT_DISABLE_SOCKET_PROXY;
|
||||
/**
|
||||
* 是否使用基本身份验证对代理服务器进行抢先身份验证
|
||||
*/
|
||||
private boolean preemptiveBasicProxyAuth;
|
||||
/**
|
||||
* Socket层传输数据的超时时间(单位:毫秒)。默认为50000毫秒
|
||||
*/
|
||||
private int socketTimeout = DEFAULT_SOCKET_TIMEOUT;
|
||||
/**
|
||||
* 请求的默认超时时间。默认为0,禁用的。
|
||||
*/
|
||||
private int requestTimeout = DEFAULT_REQUEST_TIMEOUT;
|
||||
/**
|
||||
* 请求的默认超时时间。默认为0,禁用的。
|
||||
*/
|
||||
private int clientExecutionTimeout = DEFAULT_CLIENT_EXECUTION_TIMEOUT;
|
||||
/**
|
||||
* 公共HTTP请求头前缀。
|
||||
*/
|
||||
private String userAgentPrefix = DEFAULT_USER_AGENT;
|
||||
/**
|
||||
* 公共HTTP请求头后缀。
|
||||
*/
|
||||
private String userAgentSuffix;
|
||||
/**
|
||||
* 是否使用com.amazonaws.http.IdleConnectionReaper管理旧连接
|
||||
*/
|
||||
private boolean useReaper = DEFAULT_USE_REAPER;
|
||||
/**
|
||||
* 是否使用gzip解压缩
|
||||
*/
|
||||
private boolean useGzip = DEFAULT_USE_GZIP;
|
||||
/**
|
||||
* Socket发送缓冲区的大小提示(以字节为单位)。
|
||||
*/
|
||||
private int socketSendBufferSizeHint = 0;
|
||||
/**
|
||||
* Socket接收缓冲区的大小提示(以字节为单位)。
|
||||
*/
|
||||
private int socketReceiveBufferSizeHint = 0;
|
||||
/**
|
||||
* 设置签名算法对请求进行签名。如果未明确设置,客户端将通过提取SDK中的配置文件来确定要使用的算法
|
||||
*/
|
||||
private String signerOverride;
|
||||
/**
|
||||
* 响应元数据缓存大小
|
||||
*/
|
||||
private int responseMetadataCacheSize = DEFAULT_RESPONSE_METADATA_CACHE_SIZE;
|
||||
/**
|
||||
* 是否使用USE_EXPECT_CONTINUE作为期望值
|
||||
*/
|
||||
private boolean useExpectContinue = DEFAULT_USE_EXPECT_CONTINUE;
|
||||
/**
|
||||
* 是否缓存响应元数据
|
||||
*/
|
||||
private boolean cacheResponseMetadata = DEFAULT_CACHE_RESPONSE_METADATA;
|
||||
/**
|
||||
* 连接TTL (生存时间)。Http连接由连接管理器用TTL缓存。
|
||||
*/
|
||||
private long connectionTTL = DEFAULT_CONNECTION_TTL;
|
||||
/**
|
||||
* 连接池中连接的最大空闲时间 (以毫秒为单位)。
|
||||
*/
|
||||
private long connectionMaxIdleMillis = DEFAULT_CONNECTION_MAX_IDLE_MILLIS;
|
||||
/**
|
||||
* 在必须验证连接是否仍处于打开状态之前,连接可以在连接池中处于空闲状态。
|
||||
*/
|
||||
private int validateAfterInactivityMillis = DEFAULT_VALIDATE_AFTER_INACTIVITY_MILLIS;
|
||||
/**
|
||||
* 是否使用TCP KeepAlive的默认值。
|
||||
*/
|
||||
private boolean tcpKeepAlive = DEFAULT_TCP_KEEP_ALIVE;
|
||||
/**
|
||||
* 所有请求的公共请求头
|
||||
*/
|
||||
private Map<String, String> headers = new HashMap<>();
|
||||
/**
|
||||
* 请求失败最大重试次数
|
||||
*/
|
||||
private int maxConsecutiveRetriesBeforeThrottling = DEFAULT_MAX_CONSECUTIVE_RETRIES_BEFORE_THROTTLING;
|
||||
/**
|
||||
* 是否禁用主机前缀
|
||||
*/
|
||||
private boolean disableHostPrefixInjection;
|
||||
/**
|
||||
* 重试模式
|
||||
*/
|
||||
private RetryMode retryMode;
|
||||
|
||||
public ClientConfiguration toClientConfig() {
|
||||
ClientConfiguration clientConfiguration = new ClientConfiguration();
|
||||
BeanUtil.copyProperties(this, clientConfiguration,
|
||||
"maxErrorRetry", "proxyPort");
|
||||
if (this.maxErrorRetry != -1) {
|
||||
clientConfiguration.setMaxErrorRetry(this.maxErrorRetry);
|
||||
}
|
||||
if (this.proxyPort != -1) {
|
||||
clientConfiguration.setProxyPort(this.proxyPort);
|
||||
}
|
||||
return clientConfiguration;
|
||||
}
|
||||
|
||||
}
|
@@ -1,26 +1,28 @@
|
||||
package com.schisandra.oss.application.oss.core.baidu.model;
|
||||
package com.schisandra.oss.application.oss.core.jd.model;
|
||||
|
||||
|
||||
import com.schisandra.oss.application.oss.model.SliceConfig;
|
||||
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author 陈敏
|
||||
* @version BaiduOssConfig.java, v 1.1 2022/2/19 18:25 chenmin Exp $
|
||||
* @author landaiqing
|
||||
* @version JdOssConfig.java, v 1.1 2022/2/19 18:36 chenmin Exp $
|
||||
* Created on 2022/2/19
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
public class BaiduOssConfig {
|
||||
public class JdOssConfig {
|
||||
|
||||
private String basePath;
|
||||
private String bucketName;
|
||||
private String accessKeyId;
|
||||
private String secretAccessKey;
|
||||
|
||||
private BaiduOssClientConfig clientConfig;
|
||||
private String bucketName;
|
||||
private String endpoint;
|
||||
private String accessKey;
|
||||
private String secretKey;
|
||||
|
||||
private String region;
|
||||
|
||||
private JdOssClientConfig clientConfig;
|
||||
|
||||
/**
|
||||
* 断点续传参数
|
@@ -28,9 +28,6 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.Headers;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.context.annotation.ScopedProxyMode;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
|
@@ -8,7 +8,6 @@ import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||
import com.schisandra.oss.application.oss.core.minio.model.MinioOssClientConfig;
|
||||
import com.schisandra.oss.application.oss.core.minio.model.MinioOssConfig;
|
||||
import com.schisandra.oss.common.entity.Result;
|
||||
import com.schisandra.oss.common.redis.RedisUtil;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssMinioBO;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssMinioDomainService;
|
||||
import io.minio.MinioClient;
|
||||
@@ -29,8 +28,6 @@ import java.util.concurrent.TimeUnit;
|
||||
@Slf4j
|
||||
public class MinioOssConfiguration {
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
MinioOssConfiguration minioOssConfiguration;
|
||||
|
||||
|
@@ -111,5 +111,44 @@
|
||||
<artifactId>thumbnailator</artifactId>
|
||||
<version>0.4.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-net</groupId>
|
||||
<artifactId>commons-net</artifactId>
|
||||
<version>3.8.0</version>
|
||||
</dependency>
|
||||
<!--minio-->
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
<version>8.2.1</version>
|
||||
</dependency>
|
||||
<!-- 阿里云 -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.14.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 亚马逊 -->
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>s3</artifactId>
|
||||
<version>2.17.160</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 华为云存储 -->
|
||||
<dependency>
|
||||
<groupId>com.huaweicloud</groupId>
|
||||
<artifactId>esdk-obs-java-bundle</artifactId>
|
||||
<version>3.21.11</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 京东云存储 -->
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-s3</artifactId>
|
||||
<version>1.12.167</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.schisandra.oss.common.redis;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -58,6 +57,7 @@ public class RedisUtil {
|
||||
public void setJson(String key, Object value) {
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
}
|
||||
|
||||
public HashMap<String, String> getJson(String key) {
|
||||
return (HashMap<String, String>) redisTemplate.opsForValue().get(key);
|
||||
}
|
||||
|
@@ -1,194 +0,0 @@
|
||||
package com.schisandra.oss.common.utils;
|
||||
|
||||
import net.coobird.thumbnailator.Thumbnails;
|
||||
import net.coobird.thumbnailator.geometry.Positions;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.text.AttributedString;
|
||||
|
||||
/**
|
||||
* 图像工具类
|
||||
*/
|
||||
public class ImageUtil {
|
||||
private static final Logger log = LoggerFactory.getLogger(ImageUtil.class);
|
||||
//压缩率
|
||||
private static final transient float IMAGE_RATIO = 0.1f;
|
||||
//压缩最大宽度
|
||||
private static final transient int IMAGE_WIDTH = 800;
|
||||
// 水印透明度
|
||||
private static float alpha = 0.3f;
|
||||
// 水印文字字体
|
||||
private static Font font = new Font("PingFang SC Regular", Font.PLAIN, 36);
|
||||
// 水印文字颜色
|
||||
private static Color color = new Color(111, 111, 111);
|
||||
//水印文字内容
|
||||
private static final String text = "这是一个水印文本";
|
||||
// 水印之间的间隔
|
||||
private static final int XMOVE = 80;
|
||||
// 水印之间的间隔
|
||||
private static final int YMOVE = 80;
|
||||
|
||||
/**
|
||||
* 压缩图像
|
||||
*
|
||||
* @param image
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static BufferedImage compress(BufferedImage image) throws IOException {
|
||||
Thumbnails.Builder<BufferedImage> imageBuilder = Thumbnails.of(image).outputQuality(IMAGE_RATIO);
|
||||
if (image.getWidth() > IMAGE_WIDTH) {
|
||||
return imageBuilder.width(IMAGE_WIDTH).asBufferedImage();
|
||||
} else {
|
||||
return imageBuilder.scale(1).asBufferedImage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 图像添加水印
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public static BufferedImage setWatermark(BufferedImage image) throws IOException {
|
||||
return Thumbnails.of(image)
|
||||
.outputQuality(IMAGE_RATIO)
|
||||
.scale(1)
|
||||
.watermark(Positions.BOTTOM_RIGHT
|
||||
, createWatermark(text
|
||||
, image.getWidth()
|
||||
, image.getHeight()
|
||||
)
|
||||
, alpha)
|
||||
.asBufferedImage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件扩展名判断文件是否图片格式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isImage(String fileName) {
|
||||
String[] imageExtension = new String[]{"jpeg", "jpg", "gif", "bmp", "png"};
|
||||
|
||||
for (String e : imageExtension) if (getFileExtention(fileName).toLowerCase().equals(e)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件后缀名称
|
||||
*
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public static String getFileExtention(String fileName) {
|
||||
String extension = fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
return extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据图片对象获取对应InputStream
|
||||
*
|
||||
* @param image
|
||||
* @param readImageFormat
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static InputStream getInputStream(BufferedImage image, String readImageFormat) throws IOException {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
ImageIO.write(image, readImageFormat, os);
|
||||
InputStream is = new ByteArrayInputStream(os.toByteArray());
|
||||
os.close();
|
||||
return is;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建水印图片
|
||||
*
|
||||
* @param text 水印文字
|
||||
* @param width 图片宽
|
||||
* @param height 图片高
|
||||
* @return
|
||||
*/
|
||||
public static BufferedImage createWatermark(String text, int width, int height) {
|
||||
BufferedImage image = new BufferedImage(width
|
||||
, height, BufferedImage.TYPE_INT_RGB);
|
||||
// 2.获取图片画笔
|
||||
Graphics2D g = image.createGraphics();
|
||||
// ---------- 增加下面的代码使得背景透明 -----------------
|
||||
image = g.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT);
|
||||
g.dispose();
|
||||
g = image.createGraphics();
|
||||
// ---------- 背景透明代码结束 -----------------
|
||||
// 6、处理文字
|
||||
AttributedString ats = new AttributedString(text);
|
||||
ats.addAttribute(TextAttribute.FONT, font, 0, text.length());
|
||||
AttributedCharacterIterator iter = ats.getIterator();
|
||||
// 7、设置对线段的锯齿状边缘处理
|
||||
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
// 8、设置水印旋转
|
||||
g.rotate(Math.toRadians(-30));
|
||||
// 9、设置水印文字颜色
|
||||
g.setColor(color);
|
||||
// 10、设置水印文字Font
|
||||
g.setFont(font);
|
||||
// 11、设置水印文字透明度
|
||||
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
|
||||
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
|
||||
/**
|
||||
* 水印铺满图片
|
||||
* 计算水印位置
|
||||
*/
|
||||
int x = -width / 2;
|
||||
int y = -height / 2;
|
||||
int[] arr = getWidthAndHeight(text, font);
|
||||
int markWidth = arr[0];// 字体长度
|
||||
int markHeight = arr[1];// 字体高度
|
||||
// 循环添加水印
|
||||
while (x < width * 1.5) {
|
||||
y = -height / 2;
|
||||
while (y < height * 1.5) {
|
||||
g.drawString(text, x, y);
|
||||
|
||||
y += markHeight + YMOVE;
|
||||
}
|
||||
x += markWidth + XMOVE;
|
||||
}
|
||||
// 13、释放资源
|
||||
g.dispose();
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算字体宽度及高度
|
||||
*
|
||||
* @param text
|
||||
* @param font
|
||||
* @return
|
||||
*/
|
||||
private static int[] getWidthAndHeight(String text, Font font) {
|
||||
Rectangle2D r = font.getStringBounds(text, new FontRenderContext(
|
||||
AffineTransform.getScaleInstance(1, 1), false, false));
|
||||
int unitHeight = (int) Math.floor(r.getHeight());//
|
||||
// 获取整个str用了font样式的宽度这里用四舍五入后+1保证宽度绝对能容纳这个字符串作为图片的宽度
|
||||
int width = (int) Math.round(r.getWidth()) + 1;
|
||||
// 把单个字符的高度+3保证高度绝对能容纳字符串作为图片的高度
|
||||
int height = unitHeight + 3;
|
||||
return new int[]{width, height};
|
||||
}
|
||||
}
|
@@ -25,4 +25,5 @@ public interface SchisandraOssHuaweiDomainService {
|
||||
*/
|
||||
Boolean delete(SchisandraOssHuaweiBO schisandraOssHuaweiBO);
|
||||
|
||||
SchisandraOssHuaweiBO getHuaweiOssConfig(String userId);
|
||||
}
|
||||
|
@@ -25,4 +25,5 @@ public interface SchisandraOssJdDomainService {
|
||||
*/
|
||||
Boolean delete(SchisandraOssJdBO schisandraOssJdBO);
|
||||
|
||||
SchisandraOssJdBO getJdOssConfig(String userId);
|
||||
}
|
||||
|
@@ -25,4 +25,5 @@ public interface SchisandraOssJdbcDomainService {
|
||||
*/
|
||||
Boolean delete(SchisandraOssJdbcBO schisandraOssJdbcBO);
|
||||
|
||||
SchisandraOssJdbcBO getJdbcOssConfig(String userId);
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package com.schisandra.oss.domain.service.impl;
|
||||
|
||||
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
|
||||
import com.schisandra.oss.domain.convert.SchisandraOssHuaweiBOConverter;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssHuaweiBO;
|
||||
import com.schisandra.oss.domain.convert.SchisandraOssHuaweiBOConverter;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssHuaweiDomainService;
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssHuawei;
|
||||
import com.schisandra.oss.infra.basic.service.SchisandraOssHuaweiService;
|
||||
@@ -45,4 +45,11 @@ public class SchisandraOssHuaweiDomainServiceImpl implements SchisandraOssHuawei
|
||||
return schisandraOssHuaweiService.update(schisandraOssHuawei) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchisandraOssHuaweiBO getHuaweiOssConfig(String userId) {
|
||||
SchisandraOssHuawei schisandraOssHuawei = schisandraOssHuaweiService.getHuaweiOssConfig(userId);
|
||||
SchisandraOssHuaweiBO schisandraOssHuaweiBO = SchisandraOssHuaweiBOConverter.INSTANCE.convertEntityToBO(schisandraOssHuawei);
|
||||
return schisandraOssHuaweiBO;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package com.schisandra.oss.domain.service.impl;
|
||||
|
||||
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
|
||||
import com.schisandra.oss.domain.convert.SchisandraOssJdBOConverter;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssJdBO;
|
||||
import com.schisandra.oss.domain.convert.SchisandraOssJdBOConverter;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssJdDomainService;
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssJd;
|
||||
import com.schisandra.oss.infra.basic.service.SchisandraOssJdService;
|
||||
@@ -45,4 +45,11 @@ public class SchisandraOssJdDomainServiceImpl implements SchisandraOssJdDomainSe
|
||||
return schisandraOssJdService.update(schisandraOssJd) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchisandraOssJdBO getJdOssConfig(String userId) {
|
||||
SchisandraOssJd schisandraOssJd = schisandraOssJdService.getJdOssConfig(userId);
|
||||
SchisandraOssJdBO schisandraOssJdBO = SchisandraOssJdBOConverter.INSTANCE.convertEntityToBO(schisandraOssJd);
|
||||
return schisandraOssJdBO;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package com.schisandra.oss.domain.service.impl;
|
||||
|
||||
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
|
||||
import com.schisandra.oss.domain.convert.SchisandraOssJdbcBOConverter;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssJdbcBO;
|
||||
import com.schisandra.oss.domain.convert.SchisandraOssJdbcBOConverter;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssJdbcDomainService;
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssJdbc;
|
||||
import com.schisandra.oss.infra.basic.service.SchisandraOssJdbcService;
|
||||
@@ -45,4 +45,11 @@ public class SchisandraOssJdbcDomainServiceImpl implements SchisandraOssJdbcDoma
|
||||
return schisandraOssJdbcService.update(schisandraOssJdbc) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchisandraOssJdbcBO getJdbcOssConfig(String userId) {
|
||||
SchisandraOssJdbc schisandraOssJdbc = schisandraOssJdbcService.getJdbcOssConfig(userId);
|
||||
SchisandraOssJdbcBO schisandraOssJdbcBO = SchisandraOssJdbcBOConverter.INSTANCE.convertEntityToBO(schisandraOssJdbc);
|
||||
return schisandraOssJdbcBO;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,13 +1,12 @@
|
||||
package com.schisandra.oss.infra.basic.dao;
|
||||
|
||||
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssAli;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssAli;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* 表数据库访问层
|
||||
* 表数据库访问层
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-05-14 20:10:20
|
||||
|
@@ -43,4 +43,5 @@ public interface SchisandraOssHuaweiService {
|
||||
boolean deleteById(Long id);
|
||||
|
||||
|
||||
SchisandraOssHuawei getHuaweiOssConfig(String userId);
|
||||
}
|
||||
|
@@ -43,4 +43,5 @@ public interface SchisandraOssJdService {
|
||||
boolean deleteById(Long id);
|
||||
|
||||
|
||||
SchisandraOssJd getJdOssConfig(String userId);
|
||||
}
|
||||
|
@@ -43,4 +43,5 @@ public interface SchisandraOssJdbcService {
|
||||
boolean deleteById(Long id);
|
||||
|
||||
|
||||
SchisandraOssJdbc getJdbcOssConfig(String userId);
|
||||
}
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package com.schisandra.oss.infra.basic.service.impl;
|
||||
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssHuawei;
|
||||
import com.schisandra.oss.infra.basic.dao.SchisandraOssHuaweiDao;
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssHuawei;
|
||||
import com.schisandra.oss.infra.basic.entity.table.SchisandraOssHuaweiTableDef;
|
||||
import com.schisandra.oss.infra.basic.service.SchisandraOssHuaweiService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -38,7 +39,7 @@ public class SchisandraOssHuaweiServiceImpl implements SchisandraOssHuaweiServic
|
||||
*/
|
||||
@Override
|
||||
public int insert(SchisandraOssHuawei schisandraOssHuawei) {
|
||||
return this.schisandraOssHuaweiDao.insert(schisandraOssHuawei,true);
|
||||
return this.schisandraOssHuaweiDao.insert(schisandraOssHuawei, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +50,7 @@ public class SchisandraOssHuaweiServiceImpl implements SchisandraOssHuaweiServic
|
||||
*/
|
||||
@Override
|
||||
public int update(SchisandraOssHuawei schisandraOssHuawei) {
|
||||
return this.schisandraOssHuaweiDao.update(schisandraOssHuawei,true);
|
||||
return this.schisandraOssHuaweiDao.update(schisandraOssHuawei, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,5 +64,10 @@ public class SchisandraOssHuaweiServiceImpl implements SchisandraOssHuaweiServic
|
||||
return this.schisandraOssHuaweiDao.deleteById(id) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchisandraOssHuawei getHuaweiOssConfig(String userId) {
|
||||
return schisandraOssHuaweiDao.selectOneByCondition(SchisandraOssHuaweiTableDef.SCHISANDRA_OSS_HUAWEI.USER_ID.eq(userId));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package com.schisandra.oss.infra.basic.service.impl;
|
||||
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssJd;
|
||||
import com.schisandra.oss.infra.basic.dao.SchisandraOssJdDao;
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssJd;
|
||||
import com.schisandra.oss.infra.basic.entity.table.SchisandraOssJdTableDef;
|
||||
import com.schisandra.oss.infra.basic.service.SchisandraOssJdService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -38,7 +39,7 @@ public class SchisandraOssJdServiceImpl implements SchisandraOssJdService {
|
||||
*/
|
||||
@Override
|
||||
public int insert(SchisandraOssJd schisandraOssJd) {
|
||||
return this.schisandraOssJdDao.insert(schisandraOssJd,true);
|
||||
return this.schisandraOssJdDao.insert(schisandraOssJd, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +50,7 @@ public class SchisandraOssJdServiceImpl implements SchisandraOssJdService {
|
||||
*/
|
||||
@Override
|
||||
public int update(SchisandraOssJd schisandraOssJd) {
|
||||
return this.schisandraOssJdDao.update(schisandraOssJd,true);
|
||||
return this.schisandraOssJdDao.update(schisandraOssJd, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,5 +64,10 @@ public class SchisandraOssJdServiceImpl implements SchisandraOssJdService {
|
||||
return this.schisandraOssJdDao.deleteById(id) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchisandraOssJd getJdOssConfig(String userId) {
|
||||
return schisandraOssJdDao.selectOneByCondition(SchisandraOssJdTableDef.SCHISANDRA_OSS_JD.USER_ID.eq(userId));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package com.schisandra.oss.infra.basic.service.impl;
|
||||
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssJdbc;
|
||||
import com.schisandra.oss.infra.basic.dao.SchisandraOssJdbcDao;
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssJdbc;
|
||||
import com.schisandra.oss.infra.basic.entity.table.SchisandraOssJdbcTableDef;
|
||||
import com.schisandra.oss.infra.basic.service.SchisandraOssJdbcService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -38,7 +39,7 @@ public class SchisandraOssJdbcServiceImpl implements SchisandraOssJdbcService {
|
||||
*/
|
||||
@Override
|
||||
public int insert(SchisandraOssJdbc schisandraOssJdbc) {
|
||||
return this.schisandraOssJdbcDao.insert(schisandraOssJdbc,true);
|
||||
return this.schisandraOssJdbcDao.insert(schisandraOssJdbc, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +50,7 @@ public class SchisandraOssJdbcServiceImpl implements SchisandraOssJdbcService {
|
||||
*/
|
||||
@Override
|
||||
public int update(SchisandraOssJdbc schisandraOssJdbc) {
|
||||
return this.schisandraOssJdbcDao.update(schisandraOssJdbc,true);
|
||||
return this.schisandraOssJdbcDao.update(schisandraOssJdbc, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,5 +64,10 @@ public class SchisandraOssJdbcServiceImpl implements SchisandraOssJdbcService {
|
||||
return this.schisandraOssJdbcDao.deleteById(id) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchisandraOssJdbc getJdbcOssConfig(String userId) {
|
||||
return schisandraOssJdbcDao.selectOneByCondition(SchisandraOssJdbcTableDef.SCHISANDRA_OSS_JDBC.USER_ID.eq(userId));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user