industry_fllow.go 8.2 KB

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