|
@@ -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
|
|
|
}
|