sys_admin.go 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package models
  2. import (
  3. "eta_gn/eta_report/global"
  4. "fmt"
  5. "strings"
  6. "time"
  7. )
  8. type Admin struct {
  9. AdminId int `gorm:"primaryKey;autoIncrement;column:admin_id"`
  10. AdminName string `description:"系统用户名称"`
  11. AdminAvatar string `description:"用户头像"`
  12. RealName string `description:"系统用户姓名"`
  13. Password string `json:"-"`
  14. LastUpdatedPasswordTime string `json:"-"`
  15. Enabled int
  16. Email string `description:"系统用户邮箱"`
  17. LastLoginTime string
  18. CreatedTime time.Time
  19. LastUpdatedTime string
  20. Role string `description:"系统用户角色"`
  21. Mobile string `description:"手机号"`
  22. RoleType int `description:"角色类型:1需要录入指标,0:不需要"`
  23. RoleId int `description:"角色ID"`
  24. RoleName string `description:"角色名称"`
  25. RoleTypeCode string `description:"角色类型编码"`
  26. DepartmentId int `description:"部门id"`
  27. DepartmentName string `description:"部门名称"`
  28. GroupId int `description:"分组id"`
  29. GroupName string `description:"分组名称"`
  30. Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,3:超级管理员,4:ficc销售组长"`
  31. Position string `description:"职位"`
  32. DisableTime time.Time `description:"禁用时间"`
  33. ChartPermission int8 `description:"图表权限id"`
  34. OpenId string `description:"国能部门公众号的openid"`
  35. UnionId string `description:"微信公众平台唯一标识"`
  36. EdbPermission int8 `description:"指标库操作权限,0:只能操作 自己的,1:所有指标可操作"`
  37. MysteelChemicalPermission int8 `description:"钢联化工指标操作权限,0:只能操作 自己的,1:所有指标可操作"`
  38. PredictEdbPermission int8 `description:"预测指标库操作权限,0:只能操作 自己的,1:所有预测指标可操作"`
  39. Province string `description:"省"`
  40. ProvinceCode string `description:"省编码"`
  41. City string `description:"市"`
  42. CityCode string `description:"市编码"`
  43. EmployeeId string `description:"员工工号(钉钉/每刻报销)"`
  44. TelAreaCode string `description:"手机区号"`
  45. IsLdap int `description:"是否为域用户:0-系统账户;1-域用户"`
  46. OutId string `description:"外部ID"`
  47. }
  48. func (m *Admin) TableName() string {
  49. return "admin"
  50. }
  51. func (m *Admin) GetAdminByOutId(outId string) (item *Admin, err error) {
  52. sql := fmt.Sprintf(`SELECT * FROM "admin" WHERE %s = ? LIMIT 1`, "out_id")
  53. err = global.DmSQL["eta"].Raw(sql, outId).First(&item).Error
  54. return
  55. }
  56. func (m *Admin) GetItemById(id int) (item *Admin, err error) {
  57. sql := fmt.Sprintf(`SELECT * FROM "admin" WHERE %s = ? LIMIT 1`, "admin_id")
  58. err = global.DmSQL["eta"].Raw(sql, id).First(&item).Error
  59. return
  60. }
  61. func (m *Admin) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *Admin, err error) {
  62. order := ``
  63. if orderRule != "" {
  64. order = ` ORDER BY ` + orderRule
  65. }
  66. sql := fmt.Sprintf(`SELECT * FROM "admin" WHERE 1=1 %s %s LIMIT 1`, condition, order)
  67. err = global.DmSQL["eta"].Raw(sql, pars...).First(&item).Error
  68. return
  69. }
  70. func (m *Admin) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  71. sql := fmt.Sprintf(`SELECT COUNT(1) FROM "admin" WHERE 1=1 %s`, condition)
  72. err = global.DmSQL["eta"].Raw(sql, pars...).Scan(&count).Error
  73. return
  74. }
  75. func (m *Admin) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*Admin, err error) {
  76. fields := strings.Join(fieldArr, ",")
  77. if len(fieldArr) == 0 {
  78. fields = `*`
  79. }
  80. order := `ORDER BY created_time DESC`
  81. if orderRule != "" {
  82. order = ` ORDER BY ` + orderRule
  83. }
  84. sql := fmt.Sprintf(`SELECT %s FROM "admin" WHERE 1=1 %s %s`, fields, condition, order)
  85. err = global.DmSQL["eta"].Raw(sql, pars...).Find(&items).Error
  86. return
  87. }