ソースを参照

产业下方对应的文章分类标红

xingzai 3 年 前
コミット
2eb05af10a

+ 104 - 0
controllers/report.go

@@ -4,7 +4,9 @@ import (
 	"encoding/json"
 	"fmt"
 	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
+	"rdluck_tools/paging"
 	"strconv"
 	"strings"
 	"time"
@@ -175,6 +177,13 @@ func (this *ReportController) ArticleCategoryList() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	uid := user.UserId
 	industrialManagementId, _ := this.GetInt("IndustrialManagementId")
 	if industrialManagementId < 1 {
 		br.Msg = "请输入分类ID"
@@ -186,6 +195,18 @@ func (this *ReportController) ArticleCategoryList() {
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
 		return
 	}
+
+	for k, v := range list {
+		recordCount, err := models.IndustrialUserRecordArticleCount(uid, industrialManagementId, v.CategoryId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+			return
+		}
+		if recordCount == 0 {
+			list[k].IsRed = true
+		}
+	}
 	detail, err := models.GetIndustrialManagementDetail(industrialManagementId)
 	if err != nil {
 		br.Msg = "获取信息失败"
@@ -196,6 +217,89 @@ func (this *ReportController) ArticleCategoryList() {
 	resp.List = list
 	resp.LayoutTime = utils.TimeRemoveHms(detail.LayoutTime)
 	resp.IndustryName = detail.IndustryName
+	resp.IndustrialManagementId = industrialManagementId
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @Title 产业文章列表接口
+// @Description 获取产业文章列表接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   CategoryId   query   int  true       "分类ID"
+// @Param   IndustrialManagementId   query   int  true       "产业ID"
+// @Success 200 {object} models.TacticsListResp
+// @router /industry/ArticleList [get]
+func (this *ReportController) List() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	uid := user.UserId
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	categoryId, _ := this.GetInt("CategoryId")
+	industrialManagementId, _ := this.GetInt("IndustrialManagementId")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+	var pars []interface{}
+	var total int
+	resp := new(models.TacticsListResp)
+	page := paging.GetPaging(currentIndex, pageSize, total)
+
+	if categoryId < 1 {
+		br.Msg = "请输入分类ID"
+		return
+	}
+	if industrialManagementId < 1 {
+		br.Msg = "请输入产业ID"
+		return
+	}
+
+	total, err := models.GetReportIndustrialCount(categoryId, industrialManagementId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.Msg = "获取帖子总数失败,Err:" + err.Error()
+		return
+	}
+	page = paging.GetPaging(currentIndex, pageSize, total)
+	list, err := models.GetReportIndustrialList(pars, categoryId, industrialManagementId, uid, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.Msg = "获取帖子数据失败,Err:" + err.Error()
+		return
+	}
+	lenList := len(list)
+	for i := 0; i < lenList; i++ {
+		item := list[i]
+		list[i].Body, _ = services.GetReportContentTextSub(item.Body)
+		//list[i].Abstract = html.UnescapeString(item.Abstract)
+		list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
+	}
+
+	for k, v := range list {
+		if v.Readnum == 0 {
+			list[k].IsRed = true
+		}
+	}
+	resp.List = list
+	resp.Paging = page
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 2 - 2
controllers/tactics.go

@@ -21,8 +21,8 @@ type TacticsCommonController struct {
 	BaseCommonController
 }
 
-// @Title 策略、行业、产业列表接口
-// @Description 获取策略、行业、产业通用列表接口
+// @Title 策略、行业列表接口
+// @Description 获取策略、行业 通用列表接口
 // @Param   PageSize   query   int  true       "每页数据条数"
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Param   CategoryId   query   int  true       "分类ID"

+ 1 - 0
models/industrial_management.go

@@ -91,6 +91,7 @@ func GetIndustrialManagementDetail(industrialManagementId int) (items *Industria
 	return
 }
 
+//获取该产业下最新的文章详情
 func GetIndustrialNewArticleDetail(industrialManagementId int) (item *ArticleDetail, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT

+ 65 - 0
models/report.go

@@ -1,5 +1,11 @@
 package models
 
+import (
+	"rdluck_tools/orm"
+	"strconv"
+	//"rdluck_tools/paging"
+)
+
 type IndustrialManagementList struct {
 	List []*IndustrialManagement
 }
@@ -28,3 +34,62 @@ type IndustrialSubject struct {
 	IndustrialManagementId int    `description:"产业id"`
 	SubjectName            string `description:"标的名称"`
 }
+
+//获取产业报告数量
+func GetReportIndustrialCount(categoryId, industrialManagementId int) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) count 
+FROM
+	cygx_article AS a 
+	INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
+WHERE
+	a.publish_status = 1 
+	AND category_id  = ?
+	AND man_g.industrial_management_id = ?`
+	err = o.Raw(sql, categoryId, industrialManagementId).QueryRow(&count)
+	return
+}
+
+//获取产业报告列表
+func GetReportIndustrialList(pars []interface{}, categoryId, industrialManagementId, userId, startSize, pageSize int) (items []*ReportArticle, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *,( SELECT COUNT( 1 ) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.article_id = a.article_id ) AS readnum 
+FROM
+	cygx_article AS a 
+	INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
+WHERE
+	a.publish_status = 1 
+	AND category_id  = ?
+	AND man_g.industrial_management_id = ?`
+	sql += ` ORDER BY publish_date DESC LIMIT ?,? `
+	_, err = o.Raw(sql, pars, categoryId, industrialManagementId, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+//产业下所关联的文章分类列表
+func IndustrialToArticleCategory(industrialManagementId int) (items []*IndustrialToArticleCategoryRep, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT map.match_type_name,map.category_id
+    FROM cygx_report_mapping AS map
+	INNER JOIN cygx_article AS art ON art.category_id = map.category_id
+	INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
+	WHERE map.report_type = 2 
+	AND man_g.industrial_management_id =?
+	GROUP BY map.match_type_name`
+	_, err = o.Raw(sql, industrialManagementId).QueryRows(&items)
+	return
+}
+
+//判断用户是否阅读该产业下,某一分类的文章
+func IndustrialUserRecordArticleCount(userId, industrialManagementId, categoryId int) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	COUNT(1) count
+FROM
+	cygx_article_history_record 
+WHERE
+	article_id = ( SELECT article_id FROM cygx_article WHERE article_id IN (SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id = ? ) AND category_id = ? ORDER BY publish_date DESC LIMIT 0, 1 ) 
+	AND user_id = ? `
+	err = o.Raw(sql, industrialManagementId, categoryId, userId).QueryRow(&count)
+	return
+}

+ 7 - 18
models/report_mapping.go

@@ -1,6 +1,8 @@
 package models
 
-import "rdluck_tools/orm"
+import (
+	"rdluck_tools/orm"
+)
 
 type ReportMapping struct {
 	CategoryId      int    `description:"分类ID"`
@@ -89,21 +91,8 @@ type IndustrialToArticleCategoryRep struct {
 }
 
 type IndustrialToArticleCategoryListRep struct {
-	LayoutTime   string `description:"布局时间"`
-	IndustryName string `description:"产业名称"`
-	List         []*IndustrialToArticleCategoryRep
-}
-
-//产业下所关联的文章分类列表
-func IndustrialToArticleCategory(industrialManagementId int) (items []*IndustrialToArticleCategoryRep, err error) {
-	o := orm.NewOrm()
-	sql := `SELECT map.match_type_name,map.category_id
-    FROM cygx_report_mapping AS map
-	INNER JOIN cygx_article AS art ON art.category_id = map.category_id
-	INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
-	WHERE map.report_type = 2 
-	AND man_g.industrial_management_id =?
-	GROUP BY map.match_type_name`
-	_, err = o.Raw(sql, industrialManagementId).QueryRows(&items)
-	return
+	LayoutTime             string `description:"布局时间"`
+	IndustryName           string `description:"产业名称"`
+	IndustrialManagementId int    `description:"产业D"`
+	List                   []*IndustrialToArticleCategoryRep
 }

+ 2 - 0
models/tactics.go

@@ -1,6 +1,7 @@
 package models
 
 import (
+	"fmt"
 	"rdluck_tools/orm"
 	"rdluck_tools/paging"
 	"strconv"
@@ -125,6 +126,7 @@ func GetReportTacticsList(condition string, pars []interface{}, userId, startSiz
 		sql += condition
 	}
 	sql += ` ORDER BY publish_date DESC LIMIT ?,? `
+	fmt.Println(sql)
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }