Browse Source

Merge branch 'cygx_9.5' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai 2 năm trước cách đây
mục cha
commit
9eee746436
2 tập tin đã thay đổi với 59 bổ sung8 xóa
  1. 31 1
      controllers/research.go
  2. 28 7
      models/report.go

+ 31 - 1
controllers/research.go

@@ -238,6 +238,9 @@ func (this *ResearchController) HotList() {
 // @Title KOL榜列表
 // @Description KOL榜列表接口
 // @Param   ChartPermissionId   query   int  true       "分类ID"
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   ThemeType   query   int  true       "主题类型,1关注度、2更新时间 "
 // @Success 200 {object} models.DepartmentListResp
 // @router /kolList [get]
 func (this *ResearchController) KolList() {
@@ -257,8 +260,33 @@ func (this *ResearchController) KolList() {
 	//	br.Msg = "请输入分类ID"
 	//	return
 	//}
+	themeType, _ := this.GetInt("ThemeType")
+	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)
 
-	list, err := models.GetDepartmentList(user.UserId)
+	total, err := models.GetDepartmentlistCount("")
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+
+	var condition string
+	if themeType != 2 {
+		condition = `ORDER BY fllow_num DESC `
+	} else {
+		condition = `ORDER BY sum_num DESC `
+	}
+
+	list, err := models.GetDepartmentList(condition, user.UserId, startSize, pageSize)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
@@ -285,6 +313,8 @@ func (this *ResearchController) KolList() {
 		}
 	}
 	resp := new(models.DepartmentListResp)
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp.Paging = page
 	resp.List = list
 	br.Ret = 200
 	br.Success = true

+ 28 - 7
models/report.go

@@ -578,7 +578,8 @@ type DepartmentResp struct {
 }
 
 type DepartmentListResp struct {
-	List []*DepartmentResp
+	Paging *paging.PagingItem `description:"分页数据"`
+	List   []*DepartmentResp
 }
 type IndustrialDepartmentListResp struct {
 	IndustrialManagementId int    `description:"产业Id"`
@@ -587,7 +588,7 @@ type IndustrialDepartmentListResp struct {
 }
 
 // 作者列表
-func GetDepartmentList(userId int) (items []*DepartmentResp, err error) {
+func GetDepartmentList(condition string, userId, startSize, pageSize int) (items []*DepartmentResp, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
 			d.nick_name,
@@ -603,11 +604,31 @@ func GetDepartmentList(userId int) (items []*DepartmentResp, err error) {
 			AND a.article_type_id > 0 
 			AND publish_status = 1 
 		GROUP BY
-				d.department_id
-		ORDER BY
-			sum_num DESC
-			LIMIT 15`
-	_, err = o.Raw(sql, userId).QueryRows(&items)
+				d.department_id ` + condition + ` LIMIT ?,?`
+	_, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+// 获取数量
+func GetDepartmentlistCount(condition string) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	count(*) AS count 
+FROM
+	(
+	SELECT
+		COUNT( 1 ) AS count 
+	FROM
+		cygx_article_department AS d
+		INNER JOIN cygx_article AS a ON d.department_id = a.department_id 
+	WHERE
+		1 = 1 
+		AND a.article_type_id > 0 
+		AND publish_status = 1 
+	GROUP BY
+	d.department_id 
+	) c `
+	err = o.Raw(sql).QueryRow(&count)
 	return
 }