industry_fllow.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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查研观向小助手"`
  19. FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
  20. FollowTypeOrder int `description:"排序方式,重点关注在最前面,不感兴趣在最后面。1,重点关注,-1不感兴趣,0默认接受推送"`
  21. }
  22. type CygxIndustryFllowRep struct {
  23. IndustrialManagementId int `description:"产业D"`
  24. FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
  25. }
  26. type CygxCategoryFllowRep struct {
  27. CategoryId int `description:"分类ID"`
  28. FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
  29. }
  30. // 根据手机号获取用户关注的产业
  31. func GetCygxIndustryFllowList(mobile string) (items []*CygxIndustryFllow, err error) {
  32. o := orm.NewOrm()
  33. sql := `SELECT * FROM cygx_industry_fllow WHERE mobile = ?`
  34. _, err = o.Raw(sql, mobile).QueryRows(&items)
  35. return
  36. }
  37. type CygxIndustryFllowResp struct {
  38. Status int `description:"1:关注,2:取消关注"`
  39. }
  40. // 获取数量
  41. func GetCountCygxIndustryFllowByUid(userId int) (count int, err error) {
  42. sql := `SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE user_id=? `
  43. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  44. return
  45. }
  46. // 添加
  47. func AddCygxIndustryFllow(item *CygxIndustryFllow) (lastId int64, err error) {
  48. o, err := orm.NewOrm().Begin()
  49. if err != nil {
  50. return
  51. }
  52. defer func() {
  53. if err == nil {
  54. o.Commit()
  55. } else {
  56. o.Rollback()
  57. }
  58. }()
  59. sql := `DELETE FROM cygx_industry_fllow WHERE user_id=? AND industrial_management_id=? `
  60. _, err = o.Raw(sql, item.UserId, item.IndustrialManagementId).Exec()
  61. if err != nil {
  62. return
  63. }
  64. lastId, err = o.Insert(item)
  65. return
  66. }
  67. // 删除
  68. func RemoveCygxIndustryFllow(userId, industrialManagementId int) (err error) {
  69. o := orm.NewOrm()
  70. sql := `DELETE FROM cygx_industry_fllow WHERE user_id=? AND industrial_management_id=? `
  71. _, err = o.Raw(sql, userId, industrialManagementId).Exec()
  72. return
  73. }
  74. // 获取某个用户关注某个行业下的产业数量
  75. func GetCountCygxIndustryFllowByUidAndChartPermissionId(userId, ChartPermissionId int) (count int, err error) {
  76. sql := `SELECT
  77. COUNT( 1 ) AS count
  78. FROM
  79. cygx_industry_fllow AS f
  80. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id
  81. WHERE
  82. user_id = ?
  83. AND m.chart_permission_id = ? `
  84. err = orm.NewOrm().Raw(sql, userId, ChartPermissionId).QueryRow(&count)
  85. return
  86. }
  87. // 获取用户关注的产业列表
  88. func GetUserFllowIndustrialList(userId int) (items []*CygxIndustryFllow, err error) {
  89. o := orm.NewOrm()
  90. sql := `SELECT
  91. f.user_id,
  92. f.follow_type,
  93. m.industry_name,
  94. m.industrial_management_id
  95. FROM
  96. cygx_industry_fllow AS f
  97. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id
  98. WHERE
  99. 1 = 1
  100. AND f.user_id = ? `
  101. _, err = o.Raw(sql, userId).QueryRows(&items)
  102. return
  103. }
  104. // UpdateIndustrialManagementTimeLineData 更新时间线关联对应最新文章的数据信息
  105. func UpdateIndustrialManagementTimeLineData(industrialManagementId int, timeLineData string) (err error) {
  106. o := orm.NewOrm()
  107. sql := `UPDATE cygx_industrial_management SET time_line_data = ? WHERE industrial_management_id = ? `
  108. _, err = o.Raw(sql, timeLineData, industrialManagementId).Exec()
  109. return
  110. }