kobe6258 5 сар өмнө
parent
commit
0af02be074

+ 0 - 1
controllers/user/user_controller.go

@@ -567,7 +567,6 @@ func (h *UserController) SyncCustomerRiskLevel() {
 	controllers.Wrap(&h.BaseController, func() (result *controllers.WrapData, err error) {
 		result = h.InitWrapData("同步风险等级")
 		htConfig := config.GetConfig(contants.HT).(*config.HTBizConfig)
-
 		webhookRequest := new(WebhookRequest)
 		h.GetPostParams(webhookRequest)
 		privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey())

+ 128 - 116
service/media/media_service.go

@@ -14,6 +14,7 @@ import (
 	mediaDao "eta/eta_mini_ht_api/models/media"
 	productDao "eta/eta_mini_ht_api/models/merchant"
 	userDao "eta/eta_mini_ht_api/models/user"
+	"eta/eta_mini_ht_api/service/report"
 	"eta/eta_mini_ht_api/service/user"
 	"fmt"
 	"gorm.io/gorm"
@@ -114,128 +115,139 @@ func RangeSearchByAnalyst(mediaType string, analystId int, userId int) (total in
 	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) {
 	if mediaType == "" {
 		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) {
 	parts := strings.Split(level, "R")

+ 4 - 4
service/report/report_service.go

@@ -791,9 +791,9 @@ func GetReportByIdListByOrgIds(orgIds map[string][]int) (ids []int, err error) {
 }
 
 func RangePermissionIds(isLogin bool, userId int) (filterPermissionIds []int, riskLevel string, err error) {
-	return checkUserRisk(nil, isLogin, userId)
+	return CheckUserRisk(nil, isLogin, userId)
 }
-func checkUserRisk(permissionIds []int, isLogin bool, userId int) (filterPermissionIds []int, riskLevel string, err error) {
+func CheckUserRisk(permissionIds []int, isLogin bool, userId int) (filterPermissionIds []int, riskLevel string, err error) {
 	if isLogin {
 		userProfile, userErr := user.GetUserProfile(userId)
 		if userErr != nil {
@@ -857,7 +857,7 @@ func checkUserRisk(permissionIds []int, isLogin bool, userId int) (filterPermiss
 	}
 }
 func getCount(permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, ids map[string][]int) {
-	filterPermissionIds, riskLevel, err := checkUserRisk(permissionIds, isLogin, userId)
+	filterPermissionIds, riskLevel, err := CheckUserRisk(permissionIds, isLogin, userId)
 	if err != nil {
 		logger.Error("校验用户风险等级失败:%v", err)
 		return
@@ -866,7 +866,7 @@ func getCount(permissionIds []int, isLogin bool, userId int) (total int64, lates
 }
 
 func getCountByAnalyst(permissionIds []int, isLogin bool, userId int, analystName string) (total int64, latestId int64, ids []int) {
-	filterPermissionIds, riskLevel, err := checkUserRisk(permissionIds, isLogin, userId)
+	filterPermissionIds, riskLevel, err := CheckUserRisk(permissionIds, isLogin, userId)
 	if err != nil {
 		logger.Error("校验用户风险等级失败:%v", err)
 		return