Browse Source

过滤下架产品

kobe6258 3 months ago
parent
commit
97ffb29ccb

+ 0 - 37
domian/media/media_service.go

@@ -165,43 +165,6 @@ func GetMediaPermissionMappingByPermissionIds(mediaType string, permissionIds []
 		logger.Error("获取配置品种的媒体列表信息失败:%v", err)
 		logger.Error("获取配置品种的媒体列表信息失败:%v", err)
 		return 0, 0, ids, riskLevel
 		return 0, 0, ids, riskLevel
 	}
 	}
-	if riskLevel != "" {
-		var productList []productDao.MerchantProduct
-		//现加入没有产品的媒体
-		productList, err = productDao.GetProductListBySourceIds(ids, true, productDao.Audio, productDao.Video)
-		for _, mediaId := range ids {
-			find := false
-			for _, product := range productList {
-				if product.SourceID == mediaId {
-					find = true
-					break
-				}
-			}
-			if !find {
-				ids = append(ids, mediaId)
-			}
-		}
-		riskNum, parseErr := configService.ParseRiskLevel(riskLevel)
-		if parseErr != nil {
-			logger.Error("解析风险等级失败:%v", err)
-			return
-		}
-		//再把符合风险等级的产品加入
-		for _, mediaId := range ids {
-			for _, product := range productList {
-				if product.SourceID == mediaId {
-					pdRiskNum, pdErr := configService.ParseRiskLevel(product.RiskLevel)
-					if pdErr != nil {
-						logger.Error("解析产品风险等级失败:%v,产品id:%v", pdErr, product.ID)
-						continue
-					}
-					if pdRiskNum <= riskNum && product.SaleStatus == productDao.OnSale {
-						ids = append(ids, mediaId)
-					}
-				}
-			}
-		}
-	}
 	for _, mediaId := range ids {
 	for _, mediaId := range ids {
 		find := false
 		find := false
 		for _, discardMediaId := range disCardMediaIds {
 		for _, discardMediaId := range disCardMediaIds {

+ 1 - 21
domian/report/ht_report_service.go

@@ -6,17 +6,6 @@ import (
 	reportDao "eta/eta_mini_ht_api/models/report"
 	reportDao "eta/eta_mini_ht_api/models/report"
 )
 )
 
 
-func GetHTReportIdsByPermissionIds(permissionIds []int) (ids []int, err error) {
-	//品种名字筛选
-	permissionNames, err := GetPermissionNamesByPermissionIds(permissionIds)
-	if err != nil {
-		logger.Error("获取品种名称列表失败:%v", err)
-		return
-	}
-	//更具query查询ids TODO
-	ids, err = reportDao.GetIdsByPlateNames(permissionNames)
-	return
-}
 func GetHTReportIdsByPermissionIdsWithRiskLevel(permissionIds []int) (orgIds []int, err error) {
 func GetHTReportIdsByPermissionIdsWithRiskLevel(permissionIds []int) (orgIds []int, err error) {
 	//品种名字筛选
 	//品种名字筛选
 	var permissionNames []string
 	var permissionNames []string
@@ -26,16 +15,7 @@ func GetHTReportIdsByPermissionIdsWithRiskLevel(permissionIds []int) (orgIds []i
 		return
 		return
 	}
 	}
 	//更具query查询ids
 	//更具query查询ids
-	var reports []reportDao.Report
-	reports, err = reportDao.GetReportByPlateNames(permissionNames)
-	if err != nil {
-		logger.Error("获取HT研报列表失败:%v", err)
-		return
-	}
-	for _, report := range reports {
-		orgIds = append(orgIds, report.OrgID)
-	}
-	return
+	return reportDao.GetOrgIdsByPlateNames(permissionNames)
 }
 }
 func GetHtReport(id int) (pdf string, err error) {
 func GetHtReport(id int) (pdf string, err error) {
 	return ht.GetPDFUrl(id)
 	return ht.GetPDFUrl(id)

+ 0 - 1
domian/report/permission_service.go

@@ -12,7 +12,6 @@ func GetClassifyIdsByPermissionIds(permissionIds []int) (classifyIds []int, err
 
 
 func GetPermissionNamesByPermissionIds(permissionIds []int) (permissionNames []string, err error) {
 func GetPermissionNamesByPermissionIds(permissionIds []int) (permissionNames []string, err error) {
 	return permissionDao.GetPermissionNamesByPermissionIds(permissionIds)
 	return permissionDao.GetPermissionNamesByPermissionIds(permissionIds)
-	//return etaDao.GetPermissionNamesByPermissionIds(permissionIds)
 }
 }
 func GetPermissionsByPermissionIds(permissionIds []int) (permissionDTOs []configService.PermissionDTO, err error) {
 func GetPermissionsByPermissionIds(permissionIds []int) (permissionDTOs []configService.PermissionDTO, err error) {
 	permission, err := permissionDao.GetPermissionsByPermissionIds(permissionIds)
 	permission, err := permissionDao.GetPermissionsByPermissionIds(permissionIds)

+ 99 - 55
domian/report/report_service.go

@@ -139,31 +139,41 @@ func GetReportById(reportId int) (ReportDTO ReportDTO, err error) {
 	ReportDTO.AuthorInfo = authorList
 	ReportDTO.AuthorInfo = authorList
 	return
 	return
 }
 }
-
-func GetTotalPageCount() (total int64, latestId int64, err error) {
-	return reportDao.GetTotalPageCount()
-}
-func GetTotalPageCountByAnalyst(analyst string, permissionIds []int, riskLevel string) (total int64, latestId int64, ids []int) {
+func GetTotalPageCountByAnalyst(analyst string, permissionIds []int) (total int64, latestId int64, ids []int) {
 	ids, err := reportDao.GetReportsByAnalyst(analyst)
 	ids, err := reportDao.GetReportsByAnalyst(analyst)
 	if err != nil {
 	if err != nil {
 		logger.Error("查询研究研报告列表id失败:%v", err)
 		logger.Error("查询研究研报告列表id失败:%v", err)
 		return
 		return
 	}
 	}
-	//查询这些包含在列表中的权限的报告ids
-	htOrgIds, err := GetHTReportIdsByPermissionIds(permissionIds)
-	if err != nil {
-		logger.Error("品种筛选ht报告id失败:%v", err)
-		htOrgIds = []int{}
-	}
-	etaOrgIds, err := GetETAReportIdsByPermissionIds(permissionIds)
-	if err != nil {
-		logger.Error("品种筛选eta报告id失败:%v", err)
-		etaOrgIds = []int{}
+	var wg sync.WaitGroup
+	wg.Add(2)
+	var htOrgIds []int
+	var etaOrgIds []int
+	go func() {
+		defer wg.Done()
+		htOrgIds, err = getHtOrgIds(permissionIds)
+		if err != nil {
+			logger.Error("品种筛选ht报告id失败:%v", err)
+		}
+	}()
+	go func() {
+		defer wg.Done()
+		etaOrgIds, err = getEtaOrgIds(permissionIds)
+		if err != nil {
+			logger.Error("品种筛选eta报告id失败:%v", err)
+		}
+	}()
+	wg.Wait()
+	totalCol := int64(len(etaOrgIds) + len(htOrgIds))
+	if totalCol == 0 {
+		latestId = 0
+		return
 	}
 	}
 	if len(etaOrgIds) == 0 && len(htOrgIds) == 0 {
 	if len(etaOrgIds) == 0 && len(htOrgIds) == 0 {
 		logger.Info("没有符合权限的研报")
 		logger.Info("没有符合权限的研报")
 		return
 		return
 	}
 	}
+
 	orgIds := make(map[string][]int, 2)
 	orgIds := make(map[string][]int, 2)
 	if len(etaOrgIds) == 0 {
 	if len(etaOrgIds) == 0 {
 		orgIds["ETA"] = []int{}
 		orgIds["ETA"] = []int{}
@@ -175,6 +185,7 @@ func GetTotalPageCountByAnalyst(analyst string, permissionIds []int, riskLevel s
 	} else {
 	} else {
 		orgIds["HT"] = htOrgIds
 		orgIds["HT"] = htOrgIds
 	}
 	}
+
 	permitReportIds, err := reportDao.GetReportIdListByOrgIds(orgIds)
 	permitReportIds, err := reportDao.GetReportIdListByOrgIds(orgIds)
 	if err != nil {
 	if err != nil {
 		logger.Error("根据原始报告id获取报告id列表失败:%v", err)
 		logger.Error("根据原始报告id获取报告id列表失败:%v", err)
@@ -193,6 +204,79 @@ func GetTotalPageCountByAnalyst(analyst string, permissionIds []int, riskLevel s
 		return
 		return
 	}
 	}
 	ids = filterReportIds
 	ids = filterReportIds
+	//获取一下下架的报告产品
+	var disCardReportIds []int
+	offSaleProducts, err := merchantDao.GetOffSaleProducts([]merchantDao.MerchantProductType{merchantDao.Report, merchantDao.Package})
+	if err != nil {
+		logger.Error("获取下架的报告产品失败:%v", err)
+		return
+	}
+
+	var ProductPermissionIds []int
+	for _, product := range offSaleProducts {
+		if product.Type == "package" {
+			ProductPermissionIds = append(ProductPermissionIds, product.SourceID)
+		}
+		if product.Type == "report" {
+			disCardReportIds = append(disCardReportIds, product.SourceID)
+		}
+	}
+	if len(ProductPermissionIds) > 0 {
+		wg.Add(2)
+		var permissionNames []string
+		var classifyIds []int
+		go func() {
+			defer wg.Done()
+			var permissionErr error
+			permissionNames, permissionErr = GetPermissionNamesByPermissionIds(ProductPermissionIds)
+			if permissionErr != nil {
+				logger.Error("获取ETA品种名称失败:%v", err)
+			}
+		}()
+		go func() {
+			defer wg.Done()
+			var classifyErr error
+			classifyIds, classifyErr = permissionDao.GetClassifyIdsByPermissionIds(ProductPermissionIds)
+			if classifyErr != nil {
+				logger.Error("获取ETA报告分类id失败:%v", err)
+			}
+		}()
+		wg.Wait()
+		disCardIds, _ := reportDao.GetHiddenReportIds(classifyIds, permissionNames)
+		if len(disCardIds) > 0 {
+			disCardReportIds = append(disCardReportIds, disCardIds...)
+		}
+	}
+	//对数据去重
+	disCardReportIds = uniqueArray(disCardReportIds)
+	//获取报告中还包含上架套餐的id
+	if len(disCardReportIds) > 0 {
+		reportIdsSalePackage, _ := merchantDao.GetOnSalePackageIds(disCardReportIds)
+		reportIdsSaleProduct, _ := merchantDao.GetOnSaleReportIds(disCardReportIds)
+		showReportMap := make(map[int]bool)
+		disCardMap := make(map[int]bool)
+		for _, reportId := range reportIdsSalePackage {
+			showReportMap[reportId] = true
+		}
+		for _, reportId := range reportIdsSaleProduct {
+			showReportMap[reportId] = true
+		}
+		var filterDisCardReportIds []int
+		for _, id := range disCardReportIds {
+			if _, ok := showReportMap[id]; !ok {
+				filterDisCardReportIds = append(filterDisCardReportIds, id)
+				disCardMap[id] = true
+			}
+		}
+		disCardReportIds = filterDisCardReportIds
+		var cardReportIds []int
+		for _, id := range filterReportIds {
+			if _, ok := disCardMap[id]; !ok {
+				cardReportIds = append(cardReportIds, id)
+			}
+		}
+		filterReportIds = cardReportIds
+	}
 	total = int64(len(filterReportIds))
 	total = int64(len(filterReportIds))
 	latestId = int64(findMax(filterReportIds))
 	latestId = int64(findMax(filterReportIds))
 	return
 	return
@@ -214,34 +298,6 @@ func findMax(nums []int) (max int) {
 	}
 	}
 	return
 	return
 }
 }
-func SearchMaxReportId(key string) (total int64, reportId int64) {
-	sort := []string{"reportId:desc"}
-	request := matchAll(sort, key)
-	//同步es
-	re, err := elastic().Count(request)
-	if err != nil {
-		logger.Error("es搜索异常:%v", err)
-	}
-	count := re.Count
-	total = int64(count)
-	if total > 0 {
-		request = match(key, 0, count, sort)
-		re, err = elastic().Search(request)
-		if err != nil {
-			logger.Error("es搜索异常:%v", err)
-		}
-		hits := elastic().GetSource(re.Hits)
-		data := hits[0].Source
-		report := ReportDTO{}
-		err = json.Unmarshal(data, &report)
-		if err != nil {
-			logger.Error("获取当前最大研报id失败:%v", err)
-			return
-		}
-		reportId = int64(report.ReportID)
-	}
-	return
-}
 func SearchMaxReportIdWithRange(key string, reportIds []int) (total int64) {
 func SearchMaxReportIdWithRange(key string, reportIds []int) (total int64) {
 	sort := []string{"reportId:desc"}
 	sort := []string{"reportId:desc"}
 	var docIds []string
 	var docIds []string
@@ -341,17 +397,6 @@ func GetReportPageByOrgIds(pageInfo page.PageInfo, orgIds map[string][]int, disc
 	return
 	return
 }
 }
 
 
-func GetNewReportByPublishTime(time time.Time) (reports []ReportDTO) {
-	list := reportDao.GetNewReportByPublishTime(time)
-	if list != nil {
-		for _, report := range list {
-			dto := convertReportDTO(report, false)
-			reports = append(reports, dto)
-		}
-	}
-	return
-}
-
 func getETAReportFirstPermissions(id int) (permissionDTOs []configService.PermissionDTO) {
 func getETAReportFirstPermissions(id int) (permissionDTOs []configService.PermissionDTO) {
 	classifyId, err := etaDao.GetReportClassifyById(id)
 	classifyId, err := etaDao.GetReportClassifyById(id)
 	if err != nil || classifyId == 0 {
 	if err != nil || classifyId == 0 {
@@ -359,7 +404,6 @@ func getETAReportFirstPermissions(id int) (permissionDTOs []configService.Permis
 		return
 		return
 	}
 	}
 	permissions, err := permissionDao.GetFirstPermissionsByClassifyID(classifyId)
 	permissions, err := permissionDao.GetFirstPermissionsByClassifyID(classifyId)
-	//permissions, err := etaDao.GetFirstPermissionsByClassifyID(classifyId)
 	if err != nil {
 	if err != nil {
 		logger.Error("获取研报一级品种信息失败:%v", err)
 		logger.Error("获取研报一级品种信息失败:%v", err)
 		return
 		return

+ 9 - 9
models/report/report.go

@@ -47,16 +47,12 @@ type Report struct {
 	UpdatedTime   time.Time    `gorm:"column:updated_time;comment:'修改时间'" json:"updated_time"`
 	UpdatedTime   time.Time    `gorm:"column:updated_time;comment:'修改时间'" json:"updated_time"`
 }
 }
 
 
-func GetIdsByPlateNames(plateName []string) (ids []int, err error) {
+func GetOrgIdsByPlateNames(plateName []string) (ids []int, err error) {
 	db := models.Main()
 	db := models.Main()
 	err = db.Model(&Report{}).Select("distinct org_id").Where(" source ='HT' and plate_name in ?  ", plateName).Scan(&ids).Error
 	err = db.Model(&Report{}).Select("distinct org_id").Where(" source ='HT' and plate_name in ?  ", plateName).Scan(&ids).Error
 	return
 	return
 }
 }
-func GetReportByPlateNames(plateName []string) (reportList []Report, err error) {
-	db := models.Main()
-	err = db.Model(&Report{}).Select("org_id,id").Where(" source ='HT' and plate_name in ?  ", plateName).Find(&reportList).Error
-	return
-}
+
 func BatchInsertReport(list *[]Report) (err error) {
 func BatchInsertReport(list *[]Report) (err error) {
 	db := models.Main()
 	db := models.Main()
 	//手动事务
 	//手动事务
@@ -336,15 +332,19 @@ func GetReportPageByOrgIds(latestId int64, limit int, offset int, orgIds map[str
 		logger.Error("非法的limit参数:%d", limit)
 		logger.Error("非法的limit参数:%d", limit)
 	}
 	}
 	db := models.Main()
 	db := models.Main()
+	listQuery := db.Model(&Report{}).Select(CommonColumns).Where("status = ? ", StatusPublish).Where("id<= ?", latestId)
+	if len(discardIds) > 0 {
+		listQuery.Where("id not in ?", discardIds)
+	}
 	if len(orgIds["ETA"]) == 0 {
 	if len(orgIds["ETA"]) == 0 {
-		err = db.Select(CommonColumns).Where("id<= ?", latestId).Where("status = ? and id not in ?", StatusPublish, discardIds).Where(" source='HT' and org_id in ?", orgIds["HT"]).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
+		err = listQuery.Where(" source='HT' and org_id in ?", orgIds["HT"]).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
 		return
 		return
 	}
 	}
 	if len(orgIds["HT"]) == 0 {
 	if len(orgIds["HT"]) == 0 {
-		err = db.Select(CommonColumns).Where("id<= ?", latestId).Where("status = ? and id not in ?", StatusPublish, discardIds).Where("source='ETA' and org_id in ?", orgIds["ETA"]).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
+		err = listQuery.Where("source='ETA' and org_id in ?", orgIds["ETA"]).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
 		return
 		return
 	}
 	}
-	err = db.Select(CommonColumns).Where("id<= ?", latestId).Where("status = ? and id not in ?", StatusPublish, discardIds).Where("(source='ETA' and org_id in ? ) or (source='HT' and org_id in ?) ", orgIds["ETA"], orgIds["HT"]).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
+	err = listQuery.Where("(source='ETA' and org_id in ? ) or (source='HT' and org_id in ?) ", orgIds["ETA"], orgIds["HT"]).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
 	return
 	return
 }
 }
 
 

+ 1 - 1
service/media/media_service.go

@@ -108,7 +108,7 @@ func RangeSearchByAnalyst(mediaType string, analystId int, userId int) (total in
 	return mediaService.GetAnalystMediaPermissionMappingByPermissionIds(mediaType, filterPermissionIds, analystId, riskLevel)
 	return mediaService.GetAnalystMediaPermissionMappingByPermissionIds(mediaType, filterPermissionIds, analystId, riskLevel)
 }
 }
 
 
-func getCount(mediaType string, permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, orgIds []int, mappingPdRisk string) {
+func getCount(mediaType string, permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, mediaIds []int, mappingPdRisk string) {
 	filterPermissionIds, riskLevel, err := user.GetRiskLevelPermissionList(permissionIds, isLogin, userId)
 	filterPermissionIds, riskLevel, err := user.GetRiskLevelPermissionList(permissionIds, isLogin, userId)
 	if err != nil {
 	if err != nil {
 		logger.Error("校验用户风险等级失败:%v", err)
 		logger.Error("校验用户风险等级失败:%v", err)

+ 2 - 12
service/report/report_service.go

@@ -325,16 +325,6 @@ func GetReportPage(pageInfo page.PageInfo, orgIds map[string][]int, discardIds [
 func GetReportPageByAnalyst(pageInfo page.PageInfo, analyst string, reportIds []int, templateUserId int) (list []reportService.ReportDTO, err error) {
 func GetReportPageByAnalyst(pageInfo page.PageInfo, analyst string, reportIds []int, templateUserId int) (list []reportService.ReportDTO, err error) {
 	list, err = reportService.GetReportPageByAnalyst(pageInfo, analyst, reportIds)
 	list, err = reportService.GetReportPageByAnalyst(pageInfo, analyst, reportIds)
 	list, err = dealReportInfo(list, true, templateUserId)
 	list, err = dealReportInfo(list, true, templateUserId)
-	//并发获取研报的标签
-	//var wg sync.WaitGroup
-	//wg.Add(len(list))
-	//for i := 0; i < len(list); i++ {
-	//	go func(report *reportService.ReportDTO) {
-	//		defer wg.Done()
-	//		report.Permissions, report.PermissionNames = GetReportPermissionNames(report.OrgId, report.Source)
-	//	}(&list[i])
-	//}
-	//wg.Wait()
 	if err != nil {
 	if err != nil {
 		err = exception.New(exception.QueryReportPageFailed)
 		err = exception.New(exception.QueryReportPageFailed)
 	}
 	}
@@ -591,12 +581,12 @@ 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) {
 func getCountByAnalyst(permissionIds []int, isLogin bool, userId int, analystName string) (total int64, latestId int64, ids []int) {
-	filterPermissionIds, riskLevel, err := user.GetRiskLevelPermissionList(permissionIds, isLogin, userId)
+	filterPermissionIds, _, err := user.GetRiskLevelPermissionList(permissionIds, isLogin, userId)
 	if err != nil {
 	if err != nil {
 		logger.Error("校验用户风险等级失败:%v", err)
 		logger.Error("校验用户风险等级失败:%v", err)
 		return
 		return
 	}
 	}
-	return reportService.GetTotalPageCountByAnalyst(analystName, filterPermissionIds, riskLevel)
+	return reportService.GetTotalPageCountByAnalyst(analystName, filterPermissionIds)
 }
 }
 
 
 func CountPermissionWeight(ids []int) (permissionMap map[int]int) {
 func CountPermissionWeight(ids []int) (permissionMap map[int]int) {