sys_user.go 7.3 KB

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