123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- package yb
- import (
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hz_crm_api/controllers"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/yb"
- "hongze/hz_crm_api/models/yb/response"
- "hongze/hz_crm_api/utils"
- )
- type ProductCensusController struct {
- controllers.BaseAuthController
- }
- // UserVisitCount
- // @Title 用户阅读统计
- // @Description 用户阅读统计
- // @Param UserId query int true "用户ID"
- // @Param ClickSort query int false "点击量排序:1-升序 2-降序"
- // @Param PageSize query int false "页码"
- // @param CurrentIndex query int false "每页数据量"
- // @Success 200 {object} response.ProductCensusUserVisitCountResp
- // @router /product_census/user/visit_count [get]
- func (this *ProductCensusController) UserVisitCount() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser is Empty"
- br.Ret = 408
- return
- }
- userId, _ := this.GetInt("UserId")
- if userId <= 0 {
- br.Msg = "参数有误"
- return
- }
- clickSort, _ := this.GetInt("ClickSort")
- orderRule := ``
- if clickSort == 1 {
- orderRule = `visit_count ASC`
- }
- if clickSort == 2 {
- orderRule = `visit_count DESC`
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- total, list, e := yb.GetProductVisitCountByUserId(userId, startSize, pageSize, orderRule)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分产品阅读统计详情失败, Err: " + e.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := response.ProductCensusUserVisitCountResp{
- List: list,
- Paging: page,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- // UserVisitCountDetail
- // @Title 用户阅读统计详情
- // @Description 用户阅读统计详情
- // @Param UserId query int true "用户ID"
- // @Param ProductType query int true "产品类型:1-语音播报 2-视频社区 3-问答社区"
- // @Param ProductId query int false "产品ID:仅语音播报传该参数"
- // @Param ClickSort query int false "点击量排序:1-升序 2-降序"
- // @Param PageSize query int false "页码"
- // @param CurrentIndex query int false "每页数据量"
- // @Success 200 {object} ybResp.CommunityQuestionUserVisitCountResp
- // @router /product_census/user/visit_count_detail [get]
- func (this *ProductCensusController) UserVisitCountDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser is Empty"
- br.Ret = 408
- return
- }
- userId, _ := this.GetInt("UserId")
- if userId <= 0 {
- br.Msg = "参数有误"
- return
- }
- productType, _ := this.GetInt("ProductType")
- if productType <= 0 {
- br.Msg = "参数有误"
- return
- }
- productId, _ := this.GetInt("ProductId")
- if productType == 1 && productId <= 0 {
- br.Msg = "参数有误"
- return
- }
- clickSort, _ := this.GetInt("ClickSort")
- orderRule := ``
- if clickSort == 1 {
- orderRule = `visit_count ASC`
- }
- if clickSort == 2 {
- orderRule = `visit_count DESC`
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- total := 0
- respList := make([]*response.ProductCensusUserVisitCountDetail, 0)
- // 语音播报
- if productType == 1 {
- t, list, e := yb.GetVoiceBroadcastVisitCountByUserId(userId, productId, startSize, pageSize, orderRule)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取语音播报用户点击量统计失败, Err: " + e.Error()
- return
- }
- total = t
- for _, v := range list {
- respList = append(respList, &response.ProductCensusUserVisitCountDetail{
- VisitCount: v.VisitCount,
- Title: v.BroadcastName,
- Source: v.NewSource,
- RecentTime: v.RecentTime,
- })
- }
- }
- // 视频社区
- if productType == 2 {
- t, list, e := yb.GetCommunityVideoVisitCountByUserId(userId, productId, startSize, pageSize, orderRule)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取视频社区用户点击量统计失败, Err: " + e.Error()
- return
- }
- total = t
- // 视频标题
- videoIds := make([]int, 0)
- for _, v := range list {
- videoIds = append(videoIds, v.CommunityVideoId)
- }
- idTitleMap := make(map[int]string, 0)
- if productId == 1 {
- videoList, tErr := yb.GetCommunityVideoListByIds(videoIds)
- if tErr != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取视频社区列表失败, Err: " + tErr.Error()
- return
- }
- for _, v := range videoList {
- idTitleMap[v.CommunityVideoId] = v.Title
- }
- } else {
- videoList, tErr := yb.GetRoadVideoListByIds(videoIds)
- if tErr != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取视频社区列表失败, Err: " + tErr.Error()
- return
- }
- for _, v := range videoList {
- idTitleMap[v.RoadVideoId] = v.Title
- }
- }
- for _, v := range list {
- respList = append(respList, &response.ProductCensusUserVisitCountDetail{
- VisitCount: v.VisitCount,
- Title: idTitleMap[v.CommunityVideoId],
- Source: v.NewSource,
- RecentTime: v.RecentTime,
- })
- }
- }
- // 问答社区
- if productType == 3 {
- t, list, e := yb.GetCommunityQuestionVisitCountByUserId(userId, startSize, pageSize, orderRule)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取问答社区用户点击量统计失败, Err: " + e.Error()
- return
- }
- total = t
- // 问题内容
- questionIds := make([]int, 0)
- for _, v := range list {
- questionIds = append(questionIds, v.CommunityQuestionId)
- }
- questionList, e := yb.GetQuestionListByIds(questionIds)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取问答列表失败, Err: " + e.Error()
- return
- }
- idTitleMap := make(map[int]string, 0)
- for _, v := range questionList {
- idTitleMap[v.CommunityQuestionId] = v.QuestionContent
- }
- for _, v := range list {
- respList = append(respList, &response.ProductCensusUserVisitCountDetail{
- VisitCount: v.VisitCount,
- Title: idTitleMap[v.CommunityQuestionId],
- Source: v.NewSource,
- RecentTime: v.RecentTime,
- })
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := response.ProductCensusUserVisitCountDetailResp{
- List: respList,
- Paging: page,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
|