xingzai 2 سال پیش
والد
کامیت
e90dbef3bb
6فایلهای تغییر یافته به همراه171 افزوده شده و 52 حذف شده
  1. 53 37
      controllers/research.go
  2. 4 4
      models/article_department.go
  3. 27 0
      models/industrial_subject.go
  4. 4 7
      models/report.go
  5. 4 4
      services/industrial_subject.go
  6. 79 0
      services/yan_xuan.go

+ 53 - 37
controllers/research.go

@@ -199,13 +199,14 @@ func (this *MobileResearchController) KolList() {
 		return
 	}
 	var condition string
-	if themeType != 2 {
-		condition = `ORDER BY fllow_num DESC `
+	var conditionOrder string
+	if themeType == 2 {
+		conditionOrder = `ORDER BY publish_date DESC  `
 	} else {
-		condition = `ORDER BY publish_date DESC `
+		conditionOrder = `ORDER BY sum_num DESC `
 	}
 
-	list, err := models.GetDepartmentList(condition, user.UserId, startSize, pageSize)
+	list, err := models.GetDepartmentList(condition, conditionOrder, user.UserId, startSize, pageSize)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
@@ -261,7 +262,7 @@ func (this *MobileResearchController) HotList() {
 		br.Ret = 408
 		return
 	}
-	themeType, _ := this.GetInt("ThemeType", 1)
+	themeType, _ := this.GetInt("ThemeType")
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
 	var startSize int
@@ -273,55 +274,61 @@ func (this *MobileResearchController) HotList() {
 	}
 	startSize = utils.StartIndex(currentIndex, pageSize)
 	var condition string
-	if themeType == 1 {
-		condition = `ORDER BY publish_date DESC `
+	var conditionOrder string
+	articleTypeIds, err := services.GetYanXuanArticleTypeIds()
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
+		return
+	}
+	if articleTypeIds == "" {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "研选分类ID不能为空"
+		return
+	}
+	condition = ` AND a.article_type_id IN (` + articleTypeIds + `)  `
+	if themeType == 2 {
+		conditionOrder = `ORDER BY publish_date DESC  `
 	} else {
-		condition = `ORDER BY sum_num DESC `
+		conditionOrder = `ORDER BY sum_num DESC   `
 	}
-	total, err := models.GetThemeHeatListCount("")
+
+	total, err := models.GetThemeHeatListCount(condition)
 	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
-	list, err := models.GetThemeHeatList(user.UserId, condition, startSize, pageSize)
+	list, err := models.GetThemeHeatList(user.UserId, condition, conditionOrder, startSize, pageSize)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
 		return
 	}
-	condition = ` AND a.article_type_id > 0  `
 	listSubjcet, err := models.GetThemeHeatSubjectList(condition)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
 		return
 	}
-	mapHot := make(map[string]int)
-	condition = ` ORDER BY sum_num DESC `
-	listHot, err := models.GetThemeHeatList(user.UserId, condition, 0, 3)
+	mapHot := make(map[int]bool)
+	mapNew, err := services.GetYanXuanIndustrialManagementIdNewMap(articleTypeIds)
 	if err != nil {
 		br.Msg = "获取信息失败"
-		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
+		br.ErrMsg = "GetYanXuanIndustrialManagementIdNewMap,Err:" + err.Error()
 		return
 	}
-	for _, v := range listHot {
-		mapHot[v.IndustryName] = v.IndustrialManagementId
+	if themeType == 2 {
+		mapHot, err = services.GetYanXuanIndustrialManagementIdHotMap(articleTypeIds)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "GetYanXuanIndustrialManagementIdNewMap,Err:" + err.Error()
+			return
+		}
 	}
-	nowTime := time.Now().Local()
-	threeMonBefore := nowTime.AddDate(0, -3, 0)
 	for k, v := range list {
-		if v.MinReportTime != "" {
-			t, err := time.Parse(utils.FormatDateTime, v.MinReportTime)
-			if err != nil {
-				br.Msg = "获取信息失败"
-				br.ErrMsg = "报告最早发布时间有误,Err:" + err.Error()
-				return
-			}
-			if t.After(threeMonBefore) {
-				list[k].IsNew = true
-			}
-		}
+		list[k].IsNew = mapNew[v.IndustrialManagementId]
+		list[k].IsHot = mapHot[v.IndustrialManagementId]
 		if v.FllowNum > 0 {
 			list[k].IsFollow = true
 		}
@@ -330,10 +337,6 @@ func (this *MobileResearchController) HotList() {
 				list[k].IndustrialSubjectList = append(list[k].IndustrialSubjectList, v2)
 			}
 		}
-		if mapHot[v.IndustryName] > 0 {
-			list[k].IsHot = true
-		}
-		list[k].PublishDate = utils.StrTimeToTime(v.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
 	}
 	page := paging.GetPaging(currentIndex, pageSize, total)
 	resp := new(models.IndustrialManagementHotListResp)
@@ -442,8 +445,15 @@ func (this *MobileResearchController) ThemeDetail() {
 		resp.IsFollow = true
 	}
 
+	listSub, err := models.GetcygxIndustrialSubject(industrialManagementId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
+		return
+	}
+
 	//处理文章关联的标的
-	articleGroupSubjectMap, listSubtect, err := services.GetArticleGroupSubjectMap(articleIds)
+	articleGroupSubjectMap, subjectMap, err := services.GetArticleGroupSubjectMap(articleIds)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
@@ -453,9 +463,15 @@ func (this *MobileResearchController) ThemeDetail() {
 		for k, v := range resp.List {
 			resp.List[k].ListSubject = articleGroupSubjectMap[v.ArticleId]
 		}
-		resp.ListSubject = listSubtect
 	}
-
+	for _, v := range listSub {
+		itemSubJect := new(models.IndustrialSubject)
+		itemSubJect.SubjectName = v.SubjectName
+		itemSubJect.IndustrialSubjectId = v.IndustrialSubjectId
+		if subjectMap[v.IndustrialSubjectId] != "" {
+			resp.ListSubject = append(resp.ListSubject, itemSubJect)
+		}
+	}
 	resp.IndustryName = detailIndustrial.IndustryName
 	resp.IndustrialManagementId = detailIndustrial.IndustrialManagementId
 	br.Ret = 200

+ 4 - 4
models/article_department.go

@@ -74,7 +74,7 @@ type IndustrialSubjectList struct {
 }
 
 // 作者列表
-func GetDepartmentList(condition string, userId, startSize, pageSize int) (items []*DepartmentResp, err error) {
+func GetDepartmentList(condition, conditionOrder string, userId, startSize, pageSize int) (items []*DepartmentResp, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
 			d.nick_name,
@@ -88,10 +88,10 @@ func GetDepartmentList(condition string, userId, startSize, pageSize int) (items
 			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 
+			AND a.article_type_id > 0  
+			AND publish_status = 1  ` + condition + `
 		GROUP BY
-					d.department_id ` + condition + ` LIMIT ?,?`
+					d.department_id ` + conditionOrder + ` , last_updated_time  DESC LIMIT ?,?`
 	_, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
 	return
 }

+ 27 - 0
models/industrial_subject.go

@@ -11,6 +11,11 @@ type IndustrialSubjectByArticle struct {
 	IndustryName           string `description:"产业名称"`
 	ArticleId              int    `description:"文章ID"`
 }
+type SubjectArticlGroupList struct {
+	SubjectName         string `description:"标的名称"`
+	ArticleId           int    `description:"cygx_article表的文章ID"`
+	IndustrialSubjectId int    `description:"cygx_industrial_subject表的文章ID"`
+}
 
 // 获取标的列表
 func GetArticleGroupSubjectList(pars []interface{}, condition string) (items []*IndustrialSubjectByArticle, err error) {
@@ -28,3 +33,25 @@ func GetArticleGroupSubjectList(pars []interface{}, condition string) (items []*
 	_, 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
+}
+
+func GetcygxIndustrialSubject(industrialManagementId int) (items []*IndustrialSubject, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT subject_name,industrial_subject_id FROM cygx_industrial_subject  WHERE industrial_management_id = ?`
+	_, err = o.Raw(sql, industrialManagementId).QueryRows(&items)
+	return
+}

+ 4 - 7
models/report.go

@@ -559,14 +559,13 @@ func GetThemeHeatListCount(condition string) (count int, err error) {
 			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.article_type_id > 0 AND a.publish_status = 1  ` + condition
+			1 = 1 AND a.publish_status = 1  ` + condition
 	err = o.Raw(sql).QueryRow(&count)
 	return
 }
 
 // 产业列表
-func GetThemeHeatList(userId int, condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
+func GetThemeHeatList(userId int, condition, conditionOrder string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
 			m.industry_name,
@@ -575,7 +574,7 @@ func GetThemeHeatList(userId int, condition string, startSize, pageSize int) (it
           	MAX( a.publish_date ) AS publish_date,
 			MIN(a.publish_date) AS min_report_time,
 			( SELECT count( 1 ) FROM cygx_industry_fllow AS f  WHERE f.industrial_management_id = m.industrial_management_id  AND user_id =? AND f.type = 1  ) AS fllow_num,
-			m.article_read_num + ( SELECT count( 1 ) FROM cygx_activity_meet_detail_log AS la  WHERE la.activity_id  IN  (SELECT activity_id FROM cygx_industrial_activity_group_management WHERE industrial_management_id = m.industrial_management_id  ) AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( la.activity_time ) ) AS sum_num
+			( SELECT count( 1 ) FROM cygx_industry_fllow AS f  WHERE f.industrial_management_id = m.industrial_management_id  AND f.type = 1  ) AS sum_num
 		FROM
 			cygx_industrial_management AS m
 			LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
@@ -583,9 +582,7 @@ func GetThemeHeatList(userId int, condition string, startSize, pageSize int) (it
 			LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
 		WHERE
 			1 = 1
-			AND a.article_type_id > 0
-			AND publish_status = 1 
-			GROUP BY m.industrial_management_id ` + condition + ` LIMIT ?,?`
+			AND publish_status = 1  ` + condition + `  GROUP BY m.industrial_management_id ` + conditionOrder + ` , last_updated_time  DESC LIMIT ?,?`
 	_, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
 	return
 }

+ 4 - 4
services/industrial_subject.go

@@ -7,7 +7,7 @@ import (
 )
 
 // GetArticleGroupSubjectMap 获取文章所关联的标的
-func GetArticleGroupSubjectMap(articleIds []int) (mapResp map[int][]*models.IndustrialSubject, listSubtect []*models.IndustrialSubject, err error) {
+func GetArticleGroupSubjectMap(articleIds []int) (mapResp map[int][]*models.IndustrialSubject, subjectMap map[int]string, err error) {
 	lenArticleIds := len(articleIds)
 	if lenArticleIds == 0 {
 		return
@@ -22,6 +22,7 @@ func GetArticleGroupSubjectMap(articleIds []int) (mapResp map[int][]*models.Indu
 		return
 	}
 	listMap := make(map[int][]*models.IndustrialSubject)
+	subMap := make(map[int]string)
 	mapName := make(map[int]int)
 	if len(list) > 0 {
 		for _, v := range list {
@@ -31,12 +32,11 @@ func GetArticleGroupSubjectMap(articleIds []int) (mapResp map[int][]*models.Indu
 				SubjectName:            v.SubjectName,
 			}
 			listMap[v.ArticleId] = append(listMap[v.ArticleId], &item)
-			if _, ok := mapName[v.IndustrialSubjectId]; !ok {
-				listSubtect = append(listSubtect, &item)
-			}
+			subMap[v.IndustrialSubjectId] = v.SubjectName
 			mapName[v.IndustrialSubjectId] = v.IndustrialManagementId
 		}
 	}
 	mapResp = listMap
+	subjectMap = subMap
 	return
 }

+ 79 - 0
services/yan_xuan.go

@@ -0,0 +1,79 @@
+package services
+
+import (
+	"errors"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+	"strings"
+)
+
+// 处理研选关联的新标签
+func GetYanXuanIndustrialManagementIdNewMap(articleTypeIds string) (respMap map[int]bool, err error) {
+	var condition string
+	if articleTypeIds == "" {
+		return
+	}
+	condition = ` AND a.article_type_id IN (` + articleTypeIds + `)  `
+	list, e := models.GetIndustrialManagementNewList(condition)
+	if e != nil {
+		err = errors.New("GetIndustrialManagementNewList, Err: " + e.Error())
+		return
+	}
+	newMap := make(map[int]bool)
+	for _, v := range list {
+		newMap[v.IndustrialManagementId] = true
+	}
+	respMap = newMap
+	return
+}
+
+// 处理研选关联的hot标签
+func GetYanXuanIndustrialManagementIdHotMap(articleTypeIds string) (respMap map[int]bool, err error) {
+	var condition string
+	var conditionOrder string
+	if articleTypeIds == "" {
+		return
+	}
+	condition = ` AND a.article_type_id IN (` + articleTypeIds + `)  `
+	conditionOrder = ` ORDER BY sum_num DESC `
+	listHot, e := models.GetThemeHeatList(0, condition, conditionOrder, 0, 3)
+	if e != nil {
+		err = errors.New("GetIndustrialManagementNewList, Err: " + e.Error())
+		return
+	}
+	hotMap := make(map[int]bool)
+	for _, v := range listHot {
+		hotMap[v.IndustrialManagementId] = true
+	}
+	respMap = hotMap
+	return
+}
+
+// GetArticleSubjectName 获取文章关联的多个标的名称
+func GetArticleSubjectName(articleIds []int) (respMap, subjectMap 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)
+	subMap := make(map[int]string)
+	for _, v := range list {
+		artMap[v.ArticleId] += v.SubjectName + "/"
+		subMap[v.IndustrialSubjectId] = v.SubjectName
+	}
+	for _, v := range list {
+		artMap[v.ArticleId] = strings.TrimRight(artMap[v.ArticleId], "/")
+	}
+	respMap = artMap
+	subjectMap = subMap
+	return
+}