Browse Source

近期更新主题添加分页参数

xingzai 2 years ago
parent
commit
caa2cc1df0
2 changed files with 49 additions and 10 deletions
  1. 28 6
      controllers/research.go
  2. 21 4
      models/report.go

+ 28 - 6
controllers/research.go

@@ -1,7 +1,9 @@
 package controllers
 
 import (
+	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
 	"strconv"
 )
 
@@ -46,8 +48,8 @@ func (this *ResearchController) NewList() {
 	}
 	mapHot := make(map[string]int)
 
-	condition := ` ORDER BY sum_num DESC LIMIT 3 `
-	listHot, err := models.GetThemeHeatList(categoryinfo.PermissionName, user.UserId, condition)
+	condition := ` ORDER BY sum_num DESC  `
+	listHot, err := models.GetThemeHeatList(categoryinfo.PermissionName, user.UserId, condition, 0, 3)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
@@ -122,6 +124,8 @@ func (this *ResearchController) CollectionList() {
 // @Description 主题热度/近期更新更多,列表接口
 // @Param   ChartPermissionId   query   int  true       "分类ID"
 // @Param   ThemeType   query   int  true       "主题类型,1主题热度、2近期更新 默认1"
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Success 200 {object} models.IndustrialManagementHotListResp
 // @router /hotList [get]
 func (this *ResearchController) HotList() {
@@ -142,10 +146,20 @@ func (this *ResearchController) HotList() {
 		br.Msg = "请输入分类ID"
 		return
 	}
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize15
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
 	var condition string
 	if themeType != 2 {
 		themeType = 1
-		condition = `ORDER BY sum_num DESC LIMIT 15`
+		condition = `ORDER BY sum_num DESC `
 	} else {
 		condition = `ORDER BY publish_date DESC `
 	}
@@ -155,7 +169,13 @@ func (this *ResearchController) HotList() {
 		br.ErrMsg = "获取信息失败,Err:" + err.Error()
 		return
 	}
-	list, err := models.GetThemeHeatList(categoryinfo.PermissionName, user.UserId, condition)
+	total, err := models.GetThemeHeatListCount(categoryinfo.PermissionName, "")
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	list, err := models.GetThemeHeatList(categoryinfo.PermissionName, user.UserId, condition, startSize, pageSize)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
@@ -180,8 +200,8 @@ func (this *ResearchController) HotList() {
 	}
 	mapHot := make(map[string]int)
 
-	condition = ` ORDER BY sum_num DESC LIMIT 3 `
-	listHot, err := models.GetThemeHeatList(categoryinfo.PermissionName, user.UserId, condition)
+	condition = ` ORDER BY sum_num DESC `
+	listHot, err := models.GetThemeHeatList(categoryinfo.PermissionName, user.UserId, condition, 0, 3)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
@@ -206,7 +226,9 @@ func (this *ResearchController) HotList() {
 			list[k].IsHot = true
 		}
 	}
+	page := paging.GetPaging(currentIndex, pageSize, total)
 	resp := new(models.IndustrialManagementHotListResp)
+	resp.Paging = page
 	resp.List = list
 	br.Ret = 200
 	br.Success = true

+ 21 - 4
models/report.go

@@ -373,11 +373,12 @@ type IndustrialManagementHotResp struct {
 }
 
 type IndustrialManagementHotListResp struct {
-	List []*IndustrialManagementHotResp
+	Paging *paging.PagingItem `description:"分页数据"`
+	List   []*IndustrialManagementHotResp
 }
 
 //产业列表
-func GetThemeHeatList(permissionName string, userId int, condition string) (items []*IndustrialManagementHotResp, err error) {
+func GetThemeHeatList(permissionName string, userId int, condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
 			m.industry_name,
@@ -395,8 +396,24 @@ func GetThemeHeatList(permissionName string, userId int, condition string) (item
 			1 = 1
 			AND a.category_name LIKE '%` + permissionName + `%' 
 			AND publish_status = 1 
-			GROUP BY m.industrial_management_id ` + condition
-	_, err = o.Raw(sql, userId).QueryRows(&items)
+			GROUP BY m.industrial_management_id ` + condition + ` LIMIT ?,?`
+	_, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+//获取数量
+func GetThemeHeatListCount(permissionName, condition string) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT   COUNT( DISTINCT m.industrial_management_id ) FROM
+			cygx_industrial_management AS m
+			LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
+			LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id 
+			LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
+		WHERE
+			1 = 1
+			AND a.category_name LIKE '%` + permissionName + `%' 
+			AND a.publish_status = 1  ` + condition
+	err = o.Raw(sql).QueryRow(&count)
 	return
 }