sys_admin.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package system
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. "time"
  7. )
  8. type AdminItem struct {
  9. AdminId int `description:"系统用户id"`
  10. AdminName string `description:"系统用户名称"`
  11. RealName string `description:"系统用户姓名"`
  12. Password string
  13. LastUpdatedPasswordTime string `json:"-"`
  14. Enabled int `description:"1:有效,0:禁用"`
  15. Email string `description:"系统用户邮箱"`
  16. LastLoginTime string
  17. CreatedTime time.Time
  18. LastUpdatedTime string
  19. Role string `description:"系统用户角色"`
  20. Mobile string `description:"手机号"`
  21. RoleType int `description:"角色类型:1需要录入指标,0:不需要"`
  22. RoleId int `description:"角色id"`
  23. RoleName string `description:"角色名称"`
  24. RoleTypeCode string `description:"角色编码"`
  25. DepartmentId int `description:"部门id"`
  26. DepartmentName string `json:"-" description:"部门名称"`
  27. TeamId int `description:"三级id"`
  28. GroupId int `description:"分组id"`
  29. GroupName string `json:"-" description:"分组名称"`
  30. Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,4:ficc销售组长"`
  31. Position string `description:"职位"`
  32. DepartmentGroup string `description:"部门分组"`
  33. LabelVal int `description:"标签:1:超级管理员,2:管理员,3:部门经理,4:组长,5:ficc销售主管"`
  34. ResearchGroupName string `description:"研究方向分组名称"`
  35. Province string `description:"省"`
  36. ProvinceCode string `description:"省编码"`
  37. City string `description:"市"`
  38. CityCode string `description:"市编码"`
  39. EmployeeId string `description:"员工工号(钉钉/每刻报销)"`
  40. }
  41. func GetSysAdminByName(adminName string) (item *Admin, err error) {
  42. sql := `SELECT * FROM admin WHERE admin_name=? `
  43. o := orm.NewOrm()
  44. err = o.Raw(sql, adminName).QueryRow(&item)
  45. return
  46. }
  47. func GetSysAdminById(adminId int) (item *Admin, err error) {
  48. sql := `SELECT * FROM admin WHERE admin_id=? `
  49. o := orm.NewOrm()
  50. err = o.Raw(sql, adminId).QueryRow(&item)
  51. return
  52. }
  53. // GetSysAdminByIdSlice 根据账户id列表获取账户信息列表
  54. func GetSysAdminByIdSlice(adminIdList []string) (items []*Admin, err error) {
  55. if len(adminIdList) <= 0 {
  56. return
  57. }
  58. sql := `SELECT * FROM admin WHERE admin_id in (` + strings.Join(adminIdList, ",") + `) `
  59. o := orm.NewOrm()
  60. _, err = o.Raw(sql).QueryRows(&items)
  61. return
  62. }
  63. func GetAdminByGroupId(groupId int) (items []*AdminItem, err error) {
  64. o := orm.NewOrm()
  65. sql := `SELECT * FROM admin WHERE group_id=? ORDER BY created_time DESC`
  66. _, err = o.Raw(sql, groupId).QueryRows(&items)
  67. return
  68. }
  69. // GetSysAdminList 获取admin列表
  70. func GetSysAdminList(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*Admin, err error) {
  71. fields := "*"
  72. if len(fieldArr) > 0 {
  73. fields = strings.Join(fieldArr, ",")
  74. }
  75. order := `enabled DESC, last_updated_time DESC`
  76. if orderRule != "" {
  77. order = orderRule
  78. }
  79. sql := fmt.Sprintf(`SELECT %s FROM admin WHERE 1=1 %s ORDER BY %s`, fields, condition, order)
  80. o := orm.NewOrm()
  81. _, err = o.Raw(sql, pars).QueryRows(&items)
  82. return
  83. }