Browse Source

最新数据更新

xingzai 2 years ago
parent
commit
5fb7e31253
5 changed files with 42 additions and 2 deletions
  1. 1 0
      models/db.go
  2. 11 0
      models/resource_data.go
  3. 1 1
      services/article.go
  4. 9 1
      services/chart.go
  5. 20 0
      services/resource_data.go

+ 1 - 0
models/db.go

@@ -128,6 +128,7 @@ func init() {
 		new(CygxActivitySpecialTrip),
 		new(CygxArticleData),
 		new(CygxArticleComment),
+		new(CygxResourceData),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 11 - 0
models/resource_data.go

@@ -38,3 +38,14 @@ func UpdateResourceData(sourceId int, source, publishDate string) (err error) {
 	_, err = o.Raw(sql, publishDate, sourceId, source).Exec()
 	return
 }
+
+//批量删除
+func DeleteResourceDataList(condition string, pars []interface{}) (err error) {
+	if condition == "" {
+		return
+	}
+	o := orm.NewOrm()
+	sql := `DELETE  FROM cygx_resource_data   WHERE  1=1 ` + condition
+	_, err = o.Raw(sql, pars).Exec()
+	return
+}

+ 1 - 1
services/article.go

@@ -673,7 +673,7 @@ func GetArticleListByApi(cont context.Context) (err error) {
 }
 
 //func init() {
-//	HandleArticleListByApi(5818)
+//	HandleArticleListByApi(7801)
 //}
 
 //处理同步过来的文章

+ 9 - 1
services/chart.go

@@ -64,7 +64,7 @@ func GetChartListByApi(cont context.Context) (err error) {
 	for _, v := range chartAllList {
 		mapAllChartid[v.ChartId] = v.ChartId
 	}
-
+	var chartIdsDelete []int
 	url := utils.ApiUrl + "charts/mp?take=100&skip=0"
 	authorization := utils.ApiAuthorization
 	body, err := PublicGetDate(url, authorization)
@@ -106,6 +106,9 @@ func GetChartListByApi(cont context.Context) (err error) {
 				return err
 			}
 		} else {
+			if item.PublishStatus == 0 {
+				chartIdsDelete = append(chartIdsDelete, item.ChartId)
+			}
 			updateParams := make(map[string]interface{})
 			updateParams["Title"] = v.Title
 			updateParams["PtagId"] = v.PtagId
@@ -130,6 +133,11 @@ func GetChartListByApi(cont context.Context) (err error) {
 
 	}
 
+	fmt.Println("删除的", chartIdsDelete)
+	if len(chartIdsDelete) > 0 {
+		go Deletenewchart(chartIdsDelete)
+	}
+
 	//策略平台图表,记录所有,的显示用户收藏使用
 	url = utils.ApiUrl + "charts?take=100&skip=0" // 获取所有的图表链接
 	body, err = PublicGetDate(url, authorization)

+ 20 - 0
services/resource_data.go

@@ -1,6 +1,7 @@
 package services
 
 import (
+	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
 	"strconv"
@@ -27,5 +28,24 @@ func UpdateResourceData(sourceId int, source, doType, publishDate string) (err e
 		err = models.UpdateResourceData(sourceId, source, publishDate)
 	}
 	return
+}
 
+//批量删除最新图表数据
+func Deletenewchart(chartIdsDelete []int) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("批量删除最新图表数据,Err:"+err.Error(), 3)
+		}
+	}()
+	lenchartIdsDelete := len(chartIdsDelete)
+	if lenchartIdsDelete == 0 {
+		return
+	}
+	var condition string
+	var pars []interface{}
+	condition += ` AND source = 'newchart' AND source_id IN (` + utils.GetOrmInReplace(lenchartIdsDelete) + `) `
+	pars = append(pars, chartIdsDelete)
+	err = models.DeleteResourceDataList(condition, pars)
+	return
 }