industry_fllow.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. //"time"
  6. )
  7. type CygxIndustryFllow struct {
  8. Id int `orm:"column(id);pk"`
  9. IndustrialManagementId int `description:"产业D"`
  10. UserId int `description:"用户ID"`
  11. Mobile string `description:"手机号"`
  12. Email string `description:"邮箱"`
  13. CompanyId int `description:"公司id"`
  14. CompanyName string `description:"公司名称"`
  15. Type int `description:"操作方式,1报名,2取消报名"`
  16. CreateTime time.Time `description:"创建时间"`
  17. ModifyTime time.Time `description:"更新时间"`
  18. RealName string `description:"用户实际名称"`
  19. Source int `description:"来源1查研观向,2查研观向小助手,3勾选全部赛道的用户进行自动关注"`
  20. }
  21. // 列表
  22. func GetCygxIndustryFllowList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxIndustryFllow, err error) {
  23. o := orm.NewOrmUsingDB("hz_cygx")
  24. sql := `SELECT * FROM cygx_industry_fllow WHERE 1= 1 `
  25. if condition != "" {
  26. sql += condition
  27. }
  28. if startSize+pageSize > 0 {
  29. sql += ` LIMIT ?,? `
  30. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  31. } else {
  32. _, err = o.Raw(sql, pars).QueryRows(&items)
  33. }
  34. return
  35. }
  36. // 关注产业列表
  37. func GetCygxIndustryFllowByUser(uid, startSize, pageSize int, condition string) (items []*UserInteraction, err error) {
  38. o := orm.NewOrmUsingDB("hz_cygx")
  39. sql := `SELECT
  40. a.industry_name,
  41. f.modify_time as create_time,
  42. ( SELECT GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' ) FROM cygx_industrial_subject AS s WHERE s.industrial_management_id = f.industrial_management_id ) AS subject_name_str
  43. FROM
  44. cygx_industry_fllow AS f
  45. INNER JOIN cygx_industrial_management AS a ON a.industrial_management_id = f.industrial_management_id
  46. WHERE
  47. f.user_id = ?
  48. AND f.type = 1
  49. AND f.source IN (0,1,2) ` + condition +
  50. `ORDER BY
  51. f.create_time DESC LIMIT ?,? `
  52. _, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items)
  53. return
  54. }
  55. // 关注产业数量
  56. func GetCygxIndustryFllowCount(uid int, condition string) (count int, err error) {
  57. o := orm.NewOrmUsingDB("hz_cygx")
  58. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industry_fllow as f
  59. INNER JOIN cygx_industrial_management as a ON a.industrial_management_id = f.industrial_management_id
  60. WHERE f.user_id = ? AND f.type = 1 AND f.source IN (0,1,2) ` + condition
  61. err = o.Raw(sqlCount, uid).QueryRow(&count)
  62. return
  63. }
  64. // 判断用户是否关注这些产业ID
  65. func GetCygxIndustryFllowCountByUser(uid int, industrialManagementd string) (count int, err error) {
  66. o := orm.NewOrmUsingDB("hz_cygx")
  67. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE user_id = ? AND type = 1 AND industrial_management_id IN (` + industrialManagementd + `)`
  68. err = o.Raw(sqlCount, uid).QueryRow(&count)
  69. return
  70. }
  71. // GetUserFllowIndustrialListByUserIdAndIndustrial 通过用户ID 跟产业ID获取用户关注的产业列表
  72. func GetUserFllowIndustrialListByUserIdAndIndustrial(userIds, industrials string) (items []*CygxIndustryFllow, err error) {
  73. o := orm.NewOrmUsingDB("hz_cygx")
  74. sql := `SELECT * FROM cygx_industry_fllow
  75. WHERE 1 = 1
  76. AND user_id IN ( ` + userIds + ` )
  77. AND industrial_management_id IN ( ` + industrials + `) `
  78. _, err = o.Raw(sql).QueryRows(&items)
  79. return
  80. }
  81. // 批量添加
  82. func AddCygxIndustryFllowMulti(items []*CygxIndustryFllow) (err error) {
  83. o := orm.NewOrmUsingDB("hz_cygx")
  84. if len(items) > 0 {
  85. //批量添加新的关注记录
  86. _, err = o.InsertMulti(len(items), items)
  87. }
  88. return
  89. }
  90. // 获取所有关注了该产业永续客户的openid
  91. func GetCygxForeverUserIndustryFllowOpneidByActivityIds(activityId int) (items []*OpenIdList, err error) {
  92. o := orm.NewOrmUsingDB("hz_cygx")
  93. sql := `SELECT
  94. f.*
  95. FROM
  96. cygx_industrial_activity_group_management AS agm
  97. INNER JOIN cygx_industry_fllow AS f ON f.industrial_management_id = agm.industrial_management_id
  98. WHERE
  99. agm.activity_id = ?`
  100. _, err = o.Raw(sql, activityId).QueryRows(&items)
  101. return
  102. }
  103. // 获取所有关注了该产业用户的companyIds
  104. func GetCygxIndustryFollowCompanyIdsByActivityId(activityId int) (item *string, err error) {
  105. o := orm.NewOrmUsingDB("hz_cygx")
  106. sql := ` SELECT
  107. GROUP_CONCAT( DISTINCT f.company_id SEPARATOR ',' ) AS company_ids
  108. FROM
  109. cygx_industrial_activity_group_management AS agm
  110. INNER JOIN cygx_industry_fllow AS f ON f.industrial_management_id = agm.industrial_management_id
  111. WHERE
  112. agm.activity_id = ? `
  113. err = o.Raw(sql, activityId).QueryRow(&item)
  114. return
  115. }