feat(新增): 🚀 netty初始化
This commit is contained in:
parent
f708469f43
commit
be5b656a70
|
@ -7,8 +7,32 @@
|
|||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="module-task" />
|
||||
<module name="common-generator" />
|
||||
<module name="module-minio" />
|
||||
<module name="service" />
|
||||
<module name="service-utils" />
|
||||
<module name="module-rabbitMQ" />
|
||||
<module name="common-utils" />
|
||||
<module name="model" />
|
||||
<module name="module-mail" />
|
||||
<module name="demo1" />
|
||||
<module name="module-websocket" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
<component name="JavacSettings">
|
||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||
<module name="common-generator" options="-parameters" />
|
||||
<module name="common-utils" options="-parameters" />
|
||||
<module name="model" options="-parameters" />
|
||||
<module name="module-mail" options="-parameters" />
|
||||
<module name="module-minio" options="-parameters" />
|
||||
<module name="module-rabbitMQ" options="-parameters" />
|
||||
<module name="module-task" options="-parameters" />
|
||||
<module name="module-websocket" options="-parameters" />
|
||||
<module name="service" options="-parameters" />
|
||||
<module name="service-utils" options="-parameters" />
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -4,5 +4,21 @@
|
|||
<file url="file://$PROJECT_DIR$/demo1/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/demo1/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/demo1/src/main/resources-filtered" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/common/common-generator/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/common/common-utils/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/common/service-utils/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/common/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/common/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/model/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/module/module-mail/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/module/module-minio/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/module/module-rabbitMQ/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/module/module-task/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/module/module-websocket/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/module/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/module/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/service/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/netty/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
|
@ -5,6 +5,7 @@
|
|||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/demo1/pom.xml" />
|
||||
<option value="$PROJECT_DIR$/netty/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
logs/
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
|
@ -0,0 +1,70 @@
|
|||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.bunny</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>common-generator</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>common-utils</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.1</version>
|
||||
</dependency>
|
||||
<!--mysql-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!-- mysql连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>5.1.0</version>
|
||||
</dependency>
|
||||
<!-- mybatis-plus -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- 数据库代码生成器 - 新版 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>3.5.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>2.3</version>
|
||||
</dependency>
|
||||
<!-- 数据库代码生成器 - 旧版 -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>com.baomidou</groupId> -->
|
||||
<!-- <artifactId>mybatis-plus-generator</artifactId> -->
|
||||
<!-- <version>3.4.1</version> -->
|
||||
<!-- </dependency> -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.apache.velocity</groupId> -->
|
||||
<!-- <artifactId>velocity-engine-core</artifactId> -->
|
||||
<!-- <version>2.0</version> -->
|
||||
<!-- </dependency> -->
|
||||
<!-- spring-web -->
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,83 @@
|
|||
package cn.bunny.common.generator;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class NewCodeGet {
|
||||
// 数据连接
|
||||
public static final String sqlHost = "jdbc:mysql://106.15.251.123:3305/bunny_docs?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true";
|
||||
// 作者名称
|
||||
public static final String author = "Bunny";
|
||||
// 公共路径
|
||||
public static final String outputDir = "F:\\web项目\\PC\\BunnyNote\\BunnyBBS-server\\service\\service-web";
|
||||
// 实体类名称
|
||||
public static final String entity = "Bunny";
|
||||
|
||||
public static void main(String[] args) {
|
||||
Generation("article");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据表名生成相应结构代码
|
||||
*
|
||||
* @param tableName 表名
|
||||
*/
|
||||
public static void Generation(String... tableName) {
|
||||
// TODO 修改数据库路径、账户、密码
|
||||
FastAutoGenerator.create(sqlHost, "root", "02120212")
|
||||
.globalConfig(builder -> {
|
||||
// 添加作者名称
|
||||
builder.author(author)
|
||||
// 启用swagger
|
||||
.enableSwagger()
|
||||
// 指定输出目录
|
||||
.outputDir(outputDir + "/src/main/java");
|
||||
})
|
||||
.packageConfig(builder -> {
|
||||
builder.entity(entity)// 实体类包名
|
||||
// TODO 父包名。如果为空,将下面子包名必须写全部, 否则就只需写子包名
|
||||
.parent("cn.bunny.service.web")
|
||||
.controller("controller")// 控制层包名
|
||||
.mapper("mapper")// mapper层包名
|
||||
.service("service")// service层包名
|
||||
.serviceImpl("service.impl")// service实现类包名
|
||||
// 自定义mapper.xml文件输出目录
|
||||
.pathInfo(Collections.singletonMap(OutputFile.xml, outputDir + "/src/main/resources/mapper"));
|
||||
})
|
||||
.strategyConfig(builder -> {
|
||||
// 设置要生成的表名
|
||||
builder.addInclude(tableName)
|
||||
//.addTablePrefix("sys_")// TODO 设置表前缀过滤
|
||||
.entityBuilder()
|
||||
.enableLombok()
|
||||
.enableChainModel()
|
||||
.naming(NamingStrategy.underline_to_camel)// 数据表映射实体命名策略:默认下划线转驼峰underline_to_camel
|
||||
.columnNaming(NamingStrategy.underline_to_camel)// 表字段映射实体属性命名规则:默认null,不指定按照naming执行
|
||||
.idType(IdType.AUTO)// TODO 添加全局主键类型
|
||||
.formatFileName("%s")// 格式化实体名称,%s取消首字母I,
|
||||
.mapperBuilder()
|
||||
.mapperAnnotation(Mapper.class)// 开启mapper注解
|
||||
.enableBaseResultMap()// 启用xml文件中的BaseResultMap 生成
|
||||
.enableBaseColumnList()// 启用xml文件中的BaseColumnList
|
||||
.formatMapperFileName("%sMapper")// 格式化Dao类名称
|
||||
.formatXmlFileName("%sMapper")// 格式化xml文件名称
|
||||
.serviceBuilder()
|
||||
.formatServiceFileName("%sService")// 格式化 service 接口文件名称
|
||||
.formatServiceImplFileName("%sServiceImpl")// 格式化 service 接口文件名称
|
||||
.controllerBuilder()
|
||||
.enableRestStyle();
|
||||
})
|
||||
// .injectionConfig(consumer -> {
|
||||
// Map<String, String> customFile = new HashMap<>();
|
||||
// // 配置DTO(需要的话)但是需要有能配置Dto的模板引擎,比如freemarker,但是这里我们用的VelocityEngine,因此不多作介绍
|
||||
// customFile.put(outputDir, "/src/main/resources/templates/entityDTO.java.ftl");
|
||||
// consumer.customFile(customFile);
|
||||
// })
|
||||
.execute();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package cn.bunny.common.generator;
|
||||
|
||||
public class OldCodeGet {
|
||||
public static void main(String[] args) {
|
||||
// // 1、创建代码生成器
|
||||
// AutoGenerator mpg = new AutoGenerator();
|
||||
//
|
||||
// // 2、全局配置
|
||||
// // 全局配置
|
||||
// GlobalConfig gc = new GlobalConfig();
|
||||
// // TODO 需要修改路径名称
|
||||
// gc.setOutputDir("F:\\web项目\\Bunny-Cli\\Java\\java-template\\service" + "/src/main/java");
|
||||
// gc.setServiceName("%sService"); // 去掉Service接口的首字母I
|
||||
// gc.setAuthor("bunny");
|
||||
// gc.setOpen(false);
|
||||
// mpg.setGlobalConfig(gc);
|
||||
//
|
||||
// // 3、数据源配置
|
||||
// DataSourceConfig dsc = new DataSourceConfig();
|
||||
// // TODO 需要修改数据库
|
||||
// dsc.setUrl("jdbc:mysql://106.15.251.123:3305/guigu-oa?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true");
|
||||
// dsc.setDriverName("com.mysql.cj.jdbc.Driver");
|
||||
// dsc.setUsername("root");
|
||||
// dsc.setPassword("02120212");
|
||||
// dsc.setDbType(DbType.MYSQL);
|
||||
// mpg.setDataSource(dsc);
|
||||
//
|
||||
// // 4、包配置
|
||||
// PackageConfig pc = new PackageConfig();
|
||||
// pc.setParent("cn.bunny");
|
||||
// // TODO 需要修改模块名
|
||||
// pc.setModuleName("service");
|
||||
// pc.setController("controller");
|
||||
// pc.setService("service");
|
||||
// pc.setMapper("mapper");
|
||||
// mpg.setPackageInfo(pc);
|
||||
//
|
||||
// // 5、策略配置
|
||||
// StrategyConfig strategy = getStrategyConfig();
|
||||
// mpg.setStrategy(strategy);
|
||||
//
|
||||
// // 6、执行
|
||||
// mpg.execute();
|
||||
// }
|
||||
//
|
||||
// private static StrategyConfig getStrategyConfig() {
|
||||
// StrategyConfig strategy = new StrategyConfig();
|
||||
// // TODO 要生成的表
|
||||
// strategy.setInclude("sys_menu", "sys_role_menu");
|
||||
// strategy.setNaming(NamingStrategy.underline_to_camel);// 数据库表映射到实体的命名策略
|
||||
// strategy.setColumnNaming(NamingStrategy.underline_to_camel);// 数据库表字段映射到实体的命名策略
|
||||
// strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作
|
||||
// strategy.setRestControllerStyle(true); // restful api风格控制器
|
||||
// strategy.setControllerMappingHyphenStyle(true); // url中驼峰转连字符
|
||||
// return strategy;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.bunny</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>common-utils</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>common-utils</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.bunny</groupId>
|
||||
<artifactId>model</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,51 @@
|
|||
package cn.bunny.common.utils;
|
||||
|
||||
import cn.bunny.vo.system.comment.CommentVo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommentUtil {
|
||||
/**
|
||||
* 构建树型结构
|
||||
*
|
||||
* @param commentList 评论列表
|
||||
* @return 结构列表
|
||||
*/
|
||||
public static List<CommentVo> buildTree(List<CommentVo> commentList) {
|
||||
// 构建树形结构
|
||||
List<CommentVo> tree = new ArrayList<>();
|
||||
// 遍历评论列表
|
||||
for (CommentVo comment : commentList) {
|
||||
// 找到顶级评论(没有父评论)
|
||||
if (comment.getPCommentId() == 0) {
|
||||
// 递归构建子评论
|
||||
comment.setChildren(getChildren(comment.getId(), commentList));
|
||||
tree.add(comment);
|
||||
}
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归获取子评论
|
||||
*
|
||||
* @param commentId 当前评论ID
|
||||
* @param commentList 评论列表
|
||||
* @return 子评论列表
|
||||
*/
|
||||
private static List<CommentVo> getChildren(Long commentId, List<CommentVo> commentList) {
|
||||
List<CommentVo> children = new ArrayList<>();
|
||||
|
||||
// 遍历评论列表
|
||||
for (CommentVo comment : commentList) {
|
||||
// 找到当前评论的子评论
|
||||
if (Long.valueOf(comment.getPCommentId()).equals(commentId)) {
|
||||
// 递归构建子评论的子评论
|
||||
comment.setChildren(getChildren(comment.getId(), commentList));
|
||||
children.add(comment);
|
||||
}
|
||||
}
|
||||
return children;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package cn.bunny.common.utils;
|
||||
|
||||
public class FileUtil {
|
||||
public static String getSize(Long fileSize) {
|
||||
double fileSizeInKB = fileSize / 1024.00;
|
||||
double fileSizeInMB = fileSizeInKB / 1024;
|
||||
double fileSizeInGB = fileSizeInMB / 1024;
|
||||
|
||||
String size;
|
||||
if (fileSizeInGB >= 1) {
|
||||
fileSizeInGB = Double.parseDouble(String.format("%.2f", fileSizeInGB));
|
||||
size = fileSizeInGB + "GB";
|
||||
} else if (fileSizeInMB >= 1) {
|
||||
fileSizeInMB = Double.parseDouble(String.format("%.2f", fileSizeInMB));
|
||||
size = fileSizeInMB + "MB";
|
||||
} else if (fileSizeInKB >= 1) {
|
||||
fileSizeInKB = Double.parseDouble(String.format("%.2f", fileSizeInKB));
|
||||
size = fileSizeInKB + "KB";
|
||||
} else {
|
||||
size = fileSize + "B";
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.bunny</groupId>
|
||||
<artifactId>bunny-template</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>common</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>common Maven Webapp</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
<modules>
|
||||
<module>service-utils</module>
|
||||
<module>common-generator</module>
|
||||
<module>common-utils</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,57 @@
|
|||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.bunny</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>service-utils</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>service-utils</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.bunny</groupId>
|
||||
<artifactId>model</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- httpclient -->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.14</version>
|
||||
</dependency>
|
||||
<!-- knife4j -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- redis -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<!-- redisson 分布式锁-->
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
<version>3.26.1</version>
|
||||
</dependency>
|
||||
<!-- pagehelper -->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,46 @@
|
|||
package cn.bunny.common.service.config;
|
||||
|
||||
import io.swagger.v3.oas.models.ExternalDocumentation;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Contact;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.info.License;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springdoc.core.models.GroupedOpenApi;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class Knife4jConfig {
|
||||
@Bean
|
||||
public OpenAPI openAPI() {
|
||||
log.info("Knife4jConfig===>配置knife4j");
|
||||
// 作者等信息
|
||||
Contact contact = new Contact().name("Bunny").email("1319900154@qq.com").url("http://z-bunny.com");
|
||||
// 使用协议
|
||||
License license = new License().name("MIT").url("http://MUT.com");
|
||||
// 相关信息
|
||||
Info info = new Info().title("Bunny-Java-Template").description("Bunny的Java模板").version("v1.0.0").contact(contact).license(license);
|
||||
|
||||
return new OpenAPI().info(info).externalDocs(new ExternalDocumentation());
|
||||
}
|
||||
|
||||
// 前台相关分类接口
|
||||
@Bean
|
||||
public GroupedOpenApi groupedOpenApi() {
|
||||
return GroupedOpenApi.builder().group("前台接口管理").pathsToMatch("/api/**").build();
|
||||
}
|
||||
|
||||
// 管理员相关分类接口
|
||||
@Bean
|
||||
public GroupedOpenApi groupedOpenAdminApi() {
|
||||
return GroupedOpenApi.builder().group("管理员接口请求").pathsToMatch("/admin/**").build();
|
||||
}
|
||||
|
||||
// 测试相关分类接口
|
||||
@Bean
|
||||
public GroupedOpenApi testGroupedOpenApi() {
|
||||
return GroupedOpenApi.builder().group("测试相关分类接口").pathsToMatch("/test/**").build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package cn.bunny.common.service.config;
|
||||
|
||||
import cn.bunny.common.service.context.BaseContext;
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 配置MP在修改和新增时的操作
|
||||
*/
|
||||
@Component
|
||||
public class MyBatisPlusFieldConfig implements MetaObjectHandler {
|
||||
|
||||
/**
|
||||
* 使用mp做添加操作时候,这个方法执行
|
||||
*/
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
// 设置属性值
|
||||
this.setFieldValByName("createTime", new Date(), metaObject);
|
||||
this.setFieldValByName("updateTime", new Date(), metaObject);
|
||||
this.setFieldValByName("deleteStatus", 1, metaObject);
|
||||
if (BaseContext.getUsername() != null) {
|
||||
this.setFieldValByName("createBy", BaseContext.getUsername(), metaObject);
|
||||
this.setFieldValByName("updateBy", BaseContext.getUsername(), metaObject);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用mp做修改操作时候,这个方法执行
|
||||
*/
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
this.setFieldValByName("updateTime", new Date(), metaObject);
|
||||
this.setFieldValByName("updateBy", BaseContext.getUsername(), metaObject);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package cn.bunny.common.service.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import com.github.pagehelper.PageInterceptor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
* Mybatis-Plus配置类
|
||||
*/
|
||||
@EnableTransactionManagement
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class MybatisPlusConfig {
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
log.info("MybatisPlusInterceptor===>注入Mybatis-Plus配置...");
|
||||
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
// 分页插件
|
||||
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
|
||||
paginationInnerInterceptor.setMaxLimit(100L);// ? 设置最大分页为100
|
||||
interceptor.addInnerInterceptor(paginationInnerInterceptor);
|
||||
// 乐观锁
|
||||
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
|
||||
// 防止全表删除
|
||||
interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
|
||||
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
@Bean// pagehelper分页插件需要配的拦截器
|
||||
public PageInterceptor pageInterceptor() {
|
||||
return new PageInterceptor();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package cn.bunny.common.service.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* 设置Redis序列化
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class RedisConfiguration {
|
||||
/**
|
||||
* 使用StringRedisSerializer序列化为字符串
|
||||
*/
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory connectionFactory) {
|
||||
log.info("RedisConfiguration===>使用StringRedisSerializer序列化为字符串");
|
||||
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
redisTemplate.setConnectionFactory(connectionFactory);
|
||||
// 设置key序列化为string
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
// 设置value序列化为JSON,使用GenericJackson2JsonRedisSerializer替换默认序列化
|
||||
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解决cache(@Cacheable)把数据缓存到redis中的value是乱码问题
|
||||
*/
|
||||
@Bean
|
||||
@SuppressWarnings("all")
|
||||
public CacheManager cacheManager(RedisConnectionFactory factory) {
|
||||
log.info("RedisConfiguration===>解决cache(@Cacheable)把数据缓存到redis中的value是乱码问题");
|
||||
|
||||
// 配置序列化
|
||||
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
|
||||
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
|
||||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jsonRedisSerializer()))
|
||||
.entryTtl(Duration.ofDays(30));
|
||||
|
||||
return RedisCacheManager.builder(factory).cacheDefaults(config).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定的日期模式
|
||||
*/
|
||||
public Jackson2JsonRedisSerializer<Object> jsonRedisSerializer() {
|
||||
log.info("RedisConfiguration===>指定的日期模式");
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
// 设置ObjectMapper访问权限
|
||||
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
// 记录序列化之后的数据类型,方便反序列化
|
||||
mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL);
|
||||
// LocalDatetime序列化,默认不兼容jdk8日期序列化
|
||||
JavaTimeModule timeModule = new JavaTimeModule();
|
||||
timeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
timeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
|
||||
timeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
timeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
// 关闭默认的日期格式化方式,默认UTC日期格式 yyyy-MM-dd’T’HH:mm:ss.SSS
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
mapper.registerModule(timeModule);
|
||||
|
||||
return new Jackson2JsonRedisSerializer<>(mapper, Object.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package cn.bunny.common.service.context;
|
||||
|
||||
public class BaseContext {
|
||||
private static final ThreadLocal<Long> userId = new ThreadLocal<>();
|
||||
private static final ThreadLocal<String> username = new ThreadLocal<String>();
|
||||
private static final ThreadLocal<Long> adminId = new ThreadLocal<>();
|
||||
private static final ThreadLocal<String> adminName = new ThreadLocal<>();
|
||||
|
||||
// 用户id相关
|
||||
public static Long getUserId() {
|
||||
return userId.get();
|
||||
}
|
||||
|
||||
public static void setUserId(Long _userId) {
|
||||
userId.set(_userId);
|
||||
}
|
||||
|
||||
public static String getUsername() {
|
||||
return username.get();
|
||||
}
|
||||
|
||||
public static void setUsername(String _username) {
|
||||
username.set(_username);
|
||||
}
|
||||
|
||||
public static void removeUser() {
|
||||
username.remove();
|
||||
userId.remove();
|
||||
}
|
||||
|
||||
// adminId 相关
|
||||
public static Long getAdminId() {
|
||||
return adminId.get();
|
||||
}
|
||||
|
||||
public static void setAdminId(Long _adminId) {
|
||||
adminId.set(_adminId);
|
||||
}
|
||||
|
||||
public static String getAdminName() {
|
||||
return adminName.get();
|
||||
}
|
||||
|
||||
public static void setAdminName(String _adminName) {
|
||||
adminName.set(_adminName);
|
||||
}
|
||||
|
||||
public static void removeAdmin() {
|
||||
adminName.remove();
|
||||
adminId.remove();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package cn.bunny.common.service.exception;
|
||||
|
||||
import cn.bunny.result.ResultCodeEnum;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@ToString
|
||||
@Slf4j
|
||||
public class BunnyException extends RuntimeException {
|
||||
Integer code;// 状态码
|
||||
String message;// 描述信息
|
||||
|
||||
public BunnyException(Integer code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public BunnyException(String message) {
|
||||
super(message);
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public BunnyException(ResultCodeEnum codeEnum) {
|
||||
super(codeEnum.getMessage());
|
||||
this.code = codeEnum.getCode();
|
||||
this.message = codeEnum.getMessage();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package cn.bunny.common.service.exception;
|
||||
|
||||
|
||||
import cn.bunny.result.Result;
|
||||
import cn.bunny.result.ResultCodeEnum;
|
||||
import cn.bunny.result.constant.ExceptionConstant;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.nio.file.AccessDeniedException;
|
||||
import java.sql.SQLIntegrityConstraintViolationException;
|
||||
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class GlobalExceptionHandler {
|
||||
// 自定义异常信息
|
||||
@ExceptionHandler(BunnyException.class)
|
||||
@ResponseBody
|
||||
public Result<Object> exceptionHandler(BunnyException exception) {
|
||||
log.error("GlobalExceptionHandler===>自定义异常信息:{}", exception.getMessage());
|
||||
|
||||
Integer code = exception.getCode() != null ? exception.getCode() : 500;
|
||||
return Result.error(null, code, exception.getMessage());
|
||||
}
|
||||
|
||||
// 运行时异常信息
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
@ResponseBody
|
||||
public Result<Object> exceptionHandler(RuntimeException exception) throws FileNotFoundException {
|
||||
log.error("GlobalExceptionHandler===>运行时异常信息:{}", exception.getMessage());
|
||||
exception.printStackTrace();
|
||||
return Result.error(null, 500, "出错了啦");
|
||||
}
|
||||
|
||||
// 捕获系统异常
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public Result<Object> error(Exception exception) {
|
||||
log.error("GlobalExceptionHandler===>系统异常信息:{}", exception.getMessage());
|
||||
|
||||
return Result.error(null, 500, "系统异常");
|
||||
}
|
||||
|
||||
// 特定异常处理
|
||||
@ExceptionHandler(ArithmeticException.class)
|
||||
@ResponseBody
|
||||
public Result<Object> error(ArithmeticException exception) {
|
||||
log.error("GlobalExceptionHandler===>特定异常信息:{}", exception.getMessage());
|
||||
|
||||
return Result.error(null, 500, exception.getMessage());
|
||||
}
|
||||
|
||||
// spring security异常
|
||||
@ExceptionHandler(AccessDeniedException.class)
|
||||
@ResponseBody
|
||||
public Result<String> error(AccessDeniedException exception) throws AccessDeniedException {
|
||||
log.error("GlobalExceptionHandler===>spring security异常:{}", exception.getMessage());
|
||||
|
||||
return Result.error(ResultCodeEnum.SERVICE_ERROR);
|
||||
}
|
||||
|
||||
// 处理SQL异常
|
||||
@ExceptionHandler(SQLIntegrityConstraintViolationException.class)
|
||||
@ResponseBody
|
||||
public Result<String> exceptionHandler(SQLIntegrityConstraintViolationException exception) {
|
||||
log.error("GlobalExceptionHandler===>处理SQL异常:{}", exception.getMessage());
|
||||
|
||||
String message = exception.getMessage();
|
||||
if (message.contains("Duplicate entry")) {
|
||||
// 截取用户名
|
||||
String username = message.split(" ")[2];
|
||||
// 错误信息
|
||||
String errorMessage = username + ExceptionConstant.ALREADY_USER_Exception;
|
||||
return Result.error(errorMessage);
|
||||
} else {
|
||||
return Result.error(ExceptionConstant.UNKNOWN_Exception);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package cn.bunny.common.service.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "bunny.snowflake")
|
||||
@Data
|
||||
public class SnowflakeProperties {
|
||||
// 数据中心id
|
||||
private Long datacenterId;
|
||||
// 数据中心id位数
|
||||
private Long datacenterBits;
|
||||
// 机器id
|
||||
private Long workerId;
|
||||
// 机器id位数
|
||||
private Long workerBits;
|
||||
// 序列id所占位数
|
||||
private Long sequenceBits;
|
||||
// 时间戳起始点(毫秒)
|
||||
private Long twepoch;
|
||||
// 单次批量生成id的最大数量
|
||||
private Integer maxBatchCount;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package cn.bunny.common.service.utils;
|
||||
|
||||
import cn.bunny.common.service.exception.BunnyException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@Slf4j
|
||||
public class EmptyUtil {
|
||||
/**
|
||||
* 是否为空
|
||||
*
|
||||
* @param value 判断值
|
||||
* @param message 错误消息
|
||||
*/
|
||||
public static void isEmpty(Object value, String message) {
|
||||
if (value == null || !StringUtils.hasText(value.toString())) {
|
||||
log.error("为空对象错误:{},{}", value, message);
|
||||
throw new BunnyException(message);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,206 @@
|
|||
package cn.bunny.common.service.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HttpUtil {
|
||||
public static HttpResponse doGet(String host, String path, String method, Map<String, String> headers, Map<String, String> querys) throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpGet request = new HttpGet(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
public static HttpResponse doPost(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, Map<String, String> bodys) throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (bodys != null) {
|
||||
List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
|
||||
|
||||
for (String key : bodys.keySet()) {
|
||||
nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
|
||||
}
|
||||
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
|
||||
formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
|
||||
request.setEntity(formEntity);
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
|
||||
public static HttpResponse doPost(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, String body) throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(body)) {
|
||||
request.setEntity(new StringEntity(body, "utf-8"));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
|
||||
public static HttpResponse doPost(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, byte[] body) throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (body != null) {
|
||||
request.setEntity(new ByteArrayEntity(body));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
|
||||
public static HttpResponse doPut(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, String body) throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(body)) {
|
||||
request.setEntity(new StringEntity(body, "utf-8"));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
|
||||
public static HttpResponse doPut(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, byte[] body) throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (body != null) {
|
||||
request.setEntity(new ByteArrayEntity(body));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
|
||||
public static HttpResponse doDelete(String host, String path, String method, Map<String, String> headers, Map<String, String> querys) throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
|
||||
StringBuilder sbUrl = new StringBuilder();
|
||||
sbUrl.append(host);
|
||||
if (!StringUtils.isBlank(path)) {
|
||||
sbUrl.append(path);
|
||||
}
|
||||
if (null != querys) {
|
||||
StringBuilder sbQuery = new StringBuilder();
|
||||
for (Map.Entry<String, String> query : querys.entrySet()) {
|
||||
if (!sbQuery.isEmpty()) {
|
||||
sbQuery.append("&");
|
||||
}
|
||||
if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
|
||||
sbQuery.append(query.getValue());
|
||||
}
|
||||
if (!StringUtils.isBlank(query.getKey())) {
|
||||
sbQuery.append(query.getKey());
|
||||
if (!StringUtils.isBlank(query.getValue())) {
|
||||
sbQuery.append("=");
|
||||
sbQuery.append(URLEncoder.encode(query.getValue(), StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!sbQuery.isEmpty()) {
|
||||
sbUrl.append("?").append(sbQuery);
|
||||
}
|
||||
}
|
||||
|
||||
return sbUrl.toString();
|
||||
}
|
||||
|
||||
private static HttpClient wrapClient(String host) {
|
||||
HttpClient httpClient = new DefaultHttpClient();
|
||||
if (host.startsWith("https://")) {
|
||||
sslClient(httpClient);
|
||||
}
|
||||
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
private static void sslClient(HttpClient httpClient) {
|
||||
try {
|
||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||
X509TrustManager tm = new X509TrustManager() {
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void checkClientTrusted(X509Certificate[] xcs, String str) {
|
||||
}
|
||||
|
||||
public void checkServerTrusted(X509Certificate[] xcs, String str) {
|
||||
}
|
||||
};
|
||||
ctx.init(null, new TrustManager[]{tm}, null);
|
||||
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
|
||||
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||
ClientConnectionManager ccm = httpClient.getConnectionManager();
|
||||
SchemeRegistry registry = ccm.getSchemeRegistry();
|
||||
registry.register(new Scheme("https", 443, ssf));
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package cn.bunny.common.service.utils;
|
||||
|
||||
import io.jsonwebtoken.*;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class JwtHelper {
|
||||
private static final long tokenExpiration = 24 * 60 * 60 * 1000;
|
||||
private static final String tokenSignKey = "Bunny-Java-Template";
|
||||
|
||||
public static String createToken(Long userId, String userName, Integer day) {
|
||||
return Jwts.builder()
|
||||
.setSubject("Bunny-USER")
|
||||
.setExpiration(new Date(System.currentTimeMillis() + tokenExpiration * day))
|
||||
.claim("userId", userId)
|
||||
.claim("userName", userName)
|
||||
.signWith(SignatureAlgorithm.HS256, tokenSignKey)
|
||||
.compressWith(CompressionCodecs.GZIP)
|
||||
.compact();
|
||||
}
|
||||
|
||||
public static Long getUserId(String token) {
|
||||
if (!StringUtils.hasText(token)) return null;
|
||||
|
||||
Jws<Claims> claimsJws = Jwts.parser().setSigningKey(tokenSignKey).parseClaimsJws(token);
|
||||
Claims claims = claimsJws.getBody();
|
||||
|
||||
return Long.valueOf(String.valueOf(claims.get("userId")));
|
||||
}
|
||||
|
||||
public static String getUsername(String token) {
|
||||
if (!StringUtils.hasText(token)) return "";
|
||||
|
||||
Jws<Claims> claimsJws = Jwts.parser().setSigningKey(tokenSignKey).parseClaimsJws(token);
|
||||
Claims claims = claimsJws.getBody();
|
||||
return (String) claims.get("userName");
|
||||
}
|
||||
|
||||
public static void removeToken(String token) {
|
||||
// jwttoken无需删除,客户端扔掉即可。
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String token = JwtHelper.createToken(7L, "admin", 7);
|
||||
// token = "eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAA_6tWKi5NUrJScirNy6vUDQ12DVLSUUqtKFCyMjQ3MTc0NrYwNddRKi1OLfJMUbKyNDIwNLQwMDAzg4j5JeamAjUbGhtaWhoYGJqaOBQW6iXn5yrVAgCrO9jLWAAAAA.DS1wYprXGoIMrjtUWfDSN9AG5gWoRZ17oAgcvC0kwag";
|
||||
System.out.println(JwtHelper.getUserId(token));
|
||||
System.out.println(JwtHelper.getUsername(token));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package cn.bunny.common.service.utils;
|
||||
|
||||
import cn.bunny.result.Result;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ResponseUtil {
|
||||
|
||||
public static void out(HttpServletResponse response, Result<Object> result) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
// 注册JavaTimeModule模块
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.setStatus(HttpStatus.OK.value());
|
||||
try {
|
||||
mapper.writeValue(response.getWriter(), result);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
package cn.bunny.common.service.utils;
|
||||
|
||||
|
||||
import cn.bunny.common.service.properties.SnowflakeProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class SnowflakeIdGenerator {
|
||||
// 数据中心id
|
||||
private final long datacenterId;
|
||||
// 数据中心id位数
|
||||
private final long datacenterBits;
|
||||
// 机器id
|
||||
private final long workerId;
|
||||
// 机器id位数
|
||||
private final long workerBits;
|
||||
// 序列id所占位数
|
||||
private final long sequenceBits;
|
||||
// 时间戳起始点(毫秒)
|
||||
private final long twepoch;
|
||||
|
||||
// 数据中心最大id
|
||||
private final long maxDatacenterId;
|
||||
// 机器最大id
|
||||
private final long maxWorkerId;
|
||||
// 最大序列号
|
||||
private final long maxSequence;
|
||||
|
||||
// 机器id左移位数
|
||||
private final long workerIdShift;
|
||||
// 数据中心id左移位数
|
||||
private final long datacenterIdShift;
|
||||
// 毫秒数左移位数
|
||||
private final long timestampLeftShift;
|
||||
|
||||
// 单次批量生成id的最大数量
|
||||
private final int maxBatchCount;
|
||||
|
||||
// 序列号
|
||||
private long sequence = 0L;
|
||||
// 上一次时间戳
|
||||
private long lastTimestamp = -1L;
|
||||
|
||||
public SnowflakeIdGenerator(SnowflakeProperties properties) {
|
||||
// 数据中心id
|
||||
this.datacenterId = properties.getDatacenterId();
|
||||
// 数据中心id位数
|
||||
this.datacenterBits = properties.getDatacenterBits();
|
||||
// 机器id
|
||||
this.workerId = properties.getWorkerId();
|
||||
// 机器id位数
|
||||
this.workerBits = properties.getWorkerBits();
|
||||
// 序列id所占位数
|
||||
this.sequenceBits = properties.getSequenceBits();
|
||||
// 时间戳起始点(毫秒)
|
||||
this.twepoch = properties.getTwepoch();
|
||||
// 数据中心最大id
|
||||
this.maxDatacenterId = -1L ^ (-1L << properties.getDatacenterBits());
|
||||
// 机器最大id
|
||||
this.maxWorkerId = -1L ^ (-1L << properties.getWorkerBits());
|
||||
// 最大序列号
|
||||
this.maxSequence = -1L ^ (-1L << properties.getSequenceBits());
|
||||
|
||||
this.workerIdShift = properties.getSequenceBits();
|
||||
// 数据中心id左移位数
|
||||
this.datacenterIdShift = properties.getSequenceBits() + properties.getWorkerBits();
|
||||
// 毫秒数左移位数
|
||||
this.timestampLeftShift = properties.getSequenceBits() + properties.getWorkerBits() + properties.getSequenceBits();
|
||||
// 单次批量生成id的最大数量
|
||||
this.maxBatchCount = properties.getMaxBatchCount();
|
||||
|
||||
// 校验datacenterId和workerId是否超出最大值
|
||||
if (datacenterId > maxDatacenterId || datacenterId < 0) {
|
||||
throw new IllegalArgumentException(String.format("数据中心Id不能大于%d或小于0", maxDatacenterId));
|
||||
}
|
||||
if (workerId > maxWorkerId || workerId < 0) {
|
||||
throw new IllegalArgumentException(String.format("机器Id不能大于%d或小于0", maxWorkerId));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* id生成方法(单个)
|
||||
*/
|
||||
public synchronized long nextId() {
|
||||
// 获取当前时间的毫秒数
|
||||
long timestamp = currentTime();
|
||||
|
||||
// 判断时钟是否回拨
|
||||
if (timestamp < lastTimestamp) {
|
||||
throw new RuntimeException(String.format("时钟回拨,回拨毫秒数:%d", lastTimestamp - timestamp));
|
||||
}
|
||||
|
||||
// 设置序列号
|
||||
if (lastTimestamp == timestamp) {
|
||||
// 设置序列号递增,如果当前毫秒内序列号已经达到最大值,则直到下一毫秒在重新从0开始计算序列号
|
||||
sequence = (sequence + 1) & maxSequence;
|
||||
if (sequence == 0) {
|
||||
timestamp = tilNextMillis(lastTimestamp);
|
||||
}
|
||||
} else {
|
||||
sequence = 0L;
|
||||
}
|
||||
lastTimestamp = timestamp;
|
||||
|
||||
// 计算id
|
||||
return ((timestamp - twepoch) << timestampLeftShift) |
|
||||
(datacenterId << datacenterIdShift) |
|
||||
(workerId << workerIdShift) |
|
||||
sequence;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* id生成方法(批量)
|
||||
*/
|
||||
public synchronized List<Long> nextIds(int count) {
|
||||
if (count > maxBatchCount || count < 0) {
|
||||
throw new IllegalArgumentException(String.format("批量生成id的数量不能大于%d或小于0", maxBatchCount));
|
||||
}
|
||||
List<Long> ids = new ArrayList<>(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
ids.add(nextId());
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* 循环等待直至获取到新的毫秒时间戳
|
||||
* 确保生成的时间戳总是向前移动的,即使在相同的毫秒内请求多个ID时也能保持唯一性。
|
||||
*/
|
||||
private long tilNextMillis(long lastTimestamp) {
|
||||
long timestamp = currentTime();
|
||||
// 循环等待直至获取到新的毫秒时间戳
|
||||
while (timestamp <= lastTimestamp) {
|
||||
timestamp = currentTime();
|
||||
}
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间的毫秒数
|
||||
*/
|
||||
private long currentTime() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.bunny</groupId>
|
||||
<artifactId>bunny-template</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>model</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>model</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<!-- hutool -->
|
||||
<!-- hu tool -->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
<!-- fastjson2 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
</dependency>
|
||||
<!--mysql-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!-- mysql连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>5.1.0</version>
|
||||
</dependency>
|
||||
<!-- mybatis-plus -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- knife4j -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- spring-security -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<!-- spring-security-test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-test</artifactId>
|
||||
</dependency>
|
||||
<!-- spring-web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- 实体类注解 -->
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>1.6.14</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,22 @@
|
|||
package cn.bunny.dto.article;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class LoadArticleListDto {
|
||||
private Integer pBoardId;
|
||||
private Integer boardId;
|
||||
private Integer orderType = 1;
|
||||
|
||||
public void getOrderType(Integer orderType) {
|
||||
this.orderType = Objects.requireNonNullElse(orderType, 1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package cn.bunny.dto.article;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class LoadUserArticleDto {
|
||||
private Long userId;
|
||||
private Integer type;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cn.bunny.dto.common;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class CommentPostDto {
|
||||
private String articleId;
|
||||
private Integer pCommentId;
|
||||
private String content;
|
||||
private MultipartFile image;
|
||||
private Long replyUserId;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package cn.bunny.dto.common;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class CommentQueryDto {
|
||||
private String articleId;
|
||||
// time 时间查询、goods 点赞数量
|
||||
private String orderType;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package cn.bunny.dto.common;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class QueryTopTypeDto {
|
||||
private Long commentId;
|
||||
private Integer topType;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package cn.bunny.dto.email;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class EmailTemplateDto {
|
||||
// 模板名称
|
||||
private String templateName;
|
||||
// 主题
|
||||
private String subject;
|
||||
// 邮件内容
|
||||
private String body;
|
||||
// 邮件类型
|
||||
private String type;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package cn.bunny.dto.email;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 添加邮箱用户
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class EmailUsersDto {
|
||||
// 修改时需要传
|
||||
private Long id;
|
||||
// 邮箱
|
||||
private String email;
|
||||
// 密码
|
||||
private String password;
|
||||
// SMTP服务器
|
||||
private String host;
|
||||
// 端口号
|
||||
private Integer port;
|
||||
// 邮箱协议
|
||||
private Integer smtpAgreement;
|
||||
// 是否为默认邮件
|
||||
private Boolean isDefault;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cn.bunny.dto.user;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class LoginDto {
|
||||
// 用户名
|
||||
private String username;
|
||||
// 密码
|
||||
private String password;
|
||||
// 邮箱验证码
|
||||
private String emailCode;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package cn.bunny.dto.user;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class RegisterDto {
|
||||
private String email;
|
||||
private String nickName;
|
||||
private String password;
|
||||
private String code;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package cn.bunny.dto.user;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class ResetPwdDto {
|
||||
private String email;
|
||||
private String password;
|
||||
private String emailCode;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package cn.bunny.dto.user;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class UserInfoDto {
|
||||
private String nickName;
|
||||
private String password;
|
||||
private MultipartFile avatar;
|
||||
private Integer sex;
|
||||
private String personDescription;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package cn.bunny.dto.user;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class UserIntegralRecordDto {
|
||||
private String startDate;
|
||||
private String endDate;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package cn.bunny.dto.user;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class UserMessageDto {
|
||||
private String type;
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package cn.bunny.entity.base;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class BaseEntity implements Serializable {
|
||||
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty("唯一标识")
|
||||
private Long id;
|
||||
|
||||
@TableField("create_time")
|
||||
@ApiModelProperty("创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@TableField("update_time")
|
||||
@ApiModelProperty("更新时间")
|
||||
private Date updateTime;
|
||||
|
||||
@TableField("update_user")
|
||||
@ApiModelProperty("操作用户ID")
|
||||
private Long updateUser;
|
||||
|
||||
@TableLogic
|
||||
@TableField("is_deleted")
|
||||
@ApiModelProperty("是否被删除")
|
||||
private Boolean isDeleted;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Map<String, Object> param = new HashMap<>();
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package cn.bunny.entity.system.admin;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-18
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("admin_power")
|
||||
@ApiModel(value = "AdminPower对象", description = "")
|
||||
public class AdminPower implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("权限ID")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty("权限名称")
|
||||
private String powerName;
|
||||
|
||||
@ApiModelProperty("权限编码")
|
||||
private String powerCode;
|
||||
|
||||
@ApiModelProperty("描述")
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@ApiModelProperty("更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@ApiModelProperty("更新用户")
|
||||
private String updateUser;
|
||||
|
||||
@ApiModelProperty("是否删除,0-未删除,1-已删除")
|
||||
private Byte isDelete;
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package cn.bunny.entity.system.admin;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-18
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("admin_role")
|
||||
@ApiModel(value = "AdminRole对象", description = "")
|
||||
public class AdminRole implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty("角色名称")
|
||||
private String roleName;
|
||||
|
||||
@ApiModelProperty("描述")
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty("角色代码")
|
||||
private String roleCode;
|
||||
|
||||
@ApiModelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@ApiModelProperty("更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@ApiModelProperty("操作用户")
|
||||
private String updateUser;
|
||||
|
||||
@ApiModelProperty("是否删除")
|
||||
private Byte isDeleted;
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package cn.bunny.entity.system.admin;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-18
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("admin_role_power")
|
||||
@ApiModel(value = "AdminRolePower对象", description = "")
|
||||
public class AdminRolePower implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("ID")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty("角色id")
|
||||
private String roleId;
|
||||
|
||||
@ApiModelProperty("权限id")
|
||||
private String powerId;
|
||||
|
||||
@ApiModelProperty("描述")
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@ApiModelProperty("更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@ApiModelProperty("更新用户")
|
||||
private String updateUser;
|
||||
|
||||
@ApiModelProperty("是否删除,0-未删除,1-已删除")
|
||||
private Byte isDelete;
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package cn.bunny.entity.system.admin;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-18
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("admin_user_role")
|
||||
@ApiModel(value = "AdminUserRole对象", description = "")
|
||||
public class AdminUserRole implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("ID")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty("用户id")
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty("角色id")
|
||||
private String roleId;
|
||||
|
||||
@ApiModelProperty("描述")
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@ApiModelProperty("更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@ApiModelProperty("更新用户")
|
||||
private String updateUser;
|
||||
|
||||
@ApiModelProperty("是否删除,0-未删除,1-已删除")
|
||||
private Byte isDelete;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package cn.bunny.entity.system.admin.auth;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class AuthUserRole {
|
||||
// 用户id
|
||||
private Long userId;
|
||||
// 角色id
|
||||
private Long roleId;
|
||||
// 角色代码
|
||||
private String roleCode;
|
||||
// 描述
|
||||
private String roleDescription;
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package cn.bunny.entity.system.article;
|
||||
|
||||
import cn.bunny.entity.base.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 文章信息
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-17
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value = "Article对象", description = "文章信息")
|
||||
public class Article extends BaseEntity implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("板块ID")
|
||||
private Integer boardId;
|
||||
|
||||
@ApiModelProperty("板块名称")
|
||||
private String boardName;
|
||||
|
||||
@ApiModelProperty("父级板块ID")
|
||||
private Integer pBoardId;
|
||||
|
||||
@ApiModelProperty("父板块名称")
|
||||
private String pBoardName;
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty("昵称")
|
||||
private String nickName;
|
||||
|
||||
@ApiModelProperty("最后登录ip地址")
|
||||
private String userIpAddress;
|
||||
|
||||
@ApiModelProperty("标题")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty("封面")
|
||||
private String cover;
|
||||
|
||||
@ApiModelProperty("内容")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty("0:富文本编辑器 1:markdown编辑器")
|
||||
private Byte editorType;
|
||||
|
||||
@ApiModelProperty("摘要")
|
||||
private String summary;
|
||||
|
||||
@ApiModelProperty("阅读数量")
|
||||
private Integer readCount;
|
||||
|
||||
@ApiModelProperty("点赞数")
|
||||
private Integer goodCount;
|
||||
|
||||
@ApiModelProperty("评论数")
|
||||
private Integer commentCount;
|
||||
|
||||
@ApiModelProperty("0未置顶 1:已置顶")
|
||||
private Byte topType;
|
||||
|
||||
@ApiModelProperty("0:没有附件 1:有附件")
|
||||
private Byte attachmentType;
|
||||
|
||||
@ApiModelProperty("-1已删除 0:待审核 1:已审核 ")
|
||||
private Byte status;
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package cn.bunny.entity.system.article;
|
||||
|
||||
import cn.bunny.entity.base.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 评论
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-17
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("forum_comment")
|
||||
@ApiModel(value = "ForumComment对象", description = "评论")
|
||||
public class ForumComment extends BaseEntity implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("父级评论ID")
|
||||
private Long pCommentId;
|
||||
|
||||
@ApiModelProperty("文章ID")
|
||||
private String articleId;
|
||||
|
||||
@ApiModelProperty("回复内容")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty("图片")
|
||||
private String imgPath;
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty("昵称")
|
||||
private String nickName;
|
||||
|
||||
@ApiModelProperty("用户ip地址")
|
||||
private String userIpAddress;
|
||||
|
||||
@ApiModelProperty("回复人ID")
|
||||
private Long replyUserId;
|
||||
|
||||
@ApiModelProperty("回复人昵称")
|
||||
private String replyNickName;
|
||||
|
||||
@ApiModelProperty("0:未置顶 1:置顶")
|
||||
private Integer topType;
|
||||
|
||||
@ApiModelProperty("good数量")
|
||||
private Integer goodCount;
|
||||
|
||||
@ApiModelProperty("0:待审核 1:已审核")
|
||||
private Integer status;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package cn.bunny.entity.system.article;
|
||||
|
||||
import cn.bunny.entity.base.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户积分记录表
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-17
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("integral_record")
|
||||
@ApiModel(value = "IntegralRecord对象", description = "用户积分记录表")
|
||||
public class IntegralRecord extends BaseEntity implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty("操作类型")
|
||||
private Byte operType;
|
||||
|
||||
@ApiModelProperty("积分")
|
||||
private Integer integral;
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package cn.bunny.entity.system.article;
|
||||
|
||||
import cn.bunny.entity.base.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 点赞记录
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-17
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("like_record")
|
||||
@ApiModel(value = "LikeRecord对象", description = "点赞记录")
|
||||
public class LikeRecord extends BaseEntity implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("操作类型0:文章点赞 1:评论点赞")
|
||||
private Byte opType;
|
||||
|
||||
@ApiModelProperty("主体ID")
|
||||
private String objectId;
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty("主体作者ID")
|
||||
private Long authorUserId;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package cn.bunny.entity.system.board;
|
||||
|
||||
import cn.bunny.entity.base.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 文章板块信息
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-19
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("forum_board")
|
||||
@ApiModel(value = "ForumBoard对象", description = "文章板块信息")
|
||||
public class ForumBoard extends BaseEntity implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("父级板块ID")
|
||||
private Long parentId;
|
||||
|
||||
@ApiModelProperty("板块名")
|
||||
private String boardName;
|
||||
|
||||
@ApiModelProperty("封面")
|
||||
private String cover;
|
||||
|
||||
@ApiModelProperty("描述")
|
||||
private String boardDesc;
|
||||
|
||||
@ApiModelProperty("排序")
|
||||
private Integer sort;
|
||||
|
||||
@ApiModelProperty("0:只允许管理员发帖 1:任何人可以发帖")
|
||||
private Boolean postType;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package cn.bunny.entity.system.email;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 邮件发送对象
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class EmailSend {
|
||||
// 给谁发送
|
||||
private String sendTo;
|
||||
// 发送主题
|
||||
private String subject;
|
||||
// 是否为富文本
|
||||
private Boolean isRichText;
|
||||
// 发送内容
|
||||
private String message;
|
||||
// 抄送人
|
||||
private String ccParam;
|
||||
// 发送的文件
|
||||
private MultipartFile[] file;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package cn.bunny.entity.system.email;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 邮箱发送初始化参数
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class EmailSendInit {
|
||||
private Integer port;
|
||||
private String host;
|
||||
private String username;
|
||||
private String password;
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package cn.bunny.entity.system.email;
|
||||
|
||||
import cn.bunny.entity.base.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-19
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("email_template")
|
||||
@ApiModel(value = "EmailTemplate对象", description = "邮件模板")
|
||||
public class EmailTemplate extends BaseEntity implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("模板名称")
|
||||
private String templateName;
|
||||
|
||||
@ApiModelProperty("主题")
|
||||
private String subject;
|
||||
|
||||
@ApiModelProperty("邮件内容")
|
||||
private String body;
|
||||
|
||||
@ApiModelProperty("邮件类型")
|
||||
private String type;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package cn.bunny.entity.system.email;
|
||||
|
||||
import cn.bunny.entity.base.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 邮箱发送表
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-17
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("email_users")
|
||||
@ApiModel(value = "EmailUsers对象", description = "邮箱发送表")
|
||||
public class EmailUsers extends BaseEntity implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("邮箱")
|
||||
private String email;
|
||||
|
||||
@ApiModelProperty("密码")
|
||||
private String password;
|
||||
|
||||
@ApiModelProperty("Host地址")
|
||||
private String host;
|
||||
|
||||
@ApiModelProperty("端口号")
|
||||
private Integer port;
|
||||
|
||||
@ApiModelProperty("邮箱协议")
|
||||
private String smtpAgreement;
|
||||
|
||||
@ApiModelProperty("是否为默认邮件")
|
||||
private Integer isDefault;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package cn.bunny.entity.system.file;
|
||||
|
||||
import cn.bunny.entity.base.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用于存储文件信息的数据表
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-17
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value = "Files对象", description = "用于存储文件信息的数据表")
|
||||
public class Files extends BaseEntity implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("文章ID")
|
||||
private Long articleId;
|
||||
|
||||
@ApiModelProperty("文件的名称")
|
||||
private String filename;
|
||||
|
||||
@ApiModelProperty("文件在服务器上的存储路径")
|
||||
private String filepath;
|
||||
|
||||
@ApiModelProperty("文件的大小,以字节为单位")
|
||||
private Long fileSize;
|
||||
|
||||
@ApiModelProperty("文件的MIME类型")
|
||||
private String fileType;
|
||||
|
||||
@ApiModelProperty("创建用户")
|
||||
private Long createUser;
|
||||
|
||||
@ApiModelProperty("下载次数")
|
||||
private Integer downloadCount;
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package cn.bunny.entity.system.user;
|
||||
|
||||
import cn.bunny.entity.base.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户信息
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-17
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value = "User对象", description = "用户信息")
|
||||
public class User extends BaseEntity implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ApiModelProperty("昵称")
|
||||
private String nickName;
|
||||
@ApiModelProperty("邮箱")
|
||||
private String email;
|
||||
@ApiModelProperty("密码")
|
||||
private String password;
|
||||
@ApiModelProperty("头像")
|
||||
private String avatar;
|
||||
@ApiModelProperty("0:女 1:男")
|
||||
private Byte sex;
|
||||
@ApiModelProperty("个人描述")
|
||||
private String personDescription;
|
||||
@ApiModelProperty("加入时间")
|
||||
private LocalDateTime joinTime;
|
||||
|
||||
@ApiModelProperty("最后登录时间")
|
||||
private LocalDateTime lastLoginTime;
|
||||
|
||||
@ApiModelProperty("最后登录IP")
|
||||
private String lastLoginIp;
|
||||
|
||||
@ApiModelProperty("最后登录ip地址")
|
||||
private String lastLoginIpAddress;
|
||||
|
||||
@ApiModelProperty("积分")
|
||||
private Integer totalIntegral;
|
||||
|
||||
@ApiModelProperty("当前积分")
|
||||
private Integer currentIntegral;
|
||||
|
||||
@ApiModelProperty("0:禁用 1:正常")
|
||||
private Byte status;
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package cn.bunny.entity.system.user;
|
||||
|
||||
import cn.bunny.entity.base.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户消息
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-17
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("user_message")
|
||||
@ApiModel(value = "UserMessage对象", description = "用户消息")
|
||||
public class UserMessage extends BaseEntity implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("接收人用户ID")
|
||||
private Long receivedUserId;
|
||||
|
||||
@ApiModelProperty("文章ID")
|
||||
private String articleId;
|
||||
|
||||
@ApiModelProperty("文章标题")
|
||||
private String articleTitle;
|
||||
|
||||
@ApiModelProperty("评论ID")
|
||||
private Integer commentId;
|
||||
|
||||
@ApiModelProperty("发送人用户ID")
|
||||
private Long sendUserId;
|
||||
|
||||
@ApiModelProperty("发送人昵称")
|
||||
private String sendNickName;
|
||||
|
||||
@ApiModelProperty("sys:系统消息 reply:评论 likePost:文章点赞 likeComment:评论点赞 attachment:附件下载")
|
||||
private String messageType;
|
||||
|
||||
@ApiModelProperty("消息内容")
|
||||
private String messageContent;
|
||||
|
||||
@ApiModelProperty("1:未读 2:已读")
|
||||
private Byte status;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package cn.bunny.enums;
|
||||
|
||||
/**
|
||||
* 数据库操作类型
|
||||
*/
|
||||
public enum OperationType {
|
||||
UPDATE, INSERT
|
||||
}
|
|
@ -0,0 +1,173 @@
|
|||
package cn.bunny.result;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Result<T> {
|
||||
// 状态码
|
||||
private Integer code;
|
||||
// 返回消息
|
||||
private String message;
|
||||
// 返回数据
|
||||
private T data;
|
||||
|
||||
/**
|
||||
* * 自定义返回体
|
||||
*
|
||||
* @param data 返回体
|
||||
* @return Result<T>
|
||||
*/
|
||||
protected static <T> Result<T> build(T data) {
|
||||
Result<T> result = new Result<>();
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 自定义返回体,使用ResultCodeEnum构建
|
||||
*
|
||||
* @param body 返回体
|
||||
* @param codeEnum 返回状态码
|
||||
* @return Result<T>
|
||||
*/
|
||||
public static <T> Result<T> build(T body, ResultCodeEnum codeEnum) {
|
||||
Result<T> result = build(body);
|
||||
result.setCode(codeEnum.getCode());
|
||||
result.setMessage(codeEnum.getMessage());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 自定义返回体
|
||||
*
|
||||
* @param body 返回体
|
||||
* @param code 返回状态码
|
||||
* @param message 返回消息
|
||||
* @return Result<T>
|
||||
*/
|
||||
public static <T> Result<T> build(T body, Integer code, String message) {
|
||||
Result<T> result = build(body);
|
||||
result.setCode(code);
|
||||
result.setMessage(message);
|
||||
result.setData(null);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 操作成功
|
||||
*
|
||||
* @return Result<T>
|
||||
*/
|
||||
public static <T> Result<T> success() {
|
||||
return success(null, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 操作成功
|
||||
*
|
||||
* @param data baseCategory1List
|
||||
*/
|
||||
public static <T> Result<T> success(T data) {
|
||||
return build(data, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 操作成功-状态码
|
||||
*
|
||||
* @param codeEnum 状态码
|
||||
*/
|
||||
public static <T> Result<T> success(ResultCodeEnum codeEnum) {
|
||||
return success(null, codeEnum);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 操作成功-自定义返回数据和状态码
|
||||
*
|
||||
* @param data 返回体
|
||||
* @param codeEnum 状态码
|
||||
*/
|
||||
public static <T> Result<T> success(T data, ResultCodeEnum codeEnum) {
|
||||
return build(data, codeEnum);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 操作失败-自定义返回数据和状态码
|
||||
*
|
||||
* @param data 返回体
|
||||
* @param message 错误信息
|
||||
*/
|
||||
public static <T> Result<T> success(T data, String message) {
|
||||
return build(data, 200, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 操作失败-自定义返回数据和状态码
|
||||
*
|
||||
* @param data 返回体
|
||||
* @param code 状态码
|
||||
* @param message 错误信息
|
||||
*/
|
||||
public static <T> Result<T> success(T data, Integer code, String message) {
|
||||
return build(data, code, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 操作失败
|
||||
*/
|
||||
public static <T> Result<T> error() {
|
||||
return Result.build(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 操作失败-自定义返回数据
|
||||
*
|
||||
* @param data 返回体
|
||||
*/
|
||||
public static <T> Result<T> error(T data) {
|
||||
return build(data, ResultCodeEnum.FAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 操作失败-状态码
|
||||
*
|
||||
* @param codeEnum 状态码
|
||||
*/
|
||||
public static <T> Result<T> error(ResultCodeEnum codeEnum) {
|
||||
return build(null, codeEnum);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 操作失败-自定义返回数据和状态码
|
||||
*
|
||||
* @param data 返回体
|
||||
* @param codeEnum 状态码
|
||||
*/
|
||||
public static <T> Result<T> error(T data, ResultCodeEnum codeEnum) {
|
||||
return build(data, codeEnum);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 操作失败-自定义返回数据和状态码
|
||||
*
|
||||
* @param data 返回体
|
||||
* @param code 状态码
|
||||
* @param message 错误信息
|
||||
*/
|
||||
public static <T> Result<T> error(T data, Integer code, String message) {
|
||||
return build(data, code, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 操作失败-自定义返回数据和状态码
|
||||
*
|
||||
* @param data 返回体
|
||||
* @param message 错误信息
|
||||
*/
|
||||
public static <T> Result<T> error(T data, String message) {
|
||||
return build(null, 500, message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package cn.bunny.result;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 统一返回结果状态信息类
|
||||
*/
|
||||
@Getter
|
||||
public enum ResultCodeEnum {
|
||||
// 成功操作 200
|
||||
SUCCESS(200, "操作成功"),
|
||||
SUCCESS_LOGOUT(200, "退出成功"),
|
||||
EMAIL_CODE_REFRESH(200, "邮箱验证码已刷新"),
|
||||
// 验证错误 201
|
||||
USERNAME_NOT_EMPTY(201, "用户名不能为空"),
|
||||
PASSWORD_NOT_EMPTY(201, "密码不能为空"),
|
||||
EMAIL_CODE_NOT_EMPTY(201, "邮箱验证码不能为空"),
|
||||
SEND_EMAIL_CODE_NOT_EMPTY(201, "请先发送邮箱验证码"),
|
||||
EMAIL_CODE_NOT_MATCHING(201, "邮箱验证码不匹配"),
|
||||
LOGIN_ERROR(201, "账号或密码错误"),
|
||||
LOGIN_ERROR_USERNAME_PASSWORD_NOT_EMPTY(201, "登录信息不能为空"),
|
||||
// 数据相关 206
|
||||
ILLEGAL_REQUEST(206, "非法请求"),
|
||||
REPEAT_SUBMIT(206, "重复提交"),
|
||||
DATA_ERROR(206, "数据异常"),
|
||||
// 身份过期 208
|
||||
LOGIN_AUTH(208, "请先登陆"),
|
||||
AUTHENTICATION_EXPIRED(208, "身份验证过期"),
|
||||
SESSION_EXPIRATION(208, "会话过期"),
|
||||
// 封禁 209
|
||||
FAIL_NO_ACCESS_DENIED_USER_LOCKED(209, "该账户被封禁"),
|
||||
THE_SAME_USER_HAS_LOGGED_IN(209, "相同用户已登录"),
|
||||
// 提示错误
|
||||
URL_ENCODE_ERROR(216, "URL编码失败"),
|
||||
ILLEGAL_CALLBACK_REQUEST_ERROR(217, "非法回调请求"),
|
||||
FETCH_USERINFO_ERROR(219, "获取用户信息失败"),
|
||||
// 无权访问 403
|
||||
FAIL_REQUEST_NOT_AUTH(403, "用户未认证"),
|
||||
FAIL_NO_ACCESS_DENIED(403, "无权访问"),
|
||||
FAIL_NO_ACCESS_DENIED_USER_OFFLINE(403, "用户强制下线"),
|
||||
LOGGED_IN_FROM_ANOTHER_DEVICE(403, "没有权限访问"),
|
||||
// 系统错误 500
|
||||
SERVICE_ERROR(500, "服务异常"),
|
||||
FAIL(500, "失败"),
|
||||
;
|
||||
|
||||
private final Integer code;
|
||||
private final String message;
|
||||
|
||||
ResultCodeEnum(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package cn.bunny.result.constant;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@Data
|
||||
public class ExceptionConstant {
|
||||
public static final String UNKNOWN_Exception = "未知错误";
|
||||
public static final String TOKEN_IS_EMPTY = "token为空";
|
||||
public static final String DATA_IS_EMPTY = "数据为空";
|
||||
public static final String REQUEST_DATA_NOT_EMPTY_Exception = "请求参数为空";
|
||||
public static final String UPDATE_DTO_IS_NULL_Exception = "修改参数为空";
|
||||
public static final String ADD_DATA_IS_EMPTY_Exception = "添加数据为空";
|
||||
public static final String DELETE_ID_IS_NOT_EMPTY_Exception = "删除id不能为空";
|
||||
// 文章操作相关
|
||||
public static final String DO_LIKE_COMMENT_NOT_EXIST = "点赞内容不存在";
|
||||
public static final String REPLY_USER_EMPTY_EXCEPTION = "回复的用户不存在";
|
||||
public static final String REPLY_USER_ID_EMPTY_EXCEPTION = "回复的用户不能为空";
|
||||
public static final String MENU_IS_NOT_EXIST_Exception = "菜单不存在";
|
||||
public static final String POST_COMMENT_EMPTY_Exception = "评论内容不能为空";
|
||||
public static final String ARTICLE_ID_NOT_EMPTY_Exception = "文章id不能为空";
|
||||
public static final String UPDATE_ID_IS_NOT_EMPTY_Exception = "修改id不能为空";
|
||||
public static final String CANNOT_TOP_OTHER_USER = "不能操作此内容";
|
||||
public static final String ARTICLE_NOT_FOUND_EXCEPTION = "文章未找到";
|
||||
// 登录相关
|
||||
public static final String USER_TOKEN_OUT_OF_DATE_Exception = "用户登录过期";
|
||||
public static final String LOGIN_DTO_IS_EMPTY_Exception = "登录参数不能为空";
|
||||
public static final String LOGIN_FAILED_Exception = "登录失败";
|
||||
// 账号相关
|
||||
public static final String ACCOUNT_NOT_FOUND_Exception = "账号不存在";
|
||||
public static final String ACCOUNT_LOCKED_Exception = "账号被锁定";
|
||||
// 用户相关
|
||||
public static final String USER_NOT_LOGIN_Exception = "用户未登录";
|
||||
public static final String USERNAME_IS_EMPTY_Exception = "用户名不能为空";
|
||||
public static final String ALREADY_USER_Exception = "用户已存在";
|
||||
public static final String USER_NOT_FOUND_Exception = "用户不存在";
|
||||
// 密码相关
|
||||
public static final String PASSWORD_Exception = "密码错误";
|
||||
public static final String PASSWORD_NOT_EMPTY_Exception = "密码不能为空";
|
||||
public static final String OLD_PASSWORD_Exception = "旧密码不匹配";
|
||||
public static final String PASSWORD_EDIT_Exception = "密码修改失败";
|
||||
public static final String OLD_PASSWORD_SAME_NEW_PASSWORD_Exception = "旧密码与新密码相同";
|
||||
// 验证码错误
|
||||
public static final String PLEASE_SEND_EMAIL_CODE_Exception = "请先发送验证码";
|
||||
public static final String MESSAGE_CODE_NOT_PASS_Exception = "短信验证码未过期";
|
||||
public static final String MESSAGE_CODE_UNAUTHORIZED_Exception = "短信验证码未授权,请联系管理员";
|
||||
public static final String VERIFICATION_CODE_ERROR_Exception = "验证码错误";
|
||||
public static final String CAPTCHA_IS_EMPTY_Exception = "验证码不能为空";
|
||||
public static final String KEY_IS_EMPTY_Exception = "验证码key不能为空";
|
||||
public static final String VERIFICATION_CODE_DOES_NOT_MATCH_Exception = "验证码不匹配";
|
||||
public static final String VERIFICATION_CODE_IS_EMPTY_Exception = "验证码失效或不存在";
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package cn.bunny.result.constant;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FileMessageConstant {
|
||||
public static final String DOWNLOAD_BUCKET_EXCEPTION = "下载文件失败";
|
||||
public static final String FILE_UPLOAD_EXCEPTION = "文件上传失败";
|
||||
public static final String BUCKET_EXISTS_EXCEPTION = "查询文化部对象失败";
|
||||
public static final String DELETE_BUCKET_EXCEPTION = "删除文件对象失败";
|
||||
public static final String FILE_IS_EMPTY = "文件信息为空";
|
||||
public static final String FILE_IS_NOT_EXITS = "文件信息为空";
|
||||
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 = "更新文件对象失败";
|
||||
public static final String COMPOSE_OBJECT_EXCEPTION = "对象错误";
|
||||
public static final String COPY_BUCKET_EXCEPTION = "复制文件内容失败";
|
||||
public static final String DISABLE_BUCKET_EXCEPTION = "禁用文件失败";
|
||||
public static final String ENABLE_BUCKET_EXCEPTION = "启用文件失败";
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package cn.bunny.result.constant;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LocalDateTimeConstant {
|
||||
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
|
||||
public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm";
|
||||
public static final String DEFAULT_DATE_TIME_SECOND_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss";
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package cn.bunny.result.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 = "发送消息不能为空";
|
||||
public static final String EMAIL_CONFIG_NOT_FOUND = "邮箱配置为空";
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package cn.bunny.result.constant;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Redis用户前缀设置
|
||||
*/
|
||||
@Data
|
||||
public class RedisUserConstant {
|
||||
// 管理员用户
|
||||
public static final String ADMIN_LOGIN_INFO_PREFIX = "ADMIN::LOGIN_INFO::";
|
||||
public static final String ADMIN_EMAIL_CODE_PREFIX = "ADMIN::EMAIL_CODE::";
|
||||
// 普通用户
|
||||
public static final String USER_LOGIN_INFO_PREFIX = "USER::LOGIN_INFO::";
|
||||
public static final String USER_EMAIL_CODE_PREFIX = "USER::EMAIL_CODE::";
|
||||
public static final String USER_DO_LIKE_PREFIX = "USER::doLike::";
|
||||
|
||||
/**
|
||||
* * 管理员用户登录信息
|
||||
*
|
||||
* @param adminUser 管理员用户
|
||||
* @return 登录信息key
|
||||
*/
|
||||
public static String getAdminLoginInfoPrefix(String adminUser) {
|
||||
return ADMIN_LOGIN_INFO_PREFIX + adminUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 管理员用户邮箱验证码
|
||||
*
|
||||
* @param adminUser 管理员用户
|
||||
* @return 管理员用户邮箱验证码key
|
||||
*/
|
||||
public static String getAdminUserEmailCodePrefix(String adminUser) {
|
||||
return ADMIN_EMAIL_CODE_PREFIX + adminUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 用户登录信息
|
||||
*
|
||||
* @param user 用户名
|
||||
* @return 登录信息key
|
||||
*/
|
||||
public static String getUserLoginInfoPrefix(String user) {
|
||||
return USER_LOGIN_INFO_PREFIX + user;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 用户邮箱验证码
|
||||
*
|
||||
* @param user 用户名
|
||||
* @return 用户邮箱验证码key
|
||||
*/
|
||||
public static String getUserEmailCodePrefix(String user) {
|
||||
return USER_EMAIL_CODE_PREFIX + user;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 用户点赞操作
|
||||
*
|
||||
* @param user 用户名
|
||||
* @return 用户点赞key
|
||||
*/
|
||||
public static String getUserDoLikePrefix(String user) {
|
||||
return USER_DO_LIKE_PREFIX + user;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package cn.bunny.result.constant;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 数据库中自动填充字段
|
||||
*/
|
||||
@Data
|
||||
public class SQLAutoFillConstant {
|
||||
public static final String SET_CREATE_TIME = "setCreateTime";
|
||||
public static final String SET_UPDATE_TIME = "setUpdateTime";
|
||||
public static final String SET_CREATE_USER = "setCreateUser";
|
||||
public static final String SET_UPDATE_USER = "setUpdateUser";
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package cn.bunny.result.constant;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class SecurityConstant {
|
||||
public static String[] annotations = {"/", "/test/**", "/diagram-viewer/**", "/editor-app/**", "/*.html",
|
||||
"/*/*/noAuth/**", "/*/noAuth/**", "/favicon.ico", "/swagger-resources/**", "/webjars/**", "/v3/**", "/swagger-ui.html/**", "/doc.html"};
|
||||
public static List<String> annotationsList = Arrays.asList(annotations);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package cn.bunny.result.constant;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 状态常量,启用或者禁用
|
||||
*/
|
||||
@Data
|
||||
public class StatusConstant {
|
||||
// 启用为1
|
||||
public static final Integer ENABLE = 1;
|
||||
// 禁用为0
|
||||
public static final Integer DISABLE = 0;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package cn.bunny.result.constant;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserConstant {
|
||||
public static final String USER_AVATAR = "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eoj0hHXhgJNOTSOFsS4uZs8x1ConecaVOB8eIl115xmJZcT4oCicvia7wMEufibKtTLqiaJeanU2Lpg3w/132";
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package cn.bunny.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AbstractTreeNode {
|
||||
Long getId();
|
||||
|
||||
Long getParentId();
|
||||
|
||||
void setChildren(List<? extends AbstractTreeNode> children);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package cn.bunny.tree;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TreeBuilder<T extends AbstractTreeNode> {
|
||||
|
||||
public List<T> buildTree(List<T> nodeList) {
|
||||
List<T> tree = new ArrayList<>();
|
||||
for (T node : nodeList) {
|
||||
if (node.getParentId() == 0) {
|
||||
node.setChildren(getChildren(node.getId(), nodeList));
|
||||
tree.add(node);
|
||||
}
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
|
||||
private List<T> getChildren(Long nodeId, List<T> nodeList) {
|
||||
List<T> children = new ArrayList<>();
|
||||
for (T node : nodeList) {
|
||||
if (node.getParentId().equals(nodeId)) {
|
||||
node.setChildren(getChildren(node.getId(), nodeList));
|
||||
children.add(node);
|
||||
}
|
||||
}
|
||||
return children;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cn.bunny.vo.email;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class EmailTemplateVo {
|
||||
// 模板名称
|
||||
private String templateName;
|
||||
// 主题
|
||||
private String subject;
|
||||
// 邮件内容
|
||||
private String body;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package cn.bunny.vo.file;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 返回文件信息
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class FileInfoVo {
|
||||
private Long id;
|
||||
// 文章Id
|
||||
private Long articleId;
|
||||
// 文件的名称
|
||||
private String filename;
|
||||
// 文件在服务器上的存储路径
|
||||
private String filepath;
|
||||
// 文件的大小,以字节为单位
|
||||
private Long fileSize;
|
||||
// 文件大小
|
||||
private String size;
|
||||
// 文件的MIME类型
|
||||
private String fileType;
|
||||
// 上传人昵称
|
||||
private String uploadNickname;
|
||||
private Integer downloadCount;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package cn.bunny.vo.page;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 封装分页查询结果
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class PageResult<T> implements Serializable {
|
||||
// 当前页
|
||||
private Integer pageNo;
|
||||
// 每页记录数
|
||||
private Integer pageSize;
|
||||
// 总记录数
|
||||
private long total;
|
||||
// 当前页数据集合
|
||||
private List<T> list;
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package cn.bunny.vo.system.article;
|
||||
|
||||
import cn.bunny.vo.file.FileInfoVo;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class ForumArticleVo {
|
||||
// 文章ID
|
||||
private Long id;
|
||||
// 板块ID
|
||||
private Integer boardId;
|
||||
// 父级板块ID
|
||||
private Integer pBoardId;
|
||||
// 板块名称
|
||||
private String boardName;
|
||||
// 父板块名称
|
||||
private String pBoardName;
|
||||
// 用户ID
|
||||
private String userId;
|
||||
// 昵称
|
||||
private String nickName;
|
||||
// 最后登录ip地址
|
||||
private String userIpAddress;
|
||||
// 标题
|
||||
private String title;
|
||||
// 封面
|
||||
private String cover;
|
||||
// 内容
|
||||
private String content;
|
||||
// 0:富文本编辑器 1:markdown编辑器
|
||||
private Byte editorType;
|
||||
// 摘要
|
||||
private String summary;
|
||||
// 发布时间
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
private String createTime;
|
||||
// 最后更新时间
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
private String updateTime;
|
||||
// 阅读数量
|
||||
private Integer readCount;
|
||||
// 点赞数
|
||||
private Integer goodCount;
|
||||
// 评论数
|
||||
private Integer commentCount;
|
||||
// 0未置顶 1:已置顶
|
||||
private Byte topType;
|
||||
// 0:没有附件 1:有附件
|
||||
private Byte attachmentType;
|
||||
// -1已删除 0:待审核 1:已审核
|
||||
private Byte status;
|
||||
private List<FileInfoVo> fileInfo;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package cn.bunny.vo.system.board;
|
||||
|
||||
import cn.bunny.tree.AbstractTreeNode;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ForumBoardVo implements AbstractTreeNode {
|
||||
private Long id;
|
||||
// 父级板块ID
|
||||
private Long parentId;
|
||||
// 板块名
|
||||
private String boardName;
|
||||
// 封面
|
||||
private String cover;
|
||||
// 描述
|
||||
private String boardDesc;
|
||||
// 排序
|
||||
private Integer sort;
|
||||
// 0:只允许管理员发帖 1:任何人可以发帖
|
||||
private Boolean postType;
|
||||
private List<ForumBoardVo> children;
|
||||
|
||||
@Override
|
||||
public void setChildren(List<? extends AbstractTreeNode> children) {
|
||||
this.children = (List<ForumBoardVo>) children;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package cn.bunny.vo.system.comment;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class CommentVo {
|
||||
// 评论ID
|
||||
private Long id;
|
||||
// 父级评论ID
|
||||
private Integer pCommentId;
|
||||
// 文章ID
|
||||
private String articleId;
|
||||
// 回复内容
|
||||
private String content;
|
||||
// 图片
|
||||
private String imgPath;
|
||||
// 用户ID
|
||||
private Long userId;
|
||||
// 昵称
|
||||
private String nickName;
|
||||
// 用户ip地址
|
||||
private String userIpAddress;
|
||||
// 回复人ID
|
||||
private Long replyUserId;
|
||||
// 回复人昵称
|
||||
private String replyNickName;
|
||||
// 0:未置顶 1:置顶
|
||||
private Byte topType;
|
||||
// 发布时间
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
private LocalDateTime postTime;
|
||||
// good数量
|
||||
private Integer goodCount;
|
||||
// 0:待审核 1:已审核
|
||||
private Byte status;
|
||||
private List<CommentVo> children;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package cn.bunny.vo.system.login;
|
||||
|
||||
import cn.bunny.result.constant.LocalDateTimeConstant;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户登录返回内容
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class LoginVo {
|
||||
private Long id;
|
||||
private String nickName;
|
||||
private String email;
|
||||
private String password;
|
||||
private String avatar;
|
||||
private Byte sex;
|
||||
private String personDescription;
|
||||
@JsonFormat(pattern = LocalDateTimeConstant.DEFAULT_DATE_TIME_SECOND_FORMAT)
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
private LocalDateTime joinTime;
|
||||
@JsonFormat(pattern = LocalDateTimeConstant.DEFAULT_DATE_TIME_SECOND_FORMAT)
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
private LocalDateTime lastLoginTime;
|
||||
private String lastLoginIp;
|
||||
private String lastLoginIpAddress;
|
||||
private Integer totalIntegral;
|
||||
private Integer currentIntegral;
|
||||
private Byte status;
|
||||
private String token;
|
||||
private List<String> roleList;
|
||||
private List<String> powerList;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package cn.bunny.vo.system.login;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Schema(description = "验证码响应结果实体类")
|
||||
public class ValidateCodeVo {
|
||||
@Schema(description = "验证码key")
|
||||
private String codeKey; // 验证码的key
|
||||
|
||||
@Schema(description = "验证码value")
|
||||
private String codeValue; // 图片验证码对应的字符串数据
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package cn.bunny.vo.system.user;
|
||||
|
||||
import cn.bunny.result.constant.LocalDateTimeConstant;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 获取用户信息返回参数
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class UserInfoVo {
|
||||
private Long userId;
|
||||
private String nickName;
|
||||
private String email;
|
||||
private String avatar;
|
||||
private Byte sex;
|
||||
private String personDescription;
|
||||
@JsonFormat(pattern = LocalDateTimeConstant.DEFAULT_DATE_TIME_SECOND_FORMAT)
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
private LocalDateTime joinTime;
|
||||
@JsonFormat(pattern = LocalDateTimeConstant.DEFAULT_DATE_TIME_SECOND_FORMAT)
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
private LocalDateTime lastLoginTime;
|
||||
private String lastLoginIp;
|
||||
private String lastLoginIpAddress;
|
||||
private Integer totalIntegral;
|
||||
private Integer currentIntegral;
|
||||
private Byte status;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package cn.bunny.vo.system.user;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class UserIntegralRecordVo {
|
||||
// 记录ID
|
||||
private Integer recordId;
|
||||
// 用户ID
|
||||
private String userId;
|
||||
// 操作类型
|
||||
private Byte operType;
|
||||
// 积分
|
||||
private Integer integral;
|
||||
// 创建时间
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
private LocalDateTime createTime;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cn.bunny.vo.system.user;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class UserMessageCountVo {
|
||||
private Integer total;
|
||||
private Integer sys;
|
||||
private Integer reply;
|
||||
private Integer likePost;
|
||||
private Integer likeComment;
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package cn.bunny.vo.system.user;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class UserMessageVo {
|
||||
// 自增ID
|
||||
private Integer messageId;
|
||||
// 接收人用户ID
|
||||
private String receivedUserId;
|
||||
// 文章ID
|
||||
private String articleId;
|
||||
// 文章标题
|
||||
private String articleTitle;
|
||||
// 评论ID
|
||||
private Integer commentId;
|
||||
// 发送人用户ID
|
||||
private String sendUserId;
|
||||
// 发送人昵称
|
||||
private String sendNickName;
|
||||
// sys:系统消息 reply:评论 likePost:文章点赞 likeComment:评论点赞 attachment:附件下载
|
||||
private String messageType;
|
||||
// 消息内容
|
||||
private String messageContent;
|
||||
// 创建时间
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
private LocalDateTime createTime;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.bunny</groupId>
|
||||
<artifactId>module</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>module-mail</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>module-mail</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,23 @@
|
|||
Configuration example
|
||||
|
||||
mail:
|
||||
host: smtp.qq.com # 邮箱地址
|
||||
port: 465 # 邮箱端口号
|
||||
username: xxx@qq.com # 设置发送邮箱
|
||||
password: xx # 如果是纯数字要加引号
|
||||
default-encoding: UTF-8 # 设置编码格式
|
||||
protocol: smtps
|
||||
properties:
|
||||
mail:
|
||||
debug: true # 是否开启debug模式发送邮件
|
||||
smtp:
|
||||
auth: true
|
||||
connectionTimeout: 5000 # 设置连接延迟
|
||||
timeout: 5000 # 延迟时间
|
||||
writeTimeout: 5000 # 写入邮箱延迟
|
||||
allow8BitMime: true
|
||||
sendPartial: true
|
||||
ssl:
|
||||
enabled: true # 是否开启SSL连接
|
||||
socketFactory:
|
||||
class: javax.net.ssl.SSLSocketFactory # 必要设置!!!
|
|
@ -0,0 +1,23 @@
|
|||
package cn.bunny.module.mail.utils;
|
||||
|
||||
import cn.bunny.common.service.utils.EmptyUtil;
|
||||
import cn.bunny.entity.system.email.EmailSend;
|
||||
import cn.bunny.result.constant.MailMessageConstant;
|
||||
|
||||
public class MailSendCheckUtil {
|
||||
/**
|
||||
* 检测发送对象是否为空的对象
|
||||
*
|
||||
* @param emailSend 邮件发送对象
|
||||
*/
|
||||
public static void check(EmailSend emailSend) {
|
||||
// 空发送对象
|
||||
EmptyUtil.isEmpty(emailSend, MailMessageConstant.EMPTY_SEND_OBJECT);
|
||||
// 收件人不能为空
|
||||
EmptyUtil.isEmpty(emailSend.getSendTo(), MailMessageConstant.ADDRESS_NOT_NULL);
|
||||
// 标题不能为空
|
||||
EmptyUtil.isEmpty(emailSend.getSubject(), MailMessageConstant.TITLE_NOT_NULL);
|
||||
// 发送消息不能为空
|
||||
EmptyUtil.isEmpty(emailSend.getMessage(), MailMessageConstant.SEND_MESSAGE_NOT_NULL);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
package cn.bunny.module.mail.utils;
|
||||
|
||||
import cn.bunny.entity.system.email.EmailSend;
|
||||
import cn.bunny.entity.system.email.EmailSendInit;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class MailSenderUtil {
|
||||
private final String username;
|
||||
private final JavaMailSenderImpl javaMailSender;
|
||||
|
||||
/**
|
||||
* 初始化构造函数进行当前类赋值
|
||||
*/
|
||||
public MailSenderUtil(EmailSendInit emailSendInit) {
|
||||
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
|
||||
javaMailSender.setHost(emailSendInit.getHost());
|
||||
javaMailSender.setPort(emailSendInit.getPort());
|
||||
javaMailSender.setUsername(emailSendInit.getUsername());
|
||||
javaMailSender.setPassword(emailSendInit.getPassword());
|
||||
javaMailSender.setProtocol("smtps");
|
||||
javaMailSender.setDefaultEncoding("UTF-8");
|
||||
|
||||
this.username = emailSendInit.getUsername();
|
||||
this.javaMailSender = javaMailSender;
|
||||
}
|
||||
|
||||
/**
|
||||
* 综合邮箱发送
|
||||
*
|
||||
* @param emailSend 邮件消息
|
||||
*/
|
||||
public void sendEmail(EmailSend emailSend) throws MessagingException {
|
||||
MailSendCheckUtil.check(emailSend);
|
||||
|
||||
// 创建 MimeMessage 对象用于发送邮件富文本或者附件
|
||||
MimeMessage message = javaMailSender.createMimeMessage();
|
||||
// 创建 MimeMessageHelper
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
||||
|
||||
// 设置发送人
|
||||
helper.setFrom(username);
|
||||
// 设置邮件接受者
|
||||
helper.setTo(emailSend.getSendTo());
|
||||
// 设置邮件主题
|
||||
helper.setSubject(emailSend.getSubject());
|
||||
// 设置发送消息 为富文本
|
||||
helper.setText(emailSend.getMessage(), emailSend.getIsRichText());
|
||||
// 设置抄送人
|
||||
helper.setCc(emailSend.getCcParam().split(","));
|
||||
// 邮件添加附件
|
||||
MultipartFile[] files = emailSend.getFile();
|
||||
for (MultipartFile file : files) {
|
||||
helper.addAttachment(Objects.requireNonNull(file.getOriginalFilename()), file);
|
||||
}
|
||||
|
||||
// 发送邮件
|
||||
javaMailSender.send(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送邮件-简单
|
||||
*
|
||||
* @param emailSend 邮件消息
|
||||
*/
|
||||
public void sendSimpleEmail(EmailSend emailSend) {
|
||||
MailSendCheckUtil.check(emailSend);
|
||||
// 创建邮件消息体 SimpleMailMessage 发送简单邮件
|
||||
SimpleMailMessage mailMessage = new SimpleMailMessage();
|
||||
|
||||
// 设置邮件发送人
|
||||
mailMessage.setFrom(username);
|
||||
// 设置邮件接受者
|
||||
mailMessage.setTo(emailSend.getSendTo());
|
||||
// 设置邮件主题
|
||||
mailMessage.setSubject(emailSend.getSubject());
|
||||
// 设置邮件消息
|
||||
mailMessage.setText(emailSend.getMessage());
|
||||
|
||||
javaMailSender.send(mailMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送带附件邮件
|
||||
*
|
||||
* @param emailSend 邮件消息
|
||||
*/
|
||||
public void sendAttachmentEmail(EmailSend emailSend, MultipartFile file, boolean isRich) throws MessagingException {
|
||||
MailSendCheckUtil.check(emailSend);
|
||||
// 创建 MimeMessage 对象用户发送附件或者是富文本内容
|
||||
MimeMessage mailMessage = javaMailSender.createMimeMessage();
|
||||
// 创建 MimeMessageHelper
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mailMessage, true);
|
||||
|
||||
// 奢姿邮件发送人
|
||||
helper.setFrom(username);
|
||||
// 设置邮件接受者
|
||||
helper.setTo(emailSend.getSendTo());
|
||||
// 设置邮件消息
|
||||
helper.setText(emailSend.getMessage(), isRich);
|
||||
// 设置邮件主题
|
||||
helper.setSubject(emailSend.getSubject());
|
||||
// 邮件添加附件
|
||||
helper.addAttachment(Objects.requireNonNull(file.getOriginalFilename()), file);
|
||||
|
||||
// 发送邮件
|
||||
javaMailSender.send(mailMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送富文本邮件
|
||||
*
|
||||
* @param emailSend 邮件消息
|
||||
*/
|
||||
public void sendRichText(EmailSend emailSend, boolean isRich) throws MessagingException {
|
||||
MailSendCheckUtil.check(emailSend);
|
||||
// 创建 MimeMessage 对象用户发送附件或者是富文本内容
|
||||
MimeMessage mailMessage = javaMailSender.createMimeMessage();
|
||||
// 创建 MimeMessageHelper
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mailMessage, true);
|
||||
|
||||
// 设置邮件发送者
|
||||
helper.setFrom(username);
|
||||
// 设置邮件接受者
|
||||
helper.setTo(emailSend.getSendTo());
|
||||
// 设置邮件主题
|
||||
helper.setSubject(emailSend.getSubject());
|
||||
// 设置邮件富文本,后面跟true 表示HTML格式发送
|
||||
helper.setText(emailSend.getMessage(), isRich);
|
||||
|
||||
// 发送邮件
|
||||
javaMailSender.send(mailMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送带抄送的邮件
|
||||
*
|
||||
* @param emailSend 邮件消息
|
||||
*/
|
||||
public void sendCC(EmailSend emailSend, boolean isRich) throws MessagingException {
|
||||
MailSendCheckUtil.check(emailSend);
|
||||
// 创建 MimeMessage 对象用于发送邮件富文本或者附件
|
||||
MimeMessage message = javaMailSender.createMimeMessage();
|
||||
// 创建 MimeMessageHelper
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
||||
|
||||
// 设置发送人
|
||||
helper.setFrom(username);
|
||||
// 设置邮件接受者
|
||||
helper.setTo(emailSend.getSendTo());
|
||||
// 设置邮件主题
|
||||
helper.setSubject(emailSend.getSubject());
|
||||
// 设置发送消息 为富文本
|
||||
helper.setText(emailSend.getMessage(), isRich);
|
||||
// 设置抄送人
|
||||
helper.setCc(emailSend.getCcParam().split(","));
|
||||
|
||||
// 发送邮件
|
||||
javaMailSender.send(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.bunny</groupId>
|
||||
<artifactId>module</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>module-minio</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>module-minio</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- minio -->
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,27 @@
|
|||
package cn.bunny.module.minio.properties;
|
||||
|
||||
import io.minio.MinioClient;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "bunny.minio")
|
||||
@ConditionalOnProperty(name = "bunny.minio.bucket-name")// 当属性有值时这个配置才生效
|
||||
@Data
|
||||
@Slf4j
|
||||
public class MinioProperties {
|
||||
private String endpointUrl;
|
||||
private String accessKey;
|
||||
private String secretKey;
|
||||
private String bucketName;
|
||||
|
||||
@Bean
|
||||
public MinioClient minioClient() {
|
||||
log.info("注册MinioClient...");
|
||||
return MinioClient.builder().endpoint(endpointUrl).credentials(accessKey, secretKey).build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,982 @@
|
|||
package cn.bunny.module.minio.utils;
|
||||
|
||||
import cn.bunny.result.constant.FileMessageConstant;
|
||||
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操作工具类 简化操作步骤
|
||||
* By:Bunny0212
|
||||
*/
|
||||
@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(FileMessageConstant.BUCKET_EXISTS_EXCEPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶的加密配置
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
*/
|
||||
public void deleteBucketEncryption(String bucketName) {
|
||||
try {
|
||||
minioClient.deleteBucketEncryption(DeleteBucketEncryptionArgs.builder().build());
|
||||
log.info("删除桶的加密配置 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶的加密配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
}
|
||||
throw new BunnyException(FileMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶的生命周期配置
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
*/
|
||||
public void deleteBucketLifecycle(String bucketName) {
|
||||
try {
|
||||
minioClient.deleteBucketLifecycle(DeleteBucketLifecycleArgs.builder().build());
|
||||
log.info("删除桶的生命周期配置 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶的生命周期配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶的通知配置
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
*/
|
||||
public void deleteBucketNotification(String bucketName) {
|
||||
try {
|
||||
minioClient.deleteBucketNotification(DeleteBucketNotificationArgs.builder().bucket(bucketName).build());
|
||||
log.info("删除桶的通知配置 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶的加密配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶策略配置
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
*/
|
||||
public void deleteBucketPolicy(String bucketName) {
|
||||
try {
|
||||
minioClient.deleteBucketPolicy(DeleteBucketPolicyArgs.builder().bucket(bucketName).build());
|
||||
log.info("删除桶中的对象锁配置 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶的加密配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶的桶复制配置
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
*/
|
||||
public void deleteBucketReplication(String bucketName) {
|
||||
try {
|
||||
minioClient.deleteBucketReplication(DeleteBucketReplicationArgs.builder().bucket(bucketName).build());
|
||||
log.info("删除桶的桶复制配置 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶的桶复制配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶的标签
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
*/
|
||||
public void deleteBucketTags(String bucketName) {
|
||||
try {
|
||||
minioClient.deleteBucketTags(DeleteBucketTagsArgs.builder().bucket(bucketName).build());
|
||||
log.info("删除桶的标签 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶的桶复制配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶中的对象锁配置
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
*/
|
||||
public void deleteObjectLockConfiguration(String bucketName) {
|
||||
try {
|
||||
minioClient.deleteObjectLockConfiguration(DeleteObjectLockConfigurationArgs.builder().bucket(bucketName).build());
|
||||
log.info("删除桶中的对象锁配置 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶中的对象锁配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.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(FileMessageConstant.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(FileMessageConstant.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(FileMessageConstant.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(FileMessageConstant.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(FileMessageConstant.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(FileMessageConstant.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(FileMessageConstant.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(FileMessageConstant.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(FileMessageConstant.QUERY_BUCKET_EXCEPTION);
|
||||
}
|
||||
|
||||
return buckets;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建桶
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
*/
|
||||
public void makeBucket(String bucketName) {
|
||||
try {
|
||||
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
||||
log.info("创建桶 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("创建桶 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.CREATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建桶
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
*/
|
||||
public void makeBucket(String bucketName, String region) {
|
||||
try {
|
||||
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).region(region).build());
|
||||
log.info("创建桶 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("创建桶 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.CREATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建桶
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
*/
|
||||
public void makeBucket(String bucketName, String region, boolean objectLock) {
|
||||
try {
|
||||
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).region(region).objectLock(objectLock).build());
|
||||
log.info("创建桶 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("创建桶 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.CREATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除桶
|
||||
*
|
||||
* @param bucketName 桶的名称
|
||||
*/
|
||||
public void removeBucket(String bucketName) {
|
||||
try {
|
||||
minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
|
||||
log.info("删除桶 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("删除桶 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置桶的加密配置
|
||||
*
|
||||
* @param bucketName 同名称
|
||||
* @param configuration 配置信息
|
||||
*/
|
||||
public void setBucketEncryption(String bucketName, SseConfiguration configuration) {
|
||||
try {
|
||||
minioClient.setBucketEncryption(SetBucketEncryptionArgs.builder().bucket(bucketName).config(configuration).build());
|
||||
log.info("设置桶的加密配置 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("设置桶的加密配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.UPDATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置桶策略
|
||||
*
|
||||
* @param bucketName 同名称
|
||||
* @param policyJson 配置信息
|
||||
*/
|
||||
public void setBucketPolicy(String bucketName, String policyJson) {
|
||||
try {
|
||||
minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucketName).config(policyJson).build());
|
||||
log.info("查看桶策略 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("查看桶策略 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.UPDATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置桶复制参数
|
||||
*
|
||||
* @param bucketName 同名称
|
||||
* @param config 配置信息
|
||||
* @return 布尔值是否完成
|
||||
*/
|
||||
public void setBucketReplication(String bucketName, ReplicationConfiguration config) {
|
||||
try {
|
||||
minioClient.setBucketReplication(SetBucketReplicationArgs.builder().bucket(bucketName).config(config).build());
|
||||
log.info("设置桶复制参数 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("设置桶复制参数 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.UPDATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置/修改桶标签
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param map 标签集合
|
||||
*/
|
||||
public void setBucketTags(String bucketName, Map<String, String> map) {
|
||||
try {
|
||||
minioClient.setBucketTags(SetBucketTagsArgs.builder().bucket(bucketName).tags(map).build());
|
||||
log.info("设置/修改桶标签 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("设置/修改桶标签 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.UPDATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置桶的版本配置
|
||||
*
|
||||
* @param bucketName 同名称
|
||||
* @param configuration 配置信息
|
||||
*/
|
||||
public void setBucketVersioning(String bucketName, VersioningConfiguration configuration) {
|
||||
try {
|
||||
minioClient.setBucketVersioning(
|
||||
SetBucketVersioningArgs.builder().bucket(bucketName).config(configuration).build());
|
||||
log.info("设置桶的版本配置 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("设置桶的版本配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.UPDATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象对象锁定配置
|
||||
*
|
||||
* @param bucketName 同名称
|
||||
* @param configuration 配置信息
|
||||
*/
|
||||
public void setObjectLockConfiguration(String bucketName, ObjectLockConfiguration configuration) {
|
||||
try {
|
||||
minioClient.setObjectLockConfiguration(SetObjectLockConfigurationArgs.builder().bucket(bucketName).config(configuration).build());
|
||||
log.info("对象对象锁定配置 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("对象对象锁定配置 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.UPDATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 组合对象
|
||||
*
|
||||
* @param bucketName 同名称
|
||||
* @param objectName 对象名称
|
||||
* @param sources 对象列表
|
||||
*/
|
||||
public void composeObject(String bucketName, String objectName, List<ComposeSource> sources) {
|
||||
try {
|
||||
minioClient.composeObject(ComposeObjectArgs.builder().bucket(bucketName).object(objectName).sources(sources).build());
|
||||
log.info("组合对象 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("组合对象 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.COMPOSE_OBJECT_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 组合对象
|
||||
*
|
||||
* @param bucketName 同名称
|
||||
* @param objectName 对象名称
|
||||
* @param sources 对象列表
|
||||
* @param userMetadata 用户元数据
|
||||
*/
|
||||
public void composeObject(String bucketName, String objectName, List<ComposeSource> sources, Map<String, String> userMetadata) {
|
||||
try {
|
||||
minioClient.composeObject(ComposeObjectArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.object(objectName)
|
||||
.sources(sources)
|
||||
.userMetadata(userMetadata).build());
|
||||
log.info("组合对象 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("组合对象 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.COMPOSE_OBJECT_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 组合对象
|
||||
*
|
||||
* @param bucketName 同名称
|
||||
* @param objectName 对象名称
|
||||
* @param sources 对象列表
|
||||
* @param userMetadata 用户元数据
|
||||
* @param sideEncryption 通过组合源对象列表
|
||||
*/
|
||||
public void composeObject(String bucketName, String objectName, List<ComposeSource> sources, Map<String, String> userMetadata, ServerSideEncryption sideEncryption) {
|
||||
try {
|
||||
minioClient.composeObject(ComposeObjectArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.object(objectName)
|
||||
.sources(sources)
|
||||
.userMetadata(userMetadata)
|
||||
.sse(sideEncryption).build());
|
||||
log.info("组合对象 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("组合对象 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.COMPOSE_OBJECT_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制另一个桶中文件
|
||||
*
|
||||
* @param bucketName 桶中名字
|
||||
* @param objectName 复制名称
|
||||
* @param sourceBucketName 复制到桶中名称
|
||||
* @param sourceObjectName 复制完成后名称
|
||||
*/
|
||||
public void copyObject(String bucketName, String objectName, String sourceBucketName, String sourceObjectName) {
|
||||
try {
|
||||
minioClient.copyObject(CopyObjectArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.object(objectName)
|
||||
.source(CopySource.builder().bucket(sourceBucketName).object(sourceObjectName).build())
|
||||
.build());
|
||||
log.info("复制另一个桶中文件 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("复制另一个桶中文件 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.COPY_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制另一个桶中文件
|
||||
*
|
||||
* @param bucketName 桶中名字
|
||||
* @param objectName 复制名称
|
||||
* @param sourceBucketName 复制到桶中名称
|
||||
* @param sourceObjectName 复制完成后名称
|
||||
* @param sideEncryption 加密key
|
||||
*/
|
||||
public void copyObject(String bucketName, String objectName, String sourceBucketName, String sourceObjectName, ServerSideEncryption sideEncryption) {
|
||||
try {
|
||||
minioClient.copyObject(CopyObjectArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.object(objectName)
|
||||
.source(CopySource.builder().bucket(sourceBucketName).object(sourceObjectName).build())
|
||||
.sse(sideEncryption)
|
||||
.build());
|
||||
log.info("复制另一个桶中文件 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("复制另一个桶中文件 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.COPY_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制另一个桶中文件
|
||||
*
|
||||
* @param bucketName 桶中名字
|
||||
* @param objectName 复制名称
|
||||
* @param sourceBucketName 复制到桶中名称
|
||||
* @param sourceObjectName 复制完成后名称
|
||||
* @param etag 标签
|
||||
* @param headers 头部信息
|
||||
*/
|
||||
public void copyObject(String bucketName, String objectName, String sourceBucketName, String sourceObjectName, String etag, Map<String, String> headers) {
|
||||
try {
|
||||
minioClient.copyObject(CopyObjectArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.object(objectName)
|
||||
.source(CopySource.builder().bucket(sourceBucketName).object(sourceObjectName).matchETag(etag).build())
|
||||
.headers(headers)
|
||||
.build());
|
||||
log.info("复制另一个桶中文件 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("复制另一个桶中文件 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.COPY_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除对象的标记
|
||||
*
|
||||
* @param bucketName 桶中名字
|
||||
* @param objectName 复制名称
|
||||
*/
|
||||
public void deleteObjectTags(String bucketName, String objectName) {
|
||||
try {
|
||||
minioClient.deleteObjectTags(DeleteObjectTagsArgs.builder().bucket(bucketName).object(objectName).build());
|
||||
log.info("删除对象的标记 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("删除对象的标记 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用对象
|
||||
*
|
||||
* @param bucketName 桶中名字
|
||||
* @param objectName 复制名称
|
||||
*/
|
||||
public void disableObjectLegalHold(String bucketName, String objectName) {
|
||||
try {
|
||||
minioClient.disableObjectLegalHold(DisableObjectLegalHoldArgs.builder().bucket(bucketName).object(objectName).build());
|
||||
log.info("禁用对象 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("禁用对象 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.DISABLE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用文件对象
|
||||
*
|
||||
* @param bucketName 桶中名字
|
||||
* @param objectName 复制名称
|
||||
*/
|
||||
public void enableObjectLegalHold(String bucketName, String objectName) {
|
||||
try {
|
||||
minioClient.enableObjectLegalHold(EnableObjectLegalHoldArgs.builder().bucket(bucketName).object(objectName).build());
|
||||
log.info("禁用对象 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("禁用对象 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.ENABLE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param objectName 对象名称
|
||||
*/
|
||||
public InputStream getObject(String bucketName, String objectName) {
|
||||
try {
|
||||
GetObjectResponse object = minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(objectName).build());
|
||||
log.info("获取文件 ------ 成功");
|
||||
return object;
|
||||
} catch (Exception exception) {
|
||||
log.error("获取文件 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.GET_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*
|
||||
* @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());
|
||||
log.info("下载文件 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("下载文件 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.DOWNLOAD_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param objectName 对象名称
|
||||
* @param filename 文件名
|
||||
* @param sideEncryption 秘钥
|
||||
*/
|
||||
public void downloadObject(String bucketName, String objectName, String filename, ServerSideEncryptionCustomerKey sideEncryption) {
|
||||
try {
|
||||
minioClient.downloadObject(DownloadObjectArgs.builder().bucket(bucketName).object(objectName).filename(filename).ssec(sideEncryption).build());
|
||||
log.info("下载文件 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("下载文件 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.DOWNLOAD_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对象保留
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param objectName 对象名称
|
||||
* @param versionId 版本ID
|
||||
* @return 对象保留
|
||||
*/
|
||||
public Retention getObjectRetention(String bucketName, String objectName, String versionId) {
|
||||
try {
|
||||
Retention retention = minioClient.getObjectRetention(GetObjectRetentionArgs.builder().bucket(bucketName).object(objectName).versionId(versionId).build());
|
||||
log.info("获取对象保留 ------ 成功");
|
||||
return retention;
|
||||
} catch (Exception exception) {
|
||||
log.error("获取对象保留 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.DOWNLOAD_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对象标签
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param objectName 对象名称
|
||||
* @return 对象保留
|
||||
*/
|
||||
public Tags getObjectTags(String bucketName, String objectName) {
|
||||
try {
|
||||
Tags tags = minioClient.getObjectTags(GetObjectTagsArgs.builder().bucket(bucketName).object(objectName).build());
|
||||
log.info("获取对象标签 ------ 成功");
|
||||
return tags;
|
||||
} catch (Exception exception) {
|
||||
log.error("获取对象标签 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.GET_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @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());
|
||||
log.info("上传文件 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("上传文件 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.FILE_UPLOAD_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @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());
|
||||
log.info("上传文件 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("上传文件 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.FILE_UPLOAD_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param object 对象信息
|
||||
* @param filename 文件名
|
||||
* @param contentType 文件类型
|
||||
*/
|
||||
public void putObject(String bucketName, String object, String filename, String contentType) {
|
||||
try {
|
||||
if (contentType != null) {
|
||||
minioClient.uploadObject(UploadObjectArgs.builder().bucket(bucketName).object(filename).contentType(contentType).build());
|
||||
} else {
|
||||
minioClient.uploadObject(UploadObjectArgs.builder().bucket(bucketName).object(filename).build());
|
||||
}
|
||||
log.info("上传文件 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("上传文件 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.FILE_UPLOAD_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param objectName 对象名称
|
||||
*/
|
||||
public void removeObject(String bucketName, String objectName) {
|
||||
try {
|
||||
minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build());
|
||||
log.info("删除文件 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("删除文件 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param objectName 对象名称
|
||||
* @param versionId 版本号
|
||||
*/
|
||||
public void removeObject(String bucketName, String objectName, String versionId) {
|
||||
try {
|
||||
minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(objectName).versionId(versionId).build());
|
||||
log.info("删除文件 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("删除文件 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param objectName 对象名称
|
||||
* @param bypassRetentionMode 保持模式
|
||||
*/
|
||||
public void removeObject(String bucketName, String objectName, String versionId, boolean bypassRetentionMode) {
|
||||
try {
|
||||
minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(objectName).versionId(versionId).bypassGovernanceMode(bypassRetentionMode).build());
|
||||
log.info("删除文件 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("删除文件 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传多文件,通过创建中间TAR文件(可选压缩)来完成的
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param objects 对象名称
|
||||
*/
|
||||
public void uploadSnowballObjects(String bucketName, List<SnowballObject> objects) {
|
||||
try {
|
||||
minioClient.uploadSnowballObjects(UploadSnowballObjectsArgs.builder().bucket(bucketName).objects(objects).build());
|
||||
log.info("上传多文件 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("上传多文件 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.FILE_UPLOAD_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置对象标签
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param objectName 对象名称
|
||||
* @param retention 配置信息
|
||||
* @param bypassGovernanceMode 保持模式
|
||||
*/
|
||||
public void setObjectLockRetention(String bucketName, String objectName, Retention retention, boolean bypassGovernanceMode) {
|
||||
try {
|
||||
minioClient.setObjectRetention(SetObjectRetentionArgs.builder().bucket(bucketName).object(objectName).config(retention).bypassGovernanceMode(bypassGovernanceMode).build());
|
||||
log.info("删除文件 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("删除文件 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.UPDATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置对象标签
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param objectName 对象名称
|
||||
* @param map 对象集合
|
||||
*/
|
||||
public void setObjectTags(String bucketName, String objectName, Map<String, String> map) {
|
||||
try {
|
||||
minioClient.setObjectTags(SetObjectTagsArgs.builder().bucket(bucketName).object(objectName).tags(map).build());
|
||||
log.info("删除文件 ------ 成功");
|
||||
} catch (Exception exception) {
|
||||
log.error("删除文件 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.UPDATE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对象状态
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param objectName 对象名称
|
||||
* @param versionId 版本ID
|
||||
* @param customerKey 秘钥
|
||||
* @return 对象信息
|
||||
*/
|
||||
public StatObjectResponse statObject(String bucketName, String objectName, String versionId, ServerSideEncryptionCustomerKey customerKey) {
|
||||
try {
|
||||
StatObjectResponse statObjectResponse = minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(objectName).versionId(versionId).ssec(customerKey).build());
|
||||
log.info("获取对象状态 ------ 成功");
|
||||
return statObjectResponse;
|
||||
} catch (Exception exception) {
|
||||
log.error("获取对象状态 ------ 失败消息:{}", exception.getLocalizedMessage());
|
||||
exception.getStackTrace();
|
||||
throw new BunnyException(FileMessageConstant.DELETE_BUCKET_EXCEPTION);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.bunny</groupId>
|
||||
<artifactId>module</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>module-rabbitMQ</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>module-rabbitMQ</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.amqp</groupId>
|
||||
<artifactId>spring-rabbit-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<version>2.16.0-rc1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,38 @@
|
|||
package cn.bunny.module.rabbitMQ.config;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class RabbitMqConfig {
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
rabbitTemplate.setReturnsCallback(returned -> {
|
||||
log.error("触发return callback,");
|
||||
log.debug("exchange: {}", returned.getExchange());
|
||||
log.debug("routingKey: {}", returned.getRoutingKey());
|
||||
log.debug("message: {}", returned.getMessage());
|
||||
log.debug("replyCode: {}", returned.getReplyCode());
|
||||
log.debug("replyText: {}", returned.getReplyText());
|
||||
});
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageConverter messageConverter() {
|
||||
// 1.定义消息转换器
|
||||
Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter();
|
||||
// 2.配置自动创建消息id,用于识别不同消息,也可以在业务中基于ID判断是否是重复消息
|
||||
converter.setCreateMessageIds(true);
|
||||
return converter;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package cn.bunny.module.rabbitMQ.consumer;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DelayConsumer {
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cn.bunny.module.rabbitMQ.consumer;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DirectConsumer {
|
||||
@Autowired
|
||||
RabbitTemplate rabbitTemplate;
|
||||
|
||||
/**
|
||||
* 发送红色消息
|
||||
*/
|
||||
@Test
|
||||
void testSendDirectRed() throws Exception {
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
rabbitTemplate.convertAndSend("bunny.direct", "red", "发送消息:" + i);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package cn.bunny.module.rabbitMQ.consumer;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ErrorConsumer {
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package cn.bunny.module.rabbitMQ.consumer;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class FanoutConsumer {
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package cn.bunny.module.rabbitMQ.consumer;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class LazyConsumer {
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package cn.bunny.module.rabbitMQ.consumer;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class TopicConsumer {
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package cn.bunny.module.rabbitMQ.listener;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DelayListener {
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package cn.bunny.module.rabbitMQ.listener;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.ExchangeTypes;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DirectListener {
|
||||
/**
|
||||
* * 监听者2
|
||||
* 创建队列 持久化的、不自动删除
|
||||
* 创建交换机 持久化的、不自动删除
|
||||
* key包含 red 和 yellow
|
||||
*
|
||||
* @param message 接受消息
|
||||
*/
|
||||
@RabbitListener(bindings = @QueueBinding(
|
||||
value = @Queue(name = "direct.queue2", durable = "true", autoDelete = "false"),
|
||||
exchange = @Exchange(name = "bunny.direct", type = ExchangeTypes.DIRECT, durable = "true", autoDelete = "false"),
|
||||
key = {"red", "yellow"}
|
||||
))
|
||||
public void listenDirectQueue2(String message) {
|
||||
System.out.println("消费者2接收到 Direct key 为 {\"red\", \"yellow\"} 消息:【" + message + "】");
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue