Browse Source

Merge branch 'cygx/need_1032' of http://8.136.199.33:3000/hongze/hz_crm_api

zhangchuanxing 1 week ago
parent
commit
c2a1a59159

+ 13 - 0
controllers/cygx/report_article.go

@@ -493,6 +493,17 @@ func (this *IndustrialSubjectController) ReportArticleClassification() {
 		return
 	}
 
+	detailIndustryNameList, err := cygx.GetIndustrialManagemenDetailByAaticleID(reportInfo.ArticleId)
+	if err != nil {
+		br.Msg = "分类失败"
+		br.ErrMsg = "获取报告原有分类失败,Err:" + err.Error()
+		return
+	}
+	var industryId []string
+	for _, v := range detailIndustryNameList {
+		industryId = append(industryId, strconv.Itoa(v.IndustrialManagementId))
+	}
+
 	industrialStrList := strings.Split(industrialManagementIdStr, ",")
 	for _, v := range industrialStrList {
 		condition = `AND industrial_management_id = ` + v
@@ -502,6 +513,7 @@ func (this *IndustrialSubjectController) ReportArticleClassification() {
 			br.ErrMsg = "操作失败,产业不存在IndustrialManagementId:" + v
 			return
 		}
+		industryId = append(industryId, v)
 	}
 	if req.IndustrialSubjectIdStr != "0" && req.IndustrialSubjectIdStr != "" {
 		strList := strings.Split(req.IndustrialSubjectIdStr, ",")
@@ -524,6 +536,7 @@ func (this *IndustrialSubjectController) ReportArticleClassification() {
 	}
 
 	go cygxService.DoArticleOnenIdWxTemplateMsg(reportInfo.ArticleId, 2)
+	go cygxService.UpdateIndustrialsourceHzResourceDataById(industryId, "Hz") //修改相关产业关联的报告信息
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "分类成功"

+ 28 - 3
controllers/cygx/summary_manage.go

@@ -80,6 +80,17 @@ func (this *SummaryManage) PreserveAndPublish() {
 	articleId := req.ArticleId
 	articleTypeId := req.ArticleTypeId
 
+	detailIndustryNameList, err := cygx.GetIndustrialManagemenDetailByAaticleID(articleId)
+	if err != nil {
+		br.Msg = "分类失败"
+		br.ErrMsg = "获取报告原有分类失败,Err:" + err.Error()
+		return
+	}
+	var industryId []string
+	for _, v := range detailIndustryNameList {
+		industryId = append(industryId, strconv.Itoa(v.IndustrialManagementId))
+	}
+
 	// 产业ID校验
 	industryIds := make([]int, 0)
 	industrialManagementIdList := strings.Split(industrialManagementIds, ",")
@@ -91,6 +102,7 @@ func (this *SummaryManage) PreserveAndPublish() {
 			return
 		}
 		industryIds = append(industryIds, i)
+		industryId = append(industryId, v)
 	}
 	if industrialSubjectIds != "" {
 		industrialSubjectIdList := strings.Split(industrialSubjectIds, ",")
@@ -319,9 +331,10 @@ func (this *SummaryManage) PreserveAndPublish() {
 		go cygxService.UpdateIndustryLayoutTime(industryIds, false)       // 查研观向7.4-更新产业布局时间
 		go elastic.AddComprehensiveIndustrialSource("Yx", item.ArticleId) // 查研观向10.6 更新搜索引擎的产业资源包
 	}
-	go elastic.AddComprehensiveArticle(item.ArticleId)       // ES添加文章:报告、纪要
-	go cygxService.UpdateArticleResourceData(item.ArticleId) //写入首页最新  cygx_resource_data 表
-	go cygxService.MakeArticleMomentsImg(item.ArticleId)     //生成文章分享到朋友圈的图片
+	go elastic.AddComprehensiveArticle(item.ArticleId)                        // ES添加文章:报告、纪要
+	go cygxService.UpdateArticleResourceData(item.ArticleId)                  //写入首页最新  cygx_resource_data 表
+	go cygxService.MakeArticleMomentsImg(item.ArticleId)                      //生成文章分享到朋友圈的图片
+	go cygxService.UpdateIndustrialsourceHzResourceDataById(industryId, "Yx") //修改相关产业关联的报告信息
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "操作成功"
@@ -411,6 +424,18 @@ func (this *SummaryManage) PublishAndCancel() {
 	}
 	go elastic.AddComprehensiveArticle(articleId)            // ES添加文章:报告、纪要
 	go cygxService.UpdateArticleResourceData(item.ArticleId) //写入首页最新  cygx_resource_data 表
+
+	detailIndustryNameList, err := cygx.GetIndustrialManagemenDetailByAaticleID(articleId)
+	if err != nil {
+		br.Msg = "分类失败"
+		br.ErrMsg = "获取报告原有分类失败,Err:" + err.Error()
+		return
+	}
+	var industryId []string
+	for _, v := range detailIndustryNameList {
+		industryId = append(industryId, strconv.Itoa(v.IndustrialManagementId))
+	}
+	go cygxService.UpdateIndustrialsourceHzResourceDataById(industryId, "Yx") //修改相关产业关联的报告信息
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "操作成功"

+ 34 - 0
models/cygx/industrial_article_group_management.go

@@ -208,3 +208,37 @@ func GetSearchResourceList(userId int, condition string, startSize, pageSize int
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+// GetIndustrialManagementGroupArticleMaxPublishDateByHz 获取产业ID关联最新发布文章的发布时间(弘则资源包)
+func GetIndustrialManagementGroupArticleMaxPublishDateByHz(industrialManagementId int) (maxTime string, err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	sql := ` SELECT
+			MAX( a.publish_date ) AS max_time 
+		FROM
+			cygx_industrial_article_group_management AS m
+			INNER JOIN cygx_article AS a ON a.article_id = m.article_id 
+		WHERE
+			1 = 1 
+			AND m.industrial_management_id = ? 
+			AND a.publish_status = 1 
+			AND a.article_type_id = 0 `
+	err = o.Raw(sql, industrialManagementId).QueryRow(&maxTime)
+	return
+}
+
+// GetIndustrialManagementGroupArticleMaxPublishDateByYx 获取产业ID关联最新发布文章的发布时间(研选资源包)
+func GetIndustrialManagementGroupArticleMaxPublishDateByYx(industrialManagementId int) (maxTime string, err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	sql := `SELECT
+			MAX( a.publish_date ) AS max_time 
+		FROM
+			cygx_industrial_article_group_management AS m
+			INNER JOIN cygx_article AS a ON a.article_id = m.article_id 
+		WHERE
+			1 = 1 
+			AND m.industrial_management_id = ? 
+			AND a.publish_status = 1  
+			AND a.article_type_id > 0 `
+	err = o.Raw(sql, industrialManagementId).QueryRow(&maxTime)
+	return
+}

+ 108 - 0
services/cygx/resource_data.go

@@ -7,6 +7,7 @@ import (
 	"hongze/hz_crm_api/services/alarm_msg"
 	"hongze/hz_crm_api/utils"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -1289,6 +1290,113 @@ func UpdateAskserieVideoResourceData(sourceId int) {
 	return
 }
 
+//func init() {
+//	UpdateIndustrialsourceHzResourceData(731, "HZ")
+//}
+
+func UpdateIndustrialsourceHzResourceDataById(industrialManagementIds []string, sourceType string) {
+	for _, v := range industrialManagementIds {
+		if v == "" {
+			continue
+		}
+		industrialManagementId, _ := strconv.Atoi(v)
+		if industrialManagementId < 1 {
+			continue
+		}
+		UpdateIndustrialsourceHzResourceData(industrialManagementId, sourceType)
+	}
+
+}
+
+// 更新产业资源包  写入首页最新  cygx_resource_data 表
+func UpdateIndustrialsourceHzResourceData(sourceId int, sourceType string) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go alarm_msg.SendAlarmMsg(fmt.Sprint("UpdateIndustrialsourceHzResourceData 失败: ", sourceId, err.Error()), 2)
+		}
+	}()
+	var source string
+	var e error
+	var maxData string
+	if sourceType == "Hz" {
+		maxData, e = cygx.GetIndustrialManagementGroupArticleMaxPublishDateByHz(sourceId)
+		if e != nil {
+			err = errors.New("GetIndustrialManagementGroupArticleMaxPublishDateByHz, Err: " + e.Error())
+			return
+		}
+		source = "industrialsourceHz"
+	} else {
+		maxData, e = cygx.GetIndustrialManagementGroupArticleMaxPublishDateByYx(sourceId)
+		if e != nil {
+			err = errors.New("GetIndustrialManagementGroupArticleMaxPublishDateByYx, Err: " + e.Error())
+			return
+		}
+		source = "industrialsourceYx"
+	}
+
+	if maxData == "" {
+		e = cygx.DeleteResourceData(sourceId, source)
+		if e != nil {
+			err = errors.New("DeleteResourceData, Err: " + e.Error())
+			return
+		}
+	}
+
+	industrialItem, e := cygx.GetIndustrialManagementInfo(sourceId)
+	if e != nil {
+		err = errors.New("GetIndustrialManagementInfo, Err: " + e.Error())
+		return
+	}
+
+	var subjectNames []string
+	listSub, e := cygx.GetcygxIndustrialSubject(sourceId)
+	if e != nil {
+		err = errors.New("GetcygxIndustrialSubject, Err: " + e.Error())
+		return
+	}
+	for _, v := range listSub {
+		subjectNames = append(subjectNames, v.SubjectName)
+	}
+
+	//判断是否存在,如果不存在就新增,存在就更新
+	totalData, e := cygx.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
+	if e != nil {
+		err = errors.New("GetCygxResourceDataBySourceAndIdCount, Err: " + e.Error())
+		return
+	}
+
+	item := new(cygx.CygxResourceData)
+	item.SourceId = sourceId
+	item.Source = source
+	item.PublishDate = maxData
+	item.CreateTime = time.Now()
+	if len(subjectNames) == 0 {
+		item.SearchTitle = industrialItem.IndustryName
+	} else {
+		item.SearchTitle = industrialItem.IndustryName + "," + strings.Join(subjectNames, ",")
+	}
+	item.SearchContent = ""
+	item.SearchOrderTime = maxData
+	//fmt.Println(item)
+	//return
+	if totalData == 0 {
+		_, e := cygx.AddCygxResourceData(item)
+		if e != nil {
+			err = errors.New("AddCygxResourceData, Err: " + e.Error())
+			return
+		}
+	} else {
+		e = cygx.UpdateResourceDataByItem(item)
+		if e != nil {
+			err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
+			return
+		}
+	}
+	return
+}
+
 func init300() {
 	//var condition string
 	//var pars []interface{}

+ 1 - 1
services/elastic/es_comprehensive.go

@@ -578,7 +578,7 @@ func AddComprehensiveIndustrialSource(sourceType string, articleId int) {
 		item.SubjectNames = strings.Join(mapActivitySubject[v.IndustrialManagementId], ",")
 		item.PublishDate = v.PublishDate + " 00:00:00"
 		EsAddOrEditComprehensiveData(item)
-		UpdateComprehensiveIndustrialResourceData(item)
+		//UpdateComprehensiveIndustrialResourceData(item)
 	}
 }