industry_fllow.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxIndustryFllow struct {
  7. Id int `orm:"column(id);pk"`
  8. IndustrialManagementId int `description:"产业D"`
  9. UserId int `description:"用户ID"`
  10. Mobile string `description:"手机号"`
  11. Email string `description:"邮箱"`
  12. CompanyId int `description:"公司id"`
  13. CompanyName string `description:"公司名称"`
  14. Type int `description:"操作方式,1报名,2取消报名"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"更新时间"`
  17. RealName string `description:"用户实际名称"`
  18. Source int `description:"来源1查研观向,2查研观向小助手,3勾选全部赛道的用户进行自动关注"`
  19. }
  20. type CygxIndustryFllowRep struct {
  21. IndustrialManagementId int `description:"产业D"`
  22. }
  23. type IndustryFllowArryReq struct {
  24. SourceId int `description:"资源ID"`
  25. Source string `description:"资源类型 报告 :article 、活动 :activity"`
  26. DoType string `description:"操作方式 关注 :add 、取消关注 :cancel"`
  27. }
  28. // 添加
  29. func AddCygxIndustryFllow(item *CygxIndustryFllow) (lastId int64, err error) {
  30. o := orm.NewOrm()
  31. lastId, err = o.Insert(item)
  32. return
  33. }
  34. // 批量添加
  35. func AddCygxIndustryFllowMulti(items []*CygxIndustryFllow) (err error) {
  36. o := orm.NewOrm()
  37. if len(items) > 0 {
  38. //批量添加新的关注记录
  39. _, err = o.InsertMulti(len(items), items)
  40. }
  41. return
  42. }
  43. type CygxIndustryFllowResp struct {
  44. Status int `description:"1:关注,2:取消关注"`
  45. GoFollow bool `description:"是否去关注"`
  46. }
  47. func RemoveCygxIndustryFllow(userId, industrialManagementId int) (err error) {
  48. o := orm.NewOrm()
  49. sql := `DELETE FROM cygx_industry_fllow WHERE user_id=? AND industrial_management_id=? `
  50. _, err = o.Raw(sql, userId, industrialManagementId).Exec()
  51. return
  52. }
  53. // RemoveCygxIndustryFllowArry 多个产业同时取消关注
  54. func RemoveCygxIndustryFllowArry(userId int, condition string, pars []interface{}) (err error) {
  55. o := orm.NewOrm()
  56. if condition == "" {
  57. return
  58. }
  59. sql := `DELETE FROM cygx_industry_fllow WHERE user_id=? ` + condition
  60. _, err = o.Raw(sql, userId, pars).Exec()
  61. return
  62. }
  63. // 获取数量
  64. func GetCountCygxIndustryFllow(userId, industrialManagementId int, condition string) (count int, err error) {
  65. sql := `SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE user_id=? AND industrial_management_id=? ` + condition
  66. err = orm.NewOrm().Raw(sql, userId, industrialManagementId).QueryRow(&count)
  67. return
  68. }
  69. // 获取数量
  70. func GetCountCygxIndustryFllowByUid(userId int) (count int, err error) {
  71. sql := `SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE user_id=? `
  72. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  73. return
  74. }
  75. // 获取列表信息根据手机号分组
  76. func GetCygxIndustryFllowList(condition string) (items []*CygxIndustryFllow, err error) {
  77. o := orm.NewOrm()
  78. sql := `SELECT * FROM cygx_industry_fllow WHERE 1 =1 ` + condition + ` GROUP BY user_id `
  79. _, err = o.Raw(sql).QueryRows(&items)
  80. return
  81. }
  82. // 获取列表信息根据手机号分组
  83. func GetCygxIndustryFllowListByUserId(condition string) (items []*CygxIndustryFllow, err error) {
  84. o := orm.NewOrm()
  85. sql := `SELECT * FROM cygx_industry_fllow WHERE 1 =1 ` + condition
  86. _, err = o.Raw(sql).QueryRows(&items)
  87. return
  88. }
  89. // 修改用户关注的相关信息
  90. func UpdateCygxIndustryFllow(wxUser *WxUserItem) (err error) {
  91. o := orm.NewOrm()
  92. var sql string
  93. if wxUser.Mobile != "" {
  94. sql = `UPDATE cygx_industry_fllow SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
  95. _, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
  96. } else if wxUser.Email != "" {
  97. sql = `UPDATE cygx_industry_fllow SET mobile=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
  98. _, err = o.Raw(sql, wxUser.Mobile, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Email).Exec()
  99. }
  100. return
  101. }
  102. // 获取用户关注的产业列表
  103. func GetUserFllowIndustrialList(userId int) (items []*CygxIndustryFllow, err error) {
  104. o := orm.NewOrm()
  105. sql := `SELECT
  106. f.user_id,
  107. m.industry_name,
  108. m.industrial_management_id
  109. FROM
  110. cygx_industry_fllow AS f
  111. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id
  112. WHERE
  113. 1 = 1
  114. AND f.user_id = ? `
  115. _, err = o.Raw(sql, userId).QueryRows(&items)
  116. return
  117. }
  118. type CygxIndustryFllowCountRep struct {
  119. IndustrialManagementId int `description:"产业D"`
  120. Num int `description:"数量"`
  121. }
  122. // 获取产业被关注的数量
  123. func GetUserFllowIndustrialCountList() (items []*CygxIndustryFllowCountRep, err error) {
  124. o := orm.NewOrm()
  125. sql := `SELECT
  126. COUNT( 1 ) AS num,
  127. f.industrial_management_id
  128. FROM
  129. cygx_industry_fllow AS f
  130. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id
  131. WHERE
  132. 1 = 1
  133. GROUP BY
  134. f.industrial_management_id
  135. ORDER BY
  136. num DESC
  137. LIMIT 30 `
  138. _, err = o.Raw(sql).QueryRows(&items)
  139. return
  140. }
  141. // GetUserFllowIndustrialListByUserIdAndIndustrial 通过用户ID 跟产业ID获取用户关注的产业列表
  142. func GetUserFllowIndustrialListByUserIdAndIndustrial(userIds, industrials string) (items []*CygxIndustryFllow, err error) {
  143. o := orm.NewOrm()
  144. sql := `SELECT * FROM cygx_industry_fllow
  145. WHERE 1 = 1
  146. AND user_id IN ( ` + userIds + ` )
  147. AND industrial_management_id IN ( ` + industrials + `) `
  148. _, err = o.Raw(sql).QueryRows(&items)
  149. return
  150. }
  151. // 获取某个用户关注某个行业下的产业数量
  152. func GetCountCygxIndustryFllowByUidAndChartPermissionId(userId, ChartPermissionId int) (count int, err error) {
  153. sql := `SELECT
  154. COUNT( 1 ) AS count
  155. FROM
  156. cygx_industry_fllow AS f
  157. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id
  158. WHERE
  159. user_id = ?
  160. AND m.chart_permission_id = ? `
  161. err = orm.NewOrm().Raw(sql, userId, ChartPermissionId).QueryRow(&count)
  162. return
  163. }
  164. // GetTopIndustryFollowData 获取关注度最高的产业关注数据
  165. func GetTopIndustryFollowData(startSize, pageSize int, condition string, pars []interface{}) (list []*IndustrialManagement, err error) {
  166. sql := `SELECT
  167. COUNT(1) AS one_month_follow_num,
  168. man.*
  169. FROM
  170. cygx_industry_fllow AS idf
  171. JOIN cygx_industrial_management AS man ON idf.industrial_management_id = man.industrial_management_id
  172. WHERE 1 = 1 `
  173. if condition != "" {
  174. sql += condition
  175. }
  176. sql += ` GROUP BY
  177. idf.industrial_management_id
  178. ORDER BY
  179. one_month_follow_num DESC
  180. LIMIT ?,?`
  181. _, err = orm.NewOrm().Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  182. return
  183. }
  184. // 列表
  185. func GetCygxIndustryFllowListByCon(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxIndustryFllow, err error) {
  186. o := orm.NewOrm()
  187. sql := `SELECT * FROM cygx_industry_fllow as art WHERE 1= 1 `
  188. if condition != "" {
  189. sql += condition
  190. }
  191. //sql += ` LIMIT ?,? `
  192. _, err = o.Raw(sql, pars).QueryRows(&items)
  193. return
  194. }