sys_user.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package system
  2. import (
  3. "eta/eta_mobile/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type LoginReq struct {
  8. Username string `description:"账号"`
  9. Password string `description:"密码"`
  10. IsRemember bool `description:"是否属于受信设备"`
  11. }
  12. type LoginResp struct {
  13. Authorization string
  14. AdminName string `description:"系统用户名称"`
  15. RealName string `description:"系统用户姓名"`
  16. RoleName string `description:"角色名称"`
  17. RoleTypeCode string `description:"角色类型编码"`
  18. SysRoleTypeCode string `description:"角色类型编码"`
  19. AdminId int `description:"系统用户id"`
  20. ProductName string `description:"产品名称:admin,ficc,权益"`
  21. DepartmentName string `description:"部门名称"`
  22. Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,4:ficc销售组长"`
  23. }
  24. type Admin struct {
  25. AdminId int `orm:"column(admin_id);pk" description:"系统用户id"`
  26. AdminName string `description:"系统用户名称"`
  27. AdminAvatar string `description:"用户头像"`
  28. RealName string `description:"系统用户姓名"`
  29. Password string `json:"-"`
  30. LastUpdatedPasswordTime string `json:"-"`
  31. Enabled int
  32. Email string `description:"系统用户邮箱"`
  33. LastLoginTime string
  34. CreatedTime time.Time
  35. LastUpdatedTime string
  36. Role string `description:"系统用户角色"`
  37. Mobile string `description:"手机号"`
  38. RoleType int `description:"角色类型:1需要录入指标,0:不需要"`
  39. RoleId int `description:"角色ID"`
  40. RoleName string `description:"角色名称"`
  41. RoleTypeCode string `description:"角色类型编码"`
  42. DepartmentId int `description:"部门id"`
  43. DepartmentName string `description:"部门名称"`
  44. GroupId int `description:"分组id"`
  45. GroupName string `description:"分组名称"`
  46. Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,3:超级管理员,4:ficc销售组长"`
  47. Position string `description:"职位"`
  48. DisableTime time.Time `description:"禁用时间"`
  49. ChartPermission int8 `description:"图表权限id"`
  50. OpenId string `description:"弘则部门公众号的openid"`
  51. UnionId string `description:"微信公众平台唯一标识"`
  52. EdbPermission int8 `description:"指标库操作权限,0:只能操作 自己的,1:所有指标可操作"`
  53. MysteelChemicalPermission int8 `description:"钢联化工指标操作权限,0:只能操作 自己的,1:所有指标可操作"`
  54. PredictEdbPermission int8 `description:"预测指标库操作权限,0:只能操作 自己的,1:所有预测指标可操作"`
  55. Province string `description:"省"`
  56. ProvinceCode string `description:"省编码"`
  57. City string `description:"市"`
  58. CityCode string `description:"市编码"`
  59. EmployeeId string `description:"员工工号(钉钉/每刻报销)"`
  60. TelAreaCode string `description:"手机区号"`
  61. }
  62. // Update 更新用户基础信息
  63. func (item *Admin) Update(cols []string) (err error) {
  64. o := orm.NewOrm()
  65. _, err = o.Update(item, cols...)
  66. return
  67. }
  68. func CheckSysUser(userName, password string) (item *Admin, err error) {
  69. sql := ` SELECT a.*,b.role_type_code FROM admin AS a
  70. INNER JOIN sys_role AS b ON a.role_id=b.role_id WHERE a.admin_name=? AND a.password=? LIMIT 1`
  71. o := orm.NewOrm()
  72. err = o.Raw(sql, userName, password).QueryRow(&item)
  73. return
  74. }
  75. func GetSysUserById(sysUserId int) (item *Admin, err error) {
  76. sql := `SELECT * FROM admin WHERE admin_id=? LIMIT 1`
  77. o := orm.NewOrm()
  78. err = o.Raw(sql, sysUserId).QueryRow(&item)
  79. return
  80. }
  81. // GetAdminListByIdList 根据用户id列表获取系统用户列表
  82. func GetAdminListByIdList(idList []int) (items []*Admin, err error) {
  83. lenNum := len(idList)
  84. if lenNum <= 0 {
  85. return
  86. }
  87. sql := `SELECT * FROM admin WHERE admin_id in (` + utils.GetOrmInReplace(lenNum) + `) and enabled=1 `
  88. o := orm.NewOrm()
  89. _, err = o.Raw(sql, idList).QueryRows(&items)
  90. return
  91. }
  92. // GetSysUserByMobile 手机号获取用户
  93. func GetSysUserByMobile(mobile string) (item *Admin, err error) {
  94. o := orm.NewOrm()
  95. sql := `SELECT
  96. a.*, b.role_type_code
  97. FROM
  98. admin AS a
  99. INNER JOIN sys_role AS b ON a.role_id = b.role_id
  100. WHERE
  101. a.mobile = ?
  102. LIMIT 1`
  103. err = o.Raw(sql, mobile).QueryRow(&item)
  104. return
  105. }
  106. // GetSysUserByEmail 邮箱获取用户
  107. func GetSysUserByEmail(email string) (item *Admin, err error) {
  108. o := orm.NewOrm()
  109. sql := `SELECT
  110. a.*, b.role_type_code
  111. FROM
  112. admin AS a
  113. INNER JOIN sys_role AS b ON a.role_id = b.role_id
  114. WHERE
  115. a.email = ?
  116. LIMIT 1`
  117. err = o.Raw(sql, email).QueryRow(&item)
  118. return
  119. }
  120. // GetSysUserByAdminName 账号获取用户
  121. func GetSysUserByAdminName(adminName string) (item *Admin, err error) {
  122. o := orm.NewOrm()
  123. sql := `SELECT
  124. a.*, b.role_type_code
  125. FROM
  126. admin AS a
  127. INNER JOIN sys_role AS b ON a.role_id = b.role_id
  128. WHERE
  129. a.admin_name = ?
  130. LIMIT 1`
  131. err = o.Raw(sql, adminName).QueryRow(&item)
  132. return
  133. }