param = new HashMap<>(16);
- param.put(TokenConstant.USER_ID, Func.toStr(user.getId()));
- param.put(TokenConstant.ROLE_ID, user.getRoleId());
- param.put(TokenConstant.TENANT_CODE, user.getTenantCode());
- param.put(TokenConstant.ACCOUNT, user.getAccount());
- param.put(TokenConstant.USER_NAME, user.getRealName());
- param.put(TokenConstant.ROLE_NAME, Func.join(res.getData().getRoles()));
-
- //拼装accessToken
- String accessToken = SecureUtil.createJWT(param, "audience", "issuser", true);
-
- //返回accessToken
- AuthInfo authInfo = new AuthInfo();
- authInfo.setAccount(user.getAccount());
- authInfo.setUserName(user.getRealName());
- authInfo.setAuthority(Func.join(res.getData().getRoles()));
- authInfo.setAccessToken(accessToken);
- authInfo.setTokenType(TokenConstant.BEARER);
- //设置token过期时间
- authInfo.setExpiresIn(SecureUtil.getExpire());
- return R.data(authInfo);
-
+ return R.data(TokenUtil.createAuthInfo(userInfo));
}
}
diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/wrapper/ParamWrapper.java b/blade-auth/src/main/java/org/springblade/auth/enums/BladeUserEnum.java
similarity index 56%
rename from blade-service/blade-system/src/main/java/org/springblade/system/wrapper/ParamWrapper.java
rename to blade-auth/src/main/java/org/springblade/auth/enums/BladeUserEnum.java
index 26d7e41..4d0d538 100644
--- a/blade-service/blade-system/src/main/java/org/springblade/system/wrapper/ParamWrapper.java
+++ b/blade-auth/src/main/java/org/springblade/auth/enums/BladeUserEnum.java
@@ -13,29 +13,32 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springblade.system.wrapper;
+package org.springblade.auth.enums;
import lombok.AllArgsConstructor;
-import org.springblade.core.mp.support.BaseEntityWrapper;
-import org.springblade.core.tool.utils.BeanUtil;
-import org.springblade.system.entity.Param;
-import org.springblade.system.feign.IDictClient;
-import org.springblade.system.vo.ParamVO;
+import lombok.Getter;
/**
- * 包装类,返回视图层所需的字段
+ * 用户类型枚举
*
* @author Chill
*/
+@Getter
@AllArgsConstructor
-public class ParamWrapper extends BaseEntityWrapper {
+public enum BladeUserEnum {
- private IDictClient dictClient;
+ /**
+ * web
+ */
+ WEB("web", 1),
- @Override
- public ParamVO entityVO(Param param) {
- ParamVO paramVO = BeanUtil.copy(param, ParamVO.class);
- return paramVO;
- }
+ /**
+ * app
+ */
+ APP("app", 2),
+ ;
+
+ final String name;
+ final int category;
}
diff --git a/blade-gateway/src/main/java/org/springblade/gateway/config/RateLimiterConfiguration.java b/blade-auth/src/main/java/org/springblade/auth/granter/ITokenGranter.java
similarity index 56%
rename from blade-gateway/src/main/java/org/springblade/gateway/config/RateLimiterConfiguration.java
rename to blade-auth/src/main/java/org/springblade/auth/granter/ITokenGranter.java
index 420367f..b2ec731 100644
--- a/blade-gateway/src/main/java/org/springblade/gateway/config/RateLimiterConfiguration.java
+++ b/blade-auth/src/main/java/org/springblade/auth/granter/ITokenGranter.java
@@ -13,25 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.springblade.auth.granter;
-package org.springblade.gateway.config;
-import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import reactor.core.publisher.Mono;
+import org.springblade.system.user.entity.UserInfo;
/**
- * 路由限流配置
+ * 授权认证统一接口.
*
* @author Chill
*/
-@Configuration
-public class RateLimiterConfiguration {
+public interface ITokenGranter {
- @Bean(value = "remoteAddrKeyResolver")
- public KeyResolver remoteAddrKeyResolver() {
- return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getAddress().getHostAddress());
- }
+ /**
+ * 获取用户信息
+ *
+ * @param tokenParameter 授权参数
+ * @return UserInfo
+ */
+ UserInfo grant(TokenParameter tokenParameter);
}
diff --git a/blade-auth/src/main/java/org/springblade/auth/granter/PasswordTokenGranter.java b/blade-auth/src/main/java/org/springblade/auth/granter/PasswordTokenGranter.java
new file mode 100644
index 0000000..4b398dd
--- /dev/null
+++ b/blade-auth/src/main/java/org/springblade/auth/granter/PasswordTokenGranter.java
@@ -0,0 +1,63 @@
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springblade.auth.granter;
+
+import lombok.AllArgsConstructor;
+import org.springblade.auth.enums.BladeUserEnum;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.DigestUtil;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.system.user.entity.UserInfo;
+import org.springblade.system.user.feign.IUserClient;
+import org.springframework.stereotype.Component;
+
+/**
+ * PasswordTokenGranter
+ *
+ * @author Chill
+ */
+@Component
+@AllArgsConstructor
+public class PasswordTokenGranter implements ITokenGranter {
+
+ public static final String GRANT_TYPE = "password";
+
+ private IUserClient userClient;
+
+ @Override
+ public UserInfo grant(TokenParameter tokenParameter) {
+ String tenantCode = tokenParameter.getArgs().getStr("tenantCode");
+ String account = tokenParameter.getArgs().getStr("account");
+ String password = tokenParameter.getArgs().getStr("password");
+ UserInfo userInfo = null;
+ if (Func.isNoneBlank(account, password)) {
+ // 获取用户类型
+ String userType = tokenParameter.getArgs().getStr("userType");
+ R result;
+ // 根据不同用户类型调用对应的接口返回数据,用户可自行拓展
+ if (userType.equals(BladeUserEnum.WEB.getName())) {
+ result = userClient.userInfo(tenantCode, account, DigestUtil.encrypt(password));
+ } else if (userType.equals(BladeUserEnum.APP.getName())) {
+ result = userClient.userInfo(tenantCode, account, DigestUtil.encrypt(password));
+ } else {
+ result = userClient.userInfo(tenantCode, account, DigestUtil.encrypt(password));
+ }
+ userInfo = result.isSuccess() ? result.getData() : null;
+ }
+ return userInfo;
+ }
+
+}
diff --git a/blade-auth/src/main/java/org/springblade/auth/granter/RefreshTokenGranter.java b/blade-auth/src/main/java/org/springblade/auth/granter/RefreshTokenGranter.java
new file mode 100644
index 0000000..95fd95f
--- /dev/null
+++ b/blade-auth/src/main/java/org/springblade/auth/granter/RefreshTokenGranter.java
@@ -0,0 +1,58 @@
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springblade.auth.granter;
+
+import io.jsonwebtoken.Claims;
+import lombok.AllArgsConstructor;
+import org.springblade.core.launch.constant.TokenConstant;
+import org.springblade.core.secure.utils.SecureUtil;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.system.user.entity.UserInfo;
+import org.springblade.system.user.feign.IUserClient;
+import org.springframework.stereotype.Component;
+
+import java.util.Objects;
+
+/**
+ * RefreshTokenGranter
+ *
+ * @author Chill
+ */
+@Component
+@AllArgsConstructor
+public class RefreshTokenGranter implements ITokenGranter {
+
+ public static final String GRANT_TYPE = "refresh_token";
+
+ private IUserClient userClient;
+
+ @Override
+ public UserInfo grant(TokenParameter tokenParameter) {
+ String grantType = tokenParameter.getArgs().getStr("grantType");
+ String refreshToken = tokenParameter.getArgs().getStr("refreshToken");
+ UserInfo userInfo = null;
+ if (Func.isNoneBlank(grantType, refreshToken) && grantType.equals(TokenConstant.REFRESH_TOKEN)) {
+ Claims claims = SecureUtil.parseJWT(refreshToken);
+ String tokenType = Func.toStr(Objects.requireNonNull(claims).get(TokenConstant.TOKEN_TYPE));
+ if (tokenType.equals(TokenConstant.REFRESH_TOKEN)) {
+ R result = userClient.userInfo(Func.toLong(claims.get(TokenConstant.USER_ID)));
+ userInfo = result.isSuccess() ? result.getData() : null;
+ }
+ }
+ return userInfo;
+ }
+}
diff --git a/blade-auth/src/main/java/org/springblade/auth/granter/TokenGranterBuilder.java b/blade-auth/src/main/java/org/springblade/auth/granter/TokenGranterBuilder.java
new file mode 100644
index 0000000..5f11660
--- /dev/null
+++ b/blade-auth/src/main/java/org/springblade/auth/granter/TokenGranterBuilder.java
@@ -0,0 +1,59 @@
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springblade.auth.granter;
+
+import lombok.AllArgsConstructor;
+import org.springblade.core.secure.exception.SecureException;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.SpringUtil;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * TokenGranterBuilder
+ *
+ * @author Chill
+ */
+@AllArgsConstructor
+public class TokenGranterBuilder {
+
+ /**
+ * TokenGranter缓存池
+ */
+ private static Map granterPool = new ConcurrentHashMap<>();
+
+ static {
+ granterPool.put(PasswordTokenGranter.GRANT_TYPE, SpringUtil.getBean(PasswordTokenGranter.class));
+ granterPool.put(RefreshTokenGranter.GRANT_TYPE, SpringUtil.getBean(RefreshTokenGranter.class));
+ }
+
+ /**
+ * 获取TokenGranter
+ *
+ * @param grantType 授权类型
+ * @return ITokenGranter
+ */
+ public static ITokenGranter getGranter(String grantType) {
+ ITokenGranter tokenGranter = granterPool.get(Func.toStr(grantType, PasswordTokenGranter.GRANT_TYPE));
+ if (tokenGranter == null) {
+ throw new SecureException("no grantType was found");
+ } else {
+ return tokenGranter;
+ }
+ }
+
+}
diff --git a/blade-auth/src/main/java/org/springblade/auth/granter/TokenParameter.java b/blade-auth/src/main/java/org/springblade/auth/granter/TokenParameter.java
new file mode 100644
index 0000000..368c83e
--- /dev/null
+++ b/blade-auth/src/main/java/org/springblade/auth/granter/TokenParameter.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springblade.auth.granter;
+
+import lombok.Data;
+import org.springblade.core.tool.support.Kv;
+
+/**
+ * TokenParameter
+ *
+ * @author Chill
+ */
+@Data
+public class TokenParameter {
+
+ private Kv args = Kv.init();
+
+}
diff --git a/blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java b/blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java
new file mode 100644
index 0000000..d2d6dc9
--- /dev/null
+++ b/blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java
@@ -0,0 +1,92 @@
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springblade.auth.utils;
+
+import org.springblade.core.launch.constant.TokenConstant;
+import org.springblade.core.secure.AuthInfo;
+import org.springblade.core.secure.TokenInfo;
+import org.springblade.core.secure.utils.SecureUtil;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.system.user.entity.User;
+import org.springblade.system.user.entity.UserInfo;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 认证工具类
+ *
+ * @author Chill
+ */
+public class TokenUtil {
+
+ public final static String TENANT_HEADER_KEY = "Tenant-Code";
+ public final static String DEFAULT_TENANT_ID = "000000";
+ public final static String USER_TYPE_HEADER_KEY = "User-Type";
+ public final static String DEFAULT_USER_TYPE = "web";
+ public final static String USER_NOT_FOUND = "用户名或密码错误";
+ public final static String HEADER_KEY = "Authorization";
+ public final static String HEADER_PREFIX = "Basic ";
+ public final static String DEFAULT_AVATAR = "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png";
+
+ /**
+ * 创建认证token
+ *
+ * @param userInfo 用户信息
+ * @return token
+ */
+ public static AuthInfo createAuthInfo(UserInfo userInfo) {
+ User user = userInfo.getUser();
+
+ //设置jwt参数
+ Map param = new HashMap<>(16);
+ param.put(TokenConstant.TOKEN_TYPE, TokenConstant.ACCESS_TOKEN);
+ param.put(TokenConstant.TENANT_CODE, user.getTenantCode());
+ param.put(TokenConstant.USER_ID, Func.toStr(user.getId()));
+ param.put(TokenConstant.ROLE_ID, user.getRoleId());
+ param.put(TokenConstant.ACCOUNT, user.getAccount());
+ param.put(TokenConstant.USER_NAME, user.getAccount());
+ param.put(TokenConstant.ROLE_NAME, Func.join(userInfo.getRoles()));
+
+ TokenInfo accessToken = SecureUtil.createJWT(param, "audience", "issuser", TokenConstant.ACCESS_TOKEN);
+ AuthInfo authInfo = new AuthInfo();
+ authInfo.setAccount(user.getAccount());
+ authInfo.setUserName(user.getRealName());
+ authInfo.setAuthority(Func.join(userInfo.getRoles()));
+ authInfo.setAccessToken(accessToken.getToken());
+ authInfo.setExpiresIn(accessToken.getExpire());
+ authInfo.setRefreshToken(createRefreshToken(userInfo).getToken());
+ authInfo.setTokenType(TokenConstant.BEARER);
+ authInfo.setLicense(TokenConstant.LICENSE_NAME);
+
+ return authInfo;
+ }
+
+ /**
+ * 创建refreshToken
+ *
+ * @param userInfo 用户信息
+ * @return refreshToken
+ */
+ private static TokenInfo createRefreshToken(UserInfo userInfo) {
+ User user = userInfo.getUser();
+ Map param = new HashMap<>(16);
+ param.put(TokenConstant.TOKEN_TYPE, TokenConstant.REFRESH_TOKEN);
+ param.put(TokenConstant.USER_ID, Func.toStr(user.getId()));
+ return SecureUtil.createJWT(param, "audience", "issuser", TokenConstant.REFRESH_TOKEN);
+ }
+
+}
diff --git a/blade-common/pom.xml b/blade-common/pom.xml
index b04bddb..6db6af4 100644
--- a/blade-common/pom.xml
+++ b/blade-common/pom.xml
@@ -5,7 +5,7 @@
SpringBlade
org.springblade
- 2.3.2
+ 2.3.3
4.0.0
diff --git a/blade-common/src/main/java/org/springblade/common/cache/CacheNames.java b/blade-common/src/main/java/org/springblade/common/cache/CacheNames.java
index 53bd7cf..818c6ce 100644
--- a/blade-common/src/main/java/org/springblade/common/cache/CacheNames.java
+++ b/blade-common/src/main/java/org/springblade/common/cache/CacheNames.java
@@ -22,9 +22,9 @@ package org.springblade.common.cache;
*/
public interface CacheNames {
- String NOTICE_ONE = "NOTICE_ONE";
+ String NOTICE_ONE = "notice:one";
- String DICT_VALUE = "DICT_VALUE";
- String DICT_LIST = "DICT_LIST";
+ String DICT_VALUE = "dict:value";
+ String DICT_LIST = "dict:list";
}
diff --git a/blade-gateway/pom.xml b/blade-gateway/pom.xml
index 0463a8c..34aaf60 100644
--- a/blade-gateway/pom.xml
+++ b/blade-gateway/pom.xml
@@ -5,7 +5,7 @@
SpringBlade
org.springblade
- 2.3.2
+ 2.3.3
4.0.0
diff --git a/blade-gateway/src/main/java/org/springblade/gateway/config/RouterFunctionConfiguration.java b/blade-gateway/src/main/java/org/springblade/gateway/config/RouterFunctionConfiguration.java
index 86a9255..e365667 100644
--- a/blade-gateway/src/main/java/org/springblade/gateway/config/RouterFunctionConfiguration.java
+++ b/blade-gateway/src/main/java/org/springblade/gateway/config/RouterFunctionConfiguration.java
@@ -18,22 +18,17 @@ package org.springblade.gateway.config;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.springblade.gateway.handler.*;
+import org.springblade.gateway.handler.SwaggerResourceHandler;
+import org.springblade.gateway.props.RouteProperties;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
-import org.springframework.http.server.reactive.ServerHttpRequest;
-import org.springframework.http.server.reactive.ServerHttpResponse;
-import org.springframework.web.cors.reactive.CorsUtils;
import org.springframework.web.filter.reactive.HiddenHttpMethodFilter;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.server.ServerWebExchange;
-import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;
@@ -45,55 +40,15 @@ import reactor.core.publisher.Mono;
@Slf4j
@Configuration
@AllArgsConstructor
+@EnableConfigurationProperties(RouteProperties.class)
public class RouterFunctionConfiguration {
- /**
- * 这里为支持的请求头,如果有自定义的header字段请自己添加
- */
- private static final String ALLOWED_HEADERS = "x-requested-with, blade-auth, Content-Type, Authorization, credential, X-XSRF-TOKEN, token, username, client";
- private static final String ALLOWED_METHODS = "*";
- private static final String ALLOWED_ORIGIN = "*";
- private static final String ALLOWED_EXPOSE = "*";
- private static final String MAX_AGE = "18000L";
-
- private final HystrixFallbackHandler hystrixFallbackHandler;
private final SwaggerResourceHandler swaggerResourceHandler;
- private final SwaggerSecurityHandler swaggerSecurityHandler;
- private final SwaggerUiHandler swaggerUiHandler;
-
- @Bean
- public WebFilter corsFilter() {
- return (ServerWebExchange ctx, WebFilterChain chain) -> {
- ServerHttpRequest request = ctx.getRequest();
- if (CorsUtils.isCorsRequest(request)) {
- ServerHttpResponse response = ctx.getResponse();
- HttpHeaders headers = response.getHeaders();
- headers.add("Access-Control-Allow-Headers", ALLOWED_HEADERS);
- headers.add("Access-Control-Allow-Methods", ALLOWED_METHODS);
- headers.add("Access-Control-Allow-Origin", ALLOWED_ORIGIN);
- headers.add("Access-Control-Expose-Headers", ALLOWED_EXPOSE);
- headers.add("Access-Control-Max-Age", MAX_AGE);
- headers.add("Access-Control-Allow-Credentials", "true");
- if (request.getMethod() == HttpMethod.OPTIONS) {
- response.setStatusCode(HttpStatus.OK);
- return Mono.empty();
- }
- }
- return chain.filter(ctx);
- };
- }
@Bean
public RouterFunction routerFunction() {
- return RouterFunctions.route(
- RequestPredicates.path("/fallback")
- .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), hystrixFallbackHandler)
- .andRoute(RequestPredicates.GET("/swagger-resources")
- .and(RequestPredicates.accept(MediaType.ALL)), swaggerResourceHandler)
- .andRoute(RequestPredicates.GET("/swagger-resources/configuration/ui")
- .and(RequestPredicates.accept(MediaType.ALL)), swaggerUiHandler)
- .andRoute(RequestPredicates.GET("/swagger-resources/configuration/security")
- .and(RequestPredicates.accept(MediaType.ALL)), swaggerSecurityHandler);
+ return RouterFunctions.route(RequestPredicates.GET("/swagger-resources")
+ .and(RequestPredicates.accept(MediaType.ALL)), swaggerResourceHandler);
}
diff --git a/blade-gateway/src/main/java/org/springblade/gateway/filter/RequestGlobalFilter.java b/blade-gateway/src/main/java/org/springblade/gateway/filter/RequestGlobalFilter.java
deleted file mode 100644
index b3af9d9..0000000
--- a/blade-gateway/src/main/java/org/springblade/gateway/filter/RequestGlobalFilter.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package org.springblade.gateway.filter;
-
-import org.springframework.cloud.gateway.filter.GatewayFilterChain;
-import org.springframework.cloud.gateway.filter.GlobalFilter;
-import org.springframework.core.Ordered;
-import org.springframework.http.server.reactive.ServerHttpRequest;
-import org.springframework.stereotype.Component;
-import org.springframework.util.StringUtils;
-import org.springframework.web.server.ServerWebExchange;
-import reactor.core.publisher.Mono;
-
-import java.util.Arrays;
-import java.util.stream.Collectors;
-
-import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR;
-import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.addOriginalRequestUrl;
-
-/**
- *
- * 全局拦截器,作用所有的微服务
- *
- * 1. 对请求头中参数进行处理 from 参数进行清洗
- * 2. 重写StripPrefix = 1,支持全局
- *
- * @author lengleng
- */
-@Component
-public class RequestGlobalFilter implements GlobalFilter, Ordered {
-
- /**
- * Process the Web request and (optionally) delegate to the next
- * {@code WebFilter} through the given {@link GatewayFilterChain}.
- *
- * @param exchange the current server exchange
- * @param chain provides a way to delegate to the next filter
- * @return {@code Mono} to indicate when request processing is complete
- */
- @Override
- public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) {
- // 1. 清洗请求头中from 参数
- ServerHttpRequest request = exchange.getRequest().mutate()
- .headers(httpHeaders -> httpHeaders.remove("X"))
- .build();
-
- // 2. 重写StripPrefix
- addOriginalRequestUrl(exchange, request.getURI());
- String rawPath = request.getURI().getRawPath();
- String newPath = "/" + Arrays.stream(StringUtils.tokenizeToStringArray(rawPath, "/"))
- .skip(1L).collect(Collectors.joining("/"));
- ServerHttpRequest newRequest = request.mutate()
- .path(newPath)
- .build();
- exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, newRequest.getURI());
-
- return chain.filter(exchange.mutate().request(newRequest.mutate().build()).build());
- }
-
- @Override
- public int getOrder() {
- return -1000;
- }
-
-}
diff --git a/blade-gateway/src/main/java/org/springblade/gateway/handler/HystrixFallbackHandler.java b/blade-gateway/src/main/java/org/springblade/gateway/handler/HystrixFallbackHandler.java
deleted file mode 100644
index 63d0398..0000000
--- a/blade-gateway/src/main/java/org/springblade/gateway/handler/HystrixFallbackHandler.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springblade.gateway.handler;
-
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.stereotype.Component;
-import org.springframework.web.reactive.function.BodyInserters;
-import org.springframework.web.reactive.function.server.HandlerFunction;
-import org.springframework.web.reactive.function.server.ServerRequest;
-import org.springframework.web.reactive.function.server.ServerResponse;
-import reactor.core.publisher.Mono;
-
-/**
- * Hystrix 降级处理
- *
- * @author lengleng
- */
-@Slf4j
-@Component
-public class HystrixFallbackHandler implements HandlerFunction {
- @Override
- public Mono handle(ServerRequest serverRequest) {
- log.error("网关执行请求:{}失败,hystrix服务降级处理", serverRequest.uri());
- return ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR.value())
- .contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromObject("服务异常"));
- }
-}
diff --git a/blade-gateway/src/main/java/org/springblade/gateway/handler/SwaggerSecurityHandler.java b/blade-gateway/src/main/java/org/springblade/gateway/handler/SwaggerSecurityHandler.java
deleted file mode 100644
index 59a3039..0000000
--- a/blade-gateway/src/main/java/org/springblade/gateway/handler/SwaggerSecurityHandler.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springblade.gateway.handler;
-
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.stereotype.Component;
-import org.springframework.web.reactive.function.BodyInserters;
-import org.springframework.web.reactive.function.server.HandlerFunction;
-import org.springframework.web.reactive.function.server.ServerRequest;
-import org.springframework.web.reactive.function.server.ServerResponse;
-import reactor.core.publisher.Mono;
-import springfox.documentation.swagger.web.SecurityConfiguration;
-import springfox.documentation.swagger.web.SecurityConfigurationBuilder;
-
-import java.util.Optional;
-
-/**
- * SwaggerSecurityHandler
- *
- * @author lengleng
- */
-@Slf4j
-@Component
-public class SwaggerSecurityHandler implements HandlerFunction {
- @Autowired(required = false)
- private SecurityConfiguration securityConfiguration;
-
- /**
- * Handle the given request.
- *
- * @param request the request to handler
- * @return the response
- */
- @Override
- public Mono handle(ServerRequest request) {
- return ServerResponse.status(HttpStatus.OK)
- .contentType(MediaType.APPLICATION_JSON_UTF8)
- .body(BodyInserters.fromObject(
- Optional.ofNullable(securityConfiguration)
- .orElse(SecurityConfigurationBuilder.builder().build())));
- }
-}
diff --git a/blade-gateway/src/main/java/org/springblade/gateway/handler/SwaggerUiHandler.java b/blade-gateway/src/main/java/org/springblade/gateway/handler/SwaggerUiHandler.java
deleted file mode 100644
index 0923b3a..0000000
--- a/blade-gateway/src/main/java/org/springblade/gateway/handler/SwaggerUiHandler.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springblade.gateway.handler;
-
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.stereotype.Component;
-import org.springframework.web.reactive.function.BodyInserters;
-import org.springframework.web.reactive.function.server.HandlerFunction;
-import org.springframework.web.reactive.function.server.ServerRequest;
-import org.springframework.web.reactive.function.server.ServerResponse;
-import reactor.core.publisher.Mono;
-import springfox.documentation.swagger.web.UiConfiguration;
-import springfox.documentation.swagger.web.UiConfigurationBuilder;
-
-import java.util.Optional;
-
-/**
- * SwaggerUiHandler
- *
- * @author lengleng
- */
-@Slf4j
-@Component
-public class SwaggerUiHandler implements HandlerFunction {
- @Autowired(required = false)
- private UiConfiguration uiConfiguration;
-
- /**
- * Handle the given request.
- *
- * @param request the request to handler
- * @return the response
- */
- @Override
- public Mono handle(ServerRequest request) {
- return ServerResponse.status(HttpStatus.OK)
- .contentType(MediaType.APPLICATION_JSON_UTF8)
- .body(BodyInserters.fromObject(
- Optional.ofNullable(uiConfiguration)
- .orElse(UiConfigurationBuilder.builder().build())));
- }
-}
diff --git a/blade-gateway/src/main/java/org/springblade/gateway/props/RouteProperties.java b/blade-gateway/src/main/java/org/springblade/gateway/props/RouteProperties.java
new file mode 100644
index 0000000..9b7aa5d
--- /dev/null
+++ b/blade-gateway/src/main/java/org/springblade/gateway/props/RouteProperties.java
@@ -0,0 +1,37 @@
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springblade.gateway.props;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 路由配置类
+ *
+ * @author Chill
+ */
+@Data
+@RefreshScope
+@ConfigurationProperties("blade.document")
+public class RouteProperties {
+
+ private final List resources = new ArrayList<>();
+
+}
diff --git a/blade-gateway/src/main/java/org/springblade/gateway/props/RouteResource.java b/blade-gateway/src/main/java/org/springblade/gateway/props/RouteResource.java
new file mode 100644
index 0000000..a279a40
--- /dev/null
+++ b/blade-gateway/src/main/java/org/springblade/gateway/props/RouteResource.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springblade.gateway.props;
+
+import lombok.Data;
+import org.springblade.core.launch.constant.AppConstant;
+
+/**
+ * Swagger聚合文档属性
+ *
+ * @author Chill
+ */
+@Data
+public class RouteResource {
+
+ /**
+ * 文档名
+ */
+ private String name;
+
+ /**
+ * 文档所在服务地址
+ */
+ private String location;
+
+ /**
+ * 文档版本
+ */
+ private String version = AppConstant.APPLICATION_VERSION;
+
+}
diff --git a/blade-gateway/src/main/java/org/springblade/gateway/provider/SwaggerProvider.java b/blade-gateway/src/main/java/org/springblade/gateway/provider/SwaggerProvider.java
index 052b521..c316f36 100644
--- a/blade-gateway/src/main/java/org/springblade/gateway/provider/SwaggerProvider.java
+++ b/blade-gateway/src/main/java/org/springblade/gateway/provider/SwaggerProvider.java
@@ -17,60 +17,42 @@
package org.springblade.gateway.provider;
import lombok.AllArgsConstructor;
-import org.springblade.core.launch.constant.AppConstant;
-import org.springframework.cloud.gateway.config.GatewayProperties;
-import org.springframework.cloud.gateway.route.RouteLocator;
-import org.springframework.cloud.gateway.support.NameUtils;
+import org.springblade.gateway.props.RouteProperties;
+import org.springblade.gateway.props.RouteResource;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
/**
* 聚合接口文档注册
*
- * @author Sywd
+ * @author Chill
*/
@Primary
@Component
@AllArgsConstructor
public class SwaggerProvider implements SwaggerResourcesProvider {
- public static final String API_URI = "/v2/api-docs-ext";
- private final RouteLocator routeLocator;
- private final GatewayProperties gatewayProperties;
+ private static final String API_URI = "/v2/api-docs-ext";
- private static Map routeMap = new HashMap<>();
-
- static {
- routeMap.put(AppConstant.APPLICATION_AUTH_NAME, "授权模块");
- routeMap.put(AppConstant.APPLICATION_DESK_NAME, "工作台模块");
- routeMap.put(AppConstant.APPLICATION_SYSTEM_NAME, "系统模块");
- }
+ private RouteProperties routeProperties;
@Override
public List get() {
List resources = new ArrayList<>();
- List routes = new ArrayList<>();
- routeLocator.getRoutes().subscribe(route -> routes.add(route.getId()));
- gatewayProperties.getRoutes().stream().filter(routeDefinition -> routes.contains(routeDefinition.getId()))
- .forEach(routeDefinition -> routeDefinition.getPredicates().stream()
- .filter(predicateDefinition -> "Path".equalsIgnoreCase(predicateDefinition.getName()))
- .forEach(predicateDefinition -> resources.add(swaggerResource(routeDefinition.getId(),
- predicateDefinition.getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0")
- .replace("/**", API_URI)))));
+ List routeResources = routeProperties.getResources();
+ routeResources.forEach(routeResource -> resources.add(swaggerResource(routeResource)));
return resources;
}
- private SwaggerResource swaggerResource(String name, String location) {
+ private SwaggerResource swaggerResource(RouteResource routeResource) {
SwaggerResource swaggerResource = new SwaggerResource();
- swaggerResource.setName((routeMap.get(name) == null ? name : routeMap.get(name)));
- swaggerResource.setLocation(location);
- swaggerResource.setSwaggerVersion("2.0");
+ swaggerResource.setName(routeResource.getName());
+ swaggerResource.setLocation(routeResource.getLocation().concat(API_URI));
+ swaggerResource.setSwaggerVersion(routeResource.getVersion());
return swaggerResource;
}
diff --git a/blade-gateway/src/main/resources/bootstrap.yml b/blade-gateway/src/main/resources/bootstrap.yml
index c7f53a9..b3a18ab 100644
--- a/blade-gateway/src/main/resources/bootstrap.yml
+++ b/blade-gateway/src/main/resources/bootstrap.yml
@@ -1,42 +1,9 @@
server:
port: 80
-# 需要配置的服务名
-blade:
- service:
- blade-auth: blade-auth
- blade-desk: blade-desk
- blade-system: blade-system
-
spring:
cloud:
gateway:
- routes:
- # 认证中心
- - id: ${blade.service.blade-auth}
- uri: lb://${blade.service.blade-auth}
- predicates:
- - Path=/${blade.service.blade-auth}/**
- filters:
- - name: RequestRateLimiter
- args:
- # 使用SpEL按名称引用bean
- key-resolver: '#{@remoteAddrKeyResolver}'
- # 允许用户每秒处理多少个请求
- redis-rate-limiter.replenishRate: 10
- # 允许在一秒钟内完成的最大请求数
- redis-rate-limiter.burstCapacity: 20
- - StripPrefix=1
- # 首页模块
- - id: ${blade.service.blade-desk}
- uri: lb://${blade.service.blade-desk}
- predicates:
- - Path=/${blade.service.blade-desk}/**
- # 系统模块
- - id: ${blade.service.blade-system}
- uri: lb://${blade.service.blade-system}
- predicates:
- - Path=/${blade.service.blade-system}/**
discovery:
locator:
enabled: true
@@ -44,4 +11,15 @@ spring:
retry:
enabled: true
+# 聚合文档配置
+blade:
+ document:
+ resources:
+ - name: 授权模块
+ location: /blade-auth
+ - name: 工作台模块
+ location: /blade-desk
+ - name: 系统模块
+ location: /blade-system
+
diff --git a/blade-ops/blade-admin/pom.xml b/blade-ops/blade-admin/pom.xml
index 7a34fc7..c10ae09 100644
--- a/blade-ops/blade-admin/pom.xml
+++ b/blade-ops/blade-admin/pom.xml
@@ -5,7 +5,7 @@
blade-ops
org.springblade
- 2.3.2
+ 2.3.3
4.0.0
diff --git a/blade-ops/blade-develop/pom.xml b/blade-ops/blade-develop/pom.xml
index 663a3d0..4ed2068 100644
--- a/blade-ops/blade-develop/pom.xml
+++ b/blade-ops/blade-develop/pom.xml
@@ -6,7 +6,7 @@
org.springblade
blade-ops
- 2.3.2
+ 2.3.3
4.0.0
diff --git a/blade-ops/blade-develop/src/main/java/org/springblade/develop/controller/CodeController.java b/blade-ops/blade-develop/src/main/java/org/springblade/develop/controller/CodeController.java
index d9973ff..9eac77a 100644
--- a/blade-ops/blade-develop/src/main/java/org/springblade/develop/controller/CodeController.java
+++ b/blade-ops/blade-develop/src/main/java/org/springblade/develop/controller/CodeController.java
@@ -50,7 +50,7 @@ public class CodeController extends BladeController {
* 详情
*/
@GetMapping("/detail")
- @ApiOperation(value = "详情", notes = "传入code", position = 1)
+ @ApiOperation(value = "详情", notes = "传入code")
public R detail(Code code) {
Code detail = codeService.getOne(Condition.getQueryWrapper(code));
return R.data(detail);
@@ -65,7 +65,7 @@ public class CodeController extends BladeController {
@ApiImplicitParam(name = "tableName", value = "表名", paramType = "query", dataType = "string"),
@ApiImplicitParam(name = "modelName", value = "实体名", paramType = "query", dataType = "string")
})
- @ApiOperation(value = "分页", notes = "传入code", position = 2)
+ @ApiOperation(value = "分页", notes = "传入code")
public R> list(@ApiIgnore @RequestParam Map code, Query query) {
IPage pages = codeService.page(Condition.getPage(query), Condition.getQueryWrapper(code, Code.class));
return R.data(pages);
@@ -75,7 +75,7 @@ public class CodeController extends BladeController {
* 新增或修改
*/
@PostMapping("/submit")
- @ApiOperation(value = "新增或修改", notes = "传入code", position = 6)
+ @ApiOperation(value = "新增或修改", notes = "传入code")
public R submit(@Valid @RequestBody Code code) {
return R.status(codeService.saveOrUpdate(code));
}
@@ -85,7 +85,7 @@ public class CodeController extends BladeController {
* 删除
*/
@PostMapping("/remove")
- @ApiOperation(value = "删除", notes = "传入ids", position = 7)
+ @ApiOperation(value = "删除", notes = "传入ids")
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
return R.status(codeService.removeByIds(Func.toIntList(ids)));
}
@@ -94,7 +94,7 @@ public class CodeController extends BladeController {
* 代码生成
*/
@PostMapping("/gen-code")
- @ApiOperation(value = "代码生成", notes = "传入ids", position = 8)
+ @ApiOperation(value = "代码生成", notes = "传入ids")
public R genCode(@ApiParam(value = "主键集合", required = true) @RequestParam String ids, @RequestParam(defaultValue = "sword") String system) {
Collection codes = codeService.listByIds(Func.toIntList(ids));
codes.forEach(code -> {
diff --git a/blade-ops/blade-develop/src/main/resources/templates/controller.java.vm b/blade-ops/blade-develop/src/main/resources/templates/controller.java.vm
new file mode 100644
index 0000000..95ba868
--- /dev/null
+++ b/blade-ops/blade-develop/src/main/resources/templates/controller.java.vm
@@ -0,0 +1,154 @@
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package $!{package.Controller};
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiOperationSupport;
+import io.swagger.annotations.ApiParam;
+import lombok.AllArgsConstructor;
+import javax.validation.Valid;
+
+import org.springblade.core.mp.support.Condition;
+import org.springblade.core.mp.support.Query;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.Func;
+import org.springframework.web.bind.annotation.*;
+#if($!{superEntityClass})
+import org.springframework.web.bind.annotation.RequestParam;
+#end
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import $!{package.Entity}.$!{entity};
+#set($voPackage=$package.Entity.replace("entity","vo"))
+import $!{voPackage}.$!{entity}VO;
+#set($wrapperPackage=$package.Entity.replace("entity","wrapper"))
+import $!{wrapperPackage}.$!{entity}Wrapper;
+import $!{package.Service}.$!{table.serviceName};
+#if($!{superControllerClassPackage})
+import $!{superControllerClassPackage};
+#end
+#if(!$!{superEntityClass})
+#end
+import java.util.List;
+
+/**
+ * $!{table.comment} 控制器
+ *
+ * @author $!{author}
+ * @since $!{date}
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping("#if($!{package.ModuleName})/$!{package.ModuleName}#end/$!{cfg.entityKey}")
+@Api(value = "$!{table.comment}", tags = "$!{table.comment}接口")
+#if($!{superControllerClass})
+public class $!{table.controllerName} extends $!{superControllerClass} {
+#else
+public class $!{table.controllerName} {
+#end
+
+ private $!{table.serviceName} $!{table.entityPath}Service;
+
+ /**
+ * 详情
+ */
+ @GetMapping("/detail")
+ @ApiOperationSupport(order = 1)
+ @ApiOperation(value = "详情", notes = "传入$!{table.entityPath}")
+ public R<$!{entity}VO> detail($!{entity} $!{table.entityPath}) {
+ $!{entity} detail = $!{table.entityPath}Service.getOne(Condition.getQueryWrapper($!{table.entityPath}));
+ return R.data($!{entity}Wrapper.build().entityVO(detail));
+ }
+
+ /**
+ * 分页 $!{table.comment}
+ */
+ @GetMapping("/list")
+ @ApiOperationSupport(order = 2)
+ @ApiOperation(value = "分页", notes = "传入$!{table.entityPath}")
+ public R> list($!{entity} $!{table.entityPath}, Query query) {
+ IPage<$!{entity}> pages = $!{table.entityPath}Service.page(Condition.getPage(query), Condition.getQueryWrapper($!{table.entityPath}));
+ return R.data($!{entity}Wrapper.build().pageVO(pages));
+ }
+
+ /**
+ * 自定义分页 $!{table.comment}
+ */
+ @GetMapping("/page")
+ @ApiOperationSupport(order = 3)
+ @ApiOperation(value = "分页", notes = "传入$!{table.entityPath}")
+ public R> page($!{entity}VO $!{table.entityPath}, Query query) {
+ IPage<$!{entity}VO> pages = $!{table.entityPath}Service.select$!{entity}Page(Condition.getPage(query), $!{table.entityPath});
+ return R.data(pages);
+ }
+
+ /**
+ * 新增 $!{table.comment}
+ */
+ @PostMapping("/save")
+ @ApiOperationSupport(order = 4)
+ @ApiOperation(value = "新增", notes = "传入$!{table.entityPath}")
+ public R save(@Valid @RequestBody $!{entity} $!{table.entityPath}) {
+ return R.status($!{table.entityPath}Service.save($!{table.entityPath}));
+ }
+
+ /**
+ * 修改 $!{table.comment}
+ */
+ @PostMapping("/update")
+ @ApiOperationSupport(order = 5)
+ @ApiOperation(value = "修改", notes = "传入$!{table.entityPath}")
+ public R update(@Valid @RequestBody $!{entity} $!{table.entityPath}) {
+ return R.status($!{table.entityPath}Service.updateById($!{table.entityPath}));
+ }
+
+ /**
+ * 新增或修改 $!{table.comment}
+ */
+ @PostMapping("/submit")
+ @ApiOperationSupport(order = 6)
+ @ApiOperation(value = "新增或修改", notes = "传入$!{table.entityPath}")
+ public R submit(@Valid @RequestBody $!{entity} $!{table.entityPath}) {
+ return R.status($!{table.entityPath}Service.saveOrUpdate($!{table.entityPath}));
+ }
+
+ #if($!{superEntityClass})
+
+ /**
+ * 删除 $!{table.comment}
+ */
+ @PostMapping("/remove")
+ @ApiOperationSupport(order = 7)
+ @ApiOperation(value = "逻辑删除", notes = "传入ids")
+ public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
+ return R.status($!{table.entityPath}Service.deleteLogic(Func.toIntList(ids)));
+ }
+
+ #else
+
+ /**
+ * 删除 $!{table.comment}
+ */
+ @PostMapping("/remove")
+ @ApiOperationSupport(order = 7)
+ @ApiOperation(value = "删除", notes = "传入ids")
+ public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
+ return R.status($!{table.entityPath}Service.removeByIds(Func.toIntList(ids)));
+ }
+
+ #end
+
+}
diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/wrapper/RoleMenuWrapper.java b/blade-ops/blade-develop/src/main/resources/templates/wrapper.java.vm
similarity index 53%
rename from blade-service/blade-system/src/main/java/org/springblade/system/wrapper/RoleMenuWrapper.java
rename to blade-ops/blade-develop/src/main/resources/templates/wrapper.java.vm
index e87d78b..64a8b01 100644
--- a/blade-service/blade-system/src/main/java/org/springblade/system/wrapper/RoleMenuWrapper.java
+++ b/blade-ops/blade-develop/src/main/resources/templates/wrapper.java.vm
@@ -13,29 +13,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springblade.system.wrapper;
+#set($wrapperPackage=$package.Entity.replace("entity","wrapper"))
+package $!{wrapperPackage};
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
-import org.springblade.system.entity.RoleMenu;
-import org.springblade.system.feign.IDictClient;
-import org.springblade.system.vo.RoleMenuVO;
+import $!{package.Entity}.$!{entity};
+#set($voPackage=$package.Entity.replace("entity","vo"))
+import $!{voPackage}.$!{entity}VO;
/**
- * 包装类,返回视图层所需的字段
+ * $!{table.comment}包装类,返回视图层所需的字段
*
- * @author Chill
+ * @author $!{author}
+ * @since $!{date}
*/
-@AllArgsConstructor
-public class RoleMenuWrapper extends BaseEntityWrapper {
+public class $!{entity}Wrapper extends BaseEntityWrapper<$!{entity}, $!{entity}VO> {
- private IDictClient dictClient;
+ public static $!{entity}Wrapper build() {
+ return new $!{entity}Wrapper();
+ }
@Override
- public RoleMenuVO entityVO(RoleMenu roleMenu) {
- RoleMenuVO roleMenuVO = BeanUtil.copy(roleMenu, RoleMenuVO.class);
- return roleMenuVO;
+ public $!{entity}VO entityVO($!{entity} $!{table.entityPath}) {
+ $!{entity}VO $!{table.entityPath}VO = BeanUtil.copy($!{table.entityPath}, $!{entity}VO.class);
+
+ return $!{table.entityPath}VO;
}
}
diff --git a/blade-ops/blade-develop/src/test/resources/templates/controller.java.vm b/blade-ops/blade-develop/src/test/resources/templates/controller.java.vm
new file mode 100644
index 0000000..95ba868
--- /dev/null
+++ b/blade-ops/blade-develop/src/test/resources/templates/controller.java.vm
@@ -0,0 +1,154 @@
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package $!{package.Controller};
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiOperationSupport;
+import io.swagger.annotations.ApiParam;
+import lombok.AllArgsConstructor;
+import javax.validation.Valid;
+
+import org.springblade.core.mp.support.Condition;
+import org.springblade.core.mp.support.Query;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.Func;
+import org.springframework.web.bind.annotation.*;
+#if($!{superEntityClass})
+import org.springframework.web.bind.annotation.RequestParam;
+#end
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import $!{package.Entity}.$!{entity};
+#set($voPackage=$package.Entity.replace("entity","vo"))
+import $!{voPackage}.$!{entity}VO;
+#set($wrapperPackage=$package.Entity.replace("entity","wrapper"))
+import $!{wrapperPackage}.$!{entity}Wrapper;
+import $!{package.Service}.$!{table.serviceName};
+#if($!{superControllerClassPackage})
+import $!{superControllerClassPackage};
+#end
+#if(!$!{superEntityClass})
+#end
+import java.util.List;
+
+/**
+ * $!{table.comment} 控制器
+ *
+ * @author $!{author}
+ * @since $!{date}
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping("#if($!{package.ModuleName})/$!{package.ModuleName}#end/$!{cfg.entityKey}")
+@Api(value = "$!{table.comment}", tags = "$!{table.comment}接口")
+#if($!{superControllerClass})
+public class $!{table.controllerName} extends $!{superControllerClass} {
+#else
+public class $!{table.controllerName} {
+#end
+
+ private $!{table.serviceName} $!{table.entityPath}Service;
+
+ /**
+ * 详情
+ */
+ @GetMapping("/detail")
+ @ApiOperationSupport(order = 1)
+ @ApiOperation(value = "详情", notes = "传入$!{table.entityPath}")
+ public R<$!{entity}VO> detail($!{entity} $!{table.entityPath}) {
+ $!{entity} detail = $!{table.entityPath}Service.getOne(Condition.getQueryWrapper($!{table.entityPath}));
+ return R.data($!{entity}Wrapper.build().entityVO(detail));
+ }
+
+ /**
+ * 分页 $!{table.comment}
+ */
+ @GetMapping("/list")
+ @ApiOperationSupport(order = 2)
+ @ApiOperation(value = "分页", notes = "传入$!{table.entityPath}")
+ public R> list($!{entity} $!{table.entityPath}, Query query) {
+ IPage<$!{entity}> pages = $!{table.entityPath}Service.page(Condition.getPage(query), Condition.getQueryWrapper($!{table.entityPath}));
+ return R.data($!{entity}Wrapper.build().pageVO(pages));
+ }
+
+ /**
+ * 自定义分页 $!{table.comment}
+ */
+ @GetMapping("/page")
+ @ApiOperationSupport(order = 3)
+ @ApiOperation(value = "分页", notes = "传入$!{table.entityPath}")
+ public R> page($!{entity}VO $!{table.entityPath}, Query query) {
+ IPage<$!{entity}VO> pages = $!{table.entityPath}Service.select$!{entity}Page(Condition.getPage(query), $!{table.entityPath});
+ return R.data(pages);
+ }
+
+ /**
+ * 新增 $!{table.comment}
+ */
+ @PostMapping("/save")
+ @ApiOperationSupport(order = 4)
+ @ApiOperation(value = "新增", notes = "传入$!{table.entityPath}")
+ public R save(@Valid @RequestBody $!{entity} $!{table.entityPath}) {
+ return R.status($!{table.entityPath}Service.save($!{table.entityPath}));
+ }
+
+ /**
+ * 修改 $!{table.comment}
+ */
+ @PostMapping("/update")
+ @ApiOperationSupport(order = 5)
+ @ApiOperation(value = "修改", notes = "传入$!{table.entityPath}")
+ public R update(@Valid @RequestBody $!{entity} $!{table.entityPath}) {
+ return R.status($!{table.entityPath}Service.updateById($!{table.entityPath}));
+ }
+
+ /**
+ * 新增或修改 $!{table.comment}
+ */
+ @PostMapping("/submit")
+ @ApiOperationSupport(order = 6)
+ @ApiOperation(value = "新增或修改", notes = "传入$!{table.entityPath}")
+ public R submit(@Valid @RequestBody $!{entity} $!{table.entityPath}) {
+ return R.status($!{table.entityPath}Service.saveOrUpdate($!{table.entityPath}));
+ }
+
+ #if($!{superEntityClass})
+
+ /**
+ * 删除 $!{table.comment}
+ */
+ @PostMapping("/remove")
+ @ApiOperationSupport(order = 7)
+ @ApiOperation(value = "逻辑删除", notes = "传入ids")
+ public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
+ return R.status($!{table.entityPath}Service.deleteLogic(Func.toIntList(ids)));
+ }
+
+ #else
+
+ /**
+ * 删除 $!{table.comment}
+ */
+ @PostMapping("/remove")
+ @ApiOperationSupport(order = 7)
+ @ApiOperation(value = "删除", notes = "传入ids")
+ public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
+ return R.status($!{table.entityPath}Service.removeByIds(Func.toIntList(ids)));
+ }
+
+ #end
+
+}
diff --git a/blade-ops/blade-develop/src/test/resources/templates/wrapper.java.vm b/blade-ops/blade-develop/src/test/resources/templates/wrapper.java.vm
new file mode 100644
index 0000000..64a8b01
--- /dev/null
+++ b/blade-ops/blade-develop/src/test/resources/templates/wrapper.java.vm
@@ -0,0 +1,45 @@
+/**
+ * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#set($wrapperPackage=$package.Entity.replace("entity","wrapper"))
+package $!{wrapperPackage};
+
+import lombok.AllArgsConstructor;
+import org.springblade.core.mp.support.BaseEntityWrapper;
+import org.springblade.core.tool.utils.BeanUtil;
+import $!{package.Entity}.$!{entity};
+#set($voPackage=$package.Entity.replace("entity","vo"))
+import $!{voPackage}.$!{entity}VO;
+
+/**
+ * $!{table.comment}包装类,返回视图层所需的字段
+ *
+ * @author $!{author}
+ * @since $!{date}
+ */
+public class $!{entity}Wrapper extends BaseEntityWrapper<$!{entity}, $!{entity}VO> {
+
+ public static $!{entity}Wrapper build() {
+ return new $!{entity}Wrapper();
+ }
+
+ @Override
+ public $!{entity}VO entityVO($!{entity} $!{table.entityPath}) {
+ $!{entity}VO $!{table.entityPath}VO = BeanUtil.copy($!{table.entityPath}, $!{entity}VO.class);
+
+ return $!{table.entityPath}VO;
+ }
+
+}
diff --git a/blade-ops/blade-resource/pom.xml b/blade-ops/blade-resource/pom.xml
index 7589afe..134914b 100644
--- a/blade-ops/blade-resource/pom.xml
+++ b/blade-ops/blade-resource/pom.xml
@@ -5,7 +5,7 @@
blade-ops
org.springblade
- 2.3.2
+ 2.3.3
4.0.0
diff --git a/blade-ops/pom.xml b/blade-ops/pom.xml
index f04016f..53e805b 100644
--- a/blade-ops/pom.xml
+++ b/blade-ops/pom.xml
@@ -5,7 +5,7 @@
SpringBlade
org.springblade
- 2.3.2
+ 2.3.3
4.0.0
diff --git a/blade-service-api/blade-desk-api/pom.xml b/blade-service-api/blade-desk-api/pom.xml
index 4a67d25..63fa012 100644
--- a/blade-service-api/blade-desk-api/pom.xml
+++ b/blade-service-api/blade-desk-api/pom.xml
@@ -5,7 +5,7 @@
blade-service-api
org.springblade
- 2.3.2
+ 2.3.3
4.0.0
diff --git a/blade-service-api/blade-dict-api/pom.xml b/blade-service-api/blade-dict-api/pom.xml
index de10b68..c3d7c67 100644
--- a/blade-service-api/blade-dict-api/pom.xml
+++ b/blade-service-api/blade-dict-api/pom.xml
@@ -5,7 +5,7 @@
blade-service-api
org.springblade
- 2.3.2
+ 2.3.3
4.0.0
diff --git a/blade-service-api/blade-system-api/pom.xml b/blade-service-api/blade-system-api/pom.xml
index 74bbb5d..4fabf08 100644
--- a/blade-service-api/blade-system-api/pom.xml
+++ b/blade-service-api/blade-system-api/pom.xml
@@ -5,7 +5,7 @@
blade-service-api
org.springblade
- 2.3.2
+ 2.3.3
4.0.0
diff --git a/blade-service-api/blade-user-api/pom.xml b/blade-service-api/blade-user-api/pom.xml
index 39666a6..62581ba 100644
--- a/blade-service-api/blade-user-api/pom.xml
+++ b/blade-service-api/blade-user-api/pom.xml
@@ -5,7 +5,7 @@
blade-service-api
org.springblade
- 2.3.2
+ 2.3.3
4.0.0
diff --git a/blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/feign/IUserClient.java b/blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/feign/IUserClient.java
index 9214fc7..704c9b4 100644
--- a/blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/feign/IUserClient.java
+++ b/blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/feign/IUserClient.java
@@ -38,9 +38,18 @@ public interface IUserClient {
/**
* 获取用户信息
*
- * @param tenantCode 租户编号
- * @param account 账号
- * @param password 密码
+ * @param userId 用户id
+ * @return
+ */
+ @GetMapping(API_PREFIX + "/user-info-by-id")
+ R userInfo(@RequestParam("userId") Long userId);
+
+ /**
+ * 获取用户信息
+ *
+ * @param tenantCode 租户编号
+ * @param account 账号
+ * @param password 密码
* @return
*/
@GetMapping(API_PREFIX + "/user-info")
diff --git a/blade-service-api/pom.xml b/blade-service-api/pom.xml
index a26bdaa..505cabe 100644
--- a/blade-service-api/pom.xml
+++ b/blade-service-api/pom.xml
@@ -5,13 +5,13 @@
SpringBlade
org.springblade
- 2.3.2
+ 2.3.3
4.0.0
blade-service-api
${project.artifactId}
- 2.3.2
+ 2.3.3
pom
SpringBlade 微服务API集合
diff --git a/blade-service/blade-desk/pom.xml b/blade-service/blade-desk/pom.xml
index 76371f2..f5704ee 100644
--- a/blade-service/blade-desk/pom.xml
+++ b/blade-service/blade-desk/pom.xml
@@ -6,7 +6,7 @@
org.springblade
blade-service
- 2.3.2
+ 2.3.3
4.0.0
diff --git a/blade-service/blade-desk/src/main/java/org/springblade/desk/controller/DashBoardController.java b/blade-service/blade-desk/src/main/java/org/springblade/desk/controller/DashBoardController.java
index cac1455..6f5b4e4 100644
--- a/blade-service/blade-desk/src/main/java/org/springblade/desk/controller/DashBoardController.java
+++ b/blade-service/blade-desk/src/main/java/org/springblade/desk/controller/DashBoardController.java
@@ -31,7 +31,7 @@ public class DashBoardController {
* @return
*/
@GetMapping("/activities")
- @ApiOperation(value = "活跃用户", notes = "活跃用户", position = 1)
+ @ApiOperation(value = "活跃用户", notes = "活跃用户")
public R activities() {
List