Browse Source

Merge branch 'master' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

# Conflicts:
#	controllers/activity.go
#	services/activity.go
xingzai 2 years ago
parent
commit
d4c620d631
4 changed files with 152 additions and 68 deletions
  1. 7 7
      controllers/report.go
  2. 75 56
      controllers/research.go
  3. 4 5
      models/report.go
  4. 66 0
      services/yan_xuan.go

+ 7 - 7
controllers/report.go

@@ -422,7 +422,7 @@ func (this *ReportController) ArticleCategoryList() {
 		timeLineRed := false
 		if count < 2 {
 			timeLineRed = true
-		} else if count > 1 && recordItem.CreateTime.Before(utils.StrTimeToTime(morningMeetingTime)){
+		} else if count > 1 && recordItem.CreateTime.Before(utils.StrTimeToTime(morningMeetingTime)) {
 			timeLineRed = true
 		}
 		if !timeLineItem.IsRed && timeLineRed && haveMorningMeeting {
@@ -689,7 +689,7 @@ func (this *ReportController) List() {
 			timeLineRed := false
 			if count < 2 && v.SubCategoryName == "时间线" {
 				timeLineRed = true
-			} else if count > 1 && recordItem.CreateTime.Before(utils.StrTimeToTime(v.PublishTime)){
+			} else if count > 1 && recordItem.CreateTime.Before(utils.StrTimeToTime(v.PublishTime)) {
 				timeLineRed = true
 			}
 			if v.SubCategoryName == "时间线" && timeLineRed {
@@ -2912,8 +2912,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()
@@ -3031,11 +3031,11 @@ func (this *ReportController) SearchReportAndResource() {
 		industrialIdMap := make(map[string]time.Time)
 		for _, v := range recrodList {
 			industrialManagementIdstr = strings.TrimLeft(v.Parameter, "PageSize=10&CurrentIndex=1&CategoryId=99999&IndustrialManagementId=")
-			if createTime, ok := industrialIdMap[industrialManagementIdstr]; ok{
+			if createTime, ok := industrialIdMap[industrialManagementIdstr]; ok {
 				if createTime.Before(v.CreateTime) {
 					industrialIdMap[industrialManagementIdstr] = v.CreateTime
 				}
-			}else {
+			} else {
 				industrialIdMap[industrialManagementIdstr] = v.CreateTime
 			}
 		}
@@ -3051,7 +3051,7 @@ func (this *ReportController) SearchReportAndResource() {
 		timeLineRedMap := make(map[int]bool, 0)
 
 		for _, industrialId := range industrialIdArr {
-			if createTime, ok := industrialIdMap[strconv.Itoa(industrialId)]; ok{
+			if createTime, ok := industrialIdMap[strconv.Itoa(industrialId)]; ok {
 				if createTime.Before(morningMeetingTimeMap[industrialId]) {
 					timeLineRedMap[industrialId] = true
 				}

+ 75 - 56
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 {
@@ -186,9 +199,14 @@ func (this *ResearchController) HotList() {
 		return
 	}
 	mapHot := make(map[string]int)
-
-	condition = ` ORDER BY sum_num DESC `
-	listHot, err := models.GetThemeHeatList(user.UserId, condition, 0, 3)
+	mapNew, err := services.GetYanXuanIndustrialManagementIdNewMap(articleTypeIds)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "GetYanXuanIndustrialManagementIdNewMap,Err:" + err.Error()
+		return
+	}
+	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()
@@ -197,23 +215,8 @@ func (this *ResearchController) HotList() {
 	for _, v := range listHot {
 		mapHot[v.IndustryName] = v.IndustrialManagementId
 	}
-	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]
 		if v.FllowNum > 0 {
 			list[k].IsFollw = true
 		}
@@ -282,15 +285,28 @@ func (this *ResearchController) KolList() {
 
 	var condition string
 	if themeType == 2 {
-		condition = `ORDER BY sum_num DESC `
+		condition = `ORDER BY publish_date DESC `
 	} else {
 		condition = `ORDER BY fllow_num DESC `
 	}
+	mapHot := make(map[int]bool)
+	if themeType == 2 {
+		conditionHot := `ORDER BY fllow_num DESC `
+		listhot, err := models.GetDepartmentList(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)
 	if err != nil {
 		br.Msg = "获取信息失败"
-		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
 		return
 	}
 	listIndustrial, err := models.GetIndustrialDepartmentList()
@@ -312,6 +328,9 @@ func (this *ResearchController) KolList() {
 				}
 			}
 		}
+		if themeType == 2 {
+			v.IsHot = mapHot[v.DepartmentId]
+		}
 	}
 	resp := new(models.DepartmentListResp)
 	page := paging.GetPaging(currentIndex, pageSize, total)

+ 4 - 5
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
 }

+ 66 - 0
services/yan_xuan.go

@@ -0,0 +1,66 @@
+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
+}
+
+// 处理研选关联的新标签
+func GetYanXuanIndustrialManagementIdHotMap(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
+}