product_census.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. package yb
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hz_crm_api/controllers"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/yb"
  7. "hongze/hz_crm_api/models/yb/response"
  8. "hongze/hz_crm_api/utils"
  9. )
  10. type ProductCensusController struct {
  11. controllers.BaseAuthController
  12. }
  13. // UserVisitCount
  14. // @Title 用户阅读统计
  15. // @Description 用户阅读统计
  16. // @Param UserId query int true "用户ID"
  17. // @Param ClickSort query int false "点击量排序:1-升序 2-降序"
  18. // @Param PageSize query int false "页码"
  19. // @param CurrentIndex query int false "每页数据量"
  20. // @Success 200 {object} response.ProductCensusUserVisitCountResp
  21. // @router /product_census/user/visit_count [get]
  22. func (this *ProductCensusController) UserVisitCount() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. sysUser := this.SysUser
  29. if sysUser == nil {
  30. br.Msg = "请登录"
  31. br.ErrMsg = "请登录,SysUser is Empty"
  32. br.Ret = 408
  33. return
  34. }
  35. userId, _ := this.GetInt("UserId")
  36. if userId <= 0 {
  37. br.Msg = "参数有误"
  38. return
  39. }
  40. clickSort, _ := this.GetInt("ClickSort")
  41. orderRule := ``
  42. if clickSort == 1 {
  43. orderRule = `visit_count ASC`
  44. }
  45. if clickSort == 2 {
  46. orderRule = `visit_count DESC`
  47. }
  48. pageSize, _ := this.GetInt("PageSize")
  49. currentIndex, _ := this.GetInt("CurrentIndex")
  50. var startSize int
  51. if pageSize <= 0 {
  52. pageSize = utils.PageSize20
  53. }
  54. if currentIndex <= 0 {
  55. currentIndex = 1
  56. }
  57. startSize = paging.StartIndex(currentIndex, pageSize)
  58. total, list, e := yb.GetProductVisitCountByUserId(userId, startSize, pageSize, orderRule)
  59. if e != nil {
  60. br.Msg = "获取失败"
  61. br.ErrMsg = "获取分产品阅读统计详情失败, Err: " + e.Error()
  62. return
  63. }
  64. page := paging.GetPaging(currentIndex, pageSize, total)
  65. resp := response.ProductCensusUserVisitCountResp{
  66. List: list,
  67. Paging: page,
  68. }
  69. br.Ret = 200
  70. br.Success = true
  71. br.Msg = "获取成功"
  72. br.Data = resp
  73. return
  74. }
  75. // UserVisitCountDetail
  76. // @Title 用户阅读统计详情
  77. // @Description 用户阅读统计详情
  78. // @Param UserId query int true "用户ID"
  79. // @Param ProductType query int true "产品类型:1-语音播报 2-视频社区 3-问答社区"
  80. // @Param ProductId query int false "产品ID:仅语音播报传该参数"
  81. // @Param ClickSort query int false "点击量排序:1-升序 2-降序"
  82. // @Param PageSize query int false "页码"
  83. // @param CurrentIndex query int false "每页数据量"
  84. // @Success 200 {object} ybResp.CommunityQuestionUserVisitCountResp
  85. // @router /product_census/user/visit_count_detail [get]
  86. func (this *ProductCensusController) UserVisitCountDetail() {
  87. br := new(models.BaseResponse).Init()
  88. defer func() {
  89. this.Data["json"] = br
  90. this.ServeJSON()
  91. }()
  92. sysUser := this.SysUser
  93. if sysUser == nil {
  94. br.Msg = "请登录"
  95. br.ErrMsg = "请登录,SysUser is Empty"
  96. br.Ret = 408
  97. return
  98. }
  99. userId, _ := this.GetInt("UserId")
  100. if userId <= 0 {
  101. br.Msg = "参数有误"
  102. return
  103. }
  104. productType, _ := this.GetInt("ProductType")
  105. if productType <= 0 {
  106. br.Msg = "参数有误"
  107. return
  108. }
  109. productId, _ := this.GetInt("ProductId")
  110. if productType == 1 && productId <= 0 {
  111. br.Msg = "参数有误"
  112. return
  113. }
  114. clickSort, _ := this.GetInt("ClickSort")
  115. orderRule := ``
  116. if clickSort == 1 {
  117. orderRule = `visit_count ASC`
  118. }
  119. if clickSort == 2 {
  120. orderRule = `visit_count DESC`
  121. }
  122. pageSize, _ := this.GetInt("PageSize")
  123. currentIndex, _ := this.GetInt("CurrentIndex")
  124. var startSize int
  125. if pageSize <= 0 {
  126. pageSize = utils.PageSize20
  127. }
  128. if currentIndex <= 0 {
  129. currentIndex = 1
  130. }
  131. startSize = paging.StartIndex(currentIndex, pageSize)
  132. total := 0
  133. respList := make([]*response.ProductCensusUserVisitCountDetail, 0)
  134. // 语音播报
  135. if productType == 1 {
  136. t, list, e := yb.GetVoiceBroadcastVisitCountByUserId(userId, productId, startSize, pageSize, orderRule)
  137. if e != nil {
  138. br.Msg = "获取失败"
  139. br.ErrMsg = "获取语音播报用户点击量统计失败, Err: " + e.Error()
  140. return
  141. }
  142. total = t
  143. for _, v := range list {
  144. respList = append(respList, &response.ProductCensusUserVisitCountDetail{
  145. VisitCount: v.VisitCount,
  146. Title: v.BroadcastName,
  147. Source: v.NewSource,
  148. RecentTime: v.RecentTime,
  149. })
  150. }
  151. }
  152. // 视频社区
  153. if productType == 2 {
  154. t, list, e := yb.GetCommunityVideoVisitCountByUserId(userId, productId, startSize, pageSize, orderRule)
  155. if e != nil {
  156. br.Msg = "获取失败"
  157. br.ErrMsg = "获取视频社区用户点击量统计失败, Err: " + e.Error()
  158. return
  159. }
  160. total = t
  161. // 视频标题
  162. videoIds := make([]int, 0)
  163. for _, v := range list {
  164. videoIds = append(videoIds, v.CommunityVideoId)
  165. }
  166. idTitleMap := make(map[int]string, 0)
  167. if productId == 1 {
  168. videoList, tErr := yb.GetCommunityVideoListByIds(videoIds)
  169. if tErr != nil {
  170. br.Msg = "获取失败"
  171. br.ErrMsg = "获取视频社区列表失败, Err: " + tErr.Error()
  172. return
  173. }
  174. for _, v := range videoList {
  175. idTitleMap[v.CommunityVideoId] = v.Title
  176. }
  177. } else {
  178. videoList, tErr := yb.GetRoadVideoListByIds(videoIds)
  179. if tErr != nil {
  180. br.Msg = "获取失败"
  181. br.ErrMsg = "获取视频社区列表失败, Err: " + tErr.Error()
  182. return
  183. }
  184. for _, v := range videoList {
  185. idTitleMap[v.RoadVideoId] = v.Title
  186. }
  187. }
  188. for _, v := range list {
  189. respList = append(respList, &response.ProductCensusUserVisitCountDetail{
  190. VisitCount: v.VisitCount,
  191. Title: idTitleMap[v.CommunityVideoId],
  192. Source: v.NewSource,
  193. RecentTime: v.RecentTime,
  194. })
  195. }
  196. }
  197. // 问答社区
  198. if productType == 3 {
  199. t, list, e := yb.GetCommunityQuestionVisitCountByUserId(userId, startSize, pageSize, orderRule)
  200. if e != nil {
  201. br.Msg = "获取失败"
  202. br.ErrMsg = "获取问答社区用户点击量统计失败, Err: " + e.Error()
  203. return
  204. }
  205. total = t
  206. // 问题内容
  207. questionIds := make([]int, 0)
  208. for _, v := range list {
  209. questionIds = append(questionIds, v.CommunityQuestionId)
  210. }
  211. questionList, e := yb.GetQuestionListByIds(questionIds)
  212. if e != nil {
  213. br.Msg = "获取失败"
  214. br.ErrMsg = "获取问答列表失败, Err: " + e.Error()
  215. return
  216. }
  217. idTitleMap := make(map[int]string, 0)
  218. for _, v := range questionList {
  219. idTitleMap[v.CommunityQuestionId] = v.QuestionContent
  220. }
  221. for _, v := range list {
  222. respList = append(respList, &response.ProductCensusUserVisitCountDetail{
  223. VisitCount: v.VisitCount,
  224. Title: idTitleMap[v.CommunityQuestionId],
  225. Source: v.NewSource,
  226. RecentTime: v.RecentTime,
  227. })
  228. }
  229. }
  230. page := paging.GetPaging(currentIndex, pageSize, total)
  231. resp := response.ProductCensusUserVisitCountDetailResp{
  232. List: respList,
  233. Paging: page,
  234. }
  235. br.Ret = 200
  236. br.Success = true
  237. br.Msg = "获取成功"
  238. br.Data = resp
  239. return
  240. }