Commit 5d59e233 by tangyi

优化、增加docker-compose部署脚本

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