123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package system
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/utils"
- "time"
- )
- type SysRoleAdmin struct {
- Id int `gorm:"primaryKey" description:"自增ID"`
- AdminId int `orm:"column(admin_id);" description:"系统用户id"`
- RoleId int `orm:"column(role_id);" description:"角色ID"`
- CreateTime time.Time `orm:"column(create_time);" description:"创建时间"`
- }
- type RoleAdminItem struct {
- SysRoleAdminId int `description:"管理员账号和角色映射表id"`
- AdminId int `description:"系统用户id"`
- AdminName string `description:"系统用户名称"`
- RealName string `description:"系统用户姓名"`
- Enabled int `description:"1:有效,0:禁用"`
- Mobile string `description:"手机号"`
- RoleId int `description:"角色Id"`
- RoleTypeCode string `description:"角色编码"`
- DepartmentId int `description:"部门id"`
- DepartmentName string `description:"部门名称"`
- DepartmentGroup string `description:"部门分组"`
- TeamId int `description:"小组id"`
- GroupId int `description:"分组id"`
- GroupName string `description:"分组名称"`
- Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,4:ficc销售组长"`
- LabelVal int `description:"标签:1:超级管理员,2:管理员,3:部门经理,4:组长,5:ficc销售主管"`
- }
- func (sa *SysRoleAdmin) TableName() string {
- return "sys_role_admin"
- }
- // GetRoleIdsByAdminId 根据管理员账号查询角色ID
- func GetRoleIdsByAdminId(adminId int) (items []*SysRoleAdmin, err error) {
- sql := `SELECT * from sys_role_admin where admin_id = ?`
- err = global.DEFAULT_DmSQL.Raw(sql, adminId).Find(&items).Error
- return
- }
- // GetRoleAdminList 查询对应角色绑定的管理员列表
- func GetRoleAdminList(condition string, pars []interface{}, startSize, pageSize int) (list []*RoleAdminItem, err error) {
- sql := `SELECT
- s.id as sys_role_admin_id,
- a.admin_id,
- a.admin_name,
- a.real_name,
- a.mobile,
- a.department_id,
- a.department_name,
- a.enabled,
- a.role_id,
- a.role_type_code ,
- a.group_id,
- a.authority,
- a.group_name
- FROM
- sys_role_admin s
- INNER JOIN "admin" a ON s.admin_id = a.admin_id
- where 1=1`
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY s.id DESC limit ?, ?`
- //_, err = orm.NewOrm().Raw(sql, pars...).QueryRows(&list)
- pars = append(pars, startSize)
- pars = append(pars, pageSize)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&list).Error
- return
- }
- // GetRoleAdminListTotal 查询对应角色绑定的管理员列表总数
- func GetRoleAdminListTotal(condition string, pars []interface{}) (total int64, err error) {
- sql := `SELECT
- count(*)
- FROM
- sys_role_admin s
- INNER JOIN "admin" a ON s.admin_id = a.admin_id
- where 1=1`
- if condition != "" {
- sql += condition
- }
- //err = orm.NewOrm().Raw(sql, pars).QueryRow(&total)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&total).Error
- return
- }
- // CheckRoleAdminByAdminIds 判断是否已经绑定过该角色
- func CheckRoleAdminByAdminIds(adminIds string, roleId int) (list []*SysRoleAdmin, err error) {
- sql := `SELECT
- s.*
- FROM
- sys_role_admin s
- LEFT JOIN "admin" a ON s.admin_id = a.admin_id
- where s.role_id=? and s.admin_id in (` + adminIds + `)`
- //_, err = orm.NewOrm().Raw(sql, roleId).QueryRows(&list)
- err = global.DEFAULT_DmSQL.Raw(sql, roleId).Find(&list).Error
- return
- }
- // AddRoleAdminBatch 批量新增留言版管理员
- func AddRoleAdminBatch(admins []*SysRoleAdmin) (err error) {
- err = global.DEFAULT_DmSQL.CreateInBatches(admins, utils.MultiAddNum).Error
- return
- }
- // DeleteRoleAdmin 删除管理员和角色的绑定
- func DeleteRoleAdmin(SysRoleAdminId int) (err error) {
- sql := `DELETE FROM sys_role_admin WHERE id=? `
- err = global.DEFAULT_DmSQL.Exec(sql, SysRoleAdminId).Error
- return
- }
|