wework_user.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package day_new
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // 企业微信用户信息表
  7. type WeworkUser struct {
  8. Id uint64 `orm:"column(id);pk;" description:"自增ID"`
  9. WwUserId string `orm:"column(ww_user_id)" description:"企业微信成员userid"`
  10. WwExtendUserId string `orm:"column(ww_extend_user_id)" description:"非企业成员id(external_userid)"`
  11. WwNickName string `orm:"column(ww_nick_name)" description:"企业微信昵称/微信昵称"`
  12. WwDeptId int `orm:"column(ww_dept_id)" description:"企业微信内部门ID"`
  13. CreateTime time.Time `orm:"column(create_time)" description:"创建时间"`
  14. ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
  15. }
  16. // AddWeworkUserMulti 批量新增用户
  17. func AddWeworkUserMulti(list []*WeworkUser) (err error) {
  18. o := orm.NewOrm()
  19. _, err = o.InsertMulti(len(list), list)
  20. return
  21. }
  22. // GetAllWeworkUser 获取所有企业微信用户
  23. func GetAllWeworkUser() (list []*WeworkUser, err error) {
  24. o := orm.NewOrm()
  25. sql := `SELECT * FROM wework_user`
  26. _, err = o.Raw(sql).QueryRows(&list)
  27. return
  28. }
  29. // GetEmptyNickNameWeworkUser 获取所有企业微信昵称为空的用户
  30. func GetEmptyNickNameWeworkUser() (list []*WeworkUser, err error) {
  31. o := orm.NewOrm()
  32. sql := `SELECT * FROM wework_user where (ww_nick_name = "" or ww_nick_name is null)`
  33. _, err = o.Raw(sql).QueryRows(&list)
  34. return
  35. }
  36. // GetWeworkUserByUserIds 根据员工ID查询员工姓名
  37. func GetWeworkUserByUserIds(userIds string) (list []*WeworkUser, err error) {
  38. o := orm.NewOrm()
  39. sql := `SELECT * FROM wework_user where ww_user_id in (`+userIds+`)`
  40. _, err = o.Raw(sql).QueryRows(&list)
  41. return
  42. }
  43. // GetWeworkUserByExtendUserIds 根据客户联系人ID查询昵称
  44. func GetWeworkUserByExtendUserIds(extendUserIds string) (list []*WeworkUser, err error) {
  45. o := orm.NewOrm()
  46. sql := `SELECT * FROM wework_user where ww_extend_user_id in (`+extendUserIds+`)`
  47. _, err = o.Raw(sql).QueryRows(&list)
  48. return
  49. }
  50. // MultiUpdateWeworkUserName 批量更新用户姓名
  51. func MultiUpdateWeworkUserName(multiSql string, updateSendIds string) (err error) {
  52. o := orm.NewOrm()
  53. sql := `UPDATE wework_user
  54. SET modify_time=NOW(), ww_nick_name =
  55. CASE id `+multiSql+` END
  56. WHERE
  57. id IN (`+updateSendIds+` ) `
  58. _, err = o.Raw(sql).Exec()
  59. return
  60. }