feat(minio工具类): 修改、增加工具类内容
This commit is contained in:
parent
57ce1296b2
commit
670250a6d3
|
@ -6,7 +6,7 @@ import lombok.Data;
|
|||
* 信息提示常量类
|
||||
*/
|
||||
@Data
|
||||
public class MessageConstant {
|
||||
public class CommonMessageConstant {
|
||||
public static final String PASSWORD_ERROR = "密码错误";
|
||||
public static final String OLD_PASSWORD_ERROR = "旧密码不匹配";
|
||||
public static final String OLD_PASSWORD_SAME_NEW_PASSWORD = "旧密码与新密码相同";
|
||||
|
@ -35,8 +35,4 @@ public class MessageConstant {
|
|||
public static final String LOGIN_DTO_IS_EMPTY = "登录参数不能为空";
|
||||
public static final String TOKEN_IS_EMPTY = "token为空";
|
||||
public static final String DATA_IS_EMPTY = "数据为空";
|
||||
public static final String EMPTY_SEND_OBJECT = "空发送对象";
|
||||
public static final String ADDRESS_NOT_NULL = "收件人不能为空";
|
||||
public static final String TITLE_NOT_NULL = "标题不能为空";
|
||||
public static final String SEND_MESSAGE_NOT_NULL = "发送消息不能为空";
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package cn.bunny.common.constant;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 邮箱消息
|
||||
*/
|
||||
@Data
|
||||
public class MailMessageConstant {
|
||||
public static final String EMPTY_SEND_OBJECT = "空发送对象";
|
||||
public static final String ADDRESS_NOT_NULL = "收件人不能为空";
|
||||
public static final String TITLE_NOT_NULL = "标题不能为空";
|
||||
public static final String SEND_MESSAGE_NOT_NULL = "发送消息不能为空";
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package cn.bunny.common.constant;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class MinioMessageConstant {
|
||||
public static final String BUCKET_EXISTS_EXCEPTION = "查询文化部对象失败";
|
||||
public static final String DELETE_BUCKET_EXCEPTION = "删除文件对象失败";
|
||||
public static final String GET_BUCKET_EXCEPTION = "获取文件信息失败";
|
||||
public static final String QUERY_BUCKET_EXCEPTION = "查询文件信息失败";
|
||||
public static final String CREATE_BUCKET_EXCEPTION = "创建文件对象失败";
|
||||
public static final String UPDATE_BUCKET_EXCEPTION = "更新文件对象失败";
|
||||
}
|
|
@ -1,8 +1,11 @@
|
|||
package cn.bunny.common.constant;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 数据库中自动填充字段
|
||||
*/
|
||||
@Data
|
||||
public class SQLAutoFillConstant {
|
||||
public static final String SET_CREATE_TIME = "setCreateTime";
|
||||
public static final String SET_UPDATE_TIME = "setUpdateTime";
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package cn.bunny.common.constant;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@Data
|
||||
public class SecurityConstant {
|
||||
public static String[] annotations = {"/", "/test/**", "/diagram-viewer/**", "/editor-app/**", "/*.html", "/admin/system/index/login", "/favicon.ico", "/swagger-resources/**", "/webjars/**", "/v3/**", "/swagger-ui.html/**", "/doc.html"};
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "snowflake")
|
||||
@ConfigurationProperties(prefix = "bunny.snowflake")
|
||||
@Data
|
||||
public class SnowflakeProperties {
|
||||
// 数据中心id
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package cn.bunny.common.service.exception;
|
||||
|
||||
import cn.bunny.common.constant.MessageConstant;
|
||||
import cn.bunny.common.constant.CommonMessageConstant;
|
||||
import cn.bunny.common.result.Result;
|
||||
import cn.bunny.enums.ResultCodeEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -72,10 +72,10 @@ public class GlobalExceptionHandler {
|
|||
// 截取用户名
|
||||
String username = message.split(" ")[2];
|
||||
// 错误信息
|
||||
String errorMessage = username + MessageConstant.ALREADY_EXISTS;
|
||||
String errorMessage = username + CommonMessageConstant.ALREADY_EXISTS;
|
||||
return Result.error(errorMessage);
|
||||
} else {
|
||||
return Result.error(MessageConstant.UNKNOWN_ERROR);
|
||||
return Result.error(CommonMessageConstant.UNKNOWN_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package cn.bunny.module.mail.utils;
|
||||
|
||||
import cn.bunny.common.constant.MessageConstant;
|
||||
import cn.bunny.common.constant.MailMessageConstant;
|
||||
import cn.bunny.common.service.utils.EmptyUtil;
|
||||
import cn.bunny.entity.email.EmailSend;
|
||||
|
||||
|
@ -12,12 +12,12 @@ public class MailSendCheckUtil {
|
|||
*/
|
||||
public static void check(EmailSend emailSend) {
|
||||
// 空发送对象
|
||||
EmptyUtil.isEmpty(emailSend, MessageConstant.EMPTY_SEND_OBJECT);
|
||||
EmptyUtil.isEmpty(emailSend, MailMessageConstant.EMPTY_SEND_OBJECT);
|
||||
// 收件人不能为空
|
||||
EmptyUtil.isEmpty(emailSend.getSendTo(), MessageConstant.ADDRESS_NOT_NULL);
|
||||
EmptyUtil.isEmpty(emailSend.getSendTo(), MailMessageConstant.ADDRESS_NOT_NULL);
|
||||
// 标题不能为空
|
||||
EmptyUtil.isEmpty(emailSend.getSubject(), MessageConstant.TITLE_NOT_NULL);
|
||||
EmptyUtil.isEmpty(emailSend.getSubject(), MailMessageConstant.TITLE_NOT_NULL);
|
||||
// 发送消息不能为空
|
||||
EmptyUtil.isEmpty(emailSend.getMessage(), MessageConstant.SEND_MESSAGE_NOT_NULL);
|
||||
EmptyUtil.isEmpty(emailSend.getMessage(), MailMessageConstant.SEND_MESSAGE_NOT_NULL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.bunny</groupId>
|
||||
<artifactId>service-utils</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- minio -->
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
|
|
|
@ -1,4 +1,677 @@
|
|||
package cn.bunny.module.minio.utils;
|
||||
|
||||
import cn.bunny.common.constant.MinioMessageConstant;
|
||||
import cn.bunny.common.service.exception.BunnyException;
|
||||
import io.minio.*;
|
||||
import io.minio.messages.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Minio操作工具类
|
||||
* 简化操作步骤
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MinioUtil {
|
||||
}
|
||||
@Autowired
|
||||
private MinioClient minioClient;
|
||||
|
||||
/**
|
||||
* 判断桶是否存在
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @return 布尔值,是否存在
|
||||
*/
|
||||
public boolean bucketExists(String bucketName) {
|
||||
boolean found = false;
|
||||
try {
|
||||
found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
|
||||
return found;
|
||||
} catch (Exception exception) {
|
||||
log.error("判断桶是否存在 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
}
|
||||
throw new BunnyException(MinioMessageConstant.BUCKET_EXISTS_EXCEPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶的加密配置
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @return 是否删除成功,返回布尔值
|
||||
*/
|
||||
public boolean deleteBucketEncryption(String bucketName) {
|
||||
try {
|
||||
minioClient.deleteBucketEncryption(DeleteBucketEncryptionArgs.builder().build());
|
||||
log.info("删除桶的加密配置 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶的加密配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
}
|
||||
throw new BunnyException(MinioMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶的生命周期配置
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @return 返回布尔值,是否删除成功
|
||||
*/
|
||||
public boolean deleteBucketLifecycle(String bucketName) {
|
||||
try {
|
||||
minioClient.deleteBucketLifecycle(DeleteBucketLifecycleArgs.builder().build());
|
||||
log.info("删除桶的生命周期配置 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶的生命周期配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶的通知配置
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return 返回布尔值是否删除成功
|
||||
*/
|
||||
public boolean deleteBucketNotification(String bucketName) {
|
||||
try {
|
||||
minioClient.deleteBucketNotification(DeleteBucketNotificationArgs.builder().bucket(bucketName).build());
|
||||
log.info("删除桶的通知配置 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶的加密配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶策略配置
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return 返回布尔值是否删除成功
|
||||
*/
|
||||
public boolean deleteBucketPolicy(String bucketName) {
|
||||
try {
|
||||
minioClient.deleteBucketPolicy(DeleteBucketPolicyArgs.builder().bucket(bucketName).build());
|
||||
log.info("删除桶中的对象锁配置 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶的加密配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶的桶复制配置
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return 返回布尔值是否删除成功
|
||||
*/
|
||||
public boolean deleteBucketReplication(String bucketName) {
|
||||
try {
|
||||
minioClient.deleteBucketReplication(DeleteBucketReplicationArgs.builder().bucket(bucketName).build());
|
||||
log.info("删除桶的桶复制配置 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶的桶复制配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶的标签
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return 返回布尔值是否删除成功
|
||||
*/
|
||||
public boolean deleteBucketTags(String bucketName) {
|
||||
try {
|
||||
minioClient.deleteBucketTags(DeleteBucketTagsArgs.builder().bucket(bucketName).build());
|
||||
log.info("删除桶的标签 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶的桶复制配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶中的对象锁配置
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return 返回布尔值是否删除成功
|
||||
*/
|
||||
public boolean deleteObjectLockConfiguration(String bucketName) {
|
||||
try {
|
||||
minioClient.deleteObjectLockConfiguration(DeleteObjectLockConfigurationArgs.builder().bucket(bucketName).build());
|
||||
log.info("删除桶中的对象锁配置 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶中的对象锁配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存储桶的加密配置
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return SseConfiguration 获取成功不为null
|
||||
*/
|
||||
public SseConfiguration getBucketEncryption(String bucketName) {
|
||||
SseConfiguration conf = null;
|
||||
|
||||
try {
|
||||
conf = minioClient.getBucketEncryption(GetBucketEncryptionArgs.builder().bucket(bucketName).build());
|
||||
log.info("获取存储桶的加密配置 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("获取存储桶的加密配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.GET_BUCKET_EXCEPTION);
|
||||
}
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存储桶的生命周期配置
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return LifecycleConfiguration 获取成功不为null
|
||||
*/
|
||||
public LifecycleConfiguration getBucketLifecycle(String bucketName) {
|
||||
LifecycleConfiguration lifecycle = null;
|
||||
try {
|
||||
lifecycle = minioClient.getBucketLifecycle(GetBucketLifecycleArgs.builder().bucket(bucketName).build());
|
||||
log.info("获取存储桶的生命周期配置 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("获取存储桶的生命周期配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.GET_BUCKET_EXCEPTION);
|
||||
}
|
||||
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存储桶的通知配置
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return NotificationConfiguration 获取成功不为null
|
||||
*/
|
||||
public NotificationConfiguration getBucketNotification(String bucketName) {
|
||||
NotificationConfiguration configuration = null;
|
||||
|
||||
try {
|
||||
configuration = minioClient.getBucketNotification(GetBucketNotificationArgs.builder().bucket(bucketName).build());
|
||||
log.info("获取存储桶的通知配置 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("获取存储桶的通知配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.GET_BUCKET_EXCEPTION);
|
||||
}
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取桶的桶策略配置
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return String 获取成功不为null
|
||||
*/
|
||||
public String getBucketPolicy(String bucketName) {
|
||||
String config = null;
|
||||
|
||||
try {
|
||||
config = minioClient.getBucketPolicy(GetBucketPolicyArgs.builder().bucket(bucketName).build());
|
||||
log.info("获取桶的桶策略配置 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("获取桶的桶策略配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.GET_BUCKET_EXCEPTION);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取桶复制参数
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return ReplicationConfiguration 获取成功不为null
|
||||
*/
|
||||
public ReplicationConfiguration getBucketReplication(String bucketName) {
|
||||
ReplicationConfiguration configuration = null;
|
||||
|
||||
try {
|
||||
configuration = minioClient.getBucketReplication(GetBucketReplicationArgs.builder().bucket(bucketName).build());
|
||||
log.info("获取桶复制参数 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("获取桶复制参数 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.GET_BUCKET_EXCEPTION);
|
||||
}
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存储桶的标签
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return Tags 获取成功不为null
|
||||
*/
|
||||
public Tags getBucketTags(String bucketName) {
|
||||
Tags tags = null;
|
||||
|
||||
try {
|
||||
tags = minioClient.getBucketTags(GetBucketTagsArgs.builder().bucket(bucketName).build());
|
||||
log.info("获取存储桶的标签 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("获取存储桶的标签 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.GET_BUCKET_EXCEPTION);
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存储桶的版本控制配置
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return Tags 获取成功不为null
|
||||
*/
|
||||
public VersioningConfiguration getBucketVersioning(String bucketName) {
|
||||
VersioningConfiguration configuration = null;
|
||||
|
||||
try {
|
||||
configuration = minioClient.getBucketVersioning(GetBucketVersioningArgs.builder().bucket(bucketName).build());
|
||||
log.info("获取存储桶的版本控制配置 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("获取存储桶的版本控制配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.GET_BUCKET_EXCEPTION);
|
||||
}
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存储桶中的对象锁配置
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return Tags 获取成功不为null
|
||||
*/
|
||||
public ObjectLockConfiguration getObjectLockConfiguration(String bucketName) {
|
||||
ObjectLockConfiguration configuration = null;
|
||||
try {
|
||||
configuration = minioClient.getObjectLockConfiguration(GetObjectLockConfigurationArgs.builder().bucket(bucketName).build());
|
||||
log.info("获取存储桶中的对象锁配置 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("获取存储桶中的对象锁配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.GET_BUCKET_EXCEPTION);
|
||||
}
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列出所有桶的桶信息
|
||||
*
|
||||
* @return Tags 获取成功不为null
|
||||
*/
|
||||
public List<Bucket> listBuckets() {
|
||||
List<Bucket> buckets = null;
|
||||
|
||||
try {
|
||||
buckets = minioClient.listBuckets();
|
||||
log.info("列出所有桶的桶信息 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("列出所有桶的桶信息 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.QUERY_BUCKET_EXCEPTION);
|
||||
}
|
||||
|
||||
return buckets;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建桶
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return boolean 返回是否创建成功
|
||||
*/
|
||||
public boolean makeBucket(String bucketName) {
|
||||
try {
|
||||
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
||||
log.info("创建桶 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("创建桶 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.CREATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建桶
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return boolean 返回是否创建成功
|
||||
*/
|
||||
public boolean makeBucket(String bucketName, String region) {
|
||||
try {
|
||||
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).region(region).build());
|
||||
log.info("创建桶 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("创建桶 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.CREATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建桶
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return boolean 返回是否创建成功
|
||||
*/
|
||||
public boolean makeBucket(String bucketName, String region, boolean objectLock) {
|
||||
try {
|
||||
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).region(region).objectLock(objectLock).build());
|
||||
log.info("创建桶 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("创建桶 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.CREATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
* @return boolean 是否删除成功
|
||||
*/
|
||||
public boolean removeBucket(String bucketName) {
|
||||
try {
|
||||
minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
|
||||
log.info("删除桶 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置桶的加密配置
|
||||
*
|
||||
* @param bucketName 同名称
|
||||
* @param configuration 配置信息
|
||||
* @return 布尔值是否完成
|
||||
*/
|
||||
public boolean setBucketEncryption(String bucketName, SseConfiguration configuration) {
|
||||
try {
|
||||
minioClient.setBucketEncryption(SetBucketEncryptionArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.config(configuration)
|
||||
.build());
|
||||
log.info("设置桶的加密配置 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("设置桶的加密配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.UPDATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置桶策略
|
||||
*
|
||||
* @param bucketName 同名称
|
||||
* @param policyJson 配置信息
|
||||
* @return 布尔值是否完成
|
||||
*/
|
||||
public boolean setBucketPolicy(String bucketName, String policyJson) {
|
||||
try {
|
||||
minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucketName).config(policyJson).build());
|
||||
log.info("查看桶策略 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("查看桶策略 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.UPDATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置桶复制参数
|
||||
*
|
||||
* @param bucketName 同名称
|
||||
* @param config 配置信息
|
||||
* @return 布尔值是否完成
|
||||
*/
|
||||
public boolean setBucketReplication(String bucketName, ReplicationConfiguration config) {
|
||||
try {
|
||||
minioClient.setBucketReplication(SetBucketReplicationArgs.builder().bucket(bucketName).config(config).build());
|
||||
log.info("设置桶复制参数 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("设置桶复制参数 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.UPDATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置/修改桶标签
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param map Map<String, String> map集合
|
||||
* @return 布尔值是否完成
|
||||
*/
|
||||
public boolean setBucketTags(String bucketName, Map<String, String> map) {
|
||||
try {
|
||||
minioClient.setBucketTags(SetBucketTagsArgs.builder().bucket(bucketName).tags(map).build());
|
||||
log.info("设置/修改桶标签 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("设置/修改桶标签 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.UPDATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置桶的版本配置
|
||||
*
|
||||
* @param bucketName 同名称
|
||||
* @param configuration VersioningConfiguration 配置信息
|
||||
* @return 布尔值是否完成
|
||||
*/
|
||||
public boolean setBucketVersioning(String bucketName, VersioningConfiguration configuration) {
|
||||
try {
|
||||
minioClient.setBucketVersioning(
|
||||
SetBucketVersioningArgs.builder().bucket(bucketName).config(configuration).build());
|
||||
log.info("设置桶的版本配置 ------ 成功");
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
log.error("设置桶的版本配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(MinioMessageConstant.UPDATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO setObjectLockConfiguration
|
||||
// TODO https://min.io/docs/minio/linux/developers/java/API.html#getBucketTags
|
||||
|
||||
/**
|
||||
* 复制另一个桶中文件
|
||||
*
|
||||
* @param bucketName 桶中名字
|
||||
* @param objectName 复制名称
|
||||
* @param sourceBucketName 复制到桶中名称
|
||||
* @param sourceObjectName 复制完成后名称
|
||||
* @return 布尔值是否完成
|
||||
*/
|
||||
public boolean copyObject(String bucketName, String objectName, String sourceBucketName, String sourceObjectName) {
|
||||
boolean isComplete = false;
|
||||
|
||||
try {
|
||||
minioClient.copyObject(
|
||||
CopyObjectArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.object(objectName)
|
||||
.source(
|
||||
CopySource.builder()
|
||||
.bucket(sourceBucketName)
|
||||
.object(sourceObjectName)
|
||||
.build())
|
||||
.build());
|
||||
isComplete = true;
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return isComplete;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除对象的标记。
|
||||
*
|
||||
* @param bucketName 桶中名字
|
||||
* @param objectName 复制名称
|
||||
* @return 布尔值是否完成
|
||||
*/
|
||||
public boolean deleteObjectTags(String bucketName, String objectName) {
|
||||
boolean isComplete = false;
|
||||
|
||||
try {
|
||||
minioClient.deleteObjectTags(DeleteObjectTagsArgs.builder().bucket(bucketName).object(objectName).build());
|
||||
isComplete = true;
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return isComplete;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param objectName 对象名称
|
||||
* @param filename 文件名
|
||||
*/
|
||||
public void downloadObject(String bucketName, String objectName, String filename) {
|
||||
try {
|
||||
minioClient.downloadObject(
|
||||
DownloadObjectArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.object(objectName)
|
||||
.filename(filename)
|
||||
.build());
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param objectName 对象名称
|
||||
*/
|
||||
public InputStream getObject(String bucketName, String objectName) {
|
||||
try {
|
||||
return minioClient.getObject(GetObjectArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.object(objectName)
|
||||
.build());
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
return null; // 或者抛出自定义异常
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param filename 文件名
|
||||
* @param inputStream 输入流
|
||||
* @param size 大小
|
||||
*/
|
||||
public void putObject(String bucketName, String filename, InputStream inputStream, Long size) {
|
||||
try {
|
||||
minioClient.putObject(
|
||||
PutObjectArgs.builder().bucket(bucketName)
|
||||
.object(filename)
|
||||
.stream(inputStream, size, -1)
|
||||
.build());
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param filename 文件名
|
||||
* @param contentType 文件类型
|
||||
* @param inputStream 输入流
|
||||
* @param size 大小
|
||||
*/
|
||||
public void putObject(String bucketName, String filename, String contentType, InputStream inputStream, Long size) {
|
||||
try {
|
||||
minioClient.putObject(
|
||||
PutObjectArgs.builder().bucket(bucketName)
|
||||
.object(filename)
|
||||
.stream(inputStream, size, -1)
|
||||
.contentType(contentType)
|
||||
.build());
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param objectName 对象名称
|
||||
*/
|
||||
public void removeObject(String bucketName, String objectName) {
|
||||
try {
|
||||
minioClient.removeObject(
|
||||
RemoveObjectArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.object(objectName)
|
||||
.build());
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,6 +30,11 @@
|
|||
<artifactId>module-mail</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.bunny</groupId>
|
||||
<artifactId>module-minio</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- service-utils -->
|
||||
<dependency>
|
||||
<groupId>cn.bunny</groupId>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package cn.bunny.service.security;
|
||||
|
||||
import cn.bunny.common.constant.MessageConstant;
|
||||
import cn.bunny.common.constant.CommonMessageConstant;
|
||||
import cn.bunny.common.service.exception.BunnyException;
|
||||
import cn.bunny.entity.system.SysRole;
|
||||
import cn.bunny.entity.system.SysUser;
|
||||
|
@ -28,11 +28,11 @@ public class CustomUserDetailsService implements cn.bunny.security.service.Custo
|
|||
SysUser sysUser = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, username));
|
||||
List<SysRole> sysRoleList = sysRoleMapper.selectList(null);
|
||||
if (sysUser == null) {
|
||||
throw new UsernameNotFoundException(MessageConstant.USER_DOES_NOT_EXIST);
|
||||
throw new UsernameNotFoundException(CommonMessageConstant.USER_DOES_NOT_EXIST);
|
||||
}
|
||||
|
||||
if (sysUser.getStatus() == 0) {
|
||||
throw new BunnyException(MessageConstant.ACCOUNT_LOCKED);
|
||||
throw new BunnyException(CommonMessageConstant.ACCOUNT_LOCKED);
|
||||
}
|
||||
|
||||
List<String> roleAuthoritieList = sysRoleList.stream().map(SysRole::getRoleCode).toList();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package cn.bunny.service.service.impl;
|
||||
|
||||
import cn.bunny.common.constant.MessageConstant;
|
||||
import cn.bunny.common.constant.CommonMessageConstant;
|
||||
import cn.bunny.common.service.exception.BunnyException;
|
||||
import cn.bunny.common.service.utils.JwtHelper;
|
||||
import cn.bunny.entity.system.Login;
|
||||
|
@ -48,18 +48,18 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
|
||||
// 用户是否存在
|
||||
if (sysUser == null) {
|
||||
throw new BunnyException(MessageConstant.ACCOUNT_NOT_FOUND);
|
||||
throw new BunnyException(CommonMessageConstant.ACCOUNT_NOT_FOUND);
|
||||
}
|
||||
|
||||
// 判断是否被禁用
|
||||
if (sysUser.getStatus() == 0) {
|
||||
throw new BunnyException(MessageConstant.ACCOUNT_LOCKED);
|
||||
throw new BunnyException(CommonMessageConstant.ACCOUNT_LOCKED);
|
||||
}
|
||||
|
||||
// 判断密码
|
||||
String md5DigestAsHexPassword = DigestUtils.md5DigestAsHex(password.getBytes());
|
||||
if (!md5DigestAsHexPassword.equals(sysUser.getPassword())) {
|
||||
throw new BunnyException(MessageConstant.PASSWORD_ERROR);
|
||||
throw new BunnyException(CommonMessageConstant.PASSWORD_ERROR);
|
||||
}
|
||||
// 添加token
|
||||
String token = JwtHelper.createToken(sysUser.getId(), sysUser.getUsername());
|
||||
|
|
|
@ -30,10 +30,6 @@ spring:
|
|||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
security:
|
||||
user:
|
||||
name: user
|
||||
password: 1
|
||||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
|
@ -50,18 +46,18 @@ logging:
|
|||
file:
|
||||
path: "logs/${spring.application.name}"
|
||||
|
||||
snowflake:
|
||||
#数据中心id位数
|
||||
datacenterBits: 5
|
||||
# 机器id位数
|
||||
workerBits: 5
|
||||
# 序列id所占位数
|
||||
sequenceBits: 12
|
||||
# 数据中心id,范围0-2^5-1
|
||||
datacenterId: 1
|
||||
# 机器id,范围0-2^5-1
|
||||
workerId: 1
|
||||
# 时间戳起始点(2024-01-01 00::00:00 的毫秒数)
|
||||
twepoch: 1704038400000
|
||||
#单次批量生成id的最大数量 默认10万
|
||||
maxBatchCount: 100000
|
||||
bunny:
|
||||
minio:
|
||||
endpointUrl: ${bunny.minio.endpointUrl}
|
||||
accessKey: ${bunny.minio.accessKey}
|
||||
secretKey: ${bunny.minio.secretKey}
|
||||
bucket-name: ${bunny.minio.bucket-name}
|
||||
|
||||
snowflake:
|
||||
datacenterBits: 5 # 数据中心id位数
|
||||
workerBits: 5 # 机器id位数
|
||||
sequenceBits: 12 # 序列id所占位数
|
||||
datacenterId: 1 # 数据中心id,范围0-2^5-1
|
||||
workerId: 1 # 机器id,范围0-2^5-1
|
||||
twepoch: 1704038400000 # 时间戳起始点(2024-01-01 00::00:00 的毫秒数)
|
||||
maxBatchCount: 100000 #单次批量生成id的最大数量 默认10万
|
Loading…
Reference in New Issue