|
@@ -13,7 +13,7 @@ import (
|
|
|
reportService "eta/eta_mini_ht_api/domian/report"
|
|
|
userService "eta/eta_mini_ht_api/domian/user"
|
|
|
productDao "eta/eta_mini_ht_api/models/merchant"
|
|
|
- userDao "eta/eta_mini_ht_api/models/user"
|
|
|
+ "eta/eta_mini_ht_api/service/config"
|
|
|
user "eta/eta_mini_ht_api/service/user"
|
|
|
"fmt"
|
|
|
"gorm.io/gorm"
|
|
@@ -45,9 +45,11 @@ type PublishRankedReport struct {
|
|
|
CoverUrl string `json:"coverUrl"`
|
|
|
RiskLevel string `json:"riskLevel"`
|
|
|
IsFree bool `json:"isFree"`
|
|
|
+ IsPackage bool `json:"isPackage"`
|
|
|
Price string `json:"price"`
|
|
|
IsSubscribe bool `json:"isSubscribe"`
|
|
|
Login bool `json:"login"`
|
|
|
+ ProductId int `json:"productId"`
|
|
|
}
|
|
|
|
|
|
type HotRankedReport struct {
|
|
@@ -64,17 +66,12 @@ type HotRankedReport struct {
|
|
|
RiskLevel string `json:"riskLevel"`
|
|
|
IsFree bool `json:"isFree"`
|
|
|
Price string `json:"price"`
|
|
|
+ IsPackage bool `json:"isPackage"`
|
|
|
+ ProductId int `json:"productId"`
|
|
|
IsSubscribe bool `json:"isSubscribe"`
|
|
|
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
|
|
@@ -86,7 +83,7 @@ type RecordCount struct {
|
|
|
Additional string
|
|
|
}
|
|
|
|
|
|
-func matchRiskLevel(userId int, report reportService.ReportDTO) (riskLevelMatch string, err error) {
|
|
|
+func matchRiskLevel(userId int, report reportService.ReportDTO) (riskLevelMatch string, riskLevel string, err error) {
|
|
|
userProfile, userErr := user.GetUserProfile(userId)
|
|
|
if userErr != nil {
|
|
|
if errors.Is(userErr, gorm.ErrRecordNotFound) {
|
|
@@ -131,7 +128,7 @@ func matchRiskLevel(userId int, report reportService.ReportDTO) (riskLevelMatch
|
|
|
return
|
|
|
}
|
|
|
//能够查看最高等级
|
|
|
- matchNum, err := parseRiskLevel(level.ProductRiskLevel)
|
|
|
+ matchNum, err := config.ParseRiskLevel(level.ProductRiskLevel)
|
|
|
if err != nil {
|
|
|
logger.Error("解析风险等级失败:%v", err)
|
|
|
return
|
|
@@ -142,7 +139,9 @@ func matchRiskLevel(userId int, report reportService.ReportDTO) (riskLevelMatch
|
|
|
return
|
|
|
}
|
|
|
//能够查看需要的最小等级
|
|
|
- num := getLowestRiskLevel(permissionDTOs)
|
|
|
+ //num := getLowestRiskLevel(permissionDTOs)
|
|
|
+ num := config.GetHighestRiskLevel(permissionDTOs)
|
|
|
+ riskLevel = fmt.Sprintf("R%d", num)
|
|
|
if num > matchNum {
|
|
|
riskLevelMatch = RiskLevelUnMatch
|
|
|
return
|
|
@@ -151,85 +150,124 @@ func matchRiskLevel(userId int, report reportService.ReportDTO) (riskLevelMatch
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
-func getHighestRiskLevel(permissions []permissionService.PermissionDTO) (riskLevelNum int) {
|
|
|
- for _, permission := range permissions {
|
|
|
- pRiskNum, err := parseRiskLevel(permission.RiskLevel)
|
|
|
- if err != nil {
|
|
|
- logger.Error("解析风险等级失败:%v", err)
|
|
|
- continue
|
|
|
- }
|
|
|
- if riskLevelNum == 0 {
|
|
|
- riskLevelNum = pRiskNum
|
|
|
- } else {
|
|
|
- if riskLevelNum < pRiskNum {
|
|
|
- riskLevelNum = pRiskNum
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+func GetReportById(reportId int, login bool, userId int) (report *reportService.ReportDTO, err error) {
|
|
|
+ var reportInfo reportService.ReportDTO
|
|
|
+ reportInfo, err = reportService.GetReportById(reportId, userId)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取研报失败:%v,研报ID:%d", err, report.ReportID)
|
|
|
+ err = exception.NewWithException(exception.GetReportFailed, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ mappingRiskLevel, userRiskStatus, err := user.CheckUserRiskMatchStatus(userId)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取研报失败:%v,研报ID:%d", err, report.ReportID)
|
|
|
+ err = exception.NewWithException(exception.GetReportFailed, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ report, err = DealReportInfo(&reportInfo, login, userId, mappingRiskLevel, userRiskStatus)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取研报失败:%v,研报ID:%d", err, report.ReportID)
|
|
|
+ err = exception.NewWithException(exception.GetReportFailed, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = getReportContent(report, login)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取研报失败:%v,研报ID:%d", err, report.ReportID)
|
|
|
+ err = exception.NewWithException(exception.GetReportFailed, err.Error())
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
-func getLowestRiskLevel(permissions []permissionService.PermissionDTO) (riskLevelNum int) {
|
|
|
- for _, permission := range permissions {
|
|
|
- pRiskNum, err := parseRiskLevel(permission.RiskLevel)
|
|
|
- if err != nil {
|
|
|
- logger.Error("解析风险等级失败:%v", err)
|
|
|
- continue
|
|
|
- }
|
|
|
- if riskLevelNum == 0 {
|
|
|
- riskLevelNum = pRiskNum
|
|
|
- } else {
|
|
|
- if riskLevelNum > pRiskNum {
|
|
|
- riskLevelNum = pRiskNum
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+func GetTotalPageCountByPermissionIds(permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, ids map[string][]int, disCardIds []int, mappingRiskLevel, userRiskStatus string) {
|
|
|
+ return getCount(permissionIds, isLogin, userId)
|
|
|
+}
|
|
|
+
|
|
|
+// ParseRiskLevel 解析风险等级字符串,并返回数字部分
|
|
|
+
|
|
|
+func SearchReportList(key string, Ids []int, pageInfo page.PageInfo, isLogin bool, userId int, mappingRiskLevel, userRiskStatus string) (list []reportService.ReportDTO, err error) {
|
|
|
+ offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
|
|
|
+ var reports []reportService.ReportDTO
|
|
|
+ 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)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
-func GetReportById(reportId int, login bool, userId int) (report reportService.ReportDTO, err error) {
|
|
|
- report, err = reportService.GetGetReportById(reportId)
|
|
|
+
|
|
|
+func SearchReportProduct(key string, docIds []int) (list []reportService.ReportDTO, err error) {
|
|
|
+ list, err = reportService.SearchReportProduct(key, 100, 0, docIds)
|
|
|
if err != nil {
|
|
|
- logger.Error("获取研报失败:%v", err)
|
|
|
- err = exception.New(exception.GetReportFailed)
|
|
|
- return
|
|
|
+ err = exception.New(exception.SearchReportPageFailed)
|
|
|
}
|
|
|
- var status string
|
|
|
- status, err = matchRiskLevel(userId, report)
|
|
|
+ return
|
|
|
+}
|
|
|
+func RangeSearchByAnalyst(analystName string, userId int) (total int64, latestId int64, ids []int, mappingRiskLevel, userRiskStatus string) {
|
|
|
+ return getCountByAnalyst(nil, true, userId, analystName)
|
|
|
+}
|
|
|
+func RangeSearch(key string, isLogin bool, userId int) (total int64, latestId int64, reportIds []int, discardIds []int, mappingRiskLevel, userRiskStatus string, err error) {
|
|
|
+ var orgIds map[string][]int
|
|
|
+ _, latestId, orgIds, discardIds, mappingRiskLevel, userRiskStatus = getCount(nil, isLogin, userId)
|
|
|
+ reportIds, err = GetReportByIdListByOrgIds(orgIds)
|
|
|
if err != nil {
|
|
|
- logger.Error("匹配风险等级失败:%v", err)
|
|
|
- err = exception.New(exception.ReportRiskLevelUnSet)
|
|
|
+ logger.Error("获取报告ID列表失败:%v", err)
|
|
|
+ err = exception.NewWithException(exception.GetReportSearchRangeFailed, err.Error())
|
|
|
return
|
|
|
}
|
|
|
+ total = reportService.SearchMaxReportIdWithRange(key, reportIds)
|
|
|
+ return
|
|
|
+}
|
|
|
+func dealReportInfo(list []reportService.ReportDTO, isLogin bool, userId int, mappingRiskLevel, userRiskStatus string) (resultList []reportService.ReportDTO, err error) {
|
|
|
+ var wg sync.WaitGroup
|
|
|
+ wg.Add(len(list))
|
|
|
+ for i := 0; i < len(list); i++ {
|
|
|
+ go func(report *reportService.ReportDTO) {
|
|
|
+ defer wg.Done()
|
|
|
+ report, err = DealReportInfo(report, isLogin, userId, mappingRiskLevel, userRiskStatus)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("处理报告信息失败:%v", err)
|
|
|
+ }
|
|
|
+ }(&list[i])
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+ resultList = list
|
|
|
+ return
|
|
|
+}
|
|
|
+func getETAReportDetail(report *reportService.ReportDTO) (etaReport reportService.ETAReportDTO, err error) {
|
|
|
+ return reportService.GetETAReport(report.OrgId)
|
|
|
+}
|
|
|
+
|
|
|
+func getHTReportDetail(report *reportService.ReportDTO) (url string, err error) {
|
|
|
+ return reportService.GetHtReport(report.OrgId)
|
|
|
+}
|
|
|
+func getReportContent(report *reportService.ReportDTO, login bool) (err error) {
|
|
|
var pdfUrl string
|
|
|
switch report.Source {
|
|
|
case SourceETA:
|
|
|
var detail reportService.ETAReportDTO
|
|
|
- detail, err = getETAReportDetail(&report)
|
|
|
+ detail, err = getETAReportDetail(report)
|
|
|
if err != nil {
|
|
|
logger.Error("获取研报详情失败失败:%v", err)
|
|
|
- err = exception.New(exception.GetReportFailed)
|
|
|
return
|
|
|
}
|
|
|
if !login {
|
|
|
detail.Content = ""
|
|
|
- report.RiskLevelStatus = RiskLevelUnMatch
|
|
|
- report.Login = false
|
|
|
} else {
|
|
|
- if status != RiskLevelMatch {
|
|
|
+ if report.RiskLevelStatus != RiskLevelMatch {
|
|
|
detail.Content = ""
|
|
|
}
|
|
|
- report.RiskLevelStatus = status
|
|
|
- report.Login = true
|
|
|
}
|
|
|
var jsonStr []byte
|
|
|
jsonStr, err = json.Marshal(detail)
|
|
|
if err != nil {
|
|
|
logger.Error("生成研报详情失败:%v", err)
|
|
|
- err = exception.New(exception.GetReportFailed)
|
|
|
+ return
|
|
|
}
|
|
|
report.Detail = jsonStr
|
|
|
return
|
|
|
case SourceHT:
|
|
|
- pdfUrl, err = getHTReportDetail(&report)
|
|
|
+ pdfUrl, err = getHTReportDetail(report)
|
|
|
if err != nil {
|
|
|
logger.Error("获取研报详情失败失败:%v")
|
|
|
err = exception.New(exception.GetReportFailed)
|
|
@@ -237,14 +275,10 @@ func GetReportById(reportId int, login bool, userId int) (report reportService.R
|
|
|
}
|
|
|
if !login {
|
|
|
report.PdfUrl = ""
|
|
|
- report.RiskLevelStatus = RiskLevelUnMatch
|
|
|
- report.Login = false
|
|
|
} else {
|
|
|
- if status == RiskLevelMatch {
|
|
|
+ if report.RiskLevelStatus == RiskLevelMatch {
|
|
|
report.PdfUrl = pdfUrl
|
|
|
}
|
|
|
- report.RiskLevelStatus = status
|
|
|
- report.Login = true
|
|
|
}
|
|
|
return
|
|
|
default:
|
|
@@ -253,180 +287,159 @@ func GetReportById(reportId int, login bool, userId int) (report reportService.R
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-func getETAReportDetail(report *reportService.ReportDTO) (etaReport reportService.ETAReportDTO, err error) {
|
|
|
- return reportService.GetETAReport(report.OrgId)
|
|
|
-}
|
|
|
-
|
|
|
-func getHTReportDetail(report *reportService.ReportDTO) (url string, err error) {
|
|
|
- return reportService.GetHtReport(report.OrgId)
|
|
|
-}
|
|
|
-func GetTotalPageCountByPermissionIds(permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, ids map[string][]int) {
|
|
|
- return getCount(permissionIds, isLogin, userId)
|
|
|
-}
|
|
|
-func filterPermissionsByRisk(permissionList []permissionService.PermissionDTO, riskLevel string) (resultList []permissionService.PermissionDTO) {
|
|
|
- if riskLevel != "" {
|
|
|
- riskLevelNum, err := parseRiskLevel(riskLevel)
|
|
|
- if err != nil {
|
|
|
- logger.Error("风险等级解析失败:%v", err)
|
|
|
- return
|
|
|
- }
|
|
|
- for _, permission := range permissionList {
|
|
|
- pRiskNum, riskErr := parseRiskLevel(permission.RiskLevel)
|
|
|
- if riskErr != nil {
|
|
|
- logger.Error("解析品种风险等级失败 permission:%d,risk:%v", permission.PermissionId, permission.RiskLevel)
|
|
|
- continue
|
|
|
- }
|
|
|
- if pRiskNum <= riskLevelNum {
|
|
|
- resultList = append(resultList, permission)
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- resultList = permissionList
|
|
|
- }
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-// ParseRiskLevel 解析风险等级字符串,并返回数字部分
|
|
|
-func parseRiskLevel(level string) (int, error) {
|
|
|
- parts := strings.Split(level, "R")
|
|
|
- if len(parts) < 2 {
|
|
|
- return 0, fmt.Errorf("无效的风险等级: %s", level)
|
|
|
- }
|
|
|
- numberStr := parts[1]
|
|
|
- number, err := strconv.Atoi(numberStr)
|
|
|
- if err != nil {
|
|
|
- return 0, fmt.Errorf("无法将风险等级转换为数字: %s", err)
|
|
|
+func DealReportInfo(report *reportService.ReportDTO, isLogin bool, userId int, mappingRiskLevel, userRiskStatus string) (resultReport *reportService.ReportDTO, err error) {
|
|
|
+ report.Login = isLogin
|
|
|
+ report.Permissions, report.PermissionNames = GetReportPermissionNames(report.OrgId, report.Source)
|
|
|
+ var permissions []permissionService.PermissionDTO
|
|
|
+ permissions, report.SecondPermission = getReportSecondPermissions(report.OrgId, report.Source)
|
|
|
+ if len(permissions) == 0 {
|
|
|
+ resultReport = report
|
|
|
+ return
|
|
|
}
|
|
|
- return number, nil
|
|
|
-}
|
|
|
-
|
|
|
-func SearchReportList(key string, Ids []int, pageInfo page.PageInfo, isLogin bool, userId int) (list []reportService.ReportDTO, err error) {
|
|
|
- offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
|
|
|
- var reports []reportService.ReportDTO
|
|
|
- reports, err = reportService.SearchReportList(key, Ids, offset, pageInfo.PageSize, pageInfo.LatestId)
|
|
|
- list, err = dealReportInfo(reports, isLogin, userId)
|
|
|
+ riskNum := config.GetHighestRiskLevel(permissions)
|
|
|
+ report.RiskLevel = strings.Join([]string{"R", strconv.Itoa(riskNum)}, "")
|
|
|
+ var src string
|
|
|
+ src, err = mediaService.GetImageSrc(report.CoverSrc)
|
|
|
if err != nil {
|
|
|
- err = exception.New(exception.SearchReportPageFailed)
|
|
|
+ logger.Error("获取图片地址失败:%v", err)
|
|
|
+ src = ""
|
|
|
+ } else {
|
|
|
+ report.CoverUrl = src
|
|
|
}
|
|
|
- return
|
|
|
-}
|
|
|
-func RangeSearchByAnalyst(analystName string, userId int) (total int64, latestId int64, ids []int) {
|
|
|
- return getCountByAnalyst(nil, true, userId, analystName)
|
|
|
-}
|
|
|
-func RangeSearch(key string, isLogin bool, userId int) (total int64, latestId int64, reportIds []int, err error) {
|
|
|
- var orgIds map[string][]int
|
|
|
- _, latestId, orgIds = getCount(nil, isLogin, userId)
|
|
|
- reportIds, err = GetReportByIdListByOrgIds(orgIds)
|
|
|
- if err != nil {
|
|
|
- logger.Error("获取报告ID列表失败:%v", err)
|
|
|
- err = exception.NewWithException(exception.GetReportSearchRangeFailed, err.Error())
|
|
|
- return
|
|
|
+ //套餐信息
|
|
|
+ var packageList []productService.MerchantProductDTO
|
|
|
+ //查询产品信息
|
|
|
+ product, pdErr := productService.GetProductBySourceId(report.ReportID, productDao.Report)
|
|
|
+ var permissionIds []int
|
|
|
+ if len(permissions) > 0 {
|
|
|
+ for _, permission := range permissions {
|
|
|
+ permissionIds = append(permissionIds, permission.PermissionId)
|
|
|
+ }
|
|
|
+ //单品不存在的话查套餐
|
|
|
+ packageList, err = productService.GetProductListBySourceIds(permissionIds, "package")
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取套餐列表失败:%v", err)
|
|
|
+ }
|
|
|
}
|
|
|
- total = reportService.SearchMaxReportIdWithRange(key, reportIds)
|
|
|
- return
|
|
|
-}
|
|
|
-func dealReportInfo(list []reportService.ReportDTO, isLogin bool, userId int) (resultList []reportService.ReportDTO, err error) {
|
|
|
- var wg sync.WaitGroup
|
|
|
- wg.Add(len(list))
|
|
|
- for i := 0; i < len(list); i++ {
|
|
|
- go func(report *reportService.ReportDTO) {
|
|
|
- defer wg.Done()
|
|
|
- report.Login = isLogin
|
|
|
- report.PermissionNames = getReportPermissionNames(report.OrgId, report.Source)
|
|
|
- permissions := getReportSecondPermissions(report.OrgId, report.Source)
|
|
|
- if len(permissions) == 0 {
|
|
|
- return
|
|
|
+ if pdErr != nil {
|
|
|
+ //单品不存在的话查套餐
|
|
|
+ if len(packageList) == 0 {
|
|
|
+ logger.Error("获取套餐列表失败:%v", err)
|
|
|
+ report.Price = defaultProductPrice
|
|
|
+ report.IsFree = true
|
|
|
+ report.IsSubscribe = false
|
|
|
+ report.IsPackage = false
|
|
|
+ } else {
|
|
|
+ report.Price = packageList[0].Price
|
|
|
+ report.IsFree = false
|
|
|
+ report.IsSubscribe = false
|
|
|
+ report.IsPackage = true
|
|
|
+ report.ProductId = packageList[0].Id
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ report.Price = product.Price
|
|
|
+ report.IsFree = false
|
|
|
+ report.ProductId = product.Id
|
|
|
+ report.IsPackage = false
|
|
|
+ }
|
|
|
+ //最热最新的时候使用
|
|
|
+ productList := append(packageList)
|
|
|
+ if pdErr == nil {
|
|
|
+ productList = append(productList, product)
|
|
|
+ }
|
|
|
+ if len(productList) == 0 {
|
|
|
+ report.Show = true
|
|
|
+ } else {
|
|
|
+ for _, productItem := range productList {
|
|
|
+ if productItem.SaleStatus == "on_sale" {
|
|
|
+ report.Show = true
|
|
|
+ break
|
|
|
}
|
|
|
- riskNum := getHighestRiskLevel(permissions)
|
|
|
- report.RiskLevel = strings.Join([]string{"R", strconv.Itoa(riskNum)}, "")
|
|
|
- var src string
|
|
|
- src, err = mediaService.GetImageSrc(report.CoverSrc)
|
|
|
- if err != nil {
|
|
|
- logger.Error("获取图片地址失败:%v", err)
|
|
|
- src = ""
|
|
|
- } else {
|
|
|
- report.CoverUrl = src
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if isLogin {
|
|
|
+ var productIds []int
|
|
|
+ if len(packageList) > 0 {
|
|
|
+ for _, packageItem := range packageList {
|
|
|
+ productIds = append(productIds, packageItem.Id)
|
|
|
}
|
|
|
- //下查询产品信息
|
|
|
- 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 {
|
|
|
- report.Price = defaultProductPrice
|
|
|
- report.IsFree = false
|
|
|
- report.IsSubscribe = false
|
|
|
- }
|
|
|
- } else {
|
|
|
- report.Price = product.Price.String()
|
|
|
- report.IsFree = false
|
|
|
- if isLogin {
|
|
|
- subscribe, subscribeErr := userService.GetUserSubscribe(product.Id, userId)
|
|
|
- if subscribeErr != nil {
|
|
|
- report.IsSubscribe = false
|
|
|
- } else {
|
|
|
- report.IsSubscribe = subscribe.Status == userDao.SubscribeValid
|
|
|
- }
|
|
|
+ }
|
|
|
+ if product.Id > 0 {
|
|
|
+ productIds = append(productIds, product.Id)
|
|
|
+ }
|
|
|
+ subscribeList, subscribeErr := userService.GetUserSubscribe(productIds, userId)
|
|
|
+ if subscribeErr != nil {
|
|
|
+ report.IsSubscribe = false
|
|
|
+ } else {
|
|
|
+ for _, subscribe := range subscribeList {
|
|
|
+ if subscribe.Status == productDao.SubscribeValid {
|
|
|
+ report.IsSubscribe = true
|
|
|
+ break
|
|
|
}
|
|
|
- pdRiskNum, parseErr := parseRiskLevel(product.RiskLevel)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if userRiskStatus != user.RiskValid {
|
|
|
+ if userRiskStatus == user.RiskUnTest {
|
|
|
+ report.RiskLevelStatus = RiskLevelUnTest
|
|
|
+ }
|
|
|
+ if userRiskStatus == user.RiskExpired {
|
|
|
+ report.RiskLevelStatus = RiskLevelExpired
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ report.RiskLevelStatus = RiskLevelUnMatch
|
|
|
+ if mappingRiskLevel != "" {
|
|
|
+ mappingRiskNum, parseErr := config.ParseRiskLevel(mappingRiskLevel)
|
|
|
if parseErr != nil {
|
|
|
return
|
|
|
}
|
|
|
- rpRiskNum, parseErr := parseRiskLevel(report.RiskLevel)
|
|
|
+ var rpRiskNum int
|
|
|
+ rpRiskNum, parseErr = config.ParseRiskLevel(report.RiskLevel)
|
|
|
if parseErr != nil {
|
|
|
return
|
|
|
}
|
|
|
- if rpRiskNum <= pdRiskNum {
|
|
|
- report.RiskLevel = product.RiskLevel
|
|
|
+ if rpRiskNum <= mappingRiskNum {
|
|
|
+ report.RiskLevelStatus = RiskLevelMatch
|
|
|
}
|
|
|
}
|
|
|
- }(&list[i])
|
|
|
+ }
|
|
|
}
|
|
|
- wg.Wait()
|
|
|
- resultList = list
|
|
|
+ resultReport = report
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetReportPage 分页获取报告列表
|
|
|
-func GetReportPage(pageInfo page.PageInfo, orgIds map[string][]int, searchAll bool, isLogin bool, userId int) (reports []reportService.ReportDTO, err error) {
|
|
|
+func GetReportPage(pageInfo page.PageInfo, orgIds map[string][]int, discardIds []int, isLogin bool, userId int, mappingRiskLevel, userRiskStatus string) (reports []reportService.ReportDTO, err error) {
|
|
|
var list []reportService.ReportDTO
|
|
|
- list, err = reportService.GetReportPageByOrgIds(pageInfo, orgIds, searchAll)
|
|
|
- reports, err = dealReportInfo(list, isLogin, userId)
|
|
|
-
|
|
|
+ list, err = reportService.GetReportPageByOrgIds(pageInfo, orgIds, discardIds)
|
|
|
+ reports, err = dealReportInfo(list, isLogin, userId, mappingRiskLevel, userRiskStatus)
|
|
|
if err != nil {
|
|
|
err = exception.New(exception.QueryReportPageFailed)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
-func GetReportPageByAnalyst(pageInfo page.PageInfo, analyst string, reportIds []int) (list []reportService.ReportDTO, err error) {
|
|
|
+func GetReportPageByAnalyst(pageInfo page.PageInfo, analyst string, reportIds []int, templateUserId int, mappingRiskLevel, userRiskStatus string) (list []reportService.ReportDTO, err error) {
|
|
|
list, err = reportService.GetReportPageByAnalyst(pageInfo, analyst, reportIds)
|
|
|
- //并发获取研报的标签
|
|
|
- var wg sync.WaitGroup
|
|
|
- wg.Add(len(list))
|
|
|
- for i := 0; i < len(list); i++ {
|
|
|
- go func(report *reportService.ReportDTO) {
|
|
|
- defer wg.Done()
|
|
|
- report.PermissionNames = getReportPermissionNames(report.OrgId, report.Source)
|
|
|
- }(&list[i])
|
|
|
- }
|
|
|
- wg.Wait()
|
|
|
+ list, err = dealReportInfo(list, true, templateUserId, mappingRiskLevel, userRiskStatus)
|
|
|
if err != nil {
|
|
|
err = exception.New(exception.QueryReportPageFailed)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
func CountReport(count RecordCount) (traceId string, err error) {
|
|
|
+ report, err := reportService.GetReportById(count.ReportId, 0)
|
|
|
+ if err != nil {
|
|
|
+ err = exception.New(exception.GetReportFailed)
|
|
|
+ return
|
|
|
+ }
|
|
|
dto := convertToRecordCountDTO(count)
|
|
|
+ dto.SourceTitle = report.Title
|
|
|
return userService.CountReport(dto)
|
|
|
}
|
|
|
-func GetRandedReportByWeeklyHot(limit int, isLogin bool, userId int, pdRiskLevel string) (reports []HotRankedReport, err error) {
|
|
|
+func GetRandedReportByWeeklyHot(limit int, isLogin bool, userId int, mappingRiskLevel string, userRiskStatus string) (reports []HotRankedReport, err error) {
|
|
|
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
|
|
@@ -439,118 +452,39 @@ func GetRandedReportByWeeklyHot(limit int, isLogin bool, userId int, pdRiskLevel
|
|
|
err = exception.New(exception.GetHotRandListFailed)
|
|
|
return
|
|
|
}
|
|
|
+ dtoList, err = dealReportInfo(dtoList, isLogin, userId, mappingRiskLevel, userRiskStatus)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取本周最热研报列表失败:%v", err)
|
|
|
+ err = exception.New(exception.GetHotRandListFailed)
|
|
|
+ return
|
|
|
+ }
|
|
|
var filterList []reportService.ReportDTO
|
|
|
- if pdRiskLevel != "" {
|
|
|
+ if mappingRiskLevel != "" {
|
|
|
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
|
|
|
- }
|
|
|
+ pdRiskNum, paresErr := config.ParseRiskLevel(report.RiskLevel)
|
|
|
+ if paresErr != nil {
|
|
|
+ logger.Error("解析风险等级失败:%v", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ reRiskNum, paresErr := config.ParseRiskLevel(mappingRiskLevel)
|
|
|
+ if paresErr != nil {
|
|
|
+ logger.Error("解析风险等级失败:%v", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ if pdRiskNum <= reRiskNum && report.Show {
|
|
|
filterList = append(filterList, report)
|
|
|
- } else {
|
|
|
- pdRiskNum, paresErr := parseRiskLevel(product.RiskLevel)
|
|
|
- if paresErr != nil {
|
|
|
- logger.Error("解析风险等级失败:%v", err)
|
|
|
- continue
|
|
|
- }
|
|
|
- reRiskNum, paresErr := 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 == userDao.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
|
|
|
+ for _, report := range dtoList {
|
|
|
+ if report.Show {
|
|
|
+ filterList = append(filterList, report)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- 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 = getHighestRiskLevel(permissions)
|
|
|
- }
|
|
|
- if report.RiskLevel == "" {
|
|
|
- report.RiskLevel = strings.Join([]string{"R", strconv.Itoa(riskNum)}, "")
|
|
|
- } else {
|
|
|
- reRiskNum, paresErr := 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)
|
|
|
- }
|
|
|
- report.PermissionNames = label
|
|
|
- }(&filterList[i])
|
|
|
- }
|
|
|
- wg.Wait()
|
|
|
reports = make([]HotRankedReport, len(ids))
|
|
|
for i := 0; i < len(filterList); i++ {
|
|
|
- risk, parseErr := 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 {
|
|
@@ -566,7 +500,7 @@ func GetRandedReportByWeeklyHot(limit int, isLogin bool, userId int, pdRiskLevel
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func GetRandedReportByPublishTimeWeekly(limit int, week bool, isLogin bool, userId int, pdRiskLevel string) (reports []PublishRankedReport, err error) {
|
|
|
+func GetRandedReportByPublishTimeWeekly(limit int, week bool, isLogin bool, userId int, mappingRiskLevel, userRiskStatus string) (reports []PublishRankedReport, err error) {
|
|
|
dtoList, err := reportService.GetListOrderByConditionWeekly(week, "published_time", limit, reportService.DESC)
|
|
|
if err != nil {
|
|
|
logger.Error("获取最新发布的研报列表失败:%v", err)
|
|
@@ -574,119 +508,51 @@ func GetRandedReportByPublishTimeWeekly(limit int, week bool, isLogin bool, user
|
|
|
return
|
|
|
}
|
|
|
var filterList []reportService.ReportDTO
|
|
|
- if pdRiskLevel != "" {
|
|
|
+ dtoList, err = dealReportInfo(dtoList, isLogin, userId, mappingRiskLevel, userRiskStatus)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取最新发布的研报列表失败:%v", err)
|
|
|
+ err = exception.New(exception.GetPublishedRandListFailed)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if mappingRiskLevel != "" {
|
|
|
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
|
|
|
- }
|
|
|
+ pdRiskNum, paresErr := config.ParseRiskLevel(report.RiskLevel)
|
|
|
+ if paresErr != nil {
|
|
|
+ logger.Error("解析风险等级失败:%v", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ reRiskNum, paresErr := config.ParseRiskLevel(mappingRiskLevel)
|
|
|
+ if paresErr != nil {
|
|
|
+ logger.Error("解析风险等级失败:%v", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if pdRiskNum <= reRiskNum && report.Show {
|
|
|
filterList = append(filterList, report)
|
|
|
- } else {
|
|
|
- pdRiskNum, paresErr := parseRiskLevel(product.RiskLevel)
|
|
|
- if paresErr != nil {
|
|
|
- logger.Error("解析风险等级失败:%v", err)
|
|
|
- continue
|
|
|
- }
|
|
|
- reRiskNum, paresErr := 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 == userDao.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
|
|
|
+ for _, report := range dtoList {
|
|
|
+ if report.Show {
|
|
|
+ filterList = append(filterList, report)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //并发获取研报的标签
|
|
|
- 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 = getHighestRiskLevel(permissions)
|
|
|
- }
|
|
|
- if report.RiskLevel == "" {
|
|
|
- report.RiskLevel = strings.Join([]string{"R", strconv.Itoa(riskNum)}, "")
|
|
|
- } else {
|
|
|
- reRiskNum, paresErr := 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)}, "")
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }(&filterList[i])
|
|
|
- }
|
|
|
- wg.Wait()
|
|
|
reports = convertToPublishRankedReportList(filterList)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func getReportPermissionNames(id int, source string) (labels []string) {
|
|
|
+func GetReportPermissionNames(id int, source string) (permissionMap map[int]string, labels []string) {
|
|
|
permissions := reportService.GetReportPermissionsById(id, source)
|
|
|
- for _, permission := range permissions {
|
|
|
- labels = append(labels, permission.PermissionName)
|
|
|
+ permissionMap = make(map[int]string, len(permissions))
|
|
|
+ if len(permissions) > 0 {
|
|
|
+ for _, permission := range permissions {
|
|
|
+ labels = append(labels, permission.PermissionName)
|
|
|
+ permissionMap[permission.PermissionId] = permission.PermissionName
|
|
|
+ }
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
-func getReportSecondPermissionsMap(id int, source string) (permissionMap map[int]string) {
|
|
|
+func GetReportSecondPermissionsMap(id int, source string) (permissionMap map[int]string) {
|
|
|
permissionMap = make(map[int]string)
|
|
|
permissions := reportService.GetReportSecondPermissionsById(id, source)
|
|
|
for _, permission := range permissions {
|
|
@@ -695,9 +561,15 @@ func getReportSecondPermissionsMap(id int, source string) (permissionMap map[int
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func getReportSecondPermissions(id int, source string) (permissionList []permissionService.PermissionDTO) {
|
|
|
- return reportService.GetReportSecondPermissionsById(id, source)
|
|
|
-
|
|
|
+func getReportSecondPermissions(id int, source string) (permissionList []permissionService.PermissionDTO, secondPermissionMap map[int]string) {
|
|
|
+ permissionList = reportService.GetReportSecondPermissionsById(id, source)
|
|
|
+ if len(permissionList) > 0 {
|
|
|
+ secondPermissionMap = make(map[int]string, len(permissionList))
|
|
|
+ for _, permission := range permissionList {
|
|
|
+ secondPermissionMap[permission.PermissionId] = permission.PermissionName
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
func getReportPermissionsMap(id int, source string) (permissionMap map[int]string) {
|
|
|
permissionMap = make(map[int]string)
|
|
@@ -712,11 +584,6 @@ func GetPermissionList() (root *permissionService.PermissionNode, err error) {
|
|
|
}
|
|
|
|
|
|
func convertToHotRankedReport(dto reportService.ReportDTO) (report HotRankedReport) {
|
|
|
- src, err := mediaService.GetImageSrc(dto.CoverSrc)
|
|
|
- if err != nil {
|
|
|
- logger.Error("获取封面图片失败:%v", err)
|
|
|
- src = ""
|
|
|
- }
|
|
|
report = HotRankedReport{
|
|
|
Id: dto.ReportID,
|
|
|
OrgId: dto.OrgId,
|
|
@@ -726,19 +593,21 @@ func convertToHotRankedReport(dto reportService.ReportDTO) (report HotRankedRepo
|
|
|
SecondPermissions: dto.SecondPermission,
|
|
|
Permissions: dto.Permissions,
|
|
|
PermissionNames: dto.PermissionNames,
|
|
|
- CoverUrl: src,
|
|
|
+ CoverUrl: dto.CoverUrl,
|
|
|
IsSubscribe: dto.IsSubscribe,
|
|
|
IsFree: dto.IsFree,
|
|
|
Price: dto.Price,
|
|
|
RiskLevel: dto.RiskLevel,
|
|
|
Login: dto.Login,
|
|
|
+ ProductId: dto.ProductId,
|
|
|
+ IsPackage: dto.IsPackage,
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
func convertToPublishRankedReportList(dtoList []reportService.ReportDTO) (reports []PublishRankedReport) {
|
|
|
reports = []PublishRankedReport{}
|
|
|
for _, dto := range dtoList {
|
|
|
- risk, err := parseRiskLevel(dto.RiskLevel)
|
|
|
+ risk, err := config.ParseRiskLevel(dto.RiskLevel)
|
|
|
if err != nil || risk == 0 {
|
|
|
continue
|
|
|
}
|
|
@@ -762,6 +631,8 @@ func convertToPublishRankedReportList(dtoList []reportService.ReportDTO) (report
|
|
|
Price: dto.Price,
|
|
|
RiskLevel: dto.RiskLevel,
|
|
|
Login: dto.Login,
|
|
|
+ ProductId: dto.ProductId,
|
|
|
+ IsPackage: dto.IsPackage,
|
|
|
}
|
|
|
reports = append(reports, report)
|
|
|
}
|
|
@@ -790,86 +661,42 @@ func GetReportByIdListByOrgIds(orgIds map[string][]int) (ids []int, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func RangePermissionIds(isLogin bool, userId int) (filterPermissionIds []int, riskLevel string, err error) {
|
|
|
- return CheckUserRisk(nil, isLogin, userId)
|
|
|
+func RangePermissionIds(isLogin bool, userId int) (filterPermissionIds []int, riskLevel string, userRiskStatus string, err error) {
|
|
|
+ return user.GetRiskLevelPermissionList(nil, isLogin, userId)
|
|
|
}
|
|
|
-func CheckUserRisk(permissionIds []int, isLogin bool, userId int) (filterPermissionIds []int, riskLevel string, err error) {
|
|
|
- if isLogin {
|
|
|
- userProfile, userErr := user.GetUserProfile(userId)
|
|
|
- if userErr != nil {
|
|
|
- if errors.Is(userErr, gorm.ErrRecordNotFound) {
|
|
|
- err = exception.New(exception.TemplateUserNotFound)
|
|
|
- } else {
|
|
|
- err = exception.New(exception.TemplateUserFoundFailed)
|
|
|
- }
|
|
|
- logger.Error("分页查询报告列表失败:%v", err)
|
|
|
- return
|
|
|
- }
|
|
|
- //获取产品风险等级
|
|
|
- if userProfile.RiskLevelStatus == user.RiskUnTest {
|
|
|
- logger.Warn("客户未做风险等级测评,mobile:%v", userProfile.Mobile)
|
|
|
- }
|
|
|
- if userProfile.RiskLevelStatus == user.RiskExpired {
|
|
|
- logger.Warn("客户风险等级已过期,mobile:%v", userProfile.Mobile)
|
|
|
- }
|
|
|
- var mapping permissionService.CustomerProductRiskMappingDTO
|
|
|
- if userProfile.RiskLevel != "" {
|
|
|
- mapping, err = permissionService.GetRiskMappingByCustomerRiskLevel(userProfile.RiskLevel)
|
|
|
- if err != nil {
|
|
|
- logger.Error("查询产品风险等级映射失败:%v", err)
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- var permissionList []permissionService.PermissionDTO
|
|
|
- if len(permissionIds) == 0 {
|
|
|
- //获取所有设置风险等级的品种
|
|
|
- permissionList, err = permissionService.GetPermissionListWithRisk()
|
|
|
- } else {
|
|
|
- //更具id过滤设置了风险等级的品种
|
|
|
- permissionList, err = permissionService.GetPermissionListByIds(permissionIds)
|
|
|
- }
|
|
|
- permissionList = filterPermissionsByRisk(permissionList, mapping.ProductRiskLevel)
|
|
|
- riskLevel = mapping.ProductRiskLevel
|
|
|
- if len(permissionList) == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- for _, permission := range permissionList {
|
|
|
- filterPermissionIds = append(filterPermissionIds, permission.PermissionId)
|
|
|
- }
|
|
|
+
|
|
|
+func getCount(permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, ids map[string][]int, discardIds []int, mappingRiskLevel, userRiskStatus string) {
|
|
|
+ filterPermissionIds, mappingRiskLevel, userRiskStatus, err := user.GetRiskLevelPermissionList(permissionIds, isLogin, userId)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取过滤品种信息失败:%v", err)
|
|
|
return
|
|
|
- } else { //没有登录的时候展示所有设置了风险等级的品种报告,筛选的时候过滤传入ID中没有设置风险等级的品种
|
|
|
- var permissionList []permissionService.PermissionDTO
|
|
|
- if len(permissionIds) == 0 {
|
|
|
- //获取所有设置风险等级的品种
|
|
|
- permissionList, err = permissionService.GetPermissionListWithRisk()
|
|
|
- } else {
|
|
|
- //更具id过滤设置了风险等级的品种
|
|
|
- permissionList, err = permissionService.GetPermissionListByIds(permissionIds)
|
|
|
- }
|
|
|
- if err != nil {
|
|
|
- logger.Error("根据ID查询品种列表失败:%v", err)
|
|
|
- }
|
|
|
- for _, permission := range permissionList {
|
|
|
- filterPermissionIds = append(filterPermissionIds, permission.PermissionId)
|
|
|
- }
|
|
|
- //查询品种
|
|
|
+ }
|
|
|
+ if len(filterPermissionIds) == 0 {
|
|
|
+ logger.Warn("不存在设置风险等级的品种信息")
|
|
|
return
|
|
|
}
|
|
|
+ total, latestId, ids, discardIds = reportService.GetTotalPageCountByPermissionIds(filterPermissionIds)
|
|
|
+ return
|
|
|
}
|
|
|
-func getCount(permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, ids map[string][]int) {
|
|
|
- filterPermissionIds, riskLevel, err := CheckUserRisk(permissionIds, isLogin, userId)
|
|
|
+
|
|
|
+func getCountByAnalyst(permissionIds []int, isLogin bool, userId int, analystName string) (total int64, latestId int64, ids []int, mappingRiskLevel, userRiskStatus string) {
|
|
|
+ filterPermissionIds, mappingRiskLevel, userRiskStatus, err := user.GetRiskLevelPermissionList(permissionIds, isLogin, userId)
|
|
|
if err != nil {
|
|
|
logger.Error("校验用户风险等级失败:%v", err)
|
|
|
return
|
|
|
}
|
|
|
- return reportService.GetTotalPageCountByPermissionIds(filterPermissionIds, riskLevel)
|
|
|
+ total, latestId, ids = reportService.GetTotalPageCountByAnalyst(analystName, filterPermissionIds)
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
-func getCountByAnalyst(permissionIds []int, isLogin bool, userId int, analystName string) (total int64, latestId int64, ids []int) {
|
|
|
- filterPermissionIds, riskLevel, err := CheckUserRisk(permissionIds, isLogin, userId)
|
|
|
+func CountPermissionWeight(ids []int) (permissionMap map[int]int) {
|
|
|
+ list, err := reportService.CountPermissionWeight(ids)
|
|
|
+ permissionMap = make(map[int]int)
|
|
|
if err != nil {
|
|
|
- logger.Error("校验用户风险等级失败:%v", err)
|
|
|
return
|
|
|
}
|
|
|
- return reportService.GetTotalPageCountByAnalyst(analystName, filterPermissionIds, riskLevel)
|
|
|
+ for _, item := range list {
|
|
|
+ permissionMap[item.PermissionId] = item.Weight
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|