|
@@ -1,7 +1,6 @@
|
|
|
package user
|
|
|
|
|
|
import (
|
|
|
- "encoding/json"
|
|
|
"errors"
|
|
|
"eta/eta_mini_ht_api/common/component/cache"
|
|
|
logger "eta/eta_mini_ht_api/common/component/log"
|
|
@@ -223,45 +222,60 @@ type BookMarkListReq struct {
|
|
|
SourceType string `json:"source_type"`
|
|
|
}
|
|
|
|
|
|
-type BookMarkChart struct {
|
|
|
- ChartName string `json:"chartName"`
|
|
|
- ChartImage string `json:"chartImage"`
|
|
|
- UniqueCode string `json:"uniqueCode"`
|
|
|
- ChartInfoId int `json:"chartInfoId"`
|
|
|
-}
|
|
|
-
|
|
|
-type BookMarkReport struct {
|
|
|
- Type string `json:"type"`
|
|
|
- ReportID int `json:"reportId"`
|
|
|
- OrgId int `json:"orgId"`
|
|
|
- Title string `json:"title"`
|
|
|
- Author string `json:"author"`
|
|
|
- AuthorInfo []reportDomian.Anthor `json:"authorInfo"`
|
|
|
- Source string `json:"source"`
|
|
|
- Abstract string `json:"abstract"`
|
|
|
- PublishedTime string `json:"publishedTime"`
|
|
|
- RiskLevel string `json:"riskLevel"`
|
|
|
- PlateName string `json:"-"`
|
|
|
- ClassifyId int `json:"-"`
|
|
|
- SecondPermission map[int]string `json:"-"`
|
|
|
- Permissions map[int]string `json:"-"`
|
|
|
- PermissionNames interface {
|
|
|
- } `json:"permissionNames"`
|
|
|
- Highlight []string `json:"highlight"`
|
|
|
- Detail json.RawMessage `json:"detail"`
|
|
|
- PdfUrl string `json:"pdfUrl"`
|
|
|
- CoverSrc int `json:"coverSrc"`
|
|
|
- CoverUrl string `json:"coverUrl"`
|
|
|
- Login bool `json:"login"`
|
|
|
- RiskLevelStatus string `json:"riskLevelStatus"`
|
|
|
- IsFree bool `json:"isFree"`
|
|
|
- IsSubscribe bool `json:"isSubscribe"`
|
|
|
- SubscribeStatus string `json:"subscribeStatus"`
|
|
|
- Price string `json:"price"`
|
|
|
- ProductId int `json:"productId"`
|
|
|
- IsPackage bool `json:"isPackage"`
|
|
|
- Score float64 `json:"score"`
|
|
|
- Show bool `json:"-"`
|
|
|
+// SearchBookMark 获取收藏列表
|
|
|
+// @Description 获取收藏列表
|
|
|
+// @Success 200 {object}
|
|
|
+// @router /searchBookMark [get]
|
|
|
+func (bk *BookMarkController) SearchBookMark(sourceType string, key string) {
|
|
|
+ controllers.Wrap(&bk.BaseController, func() (result *controllers.WrapData, err error) {
|
|
|
+ result = bk.InitWrapData("分页搜索收藏列表失败")
|
|
|
+ pageRes := page.Page{
|
|
|
+ Current: bk.PageInfo.Current,
|
|
|
+ PageSize: bk.PageInfo.PageSize,
|
|
|
+ }
|
|
|
+ if sourceType == "" || (sourceType != Report && sourceType != Chart) {
|
|
|
+ err = exception.New(exception.IllegalSourceType)
|
|
|
+ bk.FailedResult("分页搜索收藏列表失败", result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ userInfo := bk.Data["user"].(user.User)
|
|
|
+ var sourceIds []int
|
|
|
+ pageRes.Total, sourceIds, err = user.GetTotalBookMarkPageBySourceType(userInfo.Id, sourceType)
|
|
|
+ //隐藏品种信息未设置风险等级的报告
|
|
|
+ if sourceType == Report {
|
|
|
+ pageRes.Total, sourceIds, err = report.FilterReportIds(sourceIds)
|
|
|
+ }
|
|
|
+ if pageRes.Total == 0 {
|
|
|
+ bookMarks := new(page.PageResult)
|
|
|
+ bookMarks.Data = []interface{}{}
|
|
|
+ bookMarks.Page = pageRes
|
|
|
+ bk.SuccessResult("分页搜索收藏列表列表成功", bookMarks, result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ pageRes.Total = bk.PageInfo.Total
|
|
|
+ pageRes.TotalPage = page.TotalPages(pageRes.Total, pageRes.PageSize)
|
|
|
+ var bookMarkList userService.BookMarkInterface
|
|
|
+ bookMarkList, err = user.SearchBookMark(key, sourceType, sourceIds, bk.PageInfo, userInfo.Id)
|
|
|
+ switch sourceType {
|
|
|
+ case Chart:
|
|
|
+ var list []userService.BookMarkChart
|
|
|
+ list, err = getChartList(bk.PageInfo, userInfo.Id)
|
|
|
+ if err != nil {
|
|
|
+ err = exception.NewWithException(exception.GetBookMarkListFailed, err.Error())
|
|
|
+ bk.FailedResult("分页查询收藏列表失败", result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ bookMarks := new(page.PageResult)
|
|
|
+ bookMarks.Data = list
|
|
|
+ bookMarks.Page = pageRes
|
|
|
+ bk.SuccessResult("分页查询收藏列表成功", bookMarks, result)
|
|
|
+ return
|
|
|
+ default:
|
|
|
+ err = exception.New(exception.IllegalSourceType)
|
|
|
+ bk.FailedResult("分页查询收藏列表失败", result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
// BookMarkList 获取收藏列表
|
|
@@ -298,7 +312,7 @@ func (bk *BookMarkController) BookMarkList(sourceType string) {
|
|
|
pageRes.TotalPage = page.TotalPages(pageRes.Total, pageRes.PageSize)
|
|
|
switch sourceType {
|
|
|
case Report:
|
|
|
- var list []BookMarkReport
|
|
|
+ var list []userService.BookMarkReport
|
|
|
list, err = getReportList(bk.PageInfo, userInfo.Id, sourceIds)
|
|
|
if err != nil {
|
|
|
err = exception.NewWithException(exception.GetBookMarkListFailed, err.Error())
|
|
@@ -311,7 +325,7 @@ func (bk *BookMarkController) BookMarkList(sourceType string) {
|
|
|
bk.SuccessResult("分页查询收藏列表成功", bookMarks, result)
|
|
|
return
|
|
|
case Chart:
|
|
|
- var list []BookMarkChart
|
|
|
+ var list []userService.BookMarkChart
|
|
|
list, err = getChartList(bk.PageInfo, userInfo.Id)
|
|
|
if err != nil {
|
|
|
err = exception.NewWithException(exception.GetBookMarkListFailed, err.Error())
|
|
@@ -331,7 +345,7 @@ func (bk *BookMarkController) BookMarkList(sourceType string) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-func getReportList(info page.PageInfo, templateUserId int, sourceIds []int) (list []BookMarkReport, err error) {
|
|
|
+func getReportList(info page.PageInfo, templateUserId int, sourceIds []int) (list []userService.BookMarkReport, err error) {
|
|
|
sourceIds, err = userService.GetBookMarkPageRangeBySourceType(templateUserId, info, Report, sourceIds)
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -361,12 +375,12 @@ func getReportList(info page.PageInfo, templateUserId int, sourceIds []int) (lis
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
- list = make([]BookMarkReport, len(sourceIds))
|
|
|
+ list = make([]userService.BookMarkReport, len(sourceIds))
|
|
|
// 并发获取数据
|
|
|
for index, sourceId := range sourceIds {
|
|
|
for _, reportDTO := range reports {
|
|
|
if reportDTO.ReportID == sourceId {
|
|
|
- reportInfo := convertToBookMarkReport(reportDTO)
|
|
|
+ reportInfo := userService.ConvertToBookMarkReport(reportDTO)
|
|
|
list[index] = reportInfo
|
|
|
}
|
|
|
}
|
|
@@ -374,13 +388,13 @@ func getReportList(info page.PageInfo, templateUserId int, sourceIds []int) (lis
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func getChartList(info page.PageInfo, templateUserId int) (list []BookMarkChart, err error) {
|
|
|
+func getChartList(info page.PageInfo, templateUserId int) (list []userService.BookMarkChart, err error) {
|
|
|
sourceIds, err := userService.GetBookMarkPageBySourceType(templateUserId, info, Chart)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
// 创建一个切片来存储结果,长度与 sourceIds 相同
|
|
|
- list = make([]BookMarkChart, len(sourceIds))
|
|
|
+ list = make([]userService.BookMarkChart, len(sourceIds))
|
|
|
// 使用 WaitGroup 来等待所有 goroutine 完成
|
|
|
var wg sync.WaitGroup
|
|
|
wg.Add(len(sourceIds))
|
|
@@ -392,7 +406,7 @@ func getChartList(info page.PageInfo, templateUserId int) (list []BookMarkChart,
|
|
|
defer wg.Done()
|
|
|
var data chartService.ChartInfo
|
|
|
data, err = chartService.GetChartById(id)
|
|
|
- chartInfo := convertToBookMarkChart(data)
|
|
|
+ chartInfo := userService.ConvertToBookMarkChart(data)
|
|
|
if err != nil {
|
|
|
logger.Error("获取数据失败: %v", err)
|
|
|
}
|
|
@@ -407,47 +421,3 @@ func getChartList(info page.PageInfo, templateUserId int) (list []BookMarkChart,
|
|
|
wg.Wait()
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
-func convertToBookMarkChart(chart chartService.ChartInfo) BookMarkChart {
|
|
|
- return BookMarkChart{
|
|
|
- ChartName: chart.ChartName,
|
|
|
- ChartImage: chart.ChartImage,
|
|
|
- UniqueCode: chart.UniqueCode,
|
|
|
- ChartInfoId: chart.ChartInfoId,
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func convertToBookMarkReport(report reportDomian.ReportDTO) BookMarkReport {
|
|
|
- return BookMarkReport{
|
|
|
- Abstract: report.Abstract,
|
|
|
- Author: report.Author,
|
|
|
- AuthorInfo: report.AuthorInfo,
|
|
|
- ClassifyId: report.ClassifyId,
|
|
|
- CoverSrc: report.CoverSrc,
|
|
|
- CoverUrl: report.CoverUrl,
|
|
|
- Detail: report.Detail,
|
|
|
- Highlight: report.Highlight,
|
|
|
- IsFree: report.IsFree,
|
|
|
- IsPackage: report.IsPackage,
|
|
|
- IsSubscribe: report.IsSubscribe,
|
|
|
- Login: report.Login,
|
|
|
- OrgId: report.OrgId,
|
|
|
- PdfUrl: report.PdfUrl,
|
|
|
- PermissionNames: report.PermissionNames,
|
|
|
- Permissions: report.Permissions,
|
|
|
- PlateName: report.PlateName,
|
|
|
- Price: report.Price,
|
|
|
- ProductId: report.ProductId,
|
|
|
- PublishedTime: report.PublishedTime,
|
|
|
- ReportID: report.ReportID,
|
|
|
- RiskLevel: report.RiskLevel,
|
|
|
- RiskLevelStatus: report.RiskLevelStatus,
|
|
|
- Score: report.Score,
|
|
|
- SecondPermission: report.SecondPermission,
|
|
|
- Show: report.Show,
|
|
|
- Source: report.Source,
|
|
|
- SubscribeStatus: report.SubscribeStatus,
|
|
|
- Title: report.Title,
|
|
|
- Type: report.Type,
|
|
|
- }
|
|
|
-}
|