|
@@ -3,8 +3,10 @@ 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"
|
|
|
- "eta_mini_ht_api/models/report"
|
|
|
+ etaDao "eta_mini_ht_api/models/eta"
|
|
|
+ reportDao "eta_mini_ht_api/models/report"
|
|
|
"strconv"
|
|
|
)
|
|
|
|
|
@@ -18,30 +20,69 @@ func elastic() *es.ESClient {
|
|
|
|
|
|
// ESReport Report ES研报mapping
|
|
|
type ESReport struct {
|
|
|
- ReportID int `json:"report_id"`
|
|
|
- OrgId int `json:"org_id"`
|
|
|
- Author string `json:"author"`
|
|
|
- Source report.ReportSource `json:"source"`
|
|
|
- Abstract string `json:"abstract"`
|
|
|
- Status report.ReportStatus `json:"status"`
|
|
|
+ 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 report.GetETALatestReportId()
|
|
|
+ return reportDao.GetETALatestReportId()
|
|
|
}
|
|
|
|
|
|
func SyncETAReportList(list []eta.ETAReport) (err error) {
|
|
|
logger.Info("同步研报数量%d", len(list))
|
|
|
- var reports []report.Report
|
|
|
+ var reports []reportDao.Report
|
|
|
var esReports []es.ESBase
|
|
|
for _, etaRp := range list {
|
|
|
destRp := convertEtaReport(etaRp)
|
|
|
reports = append(reports, destRp)
|
|
|
}
|
|
|
- err = report.BatchInsertReport(&reports)
|
|
|
+ err = reportDao.BatchInsertReport(&reports)
|
|
|
if err != nil {
|
|
|
logger.Error("同步ETA研报失败:%v", err)
|
|
|
return
|
|
@@ -59,17 +100,42 @@ func SyncETAReportList(list []eta.ETAReport) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func convertEtaReport(etaRp eta.ETAReport) report.Report {
|
|
|
- return report.Report{
|
|
|
- OrgID: etaRp.ID,
|
|
|
- Title: etaRp.Title,
|
|
|
- Abstract: etaRp.Abstract,
|
|
|
- Author: etaRp.Author,
|
|
|
- Source: report.SourceETA,
|
|
|
- Status: report.StatusInit,
|
|
|
+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 convertEsReport(report report.Report) ESReport {
|
|
|
+
|
|
|
+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,
|
|
@@ -79,6 +145,23 @@ func convertEsReport(report report.Report) ESReport {
|
|
|
Status: report.Status,
|
|
|
}
|
|
|
}
|
|
|
-func GetList(id int, size int) []report.Report {
|
|
|
- return nil
|
|
|
+
|
|
|
+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,
|
|
|
+ }
|
|
|
}
|