user_interaction_num.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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 CygxUserInteractionNum struct {
  9. Id int `orm:"column(id);pk"`
  10. UserId int `description:"用户ID"`
  11. ArticleHistoryNum int `description:"文章浏览数量"`
  12. ArticleCountNum int `description:"文章收藏数量"`
  13. ChartCountNum int `description:"图表收藏"`
  14. IndustryFllowNum int `description:"产业关注数量"`
  15. DepartmentFollowNum int `description:"作者关注数量"`
  16. KeyWordNum int `description:"关键词搜索次数"`
  17. ActivityOnLineNum int `description:"线上活动报名次数"`
  18. ActivityOfficeNum int `description:"线下活动报名次数"`
  19. ActivityNum int `description:"活动报名次数"`
  20. TripNum int `description:"专项产业调研数量"`
  21. RoadshowVideoNum int `description:"产业视频播放量"`
  22. ActivityVideoNum int `description:"活动视频播放量"`
  23. ActivityVoiceNum int `description:"活动音频播放量"`
  24. RoadshowNum int `description:"路演播放总数量"`
  25. TagNum int `description:"标签点击次数"`
  26. CreateTime time.Time `description:"创建时间"`
  27. ModifyTime time.Time `description:"更新时间"`
  28. }
  29. // 添加
  30. func AddCygxUserInteractionNum(item *CygxUserInteractionNum) (lastId int64, err error) {
  31. o := orm.NewOrm()
  32. lastId, err = o.Insert(item)
  33. return
  34. }
  35. // 修改
  36. func UpdateCygxUserInteractionNum(item *CygxUserInteractionNum) (err error) {
  37. updateParams := make(map[string]interface{})
  38. updateParams["UserId"] = item.UserId
  39. updateParams["ArticleHistoryNum"] = item.ArticleHistoryNum
  40. updateParams["ArticleCountNum"] = item.ArticleCountNum
  41. updateParams["ChartCountNum"] = item.ChartCountNum
  42. updateParams["IndustryFllowNum"] = item.IndustryFllowNum
  43. updateParams["DepartmentFollowNum"] = item.DepartmentFollowNum
  44. updateParams["KeyWordNum"] = item.KeyWordNum
  45. updateParams["ActivityOnLineNum"] = item.ActivityOnLineNum
  46. updateParams["ActivityOfficeNum"] = item.ActivityOfficeNum
  47. updateParams["ActivityNum"] = item.ActivityNum
  48. updateParams["TripNum"] = item.TripNum
  49. updateParams["RoadshowVideoNum"] = item.RoadshowVideoNum
  50. updateParams["ActivityVideoNum"] = item.ActivityVideoNum
  51. updateParams["ActivityVoiceNum"] = item.ActivityVoiceNum
  52. updateParams["RoadshowNum"] = item.RoadshowNum
  53. updateParams["TagNum"] = item.TagNum
  54. updateParams["CreateTime"] = time.Now()
  55. updateParams["ModifyTime"] = time.Now()
  56. whereParam := map[string]interface{}{"user_id": item.UserId}
  57. err = UpdateByExpr(CygxUserInteractionNum{}, whereParam, updateParams)
  58. return
  59. }
  60. // 获取列表
  61. func GetCygxUserInteractionNumList() (items []*CygxUserInteractionNum, err error) {
  62. o := orm.NewOrm()
  63. sql := `SELECT * FROM cygx_user_interaction_num `
  64. _, err = o.Raw(sql).QueryRows(&items)
  65. return
  66. }
  67. // 批量添加用户互动信息
  68. func AddCygxUserInteractionNumList(items []*CygxUserInteractionNum) (lastId int64, err error) {
  69. o := orm.NewOrm()
  70. _, err = o.InsertMulti(1, items)
  71. return
  72. }
  73. // 联系人互动数量
  74. type CygxUserInteractionNumResp struct {
  75. UserId int `description:"用户ID"`
  76. CompanyId int `description:"公司ID"`
  77. InteractionNum int `description:"互动数量"`
  78. }
  79. // 用户阅读记录数量统计
  80. func GetCygxArticleHistoryRecordInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
  81. o := orm.NewOrm()
  82. var sql string
  83. sql += ` SELECT
  84. COUNT( 1 ) AS interaction_num,
  85. h.user_id,
  86. h.company_id
  87. FROM
  88. cygx_article_and_yanxuan_record AS h
  89. INNER JOIN cygx_article AS art ON art.article_id = h.source_id
  90. INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id WHERE 1=1 AND h.source = 'article' ` + condition + ` GROUP BY w.user_id `
  91. databaseName := utils.GetWeeklyDatabase()
  92. sql = fmt.Sprintf(sql, databaseName)
  93. _, err = o.Raw(sql).QueryRows(&items)
  94. return
  95. }
  96. // 用户收藏文章数量统计
  97. func GetCygxArticleCollectInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
  98. o := orm.NewOrm()
  99. var sql string
  100. sql += ` SELECT
  101. COUNT( 1 ) AS interaction_num,
  102. h.user_id,
  103. h.company_id
  104. FROM
  105. cygx_article_collect AS h
  106. INNER JOIN cygx_article AS art ON art.article_id = h.article_id
  107. INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id WHERE 1=1 ` + condition + ` GROUP BY w.user_id `
  108. databaseName := utils.GetWeeklyDatabase()
  109. sql = fmt.Sprintf(sql, databaseName)
  110. _, err = o.Raw(sql).QueryRows(&items)
  111. return
  112. }
  113. // 用户收藏图表数量统计
  114. func GetCygxChartCollectInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
  115. o := orm.NewOrm()
  116. var sql string
  117. sql += ` SELECT
  118. COUNT( 1 ) AS interaction_num,
  119. h.user_id,
  120. h.company_id
  121. FROM
  122. cygx_chart_collect AS h
  123. INNER JOIN cygx_chart_all AS art ON art.chart_id = h.chart_id
  124. INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id WHERE 1=1 ` + condition + ` GROUP BY w.user_id `
  125. databaseName := utils.GetWeeklyDatabase()
  126. sql = fmt.Sprintf(sql, databaseName)
  127. _, err = o.Raw(sql).QueryRows(&items)
  128. return
  129. }
  130. // 用户关注产业数量统计
  131. func GetCygxIndustryFllowInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
  132. o := orm.NewOrm()
  133. var sql string
  134. sql += ` SELECT
  135. COUNT( 1 ) AS interaction_num,
  136. h.user_id,
  137. h.company_id
  138. FROM
  139. cygx_industry_fllow AS h
  140. INNER JOIN cygx_industrial_management AS art ON art.industrial_management_id = h.industrial_management_id
  141. INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id WHERE 1=1 AND h.type = 1 AND h.source IN (0,1,2) ` + condition + ` GROUP BY w.user_id `
  142. databaseName := utils.GetWeeklyDatabase()
  143. sql = fmt.Sprintf(sql, databaseName)
  144. _, err = o.Raw(sql).QueryRows(&items)
  145. return
  146. }
  147. // 用户搜索关键词数量统计
  148. func GetCygxSearchKeyWordInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
  149. o := orm.NewOrm()
  150. var sql string
  151. sql += ` SELECT
  152. COUNT( 1 ) AS interaction_num,
  153. h.user_id,
  154. h.company_id
  155. FROM
  156. cygx_search_key_word AS h
  157. INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id WHERE 1=1 ` + condition + ` GROUP BY w.user_id `
  158. databaseName := utils.GetWeeklyDatabase()
  159. sql = fmt.Sprintf(sql, databaseName)
  160. _, err = o.Raw(sql).QueryRows(&items)
  161. return
  162. }
  163. // 用户活动报名参会数量统计
  164. func GetCygxActivitySignupInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
  165. o := orm.NewOrm()
  166. var sql string
  167. sql += ` SELECT
  168. COUNT( 1 ) AS interaction_num,
  169. h.user_id,
  170. h.company_id
  171. FROM
  172. cygx_activity_signup_detail AS h
  173. INNER JOIN cygx_activity AS art ON art.activity_id = h.activity_id
  174. INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id WHERE 1=1 ` + condition + ` GROUP BY w.user_id `
  175. databaseName := utils.GetWeeklyDatabase()
  176. sql = fmt.Sprintf(sql, databaseName)
  177. _, err = o.Raw(sql).QueryRows(&items)
  178. return
  179. }
  180. // 用户专项调研活动报名参会数量统计
  181. func GetCygxActivitySpecialSignupInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
  182. o := orm.NewOrm()
  183. var sql string
  184. sql += ` SELECT
  185. COUNT( 1 ) AS interaction_num,
  186. h.user_id,
  187. h.company_id
  188. FROM
  189. cygx_activity_special_meeting_detail AS h
  190. INNER JOIN cygx_activity_special AS art ON art.activity_id = h.activity_id
  191. INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id WHERE 1=1 ` + condition + ` GROUP BY w.user_id `
  192. databaseName := utils.GetWeeklyDatabase()
  193. sql = fmt.Sprintf(sql, databaseName)
  194. _, err = o.Raw(sql).QueryRows(&items)
  195. return
  196. }
  197. // 用户路演精华播放数量统计
  198. func GetCygxMicroRoadshowVideoHistoryInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
  199. o := orm.NewOrm()
  200. var sql string
  201. sql += ` SELECT
  202. COUNT( 1 ) AS interaction_num,
  203. h.user_id,
  204. h.company_id
  205. FROM
  206. cygx_micro_roadshow_video_history AS h
  207. INNER JOIN cygx_micro_roadshow_video AS art ON art.video_id = h.video_id
  208. INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id WHERE 1=1 ` + condition + ` GROUP BY w.user_id `
  209. databaseName := utils.GetWeeklyDatabase()
  210. sql = fmt.Sprintf(sql, databaseName)
  211. _, err = o.Raw(sql).QueryRows(&items)
  212. return
  213. }
  214. // 用户活动视频播放数量统计
  215. func GetCygxActivityVideoHistoryInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
  216. o := orm.NewOrm()
  217. var sql string
  218. sql += ` SELECT
  219. COUNT( 1 ) AS interaction_num,
  220. h.user_id,
  221. h.company_id
  222. FROM
  223. cygx_activity_video_history AS h
  224. INNER JOIN cygx_activity_video AS art ON art.activity_id = h.activity_id
  225. INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id WHERE 1=1 ` + condition + ` GROUP BY w.user_id `
  226. databaseName := utils.GetWeeklyDatabase()
  227. sql = fmt.Sprintf(sql, databaseName)
  228. _, err = o.Raw(sql).QueryRows(&items)
  229. return
  230. }
  231. // 用户活动音频播放数量统计
  232. func GetCygxActivityVoiceHistoryInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
  233. o := orm.NewOrm()
  234. var sql string
  235. sql += ` SELECT
  236. COUNT( 1 ) AS interaction_num,
  237. h.user_id,
  238. h.company_id
  239. FROM
  240. cygx_activity_voice_history AS h
  241. INNER JOIN cygx_activity_voice AS art ON art.activity_id = h.activity_id
  242. INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id WHERE 1=1 ` + condition + ` GROUP BY w.user_id `
  243. databaseName := utils.GetWeeklyDatabase()
  244. sql = fmt.Sprintf(sql, databaseName)
  245. _, err = o.Raw(sql).QueryRows(&items)
  246. return
  247. }
  248. // 用户首页标签点击量数量统计
  249. func GetCygxTagHistoryInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
  250. o := orm.NewOrm()
  251. var sql string
  252. sql += ` SELECT
  253. COUNT( 1 ) AS interaction_num,
  254. h.user_id,
  255. h.company_id
  256. FROM
  257. cygx_tag_history AS h
  258. INNER JOIN cygx_tag AS art ON art.tag_id = h.tag_id
  259. INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id WHERE 1=1 ` + condition + ` GROUP BY w.user_id `
  260. databaseName := utils.GetWeeklyDatabase()
  261. sql = fmt.Sprintf(sql, databaseName)
  262. _, err = o.Raw(sql).QueryRows(&items)
  263. return
  264. }
  265. // 用户关注研选作者数量统计
  266. func GetCygxArticleDepartmentFollowInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
  267. o := orm.NewOrm()
  268. var sql string
  269. sql += ` SELECT
  270. COUNT( 1 ) AS interaction_num,
  271. h.user_id,
  272. h.company_id
  273. FROM
  274. cygx_article_department_follow AS h
  275. INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id WHERE 1=1 ` + condition + ` GROUP BY w.user_id `
  276. databaseName := utils.GetWeeklyDatabase()
  277. sql = fmt.Sprintf(sql, databaseName)
  278. _, err = o.Raw(sql).QueryRows(&items)
  279. return
  280. }
  281. // 用户收藏研选专栏数量统计
  282. func GetCygxYanxuanSpecialCollectInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
  283. o := orm.NewOrm()
  284. var sql string
  285. sql += ` SELECT
  286. COUNT( 1 ) AS interaction_num,
  287. h.user_id,
  288. h.company_id
  289. FROM
  290. cygx_yanxuan_special_collect AS h
  291. INNER JOIN cygx_yanxuan_special AS art ON art.id = h.yanxuan_special_id
  292. INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id WHERE 1=1 ` + condition + ` GROUP BY w.user_id `
  293. databaseName := utils.GetWeeklyDatabase()
  294. sql = fmt.Sprintf(sql, databaseName)
  295. _, err = o.Raw(sql).QueryRows(&items)
  296. return
  297. }
  298. // 用户关注研选专栏作者数量统计
  299. func GetCygxYanxuanSpecialFollowInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
  300. o := orm.NewOrm()
  301. var sql string
  302. sql += ` SELECT
  303. COUNT( 1 ) AS interaction_num,
  304. h.user_id,
  305. h.company_id
  306. FROM
  307. cygx_yanxuan_special_follow AS h
  308. INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id WHERE 1=1 ` + condition + ` GROUP BY w.user_id `
  309. databaseName := utils.GetWeeklyDatabase()
  310. sql = fmt.Sprintf(sql, databaseName)
  311. _, err = o.Raw(sql).QueryRows(&items)
  312. return
  313. }
  314. // 用户研选专栏阅读数量数量统计
  315. func GetCygxYanxuanSpecialRecordInteractionNum(condition string) (items []*CygxUserInteractionNumResp, err error) {
  316. o := orm.NewOrm()
  317. var sql string
  318. sql += ` SELECT
  319. COUNT( 1 ) AS interaction_num,
  320. h.user_id,
  321. h.company_id
  322. FROM
  323. cygx_yanxuan_special_record AS h
  324. INNER JOIN cygx_yanxuan_special AS art ON art.id = h.yanxuan_special_id
  325. INNER JOIN %s.wx_user AS w ON w.user_id = h.user_id WHERE 1=1 ` + condition + ` GROUP BY w.user_id `
  326. databaseName := utils.GetWeeklyDatabase()
  327. sql = fmt.Sprintf(sql, databaseName)
  328. _, err = o.Raw(sql).QueryRows(&items)
  329. return
  330. }