wx_user_rai_label.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. type WxUserRaiLabel struct {
  8. RaiLabelId int `orm:"column(rai_label_id);pk"`
  9. UserId int `description:"用户ID"`
  10. RealName string `description:"用户实际名称"`
  11. Mobile string `description:"手机号"`
  12. Email string `description:"邮箱"`
  13. CompanyId int `description:"公司id"`
  14. CompanyName string `description:"公司名称"`
  15. Label string `description:"标签内容"`
  16. SourceId int `description:"来源ID"`
  17. SourceType int `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"`
  18. SysUserId int `description:"创建人id"`
  19. SysUserRealName string `description:"创建人名称"`
  20. CreateTime time.Time `description:"创建时间"`
  21. ModifyTime time.Time `description:"更新时间"`
  22. }
  23. type WxUserRaiLabelList struct {
  24. List []*WxUserRaiLabelListResp
  25. }
  26. type WxUserRaiLabelListResp struct {
  27. UserId int `description:"用户ID"`
  28. RaiLabelId int `description:"ID"`
  29. Label string `description:"标签内容"`
  30. SourceType int `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"`
  31. }
  32. type WxUserRaiLabelAddReq struct {
  33. UserId int `description:"用户ID"`
  34. Label string `description:"标签内容"`
  35. }
  36. type WxUserRaiLabelIdReq struct {
  37. RaiLabelId int `description:"ID"`
  38. }
  39. // 添加
  40. func AddWxUserRaiLabel(item *WxUserRaiLabel) (err error) {
  41. o := orm.NewOrmUsingDB("hz_cygx")
  42. _, err = o.Insert(item)
  43. return
  44. }
  45. // DeleteWxUserRaiLabel 根据主键ID删除数据
  46. func DeleteWxUserRaiLabel(raiLabelId int) (err error) {
  47. o := orm.NewOrmUsingDB("hz_cygx")
  48. sql := ` DELETE FROM wx_user_rai_label WHERE rai_label_id = ? `
  49. _, err = o.Raw(sql, raiLabelId).Exec()
  50. return
  51. }
  52. // GetWxUserRaiLabelListByUserIds 根据多个userId 获取每个UserId最新的十条数据
  53. func GetWxUserRaiLabelListByUserIds(userIdArr []int) (list []*WxUserRaiLabelListResp, err error) {
  54. lenArr := len(userIdArr)
  55. if lenArr == 0 {
  56. return
  57. }
  58. o := orm.NewOrmUsingDB("hz_cygx")
  59. sql := `SELECT
  60. t.rai_label_id,
  61. t.user_id,
  62. t.label,
  63. t.source_type
  64. FROM
  65. (
  66. SELECT
  67. rai_label_id,
  68. user_id,
  69. label,
  70. source_type,
  71. create_time,
  72. @row_number :=
  73. IF
  74. ( @prev_user_id = user_id, @row_number + 1, 1 ) AS rank,
  75. @prev_user_id := user_id
  76. FROM
  77. wx_user_rai_label,
  78. ( SELECT @row_number := 0, @prev_user_id := NULL ) AS vars
  79. WHERE
  80. user_id IN ( ` + utils.GetOrmInReplace(lenArr) + ` )
  81. ORDER BY
  82. user_id DESC
  83. ) AS t
  84. WHERE
  85. t.rank <= 10
  86. ORDER BY
  87. t.create_time DESC `
  88. _, err = o.Raw(sql, userIdArr).QueryRows(&list)
  89. return
  90. }
  91. // GetWxUserRaiLabelListByUserId 根据用户ID,获取最近四个月的数据信息
  92. func GetWxUserRaiLabelListByUserId(userId int) (list []*WxUserRaiLabelListResp, err error) {
  93. o := orm.NewOrmUsingDB("hz_cygx")
  94. sql := `SELECT
  95. rai_label_id,
  96. user_id,
  97. label,
  98. source_type
  99. FROM
  100. wx_user_rai_label
  101. WHERE
  102. user_id = ? AND create_time >= ?
  103. ORDER BY
  104. create_time DESC LIMIT 1000 `
  105. _, err = o.Raw(sql, userId, time.Now().AddDate(0, -4, 0).Format(utils.FormatDate)).QueryRows(&list)
  106. return
  107. }
  108. // 通过纪要ID获取详情
  109. func GetWxUserRaiLabelDetailById(raiLabelId int) (item *WxUserRaiLabel, err error) {
  110. o := orm.NewOrmUsingDB("hz_cygx")
  111. sql := `SELECT
  112. *
  113. FROM
  114. wx_user_rai_label
  115. WHERE
  116. rai_label_id =? `
  117. err = o.Raw(sql, raiLabelId).QueryRow(&item)
  118. return
  119. }
  120. type WxUserRaiLabelDetailResp struct {
  121. SourceType int `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"`
  122. KeyWord *WxUserRaiLabelKeyWordResp
  123. Activity *WxUserRaiLabelActivityResp
  124. RoadShow *WxUserRaiLabelRoadShowResp
  125. Seller *WxUserRaiLabelSellerResp
  126. Article *WxUserRaiLabelArticleResp
  127. }
  128. type WxUserRaiLabelKeyWordResp struct {
  129. Label string `description:"标签内容"`
  130. CreateTime string `description:"创建时间"`
  131. }
  132. type WxUserRaiLabelActivityResp struct {
  133. ActivityName string `description:"活动名称"`
  134. ActivityTypeName string `description:"活动类型名称"`
  135. ActivityTime string `description:"活动时间"`
  136. Duration string `description:"参会时长"`
  137. Label string `description:"标签内容"`
  138. }
  139. type WxUserRaiLabelRoadShowResp struct {
  140. Theme string `description:"会议主题"`
  141. ResearcherName string `description:"研究员名称"`
  142. RoadShowTime string `description:"开始时间"`
  143. Label string `description:"标签内容"`
  144. }
  145. type WxUserRaiLabelSellerResp struct {
  146. Label string `description:"标签内容"`
  147. SysUserRealName string `description:"创建人名称"`
  148. CreateTime string `description:"创建时间"`
  149. }
  150. type WxUserRaiLabelArticleResp struct {
  151. Title string `description:"标题"`
  152. PublishDate time.Time `description:"发布时间"`
  153. CreateTime string `description:"创建时间"`
  154. SourceText string `description:"阅读来源"`
  155. StopTime string `description:"阅读停留时间"`
  156. Label string `description:"标签内容"`
  157. }
  158. type WxUserRaiLabelRedis struct {
  159. UserId int `description:"用户ID"`
  160. SourceId int `description:"资源ID"`
  161. Label string `description:"标签内容"`
  162. SourceType int `description:"来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签"`
  163. CreateTime time.Time `description:"创建时间"`
  164. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  165. TableName string `description:"数据来源的表名"`
  166. }