Bladeren bron

报告增加产品信息筛选

kobe6258 4 maanden geleden
bovenliggende
commit
6b0992be9e

+ 3 - 3
models/merchant/merchant_product.go

@@ -12,8 +12,8 @@ type SaleStatus string
 type MerchantProductType string
 
 const (
-	detailColumns  = "id,title,price,is_permanent,valid_days,type,risk_level,sale_status,cover_src,description,source_id"
-	sourceIdColumn = "id,risk_level,source_id"
+	detailColumns  = "id,title,price,is_permanent,valid_days,type,sale_status,cover_src,description,source_id"
+	sourceIdColumn = "id,source_id"
 )
 const (
 	OnSale  SaleStatus          = "on_sale"  //上架
@@ -32,7 +32,7 @@ type MerchantProduct struct {
 	CoverSrc    string              `gorm:"column:cover_src;type:varchar(255);comment:封面图片"`
 	Description string              `gorm:"column:description;type:varchar(255);comment:描述"`
 	Price       decimal.Decimal     `gorm:"column:price;type:decimal(10,2);comment:价格"`
-	RiskLevel   string              `gorm:"column:risk_level;type:varchar(255);not null;comment:风险等级"`
+	RiskLevel   string              `gorm:"-"`
 	Type        MerchantProductType `gorm:"column:type;type:enum('report','video','audio','package');not null;comment:类型"`
 	IsPermanent bool                `gorm:"column:is_permanent;type:int(1);not null;default:0;comment:是否永久"`
 	ValidDays   int                 `gorm:"column:valid_days;type:int(11);comment:有效期天数"`

+ 1 - 1
models/merchant/user_subscription_access_list.go

@@ -45,7 +45,7 @@ func (UserSubscriptionAccessList) TableName() string {
 
 func GetUserSubscribe(productId int, userId int) (userSubscriptionAccessList UserSubscriptionAccessList, err error) {
 	db := models.Main()
-	err = db.Select("id,user_id,product_id,product_name,begin_date,end_date,status").Where("user_id=? and product_id=?", userId, productId).First(&userSubscriptionAccessList).Error
+	err = db.Select("id,template_user_id,product_id,product_name,begin_date,end_date,status").Where("template_user_id=? and product_id=?", userId, productId).First(&userSubscriptionAccessList).Error
 	return
 }
 

+ 34 - 205
service/report/report_service.go

@@ -68,13 +68,6 @@ type HotRankedReport struct {
 	Login             bool           `json:"login"`
 }
 
-//type PermissionNode struct {
-//	ID       int               `json:"id"`
-//	Name     string            `json:"name"`
-//	ParentID int               `json:"parentId"`
-//	Children []*PermissionNode `json:"children,omitempty"`
-//}
-
 type RecordCount struct {
 	UserId     int
 	TraceId    string
@@ -399,7 +392,6 @@ func GetRandedReportByWeeklyHot(limit int, isLogin bool, userId int, pdRiskLevel
 	end := time.Now()
 	begin := date.GetBeginOfTheWeek(end, time.Monday)
 	hotReports := userService.GetHotReports(begin.Format(time.DateOnly), end.Format(time.DateOnly), limit)
-
 	if len(hotReports) > 0 {
 		var dtoList []reportService.ReportDTO
 		var ids []int
@@ -412,118 +404,33 @@ func GetRandedReportByWeeklyHot(limit int, isLogin bool, userId int, pdRiskLevel
 			err = exception.New(exception.GetHotRandListFailed)
 			return
 		}
+		dtoList, err = dealReportInfo(dtoList, isLogin, userId)
+		if err != nil {
+			logger.Error("获取本周最热研报列表失败:%v", err)
+			err = exception.New(exception.GetHotRandListFailed)
+			return
+		}
 		var filterList []reportService.ReportDTO
 		if pdRiskLevel != "" {
 			for _, report := range dtoList {
-				product, pdErr := productService.GetProductBySourceId(report.ReportID, productDao.Report)
-				if pdErr != nil {
-					if errors.Is(pdErr, gorm.ErrRecordNotFound) {
-						report.Price = defaultProductPrice
-						report.IsFree = true
-						report.IsSubscribe = false
-					} else {
-						logger.Error("查询产品失败:%v", pdErr)
-						report.Price = defaultProductPrice
-						report.IsFree = false
-						report.IsSubscribe = false
-					}
-					filterList = append(filterList, report)
-				} else {
-					pdRiskNum, paresErr := config.ParseRiskLevel(product.RiskLevel)
-					if paresErr != nil {
-						logger.Error("解析风险等级失败:%v", err)
-						continue
-					}
-					reRiskNum, paresErr := config.ParseRiskLevel(pdRiskLevel)
-					if paresErr != nil {
-						logger.Error("解析风险等级失败:%v", err)
-						continue
-					}
-					report.RiskLevel = product.RiskLevel
-					if isLogin {
-						subscribe, subErr := userService.GetUserSubscribe(product.Id, userId)
-						if subErr != nil {
-							logger.Error("查询用户订阅信息失败:%v,productId:%v,userId:%v", err, product.Id, userId)
-							report.Price = product.Price.String()
-							report.IsFree = false
-							report.IsSubscribe = false
-						} else {
-							report.Price = product.Price.String()
-							report.IsFree = false
-							report.IsSubscribe = subscribe.Status == productDao.SubscribeValid
-						}
-					}
-					if pdRiskNum <= reRiskNum {
-						filterList = append(filterList, report)
-					}
+				pdRiskNum, paresErr := config.ParseRiskLevel(report.RiskLevel)
+				if paresErr != nil {
+					logger.Error("解析风险等级失败:%v", err)
+					continue
 				}
-			}
-		} else {
-			filterList = dtoList
-			for _, report := range filterList {
-				product, pdErr := productService.GetProductBySourceId(report.ReportID, productDao.Report)
-				if pdErr != nil {
-					if errors.Is(pdErr, gorm.ErrRecordNotFound) {
-						report.Price = defaultProductPrice
-						report.IsFree = true
-						report.IsSubscribe = false
-					} else {
-						logger.Error("查询产品失败:%v", pdErr)
-						report.Price = defaultProductPrice
-						report.IsFree = false
-						report.IsSubscribe = false
-					}
-				} else {
-					report.Price = product.Price.String()
-					report.IsFree = false
-					report.IsSubscribe = false
-					report.RiskLevel = product.RiskLevel
+				reRiskNum, paresErr := config.ParseRiskLevel(pdRiskLevel)
+				if paresErr != nil {
+					logger.Error("解析风险等级失败:%v", err)
+					continue
 				}
-			}
-		}
 
-		var wg sync.WaitGroup
-		wg.Add(len(filterList))
-		for i := 0; i < len(filterList); i++ {
-			go func(report *reportService.ReportDTO) {
-				defer wg.Done()
-				report.Login = isLogin
-				report.Permissions = getReportPermissionsMap(report.OrgId, report.Source)
-				report.SecondPermission = getReportSecondPermissionsMap(report.OrgId, report.Source)
-				permissions := getReportSecondPermissions(report.OrgId, report.Source)
-				var riskNum int
-				if len(permissions) == 0 {
-					riskNum = 0
-				} else {
-					riskNum = config.GetHighestRiskLevel(permissions)
-				}
-				if report.RiskLevel == "" {
-					report.RiskLevel = strings.Join([]string{"R", strconv.Itoa(riskNum)}, "")
-				} else {
-					reRiskNum, paresErr := config.ParseRiskLevel(report.RiskLevel)
-					if paresErr != nil {
-						logger.Error("解析风险等级失败:%v", err)
-						report.RiskLevel = strings.Join([]string{"R", strconv.Itoa(riskNum)}, "")
-					} else {
-						if reRiskNum <= riskNum {
-							report.RiskLevel = strings.Join([]string{"R", strconv.Itoa(riskNum)}, "")
-						}
-					}
-				}
-				var label []string
-				for _, permission := range report.Permissions {
-					label = append(label, permission)
+				if pdRiskNum <= reRiskNum {
+					filterList = append(filterList, report)
 				}
-				report.PermissionNames = label
-			}(&filterList[i])
+			}
 		}
-		wg.Wait()
 		reports = make([]HotRankedReport, len(ids))
 		for i := 0; i < len(filterList); i++ {
-			risk, parseErr := config.ParseRiskLevel(filterList[i].RiskLevel)
-			if parseErr != nil || risk == 0 {
-				continue
-			}
 			report := convertToHotRankedReport(filterList[i])
 			for j := 0; j < len(hotReports); j++ {
 				if hotReports[j].ReportId == report.Id {
@@ -547,107 +454,29 @@ func GetRandedReportByPublishTimeWeekly(limit int, week bool, isLogin bool, user
 		return
 	}
 	var filterList []reportService.ReportDTO
+	dtoList, err = dealReportInfo(dtoList, isLogin, userId)
+	if err != nil {
+		logger.Error("获取最新发布的研报列表失败:%v", err)
+		err = exception.New(exception.GetPublishedRandListFailed)
+		return
+	}
 	if pdRiskLevel != "" {
 		for _, report := range dtoList {
-			product, pdErr := productService.GetProductBySourceId(report.ReportID, productDao.Report)
-			if pdErr != nil {
-				if errors.Is(pdErr, gorm.ErrRecordNotFound) {
-					report.Price = defaultProductPrice
-					report.IsFree = true
-					report.IsSubscribe = false
-				} else {
-					logger.Error("查询产品失败:%v", pdErr)
-					report.Price = defaultProductPrice
-					report.IsFree = false
-					report.IsSubscribe = false
-				}
-				filterList = append(filterList, report)
-			} else {
-				pdRiskNum, paresErr := config.ParseRiskLevel(product.RiskLevel)
-				if paresErr != nil {
-					logger.Error("解析风险等级失败:%v", err)
-					continue
-				}
-				reRiskNum, paresErr := config.ParseRiskLevel(pdRiskLevel)
-				if paresErr != nil {
-					logger.Error("解析风险等级失败:%v", err)
-					continue
-				}
-				report.RiskLevel = product.RiskLevel
-				if isLogin {
-					subscribe, subErr := userService.GetUserSubscribe(product.Id, userId)
-					if subErr != nil {
-						logger.Error("查询用户订阅信息失败:%v,productId:%v,userId:%v", err, product.Id, userId)
-						report.Price = product.Price.String()
-						report.IsFree = false
-						report.IsSubscribe = false
-					} else {
-						report.Price = product.Price.String()
-						report.IsFree = false
-						report.IsSubscribe = subscribe.Status == productDao.SubscribeValid
-					}
-				}
-				if pdRiskNum <= reRiskNum {
-					filterList = append(filterList, report)
-				}
-			}
-		}
-	} else {
-		filterList = dtoList
-		for _, report := range filterList {
-			product, pdErr := productService.GetProductBySourceId(report.ReportID, productDao.Report)
-			if pdErr != nil {
-				if errors.Is(pdErr, gorm.ErrRecordNotFound) {
-					report.Price = defaultProductPrice
-					report.IsFree = true
-					report.IsSubscribe = false
-				} else {
-					logger.Error("查询产品失败:%v", pdErr)
-					report.Price = defaultProductPrice
-					report.IsFree = false
-					report.IsSubscribe = false
-				}
-			} else {
-				report.Price = product.Price.String()
-				report.IsFree = false
-				report.IsSubscribe = false
-				report.RiskLevel = product.RiskLevel
+			pdRiskNum, paresErr := config.ParseRiskLevel(report.RiskLevel)
+			if paresErr != nil {
+				logger.Error("解析风险等级失败:%v", err)
+				continue
 			}
-		}
-	}
-	//并发获取研报的标签
-	var wg sync.WaitGroup
-	wg.Add(len(filterList))
-	for i := 0; i < len(filterList); i++ {
-		go func(report *reportService.ReportDTO) {
-			defer wg.Done()
-			report.Login = isLogin
-			report.Permissions = getReportPermissionsMap(report.OrgId, report.Source)
-			report.SecondPermission = getReportSecondPermissionsMap(report.OrgId, report.Source)
-			report.PermissionNames = getReportPermissionNames(report.OrgId, report.Source)
-			var riskNum int
-			permissions := getReportSecondPermissions(report.OrgId, report.Source)
-			if len(permissions) == 0 {
-				riskNum = 0
-			} else {
-				riskNum = config.GetHighestRiskLevel(permissions)
+			reRiskNum, paresErr := config.ParseRiskLevel(pdRiskLevel)
+			if paresErr != nil {
+				logger.Error("解析风险等级失败:%v", err)
+				continue
 			}
-			if report.RiskLevel == "" {
-				report.RiskLevel = strings.Join([]string{"R", strconv.Itoa(riskNum)}, "")
-			} else {
-				reRiskNum, paresErr := config.ParseRiskLevel(report.RiskLevel)
-				if paresErr != nil {
-					logger.Error("解析风险等级失败:%v", err)
-					report.RiskLevel = strings.Join([]string{"R", strconv.Itoa(riskNum)}, "")
-				} else {
-					if reRiskNum <= riskNum {
-						report.RiskLevel = strings.Join([]string{"R", strconv.Itoa(riskNum)}, "")
-					}
-				}
+			if pdRiskNum <= reRiskNum {
+				filterList = append(filterList, report)
 			}
-		}(&filterList[i])
+		}
 	}
-	wg.Wait()
 	reports = convertToPublishRankedReportList(filterList)
 	return
 }