Browse Source

过滤下架产品

kobe6258 3 months ago
parent
commit
f2c4709d59

+ 4 - 3
controllers/report/report_controller.go

@@ -36,7 +36,7 @@ func (r *ReportController) Search(key string) {
 		//获取当前可以被搜索的报告原始ID
 		//先要限制查询的id范围
 		var reportIds []int
-		pageRes.Total, pageRes.LatestId, reportIds, err = report.RangeSearch(key, isLogin(detailType), userInfo.Id)
+		pageRes.Total, pageRes.LatestId, reportIds, _, err = report.RangeSearch(key, isLogin(detailType), userInfo.Id)
 		if err != nil {
 			logger.Error("获取报告原始ID列表失败:%v", err)
 			r.FailedResult("分页搜索报告列表失败", result)
@@ -97,7 +97,8 @@ func (r *ReportController) List(permissionIds string) {
 			return
 		}
 		var reportOrgIds map[string][]int
-		pageRes.Total, pageRes.LatestId, reportOrgIds = report.GetTotalPageCountByPermissionIds(permissionIdList, isLogin(detailType), userInfo.Id)
+		var discardIds []int
+		pageRes.Total, pageRes.LatestId, reportOrgIds, discardIds = report.GetTotalPageCountByPermissionIds(permissionIdList, isLogin(detailType), userInfo.Id)
 		if pageRes.Total == 0 {
 			reports := new(page.PageResult)
 			reports.Data = []reportService.ReportDTO{}
@@ -119,7 +120,7 @@ func (r *ReportController) List(permissionIds string) {
 			r.SuccessResult("查询报告列表成功", reports, result)
 			return
 		}
-		list, err := report.GetReportPage(r.PageInfo, reportOrgIds, false, isLogin(detailType), userInfo.Id)
+		list, err := report.GetReportPage(r.PageInfo, reportOrgIds, discardIds, isLogin(detailType), userInfo.Id)
 		if err != nil {
 			r.FailedResult("分页查询报告列表失败", result)
 			return

+ 4 - 20
domian/report/report_service.go

@@ -322,9 +322,9 @@ func GetReportPageByAnalyst(pageInfo page.PageInfo, analyst string, reportIds []
 	}
 	return
 }
-func GetReportPageByOrgIds(pageInfo page.PageInfo, orgIds map[string][]int, searchAll bool) (list []ReportDTO, err error) {
+func GetReportPageByOrgIds(pageInfo page.PageInfo, orgIds map[string][]int, discardIds []int) (list []ReportDTO, err error) {
 	offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
-	reports, err := reportDao.GetReportPageByOrgIds(pageInfo.LatestId, pageInfo.PageSize, offset, orgIds, searchAll)
+	reports, err := reportDao.GetReportPageByOrgIds(pageInfo.LatestId, pageInfo.PageSize, offset, orgIds, discardIds)
 	if err != nil {
 		logger.Error("分页查询报告列表失败:%v", err)
 		return
@@ -350,22 +350,7 @@ func GetNewReportByPublishTime(time time.Time) (reports []ReportDTO) {
 	}
 	return
 }
-func GetReportPage(pageInfo page.PageInfo) (list []ReportDTO, err error) {
-	offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
-	reports, err := reportDao.GetReportPage(pageInfo.LatestId, pageInfo.PageSize, offset)
-	if err != nil {
-		logger.Error("分页查询报告列表失败:%v", err)
-		return
-	}
-	list = make([]ReportDTO, 0)
-	if reports != nil {
-		for _, report := range reports {
-			dto := convertReportDTO(report, false)
-			list = append(list, dto)
-		}
-	}
-	return
-}
+
 func getETAReportFirstPermissions(id int) (permissionDTOs []configService.PermissionDTO) {
 	classifyId, err := etaDao.GetReportClassifyById(id)
 	if err != nil || classifyId == 0 {
@@ -846,7 +831,7 @@ func GetReportByIdListByOrgIds(orgIds map[string][]int) (ids []int, err error) {
 	return reportDao.GetReportIdListByOrgIds(orgIds)
 }
 
-func GetTotalPageCountByPermissionIds(permissionIds []int) (total int64, latestId int64, ids map[string][]int) {
+func GetTotalPageCountByPermissionIds(permissionIds []int) (total int64, latestId int64, ids map[string][]int, disCardReportIds []int) {
 	htOrgIds, err := GetHTReportIdsByPermissionIdsWithRiskLevel(permissionIds)
 	if err != nil {
 		logger.Error("品种筛选ht报告id失败:%v", err)
@@ -875,7 +860,6 @@ func GetTotalPageCountByPermissionIds(permissionIds []int) (total int64, latestI
 	}
 	//获取一下下架的报告产品
 	var offSaleProducts []merchantDao.MerchantProduct
-	var disCardReportIds []int
 	offSaleProducts, err = merchantDao.GetOffSaleProducts([]merchantDao.MerchantProductType{merchantDao.Report, merchantDao.Package})
 	if err != nil {
 		logger.Error("获取下架的报告产品失败:%v", err)

+ 0 - 1
models/merchant/merchant_product.go

@@ -65,7 +65,6 @@ func GetMerchantProductBySourceId(sourceId int, productType ...MerchantProductTy
 		} else {
 			err = db.Select(detailColumns).Where("source_id =? and type in (?) and deleted =?", sourceId, productType, false).First(&product).Error
 		}
-
 	} else {
 		err = db.Select(detailColumns).Where("source_id =? and deleted =?", sourceId, false).First(&product).Error
 	}

+ 4 - 8
models/report/report.go

@@ -325,11 +325,7 @@ func GetReportPage(latestId int64, limit int, offset int) (list []Report, err er
 	return
 }
 
-func GetReportPageByOrgIds(latestId int64, limit int, offset int, orgIds map[string][]int, searchAll bool) (list []Report, err error) {
-	//有传入品种 但是没有筛选出来的已经过滤掉了,现在orgIds为空只有是
-	if searchAll {
-		return GetReportPage(latestId, limit, offset)
-	}
+func GetReportPageByOrgIds(latestId int64, limit int, offset int, orgIds map[string][]int, discardIds []int) (list []Report, err error) {
 	if latestId < 0 {
 		err = errors.New("非法的id参数")
 		logger.Error("非法的id参数:%d", latestId)
@@ -341,14 +337,14 @@ func GetReportPageByOrgIds(latestId int64, limit int, offset int, orgIds map[str
 	}
 	db := models.Main()
 	if len(orgIds["ETA"]) == 0 {
-		err = db.Select(CommonColumns).Where("id<= ?", latestId).Where("status = ?", StatusPublish).Where(" source='HT' and org_id in ?", orgIds["HT"]).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
+		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
 		return
 	}
 	if len(orgIds["HT"]) == 0 {
-		err = db.Select(CommonColumns).Where("id<= ?", latestId).Where("status = ?", StatusPublish).Where("source='ETA' and org_id in ?", orgIds["ETA"]).Order("published_time desc").Limit(limit).Offset(offset).Find(&list).Error
+		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
 		return
 	}
-	err = db.Select(CommonColumns).Where("id<= ?", latestId).Where("status = ?", StatusPublish).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 = 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
 	return
 }
 

+ 6 - 7
service/report/report_service.go

@@ -166,7 +166,7 @@ func getETAReportDetail(report *reportService.ReportDTO) (etaReport reportServic
 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) {
+func GetTotalPageCountByPermissionIds(permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, ids map[string][]int, disCardIds []int) {
 	return getCount(permissionIds, isLogin, userId)
 }
 
@@ -193,9 +193,9 @@ func SearchReportProduct(key string, docIds []int) (list []reportService.ReportD
 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) {
+func RangeSearch(key string, isLogin bool, userId int) (total int64, latestId int64, reportIds []int, discardIds []int, err error) {
 	var orgIds map[string][]int
-	_, latestId, orgIds = getCount(nil, isLogin, userId)
+	_, latestId, orgIds, discardIds = getCount(nil, isLogin, userId)
 	reportIds, err = GetReportByIdListByOrgIds(orgIds)
 	if err != nil {
 		logger.Error("获取报告ID列表失败:%v", err)
@@ -310,11 +310,10 @@ func DealReportInfo(report *reportService.ReportDTO, isLogin bool, userId int) (
 }
 
 // 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) (reports []reportService.ReportDTO, err error) {
 	var list []reportService.ReportDTO
-	list, err = reportService.GetReportPageByOrgIds(pageInfo, orgIds, searchAll)
+	list, err = reportService.GetReportPageByOrgIds(pageInfo, orgIds, discardIds)
 	reports, err = dealReportInfo(list, isLogin, userId)
-
 	if err != nil {
 		err = exception.New(exception.QueryReportPageFailed)
 	}
@@ -575,7 +574,7 @@ func RangePermissionIds(isLogin bool, userId int) (filterPermissionIds []int, ri
 	return user.GetRiskLevelPermissionList(nil, isLogin, userId)
 }
 
-func getCount(permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, ids map[string][]int) {
+func getCount(permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, ids map[string][]int, discardIds []int) {
 	filterPermissionIds, _, err := user.GetRiskLevelPermissionList(permissionIds, isLogin, userId)
 	if err != nil {
 		logger.Error("获取过滤品种信息失败:%v", err)