Browse Source

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

xingzai 2 years ago
parent
commit
1687396e06
4 changed files with 172 additions and 82 deletions
  1. 2 2
      controllers/report.go
  2. 95 72
      controllers/research.go
  3. 7 8
      models/report.go
  4. 68 0
      services/yan_xuan.go

+ 2 - 2
controllers/report.go

@@ -2999,8 +2999,8 @@ func (this *ReportController) SearchReportAndResource() {
 	threeMonBefore := nowTime.AddDate(0, -3, 0)
 	mapHot := make(map[string]int)
 
-	hotCondition := ` ORDER BY sum_num DESC  `
-	listHot, err := models.GetThemeHeatList(user.UserId, hotCondition, 0, 3)
+	conditionOrder := ` ORDER BY sum_num DESC  `
+	listHot, err := models.GetThemeHeatList(user.UserId, condition, conditionOrder, 0, 3)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()

+ 95 - 72
controllers/research.go

@@ -2,14 +2,12 @@ package controllers
 
 import (
 	"encoding/json"
-	"errors"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
 	"strconv"
 	"strings"
-	"time"
 )
 
 // 研选
@@ -34,12 +32,21 @@ func (this *ResearchController) NewList() {
 		br.Ret = 408
 		return
 	}
-	//chartPermissionId, _ := this.GetInt("ChartPermissionId")
-	//if chartPermissionId < 1 {
-	//	br.Msg = "请输入分类ID"
-	//	return
-	//}
-	list, err := models.GetIndustrialManagementNewList("")
+	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
+	var conditionOrder string
+	condition = ` AND a.article_type_id IN (` + articleTypeIds + `)  `
+	list, err := models.GetIndustrialManagementNewList(condition)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
@@ -47,8 +54,8 @@ func (this *ResearchController) NewList() {
 	}
 	mapHot := make(map[string]int)
 
-	condition := ` ORDER BY sum_num DESC  `
-	listHot, err := models.GetThemeHeatList(user.UserId, condition, 0, 3)
+	conditionOrder = ` ORDER BY sum_num DESC  `
+	listHot, err := models.GetThemeHeatList(user.UserId, condition, conditionOrder, 0, 3)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
@@ -87,13 +94,21 @@ func (this *ResearchController) CollectionList() {
 		br.Ret = 408
 		return
 	}
-	//chartPermissionId, _ := this.GetInt("ChartPermissionId")
-	//if chartPermissionId < 1 {
-	//	br.Msg = "请输入分类ID"
-	//	return
-	//}
+
 	var condition string
-	condition = `   AND a.article_type_id > 0  AND publish_status = 1 GROUP BY a.article_id ORDER BY collect_num_order DESC, publish_date DESC LIMIT 15 `
+	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 + `)  `
+	condition += `  AND publish_status = 1 GROUP BY a.article_id ORDER BY collect_num_order DESC, publish_date DESC LIMIT 15 `
 	list, err := models.GetArticleCollectionList(condition, user.UserId)
 	if err != nil {
 		br.Msg = "获取信息失败"
@@ -133,11 +148,6 @@ func (this *ResearchController) HotList() {
 		br.Ret = 408
 		return
 	}
-	//chartPermissionId, _ := this.GetInt("ChartPermissionId")
-	//if chartPermissionId < 1 {
-	//	br.Msg = "请输入分类ID"
-	//	return
-	//}
 	themeType, _ := this.GetInt("ThemeType")
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
@@ -150,34 +160,37 @@ func (this *ResearchController) HotList() {
 	}
 	startSize = utils.StartIndex(currentIndex, pageSize)
 	var condition string
+	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 {
-		condition = `ORDER BY publish_date DESC `
+		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
 	}
-	//newMap := make(map[int]string)
-	//listNew, err := models.GetIndustrialManagementNewList("")
-	//if err != nil {
-	//	br.Msg = "获取信息失败"
-	//	br.ErrMsg = "获取产业最新信息失败,Err:" + err.Error()
-	//	return
-	//}
-	//for _, v := range listNew {
-	//	newMap[v.IndustrialManagementId] = v.IndustryName
-	//}
 	condition = ` AND a.article_type_id > 0  `
 	listSubjcet, err := models.GetThemeHeatSubjectList(condition)
 	if err != nil {
@@ -185,35 +198,24 @@ func (this *ResearchController) HotList() {
 		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 newMap[v.IndustrialManagementId] != "" {
-		//	list[k].IsNew = true
-		//}
-		// 关联报告发布时间均在3个月内则标记New
-		if v.MinReportTime != "" {
-			t, e := time.Parse(utils.FormatDateTime, v.MinReportTime)
-			if e != nil {
-				err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.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].IsFollw = true
 		}
@@ -222,9 +224,6 @@ func (this *ResearchController) HotList() {
 				list[k].IndustrialSubjectList = append(list[k].IndustrialSubjectList, v2)
 			}
 		}
-		if mapHot[v.IndustryName] > 0 {
-			list[k].IsHot = true
-		}
 	}
 	page := paging.GetPaging(currentIndex, pageSize, total)
 	resp := new(models.IndustrialManagementHotListResp)
@@ -256,11 +255,6 @@ func (this *ResearchController) KolList() {
 		br.Ret = 408
 		return
 	}
-	//chartPermissionId, _ := this.GetInt("ChartPermissionId")
-	//if chartPermissionId < 1 {
-	//	br.Msg = "请输入分类ID"
-	//	return
-	//}
 	themeType, _ := this.GetInt("ThemeType")
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
@@ -272,25 +266,51 @@ func (this *ResearchController) KolList() {
 		currentIndex = 1
 	}
 	startSize = utils.StartIndex(currentIndex, pageSize)
+	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
+	var conditionOrder string
+	condition = ` AND a.article_type_id IN (` + articleTypeIds + `)  `
 
-	total, err := models.GetDepartmentlistCount("")
+	total, err := models.GetDepartmentlistCount(condition)
 	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
 
-	var condition string
 	if themeType == 2 {
-		condition = `ORDER BY sum_num DESC `
+		conditionOrder = `ORDER BY publish_date DESC `
 	} else {
-		condition = `ORDER BY fllow_num DESC `
+		conditionOrder = `ORDER BY fllow_num DESC `
+	}
+	mapHot := make(map[int]bool)
+	if themeType == 2 {
+		conditionHot := `ORDER BY fllow_num DESC `
+		listhot, err := models.GetDepartmentList(condition, conditionHot, user.UserId, 0, 3)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取信息失败,Err:" + err.Error()
+			return
+		}
+		for _, v := range listhot {
+			mapHot[v.DepartmentId] = true
+		}
 	}
 
-	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()
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
 		return
 	}
 	listIndustrial, err := models.GetIndustrialDepartmentList()
@@ -312,6 +332,9 @@ func (this *ResearchController) KolList() {
 				}
 			}
 		}
+		if themeType == 2 {
+			v.IsHot = mapHot[v.DepartmentId]
+		}
 	}
 	resp := new(models.DepartmentListResp)
 	page := paging.GetPaging(currentIndex, pageSize, total)

+ 7 - 8
models/report.go

@@ -503,7 +503,7 @@ type IndustrialManagementHotListResp struct {
 }
 
 // 产业列表
-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,
@@ -520,9 +520,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 + ` LIMIT ?,?`
 	_, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
 	return
 }
@@ -537,7 +535,7 @@ func GetThemeHeatListCount(condition string) (count int, err error) {
 			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
+            AND a.publish_status = 1  ` + condition
 	err = o.Raw(sql).QueryRow(&count)
 	return
 }
@@ -573,6 +571,7 @@ type DepartmentResp struct {
 	NickName     string `description:"作者昵称"`
 	ImgUrl       string `description:"图片链接"`
 	IsFollw      bool   `description:"是否关注"`
+	IsHot        bool   `description:"是否关注"`
 	FllowNum     int    `description:"关注数量"`
 	List         []*IndustrialDepartmentListResp
 }
@@ -588,7 +587,7 @@ type IndustrialDepartmentListResp 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,
@@ -603,9 +602,9 @@ func GetDepartmentList(condition string, userId, startSize, pageSize int) (items
 		WHERE
 			1 = 1
 			AND a.article_type_id > 0 
-			AND publish_status = 1 
+			AND publish_status = 1  ` + condition + `
 		GROUP BY
-				d.department_id ` + condition + ` LIMIT ?,?`
+				d.department_id ` + conditionOrder + ` LIMIT ?,?`
 	_, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
 	return
 }

+ 68 - 0
services/yan_xuan.go

@@ -0,0 +1,68 @@
+package services
+
+import (
+	"errors"
+	"hongze/hongze_cygx/models"
+	"strconv"
+	"strings"
+)
+
+// 获取研选类型的文章分类Id
+func GetYanXuanArticleTypeIds() (articleTypeIds string, err error) {
+	var condition string
+	condition = " AND is_show_yanx  = 1 "
+	listType, e := models.GetCygxArticleTypeListCondition(condition)
+	if e != nil {
+		err = errors.New("GetCygxArticleTypeListCondition, Err: " + e.Error())
+		return
+	}
+	for _, v := range listType {
+		articleTypeIds += strconv.Itoa(v.ArticleTypeId) + ","
+	}
+	articleTypeIds = strings.TrimRight(articleTypeIds, ",")
+	if articleTypeIds == "" {
+		err = errors.New("研选分类ID不能为空")
+		return
+	}
+	return
+}
+
+// 处理研选关联的新标签
+func GetYanXuanIndustrialManagementIdNewMap(articleTypeIds string) (respMa 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
+	}
+	return
+}
+
+// 处理研选关联的hot标签
+func GetYanXuanIndustrialManagementIdHotMap(articleTypeIds string) (respMa 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
+	}
+	newHot := make(map[int]bool)
+	for _, v := range listHot {
+		newHot[v.IndustrialManagementId] = true
+	}
+	return
+}