Browse Source

no message

xingzai 2 years ago
parent
commit
f52bc13850
4 changed files with 107 additions and 41 deletions
  1. 51 35
      controllers/research.go
  2. 22 1
      models/industrial_article_group_subject.go
  3. 1 1
      models/report.go
  4. 33 4
      services/yan_xuan.go

+ 51 - 35
controllers/research.go

@@ -2,6 +2,7 @@ package controllers
 
 import (
 	"encoding/json"
+	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/services"
@@ -191,7 +192,6 @@ func (this *ResearchController) HotList() {
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
 		return
 	}
-	condition = ` AND a.article_type_id > 0  `
 	listSubjcet, err := models.GetThemeHeatSubjectList(condition)
 	if err != nil {
 		br.Msg = "获取信息失败"
@@ -213,6 +213,7 @@ func (this *ResearchController) HotList() {
 			return
 		}
 	}
+	fmt.Println(mapNew)
 	for k, v := range list {
 		list[k].IsNew = mapNew[v.IndustrialManagementId]
 		list[k].IsHot = mapHot[v.IndustrialManagementId]
@@ -374,11 +375,22 @@ func (this *ResearchController) ThemeDetail() {
 		source = 1
 	}
 
+	articleTypeIds, err := services.GetYanXuanArticleTypeIds()
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
+		return
+	}
+	if articleTypeIds == "" {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "研选分类ID不能为空"
+		return
+	}
 	var condition string
 	if source == 1 {
-		condition = `  AND a.category_name LIKE '%研选%' `
+		condition = ` AND a.article_type_id IN (` + articleTypeIds + `)  `
 	} else {
-		condition = `  AND a.category_name  NOT LIKE '%研选%' `
+		condition = ` AND a.article_type_id  NOT IN (` + articleTypeIds + `)  `
 	}
 	resp := new(models.GetThemeDetailResp)
 	list, err := models.GetThemeDetail(user.UserId, industrialManagementId, condition)
@@ -388,16 +400,27 @@ func (this *ResearchController) ThemeDetail() {
 		return
 	}
 
+	listSub, err := models.GetcygxIndustrialSubject(industrialManagementId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
+		return
+	}
+	mapSubjectlist := make(map[string]string)
+	for _, v := range listSub {
+		mapSubjectlist[v.SubjectName] = v.SubjectName
+	}
+
 	var itemsNull []*models.GetThemeAericleListResp
 	subjectMap := make(map[string]string)
-	articleMap := make(map[int]int)
+	var articleIds []int
 	for _, v := range list {
 		resp.IndustryName = v.IndustryName
 		resp.IndustrialManagementId = v.IndustrialManagementId
 		itemSubJect := new(models.IndustrialSubject)
 		itemSubJect.SubjectName = v.SubjectName
 		itemSubJect.IndustrialSubjectId = v.IndustrialSubjectId
-		if subjectMap[v.SubjectName] == "" && v.SubjectName != "" {
+		if subjectMap[v.SubjectName] == "" && v.SubjectName != "" && mapSubjectlist[v.SubjectName] != "" {
 			resp.ListSubject = append(resp.ListSubject, itemSubJect)
 		}
 
@@ -417,40 +440,33 @@ func (this *ResearchController) ThemeDetail() {
 			item.Pv = v.Pv
 			item.CollectNum = v.CollectNum
 			itemsNull = append(itemsNull, item)
-
 		}
+		articleIds = append(articleIds, v.ArticleId)
 	}
 
-	for _, v := range resp.ListSubject {
-		subjetcGroup := new(models.GetThemeAericleListBuSubjectResp)
-		for _, v2 := range list {
-			if v2.IndustrialSubjectId == v.IndustrialSubjectId && articleMap[v2.ArticleId] == 0 {
-				item := new(models.GetThemeAericleListResp)
-				item.ArticleId = v2.ArticleId
-				item.Title = v2.Title
-				item.PublishDate = v2.PublishDate
-				item.SubjectName = v2.SubjectName
-				item.IndustrialSubjectId = v2.IndustrialSubjectId
-				for _, v3 := range list {
-					if v3.ArticleId == v2.ArticleId && v3.SubjectName != v2.SubjectName && v3.SubjectName != "" {
-						item.SubjectName += "/" + v3.SubjectName
-					}
-				}
-				item.DepartmentId = v2.DepartmentId
-				item.NickName = v2.NickName
-				item.Pv = v2.Pv
-				item.CollectNum = v2.CollectNum
-				item.MyCollectNum = v2.MyCollectNum
-				if v2.MyCollectNum > 0 {
-					item.IsCollect = true
-				}
-				resp.List = append(resp.List, item)
-				articleMap[v2.ArticleId] = v2.ArticleId
-				//subjetcGroup.List = append(subjetcGroup.List, item)
-			}
-			subjetcGroup.SubjectName = v.SubjectName
+	mapArticleSubjectName, err := services.GetArticleSubjectName(articleIds)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
+		return
+	}
+	for _, v2 := range list {
+		item := new(models.GetThemeAericleListResp)
+		item.ArticleId = v2.ArticleId
+		item.Title = v2.Title
+		item.PublishDate = v2.PublishDate
+		item.SubjectName = v2.SubjectName
+		item.IndustrialSubjectId = v2.IndustrialSubjectId
+		item.DepartmentId = v2.DepartmentId
+		item.NickName = v2.NickName
+		item.Pv = v2.Pv
+		item.CollectNum = v2.CollectNum
+		item.MyCollectNum = v2.MyCollectNum
+		if v2.MyCollectNum > 0 {
+			item.IsCollect = true
 		}
-
+		item.SubjectName = mapArticleSubjectName[v2.ArticleId]
+		resp.List = append(resp.List, item)
 	}
 	//当标的为空时进行合并
 	if len(itemsNull) > 0 {

+ 22 - 1
models/industrial_article_group_subject.go

@@ -13,7 +13,13 @@ type CygxIndustrialArticleGroupSubject struct {
 	CreateTime          time.Time `description:"创建时间"`
 }
 
-//列表
+type SubjectArticlGroupList struct {
+	SubjectName         string `description:"标的名称"`
+	ArticleId           int    `description:"cygx_article表的文章ID"`
+	IndustrialSubjectId int    `description:"cygx_industrial_subject表的文章ID"`
+}
+
+// 列表
 func GetSubjectArticleGroupManagementList(condition string, pars []interface{}) (items []*CygxIndustrialArticleGroupSubject, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
@@ -25,3 +31,18 @@ func GetSubjectArticleGroupManagementList(condition string, pars []interface{})
 	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
 }
+
+// 列表
+func GetSubjectArticlGroupList(condition string, pars []interface{}) (items []*SubjectArticlGroupList, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			 s.subject_name,
+			 s.industrial_subject_id,
+			 ag.article_id
+		FROM
+			cygx_industrial_article_group_subject AS ag
+			INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = ag.industrial_subject_id
+			WHERE 1= 1  ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 1 - 1
models/report.go

@@ -730,7 +730,7 @@ func GetThemeDetail(userId, industrialManagementId int, condition string) (items
 		WHERE
 			1 = 1
 			AND m.industrial_management_id = ? 
-			AND publish_status = 1 ` + condition + `
+			AND publish_status = 1 ` + condition + ` GROUP BY article_id
 		ORDER BY
 			publish_date DESC`
 	_, err = o.Raw(sql, userId, userId, industrialManagementId).QueryRows(&items)

+ 33 - 4
services/yan_xuan.go

@@ -3,6 +3,7 @@ package services
 import (
 	"errors"
 	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
 	"strconv"
 	"strings"
 )
@@ -28,7 +29,7 @@ func GetYanXuanArticleTypeIds() (articleTypeIds string, err error) {
 }
 
 // 处理研选关联的新标签
-func GetYanXuanIndustrialManagementIdNewMap(articleTypeIds string) (respMa map[int]bool, err error) {
+func GetYanXuanIndustrialManagementIdNewMap(articleTypeIds string) (respMap map[int]bool, err error) {
 	var condition string
 	if articleTypeIds == "" {
 		return
@@ -43,11 +44,12 @@ func GetYanXuanIndustrialManagementIdNewMap(articleTypeIds string) (respMa map[i
 	for _, v := range list {
 		newMap[v.IndustrialManagementId] = true
 	}
+	respMap = newMap
 	return
 }
 
 // 处理研选关联的hot标签
-func GetYanXuanIndustrialManagementIdHotMap(articleTypeIds string) (respMa map[int]bool, err error) {
+func GetYanXuanIndustrialManagementIdHotMap(articleTypeIds string) (respMap map[int]bool, err error) {
 	var condition string
 	var conditionOrder string
 	if articleTypeIds == "" {
@@ -60,9 +62,36 @@ func GetYanXuanIndustrialManagementIdHotMap(articleTypeIds string) (respMa map[i
 		err = errors.New("GetIndustrialManagementNewList, Err: " + e.Error())
 		return
 	}
-	newHot := make(map[int]bool)
+	hotMap := make(map[int]bool)
 	for _, v := range listHot {
-		newHot[v.IndustrialManagementId] = true
+		hotMap[v.IndustrialManagementId] = true
 	}
+	respMap = hotMap
+	return
+}
+
+// GetArticleSubjectName 获取文章关联的多个标的名称
+func GetArticleSubjectName(articleIds []int) (respMap map[int]string, err error) {
+	lenarticleIds := len(articleIds)
+	if lenarticleIds == 0 {
+		return
+	}
+	var condition string
+	var pars []interface{}
+	condition = ` AND ag.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
+	pars = append(pars, articleIds)
+	list, e := models.GetSubjectArticlGroupList(condition, pars)
+	if e != nil {
+		err = errors.New("GetIndustrialManagementNewList, Err: " + e.Error())
+		return
+	}
+	artMap := make(map[int]string)
+	for _, v := range list {
+		artMap[v.ArticleId] += v.SubjectName + "/"
+	}
+	for _, v := range list {
+		artMap[v.ArticleId] = strings.TrimRight(artMap[v.ArticleId], "/")
+	}
+	respMap = artMap
 	return
 }