|
@@ -21,8 +21,10 @@ import (
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- SourceETA = "ETA"
|
|
|
- SourceHT = "HT"
|
|
|
+ SourceETA = "ETA"
|
|
|
+ SourceHT = "HT"
|
|
|
+ RiskLevelUnMatch = "unMatch"
|
|
|
+ RiskLevelMatch = "match"
|
|
|
)
|
|
|
|
|
|
type PublishRankedReport struct {
|
|
@@ -67,13 +69,98 @@ type RecordCount struct {
|
|
|
Additional string
|
|
|
}
|
|
|
|
|
|
-func GetReportById(reportId int, login bool) (report reportService.ReportDTO, err error) {
|
|
|
+func matchRiskLevel(userId int, report reportService.ReportDTO) (riskLevelMatch string, err error) {
|
|
|
+ userProfile, userErr := user.GetUserProfile(userId)
|
|
|
+ if userErr != nil {
|
|
|
+ if errors.Is(userErr, gorm.ErrRecordNotFound) {
|
|
|
+ logger.Error("用户信息不存在,mobile:%d", userProfile.Mobile)
|
|
|
+ err = exception.New(exception.TemplateUserNotFound)
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ logger.Error("获取用户信息失败:%v", userErr)
|
|
|
+ err = exception.New(exception.TemplateUserFoundFailed)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //比较风险等级
|
|
|
+ if userProfile.RiskLevelStatus == user.RiskUnTest {
|
|
|
+ logger.Info("客户风险等级未测试,mobile:%d", userProfile.Mobile)
|
|
|
+ riskLevelMatch = RiskLevelUnMatch
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if userProfile.RiskLevelStatus == user.RiskExpired {
|
|
|
+ logger.Info("客户风险等级已过期,mobile:%d", userProfile.Mobile)
|
|
|
+ riskLevelMatch = RiskLevelUnMatch
|
|
|
+ return
|
|
|
+ }
|
|
|
+ level, err := permissionService.GetRiskMappingByCustomerRiskLevel(userProfile.RiskLevel)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取eta报告风险等级失败:%v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ permissions := reportService.GetReportSecondPermissionsById(report.OrgId, report.Source)
|
|
|
+ if len(permissions) == 0 {
|
|
|
+ logger.Error("获取eta报告分类失败:%v", err)
|
|
|
+ riskLevelMatch = RiskLevelUnMatch
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var permissionIds []int
|
|
|
+ for _, permission := range permissions {
|
|
|
+ permissionIds = append(permissionIds, permission.ID)
|
|
|
+ }
|
|
|
+ permissionDTOs, err := permissionService.GetPermissionListByIds(permissionIds)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取品种风险等级失败:%v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //能够查看最高等级
|
|
|
+ matchNum, err := parseRiskLevel(level.ProductRiskLevel)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("解析风险等级失败:%v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //能够查看需要的最小等级
|
|
|
+ num := getLowestRiskLevel(permissionDTOs)
|
|
|
+ if num > matchNum {
|
|
|
+ riskLevelMatch = RiskLevelUnMatch
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ riskLevelMatch = RiskLevelMatch
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+func GetReportById(reportId int, login bool, userId int) (report reportService.ReportDTO, err error) {
|
|
|
report, err = reportService.GetGetReportById(reportId)
|
|
|
if err != nil {
|
|
|
logger.Error("获取研报失败:%v", err)
|
|
|
err = exception.New(exception.GetReportFailed)
|
|
|
return
|
|
|
}
|
|
|
+ var status string
|
|
|
+ status, err = matchRiskLevel(userId, report)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("匹配风险等级失败:%v", err)
|
|
|
+ err = exception.New(exception.GetReportFailed)
|
|
|
+ return
|
|
|
+ }
|
|
|
var pdfUrl string
|
|
|
switch report.Source {
|
|
|
case SourceETA:
|
|
@@ -86,8 +173,13 @@ func GetReportById(reportId int, login bool) (report reportService.ReportDTO, er
|
|
|
}
|
|
|
if !login {
|
|
|
detail.Content = ""
|
|
|
+ report.RiskLevelStatus = RiskLevelUnMatch
|
|
|
report.Login = false
|
|
|
} else {
|
|
|
+ if status == RiskLevelUnMatch {
|
|
|
+ detail.Content = ""
|
|
|
+ }
|
|
|
+ report.RiskLevelStatus = status
|
|
|
report.Login = true
|
|
|
}
|
|
|
var jsonStr []byte
|
|
@@ -107,9 +199,13 @@ func GetReportById(reportId int, login bool) (report reportService.ReportDTO, er
|
|
|
}
|
|
|
if !login {
|
|
|
report.PdfUrl = ""
|
|
|
+ report.RiskLevelStatus = RiskLevelUnMatch
|
|
|
report.Login = false
|
|
|
} else {
|
|
|
- report.PdfUrl = pdfUrl
|
|
|
+ if status == RiskLevelMatch {
|
|
|
+ report.PdfUrl = pdfUrl
|
|
|
+ }
|
|
|
+ report.RiskLevelStatus = status
|
|
|
report.Login = true
|
|
|
}
|
|
|
return
|