Browse Source

no message

xingzai 1 year ago
parent
commit
5d27263571

+ 3 - 0
controllers/cygx/yanxuan_special.go

@@ -6,6 +6,7 @@ import (
 	"hongze/hz_crm_api/models"
 	"hongze/hz_crm_api/models/cygx"
 	cygxService "hongze/hz_crm_api/services/cygx"
+	"hongze/hz_crm_api/services/elastic"
 	"hongze/hz_crm_api/utils"
 	"strconv"
 	"time"
@@ -286,6 +287,8 @@ func (this *YanxuanSpecialController) Enable() {
 	if req.Status == 1 {
 		go cygxService.SendWxMsgSpecialFollow(req.Id)
 	}
+	go cygxService.UpdateYanxuanSpecialResourceData(req.Id) //  写入首页最新  cygx_resource_data 表
+	go elastic.EsAddYanxuanSpecial(req.Id)                  //  写入es 综合搜索
 	br.Msg = "审批成功"
 	br.Ret = 200
 	br.Success = true

+ 11 - 0
models/cygx/cygx_yanxuan_special.go

@@ -138,3 +138,14 @@ JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
 	err = o.Raw(sql, specialId).QueryRow(&item)
 	return
 }
+
+// 获取数量
+func GetCygxYanxuanSpecialCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}

+ 8 - 0
models/cygx/resource_data.go

@@ -82,3 +82,11 @@ func GetCygxResourceDataByIdAndSource(sourceId int, source string) (item *CygxRe
 	err = o.Raw(sql, sourceId, source).QueryRow(&item)
 	return
 }
+
+// 获取数量
+func GetCygxResourceDataBySourceAndIdCount(sourceId int, source string) (count int, err error) {
+	o := orm.NewOrm()
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_resource_data  WHERE  source_id = ? AND source =?  `
+	err = o.Raw(sqlCount, sourceId, source).QueryRow(&count)
+	return
+}

+ 66 - 0
services/cygx/yanxuan_special.go

@@ -0,0 +1,66 @@
+package cygx
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hz_crm_api/models/cygx"
+	"hongze/hz_crm_api/services/alarm_msg"
+	"hongze/hz_crm_api/utils"
+	"time"
+)
+
+// 更新研选专栏  写入首页最新  cygx_resource_data 表
+func UpdateYanxuanSpecialResourceData(sourceId int) {
+	var err error
+	defer func() {
+		if err != nil {
+			go alarm_msg.SendAlarmMsg(fmt.Sprint("更新研选专栏失败ourceId: ", sourceId), 2)
+		}
+	}()
+	var source = utils.CYGX_OBJ_YANXUANSPECIAL
+	var condition string
+	var pars []interface{}
+	condition = ` AND status = 3  AND  id = ?  `
+	pars = append(pars, sourceId)
+	total, e := cygx.GetCygxYanxuanSpecialCount(condition, pars)
+
+	if e != nil {
+		err = errors.New("GetCygxYanxuanSpecialCount, Err: " + e.Error())
+		return
+	}
+	//如果取消发布了就做删除处理
+	if total == 0 {
+		e = cygx.DeleteResourceData(sourceId, source)
+		if e != nil {
+			err = errors.New("DeleteResourceData, Err: " + e.Error())
+			return
+		}
+	} else {
+		//判断是否存在,如果不存在就新增,存在就更新
+		totalData, e := cygx.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
+		if e != nil {
+			err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
+			return
+		}
+		publishDate := time.Now().Format(utils.FormatDateTime)
+		item := new(cygx.CygxResourceData)
+		item.SourceId = sourceId
+		item.Source = source
+		item.PublishDate = publishDate
+		item.CreateTime = time.Now()
+		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
+}

+ 35 - 0
services/elastic/es_comprehensive.go

@@ -536,3 +536,38 @@ func AddComprehensiveIndustrialSource(sourceType string, articleId int) {
 		EsAddOrEditComprehensiveData(item)
 	}
 }
+
+// Es研选专栏
+func EsAddYanxuanSpecial(sourceId int) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err)
+			go alarm_msg.SendAlarmMsg(fmt.Sprint("更新研选专栏失败sourceId: ", sourceId), 2)
+		}
+	}()
+	detail, e := cygx.GetYanxuanSpecialItemById(sourceId)
+	if e != nil {
+		err = errors.New("GetArticleInfoOtherByArticleId" + e.Error())
+		return
+	}
+	content := html.UnescapeString(detail.Content)
+	doc, e := goquery.NewDocumentFromReader(strings.NewReader(content))
+	if e != nil {
+		err = errors.New("goquery.NewDocumentFromReader" + e.Error())
+		return
+	}
+	bodyText := doc.Text()
+	item := new(ElasticComprehensiveDetail)
+	item.SourceId = detail.Id
+	item.Source = utils.CYGX_OBJ_YANXUANSPECIAL
+	item.Title = detail.Title
+	item.PublishDate = detail.PublishTime
+	item.BodyText = bodyText
+	if detail.Status == 3 {
+		EsAddOrEditComprehensiveData(item) //如果发布了就新增
+	} else {
+		EsDeleteComprehensiveData(item) // 没有发布就删除
+	}
+	return
+}

+ 1 - 0
utils/constants.go

@@ -421,6 +421,7 @@ const (
 	CYGX_OBJ_PRODUCTINTERIOR    string = "productinterior"    // 对象类型:产品内测
 	CYGX_OBJ_RESEARCHSUMMARY    string = "researchsummary"    // 对象类型:本周研究汇总
 	CYGX_OBJ_MINUTESSUMMARY     string = "minutessummary"     // 对象类型:本周研究汇总
+	CYGX_OBJ_YANXUANSPECIAL     string = "yanxuanspecial"     // 对象类型:研选专栏
 )
 
 const (