|
@@ -2,8 +2,10 @@ package report
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
+ "eta/eta_mini_ht_api/common/component/config"
|
|
|
"eta/eta_mini_ht_api/common/component/es"
|
|
|
logger "eta/eta_mini_ht_api/common/component/log"
|
|
|
+ "eta/eta_mini_ht_api/common/contants"
|
|
|
"eta/eta_mini_ht_api/common/utils/page"
|
|
|
stringUtils "eta/eta_mini_ht_api/common/utils/string"
|
|
|
analystService "eta/eta_mini_ht_api/domian/financial_analyst"
|
|
@@ -25,13 +27,13 @@ const (
|
|
|
DESC models.Order = "desc"
|
|
|
ASC models.Order = "asc"
|
|
|
|
|
|
- ESIndex = "report_index"
|
|
|
ESColumn = "title"
|
|
|
ESRangeColumn = "reportId"
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
sortField = []string{"_score:desc"}
|
|
|
+ htConfig = config.GetConfig(contants.HT).(*config.HTBizConfig)
|
|
|
)
|
|
|
|
|
|
func elastic() *es.ESClient {
|
|
@@ -234,13 +236,16 @@ func (es ESReport) GetId() string {
|
|
|
return strconv.Itoa(es.ReportID)
|
|
|
}
|
|
|
func GetETALatestReportId() (id int, err error) {
|
|
|
- return reportDao.GetETALatestReportId()
|
|
|
+ return reportDao.GetLatestReportIdBySource(reportDao.SourceETA)
|
|
|
+}
|
|
|
+
|
|
|
+func GetHTLatestReportId() (id int, err error) {
|
|
|
+ return reportDao.GetLatestReportIdBySource(reportDao.SourceHT)
|
|
|
}
|
|
|
|
|
|
func SyncETAReportList(list []eta.ETAReport) (err error) {
|
|
|
logger.Info("同步研报数量%d", len(list))
|
|
|
var reports []reportDao.Report
|
|
|
- var esReports []es.ESBase
|
|
|
for _, etaRp := range list {
|
|
|
authorNames := strings.Split(etaRp.Author, ",")
|
|
|
authorNamesWithOutEmpty := stringUtils.RemoveEmptyStrings(authorNames)
|
|
@@ -255,12 +260,63 @@ func SyncETAReportList(list []eta.ETAReport) (err error) {
|
|
|
logger.Error("同步ETA研报失败:%v", err)
|
|
|
return
|
|
|
}
|
|
|
+ //for _, etaRp := range reports {
|
|
|
+ // esRp := convertEsReport(etaRp)
|
|
|
+ // esReports = append(esReports, esRp)
|
|
|
+ //}
|
|
|
+ return syncESAndSendMessage(reports)
|
|
|
+ ////同步es
|
|
|
+ //err = elastic().BulkInsert(htConfig.GetReportIndex(), esReports)
|
|
|
+ //if err != nil {
|
|
|
+ // logger.Error("同步ETA研报到es失败:%v", err)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ ////生产meta信息
|
|
|
+ //logger.Info("生成推送META信息")
|
|
|
+ //for _, report := range reports {
|
|
|
+ // userIds := userService.GetPostUser(report.Author, report.PublishedTime)
|
|
|
+ // var author analystService.FinancialAnalystDTO
|
|
|
+ // author, err = analystService.GetAnalystByName(report.Author)
|
|
|
+ // if err != nil {
|
|
|
+ // logger.Error("获取研报作者失败:%v", err)
|
|
|
+ // continue
|
|
|
+ // }
|
|
|
+ // if len(userIds) > 0 {
|
|
|
+ // usersStr := stringUtils.IntToStringSlice(userIds)
|
|
|
+ // Meta := userService.MetaData{
|
|
|
+ // AuthorName: report.Author,
|
|
|
+ // AuthorId: author.Id,
|
|
|
+ // SourceId: report.ID,
|
|
|
+ // PublishedTime: report.PublishedTime,
|
|
|
+ // }
|
|
|
+ // metaStr, _ := json.Marshal(Meta)
|
|
|
+ // toStr := strings.Join(usersStr, ",")
|
|
|
+ // UUID := uuid.New()
|
|
|
+ // uuidStr := UUID.String()
|
|
|
+ // metaContent := userService.MetaInfoDTO{
|
|
|
+ // From: "ETA",
|
|
|
+ // Uid: "report:" + uuidStr,
|
|
|
+ // Meta: string(metaStr),
|
|
|
+ // MetaType: "USER_NOTICE",
|
|
|
+ // SourceType: "REPORT",
|
|
|
+ // To: toStr,
|
|
|
+ // }
|
|
|
+ // err = userService.CreateMetaInfo(metaContent)
|
|
|
+ // if err != nil {
|
|
|
+ // logger.Error("创建Meta信息失败:%v", err)
|
|
|
+ // return err
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+}
|
|
|
+func syncESAndSendMessage(reports []reportDao.Report) (err error) {
|
|
|
+ var esReports []es.ESBase
|
|
|
for _, etaRp := range reports {
|
|
|
esRp := convertEsReport(etaRp)
|
|
|
esReports = append(esReports, esRp)
|
|
|
}
|
|
|
//同步es
|
|
|
- err = elastic().BulkInsert(ESIndex, esReports)
|
|
|
+ err = elastic().BulkInsert(htConfig.GetReportIndex(), esReports)
|
|
|
if err != nil {
|
|
|
logger.Error("同步ETA研报到es失败:%v", err)
|
|
|
return
|
|
@@ -269,7 +325,12 @@ func SyncETAReportList(list []eta.ETAReport) (err error) {
|
|
|
logger.Info("生成推送META信息")
|
|
|
for _, report := range reports {
|
|
|
userIds := userService.GetPostUser(report.Author, report.PublishedTime)
|
|
|
- author, _ := analystService.GetAnalystByName(report.Author)
|
|
|
+ var author analystService.FinancialAnalystDTO
|
|
|
+ author, err = analystService.GetAnalystByName(report.Author)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取研报作者失败:%v", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
if len(userIds) > 0 {
|
|
|
usersStr := stringUtils.IntToStringSlice(userIds)
|
|
|
Meta := userService.MetaData{
|
|
@@ -283,7 +344,7 @@ func SyncETAReportList(list []eta.ETAReport) (err error) {
|
|
|
UUID := uuid.New()
|
|
|
uuidStr := UUID.String()
|
|
|
metaContent := userService.MetaInfoDTO{
|
|
|
- From: "ETA",
|
|
|
+ From: "HT",
|
|
|
Uid: "report:" + uuidStr,
|
|
|
Meta: string(metaStr),
|
|
|
MetaType: "USER_NOTICE",
|
|
@@ -296,11 +357,29 @@ func SyncETAReportList(list []eta.ETAReport) (err error) {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+func SyncHTReportList(list []eta.HTReport) (err error) {
|
|
|
+ logger.Info("同步研报数量%d", len(list))
|
|
|
+ var reports []reportDao.Report
|
|
|
|
|
|
+ for _, etaRp := range list {
|
|
|
+ authorNames := strings.Split(etaRp.Author, ",")
|
|
|
+ authorNamesWithOutEmpty := stringUtils.RemoveEmptyStrings(authorNames)
|
|
|
+ for _, authorName := range authorNamesWithOutEmpty {
|
|
|
+ destRp := convertHTReport(etaRp)
|
|
|
+ destRp.Author = authorName
|
|
|
+ reports = append(reports, destRp)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ err = reportDao.BatchInsertReport(&reports)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("同步HT研报失败:%v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return syncESAndSendMessage(reports)
|
|
|
+}
|
|
|
func GetListOrderByConditionWeekly(week bool, column string, limit int, order models.Order) (dtoList []ReportDTO, err error) {
|
|
|
reports, err := reportDao.GetListOrderByCondition(week, column, limit, order)
|
|
|
if err != nil {
|
|
@@ -352,6 +431,20 @@ func convertEtaReport(etaRp eta.ETAReport) reportDao.Report {
|
|
|
Author: etaRp.Author,
|
|
|
PublishedTime: etaRp.PublishTime,
|
|
|
Source: reportDao.SourceETA,
|
|
|
+ SendStatus: reportDao.UNSEND,
|
|
|
+ Status: reportDao.StatusInit,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func convertHTReport(etaRp eta.HTReport) reportDao.Report {
|
|
|
+ return reportDao.Report{
|
|
|
+ OrgID: etaRp.ID,
|
|
|
+ Title: etaRp.Title,
|
|
|
+ Abstract: etaRp.Abstract,
|
|
|
+ Author: etaRp.Author,
|
|
|
+ PublishedTime: etaRp.PublishTime,
|
|
|
+ Source: reportDao.SourceHT,
|
|
|
+ SendStatus: reportDao.UNSEND,
|
|
|
Status: reportDao.StatusInit,
|
|
|
}
|
|
|
}
|
|
@@ -388,13 +481,13 @@ func convertReportDTO(report reportDao.Report) (reportDTO ReportDTO) {
|
|
|
|
|
|
func matchAll(sorts []string, key string) (request *es.ESQueryRequest) {
|
|
|
req := new(es.ESQueryRequest)
|
|
|
- return req.CreateESQueryRequest(ESIndex, ESColumn, key, 0, 1, sorts, es.MatchAll)
|
|
|
+ return req.CreateESQueryRequest(htConfig.GetReportIndex(), ESColumn, key, 0, 1, sorts, es.MatchAll)
|
|
|
}
|
|
|
func match(key string, from int, to int, sorts []string) (request *es.ESQueryRequest) {
|
|
|
req := new(es.ESQueryRequest)
|
|
|
- return req.CreateESQueryRequest(ESIndex, ESColumn, key, from, to, sorts, es.Match)
|
|
|
+ return req.CreateESQueryRequest(htConfig.GetReportIndex(), ESColumn, key, from, to, sorts, es.Match)
|
|
|
}
|
|
|
func matchRange(key string, from int, to int, max int64, sorts []string) (request *es.ESQueryRequest) {
|
|
|
req := new(es.ESQueryRequest)
|
|
|
- return req.CreateESQueryRequest(ESIndex, ESColumn, key, from, to, sorts, es.Range).Range(0, max, ESRangeColumn)
|
|
|
+ return req.CreateESQueryRequest(htConfig.GetReportIndex(), ESColumn, key, from, to, sorts, es.Range).Range(0, max, ESRangeColumn)
|
|
|
}
|