sys_user.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package eta_trial
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type ETATrialAdmin struct {
  8. AdminId int `orm:"column(admin_id);pk" description:"系统用户id"`
  9. AdminName string `description:"系统用户名称"`
  10. AdminAvatar string `description:"用户头像"`
  11. RealName string `description:"系统用户姓名"`
  12. Password string `json:"-"`
  13. LastUpdatedPasswordTime string `json:"-"`
  14. Enabled int
  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 `description:"部门名称"`
  27. GroupId int `description:"分组id"`
  28. GroupName string `description:"分组名称"`
  29. Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,3:超级管理员,4:ficc销售组长"`
  30. Position string `description:"职位"`
  31. DisableTime time.Time `description:"禁用时间"`
  32. ChartPermission int8 `description:"图表权限id"`
  33. OpenId string `description:"弘则部门公众号的openid"`
  34. UnionId string `description:"微信公众平台唯一标识"`
  35. EdbPermission int8 `description:"指标库操作权限,0:只能操作 自己的,1:所有指标可操作"`
  36. MysteelChemicalPermission int8 `description:"钢联化工指标操作权限,0:只能操作 自己的,1:所有指标可操作"`
  37. }
  38. func (item *ETATrialAdmin) Update(cols []string) (err error) {
  39. o := orm.NewOrm()
  40. _, err = o.Update(item, cols...)
  41. return
  42. }
  43. func AddAdmin(item *ETATrialAdmin) (lastId int, err error) {
  44. o := orm.NewOrmUsingDB("weekly_trial")
  45. sql := `INSERT INTO admin ( admin_name, real_name, password, last_updated_password_time, enabled, last_login_time, created_time, last_updated_time, mobile, role_id, role_name, role_type_code, department_id, department_name, role, position) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )`
  46. _, err = o.Raw(sql, item.AdminName, item.RealName, item.Password, item.LastUpdatedPasswordTime, item.Enabled, item.LastLoginTime, item.CreatedTime, item.LastUpdatedTime, item.Mobile, item.RoleId, item.RoleName, item.RoleTypeCode, item.DepartmentId, item.DepartmentName, item.Role, item.Position).Exec()
  47. sql = `SELECT MAX(admin_id) FROM admin`
  48. err = o.Raw(sql).QueryRow(&lastId)
  49. return
  50. }
  51. func GetSysUserByRoleAndDepartment(role, dep string) (item *ETATrialAdmin, err error) {
  52. sql := `SELECT * FROM admin WHERE role_name=? AND department_name=? LIMIT 1`
  53. o := orm.NewOrmUsingDB("weekly_trial")
  54. err = o.Raw(sql, role, dep).QueryRow(&item)
  55. return
  56. }
  57. // GetSysAdminCountByMobile 查询系统中是否存在该手机号(如果有传入用户id,那么排除该用户)
  58. func GetSysAdminCountByMobile(mobile string, adminId int) (count int, err error) {
  59. sql := `SELECT COUNT(1) AS count FROM admin WHERE mobile=? `
  60. if adminId > 0 {
  61. sql += ` AND admin_id != ` + fmt.Sprint(adminId)
  62. }
  63. o := orm.NewOrmUsingDB("weekly_trial")
  64. err = o.Raw(sql, mobile).QueryRow(&count)
  65. return
  66. }
  67. func (item *ETATrialAdmin) TableName() string {
  68. return "admin"
  69. }
  70. func UpdateAdminEnable(mobile string) (err error) {
  71. sql := `UPDATE admin SET enabled=1 WHERE mobile=? `
  72. o := orm.NewOrmUsingDB("weekly_trial")
  73. _, err = o.Raw(sql, mobile).Exec()
  74. return
  75. }