xingzai 2 سال پیش
والد
کامیت
b1654daed6
4فایلهای تغییر یافته به همراه79 افزوده شده و 0 حذف شده
  1. 40 0
      models/resource_data.go
  2. 4 0
      services/article.go
  3. 4 0
      services/chart.go
  4. 31 0
      services/resource_data.go

+ 40 - 0
models/resource_data.go

@@ -0,0 +1,40 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxResourceData struct {
+	Id          int       `orm:"column(id);pk"`
+	SourceId    int       `description:"资源ID"`
+	Source      string    `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
+	Title       string    `description:"标题"`
+	Annotation  string    `description:"核心观点"`
+	CreateTime  time.Time `description:"创建时间"`
+	PublishDate string    `description:"发布时间"`
+	Abstract    string    `description:"摘要"`
+}
+
+//添加
+func AddCygxResourceData(item *CygxResourceData) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+//删除数据
+func DeleteResourceData(sourceId int, source string) (err error) {
+	o := orm.NewOrm()
+	sql := ` DELETE FROM cygx_resource_data WHERE source_id = ? AND source =?  `
+	_, err = o.Raw(sql, sourceId, source).Exec()
+	return
+}
+
+//修改数据
+func UpdateResourceData(sourceId int, source, publishDate string) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_resource_data SET publish_date=?  WHERE source_id=?  AND source =? `
+	_, err = o.Raw(sql, publishDate, sourceId, source).Exec()
+	return
+}

+ 4 - 0
services/article.go

@@ -805,6 +805,8 @@ func HandleArticleListByApi(artcleId int) (err error) {
 			fmt.Println("UpdateArticlePublish Err:", err.Error())
 			return err
 		}
+
+		go UpdateResourceData(artcleId, "article", "delete", time.Now().Format(utils.FormatDateTime))
 		go models.UpdateCygxArticleCeluePush(artcleId)
 		return err
 	}
@@ -932,6 +934,7 @@ func HandleArticleListByApi(artcleId int) (err error) {
 				//fmt.Println("触发推送规则")
 				//更新字数大于一百字触发推送规则
 				go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
+				go UpdateResourceData(v.ArticleId, "article", "update", time.Now().Format(utils.FormatDateTime))
 			}
 			var isCustom bool
 			updateParams := make(map[string]interface{})
@@ -1021,6 +1024,7 @@ func HandleArticleListByApi(artcleId int) (err error) {
 				fmt.Println("AddCygxArticle Err:", err.Error())
 				return err
 			}
+			go UpdateResourceData(v.ArticleId, "article", "add", time.Now().Format(utils.FormatDateTime))
 			//fmt.Println(newId)
 			//报告自动归类,以及推送相关模板消息
 			if v.ReportType == 2 {

+ 4 - 0
services/chart.go

@@ -99,6 +99,9 @@ func GetChartListByApi(cont context.Context) (err error) {
 		//如果没有就新增 有就更新
 		if mapChartid[v.ChartId] == 0 {
 			_, err := models.AddCygxChart(item)
+			if item.PublishStatus == 1 {
+				go UpdateResourceData(item.ChartId, "newchart", "add", time.Now().Format(utils.FormatDateTime))
+			}
 			if err != nil {
 				return err
 			}
@@ -124,6 +127,7 @@ func GetChartListByApi(cont context.Context) (err error) {
 				return err
 			}
 		}
+
 	}
 
 	//策略平台图表,记录所有,的显示用户收藏使用

+ 31 - 0
services/resource_data.go

@@ -0,0 +1,31 @@
+package services
+
+import (
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"strconv"
+	"time"
+)
+
+//同步活动到最新数据表
+func UpdateResourceData(sourceId int, source, doType, publishDate string) (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("同步到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId)+"资源类型"+source+"操作方式"+doType, 3)
+		}
+	}()
+	if doType == "add" {
+		item := new(models.CygxResourceData)
+		item.SourceId = sourceId
+		item.Source = source
+		item.PublishDate = publishDate
+		item.CreateTime = time.Now()
+		_, err = models.AddCygxResourceData(item)
+	} else if doType == "delete" {
+		err = models.DeleteResourceData(sourceId, source)
+	} else if doType == "update" {
+		err = models.UpdateResourceData(sourceId, source, publishDate)
+	}
+	return
+
+}