industry_fllow.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 wx_user AS u ON f.user_id = u.user_id
  112. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id
  113. WHERE
  114. 1 = 1
  115. AND f.user_id = ? `
  116. _, err = o.Raw(sql, userId).QueryRows(&items)
  117. return
  118. }
  119. type CygxIndustryFllowCountRep struct {
  120. IndustrialManagementId int `description:"产业D"`
  121. Num int `description:"数量"`
  122. }
  123. // 获取产业被关注的数量
  124. func GetUserFllowIndustrialCountList() (items []*CygxIndustryFllowCountRep, err error) {
  125. o := orm.NewOrm()
  126. sql := `SELECT
  127. COUNT( 1 ) AS num,
  128. f.industrial_management_id
  129. FROM
  130. cygx_industry_fllow AS f
  131. INNER JOIN wx_user AS u ON u.user_id = f.user_id
  132. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id
  133. WHERE
  134. 1 = 1
  135. GROUP BY
  136. f.industrial_management_id
  137. ORDER BY
  138. num DESC
  139. LIMIT 30 `
  140. _, err = o.Raw(sql).QueryRows(&items)
  141. return
  142. }
  143. // GetUserFllowIndustrialListByUserIdAndIndustrial 通过用户ID 跟产业ID获取用户关注的产业列表
  144. func GetUserFllowIndustrialListByUserIdAndIndustrial(userIds, industrials string) (items []*CygxIndustryFllow, err error) {
  145. o := orm.NewOrm()
  146. sql := `SELECT * FROM cygx_industry_fllow
  147. WHERE 1 = 1
  148. AND user_id IN ( ` + userIds + ` )
  149. AND industrial_management_id IN ( ` + industrials + `) `
  150. _, err = o.Raw(sql).QueryRows(&items)
  151. return
  152. }
  153. // 获取某个用户关注某个行业下的产业数量
  154. func GetCountCygxIndustryFllowByUidAndChartPermissionId(userId, ChartPermissionId int) (count int, err error) {
  155. sql := `SELECT
  156. COUNT( 1 ) AS count
  157. FROM
  158. cygx_industry_fllow AS f
  159. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id
  160. WHERE
  161. user_id = ?
  162. AND m.chart_permission_id = ? `
  163. err = orm.NewOrm().Raw(sql, userId, ChartPermissionId).QueryRow(&count)
  164. return
  165. }
  166. // GetTopIndustryFollowData 获取关注度最高的产业关注数据
  167. func GetTopIndustryFollowData(startSize, pageSize int, condition string, pars []interface{}) (list []*IndustrialManagement, err error) {
  168. sql := `SELECT
  169. COUNT(1) AS one_month_follow_num,
  170. man.*
  171. FROM
  172. cygx_industry_fllow AS idf
  173. JOIN cygx_industrial_management AS man ON idf.industrial_management_id = man.industrial_management_id
  174. WHERE 1 = 1 `
  175. if condition != "" {
  176. sql += condition
  177. }
  178. sql += ` GROUP BY
  179. idf.industrial_management_id
  180. ORDER BY
  181. one_month_follow_num DESC
  182. LIMIT ?,?`
  183. _, err = orm.NewOrm().Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  184. return
  185. }
  186. // 列表
  187. func GetCygxIndustryFllowListByCon(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxIndustryFllow, err error) {
  188. o := orm.NewOrm()
  189. sql := `SELECT * FROM cygx_industry_fllow as art WHERE 1= 1 `
  190. if condition != "" {
  191. sql += condition
  192. }
  193. //sql += ` LIMIT ?,? `
  194. _, err = o.Raw(sql, pars).QueryRows(&items)
  195. return
  196. }