升级Spring Cloud Hoxton & Alibaba,认证授权改用Oauth2。

This commit is contained in:
macro
2020-08-15 10:51:40 +08:00
parent d004888a10
commit dae82f62ed
258 changed files with 4671 additions and 3092 deletions

104
README.md
View File

@@ -10,7 +10,7 @@
## 项目介绍
`mall-swarm`是一套微服务商城系统,采用了 Spring Cloud Greenwich、Spring Boot 2、MyBatis、Docker、Elasticsearch等核心技术同时提供了基于Vue的管理后台方便快速搭建系统。`mall-swarm`在电商业务的基础集成了注册中心、配置中心、监控中心、网关等系统功能。 文档齐全附带全套Spring Cloud教程。
`mall-swarm`是一套微服务商城系统,采用了 Spring Cloud Hoxton & Alibaba、Spring Boot 2.3、Oauth2、MyBatis、Docker、Elasticsearch等核心技术同时提供了基于Vue的管理后台方便快速搭建系统。`mall-swarm`在电商业务的基础集成了注册中心、配置中心、监控中心、网关等系统功能。 文档齐全附带全套Spring Cloud教程。
## 系统架构图
@@ -22,15 +22,14 @@
mall
├── mall-common -- 工具类及通用代码模块
├── mall-mbg -- MyBatisGenerator生成的数据库操作代码模块
├── mall-security -- 封装SpringSecurity+JWT的安全认证的模块
├── mall-registry -- 基于Eureka的微服务注册中心
├── mall-config -- 基于Spring Cloud Config的微服务配置中心
├── mall-auth -- 基于Spring Security Oauth2的统一的认证中心
├── mall-gateway -- 基于Spring Cloud Gateway的微服务API网关服务
├── mall-monitor -- 基于Spring Boot Admin的微服务监控中心
├── mall-admin -- 后台管理系统服务
├── mall-search -- 基于Elasticsearch的商品搜索系统服务
├── mall-portal -- 移动端商城系统服务
── mall-demo -- 微服务远程调用测试服务
── mall-demo -- 微服务远程调用测试服务
└── config -- 配置中心存储的配置
```
## 项目文档
@@ -47,29 +46,30 @@ mall
### 后端技术
| 技术 | 说明 | 官网 |
| ---------------- | -------------------- | ---------------------------------------------------- |
| Spring Cloud | 微服务框架 | https://spring.io/projects/spring-cloud |
| Spring Boot | 容器+MVC框架 | https://spring.io/projects/spring-boot |
| Spring Security | 认证和授权框架 | https://spring.io/projects/spring-security |
| MyBatis | ORM框架 | http://www.mybatis.org/mybatis-3/zh/index.html |
| MyBatisGenerator | 数据层代码生成 | http://www.mybatis.org/generator/index.html |
| PageHelper | MyBatis物理分页插件 | http://git.oschina.net/free/Mybatis_PageHelper |
| Swagger-UI | 文档生产工具 | https://github.com/swagger-api/swagger-ui |
| Elasticsearch | 搜索引擎 | https://github.com/elastic/elasticsearch |
| RabbitMq | 消息队列 | https://www.rabbitmq.com/ |
| Redis | 分布式缓存 | https://redis.io/ |
| MongoDb | NoSql数据库 | https://www.mongodb.com/ |
| Docker | 应用容器引擎 | https://www.docker.com/ |
| Druid | 数据库连接池 | https://github.com/alibaba/druid |
| OSS | 对象存储 | https://github.com/aliyun/aliyun-oss-java-sdk |
| MinIO | 对象存储 | https://github.com/minio/minio |
| JWT | JWT登录支持 | https://github.com/jwtk/jjwt |
| LogStash | 日志收集 | https://github.com/logstash/logstash-logback-encoder |
| Lombok | 简化对象封装工具 | https://github.com/rzwitserloot/lombok |
| Seata | 全局事务管理框架 | https://github.com/seata/seata |
| Portainer | 可视化Docker容器管理 | https://github.com/portainer/portainer |
| Jenkins | 自动化部署工具 | https://github.com/jenkinsci/jenkins |
| 技术 | 说明 | 官网 |
| ---------------------- | -------------------- | ---------------------------------------------------- |
| Spring Cloud | 微服务框架 | https://spring.io/projects/spring-cloud |
| Spring Cloud Alibaba | 微服务框架 | https://github.com/alibaba/spring-cloud-alibaba |
| Spring Boot | 容器+MVC框架 | https://spring.io/projects/spring-boot |
| Spring Security Oauth2 | 认证和授权框架 | https://spring.io/projects/spring-security-oauth |
| MyBatis | ORM框架 | http://www.mybatis.org/mybatis-3/zh/index.html |
| MyBatisGenerator | 数据层代码生成 | http://www.mybatis.org/generator/index.html |
| PageHelper | MyBatis物理分页插件 | http://git.oschina.net/free/Mybatis_PageHelper |
| Knife4j | 文档生产工具 | https://github.com/xiaoymin/swagger-bootstrap-ui |
| Elasticsearch | 搜索引擎 | https://github.com/elastic/elasticsearch |
| RabbitMq | 消息队列 | https://www.rabbitmq.com/ |
| Redis | 分布式缓存 | https://redis.io/ |
| MongoDb | NoSql数据库 | https://www.mongodb.com/ |
| Docker | 应用容器引擎 | https://www.docker.com/ |
| Druid | 数据库连接池 | https://github.com/alibaba/druid |
| OSS | 对象存储 | https://github.com/aliyun/aliyun-oss-java-sdk |
| MinIO | 对象存储 | https://github.com/minio/minio |
| JWT | JWT登录支持 | https://github.com/jwtk/jjwt |
| LogStash | 日志收集 | https://github.com/logstash/logstash-logback-encoder |
| Lombok | 简化对象封装工具 | https://github.com/rzwitserloot/lombok |
| Seata | 全局事务管理框架 | https://github.com/seata/seata |
| Portainer | 可视化Docker容器管理 | https://github.com/portainer/portainer |
| Jenkins | 自动化部署工具 | https://github.com/jenkinsci/jenkins |
### 前端技术
@@ -87,15 +87,17 @@ mall
### 开发环境
工具 | 版本号 | 下载
----|----|----
JDK | 1.8 | https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Mysql | 5.7 | https://www.mysql.com/
Redis | 3.2 | https://redis.io/download
Elasticsearch | 6.2.2 | https://www.elastic.co/downloads
MongoDb | 3.2 | https://www.mongodb.com/download-center
RabbitMq | 3.7.14 | http://www.rabbitmq.com/download.html
nginx | 1.10 | http://nginx.org/en/download.html
| 工具 | 版本号 | 下载 |
| ------------- | ------ | ------------------------------------------------------------ |
| JDK | 1.8 | https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html |
| Mysql | 5.7 | https://www.mysql.com/ |
| Redis | 5.0 | https://redis.io/download |
| Elasticsearch | 7.6.2 | https://www.elastic.co/cn/downloads/elasticsearch |
| Kibana | 7.6.2 | https://www.elastic.co/cn/downloads/kibana |
| Logstash | 7.6.2 | https://www.elastic.co/cn/downloads/logstash |
| MongoDb | 4.2.5 | https://www.mongodb.com/download-center |
| RabbitMq | 3.7.14 | http://www.rabbitmq.com/download.html |
| nginx | 1.10 | http://nginx.org/en/download.html |
### 搭建步骤
@@ -106,8 +108,6 @@ nginx | 1.10 | http://nginx.org/en/download.html
- `ELK`日志收集系统的搭建请参考:[SpringBoot应用整合ELK实现日志收集](http://www.macrozheng.com/#/technology/mall_tiny_elk);
- 使用MinIO存储文件请参考[前后端分离项目,如何优雅实现文件存储](http://www.macrozheng.com/#/technology/minio_use);
- 读写分离解决方案请参考:[你还在代码里做读写分离么,试试这个中间件吧](http://www.macrozheng.com/#/reference/gaea);
- 如果想使用`Consul`作为注册及配置中心的话请参考:[Spring Cloud Consul服务治理与配置中心](http://www.macrozheng.com/#/cloud/consul);
- 如果想使用`Nacos`作为注册及配置中心的话请参考:[Spring Cloud AlibabaNacos 作为注册中心和配置中心使用](http://www.macrozheng.com/#/cloud/nacos);
- `分布式事务`解决方案请参考:[使用Seata彻底解决Spring Cloud中的分布式事务问题](http://www.macrozheng.com/#/cloud/seata)。
> Docker环境部署
@@ -120,21 +120,31 @@ nginx | 1.10 | http://nginx.org/en/download.html
## 运行效果展示
- 注册中心控制台信息:
- 查看注册中心注册服务信息访问地址http://192.168.3.101:8848/nacos/
![](http://img.macrozheng.com/mall/project/mall_swarm_linux_07.png)
![](/document/resource/mall_swarm_run_01.png)
- 监控中心应用信息
- 监控中心应用信息访问地址http://192.168.3.101:8101
![](http://img.macrozheng.com/mall/project/mall_swarm_linux_08.png)
![](/document/resource/mall_swarm_run_02.png)
![](http://img.macrozheng.com/mall/project/mall_swarm_linux_09.png)
![](/document/resource/mall_swarm_run_03.png)
- 可视化容器管理:
![](/document/resource/mall_swarm_run_04.png)
![](http://img.macrozheng.com/mall/project/mall_swarm_linux_02.png)
- API文档信息访问地址http://192.168.3.101:8201
![](http://img.macrozheng.com/mall/project/mall_swarm_linux_04.png)
![](/document/resource/mall_swarm_run_05.png)
- 日志收集系统信息访问地址http://192.168.3.101:5601
![](/document/resource/mall_swarm_run_06.png)
- 可视化容器管理访问地址http://192.168.3.101:9000
![](/document/resource/mall_swarm_run_07.png)
![](/document/resource/mall_swarm_run_08.png)
## 公众号

View File

@@ -15,7 +15,15 @@ spring:
url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
username: root
password: root
redis:
host: localhost # Redis服务器地址
database: 0 # Redis数据库索引默认为0
port: 6379 # Redis服务器连接端口
password: # Redis服务器连接密码默认为空
timeout: 3000ms # 连接超时时间(毫秒)
logging:
level:
root: info #日志配置DEBUG,INFO,WARN,ERROR
com.macro.mall: debug
root: info
com.macro.mall: debug
logstash:
host: localhost

View File

@@ -15,5 +15,16 @@ spring:
url: jdbc:mysql://db:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
username: reader
password: 123456
redis:
host: redis # Redis服务器地址
database: 0 # Redis数据库索引默认为0
port: 6379 # Redis服务器连接端口
password: #不设置密码
logging:
path: /var/logs #配置日志生成路径
file:
path: /var/logs
level:
root: info
com.macro.mall: info
logstash:
host: logstash

View File

@@ -5,6 +5,7 @@ spring:
password: root
logging:
level:
root: info #日志配置DEBUG,INFO,WARN,ERROR
root: info
com.macro.mall: debug
com.macro.mall.demo.service.FeignAdminService: debug
logstash:
host: localhost

View File

@@ -4,4 +4,10 @@ spring:
username: reader
password: 123456
logging:
path: /var/logs #配置日志生成路径
file:
path: /var/logs
level:
root: info
com.macro.mall: info
logstash:
host: logstash

View File

@@ -0,0 +1,18 @@
spring:
redis:
host: localhost # Redis服务器地址
database: 0 # Redis数据库索引默认为0
port: 6379 # Redis服务器连接端口
password: # Redis服务器连接密码默认为空
timeout: 3000ms # 连接超时时间(毫秒)
security:
oauth2:
resourceserver:
jwt:
jwk-set-uri: 'http://localhost:8201/mall-auth/rsa/publicKey'
logging:
level:
root: info
com.macro.mall: debug
logstash:
host: localhost

View File

@@ -0,0 +1,19 @@
spring:
redis:
host: redis # Redis服务器地址
database: 0 # Redis数据库索引默认为0
port: 6379 # Redis服务器连接端口
password: #不设置密码
security:
oauth2:
resourceserver:
jwt:
jwk-set-uri: 'http://mall-gateway:8201/mall-auth/rsa/publicKey'
logging:
file:
path: /var/logs
level:
root: info
com.macro.mall: info
logstash:
host: logstash

View File

@@ -19,10 +19,10 @@ spring:
virtual-host: /mall
username: mall
password: mall
publisher-confirms: true #如果对异步消息需要回调必须设置为true
# 日志配置
logging:
level:
org.springframework.data.mongodb.core: debug
com.macro.mall.mapper: debug
com.macro.mall.portal.dao: debug
root: info
com.macro.mall: debug
logstash:
host: localhost

View File

@@ -20,4 +20,12 @@ spring:
username: mall
password: mall
publisher-confirms: true #如果对异步消息需要回调必须设置为true
logging:
file:
path: /var/logs
level:
root: info
com.macro.mall: info
logstash:
host: logstash

View File

@@ -3,14 +3,12 @@ spring:
url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
username: root
password: root
data:
elasticsearch:
cluster-nodes: 127.0.0.1:9300
cluster-name: elasticsearch
elasticsearch:
rest:
uris: http://localhost:9200
logging:
level:
root: info #日志配置DEBUG,INFO,WARN,ERROR
com.macro.mall: debug
root: info
com.macro.mall: debug
logstash:
host: localhost

View File

@@ -3,16 +3,18 @@ spring:
url: jdbc:mysql://db:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
username: reader
password: 123456
data:
elasticsearch:
cluster-nodes: es:9300
cluster-name: elasticsearch
elasticsearch:
rest:
uris: http://es:9200
logging:
path: /var/logs #配置日志生成路径
management:
health:
elasticsearch:
response-timeout: 1000ms #加大健康检查超时时间
response-timeout: 1000ms #加大健康检查超时时间
logging:
file:
path: /var/logs
level:
root: info
com.macro.mall: info
logstash:
host: logstash

View File

@@ -5,23 +5,78 @@ services:
container_name: mall-admin
ports:
- 8080:8080
volumes:
- /mydata/app/mall-admin/logs:/var/logs
- /etc/localtime:/etc/localtime
environment:
- 'TZ="Asia/Shanghai"'
external_links:
- mysql:db #可以用db这个域名访问mysql服务
- nacos-registry:nacos-registry #可以用nacos-registry这个域名访问nacos服务
mall-search:
image: mall/mall-search:1.0-SNAPSHOT
container_name: mall-search
ports:
- 8081:8081
volumes:
- /mydata/app/mall-search/logs:/var/logs
- /etc/localtime:/etc/localtime
environment:
- 'TZ="Asia/Shanghai"'
external_links:
- elasticsearch:es #可以用es这个域名访问elasticsearch服务
- mysql:db #可以用db这个域名访问mysql服务
- nacos-registry:nacos-registry #可以用nacos-registry这个域名访问nacos服务
mall-portal:
image: mall/mall-portal:1.0-SNAPSHOT
container_name: mall-portal
ports:
- 8085:8085
volumes:
- /mydata/app/mall-portal/logs:/var/logs
- /etc/localtime:/etc/localtime
environment:
- 'TZ="Asia/Shanghai"'
external_links:
- redis:redis #可以用redis这个域名访问redis服务
- mongo:mongo #可以用mongo这个域名访问mongo服务
- mysql:db #可以用db这个域名访问mysql服务
- rabbitmq:rabbit #可以用rabbit这个域名访问rabbitmq服务
- rabbitmq:rabbit #可以用rabbit这个域名访问rabbitmq服务
- nacos-registry:nacos-registry #可以用nacos-registry这个域名访问nacos服务
mall-auth:
image: mall/mall-auth:1.0-SNAPSHOT
container_name: mall-auth
ports:
- 8401:8401
volumes:
- /mydata/app/mall-auth/logs:/var/logs
- /etc/localtime:/etc/localtime
environment:
- 'TZ="Asia/Shanghai"'
external_links:
- nacos-registry:nacos-registry #可以用nacos-registry这个域名访问nacos服务
mall-gateway:
image: mall/mall-gateway:1.0-SNAPSHOT
container_name: mall-gateway
ports:
- 8201:8201
volumes:
- /mydata/app/mall-gateway/logs:/var/logs
- /etc/localtime:/etc/localtime
environment:
- 'TZ="Asia/Shanghai"'
external_links:
- redis:redis #可以用redis这个域名访问redis服务
- nacos-registry:nacos-registry #可以用nacos-registry这个域名访问nacos服务
mall-monitor:
image: mall/mall-monitor:1.0-SNAPSHOT
container_name: mall-monitor
ports:
- 8101:8101
volumes:
- /mydata/app/mall-monitor/logs:/var/logs
- /etc/localtime:/etc/localtime
environment:
- 'TZ="Asia/Shanghai"'
external_links:
- nacos-registry:nacos-registry #可以用nacos-registry这个域名访问nacos服务

View File

@@ -14,7 +14,7 @@ services:
- /mydata/mysql/data/conf:/etc/mysql/conf.d #配置文件挂载
- /mydata/mysql/log:/var/log/mysql #日志文件挂载
redis:
image: redis:3.2
image: redis:5
container_name: redis
command: redis-server --appendonly yes
volumes:
@@ -40,8 +40,9 @@ services:
- 5672:5672
- 15672:15672
elasticsearch:
image: elasticsearch:6.4.0
image: elasticsearch:7.6.2
container_name: elasticsearch
user: root
environment:
- "cluster.name=elasticsearch" #设置集群名称为elasticsearch
- "discovery.type=single-node" #以单一节点模式启动
@@ -52,8 +53,24 @@ services:
ports:
- 9200:9200
- 9300:9300
logstash:
image: logstash:7.6.2
container_name: logstash
environment:
- TZ=Asia/Shanghai
volumes:
- /mydata/logstash/logstash.conf:/usr/share/logstash/pipeline/logstash.conf #挂载logstash的配置文件
depends_on:
- elasticsearch #kibana在elasticsearch启动之后再启动
links:
- elasticsearch:es #可以用es这个域名访问elasticsearch服务
ports:
- 4560:4560
- 4561:4561
- 4562:4562
- 4563:4563
kibana:
image: kibana:6.4.0
image: kibana:7.6.2
container_name: kibana
links:
- elasticsearch:es #可以用es这个域名访问elasticsearch服务
@@ -64,9 +81,16 @@ services:
ports:
- 5601:5601
mongo:
image: mongo:3.2
image: mongo:4.2.5
container_name: mongo
volumes:
- /mydata/mongo/db:/data/db #数据文件挂载
ports:
- 27017:27017
- 27017:27017
nacos-registry:
image: nacos/nacos-server:1.3.0
container_name: nacos-registry
environment:
- "MODE=standalone"
ports:
- 8848:8848

View File

@@ -1,149 +0,0 @@
# docker环境部署
## docker环境安装
### docker安装
1. 安装yum-utils
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
2. 为yum源添加docker仓库位置
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
3. 安装docker:
yum install docker-ce
4. 启动docker:
systemctl start docker
常见命令见document/reference文件夹中的docker.md
5. 安装上传下载插件:
yum -y install lrzsz
### docker compose安装
1. 下载地址https://github.com/docker/compose/releases
2. 安装地址:/usr/local/bin/docker-compose
3. 设置为可执行sudo chmod +x /usr/local/bin/docker-compose
4. 测试是否安装成功docker-compose --version
## mysql安装
### 下载镜像文件
docker pull mysql:5.7
### 创建实例并启动
docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
> 参数说明
- -p 3306:3306将容器的3306端口映射到主机的3306端口
- -v /mydata/mysql/conf:/etc/mysql将配置文件夹挂在到主机
- -v /mydata/mysql/log:/var/log/mysql将日志文件夹挂载到主机
- -v /mydata/mysql/data:/var/lib/mysql/:将配置文件夹挂载到主机
- -e MYSQL_ROOT_PASSWORD=root初始化root用户的密码
### 通过容器的mysql命令行工具连接
docker exec -it mysql mysql -uroot -proot
### 设置远程访问
grant all privileges on *.* to 'root' @'%' identified by 'root';
flush privileges;
### 进入容器文件系统
docker exec -it mysql /bin/bash
## redis安装
### 下载镜像文件
docker pull redis:3.2
### 创建实例并启动
docker run -p 6379:6379 --name redis -v /mydata/redis/data:/data -d redis:3.2 redis-server --appendonly yes
### 使用redis镜像执行redis-cli命令连接
docker exec -it redis redis-cli
## nginx安装
### 下载镜像文件
docker pull nginx:1.10
### 创建实例并启动
docker run -p 80:80 --name nginx \
-v /mydata/nginx/html:/usr/share/nginx/html \
-v /mydata/nginx/logs:/var/log/nginx \
-d nginx:1.10
### 修改nginx配置
1. 将容器内的配置文件拷贝到当前目录docker container cp nginx:/etc/nginx .
2. 修改文件名称mv nginx conf
3. 终止容器docker stop nginx
4. 执行命令删除原容器docker rm $ContainerId
5. 执行以下命令:
docker run -p 80:80 --name nginx \
-v /mydata/nginx/html:/usr/share/nginx/html \
-v /mydata/nginx/logs:/var/log/nginx \
-v /mydata/nginx/conf:/etc/nginx \
-d nginx:1.10
## rabbitmq安装
### 下载镜像文件
docker pull rabbitmq:management
### 创建实例并启动
docker run -d --name rabbitmq --publish 5671:5671 \
--publish 5672:5672 --publish 4369:4369 --publish 25672:25672 --publish 15671:15671 --publish 15672:15672 \
rabbitmq:management
## elasticsearch安装
### 下载镜像文件
docker pull elasticsearch:6.4.0
### 创建实例并运行
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch \
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
-d elasticsearch:6.4.0
### 测试
访问会返回版本信息http://192.168.1.66:9200/
### 安装目录位置
/usr/share/elasticsearch
### 安装head插件(可以不安装,仅用于测试)
1. 进入docker内部bash:docker exec -it elasticsearch /bin/bash
2. 安装插件具体参考https://github.com/mobz/elasticsearch-head
3. 测试http://192.168.1.66:9200/_plugin/head/
### 安装中文分词器IKAnalyzer
1. 进入docker内部bash:docker exec -it elasticsearch /bin/bash
2. 安装中文分词插件执行以下命令elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.2/elasticsearch-analysis-ik-6.2.2.zip
3. 测试:
- 访问header插件打开地址http://192.168.1.66:9200/_plugin/head/
- 选择复合查询输入地址POST:http://192.168.1.66:9200/_analyze
- 输入参数JSON:{"analyzer":"ik","text":"我们是大数据开发人员"}
## mongodb安装
### 下载镜像文件
docker pull mongo:3.2
### 创建实例并运行
docker run -p 27017:27017 --name mongo -v /mydata/mongo/db:/data/db -d mongo:3.2
### 使用mongo命令进入容器
docker exec -it mongo mongo
## SpringBoot应用命令部署
**docker容器间进行连接才能互相访问**
### 部署mall-admin
docker run -p 8080:8080 --name mall-admin \
--link mysql:db \
-v /etc/timezone:/etc/timezone \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/admin/logs:/var/logs \
-d mall/mall-admin:1.0-SNAPSHOT
### 部署mall-search
docker run -p 8081:8081 --name mall-search \
--link elasticsearch:es \
--link mysql:db \
-v /etc/timezone:/etc/timezone \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/search/logs:/var/logs \
-d mall/mall-search:1.0-SNAPSHOT
### 部署mall-port
docker run -p 8085:8085 --name mall-portal \
--link mysql:db \
--link redis:redis \
--link mongo:mongo \
-v /etc/timezone:/etc/timezone \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/portal/logs:/var/logs \
-d mall/mall-portal:1.0-SNAPSHOT
## SpringBoot应用自动化部署
### 部署文件
document/docker/docker-compose.yml
### 部署命令
docker-compose up -d

View File

@@ -1,14 +0,0 @@
input {
tcp {
mode => "server"
host => "0.0.0.0"
port => 4560
codec => json_lines
}
}
output {
elasticsearch {
hosts => "es:9200"
index => "springboot-logstash-%{+YYYY.MM.dd}"
}
}

View File

@@ -0,0 +1,49 @@
input {
tcp {
mode => "server"
host => "0.0.0.0"
port => 4560
codec => json_lines
type => "debug"
}
tcp {
mode => "server"
host => "0.0.0.0"
port => 4561
codec => json_lines
type => "error"
}
tcp {
mode => "server"
host => "0.0.0.0"
port => 4562
codec => json_lines
type => "business"
}
tcp {
mode => "server"
host => "0.0.0.0"
port => 4563
codec => json_lines
type => "record"
}
}
filter{
if [type] == "record" {
mutate {
remove_field => "port"
remove_field => "host"
remove_field => "@version"
}
json {
source => "message"
remove_field => ["message"]
}
}
}
output {
elasticsearch {
hosts => "es:9200"
index => "mall-%{type}-%{+YYYY.MM.dd}"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

View File

@@ -22,29 +22,37 @@
<artifactId>mall-mbg</artifactId>
</dependency>
<dependency>
<groupId>com.macro.mall</groupId>
<artifactId>mall-security</artifactId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
</dependency>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
</dependency>
</dependencies>
<build>
<plugins>

View File

@@ -3,11 +3,13 @@ package com.macro.mall;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* 应用启动入口
* Created by macro on 2018/4/26.
*/
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class MallAdminApplication {

View File

@@ -1,62 +0,0 @@
package com.macro.mall.bo;
import com.macro.mall.model.UmsAdmin;
import com.macro.mall.model.UmsResource;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
/**
* SpringSecurity需要的用户详情
* Created by macro on 2018/4/26.
*/
public class AdminUserDetails implements UserDetails {
private UmsAdmin umsAdmin;
private List<UmsResource> resourceList;
public AdminUserDetails(UmsAdmin umsAdmin,List<UmsResource> resourceList) {
this.umsAdmin = umsAdmin;
this.resourceList = resourceList;
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
//返回当前用户的角色
return resourceList.stream()
.map(role ->new SimpleGrantedAuthority(role.getId()+":"+role.getName()))
.collect(Collectors.toList());
}
@Override
public String getPassword() {
return umsAdmin.getPassword();
}
@Override
public String getUsername() {
return umsAdmin.getUsername();
}
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return umsAdmin.getStatus().equals(1);
}
}

View File

@@ -1,144 +0,0 @@
package com.macro.mall.bo;
/**
* Controller层的日志封装类
* Created by macro on 2018/4/26.
*/
public class WebLog {
/**
* 操作描述
*/
private String description;
/**
* 操作用户
*/
private String username;
/**
* 操作时间
*/
private Long startTime;
/**
* 消耗时间
*/
private Integer spendTime;
/**
* 根路径
*/
private String basePath;
/**
* URI
*/
private String uri;
/**
* URL
*/
private String url;
/**
* 请求类型
*/
private String method;
/**
* IP地址
*/
private String ip;
private Object parameter;
private Object result;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Long getStartTime() {
return startTime;
}
public void setStartTime(Long startTime) {
this.startTime = startTime;
}
public Integer getSpendTime() {
return spendTime;
}
public void setSpendTime(Integer spendTime) {
this.spendTime = spendTime;
}
public String getBasePath() {
return basePath;
}
public void setBasePath(String basePath) {
this.basePath = basePath;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public Object getParameter() {
return parameter;
}
public void setParameter(Object parameter) {
this.parameter = parameter;
}
public Object getResult() {
return result;
}
public void setResult(Object result) {
this.result = result;
}
}

View File

@@ -0,0 +1,23 @@
package com.macro.mall.component;
import com.macro.mall.service.UmsResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
* 资源与角色访问对应关系操作组件
* Created by macro on 2020/7/17.
*/
@Component
public class ResourceRoleRulesHolder {
@Autowired
private UmsResourceService resourceService;
@PostConstruct
public void initResourceRolesMap(){
resourceService.initResourceRolesMap();
}
}

View File

@@ -1,35 +0,0 @@
package com.macro.mall.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
* 全局跨域配置
* 注意:前端从网关进行调用时不需要配置
* Created by macro on 2019/7/27.
*/
//@Configuration
public class GlobalCorsConfig {
/**
* 允许跨域调用的过滤器
*/
@Bean
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
//允许所有域名进行跨域调用
config.addAllowedOrigin("*");
//允许跨越发送cookie
config.setAllowCredentials(true);
//放行全部原始头信息
config.addAllowedHeader("*");
//允许所有请求方法跨域调用
config.addAllowedMethod("*");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}

View File

@@ -1,56 +0,0 @@
package com.macro.mall.config;
import com.macro.mall.model.UmsResource;
import com.macro.mall.security.component.DynamicSecurityService;
import com.macro.mall.security.config.SecurityConfig;
import com.macro.mall.service.UmsAdminService;
import com.macro.mall.service.UmsResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* mall-security模块相关配置
* Created by macro on 2019/11/9.
*/
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class MallSecurityConfig extends SecurityConfig {
@Autowired
private UmsAdminService adminService;
@Autowired
private UmsResourceService resourceService;
@Bean
public UserDetailsService userDetailsService() {
//获取登录用户信息
return username -> adminService.loadUserByUsername(username);
}
@Bean
public DynamicSecurityService dynamicSecurityService() {
return new DynamicSecurityService() {
@Override
public Map<String, ConfigAttribute> loadDataSource() {
Map<String, ConfigAttribute> map = new ConcurrentHashMap<>();
List<UmsResource> resourceList = resourceService.listAll();
for (UmsResource resource : resourceList) {
map.put(resource.getUrl(), new org.springframework.security.access.SecurityConfig(resource.getId() + ":" + resource.getName()));
}
return map;
}
};
}
}

View File

@@ -5,7 +5,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* MyBatis配置
* MyBatis相关配置
* Created by macro on 2019/4/8.
*/
@Configuration

View File

@@ -6,6 +6,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* OSS对象存储相关配置
* Created by macro on 2018/5/17.
*/
@Configuration

View File

@@ -0,0 +1,19 @@
package com.macro.mall.config;
import com.macro.mall.common.config.BaseRedisConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* Redis相关配置
* Created by macro on 2020/6/19.
*/
@Configuration
public class RedisConfig extends BaseRedisConfig {
}

View File

@@ -1,80 +0,0 @@
package com.macro.mall.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.AuthorizationScope;
import springfox.documentation.service.SecurityReference;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.List;
/**
* Swagger2API文档的配置
* Created by macro on 2018/4/26.
*/
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.macro.mall.controller"))
.paths(PathSelectors.any())
.build()
.securitySchemes(securitySchemes())
.securityContexts(securityContexts());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("mall后台系统")
.description("mall后台模块")
.contact("macro")
.version("1.0")
.build();
}
private List<ApiKey> securitySchemes() {
//设置请求头信息
List<ApiKey> result = new ArrayList<>();
ApiKey apiKey = new ApiKey("Authorization", "Authorization", "header");
result.add(apiKey);
return result;
}
private List<SecurityContext> securityContexts() {
//设置需要登录认证的路径
List<SecurityContext> result = new ArrayList<>();
result.add(getContextByPath("/brand/.*"));
result.add(getContextByPath("/product/.*"));
result.add(getContextByPath("/productCategory/.*"));
return result;
}
private SecurityContext getContextByPath(String pathRegex){
return SecurityContext.builder()
.securityReferences(defaultAuth())
.forPaths(PathSelectors.regex(pathRegex))
.build();
}
private List<SecurityReference> defaultAuth() {
List<SecurityReference> result = new ArrayList<>();
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
result.add(new SecurityReference("Authorization", authorizationScopes));
return result;
}
}

View File

@@ -0,0 +1,41 @@
package com.macro.mall.config;
import com.macro.mall.common.config.BaseSwaggerConfig;
import com.macro.mall.common.domain.SwaggerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.AuthorizationScope;
import springfox.documentation.service.SecurityReference;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.List;
/**
* Swagger API文档相关配置
* Created by macro on 2018/4/26.
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig extends BaseSwaggerConfig {
@Override
public SwaggerProperties swaggerProperties() {
return SwaggerProperties.builder()
.apiBasePackage("com.macro.mall.controller")
.title("mall后台系统")
.description("mall后台相关接口文档")
.contactName("macro")
.version("1.0")
.enableSecurity(true)
.build();
}
}

View File

@@ -1,9 +1,11 @@
package com.macro.mall.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.json.JSONUtil;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BucketPolicyConfigDto;
import com.macro.mall.dto.MinioUploadDto;
import io.minio.MinioClient;
import io.minio.policy.PolicyType;
import io.minio.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
@@ -20,6 +22,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
/**
* MinIO对象存储管理
* Created by macro on 2019/12/25.
*/
@Api(tags = "MinioController", description = "MinIO对象存储管理")
@@ -43,39 +46,68 @@ public class MinioController {
public CommonResult upload(@RequestParam("file") MultipartFile file) {
try {
//创建一个MinIO的Java客户端
MinioClient minioClient = new MinioClient(ENDPOINT, ACCESS_KEY, SECRET_KEY);
boolean isExist = minioClient.bucketExists(BUCKET_NAME);
MinioClient minioClient =MinioClient.builder()
.endpoint(ENDPOINT)
.credentials(ACCESS_KEY,SECRET_KEY)
.build();
boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(BUCKET_NAME).build());
if (isExist) {
LOGGER.info("存储桶已经存在!");
} else {
//创建存储桶并设置只读权限
minioClient.makeBucket(BUCKET_NAME);
minioClient.setBucketPolicy(BUCKET_NAME, "*.*", PolicyType.READ_ONLY);
minioClient.makeBucket(MakeBucketArgs.builder().bucket(BUCKET_NAME).build());
BucketPolicyConfigDto bucketPolicyConfigDto = createBucketPolicyConfigDto(BUCKET_NAME);
SetBucketPolicyArgs setBucketPolicyArgs = SetBucketPolicyArgs.builder()
.bucket(BUCKET_NAME)
.config(JSONUtil.toJsonStr(bucketPolicyConfigDto))
.build();
minioClient.setBucketPolicy(setBucketPolicyArgs);
}
String filename = file.getOriginalFilename();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
// 设置存储对象名称
String objectName = sdf.format(new Date()) + "/" + filename;
// 使用putObject上传一个文件到存储桶中
minioClient.putObject(BUCKET_NAME, objectName, file.getInputStream(), file.getContentType());
PutObjectArgs putObjectArgs = PutObjectArgs.builder()
.bucket(BUCKET_NAME)
.object(objectName)
.contentType(file.getContentType())
.stream(file.getInputStream(), file.getSize(), ObjectWriteArgs.MIN_MULTIPART_SIZE).build();
minioClient.putObject(putObjectArgs);
LOGGER.info("文件上传成功!");
MinioUploadDto minioUploadDto = new MinioUploadDto();
minioUploadDto.setName(filename);
minioUploadDto.setUrl(ENDPOINT + "/" + BUCKET_NAME + "/" + objectName);
return CommonResult.success(minioUploadDto);
} catch (Exception e) {
e.printStackTrace();
LOGGER.info("上传发生错误: {}", e.getMessage());
}
return CommonResult.failed();
}
private BucketPolicyConfigDto createBucketPolicyConfigDto(String bucketName) {
BucketPolicyConfigDto.Statement statement = BucketPolicyConfigDto.Statement.builder()
.Effect("Allow")
.Principal("*")
.Action("s3:GetObject")
.Resource("arn:aws:s3:::"+bucketName+"/*.**").build();
return BucketPolicyConfigDto.builder()
.Version("2012-10-17")
.Statement(CollUtil.toList(statement))
.build();
}
@ApiOperation("文件删除")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@RequestParam("objectName") String objectName) {
try {
MinioClient minioClient = new MinioClient(ENDPOINT, ACCESS_KEY, SECRET_KEY);
minioClient.removeObject(BUCKET_NAME, objectName);
MinioClient minioClient = MinioClient.builder()
.endpoint(ENDPOINT)
.credentials(ACCESS_KEY,SECRET_KEY)
.build();
minioClient.removeObject(RemoveObjectArgs.builder().bucket(BUCKET_NAME).object(objectName).build());
return CommonResult.success(null);
} catch (Exception e) {
e.printStackTrace();

View File

@@ -1,7 +1,9 @@
package com.macro.mall.controller;
import cn.hutool.core.collection.CollUtil;
import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.common.domain.UserDto;
import com.macro.mall.dto.UmsAdminLoginParam;
import com.macro.mall.dto.UmsAdminParam;
import com.macro.mall.dto.UpdateAdminPasswordParam;
@@ -13,16 +15,14 @@ import com.macro.mall.service.UmsRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.security.Principal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 后台用户管理
@@ -32,10 +32,6 @@ import java.util.Map;
@Api(tags = "UmsAdminController", description = "后台用户管理")
@RequestMapping("/admin")
public class UmsAdminController {
@Value("${jwt.tokenHeader}")
private String tokenHeader;
@Value("${jwt.tokenHead}")
private String tokenHead;
@Autowired
private UmsAdminService adminService;
@Autowired
@@ -56,45 +52,23 @@ public class UmsAdminController {
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public CommonResult login(@RequestBody UmsAdminLoginParam umsAdminLoginParam, BindingResult result) {
String token = adminService.login(umsAdminLoginParam.getUsername(), umsAdminLoginParam.getPassword());
if (token == null) {
return CommonResult.validateFailed("用户名或密码错误");
}
Map<String, String> tokenMap = new HashMap<>();
tokenMap.put("token", token);
tokenMap.put("tokenHead", tokenHead);
return CommonResult.success(tokenMap);
}
@ApiOperation(value = "刷新token")
@RequestMapping(value = "/refreshToken", method = RequestMethod.GET)
@ResponseBody
public CommonResult refreshToken(HttpServletRequest request) {
String token = request.getHeader(tokenHeader);
String refreshToken = adminService.refreshToken(token);
if (refreshToken == null) {
return CommonResult.failed("token已经过期");
}
Map<String, String> tokenMap = new HashMap<>();
tokenMap.put("token", refreshToken);
tokenMap.put("tokenHead", tokenHead);
return CommonResult.success(tokenMap);
return adminService.login(umsAdminLoginParam.getUsername(),umsAdminLoginParam.getPassword());
}
@ApiOperation(value = "获取当前登录用户信息")
@RequestMapping(value = "/info", method = RequestMethod.GET)
@ResponseBody
public CommonResult getAdminInfo(Principal principal) {
if(principal==null){
return CommonResult.unauthorized(null);
}
String username = principal.getName();
UmsAdmin umsAdmin = adminService.getAdminByUsername(username);
public CommonResult getAdminInfo() {
UmsAdmin umsAdmin = adminService.getCurrentAdmin();
Map<String, Object> data = new HashMap<>();
data.put("username", umsAdmin.getUsername());
data.put("roles", new String[]{"TEST"});
data.put("menus", roleService.getMenuList(umsAdmin.getId()));
data.put("icon", umsAdmin.getIcon());
List<UmsRole> roleList = adminService.getRoleList(umsAdmin.getId());
if(CollUtil.isNotEmpty(roleList)){
List<String> roles = roleList.stream().map(UmsRole::getName).collect(Collectors.toList());
data.put("roles",roles);
}
return CommonResult.success(data);
}
@@ -215,4 +189,12 @@ public class UmsAdminController {
List<UmsPermission> permissionList = adminService.getPermissionList(adminId);
return CommonResult.success(permissionList);
}
@ApiOperation("根据用户名获取通用用户信息")
@RequestMapping(value = "/loadByUsername", method = RequestMethod.GET)
@ResponseBody
public UserDto loadUserByUsername(@RequestParam String username) {
UserDto userDTO = adminService.loadUserByUsername(username);
return userDTO;
}
}

View File

@@ -3,7 +3,6 @@ package com.macro.mall.controller;
import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.UmsResource;
import com.macro.mall.security.component.DynamicSecurityMetadataSource;
import com.macro.mall.service.UmsResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -12,6 +11,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* 后台资源管理Controller
@@ -24,15 +24,12 @@ public class UmsResourceController {
@Autowired
private UmsResourceService resourceService;
@Autowired
private DynamicSecurityMetadataSource dynamicSecurityMetadataSource;
@ApiOperation("添加后台资源")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody UmsResource umsResource) {
int count = resourceService.create(umsResource);
dynamicSecurityMetadataSource.clearDataSource();
if (count > 0) {
return CommonResult.success(count);
} else {
@@ -46,7 +43,6 @@ public class UmsResourceController {
public CommonResult update(@PathVariable Long id,
@RequestBody UmsResource umsResource) {
int count = resourceService.update(id, umsResource);
dynamicSecurityMetadataSource.clearDataSource();
if (count > 0) {
return CommonResult.success(count);
} else {
@@ -67,7 +63,6 @@ public class UmsResourceController {
@ResponseBody
public CommonResult delete(@PathVariable Long id) {
int count = resourceService.delete(id);
dynamicSecurityMetadataSource.clearDataSource();
if (count > 0) {
return CommonResult.success(count);
} else {
@@ -94,4 +89,12 @@ public class UmsResourceController {
List<UmsResource> resourceList = resourceService.listAll();
return CommonResult.success(resourceList);
}
@ApiOperation("初始化资源角色关联数据")
@RequestMapping(value = "/initResourceRolesMap", method = RequestMethod.GET)
@ResponseBody
public CommonResult initResourceRolesMap() {
Map<String, List<String>> resourceRolesMap = resourceService.initResourceRolesMap();
return CommonResult.success(resourceRolesMap);
}
}

View File

@@ -6,7 +6,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 自定义优选和商品关系操作
* 自定义优选和商品关系操作Dao
* Created by macro on 2018/4/26.
*/
public interface CmsPrefrenceAreaProductRelationDao {

View File

@@ -6,7 +6,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 自定义商品和专题关系操作
* 自定义商品和专题关系操作Dao
* Created by macro on 2018/4/26.
*/
public interface CmsSubjectProductRelationDao {

View File

@@ -10,7 +10,7 @@ import java.util.List;
*/
public interface PmsProductAttributeCategoryDao {
/**
* 获取商品属性分类,包括属性
* 获取包含属性的商品属性分类
*/
List<PmsProductAttributeCategoryItem> getListWithAttr();
}

View File

@@ -10,7 +10,7 @@ import java.util.List;
*/
public interface PmsProductCategoryDao {
/**
* 获取商品分类包括子分类
* 获取商品分类及其子分类
*/
List<PmsProductCategoryWithChildrenItem> listWithChildren();
}

View File

@@ -5,7 +5,7 @@ import org.apache.ibatis.annotations.Param;
/**
* 商品自定义Dao
* 自定义商品管理Dao
* Created by macro on 2018/4/26.
*/
public interface PmsProductDao {

View File

@@ -10,5 +10,8 @@ import java.util.List;
* Created by macro on 2018/4/26.
*/
public interface PmsProductLadderDao {
/**
* 批量创建
*/
int insertList(@Param("list") List<PmsProductLadder> productLadderList);
}

View File

@@ -6,9 +6,12 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 商品审核日志自定义Dao
* 自定义商品审核日志管理Dao
* Created by macro on 2018/4/27.
*/
public interface PmsProductVertifyRecordDao {
/**
* 批量创建
*/
int insertList(@Param("list") List<PmsProductVertifyRecord> list);
}

View File

@@ -6,7 +6,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 自定义商品sku库存Dao
* 自定义商品SKU管理Dao
* Created by macro on 2018/4/26.
*/
public interface PmsSkuStockDao {

View File

@@ -4,9 +4,12 @@ import com.macro.mall.dto.SmsCouponParam;
import org.apache.ibatis.annotations.Param;
/**
* 优惠券管理自定义查询Dao
* 自定义优惠券管理Dao
* Created by macro on 2018/8/29.
*/
public interface SmsCouponDao {
/**
* 获取优惠券详情包括绑定关系
*/
SmsCouponParam getItem(@Param("id") Long id);
}

View File

@@ -6,9 +6,12 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 优惠券和商品分类关系自定义Dao
* 自定义优惠券和商品分类关系管理Dao
* Created by macro on 2018/8/28.
*/
public interface SmsCouponProductCategoryRelationDao {
/**
* 批量创建
*/
int insertList(@Param("list")List<SmsCouponProductCategoryRelation> productCategoryRelationList);
}

View File

@@ -6,9 +6,12 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 优惠券和品关系自定义Dao
* 自定义优惠券和品关系关系Dao
* Created by macro on 2018/8/28.
*/
public interface SmsCouponProductRelationDao {
/**
* 批量创建
*/
int insertList(@Param("list")List<SmsCouponProductRelation> productRelationList);
}

View File

@@ -6,7 +6,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 限时购商品关联自定义Dao
* 自定义限时购商品关系管理Dao
* Created by macro on 2018/11/16.
*/
public interface SmsFlashPromotionProductRelationDao {

View File

@@ -6,9 +6,12 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 用户权限自定义Dao
* 自定义用户权限关系管理Dao
* Created by macro on 2018/10/8.
*/
public interface UmsAdminPermissionRelationDao {
/**
* 批量创建
*/
int insertList(@Param("list") List<UmsAdminPermissionRelation> list);
}

View File

@@ -9,7 +9,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 后台用户与角色管理自定义Dao
* 自定义后台用户与角色管理Dao
* Created by macro on 2018/10/8.
*/
public interface UmsAdminRoleRelationDao {
@@ -37,4 +37,9 @@ public interface UmsAdminRoleRelationDao {
* 获取用户所有可访问资源
*/
List<UmsResource> getResourceList(@Param("adminId") Long adminId);
/**
* 获取资源相关用户ID列表
*/
List<Long> getAdminIdList(@Param("resourceId") Long resourceId);
}

View File

@@ -7,13 +7,20 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 后台用户角色自定义Dao
* 自定义后台角色管理Dao
* Created by macro on 2020/2/2.
*/
public interface UmsRoleDao {
/**
* 根据后台用户ID获取菜单
*/
List<UmsMenu> getMenuList(@Param("adminId") Long adminId);
/**
* 根据角色ID获取菜单
*/
List<UmsMenu> getMenuListByRoleId(@Param("roleId") Long roleId);
/**
* 根据角色ID获取资源
*/
List<UmsResource> getResourceListByRoleId(@Param("roleId") Long roleId);
}

View File

@@ -7,7 +7,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 后台用户角色管理自定义Dao
* 自定义角色权限关系管理Dao
* Created by macro on 2018/9/30.
*/
public interface UmsRolePermissionRelationDao {

View File

@@ -0,0 +1,31 @@
package com.macro.mall.dto;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
/**
* Minio Bucket访问策略配置
* Created by macro on 2020/8/11.
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Builder
public class BucketPolicyConfigDto {
private String Version;
private List<Statement> Statement;
@Data
@EqualsAndHashCode(callSuper = false)
@Builder
public static class Statement {
private String Effect;
private String Principal;
private String Action;
private String Resource;
}
}

View File

@@ -1,5 +1,6 @@
package com.macro.mall.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -10,6 +11,8 @@ import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public class MinioUploadDto {
@ApiModelProperty("文件访问URL")
private String url;
@ApiModelProperty("文件名称")
private String name;
}

View File

@@ -1,5 +1,6 @@
package com.macro.mall.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
@@ -12,8 +13,12 @@ import java.math.BigDecimal;
@Getter
@Setter
public class OmsMoneyInfoParam {
@ApiModelProperty("订单ID")
private Long orderId;
@ApiModelProperty("运费金额")
private BigDecimal freightAmount;
@ApiModelProperty("管理员后台调整订单使用的折扣金额")
private BigDecimal discountAmount;
@ApiModelProperty("订单状态0->待付款1->待发货2->已发货3->已完成4->已关闭5->无效订单")
private Integer status;
}

View File

@@ -3,6 +3,7 @@ package com.macro.mall.dto;
import com.macro.mall.model.OmsOrder;
import com.macro.mall.model.OmsOrderItem;
import com.macro.mall.model.OmsOrderOperateHistory;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
@@ -15,8 +16,10 @@ import java.util.List;
public class OmsOrderDetail extends OmsOrder {
@Getter
@Setter
@ApiModelProperty("订单商品列表")
private List<OmsOrderItem> orderItemList;
@Getter
@Setter
@ApiModelProperty("订单操作记录列表")
private List<OmsOrderOperateHistory> historyList;
}

View File

@@ -2,6 +2,7 @@ package com.macro.mall.dto;
import com.macro.mall.model.OmsCompanyAddress;
import com.macro.mall.model.OmsOrderReturnApply;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
@@ -12,5 +13,6 @@ import lombok.Setter;
public class OmsOrderReturnApplyResult extends OmsOrderReturnApply {
@Getter
@Setter
@ApiModelProperty(value = "公司收货地址")
private OmsCompanyAddress companyAddress;
}

View File

@@ -1,5 +1,6 @@
package com.macro.mall.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
@@ -10,13 +11,22 @@ import lombok.Setter;
@Getter
@Setter
public class OmsReceiverInfoParam {
@ApiModelProperty(value = "订单ID")
private Long orderId;
@ApiModelProperty(value = "收货人姓名")
private String receiverName;
@ApiModelProperty(value = "收货人电话")
private String receiverPhone;
@ApiModelProperty(value = "收货人邮编")
private String receiverPostCode;
@ApiModelProperty(value = "详细地址")
private String receiverDetailAddress;
@ApiModelProperty(value = "省份/直辖市")
private String receiverProvince;
@ApiModelProperty(value = "城市")
private String receiverCity;
@ApiModelProperty(value = "")
private String receiverRegion;
@ApiModelProperty(value = "订单状态0->待付款1->待发货2->已发货3->已完成4->已关闭5->无效订单")
private Integer status;
}

View File

@@ -1,11 +1,15 @@
package com.macro.mall.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* oss上传成功后的回调参数
* Created by macro on 2018/5/17.
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class OssCallbackParam {
@ApiModelProperty("请求的回调地址")
private String callbackUrl;
@@ -13,28 +17,4 @@ public class OssCallbackParam {
private String callbackBody;
@ApiModelProperty("回调时传入参数的格式,比如表单提交形式")
private String callbackBodyType;
public String getCallbackUrl() {
return callbackUrl;
}
public void setCallbackUrl(String callbackUrl) {
this.callbackUrl = callbackUrl;
}
public String getCallbackBody() {
return callbackBody;
}
public void setCallbackBody(String callbackBody) {
this.callbackBody = callbackBody;
}
public String getCallbackBodyType() {
return callbackBodyType;
}
public void setCallbackBodyType(String callbackBodyType) {
this.callbackBodyType = callbackBodyType;
}
}

View File

@@ -1,11 +1,15 @@
package com.macro.mall.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* oss上传文件的回调结果
* Created by macro on 2018/5/17.
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class OssCallbackResult {
@ApiModelProperty("文件名称")
private String filename;
@@ -17,44 +21,4 @@ public class OssCallbackResult {
private String width;
@ApiModelProperty("图片文件的高")
private String height;
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public String getMimeType() {
return mimeType;
}
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
public String getWidth() {
return width;
}
public void setWidth(String width) {
this.width = width;
}
public String getHeight() {
return height;
}
public void setHeight(String height) {
this.height = height;
}
}

View File

@@ -1,11 +1,15 @@
package com.macro.mall.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 获取OSS上传文件授权返回结果
* Created by macro on 2018/5/17.
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class OssPolicyResult {
@ApiModelProperty("访问身份验证中用到用户标识")
private String accessKeyId;
@@ -19,52 +23,4 @@ public class OssPolicyResult {
private String host;
@ApiModelProperty("上传成功后的回调设置")
private String callback;
public String getAccessKeyId() {
return accessKeyId;
}
public void setAccessKeyId(String accessKeyId) {
this.accessKeyId = accessKeyId;
}
public String getPolicy() {
return policy;
}
public void setPolicy(String policy) {
this.policy = policy;
}
public String getSignature() {
return signature;
}
public void setSignature(String signature) {
this.signature = signature;
}
public String getDir() {
return dir;
}
public void setDir(String dir) {
this.dir = dir;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getCallback() {
return callback;
}
public void setCallback(String callback) {
this.callback = callback;
}
}

View File

@@ -2,6 +2,8 @@ package com.macro.mall.dto;
import com.macro.mall.validator.FlagValidator;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
@@ -10,6 +12,8 @@ import javax.validation.constraints.NotEmpty;
* 品牌传递参数
* Created by macro on 2018/4/26.
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class PmsBrandParam {
@ApiModelProperty(value = "品牌名称",required = true)
@NotEmpty(message = "名称不能为空")
@@ -32,68 +36,4 @@ public class PmsBrandParam {
private String bigPic;
@ApiModelProperty(value = "品牌故事")
private String brandStory;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFirstLetter() {
return firstLetter;
}
public void setFirstLetter(String firstLetter) {
this.firstLetter = firstLetter;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public Integer getFactoryStatus() {
return factoryStatus;
}
public void setFactoryStatus(Integer factoryStatus) {
this.factoryStatus = factoryStatus;
}
public Integer getShowStatus() {
return showStatus;
}
public void setShowStatus(Integer showStatus) {
this.showStatus = showStatus;
}
public String getLogo() {
return logo;
}
public void setLogo(String logo) {
this.logo = logo;
}
public String getBigPic() {
return bigPic;
}
public void setBigPic(String bigPic) {
this.bigPic = bigPic;
}
public String getBrandStory() {
return brandStory;
}
public void setBrandStory(String brandStory) {
this.brandStory = brandStory;
}
}

View File

@@ -2,6 +2,10 @@ package com.macro.mall.dto;
import com.macro.mall.model.PmsProductAttribute;
import com.macro.mall.model.PmsProductAttributeCategory;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@@ -10,13 +14,8 @@ import java.util.List;
* Created by macro on 2018/5/24.
*/
public class PmsProductAttributeCategoryItem extends PmsProductAttributeCategory {
@Getter
@Setter
@ApiModelProperty(value = "商品属性列表")
private List<PmsProductAttribute> productAttributeList;
public List<PmsProductAttribute> getProductAttributeList() {
return productAttributeList;
}
public void setProductAttributeList(List<PmsProductAttribute> productAttributeList) {
this.productAttributeList = productAttributeList;
}
}

View File

@@ -2,6 +2,8 @@ package com.macro.mall.dto;
import com.macro.mall.validator.FlagValidator;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotEmpty;
@@ -9,6 +11,8 @@ import javax.validation.constraints.NotEmpty;
* 商品属性参数
* Created by macro on 2018/4/26.
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class PmsProductAttributeParam {
@ApiModelProperty("属性分类ID")
@NotEmpty(message = "属性分类不能为空")
@@ -41,92 +45,4 @@ public class PmsProductAttributeParam {
@ApiModelProperty("属性的类型0->规格1->参数")
@FlagValidator({"0","1"})
private Integer type;
public Long getProductAttributeCategoryId() {
return productAttributeCategoryId;
}
public void setProductAttributeCategoryId(Long productAttributeCategoryId) {
this.productAttributeCategoryId = productAttributeCategoryId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getSelectType() {
return selectType;
}
public void setSelectType(Integer selectType) {
this.selectType = selectType;
}
public Integer getInputType() {
return inputType;
}
public void setInputType(Integer inputType) {
this.inputType = inputType;
}
public String getInputList() {
return inputList;
}
public void setInputList(String inputList) {
this.inputList = inputList;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public Integer getFilterType() {
return filterType;
}
public void setFilterType(Integer filterType) {
this.filterType = filterType;
}
public Integer getSearchType() {
return searchType;
}
public void setSearchType(Integer searchType) {
this.searchType = searchType;
}
public Integer getRelatedStatus() {
return relatedStatus;
}
public void setRelatedStatus(Integer relatedStatus) {
this.relatedStatus = relatedStatus;
}
public Integer getHandAddStatus() {
return handAddStatus;
}
public void setHandAddStatus(Integer handAddStatus) {
this.handAddStatus = handAddStatus;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
}

View File

@@ -2,6 +2,8 @@ package com.macro.mall.dto;
import com.macro.mall.validator.FlagValidator;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
@@ -11,6 +13,8 @@ import java.util.List;
* 添加更新产品分类的参数
* Created by macro on 2018/4/26.
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class PmsProductCategoryParam {
@ApiModelProperty("父分类的编号")
private Long parentId;
@@ -36,84 +40,4 @@ public class PmsProductCategoryParam {
private String description;
@ApiModelProperty("产品相关筛选属性集合")
private List<Long> productAttributeIdList;
public Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getProductUnit() {
return productUnit;
}
public void setProductUnit(String productUnit) {
this.productUnit = productUnit;
}
public Integer getNavStatus() {
return navStatus;
}
public void setNavStatus(Integer navStatus) {
this.navStatus = navStatus;
}
public Integer getShowStatus() {
return showStatus;
}
public void setShowStatus(Integer showStatus) {
this.showStatus = showStatus;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getKeywords() {
return keywords;
}
public void setKeywords(String keywords) {
this.keywords = keywords;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public List<Long> getProductAttributeIdList() {
return productAttributeIdList;
}
public void setProductAttributeIdList(List<Long> productAttributeIdList) {
this.productAttributeIdList = productAttributeIdList;
}
}

View File

@@ -1,6 +1,9 @@
package com.macro.mall.dto;
import com.macro.mall.model.PmsProductCategory;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@@ -8,13 +11,8 @@ import java.util.List;
* Created by macro on 2018/5/25.
*/
public class PmsProductCategoryWithChildrenItem extends PmsProductCategory {
@Getter
@Setter
@ApiModelProperty("子级分类")
private List<PmsProductCategory> children;
public List<PmsProductCategory> getChildren() {
return children;
}
public void setChildren(List<PmsProductCategory> children) {
this.children = children;
}
}

View File

@@ -2,6 +2,8 @@ package com.macro.mall.dto;
import com.macro.mall.model.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@@ -9,6 +11,8 @@ import java.util.List;
* 创建和修改商品时使用的参数
* Created by macro on 2018/4/26.
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class PmsProductParam extends PmsProduct{
@ApiModelProperty("商品阶梯价格设置")
private List<PmsProductLadder> productLadderList;
@@ -24,60 +28,4 @@ public class PmsProductParam extends PmsProduct{
private List<CmsSubjectProductRelation> subjectProductRelationList;
@ApiModelProperty("优选专区和商品的关系")
private List<CmsPrefrenceAreaProductRelation> prefrenceAreaProductRelationList;
public List<PmsProductLadder> getProductLadderList() {
return productLadderList;
}
public void setProductLadderList(List<PmsProductLadder> productLadderList) {
this.productLadderList = productLadderList;
}
public List<PmsProductFullReduction> getProductFullReductionList() {
return productFullReductionList;
}
public void setProductFullReductionList(List<PmsProductFullReduction> productFullReductionList) {
this.productFullReductionList = productFullReductionList;
}
public List<PmsMemberPrice> getMemberPriceList() {
return memberPriceList;
}
public void setMemberPriceList(List<PmsMemberPrice> memberPriceList) {
this.memberPriceList = memberPriceList;
}
public List<PmsSkuStock> getSkuStockList() {
return skuStockList;
}
public void setSkuStockList(List<PmsSkuStock> skuStockList) {
this.skuStockList = skuStockList;
}
public List<PmsProductAttributeValue> getProductAttributeValueList() {
return productAttributeValueList;
}
public void setProductAttributeValueList(List<PmsProductAttributeValue> productAttributeValueList) {
this.productAttributeValueList = productAttributeValueList;
}
public List<CmsSubjectProductRelation> getSubjectProductRelationList() {
return subjectProductRelationList;
}
public void setSubjectProductRelationList(List<CmsSubjectProductRelation> subjectProductRelationList) {
this.subjectProductRelationList = subjectProductRelationList;
}
public List<CmsPrefrenceAreaProductRelation> getPrefrenceAreaProductRelationList() {
return prefrenceAreaProductRelationList;
}
public void setPrefrenceAreaProductRelationList(List<CmsPrefrenceAreaProductRelation> prefrenceAreaProductRelationList) {
this.prefrenceAreaProductRelationList = prefrenceAreaProductRelationList;
}
}

View File

@@ -1,11 +1,15 @@
package com.macro.mall.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 产品查询参数
* Created by macro on 2018/4/27.
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class PmsProductQueryParam {
@ApiModelProperty("上架状态")
private Integer publishStatus;
@@ -19,52 +23,4 @@ public class PmsProductQueryParam {
private Long productCategoryId;
@ApiModelProperty("商品品牌编号")
private Long brandId;
public Integer getPublishStatus() {
return publishStatus;
}
public void setPublishStatus(Integer publishStatus) {
this.publishStatus = publishStatus;
}
public Integer getVerifyStatus() {
return verifyStatus;
}
public void setVerifyStatus(Integer verifyStatus) {
this.verifyStatus = verifyStatus;
}
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
public String getProductSn() {
return productSn;
}
public void setProductSn(String productSn) {
this.productSn = productSn;
}
public Long getProductCategoryId() {
return productCategoryId;
}
public void setProductCategoryId(Long productCategoryId) {
this.productCategoryId = productCategoryId;
}
public Long getBrandId() {
return brandId;
}
public void setBrandId(Long brandId) {
this.brandId = brandId;
}
}

View File

@@ -1,18 +1,16 @@
package com.macro.mall.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
/**
* 查询单个产品进行修改时返回的结果
* Created by macro on 2018/4/26.
*/
public class PmsProductResult extends PmsProductParam {
//商品所选分类的父id
@Getter
@Setter
@ApiModelProperty("商品所选分类的父id")
private Long cateParentId;
public Long getCateParentId() {
return cateParentId;
}
public void setCateParentId(Long cateParentId) {
this.cateParentId = cateParentId;
}
}

View File

@@ -1,27 +1,19 @@
package com.macro.mall.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 商品分类对应属性信息
* Created by macro on 2018/5/23.
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class ProductAttrInfo {
@ApiModelProperty("商品属性ID")
private Long attributeId;
@ApiModelProperty("商品属性分类ID")
private Long attributeCategoryId;
public Long getAttributeId() {
return attributeId;
}
public void setAttributeId(Long attributeId) {
this.attributeId = attributeId;
}
public Long getAttributeCategoryId() {
return attributeCategoryId;
}
public void setAttributeCategoryId(Long attributeCategoryId) {
this.attributeCategoryId = attributeCategoryId;
}
}

View File

@@ -3,6 +3,9 @@ package com.macro.mall.dto;
import com.macro.mall.model.SmsCoupon;
import com.macro.mall.model.SmsCouponProductCategoryRelation;
import com.macro.mall.model.SmsCouponProductRelation;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@@ -11,24 +14,12 @@ import java.util.List;
* Created by macro on 2018/8/28.
*/
public class SmsCouponParam extends SmsCoupon {
//优惠券绑定的商品
@Getter
@Setter
@ApiModelProperty("优惠券绑定的商品")
private List<SmsCouponProductRelation> productRelationList;
//优惠券绑定的商品分类
@Getter
@Setter
@ApiModelProperty("优惠券绑定的商品分类")
private List<SmsCouponProductCategoryRelation> productCategoryRelationList;
public List<SmsCouponProductRelation> getProductRelationList() {
return productRelationList;
}
public void setProductRelationList(List<SmsCouponProductRelation> productRelationList) {
this.productRelationList = productRelationList;
}
public List<SmsCouponProductCategoryRelation> getProductCategoryRelationList() {
return productCategoryRelationList;
}
public void setProductCategoryRelationList(List<SmsCouponProductCategoryRelation> productCategoryRelationList) {
this.productCategoryRelationList = productCategoryRelationList;
}
}

View File

@@ -2,6 +2,7 @@ package com.macro.mall.dto;
import com.macro.mall.model.PmsProduct;
import com.macro.mall.model.SmsFlashPromotionProductRelation;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
@@ -12,5 +13,6 @@ import lombok.Setter;
public class SmsFlashPromotionProduct extends SmsFlashPromotionProductRelation{
@Getter
@Setter
@ApiModelProperty("关联商品")
private PmsProduct product;
}

View File

@@ -1,6 +1,7 @@
package com.macro.mall.dto;
import com.macro.mall.model.SmsFlashPromotionSession;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
@@ -11,5 +12,6 @@ import lombok.Setter;
public class SmsFlashPromotionSessionDetail extends SmsFlashPromotionSession {
@Setter
@Getter
@ApiModelProperty("商品数量")
private Long productCount;
}

View File

@@ -1,6 +1,8 @@
package com.macro.mall.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotEmpty;
@@ -8,6 +10,8 @@ import javax.validation.constraints.NotEmpty;
* 用户登录参数
* Created by macro on 2018/4/26.
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class UmsAdminLoginParam {
@ApiModelProperty(value = "用户名", required = true)
@NotEmpty(message = "用户名不能为空")
@@ -15,20 +19,4 @@ public class UmsAdminLoginParam {
@ApiModelProperty(value = "密码", required = true)
@NotEmpty(message = "密码不能为空")
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

View File

@@ -1,6 +1,7 @@
package com.macro.mall.dto;
import com.macro.mall.model.UmsMenu;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
@@ -13,5 +14,6 @@ import java.util.List;
@Getter
@Setter
public class UmsMenuNode extends UmsMenu {
@ApiModelProperty(value = "子级菜单")
private List<UmsMenuNode> children;
}

View File

@@ -1,6 +1,7 @@
package com.macro.mall.dto;
import com.macro.mall.model.UmsPermission;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
@@ -13,5 +14,6 @@ import java.util.List;
public class UmsPermissionNode extends UmsPermission {
@Getter
@Setter
@ApiModelProperty(value = "子级权限")
private List<UmsPermissionNode> children;
}

View File

@@ -0,0 +1,20 @@
package com.macro.mall.service;
import com.macro.mall.common.api.CommonResult;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Map;
/**
* 认证服务远程调用
* Created by macro on 2020/7/19.
*/
@FeignClient("mall-auth")
public interface AuthService {
@PostMapping(value = "/oauth/token")
CommonResult getAccessToken(@RequestParam Map<String, String> parameters);
}

View File

@@ -14,8 +14,7 @@ import java.util.List;
public interface PmsProductAttributeService {
/**
* 根据分类分页获取商品属性
*
* @param cid 分类id
* @param cid 分类id
* @param type 0->属性2->参数
*/
List<PmsProductAttribute> getList(Long cid, Integer type, Integer pageSize, Integer pageNum);
@@ -36,14 +35,8 @@ public interface PmsProductAttributeService {
*/
PmsProductAttribute getItem(Long id);
/**
* 批量删除商品属性
*/
@Transactional
int delete(List<Long> ids);
/**
* 获取和分类相关的商品属性
*/
List<ProductAttrInfo> getProductAttrInfo(Long productCategoryId);
}

View File

@@ -0,0 +1,27 @@
package com.macro.mall.service;
import com.macro.mall.model.UmsAdmin;
import com.macro.mall.model.UmsResource;
import java.util.List;
/**
* 后台用户缓存操作类
* Created by macro on 2020/3/13.
*/
public interface UmsAdminCacheService {
/**
* 删除后台用户缓存
*/
void delAdmin(Long adminId);
/**
* 获取缓存后台用户信息
*/
UmsAdmin getAdmin(Long adminId);
/**
* 设置缓存后台用户信息
*/
void setAdmin(UmsAdmin admin);
}

View File

@@ -1,12 +1,10 @@
package com.macro.mall.service;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.common.domain.UserDto;
import com.macro.mall.dto.UmsAdminParam;
import com.macro.mall.dto.UpdateAdminPasswordParam;
import com.macro.mall.model.UmsAdmin;
import com.macro.mall.model.UmsPermission;
import com.macro.mall.model.UmsResource;
import com.macro.mall.model.UmsRole;
import org.springframework.security.core.userdetails.UserDetails;
import com.macro.mall.model.*;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@@ -30,15 +28,9 @@ public interface UmsAdminService {
* 登录功能
* @param username 用户名
* @param password 密码
* @return 生成的JWT的token
* @return 调用认证中心返回结果
*/
String login(String username,String password);
/**
* 刷新token的功能
* @param oldToken 旧的token
*/
String refreshToken(String oldToken);
CommonResult login(String username, String password);
/**
* 根据用户id获取用户
@@ -95,5 +87,10 @@ public interface UmsAdminService {
/**
* 获取用户信息
*/
UserDetails loadUserByUsername(String username);
UserDto loadUserByUsername(String username);
/**
* 获取当前登录后台用户
*/
UmsAdmin getCurrentAdmin();
}

View File

@@ -3,6 +3,7 @@ package com.macro.mall.service;
import com.macro.mall.model.UmsResource;
import java.util.List;
import java.util.Map;
/**
* 后台资源管理Service
@@ -38,4 +39,9 @@ public interface UmsResourceService {
* 查询全部资源
*/
List<UmsResource> listAll();
/**
* 初始化资源角色规则
*/
Map<String,List<String>> initResourceRolesMap();
}

View File

@@ -0,0 +1,45 @@
package com.macro.mall.service.impl;
import com.macro.mall.common.service.RedisService;
import com.macro.mall.model.UmsAdmin;
import com.macro.mall.service.UmsAdminCacheService;
import com.macro.mall.service.UmsAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* UmsAdminCacheService实现类
* Created by macro on 2020/3/13.
*/
@Service
public class UmsAdminCacheServiceImpl implements UmsAdminCacheService {
@Autowired
private UmsAdminService adminService;
@Autowired
private RedisService redisService;
@Value("${redis.database}")
private String REDIS_DATABASE;
@Value("${redis.expire.common}")
private Long REDIS_EXPIRE;
@Value("${redis.key.admin}")
private String REDIS_KEY_ADMIN;
@Override
public void delAdmin(Long adminId) {
String key = REDIS_DATABASE + ":" + REDIS_KEY_ADMIN + ":" + adminId;
redisService.del(key);
}
@Override
public UmsAdmin getAdmin(Long adminId) {
String key = REDIS_DATABASE + ":" + REDIS_KEY_ADMIN + ":" + adminId;
return (UmsAdmin) redisService.get(key);
}
@Override
public void setAdmin(UmsAdmin admin) {
String key = REDIS_DATABASE + ":" + REDIS_KEY_ADMIN + ":" + admin.getId();
redisService.set(key, admin, REDIS_EXPIRE);
}
}

View File

@@ -2,8 +2,14 @@ package com.macro.mall.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.BCrypt;
import cn.hutool.json.JSONUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.bo.AdminUserDetails;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.common.api.ResultCode;
import com.macro.mall.common.constant.AuthConstant;
import com.macro.mall.common.domain.UserDto;
import com.macro.mall.common.exception.Asserts;
import com.macro.mall.dao.UmsAdminPermissionRelationDao;
import com.macro.mall.dao.UmsAdminRoleRelationDao;
import com.macro.mall.dto.UmsAdminParam;
@@ -13,19 +19,13 @@ import com.macro.mall.mapper.UmsAdminMapper;
import com.macro.mall.mapper.UmsAdminPermissionRelationMapper;
import com.macro.mall.mapper.UmsAdminRoleRelationMapper;
import com.macro.mall.model.*;
import com.macro.mall.security.util.JwtTokenUtil;
import com.macro.mall.service.AuthService;
import com.macro.mall.service.UmsAdminCacheService;
import com.macro.mall.service.UmsAdminService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -33,9 +33,7 @@ import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -46,10 +44,6 @@ import java.util.stream.Collectors;
public class UmsAdminServiceImpl implements UmsAdminService {
private static final Logger LOGGER = LoggerFactory.getLogger(UmsAdminServiceImpl.class);
@Autowired
private JwtTokenUtil jwtTokenUtil;
@Autowired
private PasswordEncoder passwordEncoder;
@Autowired
private UmsAdminMapper adminMapper;
@Autowired
private UmsAdminRoleRelationMapper adminRoleRelationMapper;
@@ -61,6 +55,12 @@ public class UmsAdminServiceImpl implements UmsAdminService {
private UmsAdminPermissionRelationDao adminPermissionRelationDao;
@Autowired
private UmsAdminLoginLogMapper loginLogMapper;
@Autowired
private AuthService authService;
@Autowired
private UmsAdminCacheService adminCacheService;
@Autowired
private HttpServletRequest request;
@Override
public UmsAdmin getAdminByUsername(String username) {
@@ -87,30 +87,29 @@ public class UmsAdminServiceImpl implements UmsAdminService {
return null;
}
//将密码进行加密操作
String encodePassword = passwordEncoder.encode(umsAdmin.getPassword());
String encodePassword = BCrypt.hashpw(umsAdmin.getPassword());
umsAdmin.setPassword(encodePassword);
adminMapper.insert(umsAdmin);
return umsAdmin;
}
@Override
public String login(String username, String password) {
String token = null;
//密码需要客户端加密后传递
try {
UserDetails userDetails = loadUserByUsername(username);
if(!passwordEncoder.matches(password,userDetails.getPassword())){
throw new BadCredentialsException("密码不正确");
}
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication);
token = jwtTokenUtil.generateToken(userDetails);
public CommonResult login(String username, String password) {
if(StrUtil.isEmpty(username)||StrUtil.isEmpty(password)){
Asserts.fail("用户名或密码不能为空!");
}
Map<String, String> params = new HashMap<>();
params.put("client_id", AuthConstant.ADMIN_CLIENT_ID);
params.put("client_secret","123456");
params.put("grant_type","password");
params.put("username",username);
params.put("password",password);
CommonResult restResult = authService.getAccessToken(params);
if(ResultCode.SUCCESS.getCode()==restResult.getCode()&&restResult.getData()!=null){
// updateLoginTimeByUsername(username);
insertLoginLog(username);
} catch (AuthenticationException e) {
LOGGER.warn("登录异常:{}", e.getMessage());
}
return token;
return restResult;
}
/**
@@ -119,6 +118,7 @@ public class UmsAdminServiceImpl implements UmsAdminService {
*/
private void insertLoginLog(String username) {
UmsAdmin admin = getAdminByUsername(username);
if(admin==null) return;
UmsAdminLoginLog loginLog = new UmsAdminLoginLog();
loginLog.setAdminId(admin.getId());
loginLog.setCreateTime(new Date());
@@ -139,11 +139,6 @@ public class UmsAdminServiceImpl implements UmsAdminService {
adminMapper.updateByExampleSelective(record, example);
}
@Override
public String refreshToken(String oldToken) {
return jwtTokenUtil.refreshHeadToken(oldToken);
}
@Override
public UmsAdmin getItem(Long id) {
return adminMapper.selectByPrimaryKey(id);
@@ -173,15 +168,19 @@ public class UmsAdminServiceImpl implements UmsAdminService {
if(StrUtil.isEmpty(admin.getPassword())){
admin.setPassword(null);
}else{
admin.setPassword(passwordEncoder.encode(admin.getPassword()));
admin.setPassword(BCrypt.hashpw(admin.getPassword()));
}
}
return adminMapper.updateByPrimaryKeySelective(admin);
int count = adminMapper.updateByPrimaryKeySelective(admin);
adminCacheService.delAdmin(id);
return count;
}
@Override
public int delete(Long id) {
return adminMapper.deleteByPrimaryKey(id);
int count = adminMapper.deleteByPrimaryKey(id);
adminCacheService.delAdmin(id);
return count;
}
@Override
@@ -271,22 +270,46 @@ public class UmsAdminServiceImpl implements UmsAdminService {
return -2;
}
UmsAdmin umsAdmin = adminList.get(0);
if(!passwordEncoder.matches(param.getOldPassword(),umsAdmin.getPassword())){
if(!BCrypt.checkpw(param.getOldPassword(),umsAdmin.getPassword())){
return -3;
}
umsAdmin.setPassword(passwordEncoder.encode(param.getNewPassword()));
umsAdmin.setPassword(BCrypt.hashpw(param.getNewPassword()));
adminMapper.updateByPrimaryKey(umsAdmin);
adminCacheService.delAdmin(umsAdmin.getId());
return 1;
}
@Override
public UserDetails loadUserByUsername(String username){
public UserDto loadUserByUsername(String username){
//获取用户信息
UmsAdmin admin = getAdminByUsername(username);
if (admin != null) {
List<UmsResource> resourceList = getResourceList(admin.getId());
return new AdminUserDetails(admin,resourceList);
List<UmsRole> roleList = getRoleList(admin.getId());
UserDto userDTO = new UserDto();
BeanUtils.copyProperties(admin,userDTO);
if(CollUtil.isNotEmpty(roleList)){
List<String> roleStrList = roleList.stream().map(item -> item.getId() + "_" + item.getName()).collect(Collectors.toList());
userDTO.setRoles(roleStrList);
}
return userDTO;
}
return null;
}
@Override
public UmsAdmin getCurrentAdmin() {
String userStr = request.getHeader(AuthConstant.USER_TOKEN_HEADER);
if(StrUtil.isEmpty(userStr)){
Asserts.fail(ResultCode.UNAUTHORIZED);
}
UserDto userDto = JSONUtil.toBean(userStr, UserDto.class);
UmsAdmin admin = adminCacheService.getAdmin(userDto.getId());
if(admin!=null){
return admin;
}else{
admin = adminMapper.selectByPrimaryKey(userDto.getId());
adminCacheService.setAdmin(admin);
return admin;
}
throw new UsernameNotFoundException("用户名或密码错误");
}
}

View File

@@ -2,15 +2,20 @@ package com.macro.mall.service.impl;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.common.constant.AuthConstant;
import com.macro.mall.common.service.RedisService;
import com.macro.mall.mapper.UmsResourceMapper;
import com.macro.mall.model.UmsResource;
import com.macro.mall.model.UmsResourceExample;
import com.macro.mall.mapper.UmsRoleMapper;
import com.macro.mall.mapper.UmsRoleResourceRelationMapper;
import com.macro.mall.model.*;
import com.macro.mall.service.UmsAdminCacheService;
import com.macro.mall.service.UmsResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
* 后台资源管理Service实现类
@@ -20,16 +25,28 @@ import java.util.List;
public class UmsResourceServiceImpl implements UmsResourceService {
@Autowired
private UmsResourceMapper resourceMapper;
@Autowired
private UmsRoleMapper roleMapper;
@Autowired
private UmsRoleResourceRelationMapper roleResourceRelationMapper;
@Autowired
private RedisService redisService;
@Value("${spring.application.name}")
private String applicationName;
@Override
public int create(UmsResource umsResource) {
umsResource.setCreateTime(new Date());
return resourceMapper.insert(umsResource);
int count = resourceMapper.insert(umsResource);
initResourceRolesMap();
return count;
}
@Override
public int update(Long id, UmsResource umsResource) {
umsResource.setId(id);
return resourceMapper.updateByPrimaryKeySelective(umsResource);
int count = resourceMapper.updateByPrimaryKeySelective(umsResource);
initResourceRolesMap();
return count;
}
@Override
@@ -39,7 +56,9 @@ public class UmsResourceServiceImpl implements UmsResourceService {
@Override
public int delete(Long id) {
return resourceMapper.deleteByPrimaryKey(id);
int count = resourceMapper.deleteByPrimaryKey(id);
initResourceRolesMap();
return count;
}
@Override
@@ -63,4 +82,21 @@ public class UmsResourceServiceImpl implements UmsResourceService {
public List<UmsResource> listAll() {
return resourceMapper.selectByExample(new UmsResourceExample());
}
@Override
public Map<String,List<String>> initResourceRolesMap() {
Map<String,List<String>> resourceRoleMap = new TreeMap<>();
List<UmsResource> resourceList = resourceMapper.selectByExample(new UmsResourceExample());
List<UmsRole> roleList = roleMapper.selectByExample(new UmsRoleExample());
List<UmsRoleResourceRelation> relationList = roleResourceRelationMapper.selectByExample(new UmsRoleResourceRelationExample());
for (UmsResource resource : resourceList) {
Set<Long> roleIds = relationList.stream().filter(item -> item.getResourceId().equals(resource.getId())).map(UmsRoleResourceRelation::getRoleId).collect(Collectors.toSet());
List<String> roleNames = roleList.stream().filter(item -> roleIds.contains(item.getId())).map(item -> item.getId() + "_" + item.getName()).collect(Collectors.toList());
resourceRoleMap.put("/"+applicationName+resource.getUrl(),roleNames);
}
redisService.del(AuthConstant.RESOURCE_ROLES_MAP_KEY);
redisService.hSetAll(AuthConstant.RESOURCE_ROLES_MAP_KEY, resourceRoleMap);
return resourceRoleMap;
}
}

View File

@@ -8,6 +8,8 @@ import com.macro.mall.mapper.UmsRoleMenuRelationMapper;
import com.macro.mall.mapper.UmsRolePermissionRelationMapper;
import com.macro.mall.mapper.UmsRoleResourceRelationMapper;
import com.macro.mall.model.*;
import com.macro.mall.service.UmsAdminCacheService;
import com.macro.mall.service.UmsResourceService;
import com.macro.mall.service.UmsRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -35,6 +37,8 @@ public class UmsRoleServiceImpl implements UmsRoleService {
private UmsRolePermissionRelationDao rolePermissionRelationDao;
@Autowired
private UmsRoleDao roleDao;
@Autowired
private UmsResourceService resourceService;
@Override
public int create(UmsRole role) {
role.setCreateTime(new Date());
@@ -53,7 +57,9 @@ public class UmsRoleServiceImpl implements UmsRoleService {
public int delete(List<Long> ids) {
UmsRoleExample example = new UmsRoleExample();
example.createCriteria().andIdIn(ids);
return roleMapper.deleteByExample(example);
int count = roleMapper.deleteByExample(example);
resourceService.initResourceRolesMap();
return count;
}
@Override
@@ -137,6 +143,7 @@ public class UmsRoleServiceImpl implements UmsRoleService {
relation.setResourceId(resourceId);
roleResourceRelationMapper.insert(relation);
}
resourceService.initResourceRolesMap();
return resourceIds.size();
}
}

Some files were not shown because too many files have changed in this diff Show More