kobe6258 vor 3 Wochen
Ursprung
Commit
020d95b7d3

+ 71 - 5
controllers/user/bookmark_controller.go

@@ -255,12 +255,35 @@ func (bk *BookMarkController) SearchBookMark(sourceType string, key string) {
 		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)
-		if err != nil {
-			err = exception.New(exception.BookMarkListFailed)
+		switch sourceType {
+		case Report:
+			reportList, reportErr := report.SearchReportBookMark(key, sourceIds, bk.PageInfo, true, userInfo.Id)
+			if reportErr != nil {
+				logger.Error("搜索研报列表失败%v", err)
+				err = exception.NewWithException(exception.GetBookMarkListFailed, reportErr.Error())
+				bk.FailedResult("分页搜索收藏列表失败", result)
+				return
+			}
+			for _, reportInfo := range reportList {
+				bookMarkList = append(bookMarkList, ConvertToBookMarkReport(reportInfo))
+			}
+		case Chart:
+			chartList, chartErr := chartService.SearchChartList(key, sourceIds, bk.PageInfo)
+			if chartErr != nil {
+				logger.Error("搜索研报列表失败%v", err)
+				err = exception.NewWithException(exception.GetBookMarkListFailed, chartErr.Error())
+				bk.FailedResult("分页搜索收藏列表失败", result)
+				return
+			}
+			for _, chart := range chartList {
+				bookMarkList = append(bookMarkList, ConvertToBookMarkChart(chart))
+			}
+		default:
+			err = exception.NewWithException(exception.GetBookMarkListFailed, "不支持的收藏类型")
 			bk.FailedResult("分页搜索收藏列表失败", result)
 			return
 		}
+		//bookMarkList, err = user.SearchBookMark(key, sourceType, sourceIds, bk.PageInfo, userInfo.Id)
 		bookMarks := new(page.PageResult)
 		bookMarks.Data = bookMarkList
 		bookMarks.Page = pageRes
@@ -268,6 +291,49 @@ func (bk *BookMarkController) SearchBookMark(sourceType string, key string) {
 		return
 	})
 }
+func ConvertToBookMarkChart(chart chartService.ChartInfo) userService.BookMarkChart {
+	return userService.BookMarkChart{
+		ChartName:   chart.ChartName,
+		ChartImage:  chart.ChartImage,
+		UniqueCode:  chart.UniqueCode,
+		ChartInfoId: chart.ChartInfoId,
+	}
+}
+
+func ConvertToBookMarkReport(report reportDomian.ReportDTO) userService.BookMarkReport {
+	return userService.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,
+	}
+}
 
 // BookMarkList 获取收藏列表
 // @Description 获取收藏列表
@@ -371,7 +437,7 @@ func getReportList(info page.PageInfo, templateUserId int, sourceIds []int) (lis
 	for index, sourceId := range sourceIds {
 		for _, reportDTO := range reports {
 			if reportDTO.ReportID == sourceId {
-				reportInfo := userService.ConvertToBookMarkReport(reportDTO)
+				reportInfo := ConvertToBookMarkReport(reportDTO)
 				list[index] = reportInfo
 			}
 		}
@@ -397,7 +463,7 @@ func getChartList(info page.PageInfo, templateUserId int) (list []userService.Bo
 			defer wg.Done()
 			var data chartService.ChartInfo
 			data, err = chartService.GetChartById(id)
-			chartInfo := userService.ConvertToBookMarkChart(data)
+			chartInfo := ConvertToBookMarkChart(data)
 			if err != nil {
 				logger.Error("获取数据失败: %v", err)
 			}

+ 35 - 1
domian/media/chart_service.go

@@ -2,7 +2,9 @@ package media
 
 import (
 	"encoding/json"
+	"eta/eta_mini_ht_api/common/component/es"
 	logger "eta/eta_mini_ht_api/common/component/log"
+	"strconv"
 )
 
 const (
@@ -50,7 +52,39 @@ type EsChartInfo struct {
 func AddChartToEs(esChart EsChartInfo) bool {
 	return elastic().InsertOrUpdate(htConfig.GetChartIndex(), esChart.ChartInfoId, esChart)
 }
-
+func matchRangeWithDocIdsNoLimit(key string, from int, to int, sorts []string, docIds []string) (request *es.ESQueryRequest) {
+	req := new(es.ESQueryRequest)
+	return req.CreateESQueryRequest(htConfig.GetReportIndex(), ESColumn, key, from, to, sorts, es.RangeByConditionWithDocIds).ByCondition("status", "PUBLISH").WithDocs(docIds)
+}
+func SearchChartList(key string, ids []int, from int, size int) (charts []EsChartInfo, err error) {
+	//同步es
+	var docIds []string
+	for _, id := range ids {
+		docIds = append(docIds, strconv.Itoa(id))
+	}
+	sorts := append(sortField)
+	request := matchRangeWithDocIdsNoLimit(key, from, size, sorts, docIds)
+	re, err := elastic().Search(request)
+	if err != nil {
+		logger.Error("es搜索异常:%v", err)
+	}
+	hits := elastic().GetSource(re.Hits)
+	if len(hits) == 0 {
+		return
+	}
+	for _, hit := range hits {
+		var content map[string][]string
+		err = json.Unmarshal(hit.Highlight, &content)
+		chart := EsChartInfo{}
+		err = json.Unmarshal(hit.Source, &chart)
+		if err != nil {
+			logger.Error("解析研报数据失败:%v", err)
+			continue
+		}
+		charts = append(charts, chart)
+	}
+	return
+}
 func UpdateChartImage(image string, id int) bool {
 	doc, err := elastic().Get(htConfig.GetChartIndex(), id)
 	if err != nil {

+ 6 - 29
service/media/chart_service.go

@@ -1,13 +1,12 @@
 package media
 
 import (
-	"encoding/json"
 	"eta/eta_mini_ht_api/common/component/config"
 	"eta/eta_mini_ht_api/common/component/es"
 	logger "eta/eta_mini_ht_api/common/component/log"
 	"eta/eta_mini_ht_api/common/contants"
+	"eta/eta_mini_ht_api/common/utils/page"
 	chartService "eta/eta_mini_ht_api/domian/media"
-	"strconv"
 )
 
 type ChartInfo struct {
@@ -40,40 +39,18 @@ func AddChartToEs(chartInfo ChartInfo) {
 		logger.Error("新增图表到ES失败, chartInfoId:%d,uniqueCode:%s", chartInfo.ChartInfoId, chartInfo.UniqueCode)
 	}
 }
-func SearchChartList(key string, ids []int, from int, size int) (charts []ChartInfo, err error) {
-	//同步es
-	var docIds []string
-	for _, id := range ids {
-		docIds = append(docIds, strconv.Itoa(id))
-	}
-	sorts := append(sortField)
-	request := matchRangeWithDocIds(key, from, size, sorts, docIds)
-	re, err := elastic().Search(request)
+func SearchChartList(key string, ids []int, pageInfo page.PageInfo) (charts []ChartInfo, err error) {
+	offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
+	esChart, err := chartService.SearchChartList(key, ids, offset, pageInfo.PageSize)
 	if err != nil {
-		logger.Error("es搜索异常:%v", err)
-	}
-	hits := elastic().GetSource(re.Hits)
-	if len(hits) == 0 {
 		return
 	}
-	for _, hit := range hits {
-		var content map[string][]string
-		err = json.Unmarshal(hit.Highlight, &content)
-		chart := ChartInfo{}
-		err = json.Unmarshal(hit.Source, &chart)
-		if err != nil {
-			logger.Error("解析研报数据失败:%v", err)
-			continue
-		}
-		charts = append(charts, chart)
+	for _, chart := range esChart {
+		charts = append(charts, convertChartInfo(chart))
 	}
 	return
 }
 
-func matchRangeWithDocIds(key string, from int, to int, sorts []string, docIds []string) (request *es.ESQueryRequest) {
-	req := new(es.ESQueryRequest)
-	return req.CreateESQueryRequest(htConfig.GetReportIndex(), ESColumn, key, from, to, sorts, es.RangeByConditionWithDocIds).ByCondition("status", "PUBLISH").WithDocs(docIds)
-}
 func UpdateChartImage(image string, id int) bool {
 	return chartService.UpdateChartImage(image, id)
 }

+ 1 - 1
service/report/report_service.go

@@ -219,7 +219,7 @@ func SearchReportBookMark(key string, Ids []int, pageInfo page.PageInfo, isLogin
 	}
 	offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
 	var reports []reportService.ReportDTO
-	reports, err = reportService.SearchReportList(key, Ids, offset, pageInfo.PageSize, -1)
+	reports, err = reportService.SearchReportList(key, Ids, offset, pageInfo.PageSize, pageInfo.LatestId)
 	list, err = dealReportInfo(reports, isLogin, userId, mappingRiskLevel, userRiskStatus)
 	if err != nil {
 		err = exception.New(exception.SearchReportPageFailed)

+ 4 - 75
service/user/user_service.go

@@ -13,8 +13,6 @@ import (
 	merchantDao "eta/eta_mini_ht_api/models/merchant"
 	userDao "eta/eta_mini_ht_api/models/user"
 	"eta/eta_mini_ht_api/service/config"
-	chartService "eta/eta_mini_ht_api/service/media"
-	reportService "eta/eta_mini_ht_api/service/report"
 	"gorm.io/gorm"
 	"sort"
 	"sync"
@@ -594,76 +592,7 @@ func (bk BookMarkChart) GetID() int {
 func (bk BookMarkChart) GetSourceType() string {
 	return ChartBookMark
 }
-func SearchBookMark(key string, sourceType string, ids []int, pageInfo page.PageInfo, userId int) (list []BookMarkInterface, err error) {
-	switch sourceType {
-	case ReportBookMark:
-		reportList, reportErr := reportService.SearchReportBookMark(key, ids, pageInfo, true, userId)
-		if reportErr != nil {
-			logger.Error("搜索研报列表失败%v", err)
-			err = exception.NewWithException(exception.GetBookMarkListFailed, reportErr.Error())
-			return
-		}
-		for _, report := range reportList {
-			list = append(list, ConvertToBookMarkReport(report))
-		}
-		return
-	case ChartBookMark:
-		offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
-		chartList, chartErr := chartService.SearchChartList(key, ids, offset, pageInfo.PageSize)
-		if chartErr != nil {
-			logger.Error("搜索研报列表失败%v", err)
-			err = exception.NewWithException(exception.GetBookMarkListFailed, chartErr.Error())
-			return
-		}
-		for _, chart := range chartList {
-			list = append(list, ConvertToBookMarkChart(chart))
-		}
-		return
-	default:
-		err = exception.NewWithException(exception.GetBookMarkListFailed, "不支持的收藏类型")
-		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,
-	}
-}
+
+// func SearchBookMark(key string, sourceType string, ids []int, pageInfo page.PageInfo, userId int) (list []BookMarkInterface, err error) {
+//
+// }