Browse Source

Merge branch 'cygx_13.8.1' of http://8.136.199.33:3000/hongze/hongze_cygx

xingzai 4 months ago
parent
commit
a93def5682
3 changed files with 121 additions and 2 deletions
  1. 14 2
      controllers/report.go
  2. 25 0
      models/industrial_subject.go
  3. 82 0
      services/industrial_subject.go

+ 14 - 2
controllers/report.go

@@ -653,13 +653,18 @@ func (this *ReportController) List() {
 
 		//处理晨会精华关联的标的,以及要跳转的文章ID
 		var meetingreviewchaptIds []int
-		mapchaptIdAndArticleId := make(map[int]int)                            // 晨会精华ID与跳转文章ID的映射关系
-		mapchaptIdListSubject := make(map[int][]*models.CygxIndustrialSubject) // 晨会精华ID与标的列表的映射关系
+		var articleIds []int
+		mapchaptIdAndArticleId := make(map[int]int)                              // 晨会精华ID与跳转文章ID的映射关系
+		mapchaptIdListSubject := make(map[int][]*models.CygxIndustrialSubject)   // 晨会精华ID与标的列表的映射关系
+		mapArticleIdListSubject := make(map[int][]*models.CygxIndustrialSubject) // 报告ID与标的列表的映射关系
 		for _, v := range list {
 			if v.Resource == 3 {
 				meetingreviewchaptIds = append(meetingreviewchaptIds, v.Id)
 				v.Content = services.AnnotationHtml(v.Content)
 			}
+			if v.Resource == 1 {
+				articleIds = append(articleIds, v.Id)
+			}
 		}
 		if len(meetingreviewchaptIds) > 0 {
 			listMeet, err := services.GetCygxMorningMeetingReviewChapterListByIds(meetingreviewchaptIds)
@@ -672,6 +677,10 @@ func (this *ReportController) List() {
 				mapchaptIdListSubject[v.Id] = v.ListSubject
 			}
 		}
+		if len(articleIds) > 0 {
+			mapArticleIdListSubject = services.GetArticleGroupSubjectMapByIndustrialManagementId(articleIds, industrialManagementId)
+		}
+
 		//对应分类的所图片
 		detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
 		if err != nil {
@@ -745,6 +754,9 @@ func (this *ReportController) List() {
 				v.LinkArticleId = mapchaptIdAndArticleId[v.Id]
 				v.ListSubject = mapchaptIdListSubject[v.Id]
 			}
+			if v.Resource == 1 {
+				v.ListSubject = mapArticleIdListSubject[v.Id]
+			}
 		}
 
 		resp := new(models.TimeLineReportListResp)

+ 25 - 0
models/industrial_subject.go

@@ -12,6 +12,14 @@ type CygxIndustrialSubject struct {
 	Source                 int    `description:"来源,1正常添加,2:通过文章添加,3通过活动添加(默认为1)"`
 }
 
+type IndustrialSubjectByArticle struct {
+	IndustrialSubjectId    int    `description:"标的id"`
+	IndustrialManagementId int    `description:"产业id"`
+	SubjectName            string `description:"标的名称"`
+	IndustryName           string `description:"产业名称"`
+	ArticleId              int    `description:"文章ID"`
+}
+
 // 获取标的列表
 func GetCygxIndustrialSubjectListCondition(condition string, pars []interface{}) (items []*CygxIndustrialSubject, err error) {
 	o := orm.NewOrm()
@@ -21,3 +29,20 @@ func GetCygxIndustrialSubjectListCondition(condition string, pars []interface{})
 	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
 }
+
+// 获取标的列表
+func GetArticleGroupSubjectList(pars []interface{}, condition string) (items []*IndustrialSubjectByArticle, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			s.subject_name,
+			s.industrial_subject_id,
+			s.industrial_management_id,
+			g.article_id 
+		FROM
+			cygx_industrial_article_group_subject AS g
+			INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = g.industrial_subject_id 
+		WHERE
+			1 = 1 ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 82 - 0
services/industrial_subject.go

@@ -0,0 +1,82 @@
+package services
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"strings"
+)
+
+// GetArticleGroupSubjectMapByIndustrialManagementId 通过文章ID,产业;获取文章所关联的标的
+func GetArticleGroupSubjectMapByIndustrialManagementId(articleIds []int, industrialManagementId int) (mapResp map[int][]*models.CygxIndustrialSubject) {
+	var err error
+	lenArticleIds := len(articleIds)
+	if lenArticleIds == 0 {
+		return
+	}
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg(fmt.Sprint("通过文章ID,产业;获取文章所关联的标的失败 ,GetArticleGroupSubjectMapByIndustrialManagementId err"+err.Error(), "articleIds:", articleIds), 2)
+		}
+	}()
+	mapSubject := make(map[string]int)
+	listSub, e := models.GetcygxIndustrialSubject(industrialManagementId)
+	if e != nil {
+		err = errors.New("GetcygxIndustrialSubject, Err: " + e.Error())
+		return
+	}
+	for _, v := range listSub {
+		mapSubject[v.SubjectName] = v.IndustrialSubjectId
+	}
+
+	var condition string
+	var pars []interface{}
+	condition += ` AND  article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `) `
+	pars = append(pars, articleIds)
+	articleList, e := models.GetArticleList(condition, pars)
+	if e != nil {
+		err = errors.New("GetArticleList, Err: " + e.Error())
+		return
+	}
+
+	listMap := make(map[int][]*models.CygxIndustrialSubject, 0)
+	for _, v := range articleList {
+		sliceSubjects := strings.Split(v.Stock, "/")
+		for _, vSubject := range sliceSubjects {
+			sliceKuohao := strings.Split(vSubject, "(")           //过滤括号
+			sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
+			subject := sliceXiahuaxian[0]
+			if mapSubject[subject] == 0 {
+				continue
+			}
+			item := models.CygxIndustrialSubject{
+				IndustrialSubjectId:    mapSubject[subject],
+				IndustrialManagementId: industrialManagementId,
+				SubjectName:            subject,
+			}
+			listMap[v.ArticleId] = append(listMap[v.ArticleId], &item)
+		}
+	}
+
+	//condition = ` AND g.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)  AND s.industrial_management_id = ? `
+	//pars = append(pars, articleIds, industrialManagementId)
+	//list, e := models.GetArticleGroupSubjectList(pars, condition)
+	//if e != nil {
+	//	err = errors.New("GetArticleGroupSubjectList " + e.Error())
+	//	return
+	//}
+	//
+	//if len(list) > 0 {
+	//	for _, v := range list {
+	//		item := models.CygxIndustrialSubject{
+	//			IndustrialSubjectId:    v.IndustrialSubjectId,
+	//			IndustrialManagementId: v.IndustrialManagementId,
+	//			SubjectName:            v.SubjectName,
+	//		}
+	//		listMap[v.ArticleId] = append(listMap[v.ArticleId], &item)
+	//	}
+	//}
+	mapResp = listMap
+	return
+}