|
@@ -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 {
|