diff --git a/api/v1/common/req.go b/api/v1/common/req.go new file mode 100644 index 0000000..f944af5 --- /dev/null +++ b/api/v1/common/req.go @@ -0,0 +1,23 @@ +/* +* @desc:公共接口相关 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @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"` +} diff --git a/api/v1/system/sys_role.go b/api/v1/system/sys_role.go new file mode 100644 index 0000000..a257efa --- /dev/null +++ b/api/v1/system/sys_role.go @@ -0,0 +1,27 @@ +/* +* @desc:角色api +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @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"` +} diff --git a/internal/app/common/consts/consts.go b/internal/app/common/consts/consts.go new file mode 100644 index 0000000..8f8dfcb --- /dev/null +++ b/internal/app/common/consts/consts.go @@ -0,0 +1,10 @@ +/* +* @desc:常量 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @Date: 2022/3/30 11:54 + */ + +package consts + +const () diff --git a/internal/app/system/consts/consts.go b/internal/app/system/consts/consts.go index d709a2b..c0c0da5 100644 --- a/internal/app/system/consts/consts.go +++ b/internal/app/system/consts/consts.go @@ -1 +1,5 @@ package consts + +const ( + PageSize = 10 //分页长度 +) diff --git a/internal/app/system/controller/sys_auth_rule.go b/internal/app/system/controller/sys_auth_rule.go index 5c35e52..ccb734f 100644 --- a/internal/app/system/controller/sys_auth_rule.go +++ b/internal/app/system/controller/sys_auth_rule.go @@ -17,6 +17,7 @@ import ( var Menu = menuController{} type menuController struct { + BaseController } func (c *menuController) List(ctx context.Context, req *system.RuleSearchReq) (res *system.RuleListRes, err error) { diff --git a/internal/app/system/controller/sys_role.go b/internal/app/system/controller/sys_role.go new file mode 100644 index 0000000..5d767be --- /dev/null +++ b/internal/app/system/controller/sys_role.go @@ -0,0 +1,26 @@ +/* +* @desc:角色管理 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @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 +} diff --git a/internal/app/system/model/sys_auth_rule.go b/internal/app/system/model/sys_auth_rule.go index 6e8f1db..8ff60de 100644 --- a/internal/app/system/model/sys_auth_rule.go +++ b/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按钮 Weigh int `orm:"weigh" json:"weigh"` // 权重 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"` //是否固定 Path string `orm:"path" json:"path"` // 路由地址 Redirect string `orm:"redirect" json:"redirect"` // 跳转路由 diff --git a/internal/app/system/model/sys_role.go b/internal/app/system/model/sys_role.go new file mode 100644 index 0000000..cb4b8b4 --- /dev/null +++ b/internal/app/system/model/sys_role.go @@ -0,0 +1,8 @@ +/* +* @desc:角色 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @Date: 2022/3/30 9:11 + */ + +package model diff --git a/internal/app/system/router/router.go b/internal/app/system/router/router.go index 1385c86..0fb28ac 100644 --- a/internal/app/system/router/router.go +++ b/internal/app/system/router/router.go @@ -25,6 +25,7 @@ func BindController(group *ghttp.RouterGroup) { group.Bind( controller.User, controller.Menu, + controller.Role, controller.DictData, ) }) diff --git a/internal/app/system/service/sys_role.go b/internal/app/system/service/sys_role.go index e13d75f..18d64d7 100644 --- a/internal/app/system/service/sys_role.go +++ b/internal/app/system/service/sys_role.go @@ -9,9 +9,9 @@ package service import ( "context" - "fmt" "github.com/gogf/gf/v2/frame/g" "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" "github.com/tiger1103/gfast/v3/internal/app/system/consts" "github.com/tiger1103/gfast/v3/internal/app/system/model/entity" @@ -21,6 +21,7 @@ import ( type IRole interface { GetRoleList(ctx context.Context) (list []*entity.SysRole, err error) + GetRoleListSearch(ctx context.Context, req *system.RoleListReq) (res *system.RoleListRes, err error) } type roleImpl struct { @@ -32,6 +33,31 @@ func Role() IRole { 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 获取角色列表 func (s *roleImpl) GetRoleList(ctx context.Context) (list []*entity.SysRole, err error) { cache := commonService.Cache(ctx) @@ -62,9 +88,9 @@ func (s *roleImpl) AddRoleRule(ctx context.Context, iRule interface{}, roleId in err = g.Try(func() { enforcer, e := commonService.CasbinEnforcer(ctx) 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) } })