Просмотр исходного кода

:zap: 接口返回格式与oauth2一致

smallchill 7 лет назад
Родитель
Сommit
05a4269d0e

+ 68 - 0
doc/sql/bladex-mysql-oauth2-client-upadte.sql

@@ -0,0 +1,68 @@
+/*
+ Navicat Premium Data Transfer
+
+ Source Server         : mysql_localhost
+ Source Server Type    : MySQL
+ Source Server Version : 50723
+ Source Host           : localhost:3306
+ Source Schema         : bladex
+
+ Target Server Type    : MySQL
+ Target Server Version : 50723
+ File Encoding         : 65001
+
+ Date: 24/03/2019 16:29:29
+*/
+
+SET NAMES utf8mb4;
+SET FOREIGN_KEY_CHECKS = 0;
+
+-- ----------------------------
+-- Table structure for blade_client
+-- ----------------------------
+DROP TABLE IF EXISTS `blade_client`;
+CREATE TABLE `blade_client`  (
+ `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
+ `client_id` varchar(48) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '客户端id',
+ `client_secret` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '客户端密钥',
+ `resource_ids` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '资源集合',
+ `scope` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '授权范围',
+ `authorized_grant_types` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '授权类型',
+ `web_server_redirect_uri` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '回调地址',
+ `authorities` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '权限',
+ `access_token_validity` int(11) NOT NULL COMMENT '令牌过期秒数',
+ `refresh_token_validity` int(11) NOT NULL COMMENT '刷新令牌过期秒数',
+ `additional_information` varchar(4096) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '附加说明',
+ `autoapprove` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '自动授权',
+ `create_user` int(11) NULL DEFAULT NULL COMMENT '创建人',
+ `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
+ `update_user` int(11) NULL DEFAULT NULL COMMENT '修改人',
+ `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间',
+ `status` int(2) NOT NULL COMMENT '状态',
+ `is_deleted` int(2) NOT NULL COMMENT '是否已删除',
+ PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
+
+-- ----------------------------
+-- Records of blade_client
+-- ----------------------------
+BEGIN;
+INSERT INTO `blade_client` VALUES (1, 'sword', 'sword_secret', NULL, 'all', 'refresh_token,password,authorization_code', 'http://localhost:8888', NULL, 3600, 604800, NULL, NULL, 1, '2019-03-24 10:40:55', 1, '2019-03-24 10:40:59', 1, 0), (2, 'saber', 'saber_secret', NULL, 'all', 'refresh_token,password,authorization_code', 'http://localhost:8080', NULL, 3600, 604800, NULL, NULL, 1, '2019-03-24 10:42:29', 1, '2019-03-24 10:42:32', 1, 0);
+COMMIT;
+
+SET FOREIGN_KEY_CHECKS = 1;
+
+
+
+INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
+VALUES (3, 'client', '应用管理', 'menu', '/system/client', NULL, 8, 1, 0, 1, NULL, 0);
+set @parentid = (SELECT LAST_INSERT_ID());
+INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
+VALUES (@parentid, 'client_add', '新增', 'add', '/system/client/add', 'plus', 1, 2, 1, 1, NULL, 0);
+INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
+VALUES (@parentid, 'client_edit', '修改', 'edit', '/system/client/edit', 'form', 2, 2, 2, 2, NULL, 0);
+INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
+VALUES (@parentid, 'client_delete', '删除', 'delete', '/api/blade-system/client/remove', 'delete', 3, 2, 3, 3, NULL, 0);
+INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
+VALUES (@parentid, 'client_view', '查看', 'view', '/system/client/view', 'file-text', 4, 2, 2, 2, NULL, 0);
+

Разница между файлами не показана из-за своего большого размера
+ 35 - 2
doc/sql/bladex-saber-mysql.sql


Разница между файлами не показана из-за своего большого размера
+ 35 - 2
doc/sql/bladex-sword-mysql.sql


+ 0 - 60
doc/sql/bladex-tenant-mysql-update-RC5.sql

@@ -1,60 +0,0 @@
--- ----------------------------
--- 租户字段增加
--- ----------------------------
-ALTER TABLE `bladex`.`blade_notice`
-    ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
-ALTER TABLE `bladex`.`blade_dept`
-    ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
-ALTER TABLE `bladex`.`blade_role`
-    ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
-ALTER TABLE `bladex`.`blade_user`
-    ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
-ALTER TABLE `bladex`.`blade_log_api`
-    ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
-ALTER TABLE `bladex`.`blade_log_error`
-    ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
-ALTER TABLE `bladex`.`blade_log_usual`
-    ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
-
-
--- ----------------------------
--- 租户菜单增加
--- ----------------------------
-INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
-VALUES (3, 'tenant', '租户管理', 'menu', '/system/tenant', NULL, 1, 1, 0, 1, NULL, 0);
-set @parentid = (SELECT LAST_INSERT_ID());
-INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
-VALUES (@parentid, 'tenant_add', '新增', 'add', '/system/tenant/add', 'plus', 1, 2, 1, 1, NULL, 0);
-INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
-VALUES (@parentid, 'tenant_edit', '修改', 'edit', '/system/tenant/edit', 'form', 1, 2, 1, 1, NULL, 0);
-INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
-VALUES (@parentid, 'tenant_delete', '删除', 'delete', '/api/blade-system/tenant/delete', 'delete', 1, 2, 1, 1, NULL, 0);
-INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
-VALUES (@parentid, 'tenant_view', '查看', 'view', '/system/tenant/view', 'file-text', 1, 2, 1, 1, NULL, 0);
-
--- ----------------------------
--- 租户表创建
--- ----------------------------
-DROP TABLE IF EXISTS `blade_tenant`;
-CREATE TABLE `blade_tenant`  (
- `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
- `tenant_code` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '租户编号',
- `tenant_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '租户名称',
- `linkman` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '联系人',
- `contact_number` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '联系电话',
- `address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '联系地址',
- `create_user` int(11) NULL DEFAULT NULL COMMENT '创建人',
- `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
- `update_user` int(11) NULL DEFAULT NULL COMMENT '修改人',
- `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间',
- `status` int(2) NULL DEFAULT NULL COMMENT '状态',
- `is_deleted` int(2) NULL DEFAULT 0 COMMENT '是否已删除',
- PRIMARY KEY (`id`) USING BTREE
-) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
-
--- ----------------------------
--- 租户表数据插入
--- ----------------------------
-BEGIN;
-INSERT INTO `blade_tenant` VALUES (1, '000000', '管理组', 'admin', '666666', '管理组', 1, '2019-01-01 00:00:39', 1, '2019-01-01 00:00:39', 1, 0);
-COMMIT;

+ 4 - 4
pom.xml

@@ -7,15 +7,15 @@
     <groupId>org.springblade</groupId>
     <artifactId>BladeX-Boot</artifactId>
     <packaging>jar</packaging>
-    <version>2.0.0.RC6</version>
+    <version>2.0.0.RC7</version>
 
     <properties>
-        <bladex.tool.version>2.0.0.RC6</bladex.tool.version>
+        <bladex.tool.version>2.0.0.RC7</bladex.tool.version>
 
         <java.version>1.8</java.version>
         <swagger.version>2.9.2</swagger.version>
         <swagger.models.version>1.5.21</swagger.models.version>
-        <swagger.bootstrapui.version>1.9.0</swagger.bootstrapui.version>
+        <swagger.bootstrapui.version>1.9.1</swagger.bootstrapui.version>
         <mybatis.plus.version>3.1.0</mybatis.plus.version>
         <protostuff.version>1.6.0</protostuff.version>
 
@@ -23,7 +23,7 @@
         <spring.platform.version>Cairo-SR7</spring.platform.version>
 
         <!-- 推荐使用Harbor -->
-        <docker.registry.url>192.168.186.129</docker.registry.url>
+        <docker.registry.url>10.211.55.5</docker.registry.url>
         <docker.registry.host>http://${docker.registry.url}:2375</docker.registry.host>
         <docker.plugin.version>1.2.0</docker.plugin.version>
     </properties>

+ 6 - 3
src/main/java/org/springblade/common/cache/CacheNames.java

@@ -23,9 +23,12 @@ package org.springblade.common.cache;
  */
 public interface CacheNames {
 
-	String NOTICE_ONE = "NOTICE_ONE";
+	String NOTICE_ONE = "blade_dict:notice:one";
+
+	String DICT_VALUE = "blade_dict:dict:value";
+	String DICT_LIST = "blade_dict:dict:list";
+
+	String AUTH_ROUTES = "blade_menu:auth_routes";
 
-	String DICT_VALUE = "DICT_VALUE";
-	String DICT_LIST = "DICT_LIST";
 
 }

+ 2 - 4
src/main/java/org/springblade/common/config/BladeConfiguration.java

@@ -47,10 +47,8 @@ public class BladeConfiguration implements WebMvcConfigurer {
 	@Override
 	public void addResourceHandlers(ResourceHandlerRegistry registry) {
 		registry.addResourceHandler("/js/**").addResourceLocations("classpath:/js/");
-		registry.addResourceHandler("doc.html")
-			.addResourceLocations("classpath:/META-INF/resources/");
-		registry.addResourceHandler("/webjars/**")
-			.addResourceLocations("classpath:/META-INF/resources/webjars/");
+		registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
+		registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
 	}
 
 }

+ 1 - 1
src/main/java/org/springblade/common/constant/CommonConstant.java

@@ -38,7 +38,7 @@ public interface CommonConstant {
 	/**
 	 * sentinel prod 地址
 	 */
-	String SENTINEL_PROD_ADDR = "192.168.186.129:8858";
+	String SENTINEL_PROD_ADDR = "10.211.55.5:8858";
 
 	/**
 	 * sword 系统名

+ 23 - 14
src/main/java/org/springblade/core/secure/utils/SecureUtil.java

@@ -20,6 +20,7 @@ import io.jsonwebtoken.Claims;
 import io.jsonwebtoken.JwtBuilder;
 import io.jsonwebtoken.Jwts;
 import io.jsonwebtoken.SignatureAlgorithm;
+import org.springblade.core.launch.constant.TokenConstant;
 import org.springblade.core.secure.BladeUser;
 import org.springblade.core.tool.utils.Charsets;
 import org.springblade.core.tool.utils.Func;
@@ -37,18 +38,18 @@ import java.util.*;
  * @author Chill
  */
 public class SecureUtil {
-	public static final String BLADE_USER_REQUEST_ATTR = "_BLADE_USER_REQUEST_ATTR_";
+	private static final String BLADE_USER_REQUEST_ATTR = "_BLADE_USER_REQUEST_ATTR_";
 
-	public final static String HEADER = "blade-auth";
-	public final static String BEARER = "bearer";
-	public final static String ACCOUNT = "account";
-	public final static String USER_ID = "userId";
-	public final static String ROLE_ID = "roleId";
-	public final static String USER_NAME = "userName";
-	public final static String ROLE_NAME = "roleName";
-	public final static String TENANT_CODE = "tenantCode";
-	public final static Integer AUTH_LENGTH = 7;
-	public static String BASE64_SECURITY = Base64.getEncoder().encodeToString("BladeX".getBytes(Charsets.UTF_8));
+	private final static String HEADER = TokenConstant.HEADER;
+	private final static String BEARER = TokenConstant.BEARER;
+	private final static String ACCOUNT = TokenConstant.ACCOUNT;
+	private final static String USER_ID = TokenConstant.USER_ID;
+	private final static String ROLE_ID = TokenConstant.ROLE_ID;
+	private final static String USER_NAME = TokenConstant.USER_NAME;
+	private final static String ROLE_NAME = TokenConstant.ROLE_NAME;
+	private final static String TENANT_CODE = TokenConstant.TENANT_CODE;
+	private final static Integer AUTH_LENGTH = TokenConstant.AUTH_LENGTH;
+	private static String BASE64_SECURITY = Base64.getEncoder().encodeToString(TokenConstant.SIGN_KEY.getBytes(Charsets.UTF_8));
 
 	/**
 	 * 获取用户信息
@@ -208,7 +209,7 @@ public class SecureUtil {
 	 * @return header
 	 */
 	public static String getHeader() {
-		return getHeader(WebUtil.getRequest());
+		return getHeader(Objects.requireNonNull(WebUtil.getRequest()));
 	}
 
 	/**
@@ -229,10 +230,9 @@ public class SecureUtil {
 	 */
 	public static Claims parseJWT(String jsonWebToken) {
 		try {
-			Claims claims = Jwts.parser()
+			return Jwts.parser()
 				.setSigningKey(Base64.getDecoder().decode(BASE64_SECURITY))
 				.parseClaimsJws(jsonWebToken).getBody();
-			return claims;
 		} catch (Exception ex) {
 			return null;
 		}
@@ -292,4 +292,13 @@ public class SecureUtil {
 		return cal.getTimeInMillis() - System.currentTimeMillis();
 	}
 
+	/**
+	 * 获取过期时间的秒数(次日凌晨3点)
+	 *
+	 * @return expire
+	 */
+	public static int getExpireSeconds() {
+		return (int) (getExpire() / 1000);
+	}
+
 }

+ 27 - 25
src/main/java/org/springblade/modules/auth/AuthController.java

@@ -21,10 +21,10 @@ import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import io.swagger.annotations.ApiSort;
 import lombok.AllArgsConstructor;
+import org.springblade.core.launch.constant.TokenConstant;
 import org.springblade.core.log.annotation.ApiLog;
-import org.springblade.core.secure.AuthInfo;
 import org.springblade.core.secure.utils.SecureUtil;
-import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.support.Kv;
 import org.springblade.core.tool.utils.DigestUtil;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.modules.system.entity.User;
@@ -55,46 +55,48 @@ public class AuthController {
 	@ApiLog("登录用户验证")
 	@PostMapping("token")
 	@ApiOperation(value = "获取认证token", notes = "传入租户编号:tenantCode,账号:account,密码:password")
-	public R<AuthInfo> token(@ApiParam(value = "租户编号", required = true) @RequestParam String tenantCode,
-							 @ApiParam(value = "账号", required = true) @RequestParam String account,
-							 @ApiParam(value = "密码", required = true) @RequestParam String password) {
+	public Kv token(@ApiParam(value = "租户编号", required = true) @RequestParam(defaultValue = "000000", required = false) String tenantCode,
+					@ApiParam(value = "账号", required = true) @RequestParam String username,
+					@ApiParam(value = "密码", required = true) @RequestParam String password) {
 
-		if (Func.hasEmpty(account, password)) {
-			return R.fail("接口调用不合法");
+		Kv authInfo = Kv.create();
+
+		if (Func.hasEmpty(username, password)) {
+			return authInfo.set("error_code", 400).set("error_msg", "接口调用不合法");
 		}
 
-		UserInfo userInfo = service.userInfo(tenantCode, account, DigestUtil.encrypt(password));
+		UserInfo userInfo = service.userInfo(tenantCode, username, DigestUtil.encrypt(password));
 
 		User user = userInfo.getUser();
 
 		//验证用户
 		if (user == null) {
-			return R.fail("用户名或密码不正确");
+			return authInfo.set("error_code", 400).set("error_msg", "用户名或密码不正确");
 		}
 
 		//设置jwt参数
 		Map<String, String> param = new HashMap<>(16);
-		param.put(SecureUtil.USER_ID, Func.toStr(user.getId()));
-		param.put(SecureUtil.ROLE_ID, user.getRoleId());
-		param.put(SecureUtil.TENANT_CODE, user.getTenantCode());
-		param.put(SecureUtil.ACCOUNT, user.getAccount());
-		param.put(SecureUtil.USER_NAME, user.getRealName());
-		param.put(SecureUtil.ROLE_NAME, Func.join(userInfo.getRoles()));
+		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(userInfo.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(userInfo.getRoles()));
-		authInfo.setAccessToken(accessToken);
-		authInfo.setTokenType(SecureUtil.BEARER);
-		//设置token过期时间
-		authInfo.setExpiresIn(SecureUtil.getExpire());
-		return R.data(authInfo);
-
+		authInfo.set(TokenConstant.ACCOUNT, user.getAccount())
+			.set(TokenConstant.USER_NAME, user.getRealName())
+			.set(TokenConstant.ROLE_NAME, Func.join(userInfo.getRoles()))
+			.set(TokenConstant.AVATAR, TokenConstant.DEFAULT_AVATAR)
+			.set(TokenConstant.ACCESS_TOKEN, accessToken)
+			.set(TokenConstant.REFRESH_TOKEN, accessToken)
+			.set(TokenConstant.TOKEN_TYPE, TokenConstant.BEARER)
+			.set(TokenConstant.EXPIRES_IN, SecureUtil.getExpireSeconds())
+			.set(TokenConstant.LICENSE, TokenConstant.LICENSE_NAME);
+		return authInfo;
 	}
 
 }

+ 5 - 0
src/main/java/org/springblade/modules/system/controller/MenuController.java

@@ -29,6 +29,7 @@ import org.springblade.modules.system.service.IDictService;
 import org.springblade.modules.system.service.IMenuService;
 import org.springblade.modules.system.vo.MenuVO;
 import org.springblade.modules.system.wrapper.MenuWrapper;
+import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.web.bind.annotation.*;
 import springfox.documentation.annotations.ApiIgnore;
 
@@ -36,6 +37,8 @@ import javax.validation.Valid;
 import java.util.List;
 import java.util.Map;
 
+import static org.springblade.common.cache.CacheNames.AUTH_ROUTES;
+
 /**
  * 控制器
  *
@@ -131,6 +134,7 @@ public class MenuController extends BladeController {
 	 * 新增或修改
 	 */
 	@PostMapping("/submit")
+	@CacheEvict(cacheNames = {AUTH_ROUTES})
 	@ApiOperation(value = "新增或修改", notes = "传入menu", position = 8)
 	public R submit(@Valid @RequestBody Menu menu) {
 		return R.status(menuService.saveOrUpdate(menu));
@@ -141,6 +145,7 @@ public class MenuController extends BladeController {
 	 * 删除
 	 */
 	@PostMapping("/remove")
+	@CacheEvict(cacheNames = {AUTH_ROUTES})
 	@ApiOperation(value = "删除", notes = "传入ids", position = 9)
 	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
 		return R.status(menuService.removeByIds(Func.toIntList(ids)));

+ 4 - 0
src/main/java/org/springblade/modules/system/service/impl/MenuServiceImpl.java

@@ -33,11 +33,14 @@ import org.springblade.modules.system.service.IMenuService;
 import org.springblade.modules.system.service.IRoleMenuService;
 import org.springblade.modules.system.vo.MenuVO;
 import org.springblade.modules.system.wrapper.MenuWrapper;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
 import java.util.stream.Collectors;
 
+import static org.springblade.common.cache.CacheNames.AUTH_ROUTES;
+
 /**
  * 服务实现类
  *
@@ -98,6 +101,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
 	}
 
 	@Override
+	@Cacheable(cacheNames = AUTH_ROUTES, key = "#user.roleId")
 	public List<Kv> authRoutes(BladeUser user) {
 		if (Func.isEmpty(user)) {
 			return null;

+ 1 - 1
src/main/resources/application.yml

@@ -1,6 +1,6 @@
 #服务器配置
 server:
-  port: 8800
+  port: 80
   undertow:
     # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程
     io-threads: 4

BIN
src/main/resources/static/favicon.ico


+ 4 - 4
src/main/resources/templates/saber/crud.vue.vm

@@ -69,10 +69,10 @@
       ...mapGetters(["permission"]),
       permissionList() {
         return {
-          addBtn: this.permission.$!{table.entityPath}_add,
-          viewBtn: this.permission.$!{table.entityPath}_view,
-          delBtn: this.permission.$!{table.entityPath}_delete,
-          editBtn: this.permission.$!{table.entityPath}_edit
+          addBtn: this.vaildData(this.permission.$!{table.entityPath}_add),
+          viewBtn: this.vaildData(this.permission.$!{table.entityPath}_view),
+          delBtn: this.vaildData(this.permission.$!{table.entityPath}_delete),
+          editBtn: this.vaildData(this.permission.$!{table.entityPath}_edit)
         };
       },
       ids() {

+ 3 - 3
src/main/resources/templates/sql/menu.sql.vm

@@ -4,8 +4,8 @@ set @parentid = (SELECT LAST_INSERT_ID());
 INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
 VALUES (@parentid, '$!{cfg.entityKey}_add', '新增', 'add', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/add', 'plus', 1, 2, 1, 1, NULL, 0);
 INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
-VALUES (@parentid, '$!{cfg.entityKey}_edit', '修改', 'edit', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/edit', 'form', 2, 2, 1, 2, NULL, 0);
+VALUES (@parentid, '$!{cfg.entityKey}_edit', '修改', 'edit', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/edit', 'form', 2, 2, 2, 2, NULL, 0);
 INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
-VALUES (@parentid, '$!{cfg.entityKey}_delete', '删除', 'delete', '/api/$!{cfg.serviceName}/$!{cfg.entityKey}/remove', 'delete', 3, 2, 1, 3, NULL, 0);
+VALUES (@parentid, '$!{cfg.entityKey}_delete', '删除', 'delete', '/api/$!{cfg.serviceName}/$!{cfg.entityKey}/remove', 'delete', 3, 2, 3, 3, NULL, 0);
 INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
-VALUES (@parentid, '$!{cfg.entityKey}_view', '查看', 'view', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/view', 'file-text', 4, 2, 1, 2, NULL, 0);
+VALUES (@parentid, '$!{cfg.entityKey}_view', '查看', 'view', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/view', 'file-text', 4, 2, 2, 2, NULL, 0);

+ 2 - 1
src/main/resources/templates/sword/view.js.vm

@@ -1,4 +1,5 @@
 #set($upperEntityPath=$table.entityPath.toUpperCase())
+#set($editId="$" + "{" + "id" + "}")
 import React, { PureComponent } from 'react';
 import router from 'umi/router';
 import { Form, Card, Button } from 'antd';
@@ -30,7 +31,7 @@ class $!{entity}View extends PureComponent {
         params: { id },
       },
     } = this.props;
-    router.push(`/$!{cfg.servicePackage}/$!{table.entityPath}/edit/$!{id}`);
+    router.push(`/$!{cfg.servicePackage}/$!{table.entityPath}/edit/$!{editId}`);
   };
 
   render() {

+ 4 - 4
src/test/resources/templates/saber/crud.vue.vm

@@ -69,10 +69,10 @@
       ...mapGetters(["permission"]),
       permissionList() {
         return {
-          addBtn: this.permission.$!{table.entityPath}_add,
-          viewBtn: this.permission.$!{table.entityPath}_view,
-          delBtn: this.permission.$!{table.entityPath}_delete,
-          editBtn: this.permission.$!{table.entityPath}_edit
+          addBtn: this.vaildData(this.permission.$!{table.entityPath}_add),
+          viewBtn: this.vaildData(this.permission.$!{table.entityPath}_view),
+          delBtn: this.vaildData(this.permission.$!{table.entityPath}_delete),
+          editBtn: this.vaildData(this.permission.$!{table.entityPath}_edit)
         };
       },
       ids() {

+ 3 - 3
src/test/resources/templates/sql/menu.sql.vm

@@ -4,8 +4,8 @@ set @parentid = (SELECT LAST_INSERT_ID());
 INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
 VALUES (@parentid, '$!{cfg.entityKey}_add', '新增', 'add', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/add', 'plus', 1, 2, 1, 1, NULL, 0);
 INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
-VALUES (@parentid, '$!{cfg.entityKey}_edit', '修改', 'edit', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/edit', 'form', 2, 2, 1, 2, NULL, 0);
+VALUES (@parentid, '$!{cfg.entityKey}_edit', '修改', 'edit', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/edit', 'form', 2, 2, 2, 2, NULL, 0);
 INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
-VALUES (@parentid, '$!{cfg.entityKey}_delete', '删除', 'delete', '/api/$!{cfg.serviceName}/$!{cfg.entityKey}/remove', 'delete', 3, 2, 1, 3, NULL, 0);
+VALUES (@parentid, '$!{cfg.entityKey}_delete', '删除', 'delete', '/api/$!{cfg.serviceName}/$!{cfg.entityKey}/remove', 'delete', 3, 2, 3, 3, NULL, 0);
 INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
-VALUES (@parentid, '$!{cfg.entityKey}_view', '查看', 'view', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/view', 'file-text', 4, 2, 1, 2, NULL, 0);
+VALUES (@parentid, '$!{cfg.entityKey}_view', '查看', 'view', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/view', 'file-text', 4, 2, 2, 2, NULL, 0);

+ 2 - 1
src/test/resources/templates/sword/view.js.vm

@@ -1,4 +1,5 @@
 #set($upperEntityPath=$table.entityPath.toUpperCase())
+#set($editId="$" + "{" + "id" + "}")
 import React, { PureComponent } from 'react';
 import router from 'umi/router';
 import { Form, Card, Button } from 'antd';
@@ -30,7 +31,7 @@ class $!{entity}View extends PureComponent {
         params: { id },
       },
     } = this.props;
-    router.push(`/$!{cfg.servicePackage}/$!{table.entityPath}/edit/$!{id}`);
+    router.push(`/$!{cfg.servicePackage}/$!{table.entityPath}/edit/$!{editId}`);
   };
 
   render() {

Некоторые файлы не были показаны из-за большого количества измененных файлов