|
@@ -14,6 +14,7 @@ import (
|
|
mediaDao "eta/eta_mini_ht_api/models/media"
|
|
mediaDao "eta/eta_mini_ht_api/models/media"
|
|
productDao "eta/eta_mini_ht_api/models/merchant"
|
|
productDao "eta/eta_mini_ht_api/models/merchant"
|
|
userDao "eta/eta_mini_ht_api/models/user"
|
|
userDao "eta/eta_mini_ht_api/models/user"
|
|
|
|
+ "eta/eta_mini_ht_api/service/report"
|
|
"eta/eta_mini_ht_api/service/user"
|
|
"eta/eta_mini_ht_api/service/user"
|
|
"fmt"
|
|
"fmt"
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm"
|
|
@@ -114,128 +115,139 @@ func RangeSearchByAnalyst(mediaType string, analystId int, userId int) (total in
|
|
return mediaService.GetAnalystMediaPermissionMappingByPermissionIds(mediaType, filterPermissionIds, analystId)
|
|
return mediaService.GetAnalystMediaPermissionMappingByPermissionIds(mediaType, filterPermissionIds, analystId)
|
|
}
|
|
}
|
|
|
|
|
|
-func RangeSearch(mediaType string, isLogin bool, userId int) (total int64, latestId int64, ids []int) {
|
|
|
|
- var 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.RiskLevel == user.RiskUnTest {
|
|
|
|
- logger.Error("客户未做风险等级测评,mobile:%v", userProfile.Mobile)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- if userProfile.RiskLevelStatus == user.RiskExpired {
|
|
|
|
- logger.Error("客户风险等级已过期,mobile:%v", userProfile.Mobile)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- mapping, mappingErr := permissionService.GetRiskMappingByCustomerRiskLevel(userProfile.RiskLevel)
|
|
|
|
- if mappingErr != nil {
|
|
|
|
- logger.Error("查询产品风险等级映射失败:%v", mappingErr)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- var permissionList []permissionService.PermissionDTO
|
|
|
|
- //获取所有设置风险等级的品种
|
|
|
|
- permissionList, err = permissionService.GetPermissionListWithRisk()
|
|
|
|
- permissionList = filterPermissionsByRisk(permissionList, mapping.ProductRiskLevel)
|
|
|
|
- if len(permissionList) == 0 {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- var filterPermissionIds []int
|
|
|
|
- for _, permission := range permissionList {
|
|
|
|
- filterPermissionIds = append(filterPermissionIds, permission.PermissionId)
|
|
|
|
- }
|
|
|
|
- return mediaService.GetMediaPermissionMappingByPermissionIds(mediaType, filterPermissionIds, mapping.ProductRiskLevel)
|
|
|
|
- } else { //没有登录的时候展示所有设置了风险等级的品种报告,筛选的时候过滤传入ID中没有设置风险等级的品种
|
|
|
|
- var permissionList []permissionService.PermissionDTO
|
|
|
|
- //获取所有设置风险等级的品种
|
|
|
|
- permissionList, err = permissionService.GetPermissionListWithRisk()
|
|
|
|
- if err != nil {
|
|
|
|
- logger.Error("根据ID查询品种列表失败:%v", err)
|
|
|
|
- }
|
|
|
|
- var filterPermissionIds []int
|
|
|
|
- for _, permission := range permissionList {
|
|
|
|
- filterPermissionIds = append(filterPermissionIds, permission.PermissionId)
|
|
|
|
- }
|
|
|
|
- //查询品种
|
|
|
|
- return mediaService.GetMediaPermissionMappingByPermissionIds(mediaType, filterPermissionIds, "")
|
|
|
|
|
|
+func getCount(mediaType string, permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, orgIds []int) {
|
|
|
|
+ filterPermissionIds, riskLevel, err := report.CheckUserRisk(permissionIds, isLogin, userId)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.Error("校验用户风险等级失败:%v", err)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
+ return mediaService.GetMediaPermissionMappingByPermissionIds(mediaType, filterPermissionIds, riskLevel)
|
|
|
|
+}
|
|
|
|
+func RangeSearch(mediaType string, isLogin bool, userId int) (total int64, latestId int64, ids []int) {
|
|
|
|
+ return getCount(mediaType, nil, isLogin, userId)
|
|
|
|
+ //var 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.RiskLevel == user.RiskUnTest {
|
|
|
|
+ // logger.Error("客户未做风险等级测评,mobile:%v", userProfile.Mobile)
|
|
|
|
+ // return
|
|
|
|
+ // }
|
|
|
|
+ // if userProfile.RiskLevelStatus == user.RiskExpired {
|
|
|
|
+ // logger.Error("客户风险等级已过期,mobile:%v", userProfile.Mobile)
|
|
|
|
+ // return
|
|
|
|
+ // }
|
|
|
|
+ // mapping, mappingErr := permissionService.GetRiskMappingByCustomerRiskLevel(userProfile.RiskLevel)
|
|
|
|
+ // if mappingErr != nil {
|
|
|
|
+ // logger.Error("查询产品风险等级映射失败:%v", mappingErr)
|
|
|
|
+ // return
|
|
|
|
+ // }
|
|
|
|
+ // var permissionList []permissionService.PermissionDTO
|
|
|
|
+ // //获取所有设置风险等级的品种
|
|
|
|
+ // permissionList, err = permissionService.GetPermissionListWithRisk()
|
|
|
|
+ // permissionList = filterPermissionsByRisk(permissionList, mapping.ProductRiskLevel)
|
|
|
|
+ // if len(permissionList) == 0 {
|
|
|
|
+ // return
|
|
|
|
+ // }
|
|
|
|
+ // var filterPermissionIds []int
|
|
|
|
+ // for _, permission := range permissionList {
|
|
|
|
+ // filterPermissionIds = append(filterPermissionIds, permission.PermissionId)
|
|
|
|
+ // }
|
|
|
|
+ // return mediaService.GetMediaPermissionMappingByPermissionIds(mediaType, filterPermissionIds, mapping.ProductRiskLevel)
|
|
|
|
+ //} else { //没有登录的时候展示所有设置了风险等级的品种报告,筛选的时候过滤传入ID中没有设置风险等级的品种
|
|
|
|
+ // var permissionList []permissionService.PermissionDTO
|
|
|
|
+ // //获取所有设置风险等级的品种
|
|
|
|
+ // permissionList, err = permissionService.GetPermissionListWithRisk()
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // logger.Error("根据ID查询品种列表失败:%v", err)
|
|
|
|
+ // }
|
|
|
|
+ // var filterPermissionIds []int
|
|
|
|
+ // for _, permission := range permissionList {
|
|
|
|
+ // filterPermissionIds = append(filterPermissionIds, permission.PermissionId)
|
|
|
|
+ // }
|
|
|
|
+ // //查询品种
|
|
|
|
+ // return mediaService.GetMediaPermissionMappingByPermissionIds(mediaType, filterPermissionIds, "")
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
func GetTotalPageCountByPermissionIds(mediaType string, permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, ids []int) {
|
|
func GetTotalPageCountByPermissionIds(mediaType string, permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, ids []int) {
|
|
if mediaType == "" {
|
|
if mediaType == "" {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- var 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.RiskLevel == user.RiskUnTest {
|
|
|
|
- logger.Error("客户未做风险等级测评,mobile:%v", userProfile.Mobile)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- if userProfile.RiskLevelStatus == user.RiskExpired {
|
|
|
|
- logger.Error("客户风险等级已过期,mobile:%v", userProfile.Mobile)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- mapping, mappingErr := permissionService.GetRiskMappingByCustomerRiskLevel(userProfile.RiskLevel)
|
|
|
|
- if mappingErr != nil {
|
|
|
|
- logger.Error("查询产品风险等级映射失败:%v", mappingErr)
|
|
|
|
- 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)
|
|
|
|
- if len(permissionList) == 0 {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- var filterPermissionIds []int
|
|
|
|
- for _, permission := range permissionList {
|
|
|
|
- filterPermissionIds = append(filterPermissionIds, permission.PermissionId)
|
|
|
|
- }
|
|
|
|
- return mediaService.GetMediaPermissionMappingByPermissionIds(mediaType, filterPermissionIds, mapping.ProductRiskLevel)
|
|
|
|
- } 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)
|
|
|
|
- }
|
|
|
|
- var filterPermissionIds []int
|
|
|
|
- for _, permission := range permissionList {
|
|
|
|
- filterPermissionIds = append(filterPermissionIds, permission.PermissionId)
|
|
|
|
- }
|
|
|
|
- //查询品种
|
|
|
|
- return mediaService.GetMediaPermissionMappingByPermissionIds(mediaType, filterPermissionIds, "")
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ return getCount(mediaType, permissionIds, isLogin, userId)
|
|
|
|
+ //var 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.RiskLevel == user.RiskUnTest {
|
|
|
|
+ // logger.Error("客户未做风险等级测评,mobile:%v", userProfile.Mobile)
|
|
|
|
+ // return
|
|
|
|
+ // }
|
|
|
|
+ // if userProfile.RiskLevelStatus == user.RiskExpired {
|
|
|
|
+ // logger.Error("客户风险等级已过期,mobile:%v", userProfile.Mobile)
|
|
|
|
+ // return
|
|
|
|
+ // }
|
|
|
|
+ // mapping, mappingErr := permissionService.GetRiskMappingByCustomerRiskLevel(userProfile.RiskLevel)
|
|
|
|
+ // if mappingErr != nil {
|
|
|
|
+ // logger.Error("查询产品风险等级映射失败:%v", mappingErr)
|
|
|
|
+ // 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)
|
|
|
|
+ // if len(permissionList) == 0 {
|
|
|
|
+ // return
|
|
|
|
+ // }
|
|
|
|
+ // var filterPermissionIds []int
|
|
|
|
+ // for _, permission := range permissionList {
|
|
|
|
+ // filterPermissionIds = append(filterPermissionIds, permission.PermissionId)
|
|
|
|
+ // }
|
|
|
|
+ // return mediaService.GetMediaPermissionMappingByPermissionIds(mediaType, filterPermissionIds, mapping.ProductRiskLevel)
|
|
|
|
+ //} 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)
|
|
|
|
+ // }
|
|
|
|
+ // var filterPermissionIds []int
|
|
|
|
+ // for _, permission := range permissionList {
|
|
|
|
+ // filterPermissionIds = append(filterPermissionIds, permission.PermissionId)
|
|
|
|
+ // }
|
|
|
|
+ // //查询品种
|
|
|
|
+ // return mediaService.GetMediaPermissionMappingByPermissionIds(mediaType, filterPermissionIds, "")
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
func parseRiskLevel(level string) (int, error) {
|
|
func parseRiskLevel(level string) (int, error) {
|
|
parts := strings.Split(level, "R")
|
|
parts := strings.Split(level, "R")
|