Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-microservice-exam
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
汪想
spring-microservice-exam
Commits
5d59e233
Commit
5d59e233
authored
May 22, 2019
by
tangyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化、增加docker-compose部署脚本
parent
88915a77
Show whitespace changes
Inline
Side-by-side
Showing
54 changed files
with
380 additions
and
369 deletions
+380
-369
start.sh
doc/deploy/start.sh
+103
-0
在线考试系统V2.0_部署文档(docker版).md
doc/在线考试系统V2.0_部署文档(docker版).md
+17
-45
TokenCacheMap.java
...n/java/com/github/tangyi/gateway/cache/TokenCacheMap.java
+0
-92
RegistrySwaggerResourcesProvider.java
...ngyi/gateway/config/RegistrySwaggerResourcesProvider.java
+15
-13
RouteInitConfig.java
...ava/com/github/tangyi/gateway/config/RouteInitConfig.java
+4
-5
GatewayRouteController.java
...hub/tangyi/gateway/controller/GatewayRouteController.java
+2
-9
SwaggerController.java
...m/github/tangyi/gateway/controller/SwaggerController.java
+0
-1
DecodePasswordFilter.java
...m/github/tangyi/gateway/filters/DecodePasswordFilter.java
+5
-4
PreviewFilter.java
...java/com/github/tangyi/gateway/filters/PreviewFilter.java
+4
-4
TokenRequestGlobalFilter.java
...thub/tangyi/gateway/filters/TokenRequestGlobalFilter.java
+6
-9
TokenResponseGlobalFilter.java
...hub/tangyi/gateway/filters/TokenResponseGlobalFilter.java
+7
-3
ValidateCodeFilter.java
...com/github/tangyi/gateway/filters/ValidateCodeFilter.java
+5
-4
GatewayRouteReceiver.java
.../github/tangyi/gateway/receiver/GatewayRouteReceiver.java
+3
-2
DynamicRouteService.java
...om/github/tangyi/gateway/service/DynamicRouteService.java
+6
-2
SwaggerConfig.java
...ain/java/com/github/tangyi/auth/config/SwaggerConfig.java
+17
-1
OauthClientDetailsController.java
.../tangyi/auth/controller/OauthClientDetailsController.java
+4
-4
ExaminationInitConfig.java
.../com/github/tangyi/exam/config/ExaminationInitConfig.java
+4
-5
SwaggerConfig.java
...ain/java/com/github/tangyi/exam/config/SwaggerConfig.java
+17
-1
AnswerController.java
...a/com/github/tangyi/exam/controller/AnswerController.java
+3
-3
CourseController.java
...a/com/github/tangyi/exam/controller/CourseController.java
+3
-3
ExamRecordController.java
...m/github/tangyi/exam/controller/ExamRecordController.java
+5
-7
ExaminationController.java
.../github/tangyi/exam/controller/ExaminationController.java
+4
-5
IncorrectAnswerController.java
...hub/tangyi/exam/controller/IncorrectAnswerController.java
+4
-5
KnowledgeController.java
...om/github/tangyi/exam/controller/KnowledgeController.java
+4
-5
SubjectBankController.java
.../github/tangyi/exam/controller/SubjectBankController.java
+4
-4
SubjectCategoryController.java
...hub/tangyi/exam/controller/SubjectCategoryController.java
+3
-3
SubjectController.java
.../com/github/tangyi/exam/controller/SubjectController.java
+6
-9
RabbitSubmitExaminationReceiver.java
...ithub/tangyi/exam/mq/RabbitSubmitExaminationReceiver.java
+4
-5
AnswerService.java
...in/java/com/github/tangyi/exam/service/AnswerService.java
+6
-9
ExamRecordService.java
...ava/com/github/tangyi/exam/service/ExamRecordService.java
+6
-9
ExaminationService.java
...va/com/github/tangyi/exam/service/ExaminationService.java
+3
-3
SubjectService.java
...n/java/com/github/tangyi/exam/service/SubjectService.java
+4
-5
RouteInitConfig.java
...n/java/com/github/tangyi/user/config/RouteInitConfig.java
+5
-7
SwaggerConfig.java
...ain/java/com/github/tangyi/user/config/SwaggerConfig.java
+17
-1
AttachmentController.java
...m/github/tangyi/user/controller/AttachmentController.java
+3
-3
DashboardController.java
...om/github/tangyi/user/controller/DashboardController.java
+4
-5
DeptController.java
...ava/com/github/tangyi/user/controller/DeptController.java
+3
-3
LogController.java
...java/com/github/tangyi/user/controller/LogController.java
+3
-3
MenuController.java
...ava/com/github/tangyi/user/controller/MenuController.java
+3
-3
RoleController.java
...ava/com/github/tangyi/user/controller/RoleController.java
+4
-5
RouteController.java
...va/com/github/tangyi/user/controller/RouteController.java
+4
-5
SysConfigController.java
...om/github/tangyi/user/controller/SysConfigController.java
+3
-3
UserController.java
...ava/com/github/tangyi/user/controller/UserController.java
+6
-9
ValidateCodeController.java
...github/tangyi/user/controller/ValidateCodeController.java
+4
-5
RouteReceiver.java
...n/java/com/github/tangyi/user/receiver/RouteReceiver.java
+3
-3
AttachmentService.java
...ava/com/github/tangyi/user/service/AttachmentService.java
+5
-4
FastDfsService.java
...n/java/com/github/tangyi/user/service/FastDfsService.java
+14
-7
MenuService.java
...main/java/com/github/tangyi/user/service/MenuService.java
+3
-3
RoleMenuService.java
.../java/com/github/tangyi/user/service/RoleMenuService.java
+3
-3
RoleService.java
...main/java/com/github/tangyi/user/service/RoleService.java
+4
-5
UserRoleService.java
.../java/com/github/tangyi/user/service/UserRoleService.java
+3
-3
UserService.java
...main/java/com/github/tangyi/user/service/UserService.java
+6
-8
MenuUtil.java
.../src/main/java/com/github/tangyi/user/utils/MenuUtil.java
+1
-1
UserUtils.java
...src/main/java/com/github/tangyi/user/utils/UserUtils.java
+1
-1
No files found.
doc/deploy/start.sh
0 → 100644
View file @
5d59e233
#!/bin/sh
# 配置文件根目录,固定是spring-microservice-exam
DOCKERHOME
=
/spring-microservice-exam
# 镜像名称前缀、标签
BASE_IMAGE_NAME
=
registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam
BSEE_IMAGE_TAG
=
2.0
# 各服务的镜像名称
CONFIG_SERVICE
=
$BASE_IMAGE_NAME
/config-service:
$BSEE_IMAGE_TAG
AUTH_SERVICE
=
$BASE_IMAGE_NAME
/auth-service:
$BSEE_IMAGE_TAG
USER_SERVICE
=
$BASE_IMAGE_NAME
/user-service:
$BSEE_IMAGE_TAG
EXAM_SERVICE
=
$BASE_IMAGE_NAME
/exam-service:
$BSEE_IMAGE_TAG
GATEWAY_SERVICE
=
$BASE_IMAGE_NAME
/gateway-service:
$BSEE_IMAGE_TAG
MONITOR_SERVICE
=
$BASE_IMAGE_NAME
/monitor-service:
$BSEE_IMAGE_TAG
UI_SERVICE
=
$BASE_IMAGE_NAME
/spring-microservice-exam-ui:
$BSEE_IMAGE_TAG
WEB_SERVICE
=
$BASE_IMAGE_NAME
/spring-microservice-exam-web:
$BSEE_IMAGE_TAG
case
"
$1
"
in
# 删除容器
removeAll
)
echo
"* 正在删除容器..."
time
docker
rm
$(
docker ps
-aq
)
-f
echo
"* 删除容器成功..."
;;
# 拉取镜像
pull
)
echo
"* 正在拉取后端镜像..."
time
docker pull
$CONFIG_SERVICE
time
docker pull
$AUTH_SERVICE
time
docker pull
$USER_SERVICE
time
docker pull
$EXAM_SERVICE
time
docker pull
$GATEWAY_SERVICE
time
docker pull
$MONITOR_SERVICE
echo
"* 开始拉取前端镜像..."
time
docker pull
$UI_SERVICE
time
docker pull
$WEB_SERVICE
echo
"* 拉取镜像成功..."
;;
# 运行镜像
run
)
echo
"* 开始运行基础镜像..."
time
docker-compose
-f
$DOCKERHOME
/docker-compose-base.yml up
-d
echo
"* 等待10s..."
sleep
10
echo
"* 开始运行后端服务镜像..."
time
docker-compose
-f
$DOCKERHOME
/docker-compose-services.yml up
-d
echo
"* 等待10s..."
sleep
10
echo
"* 开始运行前端服务镜像..."
time
docker-compose
-f
$DOCKERHOME
/docker-compose-nginx.yml up
-d
echo
"* 运行成功..."
;;
# 拉取镜像并运行
pullrun
)
echo
"* 正在拉取后端镜像..."
time
docker pull
$CONFIG_SERVICE
time
docker pull
$AUTH_SERVICE
time
docker pull
$USER_SERVICE
time
docker pull
$EXAM_SERVICE
time
docker pull
$GATEWAY_SERVICE
time
docker pull
$MONITOR_SERVICE
echo
"* 开始拉取前端镜像..."
time
docker pull
$UI_SERVICE
time
docker pull
$WEB_SERVICE
echo
"* 拉取镜像成功..."
echo
"* 开始运行基础镜像..."
time
docker-compose
-f
$DOCKERHOME
/docker-compose-base.yml up
-d
echo
"* 等待10s..."
sleep
10
echo
"* 开始运行后端服务镜像..."
time
docker-compose
-f
$DOCKERHOME
/docker-compose-services.yml up
-d
echo
"* 等待10s..."
sleep
10
echo
"* 开始运行前端服务镜像..."
time
docker-compose
-f
$DOCKERHOME
/docker-compose-nginx.yml up
-d
echo
"* 运行成功..."
;;
# 停止容器
stop
)
echo
"* 正在停止容器..."
time
docker-compose
-f
$DOCKERHOME
/docker-compose-nginx.yml stop
time
docker-compose
-f
$DOCKERHOME
/docker-compose-services.yml stop
time
docker-compose
-f
$DOCKERHOME
/docker-compose-base.yml stop
echo
"* 停止容器成功..."
;;
# 重启容器
restart
)
echo
"* 正在停止镜像..."
time
docker-compose
-f
$DOCKERHOME
/docker-compose-nginx.yml restart
time
docker-compose
-f
$DOCKERHOME
/docker-compose-services.yml restart
time
docker-compose
-f
$DOCKERHOME
/docker-compose-base.yml restart
;;
# 其它
*
)
echo
"* ..."
;;
esac
exit
0
\ No newline at end of file
doc/在线考试系统V2.0_部署文档(docker版).md
View file @
5d59e233
主要介绍如
何基于docker、docker-compose部署后端项目、前端项目,主要的步骤是本地构建镜像,推送的远程仓库,远程服务器从远程仓库拉去镜像运行
主要介绍如
何基于docker、docker-compose部署后端项目、前端项目,主要的步骤是本地构建镜像,推送的远程仓库,远程服务器从远程仓库拉去镜像运行
...
...
@@ -26,40 +26,14 @@ windows系统安装`Docker for Windows`
参考:
[
fastdfs文件系统单机环境搭建和spring boot整合
](
https://blog.csdn.net/baidu_36415076/article/details/79505027
)
## 拉取镜像
1.
登录阿里云Docker Registry
```
docker login --username=你的阿里云账号 registry.cn-hangzhou.aliyuncs.com
如:
docker login --username=tb70177569 registry.cn-hangzhou.aliyuncs.com
```
2.
拉取镜像
拉取各服务的镜像:
```
后端镜像:
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/config-service:2.0
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/auth-service:2.0
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/user-service:2.0
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/exam-service:2.0
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/gateway-service:2.0
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/monitor-service:2.0
前端镜像:
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/spring-microservice-exam-ui:2.0
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/spring-microservice-exam-web:2.0
```
## 修改配置
在服务器的根目录创建文件夹:
`spring-microservice-exam`
将源码目录下的
`docker-compose.env`
、
`docker-compose-base.yml`
、
`docker-compose-services.yml`
、
`docker-compose-nginx.yml`
、
`nginx.conf`
上传到服务器的
`/spring-microservice-exam/`
目录下
将启动脚本
`doc/deploy/start.sh`
上传到服务器的
`/spring-microservice-exam/`
目录下
目录结构:

...
...
@@ -72,26 +46,17 @@ docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/spring-mi
## 运行
1.
按顺序执行:
1.
登录阿里云Docker Registry
```
运行基础服务:
docker-compose -f docker-compose-base.yml up -d
运行后端服务:
docker-compose -f docker-compose-services.yml up -d
$ docker login --username=你的阿里云账号 registry.cn-hangzhou.aliyuncs.com
运行前端服务:
docker-compose -f docker-compose-nginx.yml up -d
如:docker login --username=tb70177569 registry.cn-hangzhou.aliyuncs.com
```
`-d`
表示后台运行
2.
拉取镜像并启动:
`./start.sh pullrun`
2.
检查是否启动成功
```
docker ps
```
3.
检查是否启动成功:
`docker ps`
## 访问
...
...
@@ -99,6 +64,13 @@ docker ps
后台地址:ip:81
## 其它命令
1.
停止容器:
`./start.sh stop`
2.
删除所有容器:
`./start.sh removeAll`
3.
重启所有容器:
`./start.sh restart`
4.
拉取并启动:
`./start.sh pullrun`
## 参考资料
-
[
安装docker
](
https://www.cnblogs.com/yufeng218/p/8370670.html
)
...
...
gateway-service/src/main/java/com/github/tangyi/gateway/cache/TokenCacheMap.java
deleted
100644 → 0
View file @
88915a77
package
com
.
github
.
tangyi
.
gateway
.
cache
;
import
com.github.tangyi.gateway.model.AccessToken
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* 缓存token
*
* @author tangyi
* @date 2019/5/19 18:01
*/
@Slf4j
public
class
TokenCacheMap
{
private
static
final
long
DEFAULT_TIMEOUT
=
30000
;
/**
* 单例
*/
private
static
TokenCacheMap
instance
;
/**
* concurrentHashMap
*/
private
static
ConcurrentHashMap
<
String
,
AccessToken
>
concurrentHashMap
;
public
TokenCacheMap
()
{
concurrentHashMap
=
new
ConcurrentHashMap
<>();
new
ClearThread
().
start
();
}
/**
* 获取单例
*
* @return TokenCacheMap
*/
public
static
synchronized
TokenCacheMap
getInstance
()
{
if
(
instance
==
null
)
{
instance
=
new
TokenCacheMap
();
}
return
instance
;
}
/**
* 获取AccessToken
*
* @param key key
* @return AccessToken
*/
public
static
AccessToken
get
(
String
key
)
{
return
concurrentHashMap
.
get
(
key
);
}
/**
* 设置AccessToken
*
* @param key key
* @param accessToken accessToken
*/
public
static
void
set
(
String
key
,
AccessToken
accessToken
)
{
concurrentHashMap
.
put
(
key
,
accessToken
);
}
/**
* 定时清除线程
*/
private
class
ClearThread
extends
Thread
{
ClearThread
()
{
setName
(
"clear token cache thread"
);
}
public
void
run
()
{
while
(
true
)
{
try
{
long
now
=
System
.
currentTimeMillis
();
concurrentHashMap
.
keySet
().
forEach
(
key
->
{
AccessToken
accessToken
=
concurrentHashMap
.
get
(
key
);
// 定时清除
if
(
now
-
accessToken
.
getCreateTime
()
>=
accessToken
.
getExpiresIn
())
{
concurrentHashMap
.
remove
(
key
);
}
});
Thread
.
sleep
(
DEFAULT_TIMEOUT
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
}
}
}
}
gateway-service/src/main/java/com/github/tangyi/gateway/config/RegistrySwaggerResourcesProvider.java
View file @
5d59e233
package
com
.
github
.
tangyi
.
gateway
.
config
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
lombok.AllArgsConstructor
;
import
org.springframework.cloud.gateway.config.GatewayProperties
;
import
org.springframework.cloud.gateway.handler.predicate.PredicateDefinition
;
import
org.springframework.cloud.gateway.route.RouteDefinition
;
import
org.springframework.cloud.gateway.route.RouteLocator
;
import
org.springframework.cloud.gateway.support.NameUtils
;
import
org.springframework.context.annotation.Primary
;
...
...
@@ -11,15 +13,18 @@ import springfox.documentation.swagger.web.SwaggerResourcesProvider;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* Swagger聚合文档
* 目前问题:结合动态更新路由之后,GatewayProperties获取不到新的路由列表,导致swagger-ui显示不了
*
* @author tangyi
* @date 2019/3/26 15:39
*/
@Component
@Primary
@AllArgsConstructor
public
class
RegistrySwaggerResourcesProvider
implements
SwaggerResourcesProvider
{
private
static
final
String
API_URI
=
"/v2/api-docs"
;
...
...
@@ -30,13 +35,6 @@ public class RegistrySwaggerResourcesProvider implements SwaggerResourcesProvide
private
final
SwaggerProviderConfig
swaggerProviderConfig
;
@Autowired
public
RegistrySwaggerResourcesProvider
(
RouteLocator
routeLocator
,
GatewayProperties
gatewayProperties
,
SwaggerProviderConfig
swaggerProviderConfig
)
{
this
.
routeLocator
=
routeLocator
;
this
.
gatewayProperties
=
gatewayProperties
;
this
.
swaggerProviderConfig
=
swaggerProviderConfig
;
}
@Override
public
List
<
SwaggerResource
>
get
()
{
List
<
SwaggerResource
>
resources
=
new
ArrayList
<>();
...
...
@@ -48,12 +46,16 @@ public class RegistrySwaggerResourcesProvider implements SwaggerResourcesProvide
routes
.
add
(
route
.
getId
());
});
// 结合配置的route-路径(Path),和route过滤,只获取有效的route节点
gatewayProperties
.
getRoutes
().
stream
().
filter
(
routeDefinition
->
routes
.
contains
(
routeDefinition
.
getId
()))
.
forEach
(
routeDefinition
->
routeDefinition
.
getPredicates
().
stream
()
.
filter
(
predicateDefinition
->
(
"Path"
).
equalsIgnoreCase
(
predicateDefinition
.
getName
()))
.
forEach
(
predicateDefinition
->
resources
.
add
(
swaggerResource
(
routeDefinition
.
getId
(),
List
<
RouteDefinition
>
routeDefinitions
=
gatewayProperties
.
getRoutes
().
stream
().
filter
(
routeDefinition
->
routes
.
contains
(
routeDefinition
.
getId
())).
collect
(
Collectors
.
toList
());
routeDefinitions
.
forEach
(
routeDefinition
->
{
List
<
PredicateDefinition
>
predicates
=
routeDefinition
.
getPredicates
().
stream
()
.
filter
(
predicateDefinition
->
(
"Path"
).
equalsIgnoreCase
(
predicateDefinition
.
getName
())).
collect
(
Collectors
.
toList
());
predicates
.
forEach
(
predicateDefinition
->
{
resources
.
add
(
swaggerResource
(
routeDefinition
.
getId
(),
predicateDefinition
.
getArgs
().
get
(
NameUtils
.
GENERATED_NAME_PREFIX
+
"0"
)
.
replace
(
"/**"
,
API_URI
)))));
.
replace
(
"/**"
,
API_URI
)));
});
});
return
resources
;
}
...
...
gateway-service/src/main/java/com/github/tangyi/gateway/config/RouteInitConfig.java
View file @
5d59e233
...
...
@@ -4,9 +4,9 @@ import com.github.tangyi.common.core.constant.CommonConstant;
import
com.github.tangyi.common.core.model.Route
;
import
com.github.tangyi.common.core.utils.JsonMapper
;
import
com.github.tangyi.gateway.receiver.GatewayRouteReceiver
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.core.RedisTemplate
;
...
...
@@ -22,14 +22,13 @@ import java.util.List;
* @date 2019/4/2 14:40
*/
@Slf4j
@AllArgsConstructor
@Configuration
public
class
RouteInitConfig
{
@Autowired
private
RedisTemplate
redisTemplate
;
private
final
RedisTemplate
redisTemplate
;
@Autowired
private
GatewayRouteReceiver
gatewayRouteReceiver
;
private
final
GatewayRouteReceiver
gatewayRouteReceiver
;
@PostConstruct
public
void
initRoute
()
{
...
...
gateway-service/src/main/java/com/github/tangyi/gateway/controller/GatewayRouteController.java
View file @
5d59e233
...
...
@@ -6,9 +6,9 @@ import com.github.tangyi.common.core.vo.RouteFilterVo;
import
com.github.tangyi.common.core.vo.RoutePredicateVo
;
import
com.github.tangyi.common.core.vo.RouteVo
;
import
com.github.tangyi.gateway.service.DynamicRouteService
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.amqp.core.AmqpTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.gateway.filter.FilterDefinition
;
import
org.springframework.cloud.gateway.filter.GatewayFilter
;
import
org.springframework.cloud.gateway.handler.predicate.PredicateDefinition
;
...
...
@@ -33,6 +33,7 @@ import java.util.Map;
* @date 2019/3/27 10:59
*/
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping
(
"/api/route"
)
public
class
GatewayRouteController
{
...
...
@@ -45,14 +46,6 @@ public class GatewayRouteController {
private
final
AmqpTemplate
amqpTemplate
;
@Autowired
public
GatewayRouteController
(
RouteDefinitionLocator
routeDefinitionLocator
,
RouteLocator
routeLocator
,
DynamicRouteService
dynamicRouteService
,
AmqpTemplate
amqpTemplate
)
{
this
.
routeDefinitionLocator
=
routeDefinitionLocator
;
this
.
routeLocator
=
routeLocator
;
this
.
dynamicRouteService
=
dynamicRouteService
;
this
.
amqpTemplate
=
amqpTemplate
;
}
/**
* 获取路由信息列表
*
...
...
gateway-service/src/main/java/com/github/tangyi/gateway/controller/SwaggerController.java
View file @
5d59e233
...
...
@@ -17,7 +17,6 @@ import java.util.Optional;
* @author tangyi
* @date 2019/3/26 17:01
*/
@RestController
@RequestMapping
(
"/swagger-resources"
)
public
class
SwaggerController
{
...
...
gateway-service/src/main/java/com/github/tangyi/gateway/filters/DecodePasswordFilter.java
View file @
5d59e233
package
com
.
github
.
tangyi
.
gateway
.
filters
;
import
cn.hutool.core.codec.Base64
;
import
cn.hutool.core.util.CharsetUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.github.tangyi.gateway.constants.GatewayConstant
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -11,6 +10,7 @@ import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import
org.springframework.cloud.gateway.filter.GlobalFilter
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.Ordered
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
import
org.springframework.web.server.ServerWebExchange
;
...
...
@@ -21,6 +21,7 @@ import javax.crypto.Cipher;
import
javax.crypto.spec.IvParameterSpec
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.net.URI
;
import
java.nio.charset.StandardCharsets
;
/**
* 解密过滤器
...
...
@@ -50,7 +51,7 @@ public class DecodePasswordFilter implements GlobalFilter, Ordered {
// 请求的URI
URI
uri
=
request
.
getURI
();
// 获取token的请求
if
(
"POST"
.
equal
s
(
request
.
getMethodValue
())
&&
StrUtil
.
containsAnyIgnoreCase
(
uri
.
getPath
(),
GatewayConstant
.
OAUTH_TOKEN_URL
,
GatewayConstant
.
REGISTER
,
if
(
HttpMethod
.
POST
.
matche
s
(
request
.
getMethodValue
())
&&
StrUtil
.
containsAnyIgnoreCase
(
uri
.
getPath
(),
GatewayConstant
.
OAUTH_TOKEN_URL
,
GatewayConstant
.
REGISTER
,
GatewayConstant
.
MOBILE_TOKEN_URL
))
{
String
grantType
=
request
.
getQueryParams
().
getFirst
(
GatewayConstant
.
GRANT_TYPE
);
// 授权类型为密码模式则解密
...
...
@@ -94,7 +95,7 @@ public class DecodePasswordFilter implements GlobalFilter, Ordered {
private
static
String
decryptAES
(
String
data
,
String
pass
)
throws
Exception
{
Cipher
cipher
=
Cipher
.
getInstance
(
DEFAULT_CIPHER_ALGORITHM
);
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
new
SecretKeySpec
(
pass
.
getBytes
(),
KEY_ALGORITHM
),
new
IvParameterSpec
(
pass
.
getBytes
()));
byte
[]
result
=
cipher
.
doFinal
(
Base64
.
decode
(
data
.
getBytes
(
CharsetUtil
.
UTF_8
)));
return
new
String
(
result
,
CharsetUtil
.
UTF_8
);
byte
[]
result
=
cipher
.
doFinal
(
Base64
.
decode
(
data
.
getBytes
(
StandardCharsets
.
UTF_8
)));
return
new
String
(
result
,
StandardCharsets
.
UTF_8
);
}
}
gateway-service/src/main/java/com/github/tangyi/gateway/filters/PreviewFilter.java
View file @
5d59e233
...
...
@@ -2,8 +2,8 @@ package com.github.tangyi.gateway.filters;
import
cn.hutool.core.util.StrUtil
;
import
com.github.tangyi.gateway.config.PreviewConfig
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.cloud.gateway.filter.GatewayFilterChain
;
import
org.springframework.cloud.gateway.filter.GlobalFilter
;
...
...
@@ -26,19 +26,19 @@ import java.util.List;
* @date 2019/4/23 10:54
*/
@Slf4j
@AllArgsConstructor
@Configuration
@ConditionalOnProperty
(
prefix
=
"preview"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
public
class
PreviewFilter
implements
GlobalFilter
,
Ordered
{
@Autowired
private
PreviewConfig
previewConfig
;
private
final
PreviewConfig
previewConfig
;
@Override
public
Mono
<
Void
>
filter
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
)
{
// 当前请求
ServerHttpRequest
request
=
exchange
.
getRequest
();
// enabled为false、GET请求、忽略的URL,直接向下执行
log
.
debug
(
"preview.enabled:{}"
,
previewConfig
.
isEnabled
());
log
.
trace
(
"preview.enabled:{}"
,
previewConfig
.
isEnabled
());
if
(!
previewConfig
.
isEnabled
()
||
StrUtil
.
equalsIgnoreCase
(
request
.
getMethodValue
(),
HttpMethod
.
GET
.
name
())
||
isIgnore
(
request
.
getURI
().
getPath
()))
return
chain
.
filter
(
exchange
);
log
.
warn
(
"演示环境不能操作,{},{}"
,
request
.
getMethodValue
(),
request
.
getURI
().
getPath
());
...
...
gateway-service/src/main/java/com/github/tangyi/gateway/filters/TokenRequestGlobalFilter.java
View file @
5d59e233
...
...
@@ -16,6 +16,7 @@ import org.springframework.core.Ordered;
import
org.springframework.core.io.buffer.DataBuffer
;
import
org.springframework.core.io.buffer.DataBufferUtils
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
import
org.springframework.http.server.reactive.ServerHttpResponseDecorator
;
...
...
@@ -24,8 +25,8 @@ import org.springframework.web.server.ServerWebExchange;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.nio.charset.StandardCharsets
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -39,7 +40,7 @@ import java.util.concurrent.TimeUnit;
@Component
public
class
TokenRequestGlobalFilter
implements
GlobalFilter
,
Ordered
{
private
final
RedisTemplate
redisTemplate
;
private
final
RedisTemplate
<
String
,
String
>
redisTemplate
;
/**
* 连接器
...
...
@@ -67,7 +68,7 @@ public class TokenRequestGlobalFilter implements GlobalFilter, Ordered {
ServerHttpRequest
request
=
exchange
.
getRequest
();
// 请求的URI
URI
uri
=
request
.
getURI
();
if
(
"POST"
.
equal
s
(
request
.
getMethodValue
())
if
(
HttpMethod
.
POST
.
matche
s
(
request
.
getMethodValue
())
&&
StrUtil
.
containsAnyIgnoreCase
(
uri
.
getPath
(),
GatewayConstant
.
OAUTH_TOKEN_URL
,
GatewayConstant
.
REGISTER
,
GatewayConstant
.
MOBILE_TOKEN_URL
))
{
String
grantType
=
request
.
getQueryParams
().
getFirst
(
GatewayConstant
.
GRANT_TYPE
);
// 授权类型为密码模式
...
...
@@ -86,11 +87,7 @@ public class TokenRequestGlobalFilter implements GlobalFilter, Ordered {
dataBuffer
.
read
(
content
);
// 释放缓存
DataBufferUtils
.
release
(
dataBuffer
);
try
{
contentList
.
add
(
new
String
(
content
,
"utf-8"
));
}
catch
(
IOException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
contentList
.
add
(
new
String
(
content
,
StandardCharsets
.
UTF_8
));
});
// 因为返回的数据量大时,获取到的buffer是不完整的,所以需要连接多个buffer
String
accessTokenContent
=
joiner
.
join
(
contentList
);
...
...
@@ -104,7 +101,7 @@ public class TokenRequestGlobalFilter implements GlobalFilter, Ordered {
String
converted
=
JsonMapper
.
getInstance
().
toJson
(
accessToken
);
log
.
trace
(
"转换token结果:{}"
,
converted
);
// 将真正的access_token,refresh_token存入Redis,建立jti->access_token的映射关系,失效时间为token的失效时间
// 暂时用Redis
,可以考虑用内存队列实现来提高性能,参考TokenCacheMap
// 暂时用Redis
redisTemplate
.
opsForValue
().
set
(
GatewayConstant
.
GATEWAY_ACCESS_TOKENS
+
accessToken
.
getJti
(),
realAccessToken
,
accessToken
.
getExpiresIn
(),
TimeUnit
.
SECONDS
);
redisTemplate
.
opsForValue
().
set
(
GatewayConstant
.
GATEWAY_REFRESH_TOKENS
+
accessToken
.
getJti
(),
realRefreshToken
,
REFRESH_TOKEN_EXPIRE
,
TimeUnit
.
SECONDS
);
log
.
trace
(
"转换token和建立映射关系成功,耗时:{}ms"
,
System
.
currentTimeMillis
()
-
start
);
...
...
gateway-service/src/main/java/com/github/tangyi/gateway/filters/TokenResponseGlobalFilter.java
View file @
5d59e233
...
...
@@ -59,8 +59,10 @@ public class TokenResponseGlobalFilter implements GlobalFilter, Ordered {
// 根据jti从Redis里获取真正的refresh_token
Object
object
=
redisTemplate
.
opsForValue
().
get
(
GatewayConstant
.
GATEWAY_REFRESH_TOKENS
+
refreshToken
);
refreshToken
=
object
==
null
?
refreshToken
:
object
.
toString
();
log
.
trace
(
"refreshToken:{}"
,
refreshToken
);
// 替换refresh_token参数
URI
newUri
=
UriComponentsBuilder
.
fromUri
(
uri
).
replaceQueryParam
(
GatewayConstant
.
GRANT_TYPE_REFRESH_TOKEN
,
refreshToken
).
build
(
true
).
toUri
();
log
.
trace
(
"newUri: {}"
,
newUri
);
ServerHttpRequest
newRequest
=
exchange
.
getRequest
().
mutate
().
uri
(
newUri
).
build
();
return
chain
.
filter
(
exchange
.
mutate
().
request
(
newRequest
).
build
());
}
...
...
@@ -70,9 +72,11 @@ public class TokenResponseGlobalFilter implements GlobalFilter, Ordered {
// 从Redis里获取实际的access_token
Object
object
=
redisTemplate
.
opsForValue
().
get
(
GatewayConstant
.
GATEWAY_ACCESS_TOKENS
+
authorization
);
authorization
=
object
==
null
?
authorization
:
CommonConstant
.
TOKEN_SPLIT
+
object
.
toString
();
log
.
trace
(
"jti->token:{}"
,
authorization
);
// 更新请求头
ServerHttpRequest
newRequest
=
request
.
mutate
().
header
(
CommonConstant
.
REQ_HEADER
,
authorization
).
build
();
String
realAuthorization
=
authorization
;
log
.
trace
(
"jti->token:{}"
,
realAuthorization
);
// 更新请求头,参考源码:SetRequestHeaderGatewayFilterFactory
ServerHttpRequest
newRequest
=
request
.
mutate
().
headers
(
httpHeaders
->
httpHeaders
.
set
(
CommonConstant
.
REQ_HEADER
,
realAuthorization
)).
build
();
log
.
trace
(
"newRequestHeader:{}"
,
newRequest
.
getHeaders
().
getFirst
(
CommonConstant
.
REQ_HEADER
));
return
chain
.
filter
(
exchange
.
mutate
().
request
(
newRequest
).
build
());
}
return
chain
.
filter
(
exchange
);
...
...
gateway-service/src/main/java/com/github/tangyi/gateway/filters/ValidateCodeFilter.java
View file @
5d59e233
...
...
@@ -5,11 +5,12 @@ import com.github.tangyi.common.core.constant.CommonConstant;
import
com.github.tangyi.common.core.exceptions.InvalidValidateCodeException
;
import
com.github.tangyi.common.core.exceptions.ValidateCodeExpiredException
;
import
com.github.tangyi.gateway.constants.GatewayConstant
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
lombok.AllArgsConstructor
;
import
org.springframework.cloud.gateway.filter.GatewayFilterChain
;
import
org.springframework.cloud.gateway.filter.GlobalFilter
;
import
org.springframework.core.Ordered
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.MultiValueMap
;
...
...
@@ -24,11 +25,11 @@ import java.net.URI;
* @author tangyi
* @date 2019/3/18 16:40
*/
@AllArgsConstructor
@Component
public
class
ValidateCodeFilter
implements
GlobalFilter
,
Ordered
{
@Autowired
private
RedisTemplate
redisTemplate
;
private
final
RedisTemplate
<
String
,
String
>
redisTemplate
;
@Override
public
Mono
<
Void
>
filter
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
)
{
...
...
@@ -36,7 +37,7 @@ public class ValidateCodeFilter implements GlobalFilter, Ordered {
ServerHttpRequest
request
=
exchange
.
getRequest
();
// 请求的URI
URI
uri
=
request
.
getURI
();
if
(
"POST"
.
equal
s
(
request
.
getMethodValue
())
if
(
HttpMethod
.
POST
.
matche
s
(
request
.
getMethodValue
())
&&
StrUtil
.
containsAnyIgnoreCase
(
uri
.
getPath
(),
GatewayConstant
.
OAUTH_TOKEN_URL
,
GatewayConstant
.
REGISTER
,
GatewayConstant
.
MOBILE_TOKEN_URL
))
{
String
grantType
=
request
.
getQueryParams
().
getFirst
(
GatewayConstant
.
GRANT_TYPE
);
// 授权类型为密码模式、注册才校验验证码
...
...
gateway-service/src/main/java/com/github/tangyi/gateway/receiver/GatewayRouteReceiver.java
View file @
5d59e233
...
...
@@ -7,6 +7,7 @@ import com.github.tangyi.common.core.utils.JsonMapper;
import
com.github.tangyi.common.core.vo.RouteFilterVo
;
import
com.github.tangyi.common.core.vo.RoutePredicateVo
;
import
com.github.tangyi.gateway.service.DynamicRouteService
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
...
...
@@ -28,11 +29,11 @@ import java.util.List;
* @date 2019/4/2 18:07
*/
@Slf4j
@AllArgsConstructor
@Service
public
class
GatewayRouteReceiver
{
@Autowired
private
DynamicRouteService
dynamicRouteService
;
private
final
DynamicRouteService
dynamicRouteService
;
/**
* 修改路由
...
...
gateway-service/src/main/java/com/github/tangyi/gateway/service/DynamicRouteService.java
View file @
5d59e233
...
...
@@ -20,11 +20,15 @@ import reactor.core.publisher.Mono;
@Service
public
class
DynamicRouteService
implements
ApplicationEventPublisherAware
{
@Autowired
private
RouteDefinitionWriter
routeDefinitionWriter
;
private
final
RouteDefinitionWriter
routeDefinitionWriter
;
private
ApplicationEventPublisher
applicationEventPublisher
;
@Autowired
public
DynamicRouteService
(
RouteDefinitionWriter
routeDefinitionWriter
)
{
this
.
routeDefinitionWriter
=
routeDefinitionWriter
;
}
@Override
public
void
setApplicationEventPublisher
(
ApplicationEventPublisher
applicationEventPublisher
)
{
this
.
applicationEventPublisher
=
applicationEventPublisher
;
...
...
service-api-impl/auth-service/src/main/java/com/github/tangyi/auth/config/SwaggerConfig.java
View file @
5d59e233
...
...
@@ -3,6 +3,9 @@ package com.github.tangyi.auth.config;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.ParameterBuilder
;
import
springfox.documentation.builders.PathSelectors
;
...
...
@@ -26,7 +29,8 @@ import java.util.List;
*/
@Configuration
@EnableSwagger2
public
class
SwaggerConfig
{
@EnableWebMvc
public
class
SwaggerConfig
implements
WebMvcConfigurer
{
@Bean
public
Docket
createRestApi
()
{
...
...
@@ -57,4 +61,16 @@ public class SwaggerConfig {
.
version
(
"2.0"
)
.
build
();
}
/**
*
* 显示swagger-ui.html文档展示页,还必须注入swagger资源:
*
* @param registry
*/
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
registry
.
addResourceHandler
(
"swagger-ui.html"
).
addResourceLocations
(
"classpath:/META-INF/resources/"
);
registry
.
addResourceHandler
(
"/webjars/**"
).
addResourceLocations
(
"classpath:/META-INF/resources/webjars/"
);
}
}
service-api-impl/auth-service/src/main/java/com/github/tangyi/auth/controller/OauthClientDetailsController.java
View file @
5d59e233
...
...
@@ -15,6 +15,7 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -31,16 +32,15 @@ import java.util.List;
* @date 2019/3/30 16:49
*/
@Slf4j
@AllArgsConstructor
@Api
(
"Oauth2客户端信息管理"
)
@RestController
@RequestMapping
(
"/v1/client"
)
public
class
OauthClientDetailsController
extends
BaseController
{
@Autowired
private
OauthClientDetailsService
oauthClientDetailsService
;
private
final
OauthClientDetailsService
oauthClientDetailsService
;
@Autowired
private
BCryptPasswordEncoder
bCryptPasswordEncoder
;
private
final
BCryptPasswordEncoder
bCryptPasswordEncoder
;
/**
* 根据ID获取
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/config/ExaminationInitConfig.java
View file @
5d59e233
...
...
@@ -3,8 +3,8 @@ package com.github.tangyi.exam.config;
import
com.github.tangyi.common.core.constant.CommonConstant
;
import
com.github.tangyi.exam.api.module.Examination
;
import
com.github.tangyi.exam.service.ExaminationService
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.core.RedisTemplate
;
...
...
@@ -20,14 +20,13 @@ import java.util.stream.Stream;
* @date 2019/4/30 16:02
*/
@Slf4j
@AllArgsConstructor
@Configuration
public
class
ExaminationInitConfig
{
@Autowired
private
RedisTemplate
redisTemplate
;
private
final
RedisTemplate
<
String
,
Examination
>
redisTemplate
;
@Autowired
private
ExaminationService
examinationService
;
private
final
ExaminationService
examinationService
;
@PostConstruct
public
void
initExamination
()
{
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/config/SwaggerConfig.java
View file @
5d59e233
...
...
@@ -3,6 +3,9 @@ package com.github.tangyi.exam.config;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.ParameterBuilder
;
import
springfox.documentation.builders.PathSelectors
;
...
...
@@ -26,7 +29,8 @@ import java.util.List;
*/
@Configuration
@EnableSwagger2
public
class
SwaggerConfig
{
@EnableWebMvc
public
class
SwaggerConfig
implements
WebMvcConfigurer
{
@Bean
public
Docket
createRestApi
()
{
...
...
@@ -57,4 +61,16 @@ public class SwaggerConfig {
.
version
(
"2.0"
)
.
build
();
}
/**
*
* 显示swagger-ui.html文档展示页,还必须注入swagger资源:
*
* @param registry
*/
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
registry
.
addResourceHandler
(
"swagger-ui.html"
).
addResourceLocations
(
"classpath:/META-INF/resources/"
);
registry
.
addResourceHandler
(
"/webjars/**"
).
addResourceLocations
(
"classpath:/META-INF/resources/webjars/"
);
}
}
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/AnswerController.java
View file @
5d59e233
...
...
@@ -15,9 +15,9 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
/**
...
...
@@ -27,13 +27,13 @@ import org.springframework.web.bind.annotation.*;
* @date 2018/11/8 21:24
*/
@Slf4j
@AllArgsConstructor
@Api
(
"答题信息管理"
)
@RestController
@RequestMapping
(
"/v1/answer"
)
public
class
AnswerController
extends
BaseController
{
@Autowired
private
AnswerService
answerService
;
private
final
AnswerService
answerService
;
/**
* 根据ID获取
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/CourseController.java
View file @
5d59e233
...
...
@@ -15,9 +15,9 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -28,13 +28,13 @@ import org.springframework.web.bind.annotation.*;
* @date 2018/11/8 21:25
*/
@Slf4j
@AllArgsConstructor
@Api
(
"课程信息管理"
)
@RestController
@RequestMapping
(
"/v1/course"
)
public
class
CourseController
extends
BaseController
{
@Autowired
private
CourseService
courseService
;
private
final
CourseService
courseService
;
/**
* 根据ID获取
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/ExamRecordController.java
View file @
5d59e233
...
...
@@ -23,11 +23,11 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -48,19 +48,17 @@ import java.util.stream.Stream;
* @date 2018/11/8 21:27
*/
@Slf4j
@AllArgsConstructor
@Api
(
"考试记录信息管理"
)
@RestController
@RequestMapping
(
"/v1/examRecord"
)
public
class
ExamRecordController
extends
BaseController
{
@Autowired
private
ExamRecordService
examRecordService
;
private
final
ExamRecordService
examRecordService
;
@Autowired
private
ExaminationService
examinationService
;
private
final
ExaminationService
examinationService
;
@Autowired
private
UserServiceClient
userServiceClient
;
private
final
UserServiceClient
userServiceClient
;
/**
* 根据ID获取
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/ExaminationController.java
View file @
5d59e233
...
...
@@ -18,11 +18,11 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -36,16 +36,15 @@ import java.util.stream.Collectors;
* @date 2018/11/8 21:26
*/
@Slf4j
@AllArgsConstructor
@Api
(
"考试信息管理"
)
@RestController
@RequestMapping
(
"/v1/examination"
)
public
class
ExaminationController
extends
BaseController
{
@Autowired
private
ExaminationService
examinationService
;
private
final
ExaminationService
examinationService
;
@Autowired
private
CourseService
courseService
;
private
final
CourseService
courseService
;
/**
* 根据ID获取
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/IncorrectAnswerController.java
View file @
5d59e233
...
...
@@ -17,11 +17,11 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
...
...
@@ -34,16 +34,15 @@ import java.util.List;
* @date 2018/11/8 21:28
*/
@Slf4j
@AllArgsConstructor
@Api
(
"错题信息管理"
)
@RestController
@RequestMapping
(
"/v1/incorrectAnswer"
)
public
class
IncorrectAnswerController
extends
BaseController
{
@Autowired
private
IncorrectAnswerService
incorrectAnswerService
;
private
final
IncorrectAnswerService
incorrectAnswerService
;
@Autowired
private
SubjectService
subjectService
;
private
final
SubjectService
subjectService
;
/**
* 根据ID获取
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/KnowledgeController.java
View file @
5d59e233
...
...
@@ -17,11 +17,11 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
...
...
@@ -36,16 +36,15 @@ import java.util.Set;
* @date 2019/1/1 15:11
*/
@Slf4j
@AllArgsConstructor
@Api
(
"知识库信息管理"
)
@RestController
@RequestMapping
(
"/v1/knowledge"
)
public
class
KnowledgeController
extends
BaseController
{
@Autowired
private
KnowledgeService
knowledgeService
;
private
final
KnowledgeService
knowledgeService
;
@Autowired
private
UserServiceClient
userServiceClient
;
private
final
UserServiceClient
userServiceClient
;
/**
* 根据ID获取
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/SubjectBankController.java
View file @
5d59e233
...
...
@@ -16,6 +16,7 @@ import com.github.tangyi.exam.service.SubjectCategoryService;
import
com.github.tangyi.exam.utils.SubjectBankUtil
;
import
com.google.common.net.HttpHeaders
;
import
io.swagger.annotations.*
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
...
...
@@ -37,16 +38,15 @@ import java.util.List;
* @date 2018/12/9 14:12
*/
@Slf4j
@AllArgsConstructor
@Api
(
"题库信息管理"
)
@RestController
@RequestMapping
(
"/v1/subjectBank"
)
public
class
SubjectBankController
extends
BaseController
{
@Autowired
private
SubjectBankService
subjectBankService
;
private
final
SubjectBankService
subjectBankService
;
@Autowired
private
SubjectCategoryService
subjectCategoryService
;
private
final
SubjectCategoryService
subjectCategoryService
;
/**
* 根据ID获取
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/SubjectCategoryController.java
View file @
5d59e233
...
...
@@ -14,9 +14,9 @@ import com.github.tangyi.exam.service.SubjectCategoryService;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -31,13 +31,13 @@ import java.util.stream.Collectors;
* @author tangyi
* @date 2018/12/4 21:57
*/
@AllArgsConstructor
@Api
(
"题库分类信息管理"
)
@RestController
@RequestMapping
(
"/v1/subjectCategory"
)
public
class
SubjectCategoryController
extends
BaseController
{
@Autowired
private
SubjectCategoryService
categoryService
;
private
final
SubjectCategoryService
categoryService
;
/**
* 返回树形分类集合
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/SubjectController.java
View file @
5d59e233
...
...
@@ -18,9 +18,9 @@ import com.github.tangyi.exam.service.SubjectService;
import
com.github.tangyi.exam.utils.SubjectUtil
;
import
com.google.common.net.HttpHeaders
;
import
io.swagger.annotations.*
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -42,22 +42,19 @@ import java.util.stream.Stream;
* @date 2018/11/8 21:29
*/
@Slf4j
@AllArgsConstructor
@Api
(
"题目信息管理"
)
@RestController
@RequestMapping
(
"/v1/subject"
)
public
class
SubjectController
extends
BaseController
{
@Autowired
private
SubjectService
subjectService
;
private
final
SubjectService
subjectService
;
@Autowired
private
AnswerService
answerService
;
private
final
AnswerService
answerService
;
@Autowired
private
ExamRecordService
examRecordService
;
private
final
ExamRecordService
examRecordService
;
@Autowired
private
ExaminationService
examinationService
;
private
final
ExaminationService
examinationService
;
/**
* 根据ID获取
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/mq/RabbitSubmitExaminationReceiver.java
View file @
5d59e233
...
...
@@ -6,9 +6,9 @@ import com.github.tangyi.exam.api.module.Answer;
import
com.github.tangyi.exam.api.module.ExamRecord
;
import
com.github.tangyi.exam.service.AnswerService
;
import
com.github.tangyi.exam.service.ExamRecordService
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
/**
...
...
@@ -18,14 +18,13 @@ import org.springframework.stereotype.Service;
* @date 2019/5/3 14:55
*/
@Slf4j
@AllArgsConstructor
@Service
public
class
RabbitSubmitExaminationReceiver
{
@Autowired
private
AnswerService
answerService
;
private
final
AnswerService
answerService
;
@Autowired
private
ExamRecordService
examRecordService
;
private
final
ExamRecordService
examRecordService
;
/**
* 处理提交考试逻辑:统计错题,计算成绩等
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/service/AnswerService.java
View file @
5d59e233
...
...
@@ -12,10 +12,10 @@ import com.github.tangyi.exam.api.module.ExamRecord;
import
com.github.tangyi.exam.api.module.IncorrectAnswer
;
import
com.github.tangyi.exam.api.module.Subject
;
import
com.github.tangyi.exam.mapper.AnswerMapper
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.amqp.core.AmqpTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
...
...
@@ -31,20 +31,17 @@ import java.util.List;
* @date 2018/11/8 21:17
*/
@Slf4j
@AllArgsConstructor
@Service
public
class
AnswerService
extends
CrudService
<
AnswerMapper
,
Answer
>
{
@Autowired
private
AmqpTemplate
amqpTemplate
;
private
final
AmqpTemplate
amqpTemplate
;
@Autowired
private
SubjectService
subjectService
;
private
final
SubjectService
subjectService
;
@Autowired
private
IncorrectAnswerService
incorrectAnswerService
;
private
final
IncorrectAnswerService
incorrectAnswerService
;
@Autowired
private
ExamRecordService
examRecordService
;
private
final
ExamRecordService
examRecordService
;
/**
* 查找答题
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/service/ExamRecordService.java
View file @
5d59e233
...
...
@@ -13,9 +13,9 @@ import com.github.tangyi.exam.api.module.ExamRecord;
import
com.github.tangyi.exam.api.module.Examination
;
import
com.github.tangyi.exam.api.module.Subject
;
import
com.github.tangyi.exam.mapper.ExamRecordMapper
;
import
lombok.AllArgsConstructor
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
...
...
@@ -27,20 +27,17 @@ import org.springframework.transaction.annotation.Transactional;
* @author tangyi
* @date 2018/11/8 21:20
*/
@AllArgsConstructor
@Service
public
class
ExamRecordService
extends
CrudService
<
ExamRecordMapper
,
ExamRecord
>
{
@Autowired
private
SubjectService
subjectService
;
private
final
SubjectService
subjectService
;
@Autowired
private
AnswerService
answerService
;
private
final
AnswerService
answerService
;
@Autowired
private
ExamRecordService
examRecordService
;
private
final
ExamRecordService
examRecordService
;
@Autowired
private
ExaminationService
examinationService
;
private
final
ExaminationService
examinationService
;
/**
* 查询考试记录
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/service/ExaminationService.java
View file @
5d59e233
...
...
@@ -4,8 +4,8 @@ import com.github.tangyi.common.core.service.CrudService;
import
com.github.tangyi.exam.api.module.Examination
;
import
com.github.tangyi.exam.api.module.Subject
;
import
com.github.tangyi.exam.mapper.ExaminationMapper
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
...
...
@@ -18,11 +18,11 @@ import org.springframework.transaction.annotation.Transactional;
* @date 2018/11/8 21:19
*/
@Slf4j
@AllArgsConstructor
@Service
public
class
ExaminationService
extends
CrudService
<
ExaminationMapper
,
Examination
>
{
@Autowired
private
SubjectService
subjectService
;
private
final
SubjectService
subjectService
;
/**
* 查询考试
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/service/SubjectService.java
View file @
5d59e233
...
...
@@ -6,8 +6,8 @@ import com.github.tangyi.exam.api.module.Answer;
import
com.github.tangyi.exam.api.module.ExamRecord
;
import
com.github.tangyi.exam.api.module.Subject
;
import
com.github.tangyi.exam.mapper.SubjectMapper
;
import
lombok.AllArgsConstructor
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
...
...
@@ -19,14 +19,13 @@ import org.springframework.transaction.annotation.Transactional;
* @author tangyi
* @date 2018/11/8 21:23
*/
@AllArgsConstructor
@Service
public
class
SubjectService
extends
CrudService
<
SubjectMapper
,
Subject
>
{
@Autowired
private
ExamRecordService
examRecordService
;
private
final
ExamRecordService
examRecordService
;
@Autowired
private
AnswerService
answerService
;
private
final
AnswerService
answerService
;
/**
* 查找题目
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/config/RouteInitConfig.java
View file @
5d59e233
...
...
@@ -5,10 +5,10 @@ import com.github.tangyi.common.core.constant.MqConstant;
import
com.github.tangyi.common.core.model.Route
;
import
com.github.tangyi.common.core.utils.JsonMapper
;
import
com.github.tangyi.user.service.RouteService
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.amqp.core.AmqpTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.core.RedisTemplate
;
...
...
@@ -22,17 +22,15 @@ import java.util.List;
* @date 2019/4/2 18:42
*/
@Slf4j
@AllArgsConstructor
@Configuration
public
class
RouteInitConfig
{
@Autowired
private
RouteService
routeService
;
private
final
RouteService
routeService
;
@Autowired
private
AmqpTemplate
amqpTemplate
;
private
final
AmqpTemplate
amqpTemplate
;
@Autowired
private
RedisTemplate
redisTemplate
;
private
final
RedisTemplate
redisTemplate
;
@PostConstruct
public
void
initRoute
()
{
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/config/SwaggerConfig.java
View file @
5d59e233
...
...
@@ -3,6 +3,9 @@ package com.github.tangyi.user.config;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.ParameterBuilder
;
import
springfox.documentation.builders.PathSelectors
;
...
...
@@ -26,7 +29,8 @@ import java.util.List;
*/
@Configuration
@EnableSwagger2
public
class
SwaggerConfig
{
@EnableWebMvc
public
class
SwaggerConfig
implements
WebMvcConfigurer
{
@Bean
public
Docket
createRestApi
()
{
...
...
@@ -57,4 +61,16 @@ public class SwaggerConfig {
.
version
(
"2.0"
)
.
build
();
}
/**
*
* 显示swagger-ui.html文档展示页,还必须注入swagger资源:
*
* @param registry
*/
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
registry
.
addResourceHandler
(
"swagger-ui.html"
).
addResourceLocations
(
"classpath:/META-INF/resources/"
);
registry
.
addResourceHandler
(
"/webjars/**"
).
addResourceLocations
(
"classpath:/META-INF/resources/webjars/"
);
}
}
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/AttachmentController.java
View file @
5d59e233
...
...
@@ -12,12 +12,12 @@ import com.github.tangyi.user.api.module.Attachment;
import
com.github.tangyi.user.service.AttachmentService
;
import
com.google.common.net.HttpHeaders
;
import
io.swagger.annotations.*
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.FileCopyUtils
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -36,13 +36,13 @@ import java.util.stream.Collectors;
* @date 2018/10/30 20:45
*/
@Slf4j
@AllArgsConstructor
@Api
(
"附件信息管理"
)
@RestController
@RequestMapping
(
"/v1/attachment"
)
public
class
AttachmentController
extends
BaseController
{
@Autowired
private
AttachmentService
attachmentService
;
private
final
AttachmentService
attachmentService
;
/**
* 根据ID获取
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/DashboardController.java
View file @
5d59e233
...
...
@@ -8,7 +8,7 @@ import com.github.tangyi.user.api.dto.DashboardDto;
import
com.github.tangyi.user.api.feign.UserServiceClient
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
lombok.AllArgsConstructor
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -19,16 +19,15 @@ import org.springframework.web.bind.annotation.RestController;
* @author tangyi
* @date 2019-03-01 13:54
*/
@AllArgsConstructor
@Api
(
"后台首页数据展示"
)
@RestController
@RequestMapping
(
"/v1/dashboard"
)
public
class
DashboardController
extends
BaseController
{
@Autowired
private
ExaminationServiceClient
examinationService
;
private
final
ExaminationServiceClient
examinationService
;
@Autowired
private
UserServiceClient
userServiceClient
;
private
final
UserServiceClient
userServiceClient
;
/**
* 获取管控台首页数据
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/DeptController.java
View file @
5d59e233
...
...
@@ -15,8 +15,8 @@ import com.github.tangyi.user.service.DeptService;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -33,13 +33,13 @@ import java.util.stream.Stream;
* @author tangyi
* @date 2018/8/26 0026 22:49
*/
@AllArgsConstructor
@Api
(
"部门信息管理"
)
@RestController
@RequestMapping
(
"/v1/dept"
)
public
class
DeptController
extends
BaseController
{
@Autowired
private
DeptService
deptService
;
private
final
DeptService
deptService
;
/**
* 查询树形部门集合
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/LogController.java
View file @
5d59e233
...
...
@@ -14,9 +14,9 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -27,13 +27,13 @@ import org.springframework.web.bind.annotation.*;
* @date 2018/10/31 20:48
*/
@Slf4j
@AllArgsConstructor
@Api
(
"日志信息管理"
)
@RestController
@RequestMapping
(
"/v1/log"
)
public
class
LogController
extends
BaseController
{
@Autowired
private
LogService
logService
;
private
final
LogService
logService
;
/**
* 根据id获取日志
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/MenuController.java
View file @
5d59e233
...
...
@@ -17,9 +17,9 @@ import com.github.tangyi.user.service.MenuService;
import
com.github.tangyi.user.utils.MenuUtil
;
import
com.google.common.net.HttpHeaders
;
import
io.swagger.annotations.*
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -41,13 +41,13 @@ import java.util.stream.Stream;
* @date 2018/8/26 22:48
*/
@Slf4j
@AllArgsConstructor
@Api
(
"菜单信息管理"
)
@RestController
@RequestMapping
(
"/v1/menu"
)
public
class
MenuController
extends
BaseController
{
@Autowired
private
MenuService
menuService
;
private
final
MenuService
menuService
;
/**
* 返回当前用户的树形菜单集合
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/RoleController.java
View file @
5d59e233
...
...
@@ -16,9 +16,9 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -33,16 +33,15 @@ import java.util.stream.Stream;
* @date 2018/8/26 22:50
*/
@Slf4j
@AllArgsConstructor
@Api
(
"角色信息管理"
)
@RestController
@RequestMapping
(
"/v1/role"
)
public
class
RoleController
extends
BaseController
{
@Autowired
private
RoleService
roleService
;
private
final
RoleService
roleService
;
@Autowired
private
RoleMenuService
roleMenuService
;
private
final
RoleMenuService
roleMenuService
;
/**
* 根据id获取角色
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/RouteController.java
View file @
5d59e233
...
...
@@ -16,11 +16,11 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.amqp.core.AmqpTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -34,16 +34,15 @@ import java.util.List;
* @date 2019/4/2 15:03
*/
@Slf4j
@AllArgsConstructor
@Api
(
"网关路由信息管理"
)
@RestController
@RequestMapping
(
"/v1/route"
)
public
class
RouteController
extends
BaseController
{
@Autowired
private
RouteService
routeService
;
private
final
RouteService
routeService
;
@Autowired
private
AmqpTemplate
amqpTemplate
;
private
final
AmqpTemplate
amqpTemplate
;
/**
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/SysConfigController.java
View file @
5d59e233
...
...
@@ -5,7 +5,7 @@ import com.github.tangyi.common.core.web.BaseController;
import
com.github.tangyi.user.config.SysConfig
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
lombok.AllArgsConstructor
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -16,13 +16,13 @@ import org.springframework.web.bind.annotation.RestController;
* @author tangyi
* @date 2019-02-28 17:29
*/
@AllArgsConstructor
@Api
(
"系统配置信息管理"
)
@RestController
@RequestMapping
(
"/v1/sysConfig"
)
public
class
SysConfigController
extends
BaseController
{
@Autowired
private
SysConfig
sysConfig
;
private
final
SysConfig
sysConfig
;
/**
* 获取系统配置
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/UserController.java
View file @
5d59e233
...
...
@@ -22,11 +22,11 @@ import com.github.tangyi.user.service.UserRoleService;
import
com.github.tangyi.user.service.UserService
;
import
com.github.tangyi.user.utils.UserUtils
;
import
io.swagger.annotations.*
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
...
...
@@ -49,6 +49,7 @@ import java.util.stream.Stream;
* @date 2018-08-25 16:20
*/
@Slf4j
@AllArgsConstructor
@Api
(
"用户信息管理"
)
@RestController
@RequestMapping
(
value
=
"/v1/user"
)
...
...
@@ -56,17 +57,13 @@ public class UserController extends BaseController {
private
static
final
PasswordEncoder
encoder
=
new
BCryptPasswordEncoder
();
@Autowired
private
UserService
userService
;
private
final
UserService
userService
;
@Autowired
private
UserRoleService
userRoleService
;
private
final
UserRoleService
userRoleService
;
@Autowired
private
DeptService
deptService
;
private
final
DeptService
deptService
;
@Autowired
private
RoleService
roleService
;
private
final
RoleService
roleService
;
/**
* 根据id获取
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/ValidateCodeController.java
View file @
5d59e233
...
...
@@ -7,9 +7,9 @@ import com.google.code.kaptcha.Producer;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -26,16 +26,15 @@ import java.awt.image.BufferedImage;
* @author tangyi
* @date 2018-09-14-19:24
*/
@AllArgsConstructor
@Api
(
"生成验证码"
)
@RestController
@RequestMapping
(
value
=
"/v1/code"
)
public
class
ValidateCodeController
extends
BaseController
{
@Autowired
private
Producer
producer
;
private
final
Producer
producer
;
@Autowired
private
UserService
userService
;
private
final
UserService
userService
;
/**
* 生成验证码
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/receiver/RouteReceiver.java
View file @
5d59e233
...
...
@@ -2,9 +2,9 @@ package com.github.tangyi.user.receiver;
import
com.github.tangyi.common.core.constant.MqConstant
;
import
com.github.tangyi.user.config.RouteInitConfig
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
/**
...
...
@@ -12,11 +12,11 @@ import org.springframework.stereotype.Service;
* @date 2019/4/7 12:38
*/
@Slf4j
@AllArgsConstructor
@Service
public
class
RouteReceiver
{
@Autowired
private
RouteInitConfig
routeInitConfig
;
private
final
RouteInitConfig
routeInitConfig
;
/**
* 刷新路由
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/AttachmentService.java
View file @
5d59e233
...
...
@@ -7,26 +7,27 @@ import com.github.tangyi.common.core.utils.SysUtil;
import
com.github.tangyi.common.security.utils.SecurityUtil
;
import
com.github.tangyi.user.api.module.Attachment
;
import
com.github.tangyi.user.mapper.AttachmentMapper
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.InputStream
;
import
java.nio.charset.StandardCharsets
;
/**
* @author tangyi
* @date 2018/10/30 20:55
*/
@Slf4j
@AllArgsConstructor
@Service
public
class
AttachmentService
extends
CrudService
<
AttachmentMapper
,
Attachment
>
{
@Autowired
private
FastDfsService
fastDfsService
;
private
final
FastDfsService
fastDfsService
;
/**
* 上传
...
...
@@ -50,7 +51,7 @@ public class AttachmentService extends CrudService<AttachmentMapper, Attachment>
newAttachment
.
setCommonValue
(
SecurityUtil
.
getCurrentUsername
(),
SysUtil
.
getSysCode
());
newAttachment
.
setGroupName
(
fastFileId
.
substring
(
0
,
fastFileId
.
indexOf
(
"/"
)));
newAttachment
.
setFastFileId
(
fastFileId
);
newAttachment
.
setAttachName
(
new
String
(
file
.
getOriginalFilename
().
getBytes
(),
"utf-8"
));
newAttachment
.
setAttachName
(
new
String
(
file
.
getOriginalFilename
().
getBytes
(),
StandardCharsets
.
UTF_8
));
newAttachment
.
setAttachSize
(
Long
.
toString
(
attachSize
));
newAttachment
.
setBusiId
(
attachment
.
getBusiId
());
newAttachment
.
setBusiModule
(
attachment
.
getBusiModule
());
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/FastDfsService.java
View file @
5d59e233
...
...
@@ -9,10 +9,10 @@ import com.github.tobato.fastdfs.domain.proto.storage.DownloadFileWriter;
import
com.github.tobato.fastdfs.service.AppendFileStorageClient
;
import
com.github.tobato.fastdfs.service.FastFileStorageClient
;
import
com.github.tobato.fastdfs.service.TrackerClient
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.io.ByteArrayInputStream
;
...
...
@@ -28,17 +28,24 @@ import java.util.Set;
* @date 2018-01-04 10:34
*/
@Slf4j
@AllArgsConstructor
@Service
public
class
FastDfsService
{
@Autowired
private
FastFileStorageClient
fastFileStorageClient
;
// 面向普通应用的文件操作接口
/**
* 面向普通应用的文件操作接口
*/
private
final
FastFileStorageClient
fastFileStorageClient
;
@Autowired
private
AppendFileStorageClient
appendFileStorageClient
;
// 支持断点续传的文件服务接口
/**
* 支持断点续传的文件服务接口
*/
private
final
AppendFileStorageClient
appendFileStorageClient
;
@Autowired
private
TrackerClient
trackerClient
;
// 目录服务(Tracker)客户端接口
/**
* 目录服务(Tracker)客户端接口
*/
private
final
TrackerClient
trackerClient
;
/**
* 上传文件
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/MenuService.java
View file @
5d59e233
...
...
@@ -6,7 +6,7 @@ import com.github.tangyi.common.core.utils.SysUtil;
import
com.github.tangyi.common.security.utils.SecurityUtil
;
import
com.github.tangyi.user.api.module.Menu
;
import
com.github.tangyi.user.mapper.MenuMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
lombok.AllArgsConstructor
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
...
...
@@ -20,11 +20,11 @@ import java.util.List;
* @author tangyi
* @date 2018/8/26 22:45
*/
@AllArgsConstructor
@Service
public
class
MenuService
extends
CrudService
<
MenuMapper
,
Menu
>
{
@Autowired
private
MenuMapper
menuMapper
;
private
final
MenuMapper
menuMapper
;
/**
* 根据角色查找菜单
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/RoleMenuService.java
View file @
5d59e233
...
...
@@ -4,8 +4,8 @@ import com.github.tangyi.common.core.service.CrudService;
import
com.github.tangyi.common.core.utils.IdGen
;
import
com.github.tangyi.user.api.module.RoleMenu
;
import
com.github.tangyi.user.mapper.RoleMenuMapper
;
import
lombok.AllArgsConstructor
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -17,11 +17,11 @@ import java.util.List;
* @author tangyi
* @date 2018/8/26 22:47
*/
@AllArgsConstructor
@Service
public
class
RoleMenuService
extends
CrudService
<
RoleMenuMapper
,
RoleMenu
>
{
@Autowired
private
RoleMenuMapper
roleMenuMapper
;
private
final
RoleMenuMapper
roleMenuMapper
;
/**
* @param role role
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/RoleService.java
View file @
5d59e233
...
...
@@ -5,7 +5,7 @@ import com.github.tangyi.user.api.module.Role;
import
com.github.tangyi.user.mapper.RoleMapper
;
import
com.github.tangyi.user.mapper.RoleMenuMapper
;
import
com.github.tangyi.user.mapper.UserRoleMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
lombok.AllArgsConstructor
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -18,14 +18,13 @@ import java.util.List;
* @author tangyi
* @date 2018/8/26 14:16
*/
@AllArgsConstructor
@Service
public
class
RoleService
extends
CrudService
<
RoleMapper
,
Role
>
{
@Autowired
private
RoleMenuMapper
roleMenuMapper
;
private
final
RoleMenuMapper
roleMenuMapper
;
@Autowired
private
UserRoleMapper
userRoleMapper
;
private
final
UserRoleMapper
userRoleMapper
;
/**
* 查询所有角色
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/UserRoleService.java
View file @
5d59e233
...
...
@@ -3,7 +3,7 @@ package com.github.tangyi.user.service;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.user.api.module.UserRole
;
import
com.github.tangyi.user.mapper.UserRoleMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
lombok.AllArgsConstructor
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
...
...
@@ -12,11 +12,11 @@ import java.util.List;
* @author tangyi
* @date 2018/8/26 14:55
*/
@AllArgsConstructor
@Service
public
class
UserRoleService
extends
CrudService
<
UserRoleMapper
,
UserRole
>
{
@Autowired
private
UserRoleMapper
userRoleMapper
;
private
final
UserRoleMapper
userRoleMapper
;
/**
* 根据用户ID查询
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/UserService.java
View file @
5d59e233
...
...
@@ -15,6 +15,7 @@ import com.github.tangyi.user.api.module.User;
import
com.github.tangyi.user.api.module.UserRole
;
import
com.github.tangyi.user.mapper.UserMapper
;
import
com.github.tangyi.user.mapper.UserRoleMapper
;
import
lombok.AllArgsConstructor
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -34,20 +35,17 @@ import java.util.concurrent.TimeUnit;
* @author tangyi
* @date 2018-08-25 16:17
*/
@AllArgsConstructor
@Service
public
class
UserService
extends
CrudService
<
UserMapper
,
User
>
{
@Autowired
private
UserMapper
userMapper
;
private
final
UserMapper
userMapper
;
@Autowired
private
UserRoleMapper
userRoleMapper
;
private
final
UserRoleMapper
userRoleMapper
;
@Autowired
private
MenuService
menuService
;
private
final
MenuService
menuService
;
@Autowired
private
RedisTemplate
redisTemplate
;
private
final
RedisTemplate
redisTemplate
;
/**
* 新增用户
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/utils/MenuUtil.java
View file @
5d59e233
...
...
@@ -69,7 +69,7 @@ public class MenuUtil {
* @date 2018/11/28 12:48
*/
public
static
LinkedHashMap
<
String
,
String
>
getMenuMap
()
{
LinkedHashMap
<
String
,
String
>
map
=
new
LinkedHashMap
<
String
,
String
>();
LinkedHashMap
<
String
,
String
>
map
=
new
LinkedHashMap
<>();
map
.
put
(
"id"
,
"菜单id"
);
map
.
put
(
"name"
,
"菜单名称"
);
map
.
put
(
"permission"
,
"菜单权限标识"
);
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/utils/UserUtils.java
View file @
5d59e233
...
...
@@ -18,7 +18,7 @@ public class UserUtils {
* @date 2018/11/26 22:35
*/
public
static
LinkedHashMap
<
String
,
String
>
getUserMap
()
{
LinkedHashMap
<
String
,
String
>
map
=
new
LinkedHashMap
<
String
,
String
>();
LinkedHashMap
<
String
,
String
>
map
=
new
LinkedHashMap
<>();
map
.
put
(
"id"
,
"用户id"
);
map
.
put
(
"name"
,
"账号"
);
map
.
put
(
"username"
,
"姓名"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment