Browse Source

新增流量历史接口

rdluck 4 years ago
parent
commit
525593a356
2 changed files with 102 additions and 5 deletions
  1. 80 0
      controllers/user.go
  2. 22 5
      models/user.go

+ 80 - 0
controllers/user.go

@@ -433,3 +433,83 @@ func (this *UserController) InterviewApplyList() {
 	br.Success = true
 	br.Data = resp
 }
+
+// @Title 获取浏览历史列表
+// @Description 获取浏览历史列表
+// @Param   PageSize    query   int true       "PageSize"
+// @Param   CurrentIndex    query   int true       "CurrentIndex"
+// @Success 200 {object} models.ArticleBrowseHistoryListResp
+// @router /browse/history/list [get]
+func (this *UserController) BrowseHistoryList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	userId := this.User.UserId
+	var pageSize, currentIndex, startSize int
+	pageSize, _ = this.GetInt("PageSize")
+	currentIndex, _ = this.GetInt("CurrentIndex")
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+
+	endDate:=time.Now().AddDate(0,-1,0).Format(utils.FormatDate)
+	total, err := models.GetArticleUserBrowseHistoryCount(userId,endDate)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	list, err := models.GetArticleUserBrowseHistoryList(startSize, pageSize, userId,endDate)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	var articleIds []string
+	for _, v := range list {
+		articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
+	}
+	articleIdStr := strings.Join(articleIds, ",")
+	articleMap := make(map[int]*models.ArticleDetail)
+	if articleIdStr != "" {
+		articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
+		if err != nil {
+			br.Msg = "获取数据失败"
+			br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
+			return
+		}
+		for _, v := range articleList {
+			if _, ok := articleMap[v.ArticleId]; !ok {
+				articleMap[v.ArticleId] = v
+			}
+		}
+	}
+	lenList := len(list)
+	for i := 0; i < lenList; i++ {
+		item := list[i]
+		article := articleMap[item.ArticleId]
+		list[i].Title = article.Title
+		list[i].TitleEn = article.TitleEn
+		list[i].UpdateFrequency = article.UpdateFrequency
+		list[i].CreateDate = article.CreateDate
+		list[i].PublishDate = article.PublishDate
+		list[i].Body, _ = services.GetReportContentTextSub(article.Body)
+		list[i].Abstract = article.Abstract
+		list[i].CategoryName = article.CategoryName
+		list[i].SubCategoryName = article.SubCategoryName
+	}
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp := new(models.ArticleBrowseHistoryListResp)
+	resp.List = list
+	resp.Paging = page
+	br.Msg = "获取成功!"
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}

+ 22 - 5
models/user.go

@@ -147,7 +147,7 @@ type CheckStatusResp struct {
 
 func GetArticleUserCollectCount(userId int) (count int, err error) {
 	sql := `SELECT COUNT(1) AS count FROM cygx_article_collect AS a WHERE a.user_id=? `
-	err = orm.NewOrm().Raw(sql,userId).QueryRow(&count)
+	err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
 	return
 }
 
@@ -164,11 +164,9 @@ type ArticleCollectListResp struct {
 	Paging *paging.PagingItem
 }
 
-
-
 func GetArticleUserInterviewApplyCount(userId int) (count int, err error) {
 	sql := `SELECT COUNT(1) AS count FROM cygx_interview_apply AS a WHERE a.user_id=? `
-	err = orm.NewOrm().Raw(sql,userId).QueryRow(&count)
+	err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
 	return
 }
 
@@ -183,4 +181,23 @@ func GetArticleUserInterviewApplyList(startSize, pageSize, userId int) (items []
 type ArticleInterviewApplyListResp struct {
 	List   []*ArticleInterviewApplyList
 	Paging *paging.PagingItem
-}
+}
+
+func GetArticleUserBrowseHistoryCount(userId int, endDate string) (count int, err error) {
+	sql := `SELECT COUNT(1) AS count FROM cygx_article_view_record AS a WHERE a.user_id=? AND a.create_time>=? `
+	err = orm.NewOrm().Raw(sql, userId, endDate).QueryRow(&count)
+	return
+}
+
+func GetArticleUserBrowseHistoryList(startSize, pageSize, userId int, endDate string) (items []*ArticleInterviewApplyList, err error) {
+	sql := `SELECT a.* FROM cygx_article_view_record AS a
+			WHERE a.user_id=? AND a.create_time>=? 
+           ORDER BY a.create_time DESC LIMIT ?,? `
+	_, err = orm.NewOrm().Raw(sql, userId, endDate, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+type ArticleBrowseHistoryListResp struct {
+	List   []*ArticleInterviewApplyList
+	Paging *paging.PagingItem
+}