123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- package sys_role
- import (
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- type SysRoleAddReq struct {
- RoleName string `description:"角色名称"`
- RoleType string `description:"角色类型"`
- }
- type SysRole struct {
- RoleId int `orm:"column(role_id);pk" description:"角色ID"`
- RoleName string `description:"角色名称"`
- RoleType string `description:"角色类型"`
- RoleTypeCode string `description:"角色类型编码"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time
- }
- type SysRoleItem struct {
- RoleId int `orm:"column(role_id);pk" description:"角色ID"`
- RoleName string `description:"角色名称"`
- RoleType string `description:"角色类型"`
- RoleTypeCode string `description:"角色类型编码"`
- CreateTime time.Time `description:"创建时间"`
- RoleLevel int `description:"角色等级:0-表示一级角色,每个账号只能绑定一个一级角色 ,1-表示二级角色,每个账号可以绑定多个二级 角色"`
- }
- func GetSysRoleCount(roleName string) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM sys_role WHERE role_name=? `
- o := orm.NewOrm()
- err = o.Raw(sql, roleName).QueryRow(&count)
- return
- }
- func AddSysRole(item *SysRole) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- type SysRoleEditReq struct {
- RoleId int `description:"角色ID"`
- RoleName string `description:"角色名称"`
- RoleType string `description:"角色类型"`
- }
- func GetSysRoleById(roleId int) (item *SysRoleItem, err error) {
- sql := `SELECT * FROM sys_role WHERE role_id=? `
- o := orm.NewOrm()
- err = o.Raw(sql, roleId).QueryRow(&item)
- return
- }
- func GetSysRoleByName(roleName string) (item *SysRoleItem, err error) {
- sql := `SELECT * FROM sys_role WHERE role_name=? `
- o := orm.NewOrm()
- err = o.Raw(sql, roleName).QueryRow(&item)
- return
- }
- // GetSysRoleByRoleTypeCode role_type_code
- func GetSysRoleByRoleTypeCode(roleTypeCode string) (item *SysRoleItem, err error) {
- sql := `SELECT * FROM sys_role WHERE role_type_code=? `
- o := orm.NewOrm()
- err = o.Raw(sql, roleTypeCode).QueryRow(&item)
- return
- }
- func ModifySysRole(roleName, roleType, roleTypeCode string, groupId int) (err error) {
- sql := `UPDATE sys_role SET role_name=?,role_type=?,role_type_code=?,modify_time=NOW() WHERE role_id=? `
- o := orm.NewOrm()
- _, err = o.Raw(sql, roleName, roleType, roleTypeCode, groupId).Exec()
- return
- }
- type SysRoleDeleteReq struct {
- RoleId int `description:"角色ID"`
- }
- func DeleteSysRole(roleId int) (err error) {
- sql := `DELETE FROM sys_role WHERE role_id=? `
- o := orm.NewOrm()
- _, err = o.Raw(sql, roleId).Exec()
- return
- }
- func GetSysRoleListCount(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) AS count FROM sys_role WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- func GetSysRoleList(condition string, pars []interface{}, startSize, pageSize int) (items []*SysRoleItem, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM sys_role WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += `ORDER BY modify_time DESC LIMIT ?,?`
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- type SysRoleListResp struct {
- List []*SysRoleItem
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type RoleMenu struct {
- MenuId int `description:"导航唯一标识"`
- Name string `description:"导航名称"`
- }
- type RoleMenuList struct {
- MenuId int `description:"导航唯一标识"`
- Name string `description:"导航名称"`
- Child []*RoleMenu
- CheckList []int
- }
- type RoleMenuListResp struct {
- List []*RoleMenuList
- }
- func GetRoleMenuList() (items []*RoleMenuList, err error) {
- sql := `SELECT * FROM sys_menu WHERE parent_id=0 ORDER BY sort ASC `
- _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
- return
- }
- func GetRoleMenuByParentId(parentId int) (items []*RoleMenu, err error) {
- sql := `SELECT * FROM sys_menu WHERE parent_id=? ORDER BY sort ASC `
- _, err = orm.NewOrm().Raw(sql, parentId).QueryRows(&items)
- return
- }
- func GetCheckListRoleMenu(roleId, parentId int) (items []*RoleMenuList, err error) {
- sql := ` SELECT b.menu_id FROM sys_role_menu AS a
- INNER JOIN sys_menu AS b ON a.menu_id=b.menu_id
- WHERE a.role_id=?
- AND b.parent_id=? `
- _, err = orm.NewOrm().Raw(sql, roleId, parentId).QueryRows(&items)
- return
- }
- type RoleMenusAddReq struct {
- RoleId int `description:"角色ID"`
- MenuIdStr string `description:"MenuId,多个用英文逗号隔开"`
- MenuButtonIdStr string `description:"menu_button_id,多个用英文逗号隔开"`
- }
- func DeleteRoleMenuByRoleId(roleId int) (err error) {
- sql := `DELETE FROM sys_role_menu WHERE role_id=? `
- _, err = orm.NewOrm().Raw(sql, roleId).Exec()
- return
- }
- type SysRoleMenu struct {
- RoleMenuId int `orm:"column(role_menu_id);pk" description:"关联id"`
- RoleId int
- MenuId int
- }
- func AddSysRoleMenu(item *SysRoleMenu) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- func GetSysRoleAll(levelFlag bool) (items []*SysRoleItem, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM sys_role WHERE 1=1`
- if levelFlag {
- sql += ` and role_level = 0`
- }
- sql += ` ORDER BY create_time DESC `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- type SysRoleAllResp struct {
- List []*SysRoleItem
- }
|