diff --git a/README.md b/README.md
index eb465f4..230f570 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,7 @@
![Gateway Version](https://img.shields.io/badge/Gateway-4.1.3-brightgreen)
![jjwt Version](https://img.shields.io/badge/jjwt-0.12.6-brightgreen)
![Mybatis-plus Version](https://img.shields.io/badge/MybatisPlus-3.5.9-brightgreen)
+![Sharding-jdbc Version](https://img.shields.io/badge/ShardingJdbc-5.5.1-brightgreen)
![Swagger Version](https://img.shields.io/badge/knife4j-4.5.0-brightgreen)
![Elasticjob Version](https://img.shields.io/badge/elasticjob-3.0.4-brightgreen)
@@ -47,6 +48,9 @@
1. `cloud-service-auth`: 认证资源服务,基于SpringSecurity以及jwt
2. `cloud-service-staff`: 员工信息服务
+ ```text
+ 1.1 使用shardingsphere-jdbc对登录登出日志进行分表
+ ```
## 开源共建
1. 如有问题可以提交[issue](https://github.com/ZhiQinIsZhen/cloud-springboot3/issues)
diff --git a/cloud-common/cloud-common-dao/pom.xml b/cloud-common/cloud-common-dao/pom.xml
index 8156609..72b7e2e 100644
--- a/cloud-common/cloud-common-dao/pom.xml
+++ b/cloud-common/cloud-common-dao/pom.xml
@@ -25,6 +25,11 @@
mybatis-plus-spring-boot3-starter
provided
+
+ com.baomidou
+ mybatis-plus-jsqlparser
+ provided
+
com.liyz.cloud
cloud-common-exception
diff --git a/cloud-dependencies-bom/pom.xml b/cloud-dependencies-bom/pom.xml
index ed7e7fa..69f16b0 100644
--- a/cloud-dependencies-bom/pom.xml
+++ b/cloud-dependencies-bom/pom.xml
@@ -13,17 +13,18 @@
21
21
UTF-8
- 3.3.4
- 2023.0.3
+ 3.3.6
+ 2023.0.4
5.8.32
33.3.1-jre
4.5.0
- 3.5.8
- 3.37.0
+ 3.5.9
+ 3.39.0
0.12.6
3.0.4
+ 5.5.1
4.0.3
- 3.3.4
+ 3.3.6
2.3.1
3.2.4
@@ -75,6 +76,11 @@
mybatis-plus-annotation
${mybatis.plus.version}
+
+ com.baomidou
+ mybatis-plus-jsqlparser
+ ${mybatis.plus.version}
+
org.redisson
redisson-spring-boot-starter
@@ -105,6 +111,11 @@
elasticjob-lite-spring-boot-starter
${elasticjob.version}
+
+ org.apache.shardingsphere
+ shardingsphere-jdbc
+ ${shardingsphere.version}
+
org.apache.rocketmq
rocketmq-spring-boot-starter
diff --git a/cloud-service/cloud-service-auth/auth-dao/pom.xml b/cloud-service/cloud-service-auth/auth-dao/pom.xml
index 59cfa2b..735480c 100644
--- a/cloud-service/cloud-service-auth/auth-dao/pom.xml
+++ b/cloud-service/cloud-service-auth/auth-dao/pom.xml
@@ -20,6 +20,10 @@
com.baomidou
mybatis-plus-spring-boot3-starter
+
+ com.baomidou
+ mybatis-plus-jsqlparser
+
com.liyz.cloud
cloud-common-exception
diff --git a/cloud-service/cloud-service-staff/staff-dao/pom.xml b/cloud-service/cloud-service-staff/staff-dao/pom.xml
index 47618a6..42a6ca7 100644
--- a/cloud-service/cloud-service-staff/staff-dao/pom.xml
+++ b/cloud-service/cloud-service-staff/staff-dao/pom.xml
@@ -20,6 +20,10 @@
com.baomidou
mybatis-plus-spring-boot3-starter
+
+ com.baomidou
+ mybatis-plus-jsqlparser
+
com.liyz.cloud
cloud-common-exception
@@ -32,6 +36,10 @@
com.zaxxer
HikariCP
+
+ org.apache.shardingsphere
+ shardingsphere-jdbc
+
com.mysql
mysql-connector-j
diff --git a/cloud-service/cloud-service-staff/staff-web/src/main/resources/application.yaml b/cloud-service/cloud-service-staff/staff-web/src/main/resources/application.yaml
index 0fa23fa..a71ff9d 100644
--- a/cloud-service/cloud-service-staff/staff-web/src/main/resources/application.yaml
+++ b/cloud-service/cloud-service-staff/staff-web/src/main/resources/application.yaml
@@ -40,10 +40,8 @@ spring:
enabled: false
# datasource
datasource:
- url: jdbc:mysql://localhost:3306/staff3?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=GMT%2B8
- type: com.zaxxer.hikari.HikariDataSource
- username: root
- password: root
+ url: jdbc:shardingsphere:classpath:sharding.yaml
+ driver-class-name: org.apache.shardingsphere.driver.ShardingSphereDriver
# hikari
hikari:
minimum-idle: 2
diff --git a/cloud-service/cloud-service-staff/staff-web/src/main/resources/sharding.yaml b/cloud-service/cloud-service-staff/staff-web/src/main/resources/sharding.yaml
new file mode 100644
index 0000000..9527a5e
--- /dev/null
+++ b/cloud-service/cloud-service-staff/staff-web/src/main/resources/sharding.yaml
@@ -0,0 +1,56 @@
+databaseName: staff2
+
+dataSources:
+ staff_db_0:
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ driverClassName: com.mysql.cj.jdbc.Driver
+ jdbcUrl: jdbc:mysql://localhost:3306/staff2?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=GMT%2B8
+ username: root
+ password: root
+
+rules:
+ - !SINGLE
+ tables:
+ - "staff_db_0.*"
+ - !SHARDING
+ tables:
+ staff_login_log:
+ actualDataNodes: staff_db_0.staff_login_log_$->{0..1}
+ databaseStrategy:
+ none:
+ tableStrategy:
+ standard:
+ shardingColumn: staff_id
+ shardingAlgorithmName: login_inline
+ keyGenerateStrategy:
+ column: id
+ keyGeneratorName: snowflake
+ staff_logout_log:
+ actualDataNodes: staff_db_0.staff_logout_log_$->{0..1}
+ databaseStrategy:
+ none:
+ tableStrategy:
+ standard:
+ shardingColumn: staff_id
+ shardingAlgorithmName: logout_inline
+ keyGenerateStrategy:
+ column: id
+ keyGeneratorName: snowflake
+ keyGenerators:
+ snowflake:
+ type: SNOWFLAKE
+ props:
+ worker-id: 123
+ # 分片算法配置
+ shardingAlgorithms:
+ login_inline:
+ type: INLINE
+ props:
+ algorithm-expression: staff_login_log_$->{staff_id % 2}
+ logout_inline:
+ type: INLINE
+ props:
+ algorithm-expression: staff_logout_log_$->{staff_id % 2}
+
+props:
+ sql-show: true
diff --git a/cloud-service/cloud-service-staff/user.sql b/cloud-service/cloud-service-staff/user.sql
index d22364a..a16ae35 100644
--- a/cloud-service/cloud-service-staff/user.sql
+++ b/cloud-service/cloud-service-staff/user.sql
@@ -1,5 +1,5 @@
-CREATE TABLE `user_auth_email` (
- `user_id` bigint(20) unsigned NOT NULL COMMENT '用户ID',
+CREATE TABLE `staff_auth_email` (
+ `staff_id` bigint(20) unsigned NOT NULL COMMENT '员工ID',
`email` varchar(128) NOT NULL COMMENT '邮箱',
`password` varchar(256) NOT NULL COMMENT '密码',
`create_user` bigint(20) NOT NULL COMMENT '创建者',
@@ -8,12 +8,12 @@ CREATE TABLE `user_auth_email` (
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`is_deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除 | 0、未删除 1、已删除',
`version` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '版本号',
- PRIMARY KEY (`user_id`) USING BTREE,
+ PRIMARY KEY (`staff_id`) USING BTREE,
UNIQUE KEY `uniq_email` (`email`) USING BTREE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户邮箱认证表';
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='员工邮箱认证表';
-CREATE TABLE `user_auth_mobile` (
- `user_id` bigint(20) unsigned NOT NULL COMMENT '用户ID',
+CREATE TABLE `staff_auth_mobile` (
+ `staff_id` bigint(20) unsigned NOT NULL COMMENT '员工ID',
`mobile` varchar(11) NOT NULL COMMENT '邮箱',
`password` varchar(256) NOT NULL COMMENT '密码',
`create_user` bigint(20) NOT NULL COMMENT '创建者',
@@ -22,12 +22,12 @@ CREATE TABLE `user_auth_mobile` (
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`is_deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除 | 0、未删除 1、已删除',
`version` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '版本号',
- PRIMARY KEY (`user_id`) USING BTREE,
+ PRIMARY KEY (`staff_id`) USING BTREE,
UNIQUE KEY `uniq_mobile` (`mobile`) USING BTREE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户手机认证表';
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='员工手机认证表';
-CREATE TABLE `user_info` (
- `user_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '用户ID',
+CREATE TABLE `staff_info` (
+ `staff_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '员工ID',
`real_name` varchar(128) DEFAULT NULL COMMENT '真实名称',
`nick_name` varchar(128) NOT NULL COMMENT '昵称',
`mobile` varchar(11) DEFAULT NULL COMMENT '手机号码',
@@ -40,12 +40,12 @@ CREATE TABLE `user_info` (
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`is_deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除 | 0、未删除 1、已删除',
`version` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '版本号',
- PRIMARY KEY (`user_id`) USING BTREE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户基础信息表';
+ PRIMARY KEY (`staff_id`) USING BTREE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='员工基础信息表';
-CREATE TABLE `user_login_log` (
+CREATE TABLE `staff_login_log_0` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增ID',
- `user_id` bigint(20) unsigned NOT NULL COMMENT '用户ID',
+ `staff_id` bigint(20) unsigned NOT NULL COMMENT '员工ID',
`login_type` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '登录方式:1:手机;2:邮箱',
`device` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '登录设备:1:手机;2:web',
`login_time` timestamp NOT NULL COMMENT '登录时间',
@@ -57,12 +57,29 @@ CREATE TABLE `user_login_log` (
`is_deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除 | 0、未删除 1、已删除',
`version` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '版本号',
PRIMARY KEY (`id`) USING BTREE,
- KEY `idx_user_id` (`user_id`) USING BTREE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户登录日志表';
+ KEY `idx_staff_id` (`staff_id`) USING BTREE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='员工登录日志表-0';
-CREATE TABLE `user_logout_log` (
+CREATE TABLE `staff_login_log_1` (
+`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增ID',
+`staff_id` bigint(20) unsigned NOT NULL COMMENT '员工ID',
+`login_type` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '登录方式:1:手机;2:邮箱',
+`device` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '登录设备:1:手机;2:web',
+`login_time` timestamp NOT NULL COMMENT '登录时间',
+`ip` varchar(256) DEFAULT NULL COMMENT '登录IP地址',
+`create_user` bigint(20) NOT NULL COMMENT '创建者',
+`update_user` bigint(20) NOT NULL COMMENT '更新者',
+`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+`is_deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除 | 0、未删除 1、已删除',
+`version` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '版本号',
+PRIMARY KEY (`id`) USING BTREE,
+KEY `idx_staff_id` (`staff_id`) USING BTREE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='员工登录日志表-1';
+
+CREATE TABLE `staff_logout_log_0` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增ID',
- `user_id` bigint(20) unsigned NOT NULL COMMENT '用户ID',
+ `staff_id` bigint(20) unsigned NOT NULL COMMENT '员工ID',
`logout_type` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '登出方式:1:手机;2:邮箱',
`device` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '登录设备:1:手机;2:web',
`logout_time` timestamp NOT NULL COMMENT '登录时间',
@@ -74,5 +91,23 @@ CREATE TABLE `user_logout_log` (
`is_deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除 | 0、未删除 1、已删除',
`version` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '版本号',
PRIMARY KEY (`id`) USING BTREE,
- KEY `idx_user_id` (`user_id`) USING BTREE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户登出日志表';
\ No newline at end of file
+ KEY `idx_staff_id` (`staff_id`) USING BTREE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='员工登出日志表-0';
+
+
+CREATE TABLE `staff_logout_log_1` (
+ `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增ID',
+ `staff_id` bigint(20) unsigned NOT NULL COMMENT '员工ID',
+ `logout_type` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '登出方式:1:手机;2:邮箱',
+ `device` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '登录设备:1:手机;2:web',
+ `logout_time` timestamp NOT NULL COMMENT '登录时间',
+ `ip` varchar(256) DEFAULT NULL COMMENT '登录IP地址',
+ `create_user` bigint(20) NOT NULL COMMENT '创建者',
+ `update_user` bigint(20) NOT NULL COMMENT '更新者',
+ `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+ `is_deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除 | 0、未删除 1、已删除',
+ `version` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '版本号',
+ PRIMARY KEY (`id`) USING BTREE,
+ KEY `idx_staff_id` (`staff_id`) USING BTREE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='员工登出日志表-1';
\ No newline at end of file