Browse Source

3.1收藏

kobe6258 4 months ago
parent
commit
be1ae07363
3 changed files with 79 additions and 35 deletions
  1. 69 31
      controllers/user/bookmark_controller.go
  2. 9 2
      domian/report/report_service.go
  3. 1 2
      models/report/report.go

+ 69 - 31
controllers/user/bookmark_controller.go

@@ -1,6 +1,7 @@
 package user
 
 import (
+	"encoding/json"
 	"errors"
 	"eta/eta_mini_ht_api/common/component/cache"
 	logger "eta/eta_mini_ht_api/common/component/log"
@@ -228,11 +229,39 @@ type BookMarkChart struct {
 	UniqueCode  string `json:"uniqueCode"`
 	ChartInfoId int    `json:"chartInfoId"`
 }
+
 type BookMarkReport struct {
-	ChartName   string `json:"chartName"`
-	ChartImage  string `json:"chartImage"`
-	UniqueCode  string `json:"uniqueCode"`
-	ChartInfoId int    `json:"chartInfoId"`
+	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:"-"`
 }
 
 // BookMarkList 获取收藏列表
@@ -332,32 +361,15 @@ func getReportList(info page.PageInfo, templateUserId int, sourceIds []int) (lis
 	if err != nil {
 		return nil, err
 	}
-	// 创建一个切片来存储结果,长度与 sourceIds 相同
-	list = make([]BookMarkReport, len(sourceIds))
-	// 使用 WaitGroup 来等待所有 goroutine 完成
-	var wg sync.WaitGroup
-	wg.Add(len(sourceIds))
-	// 使用 Mutex 来保护对 list 的写操作
-	var mu sync.Mutex
 	// 并发获取数据
 	for index, sourceId := range sourceIds {
-		go func(index int, id int) {
-			defer wg.Done()
-			var data chartService.ChartInfo
-			data, err = chartService.GetChartById(id)
-			reportInfo := convertToBookMarkChart(data)
-			if err != nil {
-				logger.Error("获取数据失败: %v", err)
+		for _, reportDTO := range reports {
+			if reportDTO.ReportID == sourceId {
+				reportInfo := convertToBookMarkReport(reportDTO)
+				list[index] = reportInfo
 			}
-			// 使用 Mutex 保护对 list 的写操作
-			mu.Lock()
-			list[index] = reportInfo
-			mu.Unlock()
-		}(index, sourceId)
-
+		}
 	}
-	// 等待所有 goroutine 完成
-	wg.Wait()
 	return
 }
 
@@ -404,11 +416,37 @@ func convertToBookMarkChart(chart chartService.ChartInfo) BookMarkChart {
 	}
 }
 
-func convertToBookMarkReport(chart chartService.ChartInfo) BookMarkReport {
+func convertToBookMarkReport(report reportDomian.ReportDTO) BookMarkReport {
 	return BookMarkReport{
-		ChartName:   chart.ChartName,
-		ChartImage:  chart.ChartImage,
-		UniqueCode:  chart.UniqueCode,
-		ChartInfoId: chart.ChartInfoId,
+		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,
 	}
 }

+ 9 - 2
domian/report/report_service.go

@@ -1155,6 +1155,13 @@ func FilterReportIds(sourceIds []int) (total int64, reportIds []int, err error)
 	return reportDao.FilterReportIds(sourceIds)
 }
 
-func GetReportListById(reportIds []int) ([]ReportDTO, error) {
-	return reportDao.GetReportListById(reportIds)
+func GetReportListById(reportIds []int) (reportList []ReportDTO, err error) {
+	reports, err := reportDao.GetReportListById(reportIds)
+	if err != nil {
+		return
+	}
+	for _, report := range reports {
+		reportList = append(reportList, convertReportDTO(report, false))
+	}
+	return
 }

+ 1 - 2
models/report/report.go

@@ -5,7 +5,6 @@ import (
 	logger "eta/eta_mini_ht_api/common/component/log"
 	"eta/eta_mini_ht_api/common/utils/date"
 	silce_utils "eta/eta_mini_ht_api/common/utils/silce"
-	"eta/eta_mini_ht_api/domian/report"
 	"eta/eta_mini_ht_api/models"
 	permissionDao "eta/eta_mini_ht_api/models/config"
 	"fmt"
@@ -442,7 +441,7 @@ func FilterReportIds(ids []int) (total int64, reportIds []int, err error) {
 	return
 }
 
-func GetReportListById(ids []int) (reports []report.ReportDTO, err error) {
+func GetReportListById(ids []int) (reports []Report, err error) {
 	db := models.Main()
 	err = db.Select(CommonColumns).
 		Where("id in ?", ids).Find(&reports).Error