Browse Source

订阅中心

kobe6258 4 months ago
parent
commit
7913fce7dd

+ 51 - 55
controllers/home/home_controller.go

@@ -1,11 +1,7 @@
 package home
 
 import (
-	"eta/eta_mini_ht_api/common/exception"
-	"eta/eta_mini_ht_api/common/utils/page"
 	"eta/eta_mini_ht_api/controllers"
-	reportService "eta/eta_mini_ht_api/domian/report"
-	"eta/eta_mini_ht_api/service/report"
 )
 
 type HomeController struct {
@@ -19,57 +15,57 @@ type HomeController struct {
 func (r *HomeController) Search(key string) {
 	controllers.Wrap(&r.BaseController, func() (result *controllers.WrapData, err error) {
 		result = r.InitWrapData("分页搜索报告列表失败")
-		if key == "" {
-			err = exception.New(exception.SearchKeyEmptyError)
-			r.FailedResult("分页搜索报告列表失败", result)
-			return
-		}
-		detailType := r.Data["detailType"].(string)
-		userInfo := r.Data["user"].(user.User)
-		pageRes := page.Page{
-			Current:  r.PageInfo.Current,
-			PageSize: r.PageInfo.PageSize,
-		}
-		//获取当前可以被搜索的报告原始ID
-		//先要限制查询的id范围
-		var reportIds []int
-		pageRes.Total, pageRes.LatestId, reportIds, err = report.RangeSearch(key, isLogin(detailType), userInfo.Id)
-		if err != nil {
-			logger.Error("获取报告原始ID列表失败:%v", err)
-			r.FailedResult("分页搜索报告列表失败", result)
-			return
-		}
-		if len(reportIds) == 0 {
-			reports := new(page.PageResult)
-			reports.Data = []reportService.ReportDTO{}
-			reports.Page = pageRes
-			logger.Info("没有可以查询的报告列表")
-			r.SuccessResult("分页搜索报告列表成功", reports, result)
-			return
-		}
-
-		if r.PageInfo.LatestId == 0 {
-			//pageRes.Total, pageRes.LatestId = report.SearchMaxReportId(key)
-			r.PageInfo.LatestId = pageRes.LatestId
-			r.PageInfo.Total = pageRes.Total
-		} else {
-			pageRes.LatestId = r.PageInfo.LatestId
-			pageRes.Total = r.PageInfo.Total
-		}
-		pageRes.TotalPage = page.TotalPages(pageRes.Total, pageRes.PageSize)
-		list := make([]reportService.ReportDTO, 0)
-		if pageRes.LatestId > 0 {
-			//订阅 TODO
-			list, err = report.SearchReportList(key, reportIds, r.PageInfo, isLogin(detailType), userInfo.Id)
-			if err != nil {
-				r.FailedResult("分页搜索报告列表失败", result)
-				return
-			}
-		}
-		reports := new(page.PageResult)
-		reports.Data = list
-		reports.Page = pageRes
-		r.SuccessResult("分页搜索报告列表成功", reports, result)
+		//if key == "" {
+		//	err = exception.New(exception.SearchKeyEmptyError)
+		//	r.FailedResult("分页搜索报告列表失败", result)
+		//	return
+		//}
+		//detailType := r.Data["detailType"].(string)
+		//userInfo := r.Data["user"].(user.User)
+		//pageRes := page.Page{
+		//	Current:  r.PageInfo.Current,
+		//	PageSize: r.PageInfo.PageSize,
+		//}
+		////获取当前可以被搜索的报告原始ID
+		////先要限制查询的id范围
+		//var reportIds []int
+		//pageRes.Total, pageRes.LatestId, reportIds, err = report.RangeSearch(key, isLogin(detailType), userInfo.Id)
+		//if err != nil {
+		//	logger.Error("获取报告原始ID列表失败:%v", err)
+		//	r.FailedResult("分页搜索报告列表失败", result)
+		//	return
+		//}
+		//if len(reportIds) == 0 {
+		//	reports := new(page.PageResult)
+		//	reports.Data = []reportService.ReportDTO{}
+		//	reports.Page = pageRes
+		//	logger.Info("没有可以查询的报告列表")
+		//	r.SuccessResult("分页搜索报告列表成功", reports, result)
+		//	return
+		//}
+		//
+		//if r.PageInfo.LatestId == 0 {
+		//	//pageRes.Total, pageRes.LatestId = report.SearchMaxReportId(key)
+		//	r.PageInfo.LatestId = pageRes.LatestId
+		//	r.PageInfo.Total = pageRes.Total
+		//} else {
+		//	pageRes.LatestId = r.PageInfo.LatestId
+		//	pageRes.Total = r.PageInfo.Total
+		//}
+		//pageRes.TotalPage = page.TotalPages(pageRes.Total, pageRes.PageSize)
+		//list := make([]reportService.ReportDTO, 0)
+		//if pageRes.LatestId > 0 {
+		//	//订阅 TODO
+		//	list, err = report.SearchReportList(key, reportIds, r.PageInfo, isLogin(detailType), userInfo.Id)
+		//	if err != nil {
+		//		r.FailedResult("分页搜索报告列表失败", result)
+		//		return
+		//	}
+		//}
+		//reports := new(page.PageResult)
+		//reports.Data = list
+		//reports.Page = pageRes
+		//r.SuccessResult("分页搜索报告列表成功", reports, result)
 		return
 	})
 }

+ 6 - 1
service/product/product_service.go

@@ -392,7 +392,8 @@ func LatestId() (latestId int64) {
 }
 
 func CountSearchPackageList(list []reportDomain.ProductSearchDTO) (total, latestId int64, permissionTotalMap map[int]*atomic.Int32) {
-	var productIdMap map[string][]int
+	productIdMap := make(map[string][]int, len(list))
+	permissionTotalMap = make(map[int]*atomic.Int32)
 	for _, product := range list {
 		ids := productIdMap[product.SourceType]
 		ids = append(ids, product.SourceId)
@@ -402,6 +403,7 @@ func CountSearchPackageList(list []reportDomain.ProductSearchDTO) (total, latest
 	wg.Add(len(productIdMap))
 	for key, ids := range productIdMap {
 		go func(k string, ids []int) {
+			defer wg.Done()
 			var permissionMap map[int]int
 			switch k {
 			case "report":
@@ -410,6 +412,9 @@ func CountSearchPackageList(list []reportDomain.ProductSearchDTO) (total, latest
 				permissionMap = mediaService.CountPermissionWeight(ids)
 			}
 			for permissionId, weight := range permissionMap {
+				if permissionTotalMap[permissionId] == nil {
+					permissionTotalMap[permissionId] = new(atomic.Int32)
+				}
 				permissionTotalMap[permissionId].Add(int32(weight))
 			}
 		}(key, ids)

+ 1 - 0
service/report/report_service.go

@@ -709,6 +709,7 @@ func getCountByAnalyst(permissionIds []int, isLogin bool, userId int, analystNam
 
 func CountPermissionWeight(ids []int) (permissionMap map[int]int) {
 	list, err := reportService.CountPermissionWeight(ids)
+	permissionMap = make(map[int]int)
 	if err != nil {
 		return
 	}