activity_ask_email.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/models/system"
  5. )
  6. type AskEmailRep struct {
  7. Name string `description:"姓名"`
  8. Email string `description:"邮箱"`
  9. Mobile string `description:"手机号"`
  10. ChartPermissionName string `description:"权限名称"`
  11. AdminId int
  12. }
  13. func GetAskEmail() (item []*AskEmailRep, err error) {
  14. o := orm.NewOrmUsingDB("hz_cygx")
  15. sql := `SELECT * FROM cygx_activity_ask_email`
  16. _, err = o.Raw(sql).QueryRows(&item)
  17. return
  18. }
  19. // 判断研究员是不是策略行业的
  20. func GetAskEmailCountByCelue(adminId string) (count int, err error) {
  21. o := orm.NewOrmUsingDB("hz_cygx")
  22. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_ask_email WHERE chart_permission_name = '策略' AND admin_id IN (` + adminId + `) `
  23. err = o.Raw(sqlCount).QueryRow(&count)
  24. return
  25. }
  26. func GetAskEmailListByAdminIds(adminId string) (item []*AskEmailRep, err error) {
  27. o := orm.NewOrmUsingDB("hz_cygx")
  28. sql := `SELECT * FROM cygx_activity_ask_email WHERE chart_permission_name != '' AND admin_id IN (` + adminId + `) `
  29. _, err = o.Raw(sql).QueryRows(&item)
  30. return
  31. }
  32. func GetAskEmailList() (item []*AskEmailRep, err error) {
  33. o := orm.NewOrmUsingDB("hz_cygx")
  34. sql := `SELECT * FROM cygx_activity_ask_email WHERE chart_permission_name != '' ORDER BY sort DESC`
  35. _, err = o.Raw(sql).QueryRows(&item)
  36. return
  37. }
  38. func UpdateAskEmail(item *AskEmailRep) (err error) {
  39. o := orm.NewOrmUsingDB("hz_cygx")
  40. sql := `UPDATE cygx_activity_ask_email SET admin_id=? where mobile=?`
  41. _, err = o.Raw(sql, item.AdminId, item.Mobile).Exec()
  42. return
  43. }
  44. func InitSyncActivityAskEmailAdminId() {
  45. list, err := GetAskEmailList()
  46. if err != nil {
  47. return
  48. }
  49. sysUserList, err := system.GetAdminList()
  50. if err != nil {
  51. return
  52. }
  53. adminMap := make(map[string]*system.Admin, 0)
  54. for _, v := range sysUserList {
  55. adminMap[v.Mobile] = v
  56. }
  57. for _, v := range list {
  58. if admin, ok := adminMap[v.Mobile]; ok {
  59. v.AdminId = admin.AdminId
  60. err = UpdateAskEmail(v)
  61. if err != nil {
  62. return
  63. }
  64. }
  65. }
  66. }