sys_role_admin.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package system
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "time"
  6. )
  7. type SysRoleAdmin struct {
  8. Id int `gorm:"primaryKey" description:"自增ID"`
  9. AdminId int `orm:"column(admin_id);" description:"系统用户id"`
  10. RoleId int `orm:"column(role_id);" description:"角色ID"`
  11. CreateTime time.Time `orm:"column(create_time);" description:"创建时间"`
  12. }
  13. type RoleAdminItem struct {
  14. SysRoleAdminId int `description:"管理员账号和角色映射表id"`
  15. AdminId int `description:"系统用户id"`
  16. AdminName string `description:"系统用户名称"`
  17. RealName string `description:"系统用户姓名"`
  18. Enabled int `description:"1:有效,0:禁用"`
  19. Mobile string `description:"手机号"`
  20. RoleId int `description:"角色Id"`
  21. RoleTypeCode string `description:"角色编码"`
  22. DepartmentId int `description:"部门id"`
  23. DepartmentName string `description:"部门名称"`
  24. DepartmentGroup string `description:"部门分组"`
  25. TeamId int `description:"小组id"`
  26. GroupId int `description:"分组id"`
  27. GroupName string `description:"分组名称"`
  28. Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,4:ficc销售组长"`
  29. LabelVal int `description:"标签:1:超级管理员,2:管理员,3:部门经理,4:组长,5:ficc销售主管"`
  30. }
  31. func (sa *SysRoleAdmin) TableName() string {
  32. return "sys_role_admin"
  33. }
  34. // GetRoleIdsByAdminId 根据管理员账号查询角色ID
  35. func GetRoleIdsByAdminId(adminId int) (items []*SysRoleAdmin, err error) {
  36. sql := `SELECT * from sys_role_admin where admin_id = ?`
  37. err = global.DEFAULT_DmSQL.Raw(sql, adminId).Find(&items).Error
  38. return
  39. }
  40. // GetRoleAdminList 查询对应角色绑定的管理员列表
  41. func GetRoleAdminList(condition string, pars []interface{}, startSize, pageSize int) (list []*RoleAdminItem, err error) {
  42. sql := `SELECT
  43. s.id as sys_role_admin_id,
  44. a.admin_id,
  45. a.admin_name,
  46. a.real_name,
  47. a.mobile,
  48. a.department_id,
  49. a.department_name,
  50. a.enabled,
  51. a.role_id,
  52. a.role_type_code ,
  53. a.group_id,
  54. a.authority,
  55. a.group_name
  56. FROM
  57. sys_role_admin s
  58. INNER JOIN "admin" a ON s.admin_id = a.admin_id
  59. where 1=1`
  60. if condition != "" {
  61. sql += condition
  62. }
  63. sql += ` ORDER BY s.id DESC limit ?, ?`
  64. //_, err = orm.NewOrm().Raw(sql, pars...).QueryRows(&list)
  65. pars = append(pars, startSize)
  66. pars = append(pars, pageSize)
  67. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&list).Error
  68. return
  69. }
  70. // GetRoleAdminListTotal 查询对应角色绑定的管理员列表总数
  71. func GetRoleAdminListTotal(condition string, pars []interface{}) (total int64, err error) {
  72. sql := `SELECT
  73. count(*)
  74. FROM
  75. sys_role_admin s
  76. INNER JOIN "admin" a ON s.admin_id = a.admin_id
  77. where 1=1`
  78. if condition != "" {
  79. sql += condition
  80. }
  81. //err = orm.NewOrm().Raw(sql, pars).QueryRow(&total)
  82. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&total).Error
  83. return
  84. }
  85. // CheckRoleAdminByAdminIds 判断是否已经绑定过该角色
  86. func CheckRoleAdminByAdminIds(adminIds string, roleId int) (list []*SysRoleAdmin, err error) {
  87. sql := `SELECT
  88. s.*
  89. FROM
  90. sys_role_admin s
  91. LEFT JOIN "admin" a ON s.admin_id = a.admin_id
  92. where s.role_id=? and s.admin_id in (` + adminIds + `)`
  93. //_, err = orm.NewOrm().Raw(sql, roleId).QueryRows(&list)
  94. err = global.DEFAULT_DmSQL.Raw(sql, roleId).Find(&list).Error
  95. return
  96. }
  97. // AddRoleAdminBatch 批量新增留言版管理员
  98. func AddRoleAdminBatch(admins []*SysRoleAdmin) (err error) {
  99. err = global.DEFAULT_DmSQL.CreateInBatches(admins, utils.MultiAddNum).Error
  100. return
  101. }
  102. // DeleteRoleAdmin 删除管理员和角色的绑定
  103. func DeleteRoleAdmin(SysRoleAdminId int) (err error) {
  104. sql := `DELETE FROM sys_role_admin WHERE id=? `
  105. err = global.DEFAULT_DmSQL.Exec(sql, SysRoleAdminId).Error
  106. return
  107. }