瀏覽代碼

批量修改获取产业关联文章的最新发布时间

xingzai 2 年之前
父節點
當前提交
ed8cd5aeca

+ 160 - 158
controllers/report.go

@@ -237,172 +237,174 @@ func (this *ReportController) IndustryList() {
 	// 获取近一个月产业报告阅读次数最多的产业
 	var topCond string
 	var topPars []interface{}
-	topReadIndustryId := 0
+	//topReadIndustryId := 0
 	if ChartPermissionId > 0 {
 		topCond += ` AND chart_permission_id = ?`
 		topPars = append(topPars, ChartPermissionId)
 	}
-	topReadIndustry, e := models.GetTopOneMonthArtReadNumIndustry(topCond, topPars)
-	if e != nil && e.Error() != utils.ErrNoRow() {
-		br.Msg = "获取信息失败"
-		br.ErrMsg = "获取近一个月报告阅读次数最多的产业失败, Err: " + e.Error()
-		return
-	}
-	if topReadIndustry != nil {
-		topReadIndustryId = topReadIndustry.IndustrialManagementId
-	}
+	//topReadIndustry, e := models.GetTopOneMonthArtReadNumIndustry(topCond, topPars)
+	//if e != nil && e.Error() != utils.ErrNoRow() {
+	//	br.Msg = "获取信息失败"
+	//	br.ErrMsg = "获取近一个月报告阅读次数最多的产业失败, Err: " + e.Error()
+	//	return
+	//}
+	//if topReadIndustry != nil {
+	//	topReadIndustryId = topReadIndustry.IndustrialManagementId
+	//}
 
 	//查询产业视频
-	industrialVideoMap := make(map[int]*models.MicroVideoSimpleInfo)
-	var industrialManagementIds []int
-	for _, v := range list {
-		if v.IndustrialManagementId > 0 {
-			industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
-		}
-	}
+	//industrialVideoMap := make(map[int]*models.MicroVideoSimpleInfo)
+	//var industrialManagementIds []int
+	//for _, v := range list {
+	//	if v.IndustrialManagementId > 0 {
+	//		industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
+	//	}
+	//}
 
 	// 用户权限
-	authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
-	if e != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
-		return
-	}
-	mapUPdateTime := make(map[int]string)
-
-	if len(industrialManagementIds) > 0 {
-		// 获取默认图配置
-		_, videoMap, _, _, e := services.GetMicroRoadShowDefaultImgConfig()
-		if e != nil {
-			br.Msg = "获取视频默认配置图失败"
-			br.ErrMsg = "获取视频默认配置图失败, Err: " + e.Error()
-			return
-		}
-		videoList, err := models.GetMicroRoadshowVideoByIndustryIds(industrialManagementIds)
-		if err != nil {
-			br.Msg = "产业视频列表失败"
-			br.ErrMsg = "产业视频列表失败, Err: " + err.Error()
-			return
-		}
-		for _, v := range videoList {
-			tmp := &models.MicroVideoSimpleInfo{
-				Id:                  v.VideoId,
-				Title:               "5min逻辑【" + v.IndustryName + "】解析",
-				ResourceUrl:         v.VideoUrl,
-				BackgroundImg:       v.ImgUrl,
-				PlaySeconds:         v.VideoDuration,
-				DetailImgUrl:        v.DetailImgUrl,
-				ChartPermissionId:   v.ChartPermissionId,
-				ChartPermissionName: v.ChartPermissionName,
-			}
-			if tmp.BackgroundImg == "" {
-				tmp.BackgroundImg = videoMap[v.ChartPermissionId]
-			}
-			industrialVideoMap[v.IndustryId] = tmp
-		}
-		//获取这些产业下最新更新的文章
-		listUpdateTime, err := models.GetNewArticleDetailByIndustrialIds(industrialManagementIds)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			return
-		}
-		for _, v := range listUpdateTime {
-			mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
-		}
-
-		//时间线的更新时间
-		//	maptimelineUPdateTime := make(map[int]string)
-		listtimelinePublishdate, err := models.GetTimeLineReportIndustrialPublishdateList(industrialManagementIds)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			return
-		}
-		for _, v := range listtimelinePublishdate {
-			if mapUPdateTime[v.IndustrialManagementId] != "" {
-				if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
-					mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
-				}
-			}
-		}
-	}
-
-	nowTime := time.Now().Local()
-	threeMonBefore := nowTime.AddDate(0, -3, 0)
-	for k, v := range list {
-		industrialSubjectList, err := models.GetIndustrialSubjectAll(v.IndustrialManagementId)
-		if err != nil {
-			br.Msg = "获取信息失败"
-			br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
-			return
-		}
-		list[k].IndustrialSubjectList = industrialSubjectList
-		list[k].LayoutTime = utils.TimeRemoveHms(v.LayoutTime)
-		newArtinfo, err := models.GetIndustrialNewArticleDetail(v.IndustrialManagementId)
-		if err != nil {
-			br.Msg = "获取信息失败"
-			br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
-			return
-		}
-		list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
-		recordCount, err := models.GetUserToArticleCount(uid, newArtinfo.ArticleId)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			br.Msg = "获取信息失败"
-			br.ErrMsg = "获取信息失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(newArtinfo.ArticleId)
-			return
-		}
-		if recordCount == 0 && user.CreatedTime.Before(utils.StrTimeToTime(newArtinfo.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(newArtinfo.PublishDate)) {
-			list[k].IsRed = true
-		}
-		// 原:关联的报告阅读量大于等于阅读第三的产业,则标记热门
-		//if v.ArticleReadNum >= detailHot3.ArticleReadNum {
-		//	list[k].IsHot = true
-		//}
-
-		// 近一个月报告阅读次数最多的产业标记Hot
-		if topReadIndustryId > 0 && list[k].IndustrialManagementId == topReadIndustryId {
-			list[k].IsHot = true
-		}
-
-		// 关联报告发布时间均在3个月内则标记New
-		if v.MinReportTime != "" {
-			t, e := time.Parse(utils.FormatDateTime, v.MinReportTime)
-			if e != nil {
-				br.Msg = "获取信息失败"
-				br.ErrMsg = "报告最早发布时间有误, Err: " + e.Error()
-				return
-			}
-			if t.After(threeMonBefore) {
-				list[k].IsNew = true
-			}
-		}
-
-		//展示产业视频
-		if video, ok := industrialVideoMap[v.IndustrialManagementId]; ok {
-			//控制用户权限
-			// 权限
-			au := new(models.UserPermissionAuthInfo)
-			au.SellerName = authInfo.SellerName
-			au.SellerMobile = authInfo.SellerMobile
-			au.HasPermission = authInfo.HasPermission
-			au.OperationMode = authInfo.OperationMode
-			if au.HasPermission == 1 {
-				// 非宏观权限进一步判断是否有权限
-				if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
-					au.HasPermission = 2
-				}
-			}
-			// 无权限的弹框提示
-			if au.HasPermission != 1 {
-				if au.OperationMode == services.UserPermissionOperationModeCall {
-					au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
-				} else {
-					au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
-				}
-				video.ResourceUrl = ""
-			}
-			list[k].AuthInfo = au
-			list[k].IndustryVideo = video
-		}
-
-	}
+	//authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
+	//if e != nil {
+	//	br.Msg = "获取失败"
+	//	br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
+	//	return
+	//}
+	//mapUPdateTime := make(map[int]string)
+	//
+	//if len(industrialManagementIds) > 0 {
+	//	// 获取默认图配置
+	//	_, videoMap, _, _, e := services.GetMicroRoadShowDefaultImgConfig()
+	//	if e != nil {
+	//		br.Msg = "获取视频默认配置图失败"
+	//		br.ErrMsg = "获取视频默认配置图失败, Err: " + e.Error()
+	//		return
+	//	}
+	//	videoList, err := models.GetMicroRoadshowVideoByIndustryIds(industrialManagementIds)
+	//	if err != nil {
+	//		br.Msg = "产业视频列表失败"
+	//		br.ErrMsg = "产业视频列表失败, Err: " + err.Error()
+	//		return
+	//	}
+	//	for _, v := range videoList {
+	//		tmp := &models.MicroVideoSimpleInfo{
+	//			Id:                  v.VideoId,
+	//			Title:               "5min逻辑【" + v.IndustryName + "】解析",
+	//			ResourceUrl:         v.VideoUrl,
+	//			BackgroundImg:       v.ImgUrl,
+	//			PlaySeconds:         v.VideoDuration,
+	//			DetailImgUrl:        v.DetailImgUrl,
+	//			ChartPermissionId:   v.ChartPermissionId,
+	//			ChartPermissionName: v.ChartPermissionName,
+	//		}
+	//		if tmp.BackgroundImg == "" {
+	//			tmp.BackgroundImg = videoMap[v.ChartPermissionId]
+	//		}
+	//		industrialVideoMap[v.IndustryId] = tmp
+	//	}
+	//	//获取这些产业下最新更新的文章
+	//	listUpdateTime, err := models.GetNewArticleDetailByIndustrialIds(industrialManagementIds)
+	//	if err != nil && err.Error() != utils.ErrNoRow() {
+	//		return
+	//	}
+	//	for _, v := range listUpdateTime {
+	//		mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
+	//	}
+	//
+	//	//时间线的更新时间
+	//	//	maptimelineUPdateTime := make(map[int]string)
+	//	listtimelinePublishdate, err := models.GetTimeLineReportIndustrialPublishdateList(industrialManagementIds)
+	//	if err != nil && err.Error() != utils.ErrNoRow() {
+	//		return
+	//	}
+	//	for _, v := range listtimelinePublishdate {
+	//		if mapUPdateTime[v.IndustrialManagementId] != "" {
+	//			if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
+	//				mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
+	//			}
+	//		}
+	//	}
+	//}
+	//
+	//nowTime := time.Now().Local()
+	//threeMonBefore := nowTime.AddDate(0, -3, 0)
+
+	list, err = services.HandleIndustryList(list, user)
+	//for k, v := range list {
+	//	industrialSubjectList, err := models.GetIndustrialSubjectAll(v.IndustrialManagementId)
+	//	if err != nil {
+	//		br.Msg = "获取信息失败"
+	//		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
+	//		return
+	//	}
+	//	list[k].IndustrialSubjectList = industrialSubjectList
+	//	list[k].LayoutTime = utils.TimeRemoveHms(v.LayoutTime)
+	//	newArtinfo, err := models.GetIndustrialNewArticleDetail(v.IndustrialManagementId)
+	//	if err != nil {
+	//		br.Msg = "获取信息失败"
+	//		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
+	//		return
+	//	}
+	//	list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
+	//	recordCount, err := models.GetUserToArticleCount(uid, newArtinfo.ArticleId)
+	//	if err != nil && err.Error() != utils.ErrNoRow() {
+	//		br.Msg = "获取信息失败"
+	//		br.ErrMsg = "获取信息失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(newArtinfo.ArticleId)
+	//		return
+	//	}
+	//	if recordCount == 0 && user.CreatedTime.Before(utils.StrTimeToTime(newArtinfo.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(newArtinfo.PublishDate)) {
+	//		list[k].IsRed = true
+	//	}
+	//	// 原:关联的报告阅读量大于等于阅读第三的产业,则标记热门
+	//	//if v.ArticleReadNum >= detailHot3.ArticleReadNum {
+	//	//	list[k].IsHot = true
+	//	//}
+	//
+	//	// 近一个月报告阅读次数最多的产业标记Hot
+	//	if topReadIndustryId > 0 && list[k].IndustrialManagementId == topReadIndustryId {
+	//		list[k].IsHot = true
+	//	}
+	//
+	//	// 关联报告发布时间均在3个月内则标记New
+	//	if v.MinReportTime != "" {
+	//		t, e := time.Parse(utils.FormatDateTime, v.MinReportTime)
+	//		if e != nil {
+	//			br.Msg = "获取信息失败"
+	//			br.ErrMsg = "报告最早发布时间有误, Err: " + e.Error()
+	//			return
+	//		}
+	//		if t.After(threeMonBefore) {
+	//			list[k].IsNew = true
+	//		}
+	//	}
+	//
+	//	//展示产业视频
+	//	if video, ok := industrialVideoMap[v.IndustrialManagementId]; ok {
+	//		//控制用户权限
+	//		// 权限
+	//		au := new(models.UserPermissionAuthInfo)
+	//		au.SellerName = authInfo.SellerName
+	//		au.SellerMobile = authInfo.SellerMobile
+	//		au.HasPermission = authInfo.HasPermission
+	//		au.OperationMode = authInfo.OperationMode
+	//		if au.HasPermission == 1 {
+	//			// 非宏观权限进一步判断是否有权限
+	//			if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
+	//				au.HasPermission = 2
+	//			}
+	//		}
+	//		// 无权限的弹框提示
+	//		if au.HasPermission != 1 {
+	//			if au.OperationMode == services.UserPermissionOperationModeCall {
+	//				au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
+	//			} else {
+	//				au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
+	//			}
+	//			video.ResourceUrl = ""
+	//		}
+	//		list[k].AuthInfo = au
+	//		list[k].IndustryVideo = video
+	//	}
+	//
+	//}
 	//记录用户搜索的筛选条件
 	if orderColumnNew != "" {
 		item := new(models.CygxReportIndustrialSeaarchHistory)

+ 27 - 0
models/article_history_record.go

@@ -21,6 +21,12 @@ type CygxArticleHistoryRecord struct {
 	OutType     int       `description:"退出方式,1正常退出,2强制关闭"`
 }
 
+type CygxArticleHistoryResp struct {
+	Pv        int `description:"阅读PV"`
+	ArticleId int `description:"文章id"`
+	Num       int `description:"数量"`
+}
+
 //添加历史信息
 func AddCygxArticleHistoryRecord(item *CygxArticleHistoryRecord) (lastId int64, err error) {
 	o, err := orm.NewOrm().Begin()
@@ -124,3 +130,24 @@ func GetArticleHistoryList() (items []*CygxArticleHistoryRecordNewpv, err error)
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+//获取用户阅读记录
+func GetUserToArticleHistory(uid int, articleIdArr []int) (items []*CygxArticleHistoryResp, err error) {
+	arrLen := len(articleIdArr)
+	if arrLen == 0 {
+		return
+	}
+	sql := `SELECT
+			article_id 
+		FROM
+			cygx_article_history_record 
+		WHERE
+			1 = 1 
+		AND user_id = ?
+			AND article_id IN (` + utils.GetOrmInReplace(len(articleIdArr)) + `)   
+		GROUP BY
+			article_id `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, uid, articleIdArr).QueryRows(&items)
+	return
+}

+ 44 - 1
models/industrial_management.go

@@ -62,7 +62,7 @@ func GetIndustrialManagementAll(uid int, condition, orderSrt string, startSize,
 	o := orm.NewOrm()
 	sql := `SELECT
 			man.*,re.chart_permission_name as permission_name,
-            MAX( art.publish_date ) AS update_time , MIN(art.publish_date) AS min_report_time,(
+            man.new_art_publish_date AS update_time , MIN(art.publish_date) AS min_report_time,(
 			SELECT COUNT( 1 ) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(uid) + ` AND rec.article_id = art.article_id ) AS readnum ,
 		    (SELECT COUNT( 1 )  FROM cygx_industry_fllow AS f WHERE f.user_id = ` + strconv.Itoa(uid) + ` AND f.industrial_management_id = man.industrial_management_id AND f.type = 1) AS is_follow
 			FROM
@@ -683,3 +683,46 @@ func GetNewArticleDetailByIndustrialIds(industrialIdArr []int) (items []*Industr
 	_, err = o.Raw(sql, utils.SummaryArticleId, industrialIdArr).QueryRows(&items)
 	return
 }
+
+//GetIndustrialManagementArticleNewPublishData 获取产业关联文章的最新发布时间
+func GetIndustrialManagementArticleNewPublishData() (items []*IndustrialManagement, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			man.industrial_management_id,
+			MAX( art.publish_date ) AS update_time 
+		FROM
+			cygx_industrial_management AS man
+			INNER JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id
+			INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
+			INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id 
+		WHERE
+			1 = 1 
+			AND re.report_type = 2 
+			AND art.is_report = 1 
+			AND art.is_class = 1 
+		GROUP BY
+			man.industry_name 
+		ORDER BY
+			update_time DESC`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// UpdateIndustrialManagementArticleNewPublishData 批量修改获取产业关联文章的最新发布时间
+func UpdateIndustrialManagementArticleNewPublishData(items map[int]string) (err error) {
+	o := orm.NewOrm()
+	p, err := o.Raw("UPDATE cygx_industrial_management SET new_art_publish_date = ? WHERE industrial_management_id = ?").Prepare()
+	if err != nil {
+		return
+	}
+	defer func() {
+		_ = p.Close() // 别忘记关闭 statement
+	}()
+	for k, v := range items {
+		_, err = p.Exec(v, k)
+		if err != nil {
+			return
+		}
+	}
+	return
+}

+ 16 - 0
models/micro_roadshow.go

@@ -317,3 +317,19 @@ type MicroRoadshowCollectReq struct {
 	Id         int `description:"音频或视频ID"`
 	SourceType int `description:"视频来源: 1-音频; 2-活动视频; 3-微路演视频 (不传默认为1)"`
 }
+
+// GetMicroRoadshowVideoList 获取已经发布的微路演视频
+func GetMicroRoadshowVideoList() (list []*MicroRoadshowVideo, err error) {
+	sql := `SELECT * FROM cygx_micro_roadshow_video WHERE  publish_status = 1`
+	_, err = orm.NewOrm().Raw(sql).QueryRows(&list)
+	return
+}
+
+//GetMicroRoadshowVideoByIndustryIdCount  根据行业ID查询产业视频是否存在
+func GetMicroRoadshowVideoByIndustryIdCount(industryId int) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) count
+			FROM cygx_micro_roadshow_video WHERE industry_id = ? and publish_status = 1`
+	err = o.Raw(sql, industryId).QueryRow(&count)
+	return
+}

+ 2 - 1
models/report.go

@@ -10,7 +10,6 @@ import (
 type IndustrialManagementList struct {
 	Paging *paging.PagingItem
 	List   []*IndustrialManagement
-
 }
 
 type IndustrialManagement struct {
@@ -35,6 +34,8 @@ type IndustrialManagement struct {
 	PermissionName         string               `description:"行业名称"`
 	IndustryVideo          *MicroVideoSimpleInfo
 	AuthInfo               *UserPermissionAuthInfo
+	ArticleId              int `description:"文章id"`
+	Source                 int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
 }
 
 type MicroVideoSimpleInfo struct {

+ 1 - 1
services/article.go

@@ -1115,7 +1115,7 @@ func HandleArticleListByApi(artcleId int) (err error) {
 	go models.UpdateCygxArticleCeluePush(artcleId)
 
 	GetSummarytoEs(artcleId)
-
+	GetIndustrialManagementArticleNewPublishData()
 	if len(listArticleData) > 0 {
 		for _, v := range listArticleData {
 			count, err := models.GetCygxArticleDataCount(v.ArticleId)

+ 185 - 0
services/industrial_management.go

@@ -266,3 +266,188 @@ func GetIndustryNewLabelMap(industryIds []int) (labelMap map[int]bool, err error
 	}
 	return
 }
+
+//func init() {
+//	GetIndustrialManagementArticleNewPublishData()
+//}
+
+//批量修改获取产业关联文章的最新发布时间
+func GetIndustrialManagementArticleNewPublishData() (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("批量修改获取产业关联文章的最新发布时间"+"GetIndustrialManagementArticleNewPublishData ErrMsg:"+err.Error(), 2)
+
+		}
+	}()
+	articleNewPublishDataList, e := models.GetIndustrialManagementArticleNewPublishData()
+	if e != nil {
+		err = errors.New("获取客户剩余报名次数失败 GetIndustrialManagementArticleNewPublishData, Err: " + e.Error())
+		return
+	}
+	mapUPdateTime := make(map[int]string)
+	var industrialManagementIds []int
+	for _, v := range articleNewPublishDataList {
+		if v.IndustrialManagementId > 0 {
+			industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
+		}
+		mapUPdateTime[v.IndustrialManagementId] = v.UpdateTime
+	}
+	//时间线的更新时间
+	listtimelinePublishdate, err := models.GetTimeLineReportIndustrialPublishdateList(industrialManagementIds)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+	for _, v := range listtimelinePublishdate {
+		if mapUPdateTime[v.IndustrialManagementId] != "" {
+			if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
+				mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
+			}
+		}
+	}
+	err = models.UpdateIndustrialManagementArticleNewPublishData(mapUPdateTime)
+	return
+}
+
+//HandleIndustryList预处理产业列表字段
+func HandleIndustryList(list []*models.IndustrialManagement, user *models.WxUserItem) (items []*models.IndustrialManagement, err error) {
+	userId := user.UserId
+	fllowList, err := models.GetUserFllowIndustrialList(userId)
+	if err != nil {
+		return
+	}
+	fllowMap := make(map[int]int)
+	if len(fllowList) > 0 {
+		for _, v := range fllowList {
+			fllowMap[v.IndustrialManagementId] = v.IndustrialManagementId
+		}
+	}
+	mapindustrialId, e := GetMicroRoadshowVideoMap()
+	if e != nil {
+		err = e
+		return
+	}
+	//合并产业关联的标的
+	listSubjcet, err := models.GetThemeHeatSubjectList("")
+	if err != nil {
+		return
+	}
+	industrialIdArr := make([]int, 0)
+	for k, v := range list {
+		list[k].Source = 1
+		if fllowMap[v.IndustrialManagementId] > 0 {
+			list[k].IsFollow = 1
+		}
+		industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
+		if _, ok := mapindustrialId[v.IndustrialManagementId]; !ok {
+			continue
+		}
+		videoSimple, au, e := GetindustryVideo(user, v.IndustrialManagementId)
+		if e != nil {
+			err = errors.New("获取产业关联的视频失败,GetindustryVideo " + e.Error())
+			return
+		}
+		if videoSimple != nil && videoSimple.Id > 0 {
+			v.IndustryVideo = videoSimple
+		}
+		v.AuthInfo = au
+	}
+
+	if len(industrialIdArr) > 0 {
+		//合并产业关联的标的
+		listSubjcet, err = models.GetIndustrialSubjectAllByIndustrialId(industrialIdArr)
+		if err != nil {
+			return
+		}
+		mapIndustrial := make(map[string]int)
+		for _, v := range listSubjcet {
+			for k2, v2 := range list {
+				if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
+					list[k2].IndustrialSubjectList = append(list[k2].IndustrialSubjectList, v)
+					mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] = v2.IndustrialManagementId
+				}
+			}
+		}
+	}
+	mapUPdateTime := make(map[int]string)
+	articleIdArr := make([]int, 0)
+	//获取这些产业下最新更新的文章
+
+	listUpdateTime, err := models.GetNewArticleDetailByIndustrialIds(industrialIdArr)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+	for _, v := range listUpdateTime {
+		mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
+		articleIdArr = append(articleIdArr, v.ArticleId)
+	}
+
+	//时间线的更新时间
+	//	maptimelineUPdateTime := make(map[int]string)
+	listtimelinePublishdate, err := models.GetTimeLineReportIndustrialPublishdateList(industrialIdArr)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+	for _, v := range listtimelinePublishdate {
+		if mapUPdateTime[v.IndustrialManagementId] != "" {
+			if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
+				mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
+			}
+		}
+	}
+
+	mapHistroyArticleId := make(map[int]int)
+
+	if userId > 0 {
+		listArticleHistory, e := models.GetUserToArticleHistory(userId, industrialIdArr)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("获取产业关联的视频失败,GetindustryVideo " + e.Error())
+			return
+		}
+		for _, v := range listArticleHistory {
+			mapHistroyArticleId[v.ArticleId] = v.ArticleId
+		}
+	}
+	nowTime := time.Now().Local()
+	threeMonBefore := nowTime.AddDate(0, -3, 0)
+	for k, v := range list {
+		list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
+		if userId > 0 {
+			//如果文章没有阅读,而且,文章的发布时间晚于项目的上线时间,而且文章的发布时间晚于用户的注册时间,就进行标红处理
+			if mapHistroyArticleId[v.ArticleId] == 0 && user.CreatedTime.Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
+				list[k].IsRed = true
+			}
+		} else {
+			if utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
+				list[k].IsRed = true
+			}
+			list[k].IsFollow = 0
+		}
+
+		list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
+		if userId > 0 {
+			//如果文章没有阅读,而且,文章的发布时间晚于项目的上线时间,而且文章的发布时间晚于用户的注册时间,就进行标红处理
+			if mapHistroyArticleId[v.ArticleId] == 0 && user.CreatedTime.Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
+				list[k].IsRed = true
+			}
+		} else {
+			if utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
+				list[k].IsRed = true
+			}
+			list[k].IsFollow = 0
+		}
+
+		// 关联报告发布时间均在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
+			}
+		}
+	}
+	items = list
+	return
+}

+ 79 - 0
services/micro_roadshow.go

@@ -332,3 +332,82 @@ func GetMicroRoadShowMycollect(pageSize, currentIndex int, audioIds, videoIds, a
 	respList = videoList
 	return
 }
+
+//GetMicroRoadshowVideoMap 获取已经发布的微路演的产业ID
+func GetMicroRoadshowVideoMap() (items map[int]int, err error) {
+	list, e := models.GetMicroRoadshowVideoList()
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("获取已经发布的微路演的产业失败,GetMicroRoadshowVideoList " + e.Error())
+		return
+	}
+	mapindustrialId := make(map[int]int)
+	for _, v := range list {
+		mapindustrialId[v.IndustryId] = v.IndustryId
+	}
+	items = mapindustrialId
+	return
+}
+
+func GetindustryVideo(user *models.WxUserItem, industrialManagementId int) (industryVideo *models.MicroVideoSimpleInfo, AuthInfo *models.UserPermissionAuthInfo, err error) {
+	total, e := models.GetMicroRoadshowVideoByIndustryIdCount(industrialManagementId)
+	if e != nil {
+		err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryIdCount " + e.Error())
+		return
+	}
+	if total == 0 {
+		return
+	}
+	// 用户权限
+	authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
+	if e != nil {
+		err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
+		return
+	}
+	videoSimple := new(models.MicroVideoSimpleInfo)
+	// 权限
+	var au *models.UserPermissionAuthInfo
+	video, e := models.GetMicroRoadshowVideoByIndustryId(industrialManagementId)
+	if e != nil {
+		err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
+		return
+	} else {
+		videoSimple.Id = video.VideoId
+		videoSimple.Title = "5min【" + video.IndustryName + "】逻辑解析"
+		videoSimple.BackgroundImg = video.ImgUrl
+		videoSimple.DetailImgUrl = video.DetailImgUrl
+		if videoSimple.BackgroundImg == "" {
+			// 获取默认图配置
+			_, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
+			if e != nil {
+				err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
+				return
+			}
+			videoSimple.BackgroundImg = videoMap[video.ChartPermissionId]
+		}
+		videoSimple.PlaySeconds = video.VideoDuration
+		videoSimple.ResourceUrl = video.VideoUrl
+		au = new(models.UserPermissionAuthInfo)
+		au.SellerName = authInfo.SellerName
+		au.SellerMobile = authInfo.SellerMobile
+		au.HasPermission = authInfo.HasPermission
+		au.OperationMode = authInfo.OperationMode
+		if au.HasPermission == 1 {
+			// 非宏观权限进一步判断是否有权限
+			if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
+				au.HasPermission = 2
+			}
+		}
+		// 无权限的弹框提示
+		if au.HasPermission != 1 {
+			if au.OperationMode == UserPermissionOperationModeCall {
+				au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
+			} else {
+				au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
+			}
+			videoSimple.ResourceUrl = ""
+		}
+	}
+	industryVideo = videoSimple
+	AuthInfo = au
+	return
+}