|
@@ -322,11 +322,18 @@ func SyncETAReportList(list []eta.ETAReport) (err error) {
|
|
|
reports = append(reports, destRp)
|
|
|
}
|
|
|
}
|
|
|
- err = reportDao.BatchInsertReport(&reports)
|
|
|
+ var ids []int
|
|
|
+ ids, err = reportDao.InsertOrUpdateReport(&reports, SourceETA)
|
|
|
if err != nil {
|
|
|
logger.Error("同步ETA研报失败:%v", err)
|
|
|
return
|
|
|
}
|
|
|
+ for _, id := range ids {
|
|
|
+ success := elastic().Delete(htConfig.GetReportIndex(), id)
|
|
|
+ if !success {
|
|
|
+ logger.Error("删除es失败,reportId::%d,err:%v", id, err)
|
|
|
+ }
|
|
|
+ }
|
|
|
return syncESAndSendMessage(reports)
|
|
|
}
|
|
|
func syncESAndSendMessage(reports []reportDao.Report) (err error) {
|
|
@@ -454,33 +461,69 @@ func InitHTReportList(list []ht.HTReport) (noRecord bool, err error) {
|
|
|
return false, syncES(reports)
|
|
|
}
|
|
|
}
|
|
|
-func SyncHTReportList(list []ht.HTReport) (err error) {
|
|
|
- //logger.Info("同步研报数量%d", len(list))
|
|
|
- //var reports []reportDao.Report
|
|
|
- //for _, htRp := range list {
|
|
|
- // var authorStr string
|
|
|
- // authorStr, err = reportDao.GetGLAuthorNames(htRp.Plate, htRp.Permission)
|
|
|
- // if err != nil {
|
|
|
- // logger.Error("获取钢联研报作者失败:%v", err)
|
|
|
- // }
|
|
|
- // if authorStr != "" {
|
|
|
- // htRp.Author = authorStr
|
|
|
- // }
|
|
|
- // authorNames := strings.Split(htRp.Author, ",")
|
|
|
- // authorNamesWithOutEmpty := stringUtils.RemoveEmptyStrings(authorNames)
|
|
|
- // for _, authorName := range authorNamesWithOutEmpty {
|
|
|
- // destRp := convertHTReport(htRp)
|
|
|
- // destRp.Author = authorName
|
|
|
- // reports = append(reports, destRp)
|
|
|
- // }
|
|
|
- //}
|
|
|
- //err = reportDao.BatchInsertReport(&reports)
|
|
|
- //if err != nil {
|
|
|
- // logger.Error("同步HT研报失败:%v", err)
|
|
|
- // return
|
|
|
- //}
|
|
|
- //return syncESAndSendMessage(reports)
|
|
|
- return
|
|
|
+func SyncHTReportList(list []ht.HTReport) (noRecord bool, err error) {
|
|
|
+ var reports []reportDao.Report
|
|
|
+ permissions, err := reportDao.GetGLAuthorNames()
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取钢联研报作者失败:%v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, htRp := range list {
|
|
|
+ for _, permission := range permissions {
|
|
|
+ if htRp.PermissionName == permission.Permission {
|
|
|
+ if permission.AuthorNames != "" {
|
|
|
+ htRp.PublishUserName = permission.AuthorNames
|
|
|
+ }
|
|
|
+ authorNames := strings.Split(htRp.PublishUserName, ",")
|
|
|
+ authorNamesWithOutEmpty := stringUtils.RemoveEmptyStrings(authorNames)
|
|
|
+ for _, authorName := range authorNamesWithOutEmpty {
|
|
|
+ destRp := convertHTReport(htRp)
|
|
|
+ destRp.Author = authorName
|
|
|
+ var coverSrc int
|
|
|
+ permissionId, err := etaDao.GetPermissionIdByName(htRp.PermissionName)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("HT获取eta品种id失败:%v", err)
|
|
|
+ coverSrc = 0
|
|
|
+ }
|
|
|
+ ids, err := mediaDao.GetIdsByPermissionId(permissionId)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取图片资源失败:%v", err)
|
|
|
+ coverSrc = 0
|
|
|
+ }
|
|
|
+ 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]
|
|
|
+ }
|
|
|
+ destRp.CoverSrc = coverSrc
|
|
|
+ destRp.PlateName = htRp.PermissionName
|
|
|
+ reports = append(reports, destRp)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(reports) == 0 {
|
|
|
+ return true, nil
|
|
|
+ } else {
|
|
|
+ logger.Info("同步研报数量%d", len(list))
|
|
|
+ }
|
|
|
+ var ids []int
|
|
|
+ ids, err = reportDao.InsertOrUpdateReport(&reports, SourceHT)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("同步HT研报失败:%v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, id := range ids {
|
|
|
+ success := elastic().Delete(htConfig.GetReportIndex(), id)
|
|
|
+ if !success {
|
|
|
+ logger.Error("删除es失败,reportId::%d,err:%v", id, err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false, 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)
|
|
@@ -488,8 +531,8 @@ func GetListOrderByConditionWeekly(week bool, column string, limit int, order mo
|
|
|
logger.Error("获取研报失败:%v", err)
|
|
|
return
|
|
|
}
|
|
|
- for _, report := range reports {
|
|
|
- dto := convertReportDTO(report)
|
|
|
+ for _, reportItem := range reports {
|
|
|
+ dto := convertReportDTO(reportItem)
|
|
|
dtoList = append(dtoList, dto)
|
|
|
}
|
|
|
return
|
|
@@ -505,8 +548,8 @@ func GetListByCondition[T any](column string, ids []T) (dtoList []ReportDTO, err
|
|
|
logger.Error("获取研报失败:%v", err)
|
|
|
return
|
|
|
}
|
|
|
- for _, report := range reports {
|
|
|
- dto := convertReportDTO(report)
|
|
|
+ for _, reportItem := range reports {
|
|
|
+ dto := convertReportDTO(reportItem)
|
|
|
dtoList = append(dtoList, dto)
|
|
|
}
|
|
|
return
|