瀏覽代碼

Merge branch 'master' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai 5 月之前
父節點
當前提交
19b7ffd6da
共有 4 個文件被更改,包括 93 次插入85 次删除
  1. 85 81
      services/ficc_report.go
  2. 4 2
      services/resource_data.go
  3. 2 2
      services/tag.go
  4. 2 0
      services/task.go

+ 85 - 81
services/ficc_report.go

@@ -2,6 +2,7 @@ package services
 
 //FICC研报
 import (
+	"context"
 	"errors"
 	"fmt"
 	"hongze/hongze_cygx/models"
@@ -431,107 +432,109 @@ func GetChapterListByReportChapterIdList(classifyNameFirst string, reportId int,
 //}
 
 // 获取FICC研报到查研观向数据库中
-func GetFiccRreportToCygxArticle() (err error) {
+func GetFiccRreportToCygxArticle(cont context.Context) (err error) {
 	defer func() {
 		if err != nil {
 			fmt.Println(err)
-			go utils.SendAlarmMsg(fmt.Sprint("自动取消十分钟之内没有付款的的订单 CancelCygxOrder ,err:", err.Error()), 2)
+			go utils.SendAlarmMsg(fmt.Sprint("获取FICC研报到查研观向数据库中定时任务失败 ,err:", err.Error()), 2)
 		}
 	}()
 	var condition string
 	var pars []interface{}
-	//modifyTime := time.Now().Add(-10 * time.Minute)
-	//condition = `  AND modify_time >= ?   `
-	//pars = append(pars, modifyTime)
+	modifyTime := time.Now().Add(-10 * time.Minute)
+	condition = `  AND modify_time >= ?   `
+	pars = append(pars, modifyTime)
 	reportList, e := ficc_report.GetFiccRreportToCygxArticle(condition, pars)
 	if e != nil {
 		err = errors.New("GetFiccRreportToCygxArticle, Err: " + e.Error())
 		return
 	}
 	fmt.Println(len(reportList))
-	if len(reportList) == 0 {
-		return
-	}
+	//if len(reportList) == 0 {
+	//	return
+	//}
 
-	var reportIds []int
-	for _, v := range reportList {
-		reportIds = append(reportIds, v.Id)
-	}
-	listFiccReport, e := models.GetCygxCygxArticleListByReportIds(reportIds)
-	if e != nil {
-		err = errors.New("GetCygxCygxArticleListByReportIds, Err: " + e.Error())
-		return
-	}
-	mapFiccReport := make(map[int]int)
-	for _, v := range listFiccReport {
-		mapFiccReport[v.ReportId] = v.ArticleId
-	}
-
-	//量不大,先这么写吧
-	for _, v := range reportList {
-		time.Sleep(1 * time.Millisecond) // 延时一秒
-		item := new(models.CygxArticle)
-		item.ReportId = v.Id
-		item.PublishDate = v.PublishTime.Format(utils.FormatDateTime)
-		item.Title = v.Title
-		item.Body = v.Content
-		item.Abstract = v.Abstract
-		item.CreateDate = time.Now().Format(utils.FormatDate)
-		item.PublishStatus = 1
-		item.IsReport = 1
-		item.IsClass = 1
-
-		if (v.ClassifyNameFirst == "宏观报告" && v.ClassifyNameSecond == "大类资产周报") || (v.ClassifyNameFirst == "晨会纪要" && v.ClassifyNameSecond == "晨会纪要") || (v.ClassifyNameFirst == "调研纪要" && v.ClassifyNameSecond == "黑色调研") {
-			item.SubCategoryName = v.ClassifyNameSecond
-			item.MatchTypeName = v.ClassifyNameSecond
-		} else {
-			continue
+	if len(reportList) > 0 {
+		var reportIds []int
+		for _, v := range reportList {
+			reportIds = append(reportIds, v.Id)
 		}
-		detailCategory, detailCategoryErr := models.GetCygxReportMappingCelueDetailByZhoQiCategoryName(item.SubCategoryName)
-		if detailCategoryErr != nil {
-			continue
+		listFiccReport, e := models.GetCygxCygxArticleListByReportIds(reportIds)
+		if e != nil {
+			err = errors.New("GetCygxCygxArticleListByReportIds, Err: " + e.Error())
+			return
 		}
-		item.CategoryId = detailCategory.CategoryId
-		item.CategoryIdTwo = detailCategory.CategoryId
-		var articleIdMax int
-		//如果不存在就新增
-		if mapFiccReport[v.Id] == 0 {
-			maxArticleIdArticleInfo, e := models.GetMaxArticleIdInfo()
-			if e != nil {
-				err = errors.New("GetMaxArticleIdInfo, Err: " + e.Error())
-				return
+		mapFiccReport := make(map[int]int)
+		for _, v := range listFiccReport {
+			mapFiccReport[v.ReportId] = v.ArticleId
+		}
+
+		//量不大,先这么写吧
+		for _, v := range reportList {
+			time.Sleep(1 * time.Millisecond) // 延时一秒
+			item := new(models.CygxArticle)
+			item.ReportId = v.Id
+			item.PublishDate = v.PublishTime.Format(utils.FormatDateTime)
+			item.Title = v.Title
+			item.Body = v.Content
+			item.Abstract = v.Abstract
+			item.CreateDate = time.Now().Format(utils.FormatDate)
+			item.PublishStatus = 1
+			item.IsReport = 1
+			item.IsClass = 1
+
+			if (v.ClassifyNameFirst == "宏观报告" && v.ClassifyNameSecond == "大类资产周报") || (v.ClassifyNameFirst == "晨会纪要" && v.ClassifyNameSecond == "晨会纪要") || (v.ClassifyNameFirst == "调研纪要" && v.ClassifyNameSecond == "黑色调研") {
+				item.SubCategoryName = v.ClassifyNameSecond
+				item.MatchTypeName = v.ClassifyNameSecond
+			} else {
+				continue
 			}
-			articleIdMax = maxArticleIdArticleInfo.ArticleId + 1
-			item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdMax))
-			item.ArticleId = articleIdMax
-			_, e = models.AddCygxArticles(item)
-			if e != nil {
-				err = errors.New("AddCygxArticles, Err: " + e.Error())
-				return
+			detailCategory, detailCategoryErr := models.GetCygxReportMappingCelueDetailByZhoQiCategoryName(item.SubCategoryName)
+			if detailCategoryErr != nil {
+				continue
 			}
-		} else {
-			articleIdMax = mapFiccReport[v.Id]
-			item.ArticleId = mapFiccReport[v.Id]
-			updateParams := make(map[string]interface{})
-			updateParams["Title"] = item.Title
-			updateParams["PublishDate"] = item.PublishDate
-			updateParams["Body"] = item.Body
-			updateParams["Abstract"] = item.Abstract
-			updateParams["PublishStatus"] = item.PublishStatus
-			updateParams["SubCategoryName"] = item.SubCategoryName
-			updateParams["MatchTypeName"] = item.MatchTypeName
-			updateParams["CategoryId"] = item.CategoryId
-			updateParams["CategoryIdTwo"] = item.CategoryIdTwo
-			whereParam := map[string]interface{}{"article_id": item.ArticleId}
-			err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
-			if err != nil {
-				fmt.Println("UpdateByExpr Err:" + err.Error())
-				return err
+			item.CategoryId = detailCategory.CategoryId
+			item.CategoryIdTwo = detailCategory.CategoryId
+			var articleIdMax int
+			//如果不存在就新增
+			if mapFiccReport[v.Id] == 0 {
+				maxArticleIdArticleInfo, e := models.GetMaxArticleIdInfo()
+				if e != nil {
+					err = errors.New("GetMaxArticleIdInfo, Err: " + e.Error())
+					return
+				}
+				articleIdMax = maxArticleIdArticleInfo.ArticleId + 1
+				item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdMax))
+				item.ArticleId = articleIdMax
+				_, e = models.AddCygxArticles(item)
+				if e != nil {
+					err = errors.New("AddCygxArticles, Err: " + e.Error())
+					return
+				}
+			} else {
+				articleIdMax = mapFiccReport[v.Id]
+				item.ArticleId = mapFiccReport[v.Id]
+				updateParams := make(map[string]interface{})
+				updateParams["Title"] = item.Title
+				updateParams["PublishDate"] = item.PublishDate
+				updateParams["Body"] = item.Body
+				updateParams["Abstract"] = item.Abstract
+				updateParams["PublishStatus"] = item.PublishStatus
+				updateParams["SubCategoryName"] = item.SubCategoryName
+				updateParams["MatchTypeName"] = item.MatchTypeName
+				updateParams["CategoryId"] = item.CategoryId
+				updateParams["CategoryIdTwo"] = item.CategoryIdTwo
+				whereParam := map[string]interface{}{"article_id": item.ArticleId}
+				err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
+				if err != nil {
+					fmt.Println("UpdateByExpr Err:" + err.Error())
+					return err
+				}
 			}
-		}
-		UpdateFICCReportResourceData(v.Id)
+			UpdateFICCReportResourceData(v.Id)
 
-		AddCygxReportMappingCategoryGroupByArticleId(articleIdMax)
+			AddCygxReportMappingCategoryGroupByArticleId(articleIdMax)
+		}
 	}
 
 	//获取已经同步到查研的FICC研报 对比,如果FICC研报已经取消发布,查研也做对应的删除
@@ -549,6 +552,7 @@ func GetFiccRreportToCygxArticle() (err error) {
 		return
 	}
 	condition = ` AND id IN (` + utils.GetOrmInReplace(lenArr) + `) `
+	pars = make([]interface{}, 0)
 	pars = append(pars, cygxFiccReportIds)
 	ficcReportListPush, e := ficc_report.GetFiccRreportToCygxArticle(condition, pars)
 	if e != nil {

+ 4 - 2
services/resource_data.go

@@ -1059,12 +1059,14 @@ func UpdateFICCReportResourceData(sourceId int) {
 			}
 			resourceDataId = int(newId)
 		} else {
-			e = models.UpdateResourceDataByItem(item)
+			sourceDetail, e := models.GetCygxResourceDataByIdAndSource(sourceId, source)
 			if e != nil {
 				err = errors.New("UpdateResourceData, Err: " + e.Error())
 				return
 			}
-			sourceDetail, e := models.GetCygxResourceDataByIdAndSource(sourceId, source)
+			item.PublishDate = sourceDetail.PublishDate
+			item.SearchOrderTime = sourceDetail.SearchOrderTime
+			e = models.UpdateResourceDataByItem(item)
 			if e != nil {
 				err = errors.New("UpdateResourceData, Err: " + e.Error())
 				return

+ 2 - 2
services/tag.go

@@ -182,7 +182,7 @@ func GetConditionInitByTagIds(tagIds string, chartPermissionId int) (conditionIn
 				resourceDataIdStrs = append(resourceDataIdStrs, strconv.Itoa(v))
 				resourceDataIdMap[v] = true
 			}
-			conditionInit += " AND id IN  (" + strings.Join(resourceDataIdStrs, ",") + ") "
+			conditionInit += " AND id IN  (" + strings.Join(resourceDataIdStrs, ",") + ")   OR IF   ( source IN ('ficcreport') , search_tag IN ('黑色调研')  ,1=1 ) "
 		}
 	case 1: // 热门活动
 		conf, e := models.GetConfigByCode(utils.CYGX_TAG_HOT_ACTIVITY_ID)
@@ -270,7 +270,7 @@ func GetConditionInitByTagIds(tagIds string, chartPermissionId int) (conditionIn
 		for _, v := range articleList {
 			articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
 		}
-		conditionInit = "  AND source_id IN ( " + strings.Join(articleIds, ",") + ")  AND source = '" + utils.CYGX_OBJ_ARTICLE + "'"
+		conditionInit = "  AND source_id IN ( " + strings.Join(articleIds, ",") + ")  AND source = '" + utils.CYGX_OBJ_ARTICLE + "' OR IF   ( source IN ('ficcreport') , search_tag IN ('晨会纪要','大类资产周报')  ,1=1 )"
 	}
 
 	return

+ 2 - 0
services/task.go

@@ -162,6 +162,8 @@ func Task() {
 		getYanxuanSpecialLikeCountDifferent := task.NewTask("getYanxuanSpecialLikeCountDifferent", "0 0 */1 * * *", GetYanxuanSpecialLikeCountDifferent)
 		task.AddTask("定时任务处理退款回调", getYanxuanSpecialLikeCountDifferent) // 专栏文章获得点赞时,模板消息通知作者(每个整点发送,不同文章分多条发送)
 
+		getFiccRreportToCygxArticle := task.NewTask("getFiccRreportToCygxArticle", "0 */10 * * * *", GetFiccRreportToCygxArticle)
+		task.AddTask("获取FICC研报到查研观向数据库中", getFiccRreportToCygxArticle) //获取FICC研报到查研观向数据库中
 	}
 
 	//UpdateRaiServeBillDate()