yxh 4 år sedan
förälder
incheckning
4b8e720f64

+ 23 - 0
api/v1/common/req.go

@@ -0,0 +1,23 @@
+/*
+* @desc:公共接口相关
+* @company:云南奇讯科技有限公司
+* @Author: yixiaohu<yxh669@qq.com>
+* @Date:   2022/3/30 9:28
+ */
+
+package common
+
+//
+type PageReq struct {
+	BeginTime string `p:"beginTime"` //开始时间
+	EndTime   string `p:"endTime"`   //结束时间
+	PageNum   int    `p:"pageNum"`   //当前页码
+	PageSize  int    `p:"pageSize"`  //每页数
+	OrderBy   string //排序方式
+}
+
+// ListRes 列表公共返回
+type ListRes struct {
+	CurrentPage int `json:"currentPage"`
+	Total       int `json:"total"`
+}

+ 27 - 0
api/v1/system/sys_role.go

@@ -0,0 +1,27 @@
+/*
+* @desc:角色api
+* @company:云南奇讯科技有限公司
+* @Author: yixiaohu<yxh669@qq.com>
+* @Date:   2022/3/30 9:16
+ */
+
+package system
+
+import (
+	"github.com/gogf/gf/v2/frame/g"
+	commonApi "github.com/tiger1103/gfast/v3/api/v1/common"
+	"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
+)
+
+type RoleListReq struct {
+	g.Meta   `path:"/role/list" tags:"角色管理" method:"get" summary:"角色列表"`
+	RoleName string `p:"roleName"` //参数名称
+	Status   string `p:"status"`   //状态
+	commonApi.PageReq
+}
+
+type RoleListRes struct {
+	g.Meta `mime:"application/json"`
+	commonApi.ListRes
+	List []*entity.SysRole `json:"list"`
+}

+ 10 - 0
internal/app/common/consts/consts.go

@@ -0,0 +1,10 @@
+/*
+* @desc:常量
+* @company:云南奇讯科技有限公司
+* @Author: yixiaohu<yxh669@qq.com>
+* @Date:   2022/3/30 11:54
+ */
+
+package consts
+
+const ()

+ 4 - 0
internal/app/system/consts/consts.go

@@ -1 +1,5 @@
 package consts
 package consts
+
+const (
+	PageSize = 10 //分页长度
+)

+ 1 - 0
internal/app/system/controller/sys_auth_rule.go

@@ -17,6 +17,7 @@ import (
 var Menu = menuController{}
 var Menu = menuController{}
 
 
 type menuController struct {
 type menuController struct {
+	BaseController
 }
 }
 
 
 func (c *menuController) List(ctx context.Context, req *system.RuleSearchReq) (res *system.RuleListRes, err error) {
 func (c *menuController) List(ctx context.Context, req *system.RuleSearchReq) (res *system.RuleListRes, err error) {

+ 26 - 0
internal/app/system/controller/sys_role.go

@@ -0,0 +1,26 @@
+/*
+* @desc:角色管理
+* @company:云南奇讯科技有限公司
+* @Author: yixiaohu<yxh669@qq.com>
+* @Date:   2022/3/30 9:08
+ */
+
+package controller
+
+import (
+	"context"
+	"github.com/tiger1103/gfast/v3/api/v1/system"
+	"github.com/tiger1103/gfast/v3/internal/app/system/service"
+)
+
+var Role = roleController{}
+
+type roleController struct {
+	BaseController
+}
+
+// List 角色列表
+func (c *roleController) List(ctx context.Context, req *system.RoleListReq) (res *system.RoleListRes, err error) {
+	res, err = service.Role().GetRoleListSearch(ctx, req)
+	return
+}

+ 1 - 1
internal/app/system/model/sys_auth_rule.go

@@ -18,7 +18,7 @@ type SysAuthRuleInfoRes struct {
 	MenuType  uint   `orm:"menu_type"   json:"menuType"`  // 类型 0目录 1菜单 2按钮
 	MenuType  uint   `orm:"menu_type"   json:"menuType"`  // 类型 0目录 1菜单 2按钮
 	Weigh     int    `orm:"weigh"       json:"weigh"`     // 权重
 	Weigh     int    `orm:"weigh"       json:"weigh"`     // 权重
 	IsHide    uint   `orm:"is_hide" json:"isHide"`        // 显示状态
 	IsHide    uint   `orm:"is_hide" json:"isHide"`        // 显示状态
-	IsCached  uint   `orm:"is_hide"  json:"isCached"`     // 是否缓存
+	IsCached  uint   `orm:"is_cached"  json:"isCached"`   // 是否缓存
 	IsAffix   uint   `orm:"is_affix" json:"isAffix"`      //是否固定
 	IsAffix   uint   `orm:"is_affix" json:"isAffix"`      //是否固定
 	Path      string `orm:"path"        json:"path"`      // 路由地址
 	Path      string `orm:"path"        json:"path"`      // 路由地址
 	Redirect  string `orm:"redirect"   json:"redirect"`   // 跳转路由
 	Redirect  string `orm:"redirect"   json:"redirect"`   // 跳转路由

+ 8 - 0
internal/app/system/model/sys_role.go

@@ -0,0 +1,8 @@
+/*
+* @desc:角色
+* @company:云南奇讯科技有限公司
+* @Author: yixiaohu<yxh669@qq.com>
+* @Date:   2022/3/30 9:11
+ */
+
+package model

+ 1 - 0
internal/app/system/router/router.go

@@ -25,6 +25,7 @@ func BindController(group *ghttp.RouterGroup) {
 		group.Bind(
 		group.Bind(
 			controller.User,
 			controller.User,
 			controller.Menu,
 			controller.Menu,
+			controller.Role,
 			controller.DictData,
 			controller.DictData,
 		)
 		)
 	})
 	})

+ 30 - 4
internal/app/system/service/sys_role.go

@@ -9,9 +9,9 @@ package service
 
 
 import (
 import (
 	"context"
 	"context"
-	"fmt"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/util/gconv"
 	"github.com/gogf/gf/v2/util/gconv"
+	"github.com/tiger1103/gfast/v3/api/v1/system"
 	commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
 	commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
 	"github.com/tiger1103/gfast/v3/internal/app/system/consts"
 	"github.com/tiger1103/gfast/v3/internal/app/system/consts"
 	"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
 	"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
@@ -21,6 +21,7 @@ import (
 
 
 type IRole interface {
 type IRole interface {
 	GetRoleList(ctx context.Context) (list []*entity.SysRole, err error)
 	GetRoleList(ctx context.Context) (list []*entity.SysRole, err error)
+	GetRoleListSearch(ctx context.Context, req *system.RoleListReq) (res *system.RoleListRes, err error)
 }
 }
 
 
 type roleImpl struct {
 type roleImpl struct {
@@ -32,6 +33,31 @@ func Role() IRole {
 	return IRole(&role)
 	return IRole(&role)
 }
 }
 
 
+func (s *roleImpl) GetRoleListSearch(ctx context.Context, req *system.RoleListReq) (res *system.RoleListRes, err error) {
+	res = new(system.RoleListRes)
+	g.Try(func() {
+		model := dao.SysRole.Ctx(ctx)
+		if req.RoleName != "" {
+			model = model.Where("name like ?", "%"+req.RoleName+"%")
+		}
+		if req.Status != "" {
+			model = model.Where("status", gconv.Int(req.Status))
+		}
+		res.Total, err = model.Count()
+		liberr.ErrIsNil(ctx, err, "获取角色数据失败")
+		if req.PageNum == 0 {
+			req.PageNum = 1
+		}
+		res.CurrentPage = req.PageNum
+		if req.PageSize == 0 {
+			req.PageSize = consts.PageSize
+		}
+		err = model.Page(res.CurrentPage, req.PageSize).Order("id asc").Scan(&res.List)
+		liberr.ErrIsNil(ctx, err, "获取数据失败")
+	})
+	return
+}
+
 // GetRoleList 获取角色列表
 // GetRoleList 获取角色列表
 func (s *roleImpl) GetRoleList(ctx context.Context) (list []*entity.SysRole, err error) {
 func (s *roleImpl) GetRoleList(ctx context.Context) (list []*entity.SysRole, err error) {
 	cache := commonService.Cache(ctx)
 	cache := commonService.Cache(ctx)
@@ -62,9 +88,9 @@ func (s *roleImpl) AddRoleRule(ctx context.Context, iRule interface{}, roleId in
 	err = g.Try(func() {
 	err = g.Try(func() {
 		enforcer, e := commonService.CasbinEnforcer(ctx)
 		enforcer, e := commonService.CasbinEnforcer(ctx)
 		liberr.ErrIsNil(ctx, e)
 		liberr.ErrIsNil(ctx, e)
-		rule := gconv.Strings(iRule)
-		for _, v := range rule {
-			_, err = enforcer.AddPolicy(fmt.Sprintf("%d", roleId), fmt.Sprintf("%s", v), "All")
+		ruleIds := gconv.Strings(iRule)
+		for _, v := range ruleIds {
+			_, err = enforcer.AddPolicy(gconv.String(roleId), gconv.String(v), "All")
 			liberr.ErrIsNil(ctx, err)
 			liberr.ErrIsNil(ctx, err)
 		}
 		}
 	})
 	})