Glory-Admin
Gloriyadmin is a background framework based on springboot2.1.9.release and Vue admin template;
Gloryadmin uses role-based rights management. The role tree is a tree with “system administrator” as the root node, and the permission tree is composed of multiple sub permission trees. “System administrator” has all permissions; non system administrator role can view the information of current role and direct subordinate role, but can only add, delete and modify the information of the role of direct subordinate (direct subordinate: if a is a direct subordinate of B, then a must be a child node of B).
-
Glory-Admin
-
- Technical description
- demonstration
- system architecture
-
Project launch
- Database installation
- Project launch
-
database
- Why split data? What is sub database and sub table? What is a distributed database?
- Version control of database
- Database cache layer cachedao
- Sub database and sub table
- Data fragmentation can be divided into vertical slicing and horizontal slicing
- Common segmentation algorithms
-
back-end
- Permission design
- Project structure
- Maven uses BOM management
- Logging
- User action log
- front end
Technical description
project | technology |
---|---|
Back end project | springboot |
Front end project | Element UI & Vue.js |
database | MySQL |
cache | Redis |
demonstration
Demo address
system architecture
Project launch
Database installation
This project uses MySQL database, you can use database script to create two databasesmulti_module_db multi_module_db_01
Project launch
Background boot, using 28081 port
Front end boot, using port 9523
Open browser access http://localhost :9523 admin a123456
database
Why split data? What is sub database and sub table? What is a distributed database?
The essence of sub database and sub table or sharding is the failure of Moore’s law. The solution of centralized storage of data to a single data node has been difficult to meet the massive data scenarios of the Internet in terms of performance, availability and operation and maintenance cost.
Single database can not support the existing business, so there are sub databases and sub tables, and multiple databases are used for data storage. The simple understanding of sub database and sub table is that the contents in a basket are limited, which affects the search efficiency and capacity. The contents in the basket are divided into N parts and loaded into different baskets. In order to break the capacity limit and improve the query efficiency.
Then let’s talk about distributed databases. The popular ones in China are Tencent’s tdsql, Alibaba’s oceanbase, polardb, Huawei’s gaussdb, etc. Basically all of themIndependent research and development, strong consistency, high availability, global deployment architecture, distributed unlimited horizontal expansion, high performance, cross bank and cross table transactions on hundreds of billions of records and hundreds of terabytes of data (praise for the motherland)。 Distributed database hides the strategy of database sub database and sub table. It can intelligently divide data into sub databases and sub tables, which is just like operating a database.
Version control of flyway database
Database cache layer cachedao
Since memory operations and disk operations are not of the same order of magnitude at all, they need to be used in large projectsDisk databasedoMemory based buffer layerTo cache disk data into memory. The data cache layer is used to cache the data of the whole data layer and accelerate the site access speed. Use of this projectAOP technology、Redis memory databaseDo data cache layer. Please check the code COM / spring / common / AOP for details/ CacheDaoAspect.java
Sub database and sub table
This project uses sharding JDBC to process the sub database and sub table of database. Split the data according to the business scenario.
Usually, there is only one database in a project, and the Druid of Alibaba cloud is often used as the connection pool of the database. This project uses mysql, Druid, sharding JDBC. The principle of data partition is maintained in the programMultiple database connection pools, each of which corresponds to one database.Sub database and sub tableTwo phase transaction based on XA protocolhandle. Configuration pathcom.spring.common.config.shardingJDBC
Data fragmentation can be divided into vertical slicing and horizontal slicing
Vertical splitting: vertical splitting is also called vertical splitting according to the business splitting method. Distribute tables to different databases according to business, thus spreading the pressure to different databases.
Horizontal splitting: it does not care about business logic classification, but distributes data to multiple databases or tables according to certain rules through a certain field (or several fields) of a table. The rules here, the algorithms involved, we call themPartition algorithm。
Common segmentation algorithms
(The following is taken from the sharding JDBC documentation)
- Accurate segmentation algorithm
The corresponding precise sharding algorithm is used to handle the=
AndIN
The scene of fragmentation. It needs to be used with standard shardingstrategy.
- Range slicing algorithm
Corresponding to the range sharding algorithm, which is used to process theBETWEEN AND
、>
、<
、>=
、<=
The scene of fragmentation. It needs to be used with standard shardingstrategy.
- Compound partition algorithm
Corresponding to the complex keys sharding algorithm, it is used to deal with scenarios where multiple keys are used as partitioning keys. The logic of multiple partitioning keys is complex, and the complexity needs to be handled by application developers themselves. It needs to be used with the complexshaddingstrategy.
- Hint partition algorithm
Corresponding to hintshardingalgorithmfor processing and usingHint
The scene of line segmentation. It needs to be used with hintshardingstrategy.
back-end
Permission design
- The user logs in to get the token and store it to the local (adminlogin)
- The user sends a token to obtain the user information and permission information and store it in the store. Since F5 will cause the store to be lost, an interceptor is added to the front-end request. If there is no user information and permission information, the user information and permission will be obtained again (getadmininfo)
- The user’s rights, not roles, are returned here. The user dynamically generates the front-end route
Asyncroutes is a dynamically generated permission. If the user’s permission corresponds to the route’s permission, it will be displayed;
Project structure
- Common: data operation, data cache, transaction operation
- Admin is only a controller, which is used to process the forwarding between user requests and background business. Why is this design Because some middleware systems need to use RPC framework for request forwarding, because some secret systems disdain spring MVC and choose vertx to develop request layer independently.
Maven uses BOM management
useMaven inheritanceManage project dependencies. ModulesdependencyManagementWhen a dependency is introduced and a version is specified, the subproject inherits modules. When importing a dependency, it is not necessary to specify a version
Logging
Global log processing
User action log
User operation log, using the method of annotation. If this method needs to log operations, just add it above the method name@OperateLogAnnotation is enough.
@OperateLog
@Apioperation (value = log out, notes = log out)
@GetMapping(Route.Admin.adminLogout)
public ResponseDate adminLogout(HttpServletRequest httpServletRequest) {
AdminInfoDTO adminInfoDTO = AdminTool.getAdminUser(httpServletRequest);
AdminUser adminUser = adminUserMapper.selectByPrimaryKey(adminInfoDTO.getAdminUk());
adminUser.setNowToken("log-out");
int result = adminUserService.updateAdminToken(adminUser);
return ResponseDate.builder()
.success(result == 1)
.build();
}