Commit 36121f3e by giaogiao

短信验证码; shiro获取当前用户id; 增加app注册登陆

parent 57fea55b
<p align="center"> # 卓美亚航空 - 后端项目
<a href="https://github.com/geekidea/spring-boot-plus">
<img alt="spring-boot-plus logo" src="https://springboot.plus/img/logo.png">
</a>
</p>
<p align="center">
Everyone can develop projects independently, quickly and efficiently!
</p>
<p align="center">
<a href="https://github.com/geekidea/spring-boot-plus/">
<img alt="spring-boot-plus version" src="https://img.shields.io/badge/spring--boot--plus-2.0-blue">
</a>
<a href="https://github.com/spring-projects/spring-boot">
<img alt="spring boot version" src="https://img.shields.io/badge/spring%20boot-2.2.5.RELEASE-brightgreen">
</a>
<a href="https://www.apache.org/licenses/LICENSE-2.0">
<img alt="code style" src="https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?style=flat-square">
</a>
</p>
### spring-boot-plus是一套集成spring boot常用开发组件的后台快速开发框架
> Spring-Boot-Plus是易于使用,快速,高效,功能丰富,开源的spring boot 脚手架.
> 前后端分离,专注于后端服务
## 目标
> 每个人都可以独立、快速、高效地开发项目!
#### [GITHUB](https://github.com/geekidea/spring-boot-plus) | [GITEE](https://gitee.com/geekidea/spring-boot-plus)
#### [springboot.plus](http://springboot.plus)
### 主要特性
- 集成spring boot 常用开发组件集、公共配置、AOP日志等
- Maven多模块架构
- 集成mybatis plus快速dao操作
- 快速生成后台代码: entity/param/vo/controller/service/mapper/xml
- 集成Swagger/Knife4j,可自动生成api文档
- 集成jwt、shiro权限控制
- 集成Redis缓存
- 集成HikariCP连接池,JDBC性能和慢查询检测
- 集成spring boot admin,实时检测项目运行情况
- 使用assembly maven插件进行不同环境打包部署,包含启动、重启命令,配置文件提取到外部config目录
## [V2.0视频介绍](https://www.bilibili.com/video/BV16A41187XE/)
<p align="center">
<a href="https://www.bilibili.com/video/BV16A41187XE/">
<img alt="spring-boot-plus videos" src="https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/videos-acfun-ui.png">
</a>
</p>
## 框架介绍
> 本项目使用第三方开源脚手架项目: spring-boot-plus 参考:README-zh.md
---
## 项目结构 ## 项目结构
```text ```text
└── spring-boot-plus └── spring-boot-plus
...@@ -64,405 +18,121 @@ ...@@ -64,405 +18,121 @@
└── api-system 平台管理系统api模块 └── api-system 平台管理系统api模块
└── api-app app的api模块 └── api-app app的api模块
└── api-merchant 商家api服务模块 └── api-merchant 商家api服务模块
└── common 通用模块 └── common 通用模块(包含service dao mapper)
``` ```
---
## 安装中间件
redis(必须本地开启)
### 项目环境 mysql5.7 (你本地可以不开,在本地配置中已经连上了测试环境)
中间件 | 版本 | 备注
-|-|-
JDK | 1.8+ | JDK1.8及以上 |
MySQL | 5.7+ | 5.7及以上 |
Redis | 3.2+ | |
### 技术选型
技术 | 版本 | 备注
-|-|-
Spring Boot | 2.2.0.RELEASE | 最新发布稳定版 |
Spring Framework | 5.2.0.RELEASE | 最新发布稳定版 |
Spring Boot Admin| 2.2.2 | 管理和监控SpringBoot应用程序 |
Mybatis | 3.5.3 | 持久层框架 |
Mybatis Plus | 3.3.1 | mybatis增强框架 |
HikariCP | 3.4.2 | 数据源 |
Fastjson | 1.2.67 | JSON处理工具集 |
Swagger2 | 2.9.2 | api文档生成工具 |
Knife4j | 2.0.2 | api文档生成工具 |
commons-lang3 | 3.9 | 常用工具包 |
commons-io | 2.6 | IO工具包 |
commons-codec | 1.14 | 加密解密等工具包 |
commons-collections4 | 4.4 | 集合工具包 |
reflections | 0.9.9 | 反射工具包 |
hibernate-validator | 6.0.18.Final | 后台参数校验注解 |
Shiro | 1.5.1 | 权限控制 |
JWT | 3.10.1 | JSON WEB TOKEN |
hutool-all | 5.2.4 | 常用工具集 |
lombok | 1.18.12 | 注解生成Java Bean等工具 |
mapstruct | 1.3.1.Final | 对象属性复制工具 |
### 项目链路图
![项目调用链路图](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/spring-boot-plus-link-diagram.jpg)
### [CHANGELOG](https://github.com/geekidea/spring-boot-plus/blob/master/CHANGELOG.md)
## 快速开始
### 克隆 spring-boot-plus
```bash
git clone https://gitee.com/geekidea/spring-boot-plus.git
cd spring-boot-plus
```
### Maven 构建
> 默认使用dev环境,对应配置文件:application-dev.yml
```bash ---
mvn clean package -Pdev
```
## 开发规范
### 关于模块
api-system api-app api-merchant
## 5分钟完成增删改查 三个模块是各自针对不同后端模块的api接口,都包含common模块的依赖,
### 1. 创建数据库表
```sql
-- ----------------------------
-- Table structure for foo_bar
-- ----------------------------
DROP TABLE IF EXISTS `foo_bar`;
CREATE TABLE `foo_bar`
(
`id` bigint(20) NOT NULL COMMENT '主键',
`name` varchar(20) NOT NULL COMMENT '名称',
`foo` varchar(20) DEFAULT NULL COMMENT 'Foo',
`bar` varchar(20) NOT NULL COMMENT 'Bar',
`remark` varchar(200) DEFAULT NULL COMMENT '备注',
`state` int(11) NOT NULL DEFAULT '1' COMMENT '状态,0:禁用,1:启用',
`version` int(11) NOT NULL DEFAULT '0' COMMENT '版本',
`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NULL DEFAULT NULL COMMENT '修改时间',
PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci COMMENT ='FooBar';
-- ----------------------------
-- Records of foo_bar
-- ----------------------------
INSERT INTO foo_bar (id, name, foo, bar, remark, state, version, create_time, update_time)
VALUES (1, 'FooBar', 'foo', 'bar', 'remark...', 1, 0, '2019-11-01 14:05:14', null);
INSERT INTO foo_bar (id, name, foo, bar, remark, state, version, create_time, update_time)
VALUES (2, 'HelloWorld', 'hello', 'world', null, 1, 0, '2019-11-01 14:05:14', null);
``` 你只能在其中开发模块属于自己的controller和service,
并且可以实现当前模块的service业务逻辑层,但对数据库操作,请一定调用common模块的service,不要在api-XXX的模块下写数据库的操作.
### 2.使用代码生成器生成增删改查代码 如果业务流程没有很复杂, 在controller类中你可以直接调用common模块的service
> 代码生成入口类,在generator模块中
```text ### 例如:
spring-boot-plus/generator/src/main/java/io/geekidea/springbootplus/generator/SpringBootPlusGenerator.java #### 商户注册
``` 在api-merchant模块中的controller包下新建一个Register控制器,
```java
/**
* spring-boot-plus代码生成器入口类
*
* @author geekidea
* @date 2019-10-22
**/
@Component
public class SpringBootPlusGenerator {
/**
* 生成代码
* @param args
*/
public static void main(String[] args) {
GeneratorProperties generatorProperties = new GeneratorProperties();
// 设置基本信息
generatorProperties
.setMavenModuleName("example")
.setParentPackage("com.example")
.setModuleName("foobar")
.setAuthor("geekidea")
.setFileOverride(true);
// 设置表信息
generatorProperties.addTable("foo_bar","id");
// 数据源配置
generatorProperties.getDataSourceConfig()
.setDbType(DbType.MYSQL)
.setUsername("root")
.setPassword("root")
.setDriverName("com.mysql.jdbc.Driver")
.setUrl("jdbc:mysql://localhost:3306/spring_boot_plus?useUnicode=true&characterEncoding=UTF-8&useSSL=false");
// 生成配置
generatorProperties.getGeneratorConfig()
.setGeneratorStrategy(GeneratorStrategy.SINGLE)
.setGeneratorEntity(true)
.setGeneratorController(true)
.setGeneratorService(true)
.setGeneratorServiceImpl(true)
.setGeneratorMapper(true)
.setGeneratorMapperXml(true)
.setGeneratorPageParam(true)
.setGeneratorQueryVo(true)
.setRequiresPermissions(true)
.setPageListOrder(true)
.setParamValidation(true)
.setSwaggerTags(true)
.setOperationLog(true);
// 全局配置
generatorProperties.getMybatisPlusGeneratorConfig().getGlobalConfig()
.setOpen(true)
.setSwagger2(true)
.setIdType(IdType.AUTO)
.setDateType(DateType.ONLY_DATE);
// 策略配置
generatorProperties.getMybatisPlusGeneratorConfig().getStrategyConfig()
.setNaming(NamingStrategy.underline_to_camel)
.setColumnNaming(NamingStrategy.underline_to_camel)
.setEntityLombokModel(true)
.setRestControllerStyle(true)
.setControllerMappingHyphenStyle(true)
.setVersionFieldName(GeneratorConstant.VERSION)
.setLogicDeleteFieldName(GeneratorConstant.DELETED);
// 生成代码
CodeGenerator codeGenerator = new CodeGenerator();
codeGenerator.generator(generatorProperties);
}
}
```
#### Code Generator Templates 模块下每个控制器url路径必须要加上前缀```"/merchant/"```,这样为了方便权限控制
> 使用Velocity模版生成代码,可自定义修改代码生成模版
```text 像这样:
spring-boot-plus/generator/src/main/resources
``` ```
@RequestMapping("/merchant/register/")
```text
└── templates
├── controller.java.vm 控制器代码生成模版
├── entity.java.vm 实体类代码生成模版
├── mapper.java.vm mapper代码生成模版
├── mapper.xml.vm mapper xml 代码生成模版
├── pageParam.java.vm 分页参数代码生成模版
├── queryVo.java.vm 查询结果代码生成模版
├── service.java.vm 服务接口代码生成模版
└── serviceImpl.java.vm 服务实现代码生成模版
``` ```
#### 生成的代码结构 注册业务逻辑要调用common模块中的service去操作
```text
└── src
└── main
├── java
│   └── com
│   └── example
│   └── foobar
│   ├── controller
│   │   └── FooBarController.java
│   ├── entity
│   │   └── FooBar.java
│   ├── mapper
│   │   └── FooBarMapper.java
│   ├── param
│   │   └── FooBarPageParam.java
│   ├── service
│   │   ├── FooBarService.java
│   │   └── impl
│   │   └── FooBarServiceImpl.java
│   └── vo
│   └── FooBarQueryVo.java
└── resources
└── mapper
└── foobar
└── FooBarMapper.xml
```
### 3. 启动SpringBootAdmin #### app注册
> SpringBootAdmin Server启动类,在admin模块中 [http://localhost:8000](http://localhost:8000) 在api-app模块中的controller包下新建一个Register控制器,
```text
spring-boot-plus/admin/src/main/java/io/geekidea/springbootplus/admin/SpringBootPlusAdminApplication
```
```java 模块下每个控制器url路径必须要加上前缀```"/app/"```,这样为了方便权限控制
/**
* Spring Boot Admin Bootstrap Main Class
*
* @author geekidea
* @date 2020/3/20
**/
@Slf4j
@Configuration
@EnableAutoConfiguration
@EnableAdminServer
@SpringBootApplication
public class SpringBootPlusAdminApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(SpringBootPlusAdminApplication.class, args);
ConfigurableEnvironment environment = context.getEnvironment();
String serverPort = environment.getProperty("server.port");
log.info("SpringBootAdmin: http://localhost:" + serverPort);
}
} 像这样:
``` ```
@RequestMapping("/app/register/")
### 4. 启动项目
> 项目入口类,在bootstrap模块中 [http://localhost:8888](http://localhost:8888)
```text
spring-boot-plus/bootstrap/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java
``` ```
```java 注册业务逻辑要调用common模块中的service去操作
/**
* spring-boot-plus 项目启动入口
*
* @author geekidea
* @since 2018-11-08
*/
@EnableAsync
@EnableScheduling
@EnableTransactionManagement
@EnableConfigurationProperties
@ServletComponentScan
@MapperScan({"io.geekidea.springbootplus.**.mapper", "com.example.**.mapper"})
@SpringBootApplication(scanBasePackages = {"io.geekidea.springbootplus", "com.example"})
public class SpringBootPlusApplication {
public static void main(String[] args) {
// 启动spring-boot-plus
ConfigurableApplicationContext context = SpringApplication.run(SpringBootPlusApplication.class, args);
// 打印项目信息
PrintApplicationInfo.print(context);
// 打印项目提示
PrintApplicationInfo.printTip(context);
}
}
```
### 5. 访问项目Swagger文档 ---
[http://47.105.159.10:8888/api/swagger-ui.html](http://47.105.159.10:8888/api/swagger-ui.html) ### 数据库规范
![swagger-ui.png](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/swagger-ui.png) - 主键id使用自增ID
![swagger-ui-1.png](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/swagger-ui-1.png) - 时间类型使用时间戳timestamp
### 6. 访问Knife4j文档
[http://47.105.159.10:8888/api/doc.html](http://47.105.159.10:8888/api/doc.html)
![knife4j.png](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/knife4j.png)
![knife4j-1.png](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/knife4j-1.png)
## CentOS快速安装环境/构建/部署/启动spring-boot-plus项目 ---
### 1. 下载安装脚本 ### 分支管理
> 安装 `jdk`, `git`, `maven`, `redis`, `mysql`
```bash > 请看此文章:https://www.jianshu.com/p/780aa5c4c7fe
wget -O download-install-all.sh https://springboot.plus/bin/download-install-all.sh
```
### 2. 运行安装脚本 ---
```bash ## swagger文档
sh download-install-all.sh http://127.0.0.1:8889/api/doc.html#/home
```
### 3. 修改MySQL密码 左上角可以切换到不同的模块
```bash
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Springbootplus666!';
exit
mysql -uroot -pSpringbootplus666!
```
### 4. 导入MySQL脚本 ---
```bash
create database if not exists spring_boot_plus character set utf8mb4;
use spring_boot_plus;
source /root/Jumeirah.sql;
show tables;
exit
```
### 5. 下载部署脚本 `deploy.sh` ## 配置接口权限
```bash *例如:*
wget -O deploy.sh https://springboot.plus/bin/deploy.sh
``` ```
/**
### 6. 执行脚本 * 获取获取菜单树形列表
```bash */
sh deploy.sh @PostMapping("/getAllMenuTree")
@RequiresPermissions("sys:permission:all:menu:tree")
public ApiResult<List<SysPermissionTreeVo>> getAllMenuTree() throws Exception {
List<SysPermissionTreeVo> treeVos = sysPermissionService.getAllMenuTree();
return ApiResult.ok(treeVos);
}
``` ```
### 7. 查看项目运行日志 >其中注解@RequiresPermissions表示访问此接口需要的权限,
```bash 权限可以在数据库表中先分配给角色, 再将角色与用户进行关联
tail -f -n 1000 /spring-boot-plus-server-2.0/logs/spring-boot-plus.log
``` **系统平台权限相关表:**
系统角色sys_role,
## spring-boot-plus Views 系统用户sys_user,
### spring-boot-plus IDEA Sources Views 系统权限sys_permission,
![spring-boot-plus-idea](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/idea.png) 角色权限关系sys_role_permission
### [Spring Boot Admin Instances](http://47.105.159.10:8000/instances/11090f218c47/details) ---
<p> ## shiro理论知识
<a href="http://47.105.159.10:8000/instances/11090f218c47/details">
<img src="https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/springbootadmin.png" alt="spring-boot-admin instances">
</a>
</p>
### [Spring Boot Admin Statistics](http://47.105.159.10:8000/instances/11090f218c47/details) Subject(主体): 用于记录当前的操作用户,Subject在shiro中是一个接口,接口中定义了很多认证授相关的方法,外部程序通过subject进行认证授权,而subject是通过SecurityManager安全管理器进行认证授权
<p>
<a href="http://47.105.159.10:8000/instances/11090f218c47/details">
<img src="https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/springbootadmin1.png" alt="spring-boot-admin statistics">
</a>
</p>
### [Spring Boot Admin Log](http://47.105.159.10:8000/instances/11090f218c47/logfile) SecurityManager(安全管理器):对Subject 进行管理,他是shiro的核心SecurityManager是一个接口,继承了Authenticator, Authorizer, SessionManager这三个接口。
<p>
<a href="http://47.105.159.10:8000/instances/11090f218c47/logfile">
<img src="https://spring-boot-plus.gitee.io/img/home/spring-boot-admin-log.png" alt="spring-boot-admin log">
</a>
</p>
## spring-boot-plus-vue 前端项目 Authenticator(认证器):对用户身份进行认证
### [GITHUB-REPO](https://github.com/geekidea/spring-boot-plus-vue)
### [VUE演示地址](http://47.105.159.10/)
#### VUE主页
![VUE主页](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/springbootplusvue.png)
#### 系统用户列表
![系统用户列表](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/springbootplusvue-1.png)
#### 系统角色列表
![系统角色模块](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/springbootplusvue-2.png)
#### 系统菜单列表
![系统菜单列表](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/springbootplusvue-3.png)
## spring-boot-plus 视频 :movie_camera: Authorizer(授权器):用户通过认证后,来判断时候拥有该权限
- [V2.x 视频介绍慢放版](https://www.bilibili.com/video/BV1HQ4y1M73i/)
- [V1.x 5分钟完成增删改查](https://www.bilibili.com/video/av67401204)
- [CentOS 快速安装 JDK/Git/Maven/Redis/MySQL](https://www.bilibili.com/video/av67218836/)
- [CentOS 快速部署/构建/打包/运行项目](https://www.bilibili.com/video/av67218970/)
realm:获取用户权限数据
## 联系 sessionManager(会话管理):shiro框架定义了一套会话管理,它不依赖web容器的session,所以shiro可以使用在非web应用上,也可以将分布式应用的会话集中在一点管理,此特性可使它实现单点登录。
QQ 625301326| 微信公众号 geekideaio| 今日头条 GeekIdea
-|-|-
![spring-boot-plus QQ Group](https://spring-boot-plus.gitee.io/img/spring-boot-plus-qq-group.png) | ![Wechat Official Account](https://geekidea.oss-cn-chengdu.aliyuncs.com/geekidea/geekidea-wechat-official.jpg) | ![toutiao](https://geekidea.oss-cn-chengdu.aliyuncs.com/geekidea/geekidea-toutiao.jpeg) |
## 赞赏 CacheManager(缓存管理器):将用户权限数据存储在缓存,这样可以提高性能。
请作者喝咖啡,让代码飞一会儿!
![geekidea-wechat-donate](https://geekidea.oss-cn-chengdu.aliyuncs.com/geekidea/geekidea-wechat-donate.jpeg) authc:所有url都必须认证通过才可以访问;
## License anon:所有url都都可以匿名访问;
spring-boot-plus is under the Apache 2.0 license. See the [LICENSE](https://github.com/geekidea/spring-boot-plus/blob/master/LICENSE) file for details.
过滤链定义,从上向下顺序执行,一般将/**放在最为下边
\ No newline at end of file
# 卓美亚航空 - 后端项目 <p align="center">
<a href="https://github.com/geekidea/spring-boot-plus">
<img alt="spring-boot-plus logo" src="https://springboot.plus/img/logo.png">
</a>
</p>
<p align="center">
Everyone can develop projects independently, quickly and efficiently!
</p>
<p align="center">
<a href="https://github.com/geekidea/spring-boot-plus/">
<img alt="spring-boot-plus version" src="https://img.shields.io/badge/spring--boot--plus-2.0-blue">
</a>
<a href="https://github.com/spring-projects/spring-boot">
<img alt="spring boot version" src="https://img.shields.io/badge/spring%20boot-2.2.5.RELEASE-brightgreen">
</a>
<a href="https://www.apache.org/licenses/LICENSE-2.0">
<img alt="code style" src="https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?style=flat-square">
</a>
</p>
### spring-boot-plus是一套集成spring boot常用开发组件的后台快速开发框架
> Spring-Boot-Plus是易于使用,快速,高效,功能丰富,开源的spring boot 脚手架.
> 前后端分离,专注于后端服务
## 目标
> 每个人都可以独立、快速、高效地开发项目!
#### [GITHUB](https://github.com/geekidea/spring-boot-plus) | [GITEE](https://gitee.com/geekidea/spring-boot-plus)
#### [springboot.plus](http://springboot.plus)
### 主要特性
- 集成spring boot 常用开发组件集、公共配置、AOP日志等
- Maven多模块架构
- 集成mybatis plus快速dao操作
- 快速生成后台代码: entity/param/vo/controller/service/mapper/xml
- 集成Swagger/Knife4j,可自动生成api文档
- 集成jwt、shiro权限控制
- 集成Redis缓存
- 集成HikariCP连接池,JDBC性能和慢查询检测
- 集成spring boot admin,实时检测项目运行情况
- 使用assembly maven插件进行不同环境打包部署,包含启动、重启命令,配置文件提取到外部config目录
## [V2.0视频介绍](https://www.bilibili.com/video/BV16A41187XE/)
<p align="center">
<a href="https://www.bilibili.com/video/BV16A41187XE/">
<img alt="spring-boot-plus videos" src="https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/videos-acfun-ui.png">
</a>
</p>
## 框架介绍
> 本项目使用第三方开源脚手架项目: spring-boot-plus 参考:README-zh.md
---
## 项目结构 ## 项目结构
```text ```text
└── spring-boot-plus └── spring-boot-plus
...@@ -18,115 +64,405 @@ ...@@ -18,115 +64,405 @@
└── api-system 平台管理系统api模块 └── api-system 平台管理系统api模块
└── api-app app的api模块 └── api-app app的api模块
└── api-merchant 商家api服务模块 └── api-merchant 商家api服务模块
└── common 通用模块(包含service dao mapper) └── common 通用模块
``` ```
---
## 安装中间件
redis(必须本地开启)
mysql5.7 (你本地可以不开,在本地配置中已经连上了测试环境) ### 项目环境
中间件 | 版本 | 备注
-|-|-
JDK | 1.8+ | JDK1.8及以上 |
MySQL | 5.7+ | 5.7及以上 |
Redis | 3.2+ | |
### 技术选型
技术 | 版本 | 备注
-|-|-
Spring Boot | 2.2.0.RELEASE | 最新发布稳定版 |
Spring Framework | 5.2.0.RELEASE | 最新发布稳定版 |
Spring Boot Admin| 2.2.2 | 管理和监控SpringBoot应用程序 |
Mybatis | 3.5.3 | 持久层框架 |
Mybatis Plus | 3.3.1 | mybatis增强框架 |
HikariCP | 3.4.2 | 数据源 |
Fastjson | 1.2.67 | JSON处理工具集 |
Swagger2 | 2.9.2 | api文档生成工具 |
Knife4j | 2.0.2 | api文档生成工具 |
commons-lang3 | 3.9 | 常用工具包 |
commons-io | 2.6 | IO工具包 |
commons-codec | 1.14 | 加密解密等工具包 |
commons-collections4 | 4.4 | 集合工具包 |
reflections | 0.9.9 | 反射工具包 |
hibernate-validator | 6.0.18.Final | 后台参数校验注解 |
Shiro | 1.5.1 | 权限控制 |
JWT | 3.10.1 | JSON WEB TOKEN |
hutool-all | 5.2.4 | 常用工具集 |
lombok | 1.18.12 | 注解生成Java Bean等工具 |
mapstruct | 1.3.1.Final | 对象属性复制工具 |
### 项目链路图
![项目调用链路图](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/spring-boot-plus-link-diagram.jpg)
### [CHANGELOG](https://github.com/geekidea/spring-boot-plus/blob/master/CHANGELOG.md)
## 快速开始
### 克隆 spring-boot-plus
```bash
git clone https://gitee.com/geekidea/spring-boot-plus.git
cd spring-boot-plus
```
### Maven 构建
> 默认使用dev环境,对应配置文件:application-dev.yml
```bash
mvn clean package -Pdev
```
## 5分钟完成增删改查
### 1. 创建数据库表
```sql
-- ----------------------------
-- Table structure for foo_bar
-- ----------------------------
DROP TABLE IF EXISTS `foo_bar`;
CREATE TABLE `foo_bar`
(
`id` bigint(20) NOT NULL COMMENT '主键',
`name` varchar(20) NOT NULL COMMENT '名称',
`foo` varchar(20) DEFAULT NULL COMMENT 'Foo',
`bar` varchar(20) NOT NULL COMMENT 'Bar',
`remark` varchar(200) DEFAULT NULL COMMENT '备注',
`state` int(11) NOT NULL DEFAULT '1' COMMENT '状态,0:禁用,1:启用',
`version` int(11) NOT NULL DEFAULT '0' COMMENT '版本',
`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NULL DEFAULT NULL COMMENT '修改时间',
PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci COMMENT ='FooBar';
-- ----------------------------
-- Records of foo_bar
-- ----------------------------
INSERT INTO foo_bar (id, name, foo, bar, remark, state, version, create_time, update_time)
VALUES (1, 'FooBar', 'foo', 'bar', 'remark...', 1, 0, '2019-11-01 14:05:14', null);
INSERT INTO foo_bar (id, name, foo, bar, remark, state, version, create_time, update_time)
VALUES (2, 'HelloWorld', 'hello', 'world', null, 1, 0, '2019-11-01 14:05:14', null);
## 开发规范 ```
---
### 关于模块
api-system api-app api-merchant
三个模块是各自针对不同后端模块的api接口,都包含common模块的依赖,
你只能在其中开发模块属于自己的controller和service, ### 2.使用代码生成器生成增删改查代码
> 代码生成入口类,在generator模块中
并且可以实现当前模块的service业务逻辑层,但对数据库操作,请一定调用common模块的service,不要在api-XXX的模块下写数据库的操作. ```text
spring-boot-plus/generator/src/main/java/io/geekidea/springbootplus/generator/SpringBootPlusGenerator.java
```
如果业务流程没有很复杂, 在controller类中你可以直接调用common模块的service ```java
/**
* spring-boot-plus代码生成器入口类
*
* @author geekidea
* @date 2019-10-22
**/
@Component
public class SpringBootPlusGenerator {
/**
* 生成代码
* @param args
*/
public static void main(String[] args) {
GeneratorProperties generatorProperties = new GeneratorProperties();
// 设置基本信息
generatorProperties
.setMavenModuleName("example")
.setParentPackage("com.example")
.setModuleName("foobar")
.setAuthor("geekidea")
.setFileOverride(true);
// 设置表信息
generatorProperties.addTable("foo_bar","id");
// 数据源配置
generatorProperties.getDataSourceConfig()
.setDbType(DbType.MYSQL)
.setUsername("root")
.setPassword("root")
.setDriverName("com.mysql.jdbc.Driver")
.setUrl("jdbc:mysql://localhost:3306/spring_boot_plus?useUnicode=true&characterEncoding=UTF-8&useSSL=false");
// 生成配置
generatorProperties.getGeneratorConfig()
.setGeneratorStrategy(GeneratorStrategy.SINGLE)
.setGeneratorEntity(true)
.setGeneratorController(true)
.setGeneratorService(true)
.setGeneratorServiceImpl(true)
.setGeneratorMapper(true)
.setGeneratorMapperXml(true)
.setGeneratorPageParam(true)
.setGeneratorQueryVo(true)
.setRequiresPermissions(true)
.setPageListOrder(true)
.setParamValidation(true)
.setSwaggerTags(true)
.setOperationLog(true);
// 全局配置
generatorProperties.getMybatisPlusGeneratorConfig().getGlobalConfig()
.setOpen(true)
.setSwagger2(true)
.setIdType(IdType.AUTO)
.setDateType(DateType.ONLY_DATE);
// 策略配置
generatorProperties.getMybatisPlusGeneratorConfig().getStrategyConfig()
.setNaming(NamingStrategy.underline_to_camel)
.setColumnNaming(NamingStrategy.underline_to_camel)
.setEntityLombokModel(true)
.setRestControllerStyle(true)
.setControllerMappingHyphenStyle(true)
.setVersionFieldName(GeneratorConstant.VERSION)
.setLogicDeleteFieldName(GeneratorConstant.DELETED);
// 生成代码
CodeGenerator codeGenerator = new CodeGenerator();
codeGenerator.generator(generatorProperties);
}
}
```
### 例如: #### Code Generator Templates
#### 商户注册 > 使用Velocity模版生成代码,可自定义修改代码生成模版
在api-merchant模块中的controller包下新建一个Register控制器,
模块下每个控制器url路径必须要加上前缀```"/merchant/"```,这样为了方便权限控制 ```text
spring-boot-plus/generator/src/main/resources
```
像这样: ```text
└── templates
├── controller.java.vm 控制器代码生成模版
├── entity.java.vm 实体类代码生成模版
├── mapper.java.vm mapper代码生成模版
├── mapper.xml.vm mapper xml 代码生成模版
├── pageParam.java.vm 分页参数代码生成模版
├── queryVo.java.vm 查询结果代码生成模版
├── service.java.vm 服务接口代码生成模版
└── serviceImpl.java.vm 服务实现代码生成模版
``` ```
@RequestMapping("/merchant/register/")
#### 生成的代码结构
```text
└── src
└── main
├── java
│   └── com
│   └── example
│   └── foobar
│   ├── controller
│   │   └── FooBarController.java
│   ├── entity
│   │   └── FooBar.java
│   ├── mapper
│   │   └── FooBarMapper.java
│   ├── param
│   │   └── FooBarPageParam.java
│   ├── service
│   │   ├── FooBarService.java
│   │   └── impl
│   │   └── FooBarServiceImpl.java
│   └── vo
│   └── FooBarQueryVo.java
└── resources
└── mapper
└── foobar
└── FooBarMapper.xml
``` ```
注册业务逻辑要调用common模块中的service去操作 ### 3. 启动SpringBootAdmin
> SpringBootAdmin Server启动类,在admin模块中 [http://localhost:8000](http://localhost:8000)
```text
spring-boot-plus/admin/src/main/java/io/geekidea/springbootplus/admin/SpringBootPlusAdminApplication
```
#### app注册 ```java
在api-app模块中的controller包下新建一个Register控制器, /**
* Spring Boot Admin Bootstrap Main Class
*
* @author geekidea
* @date 2020/3/20
**/
@Slf4j
@Configuration
@EnableAutoConfiguration
@EnableAdminServer
@SpringBootApplication
public class SpringBootPlusAdminApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(SpringBootPlusAdminApplication.class, args);
ConfigurableEnvironment environment = context.getEnvironment();
String serverPort = environment.getProperty("server.port");
log.info("SpringBootAdmin: http://localhost:" + serverPort);
}
模块下每个控制器url路径必须要加上前缀```"/app/"```,这样为了方便权限控制 }
```
像这样: ### 4. 启动项目
> 项目入口类,在bootstrap模块中 [http://localhost:8888](http://localhost:8888)
```text
spring-boot-plus/bootstrap/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java
``` ```
@RequestMapping("/app/register/")
```java
/**
* spring-boot-plus 项目启动入口
*
* @author geekidea
* @since 2018-11-08
*/
@EnableAsync
@EnableScheduling
@EnableTransactionManagement
@EnableConfigurationProperties
@ServletComponentScan
@MapperScan({"io.geekidea.springbootplus.**.mapper", "com.example.**.mapper"})
@SpringBootApplication(scanBasePackages = {"io.geekidea.springbootplus", "com.example"})
public class SpringBootPlusApplication {
public static void main(String[] args) {
// 启动spring-boot-plus
ConfigurableApplicationContext context = SpringApplication.run(SpringBootPlusApplication.class, args);
// 打印项目信息
PrintApplicationInfo.print(context);
// 打印项目提示
PrintApplicationInfo.printTip(context);
}
}
``` ```
注册业务逻辑要调用common模块中的service去操作 ### 5. 访问项目Swagger文档
[http://47.105.159.10:8888/api/swagger-ui.html](http://47.105.159.10:8888/api/swagger-ui.html)
![swagger-ui.png](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/swagger-ui.png)
![swagger-ui-1.png](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/swagger-ui-1.png)
--- ### 6. 访问Knife4j文档
## swagger文档 [http://47.105.159.10:8888/api/doc.html](http://47.105.159.10:8888/api/doc.html)
http://127.0.0.1:8889/api/doc.html#/home ![knife4j.png](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/knife4j.png)
![knife4j-1.png](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/knife4j-1.png)
左上角可以切换到不同的模块 ## CentOS快速安装环境/构建/部署/启动spring-boot-plus项目
### 1. 下载安装脚本
> 安装 `jdk`, `git`, `maven`, `redis`, `mysql`
--- ```bash
wget -O download-install-all.sh https://springboot.plus/bin/download-install-all.sh
```
## 配置接口权限 ### 2. 运行安装脚本
*例如:* ```bash
sh download-install-all.sh
``` ```
### 3. 修改MySQL密码
```bash
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Springbootplus666!';
exit
mysql -uroot -pSpringbootplus666!
```
/** ### 4. 导入MySQL脚本
* 获取获取菜单树形列表 ```bash
* create database if not exists spring_boot_plus character set utf8mb4;
* @return use spring_boot_plus;
*/ source /root/Jumeirah.sql;
@PostMapping("/getAllMenuTree") show tables;
@RequiresPermissions("sys:permission:all:menu:tree") exit
public ApiResult<List<SysPermissionTreeVo>> getAllMenuTree() throws Exception {
List<SysPermissionTreeVo> treeVos = sysPermissionService.getAllMenuTree();
return ApiResult.ok(treeVos);
}
``` ```
>其中注解@RequiresPermissions表示访问此接口需要的权限, ### 5. 下载部署脚本 `deploy.sh`
权限可以在数据库表中先分配给角色, 再将角色与用户进行关联 ```bash
wget -O deploy.sh https://springboot.plus/bin/deploy.sh
```
### 6. 执行脚本
```bash
sh deploy.sh
```
**系统平台权限相关表:** ### 7. 查看项目运行日志
```bash
tail -f -n 1000 /spring-boot-plus-server-2.0/logs/spring-boot-plus.log
```
系统角色sys_role,
系统用户sys_user, ## spring-boot-plus Views
系统权限sys_permission, ### spring-boot-plus IDEA Sources Views
角色权限关系sys_role_permission ![spring-boot-plus-idea](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/idea.png)
--- ### [Spring Boot Admin Instances](http://47.105.159.10:8000/instances/11090f218c47/details)
## shiro理论知识 <p>
<a href="http://47.105.159.10:8000/instances/11090f218c47/details">
<img src="https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/springbootadmin.png" alt="spring-boot-admin instances">
</a>
</p>
Subject(主体): 用于记录当前的操作用户,Subject在shiro中是一个接口,接口中定义了很多认证授相关的方法,外部程序通过subject进行认证授权,而subject是通过SecurityManager安全管理器进行认证授权 ### [Spring Boot Admin Statistics](http://47.105.159.10:8000/instances/11090f218c47/details)
<p>
<a href="http://47.105.159.10:8000/instances/11090f218c47/details">
<img src="https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/springbootadmin1.png" alt="spring-boot-admin statistics">
</a>
</p>
SecurityManager(安全管理器):对Subject 进行管理,他是shiro的核心SecurityManager是一个接口,继承了Authenticator, Authorizer, SessionManager这三个接口。 ### [Spring Boot Admin Log](http://47.105.159.10:8000/instances/11090f218c47/logfile)
<p>
<a href="http://47.105.159.10:8000/instances/11090f218c47/logfile">
<img src="https://spring-boot-plus.gitee.io/img/home/spring-boot-admin-log.png" alt="spring-boot-admin log">
</a>
</p>
Authenticator(认证器):对用户身份进行认证 ## spring-boot-plus-vue 前端项目
### [GITHUB-REPO](https://github.com/geekidea/spring-boot-plus-vue)
### [VUE演示地址](http://47.105.159.10/)
#### VUE主页
![VUE主页](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/springbootplusvue.png)
#### 系统用户列表
![系统用户列表](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/springbootplusvue-1.png)
#### 系统角色列表
![系统角色模块](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/springbootplusvue-2.png)
#### 系统菜单列表
![系统菜单列表](https://geekidea.oss-cn-chengdu.aliyuncs.com/spring-boot-plus/img/springbootplusvue-3.png)
Authorizer(授权器):用户通过认证后,来判断时候拥有该权限 ## spring-boot-plus 视频 :movie_camera:
- [V2.x 视频介绍慢放版](https://www.bilibili.com/video/BV1HQ4y1M73i/)
- [V1.x 5分钟完成增删改查](https://www.bilibili.com/video/av67401204)
- [CentOS 快速安装 JDK/Git/Maven/Redis/MySQL](https://www.bilibili.com/video/av67218836/)
- [CentOS 快速部署/构建/打包/运行项目](https://www.bilibili.com/video/av67218970/)
realm:获取用户权限数据
sessionManager(会话管理):shiro框架定义了一套会话管理,它不依赖web容器的session,所以shiro可以使用在非web应用上,也可以将分布式应用的会话集中在一点管理,此特性可使它实现单点登录。 ## 联系
QQ 625301326| 微信公众号 geekideaio| 今日头条 GeekIdea
-|-|-
![spring-boot-plus QQ Group](https://spring-boot-plus.gitee.io/img/spring-boot-plus-qq-group.png) | ![Wechat Official Account](https://geekidea.oss-cn-chengdu.aliyuncs.com/geekidea/geekidea-wechat-official.jpg) | ![toutiao](https://geekidea.oss-cn-chengdu.aliyuncs.com/geekidea/geekidea-toutiao.jpeg) |
CacheManager(缓存管理器):将用户权限数据存储在缓存,这样可以提高性能。 ## 赞赏
请作者喝咖啡,让代码飞一会儿!
authc:所有url都必须认证通过才可以访问; ![geekidea-wechat-donate](https://geekidea.oss-cn-chengdu.aliyuncs.com/geekidea/geekidea-wechat-donate.jpeg)
anon:所有url都都可以匿名访问; ## License
spring-boot-plus is under the Apache 2.0 license. See the [LICENSE](https://github.com/geekidea/spring-boot-plus/blob/master/LICENSE) file for details.
过滤链定义,从上向下顺序执行,一般将/**放在最为下边
\ No newline at end of file
package com.jumeirah.api.app.controller;
import com.jumeirah.api.app.service.AppSmsService;
import com.jumeirah.api.app.vo.SmsCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* APP用户 控制器
*
* @author wei
* @since 2020-09-23
*/
@Slf4j
@RestController
//@Module("api-app")
@Api(value = "短信验证码", tags = {"APP短信验证码相关"})
@RequestMapping("/app/sms/")
public class AppSmsController extends BaseController {
@Autowired
private AppSmsService appSmsService;
/**
* 获取注册验证码
*/
@GetMapping("/register")
@OperationLog(name = "获取注册验证码", type = OperationLogType.INFO)
@ApiOperation(value = "获取注册验证码", response = SmsCode.class, notes = "本地环境默认666666")
public ApiResult<SmsCode> register(@RequestParam String area, @RequestParam String number) throws Exception {
return appSmsService.registerType(area,number);
}
}
...@@ -3,21 +3,23 @@ package com.jumeirah.api.app.controller; ...@@ -3,21 +3,23 @@ package com.jumeirah.api.app.controller;
import com.jumeirah.common.entity.AppUser; import com.jumeirah.common.entity.AppUser;
import com.jumeirah.common.param.AppUserPageParam; import com.jumeirah.common.param.AppUserPageParam;
import com.jumeirah.common.param.LoginParam; import com.jumeirah.common.param.LoginParam;
import com.jumeirah.common.param.RegisterParam; import com.jumeirah.common.param.app.AppSmsRegisterParam;
import com.jumeirah.common.service.AppUserService; import com.jumeirah.common.service.AppUserService;
import com.jumeirah.common.vo.AppUserQueryVo; import com.jumeirah.common.vo.AppUserQueryVo;
import com.jumeirah.common.vo.LoginSysUserTokenVo; import com.jumeirah.common.vo.LoginSysUserTokenVo;
import com.jumeirah.common.vo.app.LoginAppUserTokenVo;
import io.geekidea.springbootplus.framework.common.api.ApiResult; import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController; import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.core.pagination.Paging; import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.validator.groups.Add; import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update; import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog; import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.annotation.OperationLogIgnore;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType; import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -28,8 +30,6 @@ import org.springframework.web.bind.annotation.RequestHeader; ...@@ -28,8 +30,6 @@ import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
/** /**
* APP用户 控制器 * APP用户 控制器
* *
...@@ -38,7 +38,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -38,7 +38,7 @@ import javax.servlet.http.HttpServletResponse;
*/ */
@Slf4j @Slf4j
@RestController @RestController
//@Module("api-app") @Module("api-app")
@Api(value = "用户API", tags = {"APP用户相关"}) @Api(value = "用户API", tags = {"APP用户相关"})
@RequestMapping("/app/user/") @RequestMapping("/app/user/")
public class AppUserController extends BaseController { public class AppUserController extends BaseController {
...@@ -52,6 +52,7 @@ public class AppUserController extends BaseController { ...@@ -52,6 +52,7 @@ public class AppUserController extends BaseController {
@PostMapping("/add") @PostMapping("/add")
@OperationLog(name = "添加APP用户", type = OperationLogType.ADD) @OperationLog(name = "添加APP用户", type = OperationLogType.ADD)
@ApiOperation(value = "添加APP用户", response = ApiResult.class) @ApiOperation(value = "添加APP用户", response = ApiResult.class)
@RequiresRoles("sys:admin")
public ApiResult<Boolean> addAppUser(@Validated(Add.class) @RequestBody AppUser appUser) throws Exception { public ApiResult<Boolean> addAppUser(@Validated(Add.class) @RequestBody AppUser appUser) throws Exception {
boolean flag = appUserService.saveAppUser(appUser); boolean flag = appUserService.saveAppUser(appUser);
return ApiResult.result(flag); return ApiResult.result(flag);
...@@ -63,6 +64,7 @@ public class AppUserController extends BaseController { ...@@ -63,6 +64,7 @@ public class AppUserController extends BaseController {
@PostMapping("/update") @PostMapping("/update")
@OperationLog(name = "修改APP用户", type = OperationLogType.UPDATE) @OperationLog(name = "修改APP用户", type = OperationLogType.UPDATE)
@ApiOperation(value = "修改APP用户", response = ApiResult.class) @ApiOperation(value = "修改APP用户", response = ApiResult.class)
@RequiresRoles("sys:admin")
public ApiResult<Boolean> updateAppUser(@Validated(Update.class) @RequestBody AppUser appUser) throws Exception { public ApiResult<Boolean> updateAppUser(@Validated(Update.class) @RequestBody AppUser appUser) throws Exception {
boolean flag = appUserService.updateAppUser(appUser); boolean flag = appUserService.updateAppUser(appUser);
return ApiResult.result(flag); return ApiResult.result(flag);
...@@ -74,6 +76,7 @@ public class AppUserController extends BaseController { ...@@ -74,6 +76,7 @@ public class AppUserController extends BaseController {
@PostMapping("/delete/{id}") @PostMapping("/delete/{id}")
@OperationLog(name = "删除APP用户", type = OperationLogType.DELETE) @OperationLog(name = "删除APP用户", type = OperationLogType.DELETE)
@ApiOperation(value = "删除APP用户", response = ApiResult.class) @ApiOperation(value = "删除APP用户", response = ApiResult.class)
@RequiresRoles("sys:admin")
public ApiResult<Boolean> deleteAppUser(@PathVariable("id") Long id) throws Exception { public ApiResult<Boolean> deleteAppUser(@PathVariable("id") Long id) throws Exception {
boolean flag = appUserService.deleteAppUser(id); boolean flag = appUserService.deleteAppUser(id);
return ApiResult.result(flag); return ApiResult.result(flag);
...@@ -85,6 +88,7 @@ public class AppUserController extends BaseController { ...@@ -85,6 +88,7 @@ public class AppUserController extends BaseController {
@GetMapping("/info/{id}") @GetMapping("/info/{id}")
@OperationLog(name = "APP用户详情", type = OperationLogType.INFO) @OperationLog(name = "APP用户详情", type = OperationLogType.INFO)
@ApiOperation(value = "APP用户详情", response = AppUserQueryVo.class) @ApiOperation(value = "APP用户详情", response = AppUserQueryVo.class)
@RequiresRoles("sys:admin")
public ApiResult<AppUserQueryVo> getAppUser(@PathVariable("id") Long id) throws Exception { public ApiResult<AppUserQueryVo> getAppUser(@PathVariable("id") Long id) throws Exception {
AppUserQueryVo appUserQueryVo = appUserService.getAppUserById(id); AppUserQueryVo appUserQueryVo = appUserService.getAppUserById(id);
return ApiResult.ok(appUserQueryVo); return ApiResult.ok(appUserQueryVo);
...@@ -96,31 +100,23 @@ public class AppUserController extends BaseController { ...@@ -96,31 +100,23 @@ public class AppUserController extends BaseController {
@PostMapping("/getPageList") @PostMapping("/getPageList")
@OperationLog(name = "APP用户分页列表", type = OperationLogType.PAGE) @OperationLog(name = "APP用户分页列表", type = OperationLogType.PAGE)
@ApiOperation(value = "APP用户分页列表", response = AppUserQueryVo.class) @ApiOperation(value = "APP用户分页列表", response = AppUserQueryVo.class)
@RequiresRoles("sys:admin")
public ApiResult<Paging<AppUserQueryVo>> getAppUserPageList(@Validated @RequestBody AppUserPageParam appUserPageParam) throws Exception { public ApiResult<Paging<AppUserQueryVo>> getAppUserPageList(@Validated @RequestBody AppUserPageParam appUserPageParam) throws Exception {
Paging<AppUserQueryVo> paging = appUserService.getAppUserPageList(appUserPageParam); Paging<AppUserQueryVo> paging = appUserService.getAppUserPageList(appUserPageParam);
return ApiResult.ok(paging); return ApiResult.ok(paging);
} }
@PostMapping("/register") @PostMapping("/register")
@OperationLogIgnore @ApiOperation(value = "手机号注册", notes = "app用户注册", response = LoginSysUserTokenVo.class)
@ApiOperation(value = "注册", notes = "web用户注册", response = LoginSysUserTokenVo.class) public ApiResult<LoginAppUserTokenVo> register(@Validated @RequestBody AppSmsRegisterParam appSmsRegisterParam, @RequestHeader(required = false) String language) throws Exception {
public ApiResult<LoginSysUserTokenVo> register(@Validated @RequestBody RegisterParam registerParam, HttpServletResponse response, @RequestHeader(required = false) String language) throws Exception { return appUserService.register(appSmsRegisterParam, language);
return appUserService.register(registerParam, language);
} }
@PostMapping("/login") @PostMapping("/login")
@OperationLogIgnore @ApiOperation(value = "手机号登陆", notes = "app用户登录", response = LoginSysUserTokenVo.class)
@ApiOperation(value = "登录", notes = "系统用户登录", response = LoginSysUserTokenVo.class) public ApiResult<LoginAppUserTokenVo> login(@Validated @RequestBody AppSmsRegisterParam loginParam, @RequestHeader(required = false) String language) throws Exception {
public ApiResult<LoginSysUserTokenVo> login(@Validated @RequestBody LoginParam loginParam, HttpServletResponse response, @RequestHeader(required = false) String language) throws Exception {
return appUserService.login(loginParam, language); return appUserService.login(loginParam, language);
} }
// @PostMapping("/phoneLogin")
// @OperationLogIgnore
// @ApiOperation(value = "手机号登陆", notes = "手机号登陆", response = LoginSysUserTokenVo.class)
// public ApiResult<LoginSysUserTokenVo> phoneLogin(@Validated @RequestBody RegisterParam registerParam, HttpServletResponse response, @RequestHeader(required = false) String language) throws Exception {
// return appUserService.register(registerParam, language);
// }
} }
package com.jumeirah.api.app.service;
import com.jumeirah.api.app.vo.SmsCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
public interface AppSmsService {
/**
* 获取注册验证码
*/
ApiResult<SmsCode> registerType(String area, String number);
}
package com.jumeirah.api.app.service.impl;
import cn.hutool.core.util.RandomUtil;
import com.jumeirah.api.app.service.AppSmsService;
import com.jumeirah.api.app.vo.SmsCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.time.Duration;
import java.util.Arrays;
@Service
@Slf4j
public class AppSmsServiceImpl implements AppSmsService {
/**
* SpringBoot获取当前环境
*/
@Value("${spring.profiles.active}")
private String profiles;
@Autowired
private RedisTemplate redisTemplate;
private static final String SMS_REGIEST = "sms:register:%s:%s";
@Override
public ApiResult<SmsCode> registerType(String area, String number) {
String randomCode = getRandomCode();
// 存入redis
long expire = 120L;
Duration expireDuration = Duration.ofSeconds(expire);
redisTemplate.opsForValue().set(String.format(SMS_REGIEST, area, number), randomCode, expireDuration);
SmsCode smsCode = new SmsCode();
smsCode.setCode(randomCode);
log.info(area + "," + number + ":" + randomCode);
// TODO 需要补充调用发送代码
return ApiResult.ok(smsCode);
}
String getRandomCode() {
// 如果为测试环境则生成默认
if (profiles.equals("dev")) {
return "666666";
} else {
return Arrays.toString(RandomUtil.randomInts(6));
}
}
}
package com.jumeirah.api.app.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class RedisSmsCode implements Serializable {
private String code;
private String area;
private String number;
}
package com.jumeirah.api.app.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class SmsCode implements Serializable {
private String code;
}
...@@ -18,7 +18,7 @@ package com.jumeirah.common.convert; ...@@ -18,7 +18,7 @@ package com.jumeirah.common.convert;
import com.jumeirah.common.entity.MerchantUser; import com.jumeirah.common.entity.MerchantUser;
import com.jumeirah.common.entity.SysUser; import com.jumeirah.common.entity.SysUser;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
...@@ -39,9 +39,9 @@ public interface SysUserConvert { ...@@ -39,9 +39,9 @@ public interface SysUserConvert {
* @param sysUser * @param sysUser
* @return * @return
*/ */
LoginSysUserVo sysUserToLoginSysUserVo(SysUser sysUser); LoginUserVo sysUserToLoginSysUserVo(SysUser sysUser);
LoginSysUserVo merchantUserToLoginSysUserVo(MerchantUser sysUser); LoginUserVo merchantUserToLoginSysUserVo(MerchantUser sysUser);
} }
/*
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jumeirah.common.param.app;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 登录参数
*
* @author geekidea
* @date 2019-05-15
**/
@Data
@ApiModel("登录参数")
public class AppLoginParam implements Serializable {
private static final long serialVersionUID = 2854217576695117356L;
private String area;
private String number;
@ApiModelProperty("验证码")
private String code;
}
/*
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jumeirah.common.param.app;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* 注册参数
*
* @author geekidea
* @date 2019-05-15
**/
@Data
@ApiModel("app手机验证码注册参数")
public class AppSmsRegisterParam implements Serializable {
@NotBlank(message = "请输入手机区号")
@ApiModelProperty(value = "手机区号", example = "855")
private String phoneArea;
@NotBlank(message = "请输入手机号")
@ApiModelProperty(value = "手机号", example = "081611122")
private String phone;
@ApiModelProperty("短信验证码")
private String smsCode;
}
...@@ -2,10 +2,11 @@ package com.jumeirah.common.service; ...@@ -2,10 +2,11 @@ package com.jumeirah.common.service;
import com.jumeirah.common.entity.AppUser; import com.jumeirah.common.entity.AppUser;
import com.jumeirah.common.param.AppUserPageParam; import com.jumeirah.common.param.AppUserPageParam;
import com.jumeirah.common.param.LoginParam;
import com.jumeirah.common.param.RegisterParam; import com.jumeirah.common.param.RegisterParam;
import com.jumeirah.common.param.app.AppSmsRegisterParam;
import com.jumeirah.common.vo.AppUserQueryVo; import com.jumeirah.common.vo.AppUserQueryVo;
import com.jumeirah.common.vo.LoginSysUserTokenVo; import com.jumeirah.common.vo.LoginSysUserTokenVo;
import com.jumeirah.common.vo.app.LoginAppUserTokenVo;
import io.geekidea.springbootplus.framework.common.api.ApiResult; import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.service.BaseService; import io.geekidea.springbootplus.framework.common.service.BaseService;
import io.geekidea.springbootplus.framework.core.pagination.Paging; import io.geekidea.springbootplus.framework.core.pagination.Paging;
...@@ -18,12 +19,11 @@ import io.geekidea.springbootplus.framework.core.pagination.Paging; ...@@ -18,12 +19,11 @@ import io.geekidea.springbootplus.framework.core.pagination.Paging;
*/ */
public interface AppUserService extends BaseService<AppUser> { public interface AppUserService extends BaseService<AppUser> {
ApiResult<LoginSysUserTokenVo> register(RegisterParam registerParam, String language); ApiResult<LoginAppUserTokenVo> register(AppSmsRegisterParam appSmsRegisterParam, String language);
ApiResult<LoginSysUserTokenVo> login(LoginParam loginParam, String language); ApiResult<LoginAppUserTokenVo> login(AppSmsRegisterParam loginParam, String language);
ApiResult<LoginSysUserTokenVo> phoneLogin(RegisterParam registerParam, String language);
/** /**
* 保存 * 保存
......
...@@ -8,11 +8,10 @@ import com.jumeirah.common.entity.AppUser; ...@@ -8,11 +8,10 @@ import com.jumeirah.common.entity.AppUser;
import com.jumeirah.common.enums.StateEnum; import com.jumeirah.common.enums.StateEnum;
import com.jumeirah.common.mapper.AppUserMapper; import com.jumeirah.common.mapper.AppUserMapper;
import com.jumeirah.common.param.AppUserPageParam; import com.jumeirah.common.param.AppUserPageParam;
import com.jumeirah.common.param.LoginParam; import com.jumeirah.common.param.app.AppSmsRegisterParam;
import com.jumeirah.common.param.RegisterParam;
import com.jumeirah.common.service.AppUserService; import com.jumeirah.common.service.AppUserService;
import com.jumeirah.common.vo.AppUserQueryVo; import com.jumeirah.common.vo.AppUserQueryVo;
import com.jumeirah.common.vo.LoginSysUserTokenVo; import com.jumeirah.common.vo.app.LoginAppUserTokenVo;
import io.geekidea.springbootplus.config.properties.JwtProperties; import io.geekidea.springbootplus.config.properties.JwtProperties;
import io.geekidea.springbootplus.config.properties.SpringBootPlusProperties; import io.geekidea.springbootplus.config.properties.SpringBootPlusProperties;
import io.geekidea.springbootplus.framework.common.api.ApiCode; import io.geekidea.springbootplus.framework.common.api.ApiCode;
...@@ -24,8 +23,7 @@ import io.geekidea.springbootplus.framework.shiro.cache.AppLoginRedisService; ...@@ -24,8 +23,7 @@ import io.geekidea.springbootplus.framework.shiro.cache.AppLoginRedisService;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.util.JwtUtil; import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
import io.geekidea.springbootplus.framework.shiro.util.SaltUtil; import io.geekidea.springbootplus.framework.shiro.util.SaltUtil;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import io.geekidea.springbootplus.framework.util.PasswordUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
...@@ -68,18 +66,23 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser> ...@@ -68,18 +66,23 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser>
private AppUserMapper appUserMapper; private AppUserMapper appUserMapper;
@Override @Override
public ApiResult<LoginSysUserTokenVo> register(RegisterParam registerParam, String language) { public ApiResult<LoginAppUserTokenVo> register(AppSmsRegisterParam appSmsRegisterParam, String language) {
// JwtToken jwtToken = (JwtToken) SecurityUtils.getSubject().getPrincipal();
// 校验短信验证码是否正确
return null; return null;
} }
@Override @Override
public ApiResult<LoginSysUserTokenVo> login(LoginParam loginParam, String language) { public ApiResult<LoginAppUserTokenVo> login(AppSmsRegisterParam loginParam, String language){
// 校验验证码 // 校验验证码
// checkVerifyCode(loginParam.getVerifyToken(), loginParam.getCode()); // checkVerifyCode(loginParam.getVerifyToken(), loginParam.getCode());
String username = loginParam.getUsername(); String username = loginParam.getPhone();
// 从数据库中获取登录用户信息 // 从数据库中获取登录用户信息
AppUser appUser = appUserMapper.selectOne(new QueryWrapper<AppUser>(new AppUser().setUsername(username))); AppUser appUser = appUserMapper.selectOne(new QueryWrapper<AppUser>(new AppUser().setUsername(username)));
...@@ -98,13 +101,13 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser> ...@@ -98,13 +101,13 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser>
// 原始密码明文:123456 // 原始密码明文:123456
// 原始密码前端加密:sha256(123456) // 原始密码前端加密:sha256(123456)
// 后台加密规则:sha256(sha256(123456) + salt) // 后台加密规则:sha256(sha256(123456) + salt)
String encryptPassword = PasswordUtil.encrypt(loginParam.getPassword(), appUser.getSalt()); // String encryptPassword = PasswordUtil.encrypt(loginParam.getPassword(), appUser.getSalt());
if (!encryptPassword.equals(appUser.getPassword())) { // if (!encryptPassword.equals(appUser.getPassword())) {
return ApiResult.fail(ApiCode.PWD_OR_USERNAME_ERROR, language); // return ApiResult.fail(ApiCode.PWD_OR_USERNAME_ERROR, language);
} // }
// 将系统用户对象转换成登录用户对象 // 将系统用户对象转换成登录用户对象
LoginSysUserVo loginSysUserVo = new LoginSysUserVo(); LoginUserVo loginSysUserVo = new LoginUserVo();
loginSysUserVo.setUsername(username); loginSysUserVo.setUsername(username);
...@@ -138,21 +141,16 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser> ...@@ -138,21 +141,16 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser>
redisTemplate.opsForValue().set(tokenSha256, loginSysUserVo, 1, TimeUnit.DAYS); redisTemplate.opsForValue().set(tokenSha256, loginSysUserVo, 1, TimeUnit.DAYS);
// 返回token和登录用户信息对象 // 返回token和登录用户信息对象
LoginSysUserTokenVo loginSysUserTokenVo = new LoginSysUserTokenVo(); LoginAppUserTokenVo loginSysUserTokenVo = new LoginAppUserTokenVo();
loginSysUserTokenVo.setToken(token); loginSysUserTokenVo.setToken(token);
loginSysUserTokenVo.setLoginSysUserVo(loginSysUserVo);
// 设置token响应头
// response.setHeader(JwtTokenUtil.getTokenName(), loginSysUserTokenVo.getToken());
return ApiResult.ok(loginSysUserTokenVo, language); return ApiResult.ok(loginSysUserTokenVo, language);
} }
@Override // @Override
public ApiResult<LoginSysUserTokenVo> phoneLogin(RegisterParam registerParam, String language) { // public ApiResult<LoginSysUserTokenVo> phoneLogin(RegisterParam registerParam, String language) {
return null; // return null;
} // }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
......
...@@ -28,7 +28,7 @@ import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; ...@@ -28,7 +28,7 @@ import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.util.JwtTokenUtil; import io.geekidea.springbootplus.framework.shiro.util.JwtTokenUtil;
import io.geekidea.springbootplus.framework.shiro.util.JwtUtil; import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
import io.geekidea.springbootplus.framework.shiro.util.SaltUtil; import io.geekidea.springbootplus.framework.shiro.util.SaltUtil;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import io.geekidea.springbootplus.framework.util.PasswordUtil; import io.geekidea.springbootplus.framework.util.PasswordUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
...@@ -114,7 +114,7 @@ public class MerchantUserServiceImpl extends BaseServiceImpl<MerchantUserMapper, ...@@ -114,7 +114,7 @@ public class MerchantUserServiceImpl extends BaseServiceImpl<MerchantUserMapper,
} }
// 将系统用户对象转换成登录用户对象 // 将系统用户对象转换成登录用户对象
LoginSysUserVo loginSysUserVo = SysUserConvert.INSTANCE.merchantUserToLoginSysUserVo(merchantUser); LoginUserVo loginSysUserVo = SysUserConvert.INSTANCE.merchantUserToLoginSysUserVo(merchantUser);
// // 获取部门 // // 获取部门
// SysDepartment sysDepartment = sysDepartmentService.getById(merchantUser.getDepartmentId()); // SysDepartment sysDepartment = sysDepartmentService.getById(merchantUser.getDepartmentId());
......
...@@ -40,7 +40,7 @@ import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; ...@@ -40,7 +40,7 @@ import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.util.JwtTokenUtil; import io.geekidea.springbootplus.framework.shiro.util.JwtTokenUtil;
import io.geekidea.springbootplus.framework.shiro.util.JwtUtil; import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
import io.geekidea.springbootplus.framework.shiro.util.SaltUtil; import io.geekidea.springbootplus.framework.shiro.util.SaltUtil;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import io.geekidea.springbootplus.framework.util.PasswordUtil; import io.geekidea.springbootplus.framework.util.PasswordUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -134,7 +134,7 @@ public class SysLoginServiceImpl implements SysLoginService { ...@@ -134,7 +134,7 @@ public class SysLoginServiceImpl implements SysLoginService {
} }
// 将系统用户对象转换成登录用户对象 // 将系统用户对象转换成登录用户对象
LoginSysUserVo loginSysUserVo = SysUserConvert.INSTANCE.sysUserToLoginSysUserVo(sysUser); LoginUserVo loginSysUserVo = SysUserConvert.INSTANCE.sysUserToLoginSysUserVo(sysUser);
// 获取部门 // 获取部门
SysDepartment sysDepartment = sysDepartmentService.getById(sysUser.getDepartmentId()); SysDepartment sysDepartment = sysDepartmentService.getById(sysUser.getDepartmentId());
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
package com.jumeirah.common.vo; package com.jumeirah.common.vo;
import io.geekidea.springbootplus.framework.shiro.service.LoginToken; import io.geekidea.springbootplus.framework.shiro.service.LoginToken;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -40,5 +40,5 @@ public class LoginSysUserTokenVo implements LoginToken { ...@@ -40,5 +40,5 @@ public class LoginSysUserTokenVo implements LoginToken {
/** /**
* 登录用户对象 * 登录用户对象
*/ */
private LoginSysUserVo loginSysUserVo; private LoginUserVo loginSysUserVo;
} }
/*
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jumeirah.common.vo.app;
import io.geekidea.springbootplus.framework.shiro.service.LoginToken;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @author geekidea
* @date 2019-10-26
**/
@Data
@Accessors(chain = true)
@ApiModel("登录用户信息TokenVO")
public class LoginAppUserTokenVo implements LoginToken {
private static final long serialVersionUID = -2138450422989081056L;
@ApiModelProperty("token")
private String token;
@ApiModelProperty("主键")
private Long id;
@ApiModelProperty("用户名")
private String username;
@ApiModelProperty("昵称")
private String nickname;
// /**
// * 登录用户对象
// */
// private LoginUserVo loginSysUserVo;
}
...@@ -183,7 +183,10 @@ spring-boot-plus: ...@@ -183,7 +183,10 @@ spring-boot-plus:
# 权限配置 # 权限配置
anon: anon:
# 排除登录 注册 登出 # 排除登录 注册 登出
- /app/user/register,/app/user/phoneLogin,/app/user/login,/sys/login,/sys/logout,/sys/register,/merchantUser/login - /app/user/register,/app/user/phoneLogin,/app/user/login
- /sys/login,/sys/logout,/sys/register
- /merchantUser/login
- /app/sms/register
# 排除静态资源 # 排除静态资源
- /static/**,/templates/** - /static/**,/templates/**
# 排除Swagger # 排除Swagger
......
...@@ -18,8 +18,8 @@ package io.geekidea.springbootplus.framework.shiro.cache; ...@@ -18,8 +18,8 @@ package io.geekidea.springbootplus.framework.shiro.cache;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
/** /**
* 登录信息Redis缓存操作服务 * 登录信息Redis缓存操作服务
...@@ -36,7 +36,7 @@ public interface AppLoginRedisService { ...@@ -36,7 +36,7 @@ public interface AppLoginRedisService {
* @param jwtToken * @param jwtToken
* @param loginSysUserVo * @param loginSysUserVo
*/ */
void cacheLoginInfo(JwtToken jwtToken, LoginSysUserVo loginSysUserVo); void cacheLoginInfo(JwtToken jwtToken, LoginUserVo loginSysUserVo);
/** /**
...@@ -54,7 +54,7 @@ public interface AppLoginRedisService { ...@@ -54,7 +54,7 @@ public interface AppLoginRedisService {
* @param username * @param username
* @return * @return
*/ */
LoginSysUserRedisVo getLoginSysUserRedisVo(String username); LoginUserRedisVo getLoginSysUserRedisVo(String username);
/** /**
* 获取登录用户对象 * 获取登录用户对象
...@@ -62,7 +62,7 @@ public interface AppLoginRedisService { ...@@ -62,7 +62,7 @@ public interface AppLoginRedisService {
* @param username * @param username
* @return * @return
*/ */
LoginSysUserVo getLoginSysUserVo(String username); LoginUserVo getLoginSysUserVo(String username);
/** /**
* 通过用户名称获取盐值 * 通过用户名称获取盐值
......
...@@ -18,8 +18,8 @@ package io.geekidea.springbootplus.framework.shiro.cache; ...@@ -18,8 +18,8 @@ package io.geekidea.springbootplus.framework.shiro.cache;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
/** /**
* 登录信息Redis缓存操作服务 * 登录信息Redis缓存操作服务
...@@ -36,7 +36,7 @@ public interface MerchantLoginRedisService { ...@@ -36,7 +36,7 @@ public interface MerchantLoginRedisService {
* @param jwtToken * @param jwtToken
* @param loginSysUserVo * @param loginSysUserVo
*/ */
void cacheLoginInfo(JwtToken jwtToken, LoginSysUserVo loginSysUserVo); void cacheLoginInfo(JwtToken jwtToken, LoginUserVo loginSysUserVo);
/** /**
...@@ -54,7 +54,7 @@ public interface MerchantLoginRedisService { ...@@ -54,7 +54,7 @@ public interface MerchantLoginRedisService {
* @param username * @param username
* @return * @return
*/ */
LoginSysUserRedisVo getLoginSysUserRedisVo(String username); LoginUserRedisVo getLoginSysUserRedisVo(String username);
/** /**
* 获取登录用户对象 * 获取登录用户对象
...@@ -62,7 +62,7 @@ public interface MerchantLoginRedisService { ...@@ -62,7 +62,7 @@ public interface MerchantLoginRedisService {
* @param username * @param username
* @return * @return
*/ */
LoginSysUserVo getLoginSysUserVo(String username); LoginUserVo getLoginSysUserVo(String username);
/** /**
* 通过用户名称获取盐值 * 通过用户名称获取盐值
......
...@@ -18,8 +18,8 @@ package io.geekidea.springbootplus.framework.shiro.cache; ...@@ -18,8 +18,8 @@ package io.geekidea.springbootplus.framework.shiro.cache;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
/** /**
* 登录信息Redis缓存操作服务 * 登录信息Redis缓存操作服务
...@@ -36,7 +36,7 @@ public interface SysLoginRedisService { ...@@ -36,7 +36,7 @@ public interface SysLoginRedisService {
* @param jwtToken * @param jwtToken
* @param loginSysUserVo * @param loginSysUserVo
*/ */
void cacheLoginInfo(JwtToken jwtToken, LoginSysUserVo loginSysUserVo); void cacheLoginInfo(JwtToken jwtToken, LoginUserVo loginSysUserVo);
/** /**
...@@ -54,7 +54,7 @@ public interface SysLoginRedisService { ...@@ -54,7 +54,7 @@ public interface SysLoginRedisService {
* @param username * @param username
* @return * @return
*/ */
LoginSysUserRedisVo getLoginSysUserRedisVo(String username); LoginUserRedisVo getLoginSysUserRedisVo(String username);
/** /**
* 获取登录用户对象 * 获取登录用户对象
...@@ -62,7 +62,7 @@ public interface SysLoginRedisService { ...@@ -62,7 +62,7 @@ public interface SysLoginRedisService {
* @param username * @param username
* @return * @return
*/ */
LoginSysUserVo getLoginSysUserVo(String username); LoginUserVo getLoginSysUserVo(String username);
/** /**
* 通过用户名称获取盐值 * 通过用户名称获取盐值
......
...@@ -9,8 +9,8 @@ import io.geekidea.springbootplus.framework.shiro.convert.LoginSysUserVoConvert; ...@@ -9,8 +9,8 @@ import io.geekidea.springbootplus.framework.shiro.convert.LoginSysUserVoConvert;
import io.geekidea.springbootplus.framework.shiro.convert.ShiroMapstructConvert; import io.geekidea.springbootplus.framework.shiro.convert.ShiroMapstructConvert;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.JwtTokenRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.JwtTokenRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import io.geekidea.springbootplus.framework.util.ClientInfoUtil; import io.geekidea.springbootplus.framework.util.ClientInfoUtil;
import io.geekidea.springbootplus.framework.util.HttpServletRequestUtil; import io.geekidea.springbootplus.framework.util.HttpServletRequestUtil;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
...@@ -42,7 +42,7 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService { ...@@ -42,7 +42,7 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService {
* username:num * username:num
*/ */
@Override @Override
public void cacheLoginInfo(JwtToken jwtToken, LoginSysUserVo loginSysUserVo) { public void cacheLoginInfo(JwtToken jwtToken, LoginUserVo loginSysUserVo) {
if (jwtToken == null) { if (jwtToken == null) {
throw new IllegalArgumentException("jwtToken不能为空"); throw new IllegalArgumentException("jwtToken不能为空");
} }
...@@ -61,13 +61,14 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService { ...@@ -61,13 +61,14 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService {
// Redis缓存JWT Token信息 // Redis缓存JWT Token信息
JwtTokenRedisVo jwtTokenRedisVo = ShiroMapstructConvert.INSTANCE.jwtTokenToJwtTokenRedisVo(jwtToken); JwtTokenRedisVo jwtTokenRedisVo = ShiroMapstructConvert.INSTANCE.jwtTokenToJwtTokenRedisVo(jwtToken);
jwtTokenRedisVo.setUserId(loginSysUserVo.getId());
// 用户客户端信息 // 用户客户端信息
ClientInfo clientInfo = ClientInfoUtil.get(HttpServletRequestUtil.getRequest()); ClientInfo clientInfo = ClientInfoUtil.get(HttpServletRequestUtil.getRequest());
// Redis缓存登录用户信息 // Redis缓存登录用户信息
// 将LoginSysUserVo对象复制到LoginSysUserRedisVo,使用mapstruct进行对象属性复制 // 将LoginSysUserVo对象复制到LoginSysUserRedisVo,使用mapstruct进行对象属性复制
LoginSysUserRedisVo loginSysUserRedisVo = LoginSysUserVoConvert.INSTANCE.voToRedisVo(loginSysUserVo); LoginUserRedisVo loginSysUserRedisVo = LoginSysUserVoConvert.INSTANCE.voToRedisVo(loginSysUserVo);
loginSysUserRedisVo.setSalt(salt); loginSysUserRedisVo.setSalt(salt);
loginSysUserRedisVo.setClientInfo(clientInfo); loginSysUserRedisVo.setClientInfo(clientInfo);
...@@ -94,7 +95,7 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService { ...@@ -94,7 +95,7 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService {
@Override @Override
public void refreshLoginInfo(String oldToken, String username, JwtToken newJwtToken) { public void refreshLoginInfo(String oldToken, String username, JwtToken newJwtToken) {
// 获取缓存的登录用户信息 // 获取缓存的登录用户信息
LoginSysUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(username); LoginUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(username);
// 删除之前的token信息 // 删除之前的token信息
deleteLoginInfo(oldToken, username); deleteLoginInfo(oldToken, username);
// 缓存登录信息 // 缓存登录信息
...@@ -102,19 +103,19 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService { ...@@ -102,19 +103,19 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService {
} }
@Override @Override
public LoginSysUserRedisVo getLoginSysUserRedisVo(String username) { public LoginUserRedisVo getLoginSysUserRedisVo(String username) {
if (StringUtils.isBlank(username)) { if (StringUtils.isBlank(username)) {
throw new IllegalArgumentException("username不能为空"); throw new IllegalArgumentException("username不能为空");
} }
return (LoginSysUserRedisVo) redisTemplate.opsForValue().get(String.format(AppLoginRedisKey.LOGIN_USER, username)); return (LoginUserRedisVo) redisTemplate.opsForValue().get(String.format(AppLoginRedisKey.LOGIN_USER, username));
} }
@Override @Override
public LoginSysUserVo getLoginSysUserVo(String username) { public LoginUserVo getLoginSysUserVo(String username) {
if (StringUtils.isBlank(username)) { if (StringUtils.isBlank(username)) {
throw new IllegalArgumentException("username不能为空"); throw new IllegalArgumentException("username不能为空");
} }
LoginSysUserRedisVo userRedisVo = getLoginSysUserRedisVo(username); LoginUserRedisVo userRedisVo = getLoginSysUserRedisVo(username);
return userRedisVo; return userRedisVo;
} }
......
...@@ -9,8 +9,8 @@ import io.geekidea.springbootplus.framework.shiro.convert.LoginSysUserVoConvert; ...@@ -9,8 +9,8 @@ import io.geekidea.springbootplus.framework.shiro.convert.LoginSysUserVoConvert;
import io.geekidea.springbootplus.framework.shiro.convert.ShiroMapstructConvert; import io.geekidea.springbootplus.framework.shiro.convert.ShiroMapstructConvert;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.JwtTokenRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.JwtTokenRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import io.geekidea.springbootplus.framework.util.ClientInfoUtil; import io.geekidea.springbootplus.framework.util.ClientInfoUtil;
import io.geekidea.springbootplus.framework.util.HttpServletRequestUtil; import io.geekidea.springbootplus.framework.util.HttpServletRequestUtil;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
...@@ -42,7 +42,7 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService ...@@ -42,7 +42,7 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService
* username:num * username:num
*/ */
@Override @Override
public void cacheLoginInfo(JwtToken jwtToken, LoginSysUserVo loginSysUserVo) { public void cacheLoginInfo(JwtToken jwtToken, LoginUserVo loginSysUserVo) {
if (jwtToken == null) { if (jwtToken == null) {
throw new IllegalArgumentException("jwtToken不能为空"); throw new IllegalArgumentException("jwtToken不能为空");
} }
...@@ -60,13 +60,14 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService ...@@ -60,13 +60,14 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService
// Redis缓存JWT Token信息 // Redis缓存JWT Token信息
JwtTokenRedisVo jwtTokenRedisVo = ShiroMapstructConvert.INSTANCE.jwtTokenToJwtTokenRedisVo(jwtToken); JwtTokenRedisVo jwtTokenRedisVo = ShiroMapstructConvert.INSTANCE.jwtTokenToJwtTokenRedisVo(jwtToken);
jwtTokenRedisVo.setUserId(loginSysUserVo.getId());
// 用户客户端信息 // 用户客户端信息
ClientInfo clientInfo = ClientInfoUtil.get(HttpServletRequestUtil.getRequest()); ClientInfo clientInfo = ClientInfoUtil.get(HttpServletRequestUtil.getRequest());
// Redis缓存登录用户信息 // Redis缓存登录用户信息
// 将LoginSysUserVo对象复制到LoginSysUserRedisVo,使用mapstruct进行对象属性复制 // 将LoginSysUserVo对象复制到LoginSysUserRedisVo,使用mapstruct进行对象属性复制
LoginSysUserRedisVo loginSysUserRedisVo = LoginSysUserVoConvert.INSTANCE.voToRedisVo(loginSysUserVo); LoginUserRedisVo loginSysUserRedisVo = LoginSysUserVoConvert.INSTANCE.voToRedisVo(loginSysUserVo);
loginSysUserRedisVo.setSalt(salt); loginSysUserRedisVo.setSalt(salt);
loginSysUserRedisVo.setClientInfo(clientInfo); loginSysUserRedisVo.setClientInfo(clientInfo);
...@@ -93,7 +94,7 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService ...@@ -93,7 +94,7 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService
@Override @Override
public void refreshLoginInfo(String oldToken, String username, JwtToken newJwtToken) { public void refreshLoginInfo(String oldToken, String username, JwtToken newJwtToken) {
// 获取缓存的登录用户信息 // 获取缓存的登录用户信息
LoginSysUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(username); LoginUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(username);
// 删除之前的token信息 // 删除之前的token信息
deleteLoginInfo(oldToken, username); deleteLoginInfo(oldToken, username);
// 缓存登录信息 // 缓存登录信息
...@@ -101,19 +102,19 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService ...@@ -101,19 +102,19 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService
} }
@Override @Override
public LoginSysUserRedisVo getLoginSysUserRedisVo(String username) { public LoginUserRedisVo getLoginSysUserRedisVo(String username) {
if (StringUtils.isBlank(username)) { if (StringUtils.isBlank(username)) {
throw new IllegalArgumentException("username不能为空"); throw new IllegalArgumentException("username不能为空");
} }
return (LoginSysUserRedisVo) redisTemplate.opsForValue().get(String.format(MerchantLoginRedisKey.LOGIN_USER, username)); return (LoginUserRedisVo) redisTemplate.opsForValue().get(String.format(MerchantLoginRedisKey.LOGIN_USER, username));
} }
@Override @Override
public LoginSysUserVo getLoginSysUserVo(String username) { public LoginUserVo getLoginSysUserVo(String username) {
if (StringUtils.isBlank(username)) { if (StringUtils.isBlank(username)) {
throw new IllegalArgumentException("username不能为空"); throw new IllegalArgumentException("username不能为空");
} }
LoginSysUserRedisVo userRedisVo = getLoginSysUserRedisVo(username); LoginUserRedisVo userRedisVo = getLoginSysUserRedisVo(username);
return userRedisVo; return userRedisVo;
} }
......
...@@ -25,8 +25,8 @@ import io.geekidea.springbootplus.framework.shiro.convert.LoginSysUserVoConvert; ...@@ -25,8 +25,8 @@ import io.geekidea.springbootplus.framework.shiro.convert.LoginSysUserVoConvert;
import io.geekidea.springbootplus.framework.shiro.convert.ShiroMapstructConvert; import io.geekidea.springbootplus.framework.shiro.convert.ShiroMapstructConvert;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.JwtTokenRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.JwtTokenRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import io.geekidea.springbootplus.framework.util.ClientInfoUtil; import io.geekidea.springbootplus.framework.util.ClientInfoUtil;
import io.geekidea.springbootplus.framework.util.HttpServletRequestUtil; import io.geekidea.springbootplus.framework.util.HttpServletRequestUtil;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
...@@ -65,7 +65,7 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService { ...@@ -65,7 +65,7 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService {
* username:num * username:num
*/ */
@Override @Override
public void cacheLoginInfo(JwtToken jwtToken, LoginSysUserVo loginSysUserVo) { public void cacheLoginInfo(JwtToken jwtToken, LoginUserVo loginSysUserVo) {
if (jwtToken == null) { if (jwtToken == null) {
throw new IllegalArgumentException("jwtToken不能为空"); throw new IllegalArgumentException("jwtToken不能为空");
} }
...@@ -84,12 +84,13 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService { ...@@ -84,12 +84,13 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService {
// Redis缓存JWT Token信息 // Redis缓存JWT Token信息
JwtTokenRedisVo jwtTokenRedisVo = ShiroMapstructConvert.INSTANCE.jwtTokenToJwtTokenRedisVo(jwtToken); JwtTokenRedisVo jwtTokenRedisVo = ShiroMapstructConvert.INSTANCE.jwtTokenToJwtTokenRedisVo(jwtToken);
jwtTokenRedisVo.setUserId(loginSysUserVo.getId());
// 用户客户端信息 // 用户客户端信息
ClientInfo clientInfo = ClientInfoUtil.get(HttpServletRequestUtil.getRequest()); ClientInfo clientInfo = ClientInfoUtil.get(HttpServletRequestUtil.getRequest());
// Redis缓存登录用户信息 // Redis缓存登录用户信息
// 将LoginSysUserVo对象复制到LoginSysUserRedisVo,使用mapstruct进行对象属性复制 // 将LoginSysUserVo对象复制到LoginSysUserRedisVo,使用mapstruct进行对象属性复制
LoginSysUserRedisVo loginSysUserRedisVo = LoginSysUserVoConvert.INSTANCE.voToRedisVo(loginSysUserVo); LoginUserRedisVo loginSysUserRedisVo = LoginSysUserVoConvert.INSTANCE.voToRedisVo(loginSysUserVo);
loginSysUserRedisVo.setSalt(salt); loginSysUserRedisVo.setSalt(salt);
loginSysUserRedisVo.setClientInfo(clientInfo); loginSysUserRedisVo.setClientInfo(clientInfo);
...@@ -116,7 +117,7 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService { ...@@ -116,7 +117,7 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService {
@Override @Override
public void refreshLoginInfo(String oldToken, String username, JwtToken newJwtToken) { public void refreshLoginInfo(String oldToken, String username, JwtToken newJwtToken) {
// 获取缓存的登录用户信息 // 获取缓存的登录用户信息
LoginSysUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(username); LoginUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(username);
// 删除之前的token信息 // 删除之前的token信息
deleteLoginInfo(oldToken, username); deleteLoginInfo(oldToken, username);
// 缓存登录信息 // 缓存登录信息
...@@ -124,19 +125,19 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService { ...@@ -124,19 +125,19 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService {
} }
@Override @Override
public LoginSysUserRedisVo getLoginSysUserRedisVo(String username) { public LoginUserRedisVo getLoginSysUserRedisVo(String username) {
if (StringUtils.isBlank(username)) { if (StringUtils.isBlank(username)) {
throw new IllegalArgumentException("username不能为空"); throw new IllegalArgumentException("username不能为空");
} }
return (LoginSysUserRedisVo) redisTemplate.opsForValue().get(String.format(SysLoginRedisKey.LOGIN_USER, username)); return (LoginUserRedisVo) redisTemplate.opsForValue().get(String.format(SysLoginRedisKey.LOGIN_USER, username));
} }
@Override @Override
public LoginSysUserVo getLoginSysUserVo(String username) { public LoginUserVo getLoginSysUserVo(String username) {
if (StringUtils.isBlank(username)) { if (StringUtils.isBlank(username)) {
throw new IllegalArgumentException("username不能为空"); throw new IllegalArgumentException("username不能为空");
} }
LoginSysUserRedisVo userRedisVo = getLoginSysUserRedisVo(username); LoginUserRedisVo userRedisVo = getLoginSysUserRedisVo(username);
return userRedisVo; return userRedisVo;
} }
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
package io.geekidea.springbootplus.framework.shiro.convert; package io.geekidea.springbootplus.framework.shiro.convert;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
...@@ -38,6 +38,6 @@ public interface LoginSysUserVoConvert { ...@@ -38,6 +38,6 @@ public interface LoginSysUserVoConvert {
* @param loginSysUserVo * @param loginSysUserVo
* @return * @return
*/ */
LoginSysUserRedisVo voToRedisVo(LoginSysUserVo loginSysUserVo); LoginUserRedisVo voToRedisVo(LoginUserVo loginSysUserVo);
} }
...@@ -43,6 +43,12 @@ public class JwtToken implements HostAuthenticationToken { ...@@ -43,6 +43,12 @@ public class JwtToken implements HostAuthenticationToken {
* 登录ip * 登录ip
*/ */
private String host; private String host;
/**
* 登录用户ID
*/
private Long userId;
/** /**
* 登录用户名称 * 登录用户名称
*/ */
......
...@@ -18,7 +18,7 @@ package io.geekidea.springbootplus.framework.shiro.jwt.realm; ...@@ -18,7 +18,7 @@ package io.geekidea.springbootplus.framework.shiro.jwt.realm;
import io.geekidea.springbootplus.framework.shiro.cache.MerchantLoginRedisService; import io.geekidea.springbootplus.framework.shiro.cache.MerchantLoginRedisService;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.SetUtils; import org.apache.commons.collections4.SetUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -73,7 +73,7 @@ public class JwtRealmMerchant extends AuthorizingRealm { ...@@ -73,7 +73,7 @@ public class JwtRealmMerchant extends AuthorizingRealm {
// 获取username // 获取username
String username = jwtToken.getUsername(); String username = jwtToken.getUsername();
// 获取登录用户角色权限信息 // 获取登录用户角色权限信息
LoginSysUserRedisVo loginSysUserRedisVo = merchantLoginRedisService.getLoginSysUserRedisVo(username); LoginUserRedisVo loginSysUserRedisVo = merchantLoginRedisService.getLoginSysUserRedisVo(username);
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(); SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
// 设置角色 // 设置角色
authorizationInfo.setRoles(SetUtils.hashSet(loginSysUserRedisVo.getRoleCode())); authorizationInfo.setRoles(SetUtils.hashSet(loginSysUserRedisVo.getRoleCode()));
......
...@@ -18,7 +18,7 @@ package io.geekidea.springbootplus.framework.shiro.jwt.realm; ...@@ -18,7 +18,7 @@ package io.geekidea.springbootplus.framework.shiro.jwt.realm;
import io.geekidea.springbootplus.framework.shiro.cache.SysLoginRedisService; import io.geekidea.springbootplus.framework.shiro.cache.SysLoginRedisService;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.SetUtils; import org.apache.commons.collections4.SetUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -69,7 +69,7 @@ public class JwtRealmSystem extends AuthorizingRealm { ...@@ -69,7 +69,7 @@ public class JwtRealmSystem extends AuthorizingRealm {
// 获取username // 获取username
String username = jwtToken.getUsername(); String username = jwtToken.getUsername();
// 获取登录用户角色权限信息 // 获取登录用户角色权限信息
LoginSysUserRedisVo loginSysUserRedisVo = sysLoginRedisService.getLoginSysUserRedisVo(username); LoginUserRedisVo loginSysUserRedisVo = sysLoginRedisService.getLoginSysUserRedisVo(username);
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(); SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
// 设置角色 // 设置角色
......
...@@ -39,6 +39,12 @@ public class JwtTokenRedisVo implements Serializable { ...@@ -39,6 +39,12 @@ public class JwtTokenRedisVo implements Serializable {
* 登录ip * 登录ip
*/ */
private String host; private String host;
/**
* 登录用户ID
*/
private Long userId;
/** /**
* 登录用户名称 * 登录用户名称
*/ */
......
...@@ -30,7 +30,7 @@ import lombok.experimental.Accessors; ...@@ -30,7 +30,7 @@ import lombok.experimental.Accessors;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
public class LoginSysUserRedisVo extends LoginSysUserVo { public class LoginUserRedisVo extends LoginUserVo {
private static final long serialVersionUID = -3858850188055605806L; private static final long serialVersionUID = -3858850188055605806L;
......
...@@ -33,7 +33,7 @@ import java.util.Set; ...@@ -33,7 +33,7 @@ import java.util.Set;
**/ **/
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class LoginSysUserVo implements Serializable { public class LoginUserVo implements Serializable {
private static final long serialVersionUID = -1758338570596088158L; private static final long serialVersionUID = -1758338570596088158L;
......
...@@ -18,7 +18,7 @@ package io.geekidea.springbootplus.framework.util; ...@@ -18,7 +18,7 @@ package io.geekidea.springbootplus.framework.util;
import io.geekidea.springbootplus.framework.shiro.util.JwtTokenUtil; import io.geekidea.springbootplus.framework.shiro.util.JwtTokenUtil;
import io.geekidea.springbootplus.framework.shiro.util.JwtUtil; import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
...@@ -47,7 +47,7 @@ public class LoginUtil { ...@@ -47,7 +47,7 @@ public class LoginUtil {
* *
* @return * @return
*/ */
public static LoginSysUserRedisVo getLoginSysUserRedisVo() { public static LoginUserRedisVo getLoginSysUserRedisVo() {
// 获取当前登录用户 // 获取当前登录用户
String token = JwtTokenUtil.getToken(); String token = JwtTokenUtil.getToken();
String username = JwtUtil.getUsername(token); String username = JwtUtil.getUsername(token);
...@@ -56,7 +56,7 @@ public class LoginUtil { ...@@ -56,7 +56,7 @@ public class LoginUtil {
} }
// return (LoginSysUserRedisVo) redisTemplate.opsForValue().get(String.format(CommonRedisKey.LOGIN_USER, username)); // return (LoginSysUserRedisVo) redisTemplate.opsForValue().get(String.format(CommonRedisKey.LOGIN_USER, username));
LoginSysUserRedisVo loginSysUserRedisVo = new LoginSysUserRedisVo(); LoginUserRedisVo loginSysUserRedisVo = new LoginUserRedisVo();
loginSysUserRedisVo.setUsername(username); loginSysUserRedisVo.setUsername(username);
return loginSysUserRedisVo; return loginSysUserRedisVo;
} }
...@@ -67,7 +67,7 @@ public class LoginUtil { ...@@ -67,7 +67,7 @@ public class LoginUtil {
* @return * @return
*/ */
public static Long getUserId() { public static Long getUserId() {
LoginSysUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(); LoginUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo();
if (loginSysUserRedisVo == null) { if (loginSysUserRedisVo == null) {
return null; return null;
} }
...@@ -80,7 +80,7 @@ public class LoginUtil { ...@@ -80,7 +80,7 @@ public class LoginUtil {
* @return * @return
*/ */
public static String getUsername() { public static String getUsername() {
LoginSysUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(); LoginUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo();
if (loginSysUserRedisVo == null) { if (loginSysUserRedisVo == null) {
return null; return null;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment