|
@@ -3,6 +3,8 @@ package report
|
|
import (
|
|
import (
|
|
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/page"
|
|
reportService "eta_mini_ht_api/domian/report"
|
|
reportService "eta_mini_ht_api/domian/report"
|
|
"sync"
|
|
"sync"
|
|
"time"
|
|
"time"
|
|
@@ -12,19 +14,86 @@ type PublishRankedReport struct {
|
|
Id int
|
|
Id int
|
|
OrgId int
|
|
OrgId int
|
|
Title string
|
|
Title string
|
|
|
|
+ Abstract string
|
|
PermissionNames interface{}
|
|
PermissionNames interface{}
|
|
PublishedTime string
|
|
PublishedTime string
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+type HotRankedReport struct {
|
|
|
|
+ Id int
|
|
|
|
+ OrgId int
|
|
|
|
+ Count int
|
|
|
|
+ Title string
|
|
|
|
+ PublishedTime string
|
|
|
|
+}
|
|
|
|
+
|
|
type PermissionNode struct {
|
|
type PermissionNode struct {
|
|
ID int `json:"id"`
|
|
ID int `json:"id"`
|
|
Name string `json:"name"`
|
|
Name string `json:"name"`
|
|
ParentID int `json:"parentId"`
|
|
ParentID int `json:"parentId"`
|
|
- Children []*PermissionNode `json:"children"`
|
|
|
|
|
|
+ Children []*PermissionNode `json:"children,omitempty"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type RecordCount struct {
|
|
|
|
+ UserId int
|
|
|
|
+ Mobile string
|
|
|
|
+ ReportId int
|
|
|
|
+ IpAddress string
|
|
|
|
+ Location string
|
|
|
|
+ Referer string
|
|
|
|
+ Additional string
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func GetTotalPageCount() (total int64) {
|
|
|
|
+ return reportService.GetTotalPageCount()
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// GetReportPage 分页获取报告列表
|
|
|
|
+func GetReportPage(pageInfo page.PageInfo) (list []reportService.ReportDTO, err error) {
|
|
|
|
+ list, err = reportService.GetReportPage(pageInfo)
|
|
|
|
+ if err != nil {
|
|
|
|
+ err = exception.New(exception.QueryReportPageFailed)
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+func CountReport(count RecordCount) error {
|
|
|
|
+ dto := convertToRecordCountDTO(count)
|
|
|
|
+ return reportService.CountReport(dto)
|
|
|
|
+}
|
|
|
|
+func GetRandedReportByWeeklyHot(limit int) (reports []HotRankedReport, err error) {
|
|
|
|
+ end := time.Now()
|
|
|
|
+ begin := date.GetBeginOfTheWeek(end, time.Monday)
|
|
|
|
+ hotReports := reportService.GetHotReports(begin.Format(time.DateOnly), end.Format(time.DateOnly), limit)
|
|
|
|
+ if len(hotReports) > 0 {
|
|
|
|
+ var dtoList []reportService.ReportDTO
|
|
|
|
+ var ids []int
|
|
|
|
+ for i := 0; i < len(hotReports); i++ {
|
|
|
|
+ ids = append(ids, hotReports[i].ReportId)
|
|
|
|
+ }
|
|
|
|
+ dtoList, err = reportService.GetListByCondition("id", ids)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.Error("获取本周最热研报列表失败:%v", err)
|
|
|
|
+ err = exception.New(exception.GetHotRandListFailed)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ reports = make([]HotRankedReport, len(ids))
|
|
|
|
+ for i := 0; i < len(dtoList); i++ {
|
|
|
|
+ report := convertToHotRankedReport(dtoList[i])
|
|
|
|
+ for j := 0; j < len(ids); j++ {
|
|
|
|
+ if ids[j] == report.Id {
|
|
|
|
+ reports[j] = report
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ reports = []HotRankedReport{}
|
|
|
|
+ }
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
func GetRandedReportByPublishTime() (reports []PublishRankedReport, err error) {
|
|
func GetRandedReportByPublishTime() (reports []PublishRankedReport, err error) {
|
|
- dtoList, err := reportService.GetListByConditionDesc("published_time", 3)
|
|
|
|
|
|
+ dtoList, err := reportService.GetListOrderByCondition("published_time", 3, reportService.DESC)
|
|
if err != nil {
|
|
if err != nil {
|
|
logger.Error("获取最新发布的研报列表失败:%v", err)
|
|
logger.Error("获取最新发布的研报列表失败:%v", err)
|
|
err = exception.New(exception.GetPublishedRandListFailed)
|
|
err = exception.New(exception.GetPublishedRandListFailed)
|
|
@@ -51,38 +120,7 @@ func getReportPermissionNames(id int, source string) (labels []string) {
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-func convertToPublishRankedReportList(dtoList []reportService.ReportDTO) (reports []PublishRankedReport) {
|
|
|
|
- reports = []PublishRankedReport{}
|
|
|
|
- for _, dto := range dtoList {
|
|
|
|
- report := PublishRankedReport{
|
|
|
|
- Id: dto.ReportID,
|
|
|
|
- OrgId: dto.OrgId,
|
|
|
|
- PublishedTime: dto.PublishedTime,
|
|
|
|
- Title: dto.Title,
|
|
|
|
- PermissionNames: dto.PermissionNames,
|
|
|
|
- }
|
|
|
|
- date, err := time.Parse(time.DateTime, report.PublishedTime)
|
|
|
|
- if err == nil {
|
|
|
|
- report.PublishedTime = date.Format(time.DateOnly)
|
|
|
|
- }
|
|
|
|
- reports = append(reports, report)
|
|
|
|
- }
|
|
|
|
- return
|
|
|
|
-}
|
|
|
|
|
|
|
|
-func convertToPublishRankedReport(dto reportService.ReportDTO) (report PublishRankedReport) {
|
|
|
|
- report = PublishRankedReport{
|
|
|
|
- Id: dto.ReportID,
|
|
|
|
- OrgId: dto.OrgId,
|
|
|
|
- PublishedTime: dto.PublishedTime,
|
|
|
|
- Title: dto.Title,
|
|
|
|
- }
|
|
|
|
- date, err := time.Parse(time.DateTime, report.PublishedTime)
|
|
|
|
- if err == nil {
|
|
|
|
- report.PublishedTime = date.Format(time.DateOnly)
|
|
|
|
- }
|
|
|
|
- return
|
|
|
|
-}
|
|
|
|
func GetPermissionList() (root *PermissionNode, err error) {
|
|
func GetPermissionList() (root *PermissionNode, err error) {
|
|
list, err := reportService.GetPermissionList()
|
|
list, err := reportService.GetPermissionList()
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -113,3 +151,47 @@ func assemblePermissionNode(list []reportService.PermissionDTO, node *Permission
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+func convertToHotRankedReport(dto reportService.ReportDTO) (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)
|
|
|
|
+ //}
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+func convertToPublishRankedReportList(dtoList []reportService.ReportDTO) (reports []PublishRankedReport) {
|
|
|
|
+ reports = []PublishRankedReport{}
|
|
|
|
+ for _, dto := range dtoList {
|
|
|
|
+ report := PublishRankedReport{
|
|
|
|
+ Id: dto.ReportID,
|
|
|
|
+ OrgId: dto.OrgId,
|
|
|
|
+ PublishedTime: dto.PublishedTime,
|
|
|
|
+ Abstract: dto.Abstract,
|
|
|
|
+ Title: dto.Title,
|
|
|
|
+ PermissionNames: dto.PermissionNames,
|
|
|
|
+ }
|
|
|
|
+ //publishDate, err := time.Parse(time.DateTime, report.PublishedTime)
|
|
|
|
+ //if err == nil {
|
|
|
|
+ // report.PublishedTime = publishDate.Format(time.DateOnly)
|
|
|
|
+ //}
|
|
|
|
+ reports = append(reports, report)
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func convertToRecordCountDTO(record RecordCount) (dto reportService.RecordCountDTO) {
|
|
|
|
+ return reportService.RecordCountDTO{
|
|
|
|
+ UserId: record.UserId,
|
|
|
|
+ Mobile: record.Mobile,
|
|
|
|
+ ReportId: record.ReportId,
|
|
|
|
+ IpAddress: record.IpAddress,
|
|
|
|
+ Location: record.Location,
|
|
|
|
+ Referer: record.Referer,
|
|
|
|
+ Additional: record.Additional,
|
|
|
|
+ }
|
|
|
|
+}
|