|
@@ -139,31 +139,41 @@ func GetReportById(reportId int) (ReportDTO ReportDTO, err error) {
|
|
|
ReportDTO.AuthorInfo = authorList
|
|
|
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)
|
|
|
if err != nil {
|
|
|
logger.Error("查询研究研报告列表id失败:%v", err)
|
|
|
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 {
|
|
|
logger.Info("没有符合权限的研报")
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
orgIds := make(map[string][]int, 2)
|
|
|
if len(etaOrgIds) == 0 {
|
|
|
orgIds["ETA"] = []int{}
|
|
@@ -175,6 +185,7 @@ func GetTotalPageCountByAnalyst(analyst string, permissionIds []int, riskLevel s
|
|
|
} else {
|
|
|
orgIds["HT"] = htOrgIds
|
|
|
}
|
|
|
+
|
|
|
permitReportIds, err := reportDao.GetReportIdListByOrgIds(orgIds)
|
|
|
if err != nil {
|
|
|
logger.Error("根据原始报告id获取报告id列表失败:%v", err)
|
|
@@ -193,6 +204,79 @@ func GetTotalPageCountByAnalyst(analyst string, permissionIds []int, riskLevel s
|
|
|
return
|
|
|
}
|
|
|
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))
|
|
|
latestId = int64(findMax(filterReportIds))
|
|
|
return
|
|
@@ -214,34 +298,6 @@ func findMax(nums []int) (max int) {
|
|
|
}
|
|
|
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) {
|
|
|
sort := []string{"reportId:desc"}
|
|
|
var docIds []string
|
|
@@ -341,17 +397,6 @@ func GetReportPageByOrgIds(pageInfo page.PageInfo, orgIds map[string][]int, disc
|
|
|
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) {
|
|
|
classifyId, err := etaDao.GetReportClassifyById(id)
|
|
|
if err != nil || classifyId == 0 {
|
|
@@ -359,7 +404,6 @@ func getETAReportFirstPermissions(id int) (permissionDTOs []configService.Permis
|
|
|
return
|
|
|
}
|
|
|
permissions, err := permissionDao.GetFirstPermissionsByClassifyID(classifyId)
|
|
|
- //permissions, err := etaDao.GetFirstPermissionsByClassifyID(classifyId)
|
|
|
if err != nil {
|
|
|
logger.Error("获取研报一级品种信息失败:%v", err)
|
|
|
return
|