industry_fllow.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. }
  22. type CygxIndustryFllowRep struct {
  23. IndustrialManagementId int `description:"产业D"`
  24. }
  25. type IndustryFllowArryReq struct {
  26. SourceId int `description:"资源ID"`
  27. Source string `description:"资源类型 报告 :article 、活动 :activity"`
  28. DoType string `description:"操作方式 关注 :add 、取消关注 :cancel"`
  29. }
  30. // 添加
  31. func AddCygxIndustryFllow(item *CygxIndustryFllow) (lastId int64, err error) {
  32. o := orm.NewOrm()
  33. lastId, err = o.Insert(item)
  34. return
  35. }
  36. // 批量添加
  37. func AddCygxIndustryFllowMulti(items []*CygxIndustryFllow) (err error) {
  38. o := orm.NewOrm()
  39. if len(items) > 0 {
  40. //批量添加新的关注记录
  41. _, err = o.InsertMulti(len(items), items)
  42. }
  43. return
  44. }
  45. type CygxIndustryFllowResp struct {
  46. Status int `description:"1:关注,2:取消关注"`
  47. GoFollow bool `description:"是否去关注"`
  48. }
  49. func RemoveCygxIndustryFllow(userId, industrialManagementId int) (err error) {
  50. o := orm.NewOrm()
  51. sql := `DELETE FROM cygx_industry_fllow WHERE user_id=? AND industrial_management_id=? `
  52. _, err = o.Raw(sql, userId, industrialManagementId).Exec()
  53. return
  54. }
  55. // RemoveCygxIndustryFllowArry 多个产业同时取消关注
  56. func RemoveCygxIndustryFllowArry(userId int, condition string, pars []interface{}) (err error) {
  57. o := orm.NewOrm()
  58. if condition == "" {
  59. return
  60. }
  61. sql := `DELETE FROM cygx_industry_fllow WHERE user_id=? ` + condition
  62. _, err = o.Raw(sql, userId, pars).Exec()
  63. return
  64. }
  65. // 获取数量
  66. func GetCountCygxIndustryFllow(userId, industrialManagementId int, condition string) (count int, err error) {
  67. sql := `SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE user_id=? AND industrial_management_id=? ` + condition
  68. err = orm.NewOrm().Raw(sql, userId, industrialManagementId).QueryRow(&count)
  69. return
  70. }
  71. // 获取数量
  72. func GetCountCygxIndustryFllowByUid(userId int) (count int, err error) {
  73. sql := `SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE user_id=? `
  74. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  75. return
  76. }
  77. // 获取列表信息根据手机号分组
  78. func GetCygxIndustryFllowList(condition string) (items []*CygxIndustryFllow, err error) {
  79. o := orm.NewOrm()
  80. sql := `SELECT * FROM cygx_industry_fllow WHERE 1 =1 ` + condition + ` GROUP BY user_id `
  81. _, err = o.Raw(sql).QueryRows(&items)
  82. return
  83. }
  84. // 获取列表信息根据手机号分组
  85. func GetCygxIndustryFllowListByUserId(condition string) (items []*CygxIndustryFllow, err error) {
  86. o := orm.NewOrm()
  87. sql := `SELECT * FROM cygx_industry_fllow WHERE 1 =1 ` + condition
  88. _, err = o.Raw(sql).QueryRows(&items)
  89. return
  90. }
  91. // 修改用户关注的相关信息
  92. func UpdateCygxIndustryFllow(wxUser *WxUserItem) (err error) {
  93. o := orm.NewOrm()
  94. var sql string
  95. if wxUser.Mobile != "" {
  96. sql = `UPDATE cygx_industry_fllow SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
  97. _, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
  98. } else if wxUser.Email != "" {
  99. sql = `UPDATE cygx_industry_fllow SET mobile=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
  100. _, err = o.Raw(sql, wxUser.Mobile, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Email).Exec()
  101. }
  102. return
  103. }
  104. // 获取用户关注的产业列表
  105. func GetUserFllowIndustrialList(userId int) (items []*CygxIndustryFllow, err error) {
  106. o := orm.NewOrm()
  107. sql := `SELECT
  108. f.user_id,
  109. m.industry_name,
  110. m.industrial_management_id
  111. FROM
  112. cygx_industry_fllow AS f
  113. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id
  114. WHERE
  115. 1 = 1
  116. AND f.user_id = ? `
  117. _, err = o.Raw(sql, userId).QueryRows(&items)
  118. return
  119. }
  120. type CygxIndustryFllowCountRep struct {
  121. IndustrialManagementId int `description:"产业D"`
  122. Num int `description:"数量"`
  123. }
  124. // 获取产业被关注的数量
  125. func GetUserFllowIndustrialCountList() (items []*CygxIndustryFllowCountRep, err error) {
  126. o := orm.NewOrm()
  127. sql := `SELECT
  128. COUNT( 1 ) AS num,
  129. f.industrial_management_id
  130. FROM
  131. cygx_industry_fllow AS f
  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. man.*
  170. FROM
  171. cygx_industrial_management AS man
  172. WHERE 1 = 1 `
  173. if condition != "" {
  174. sql += condition
  175. }
  176. sql += ` ORDER BY
  177. one_month_follow_num DESC , man.industrial_management_id DESC
  178. LIMIT ?,?`
  179. _, err = orm.NewOrm().Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  180. return
  181. }
  182. // 列表
  183. func GetCygxIndustryFllowListByCon(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxIndustryFllow, err error) {
  184. o := orm.NewOrm()
  185. sql := `SELECT * FROM cygx_industry_fllow as art WHERE 1= 1 `
  186. if condition != "" {
  187. sql += condition
  188. }
  189. //sql += ` LIMIT ?,? `
  190. _, err = o.Raw(sql, pars).QueryRows(&items)
  191. return
  192. }
  193. type CygxIndustryFllowNumResp struct {
  194. IndustrialManagementId int `description:"产业D"`
  195. Total int `description:"关注数量"`
  196. }
  197. // 获取用户关注的产业列表
  198. func GetIndustrialManagementOneMonthFollowNum() (items []*CygxIndustryFllowNumResp, err error) {
  199. o := orm.NewOrm()
  200. sql := `SELECT
  201. COUNT( 1 ) AS total,
  202. industrial_management_id
  203. FROM
  204. cygx_industry_fllow AS idf
  205. WHERE
  206. 1 = 1
  207. AND create_time > '%s'
  208. AND create_time < '%s'
  209. AND source != 3
  210. GROUP BY
  211. industrial_management_id `
  212. sql = fmt.Sprintf(sql, time.Now().AddDate(0, -1, 0).Format(utils.FormatDate), time.Now().Format(utils.FormatDate))
  213. _, err = o.Raw(sql).QueryRows(&items)
  214. return
  215. }