123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- package report
- import (
- "eta_mini_ht_api/common/component/es"
- logger "eta_mini_ht_api/common/component/log"
- "eta_mini_ht_api/models"
- "eta_mini_ht_api/models/eta"
- etaDao "eta_mini_ht_api/models/eta"
- reportDao "eta_mini_ht_api/models/report"
- "strconv"
- )
- const (
- indexName = "report_index"
- )
- func elastic() *es.ESClient {
- return es.GetInstance()
- }
- // ESReport Report ES研报mapping
- type ESReport struct {
- ReportID int `json:"report_id"`
- OrgId int `json:"org_id"`
- Author string `json:"author"`
- Source reportDao.ReportSource `json:"source"`
- Abstract string `json:"abstract"`
- Status reportDao.ReportStatus `json:"status"`
- }
- type ReportDTO struct {
- ReportID int `json:"report_id"`
- OrgId int `json:"org_id"`
- Title string `json:"title"`
- Author string `json:"author"`
- Source reportDao.ReportSource `json:"source"`
- Abstract string `json:"abstract"`
- PublishedTime string `json:"published_time"`
- }
- type PermissionDTO struct {
- ID int
- Name string
- ParentID int
- }
- func GetPermissionList() (dtoList []PermissionDTO, err error) {
- list, err := etaDao.GetChartPermissionList()
- if err != nil {
- logger.Error("获取研报列表失败")
- return
- }
- dtoList = make([]PermissionDTO, 0)
- for _, node := range list {
- dto := convertPermissionDTO(node)
- dtoList = append(dtoList, dto)
- }
- return
- }
- func GetReportLabelsById(id int, source reportDao.ReportSource) {
- switch source {
- case reportDao.SourceETA:
- //eta.GetReportLabelById()
- return
- case reportDao.SourceHT:
- return
- }
- }
- func (es ESReport) GetId() string {
- return strconv.Itoa(es.ReportID)
- }
- func GetETALatestReportId() (id int, err error) {
- return reportDao.GetETALatestReportId()
- }
- func SyncETAReportList(list []eta.ETAReport) (err error) {
- logger.Info("同步研报数量%d", len(list))
- var reports []reportDao.Report
- var esReports []es.ESBase
- for _, etaRp := range list {
- destRp := convertEtaReport(etaRp)
- reports = append(reports, destRp)
- }
- err = reportDao.BatchInsertReport(&reports)
- if err != nil {
- logger.Error("同步ETA研报失败:%v", err)
- return
- }
- for _, etaRp := range reports {
- esRp := convertEsReport(etaRp)
- esReports = append(esReports, esRp)
- }
- //同步es
- err = elastic().BulkInsert(indexName, esReports)
- if err != nil {
- logger.Error("同步ETA研报到es失败:%v", err)
- return
- }
- return
- }
- func GetListByConditionDesc(column string, limit int) (dtoList []ReportDTO, err error) {
- reports, err := reportDao.GetListByCondition(column, limit, models.Desc)
- if err != nil {
- logger.Error("获取研报失败:%v", err)
- return
- }
- dtoList = []ReportDTO{}
- for _, report := range reports {
- dtoList = append(dtoList, convertReportDTO(report))
- }
- return
- }
- func GetListByConditionAsc(column string, limit int) (dtoList []ReportDTO, err error) {
- reports, err := reportDao.GetListByCondition(column, limit, models.Asc)
- if err != nil {
- logger.Error("获取研报失败:%v", err)
- return
- }
- for _, report := range reports {
- dtoList = append(dtoList, convertReportDTO(report))
- }
- return
- }
- func convertEtaReport(etaRp eta.ETAReport) reportDao.Report {
- return reportDao.Report{
- OrgID: etaRp.ID,
- Title: etaRp.Title,
- Abstract: etaRp.Abstract,
- Author: etaRp.Author,
- PublishedTime: etaRp.PublishTime,
- Source: reportDao.SourceETA,
- Status: reportDao.StatusInit,
- }
- }
- func convertEsReport(report reportDao.Report) ESReport {
- return ESReport{
- ReportID: report.ID,
- OrgId: report.OrgID,
- Author: report.Author,
- Source: report.Source,
- Abstract: report.Abstract,
- Status: report.Status,
- }
- }
- func convertReportDTO(report reportDao.Report) ReportDTO {
- return ReportDTO{
- ReportID: report.ID,
- Title: report.Title,
- OrgId: report.OrgID,
- Author: report.Author,
- Source: report.Source,
- Abstract: report.Abstract,
- PublishedTime: report.PublishedTime,
- }
- }
- func convertPermissionDTO(node etaDao.ChartPermission) PermissionDTO {
- return PermissionDTO{
- ID: node.ChartPermissionID,
- Name: node.PermissionName,
- ParentID: node.ParentID,
- }
- }
|