|
@@ -321,12 +321,35 @@ func SyncETAReportList(list []eta.ETAReport) (err error) {
|
|
logger.Info("同步研报数量%d", len(list))
|
|
logger.Info("同步研报数量%d", len(list))
|
|
var reports []reportDao.Report
|
|
var reports []reportDao.Report
|
|
for _, etaRp := range list {
|
|
for _, etaRp := range list {
|
|
|
|
+ var coverSrc int
|
|
|
|
+ var permissions []etaDao.ChartPermission
|
|
|
|
+ permissions, err = etaDao.GetSecondPermissionsByClassifyID(etaRp.ClassifyID)
|
|
|
|
+ if err != nil || len(permissions) == 0 {
|
|
|
|
+ logger.Error("获取研报二级品种信息失败:%v", err)
|
|
|
|
+ coverSrc = 0
|
|
|
|
+ } else {
|
|
|
|
+ permissionsId := permissions[0].ChartPermissionID
|
|
|
|
+ var ids []int
|
|
|
|
+ ids, err = mediaDao.GetIdsByPermissionId(permissionsId)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.Error("获取图片资源失败:%v", err)
|
|
|
|
+ }
|
|
|
|
+ if ids == nil || len(ids) == 0 {
|
|
|
|
+ coverSrc = 0
|
|
|
|
+ } else {
|
|
|
|
+ src := rand.NewSource(time.Now().UnixNano())
|
|
|
|
+ r := rand.New(src)
|
|
|
|
+ // 从切片中随机选择一个元素
|
|
|
|
+ randomIndex := r.Intn(len(ids))
|
|
|
|
+ coverSrc = ids[randomIndex]
|
|
|
|
+ }
|
|
|
|
+ }
|
|
//authorNames := strings.Split(etaRp.Author, ",")
|
|
//authorNames := strings.Split(etaRp.Author, ",")
|
|
//authorNamesWithOutEmpty := stringUtils.RemoveEmptyStrings(authorNames)
|
|
//authorNamesWithOutEmpty := stringUtils.RemoveEmptyStrings(authorNames)
|
|
//for _, authorName := range authorNamesWithOutEmpty {
|
|
//for _, authorName := range authorNamesWithOutEmpty {
|
|
status := etaStatus(etaRp.State)
|
|
status := etaStatus(etaRp.State)
|
|
destRp := convertEtaReport(etaRp, status)
|
|
destRp := convertEtaReport(etaRp, status)
|
|
- //destRp.Author = authorName
|
|
|
|
|
|
+ destRp.CoverSrc = coverSrc
|
|
reports = append(reports, destRp)
|
|
reports = append(reports, destRp)
|
|
}
|
|
}
|
|
//}
|
|
//}
|
|
@@ -353,18 +376,40 @@ func syncESAndSendMessage(reports []reportDao.Report) (err error) {
|
|
}
|
|
}
|
|
//同步es
|
|
//同步es
|
|
for _, report := range reports {
|
|
for _, report := range reports {
|
|
- update := UpdateESReport{
|
|
|
|
- Title: report.Title,
|
|
|
|
- Author: report.Author,
|
|
|
|
- PublishedTime: report.PublishedTime,
|
|
|
|
- Abstract: report.Abstract,
|
|
|
|
- Status: string(report.Status),
|
|
|
|
|
|
+ var exist bool
|
|
|
|
+ exist, err = elastic().Exist(report.ID)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.Error("查询es失败,reportId::%d,err:%v", report.ID, err)
|
|
}
|
|
}
|
|
- success := elastic().Update(htConfig.GetReportIndex(), report.ID, update)
|
|
|
|
- if !success {
|
|
|
|
- logger.Error("更新es失败,reportId::%d,err:%v", report.ID, err)
|
|
|
|
|
|
+ if exist {
|
|
|
|
+ update := UpdateESReport{
|
|
|
|
+ Title: report.Title,
|
|
|
|
+ Author: report.Author,
|
|
|
|
+ PublishedTime: report.PublishedTime,
|
|
|
|
+ Abstract: report.Abstract,
|
|
|
|
+ Status: string(report.Status),
|
|
|
|
+ }
|
|
|
|
+ success := elastic().Update(htConfig.GetReportIndex(), report.ID, update)
|
|
|
|
+ if !success {
|
|
|
|
+ logger.Error("更新es失败,reportId::%d,err:%v", report.ID, err)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ insert := ESReport{
|
|
|
|
+ ReportID: report.ID,
|
|
|
|
+ OrgId: report.OrgID,
|
|
|
|
+ Title: report.Title,
|
|
|
|
+ Author: report.Author,
|
|
|
|
+ Source: report.Source,
|
|
|
|
+ Abstract: report.Abstract,
|
|
|
|
+ CoverSrc: report.CoverSrc,
|
|
|
|
+ Status: report.Status,
|
|
|
|
+ PublishedTime: report.PublishedTime,
|
|
|
|
+ }
|
|
|
|
+ success := elastic().CreateDocument(htConfig.GetReportIndex(), report.ID, insert)
|
|
|
|
+ if !success {
|
|
|
|
+ logger.Error("创建es文档失败,reportId::%d,err:%v", report.ID, err)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
//err = elastic().BulkInsert(htConfig.GetReportIndex(), esReports)
|
|
//err = elastic().BulkInsert(htConfig.GetReportIndex(), esReports)
|