|
@@ -1,6 +1,7 @@
|
|
package report
|
|
package report
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "encoding/json"
|
|
logger "eta_mini_ht_api/common/component/log"
|
|
logger "eta_mini_ht_api/common/component/log"
|
|
"eta_mini_ht_api/common/exception"
|
|
"eta_mini_ht_api/common/exception"
|
|
"eta_mini_ht_api/common/utils/date"
|
|
"eta_mini_ht_api/common/utils/date"
|
|
@@ -10,6 +11,11 @@ import (
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+const (
|
|
|
|
+ SourceETA = "ETA"
|
|
|
|
+ SourceHT = "HT"
|
|
|
|
+)
|
|
|
|
+
|
|
type PublishRankedReport struct {
|
|
type PublishRankedReport struct {
|
|
Id int
|
|
Id int
|
|
OrgId int
|
|
OrgId int
|
|
@@ -20,11 +26,12 @@ type PublishRankedReport struct {
|
|
}
|
|
}
|
|
|
|
|
|
type HotRankedReport struct {
|
|
type HotRankedReport struct {
|
|
- Id int
|
|
|
|
- OrgId int
|
|
|
|
- Count int
|
|
|
|
- Title string
|
|
|
|
- PublishedTime string
|
|
|
|
|
|
+ Id int
|
|
|
|
+ OrgId int
|
|
|
|
+ Count int
|
|
|
|
+ Title string
|
|
|
|
+ PublishedTime string
|
|
|
|
+ PermissionNames interface{}
|
|
}
|
|
}
|
|
|
|
|
|
type PermissionNode struct {
|
|
type PermissionNode struct {
|
|
@@ -45,6 +52,41 @@ type RecordCount struct {
|
|
}
|
|
}
|
|
|
|
|
|
func GetReportById(reportId int) (report reportService.ReportDTO, err error) {
|
|
func GetReportById(reportId int) (report reportService.ReportDTO, err error) {
|
|
|
|
+ report, err = reportService.GetGetReportById(reportId)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.Error("获取研报失败:%v", err)
|
|
|
|
+ err = exception.New(exception.GetReportFailed)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ var detail interface{}
|
|
|
|
+ switch report.Source {
|
|
|
|
+ case SourceETA:
|
|
|
|
+ detail, err = getETAReportDetail(&report)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return reportService.ReportDTO{}, err
|
|
|
|
+ }
|
|
|
|
+ case SourceHT:
|
|
|
|
+ detail = nil
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.Error("获取研报详情失败失败:%v")
|
|
|
|
+ err = exception.New(exception.GetReportFailed)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ json, err := json.Marshal(detail)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.Error("生成研报详情失败:%v", err)
|
|
|
|
+ err = exception.New(exception.GetReportFailed)
|
|
|
|
+ }
|
|
|
|
+ report.Detail = json
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func getETAReportDetail(report *reportService.ReportDTO) (etaReport reportService.ETAReportDTO, err error) {
|
|
|
|
+ return reportService.GetETAReport(report.OrgId)
|
|
|
|
+}
|
|
|
|
+func getHTReportDetail(report *reportService.ReportDTO) (err error) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
func GetTotalPageCount() (total int64) {
|
|
func GetTotalPageCount() (total int64) {
|
|
@@ -53,6 +95,15 @@ func GetTotalPageCount() (total int64) {
|
|
func SearchReportList(key string, pageInfo page.PageInfo) (reports []reportService.ReportDTO, err error) {
|
|
func SearchReportList(key string, pageInfo page.PageInfo) (reports []reportService.ReportDTO, err error) {
|
|
offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
|
|
offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
|
|
reports, err = reportService.SearchReportList(key, offset, pageInfo.PageSize, pageInfo.LatestId)
|
|
reports, err = reportService.SearchReportList(key, offset, pageInfo.PageSize, pageInfo.LatestId)
|
|
|
|
+ var wg sync.WaitGroup
|
|
|
|
+ wg.Add(len(reports))
|
|
|
|
+ for i := 0; i < len(reports); i++ {
|
|
|
|
+ go func(report *reportService.ReportDTO) {
|
|
|
|
+ defer wg.Done()
|
|
|
|
+ report.PermissionNames = getReportPermissionNames(report.OrgId, report.Source)
|
|
|
|
+ }(&reports[i])
|
|
|
|
+ }
|
|
|
|
+ wg.Wait()
|
|
if err != nil {
|
|
if err != nil {
|
|
err = exception.New(exception.SearchReportPageFailed)
|
|
err = exception.New(exception.SearchReportPageFailed)
|
|
}
|
|
}
|
|
@@ -66,6 +117,16 @@ func SearchMaxReportId() (id int64) {
|
|
// GetReportPage 分页获取报告列表
|
|
// GetReportPage 分页获取报告列表
|
|
func GetReportPage(pageInfo page.PageInfo) (list []reportService.ReportDTO, err error) {
|
|
func GetReportPage(pageInfo page.PageInfo) (list []reportService.ReportDTO, err error) {
|
|
list, err = reportService.GetReportPage(pageInfo)
|
|
list, err = reportService.GetReportPage(pageInfo)
|
|
|
|
+ //并发获取研报的标签
|
|
|
|
+ var wg sync.WaitGroup
|
|
|
|
+ wg.Add(len(list))
|
|
|
|
+ for i := 0; i < len(list); i++ {
|
|
|
|
+ go func(report *reportService.ReportDTO) {
|
|
|
|
+ defer wg.Done()
|
|
|
|
+ report.PermissionNames = getReportPermissionNames(report.OrgId, report.Source)
|
|
|
|
+ }(&list[i])
|
|
|
|
+ }
|
|
|
|
+ wg.Wait()
|
|
if err != nil {
|
|
if err != nil {
|
|
err = exception.New(exception.QueryReportPageFailed)
|
|
err = exception.New(exception.QueryReportPageFailed)
|
|
}
|
|
}
|
|
@@ -91,6 +152,15 @@ func GetRandedReportByWeeklyHot(limit int) (reports []HotRankedReport, err error
|
|
err = exception.New(exception.GetHotRandListFailed)
|
|
err = exception.New(exception.GetHotRandListFailed)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ var wg sync.WaitGroup
|
|
|
|
+ wg.Add(len(dtoList))
|
|
|
|
+ for i := 0; i < len(dtoList); i++ {
|
|
|
|
+ go func(report *reportService.ReportDTO) {
|
|
|
|
+ defer wg.Done()
|
|
|
|
+ report.PermissionNames = getReportPermissionNames(report.OrgId, report.Source)
|
|
|
|
+ }(&dtoList[i])
|
|
|
|
+ }
|
|
|
|
+ wg.Wait()
|
|
reports = make([]HotRankedReport, len(ids))
|
|
reports = make([]HotRankedReport, len(ids))
|
|
for i := 0; i < len(dtoList); i++ {
|
|
for i := 0; i < len(dtoList); i++ {
|
|
report := convertToHotRankedReport(dtoList[i])
|
|
report := convertToHotRankedReport(dtoList[i])
|
|
@@ -168,15 +238,12 @@ func assemblePermissionNode(list []reportService.PermissionDTO, node *Permission
|
|
}
|
|
}
|
|
func convertToHotRankedReport(dto reportService.ReportDTO) (report HotRankedReport) {
|
|
func convertToHotRankedReport(dto reportService.ReportDTO) (report HotRankedReport) {
|
|
report = HotRankedReport{
|
|
report = HotRankedReport{
|
|
- Id: dto.ReportID,
|
|
|
|
- OrgId: dto.OrgId,
|
|
|
|
- PublishedTime: dto.PublishedTime,
|
|
|
|
- Title: dto.Title,
|
|
|
|
- }
|
|
|
|
- //publishDate, err := time.Parse(time.DateTime, report.PublishedTime)
|
|
|
|
- //if err == nil {
|
|
|
|
- // report.PublishedTime = publishDate.Format(time.DateOnly)
|
|
|
|
- //}
|
|
|
|
|
|
+ Id: dto.ReportID,
|
|
|
|
+ OrgId: dto.OrgId,
|
|
|
|
+ PublishedTime: dto.PublishedTime,
|
|
|
|
+ Title: dto.Title,
|
|
|
|
+ PermissionNames: dto.PermissionNames,
|
|
|
|
+ }
|
|
return
|
|
return
|
|
}
|
|
}
|
|
func convertToPublishRankedReportList(dtoList []reportService.ReportDTO) (reports []PublishRankedReport) {
|
|
func convertToPublishRankedReportList(dtoList []reportService.ReportDTO) (reports []PublishRankedReport) {
|