From 46fa8e1a19366cd6a664a16ccd04a6f06fbe3af7 Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Wed, 15 Apr 2020 16:37:17 +0800 Subject: [PATCH] =?UTF-8?q?menu=E5=92=8Cauthority=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=88=B6=E7=BA=A7=E5=8F=98=E4=B8=BA=E9=80=89=E6=8B=A9=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/v1/sys_authority.go | 19 +++++++++++++ server/api/v1/sys_menu.go | 1 - server/db/qmplus.sql | 48 +++++++++------------------------ server/router/sys_authority.go | 1 + server/service/sys_authority.go | 12 +++++++++ server/service/sys_base_menu.go | 2 +- server/service/sys_menu.go | 4 +-- 7 files changed, 48 insertions(+), 39 deletions(-) diff --git a/server/api/v1/sys_authority.go b/server/api/v1/sys_authority.go index f96519f0..7ce4a2fa 100644 --- a/server/api/v1/sys_authority.go +++ b/server/api/v1/sys_authority.go @@ -49,6 +49,25 @@ func DeleteAuthority(c *gin.Context) { } } +// @Tags authority +// @Summary 设置角色资源权限 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body model.SysAuthority true "设置角色资源权限" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}" +// @Router /authority/updateAuthority [post] +func UpdateAuthority(c *gin.Context) { + var auth model.SysAuthority + _ = c.ShouldBindJSON(&auth) + err, authority := service.UpdateAuthority(auth) + if err != nil { + response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c) + } else { + response.OkWithData(resp.SysAuthorityResponse{authority}, c) + } +} + // @Tags authority // @Summary 分页获取角色列表 // @Security ApiKeyAuth diff --git a/server/api/v1/sys_menu.go b/server/api/v1/sys_menu.go index 1ce42523..bd421e18 100644 --- a/server/api/v1/sys_menu.go +++ b/server/api/v1/sys_menu.go @@ -84,7 +84,6 @@ func GetBaseMenuTree(c *gin.Context) { response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c) } else { response.OkWithData(resp.SysBaseMenusResponse{Menus: menus}, c) - } } diff --git a/server/db/qmplus.sql b/server/db/qmplus.sql index 85ed7bd4..2d1a94b9 100644 --- a/server/db/qmplus.sql +++ b/server/db/qmplus.sql @@ -11,7 +11,7 @@ Target Server Version : 50644 File Encoding : 65001 - Date: 13/04/2020 09:48:03 + Date: 15/04/2020 13:12:44 */ SET NAMES utf8mb4; @@ -125,6 +125,7 @@ INSERT INTO `casbin_rule` VALUES ('p', '888', '/authority/createAuthority', 'POS INSERT INTO `casbin_rule` VALUES ('p', '888', '/authority/deleteAuthority', 'POST', '', '', ''); INSERT INTO `casbin_rule` VALUES ('p', '888', '/authority/getAuthorityList', 'POST', '', '', ''); INSERT INTO `casbin_rule` VALUES ('p', '888', '/authority/setDataAuthority', 'POST', '', '', ''); +INSERT INTO `casbin_rule` VALUES ('p', '888', '/authority/updateAuthority', 'PUT', '', '', ''); INSERT INTO `casbin_rule` VALUES ('p', '888', '/menu/getMenu', 'POST', '', '', ''); INSERT INTO `casbin_rule` VALUES ('p', '888', '/menu/getMenuList', 'POST', '', '', ''); INSERT INTO `casbin_rule` VALUES ('p', '888', '/menu/addBaseMenu', 'POST', '', '', ''); @@ -154,28 +155,6 @@ INSERT INTO `casbin_rule` VALUES ('p', '888', '/customer/customer', 'DELETE', '' INSERT INTO `casbin_rule` VALUES ('p', '888', '/customer/customer', 'GET', '', '', ''); INSERT INTO `casbin_rule` VALUES ('p', '888', '/customer/customerList', 'GET', '', '', ''); INSERT INTO `casbin_rule` VALUES ('p', '888', '/autoCode/createTemp', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/base/login', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/base/register', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/api/createApi', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/api/getApiList', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/api/getApiById', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/api/deleteApi', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/api/updateApi', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/api/getAllApis', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/api/createApi', 'GET', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/authority/createAuthority', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/authority/deleteAuthority', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/authority/getAuthorityList', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/authority/setDataAuthority', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/menu/getMenu', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/menu/getMenuList', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/menu/addBaseMenu', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/menu/getBaseMenuTree', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/menu/addMenuAuthority', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/menu/getMenuAuthority', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/menu/deleteBaseMenu', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/menu/updateBaseMenu', 'POST', '', '', ''); -INSERT INTO `casbin_rule` VALUES ('p', 'asdasd', '/menu/getBaseMenuById', 'POST', '', '', ''); -- ---------------------------- -- Table structure for ch_cities @@ -3835,7 +3814,7 @@ CREATE TABLE `exa_file_chunks` ( `file_chunk_number` int(11) NULL DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE, INDEX `idx_exa_file_chunks_deleted_at`(`deleted_at`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact; +) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact; -- ---------------------------- -- Table structure for exa_file_upload_and_downloads @@ -3855,15 +3834,6 @@ CREATE TABLE `exa_file_upload_and_downloads` ( INDEX `idx_exa_file_upload_and_downloads_deleted_at`(`deleted_at`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 16 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact; --- ---------------------------- --- Records of exa_file_upload_and_downloads --- ---------------------------- -INSERT INTO `exa_file_upload_and_downloads` VALUES (7, '2019-10-26 22:46:32', '2019-10-26 22:46:32', NULL, 'logo.png', 'http://qmplusimg.henrongyi.top/1572101191logo.png', 'png', '1572101191logo.png'); -INSERT INTO `exa_file_upload_and_downloads` VALUES (10, '2019-10-26 23:10:44', '2019-10-26 23:10:44', NULL, 'logo.png', 'http://qmplusimg.henrongyi.top/1572102643logo.png', 'png', '1572102643logo.png'); -INSERT INTO `exa_file_upload_and_downloads` VALUES (12, '2019-10-26 23:14:08', '2019-10-26 23:14:08', NULL, 'logo.png', 'http://qmplusimg.henrongyi.top/1572102846logo.png', 'png', '1572102846logo.png'); -INSERT INTO `exa_file_upload_and_downloads` VALUES (13, '2019-10-26 23:18:17', '2019-10-26 23:18:17', NULL, 'logo.png', 'http://qmplusimg.henrongyi.top/1572103096logo.png', 'png', '1572103096logo.png'); -INSERT INTO `exa_file_upload_and_downloads` VALUES (15, '2019-12-15 14:31:00', '2019-12-15 14:31:00', NULL, 'logo.png', 'http://qmplusimg.henrongyi.top/1576391451logo.png', 'png', '1576391451logo.png'); - -- ---------------------------- -- Table structure for exa_files -- ---------------------------- @@ -3880,7 +3850,14 @@ CREATE TABLE `exa_files` ( `is_finish` tinyint(1) NULL DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE, INDEX `idx_exa_files_deleted_at`(`deleted_at`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact; +) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact; + +-- ---------------------------- +-- Records of exa_files +-- ---------------------------- +INSERT INTO `exa_files` VALUES (1, '2020-04-14 15:52:18', '2020-04-14 15:52:18', NULL, 'logo.png', '7022fdcb1562ff79cc36ce0644b86b8a', '', 1, 0); +INSERT INTO `exa_files` VALUES (2, '2020-04-14 15:53:00', '2020-04-14 15:53:00', NULL, 'index.html', '139ac05423499b520cbf402ceb663b6f', '', 1, 0); +INSERT INTO `exa_files` VALUES (3, '2020-04-14 16:07:43', '2020-04-14 16:07:43', NULL, 'favicon.ico', '7d34c388d92837200de70d3a90b49d3b', '', 1, 0); -- ---------------------------- -- Table structure for jwt_blacklists @@ -3953,7 +3930,7 @@ CREATE TABLE `sys_apis` ( PRIMARY KEY (`id`) USING BTREE, INDEX `idx_apis_deleted_at`(`deleted_at`) USING BTREE, INDEX `idx_sys_apis_deleted_at`(`deleted_at`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 46 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact; +) ENGINE = InnoDB AUTO_INCREMENT = 47 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact; -- ---------------------------- -- Records of sys_apis @@ -3999,6 +3976,7 @@ INSERT INTO `sys_apis` VALUES (42, '2020-02-25 15:36:48', '2020-02-25 15:37:16', INSERT INTO `sys_apis` VALUES (43, '2020-02-25 15:37:06', '2020-02-25 15:37:06', NULL, NULL, '/customer/customerList', '获取客户列表', 'customer', 'GET'); INSERT INTO `sys_apis` VALUES (44, '2020-03-12 14:36:54', '2020-03-12 14:56:50', NULL, NULL, '/casbin/casbinTest/:pathParam', 'RESTFUL模式测试', 'casbin', 'GET'); INSERT INTO `sys_apis` VALUES (45, '2020-03-29 23:01:28', '2020-03-29 23:01:28', NULL, NULL, '/autoCode/createTemp', '自动化代码', 'autoCode', 'POST'); +INSERT INTO `sys_apis` VALUES (46, '2020-04-15 12:46:58', '2020-04-15 12:46:58', NULL, NULL, '/authority/updateAuthority', '更新角色信息', 'authority', 'PUT'); -- ---------------------------- -- Table structure for sys_authorities diff --git a/server/router/sys_authority.go b/server/router/sys_authority.go index f93b794c..933f10e9 100644 --- a/server/router/sys_authority.go +++ b/server/router/sys_authority.go @@ -11,6 +11,7 @@ func InitAuthorityRouter(Router *gin.RouterGroup) { { AuthorityRouter.POST("createAuthority", v1.CreateAuthority) //创建角色 AuthorityRouter.POST("deleteAuthority", v1.DeleteAuthority) //删除角色 + AuthorityRouter.PUT("updateAuthority", v1.UpdateAuthority) //更新角色 AuthorityRouter.POST("getAuthorityList", v1.GetAuthorityList) //获取角色列表 AuthorityRouter.POST("setDataAuthority", v1.SetDataAuthority) //设置角色资源权限 } diff --git a/server/service/sys_authority.go b/server/service/sys_authority.go index 29b586d7..fc4de8a8 100644 --- a/server/service/sys_authority.go +++ b/server/service/sys_authority.go @@ -19,6 +19,18 @@ func CreateAuthority(auth model.SysAuthority) (err error, authority model.SysAut return err, auth } +// @title UpdateAuthority +// @description 更改一个角色 +// @auth (2020/04/05 20:22) +// @param auth model.SysAuthority +// @return error +// @return authority model.SysAuthority + +func UpdateAuthority(auth model.SysAuthority) (err error, authority model.SysAuthority) { + err = global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&model.SysAuthority{}).Updates(&auth).Error + return err, auth +} + // @title DeleteAuthority // @description 删除角色 // @auth (2020/04/05 20:22) diff --git a/server/service/sys_base_menu.go b/server/service/sys_base_menu.go index 453f851f..5de46cb5 100644 --- a/server/service/sys_base_menu.go +++ b/server/service/sys_base_menu.go @@ -32,7 +32,7 @@ func DeleteBaseMenu(id float64) (err error) { // @description 更新路由 // @auth (2020/04/05 20:22) // @param menu model.SysBaseMenu -// @return err error +// @return err errorgetMenu func UpdateBaseMenu(menu model.SysBaseMenu) (err error) { upDateMap := make(map[string]interface{}) diff --git a/server/service/sys_menu.go b/server/service/sys_menu.go index a8c0aae7..b3609a06 100644 --- a/server/service/sys_menu.go +++ b/server/service/sys_menu.go @@ -15,7 +15,7 @@ import ( // @return menus []model.SysMenu func GetMenuTree(authorityId string) (err error, menus []model.SysMenu) { - sql := "SELECT authority_menu.created_at,authority_menu.updated_at,authority_menu.deleted_at,authority_menu.menu_level,authority_menu.parent_id,authority_menu.path,authority_menu.`name`,authority_menu.hidden,authority_menu.component,authority_menu.title,authority_menu.icon,authority_menu.sort,authority_menu.menu_id,authority_menu.authority_id FROM authority_menu WHERE authority_menu.authority_id = ? AND authority_menu.parent_id = ?" + sql := "SELECT authority_menu.created_at,authority_menu.updated_at,authority_menu.deleted_at,authority_menu.menu_level,authority_menu.parent_id,authority_menu.path,authority_menu.`name`,authority_menu.hidden,authority_menu.component,authority_menu.title,authority_menu.icon,authority_menu.sort,authority_menu.menu_id,authority_menu.authority_id FROM authority_menu WHERE authority_menu.authority_id = ? AND authority_menu.parent_id = ? ORDER BY authority_menu.sort ASC" err = global.GVA_DB.Raw(sql, authorityId, 0).Scan(&menus).Error for i := 0; i < len(menus); i++ { @@ -127,7 +127,7 @@ func AddMenuAuthority(menus []model.SysBaseMenu, authorityId string) (err error) // @return menus []SysBaseMenu func GetMenuAuthority(authorityId string) (err error, menus []model.SysMenu) { - sql := "SELECT authority_menu.created_at,authority_menu.updated_at,authority_menu.deleted_at,authority_menu.menu_level,authority_menu.parent_id,authority_menu.path,authority_menu.`name`,authority_menu.hidden,authority_menu.component,authority_menu.title,authority_menu.icon,authority_menu.sort,authority_menu.menu_id,authority_menu.authority_id FROM authority_menu WHERE authority_menu.authority_id = ?" + sql := "SELECT authority_menu.created_at,authority_menu.updated_at,authority_menu.deleted_at,authority_menu.menu_level,authority_menu.parent_id,authority_menu.path,authority_menu.`name`,authority_menu.hidden,authority_menu.component,authority_menu.title,authority_menu.icon,authority_menu.sort,authority_menu.menu_id,authority_menu.authority_id FROM authority_menu WHERE authority_menu.authority_id = ? ORDER BY authority_menu.sort ASC" err = global.GVA_DB.Raw(sql, authorityId).Scan(&menus).Error return err, menus } -- GitLab