123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- package system
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/utils"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- type SysRoleAddReq struct {
- RoleName string `description:"角色名称"`
- RoleType string `description:"角色类型"`
- }
- type SysRole struct {
- RoleId int `gorm:"primaryKey"`
- 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=? `
- err = global.DEFAULT_DmSQL.Raw(sql, roleName).First(&count).Error
- return
- }
- func AddSysRole(item *SysRole) (lastId int64, err error) {
- err = global.DEFAULT_DmSQL.Create(item).Error
- 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=? `
- err = global.DEFAULT_DmSQL.Raw(sql, roleId).First(&item).Error
- return
- }
- func GetSysRoleByName(roleName string) (item *SysRoleItem, err error) {
- sql := `SELECT * FROM sys_role WHERE role_name=? `
- err = global.DEFAULT_DmSQL.Raw(sql, roleName).First(&item).Error
- return
- }
- // GetSysRoleByRoleTypeCode role_type_code
- func GetSysRoleByRoleTypeCode(roleTypeCode string) (item *SysRoleItem, err error) {
- sql := `SELECT * FROM sys_role WHERE role_type_code=? `
- err = global.DEFAULT_DmSQL.Raw(sql, roleTypeCode).First(&item).Error
- 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=? `
- err = global.DEFAULT_DmSQL.Exec(sql, roleName, roleType, roleTypeCode, groupId).Error
- return
- }
- type SysRoleDeleteReq struct {
- RoleId int `description:"角色ID"`
- }
- func DeleteSysRole(roleId int) (err error) {
- sql := `DELETE FROM sys_role WHERE role_id=? `
- err = global.DEFAULT_DmSQL.Exec(sql, roleId).Error
- return
- }
- func GetSysRoleListCount(condition string, pars []interface{}) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM sys_role WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
- return
- }
- func GetSysRoleList(condition string, pars []interface{}, startSize, pageSize int) (items []*SysRoleItem, err error) {
- sql := `SELECT * FROM sys_role WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += `ORDER BY modify_time DESC LIMIT ?,?`
- pars = append(pars, startSize)
- pars = append(pars, pageSize)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
- type SysRoleListResp struct {
- List []*SysRoleItem
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type RoleMenu struct {
- MenuId int `description:"导航唯一标识"`
- Name string `description:"导航名称"`
- NameEn string `description:"导航名称(英文)"`
- }
- type RoleMenuList struct {
- MenuId int `description:"导航唯一标识"`
- Name string `description:"导航名称"`
- NameEn string `description:"导航名称(英文)"`
- Child []*RoleMenu `gorm:"-"`
- 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 = global.DEFAULT_DmSQL.Raw(sql).Find(&items).Error
- return
- }
- func GetRoleMenuByParentId(parentId int) (items []*RoleMenu, err error) {
- sql := `SELECT * FROM sys_menu WHERE parent_id=? ORDER BY sort ASC `
- err = global.DEFAULT_DmSQL.Raw(sql, parentId).Find(&items).Error
- 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 a.type = 0
- AND b.parent_id=? `
- err = global.DEFAULT_DmSQL.Raw(sql, roleId, parentId).Find(&items).Error
- 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 = global.DEFAULT_DmSQL.Exec(sql, roleId).Error
- return
- }
- type SysRoleMenu struct {
- RoleMenuId int `gorm:"primaryKey"`
- RoleId int
- MenuId int
- Type int `description:"类型:0-全选;1-半选(此字段仅用于前端的回显)"`
- }
- func AddSysRoleMenu(item *SysRoleMenu) (lastId int64, err error) {
- err = global.DEFAULT_DmSQL.Create(item).Error
- return
- }
- // CreateMultiSysRoleMenu 删除并新增角色权限
- func CreateMultiSysRoleMenu(roleId int, items []*SysRoleMenu) (err error) {
- if roleId == 0 {
- return
- }
- tx := global.DEFAULT_DmSQL.Begin()
- defer func() {
- if err != nil {
- _ = tx.Rollback()
- return
- }
- _ = tx.Commit()
- }()
- sql := `DELETE FROM sys_role_menu WHERE role_id = ?`
- err = tx.Exec(sql, roleId).Error
- if err != nil {
- return
- }
- if len(items) > 0 {
- err = tx.CreateInBatches(items, utils.MultiAddNum).Error
- }
- return
- }
- func GetSysRoleAll(levelFlag bool) (items []*SysRoleItem, err error) {
- sql := `SELECT * FROM sys_role WHERE 1=1`
- if levelFlag {
- sql += ` and role_level = 0`
- }
- sql += ` ORDER BY create_time DESC `
- err = global.DEFAULT_DmSQL.Raw(sql).Find(&items).Error
- return
- }
- type SysRoleAllResp struct {
- List []*SysRoleItem
- }
- // GetEnglishAuthRoleIds 获取英文权限角色IDs
- func GetEnglishAuthRoleIds(roleCodes []string) (roleIds []int, err error) {
- if len(roleCodes) == 0 {
- return
- }
- sql := `SELECT role_id FROM sys_role WHERE role_type_code IN (` + utils.GetOrmInReplace(len(roleCodes)) + `)`
- err = global.DEFAULT_DmSQL.Raw(sql, roleCodes).Scan(&roleIds).Error
- return
- }
- // GetSysRoleMenuByRoleId 获取角色关联菜单
- func GetSysRoleMenuByRoleId(roleId int) (items []*SysRoleMenu, err error) {
- sql := `SELECT
- *
- FROM
- sys_role_menu
- WHERE
- role_id = ?`
- err = global.DEFAULT_DmSQL.Raw(sql, roleId).Find(&items).Error
- return
- }
- // GetEnglishAuthRoleItems 获取英文权限角色
- func GetEnglishAuthRoleItems(roleCodes []string) (items []*SysRole, err error) {
- if len(roleCodes) == 0 {
- return
- }
- sql := `SELECT * FROM sys_role WHERE role_type_code IN (` + utils.GetOrmInReplace(len(roleCodes)) + `)`
- err = global.DEFAULT_DmSQL.Raw(sql, roleCodes).Find(&items).Error
- return
- }
|