|
@@ -5,6 +5,7 @@ import (
|
|
|
"eta/eta_mini_ht_api/common/exception"
|
|
|
"eta/eta_mini_ht_api/common/utils/page"
|
|
|
permissionService "eta/eta_mini_ht_api/domian/config"
|
|
|
+ mediaDomain "eta/eta_mini_ht_api/domian/media"
|
|
|
merchantService "eta/eta_mini_ht_api/domian/merchant"
|
|
|
reportDomain "eta/eta_mini_ht_api/domian/report"
|
|
|
"eta/eta_mini_ht_api/domian/user"
|
|
@@ -16,7 +17,9 @@ import (
|
|
|
"eta/eta_mini_ht_api/service/order"
|
|
|
reportService "eta/eta_mini_ht_api/service/report"
|
|
|
"fmt"
|
|
|
+ "sort"
|
|
|
"sync"
|
|
|
+ "sync/atomic"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -110,7 +113,6 @@ func GetProductRiskLevel(product merchantService.MerchantProductDTO) (riskLevel,
|
|
|
}
|
|
|
}
|
|
|
_, permissionNames = reportService.GetReportPermissionNames(report.OrgId, report.Source)
|
|
|
- //permissionNames = strings.Join(permissionNamesList, ",")
|
|
|
}
|
|
|
default:
|
|
|
logger.Warn("不支持的产品类型[%s]", product.Type)
|
|
@@ -322,13 +324,11 @@ func ProductList(productIds []int, templateUserId int, info page.PageInfo) (dtoL
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
-func RangeProductList(isSignal bool) (total, latestId int64, ids []int) {
|
|
|
- //return merchantService.CountProductListByProductType(isSignal)
|
|
|
- return 0, 0, nil
|
|
|
+func RangeProductList() (productIdMap map[string][]int, err error) {
|
|
|
+ return merchantService.GetProductByProductType()
|
|
|
}
|
|
|
-func ProductSearch(productType string, key string, templateUserId int, pageInfo page.PageInfo) (list []ProductDTO, err error) {
|
|
|
+func ProductSearch(key string, templateUserId int, pageInfo page.PageInfo) (list []ProductDTO, err error) {
|
|
|
var merchantProductList []merchantService.MerchantProductDTO
|
|
|
- merchantProductList, err = merchantService.GetProductListByProductType(productType)
|
|
|
var sourceIds []int
|
|
|
var maxId int
|
|
|
for _, product := range merchantProductList {
|
|
@@ -347,6 +347,106 @@ func ProductSearch(productType string, key string, templateUserId int, pageInfo
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func PackageSearch(key string, templateUserId int) (list []ProductDTO, err error) {
|
|
|
- return nil, nil
|
|
|
+func convertReportToSearchDTO(report reportDomain.ReportDTO) (dto reportDomain.ProductSearchDTO) {
|
|
|
+ return reportDomain.ProductSearchDTO{
|
|
|
+ HighLight: report.Highlight[0],
|
|
|
+ SourceId: report.ReportID,
|
|
|
+ SourceType: "report",
|
|
|
+ Score: report.Score,
|
|
|
+ }
|
|
|
+}
|
|
|
+func convertMediaToSearchDTO(media mediaDomain.MediaDTO) (dto reportDomain.ProductSearchDTO) {
|
|
|
+ return reportDomain.ProductSearchDTO{
|
|
|
+ HighLight: media.Highlight[0],
|
|
|
+ SourceId: media.MediaId,
|
|
|
+ SourceType: media.MediaType,
|
|
|
+ Score: media.Score,
|
|
|
+ }
|
|
|
+}
|
|
|
+func SearchRelateProduct(key string, productIdMap map[string][]int) (list []reportDomain.ProductSearchDTO, err error) {
|
|
|
+ var wg sync.WaitGroup
|
|
|
+ wg.Add(2)
|
|
|
+ go func() {
|
|
|
+ defer wg.Done()
|
|
|
+ docIds := productIdMap["report"]
|
|
|
+ reports, reportErr := reportService.SearchReportProduct(key, docIds)
|
|
|
+ if reportErr != nil {
|
|
|
+ logger.Error("搜索相关报告失败:%v,key:%s", reportErr, key)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, report := range reports {
|
|
|
+ list = append(list, convertReportToSearchDTO(report))
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ go func() {
|
|
|
+ defer wg.Done()
|
|
|
+ docIds := append(productIdMap["audio"], productIdMap["video"]...)
|
|
|
+ medias, mediaErr := mediaService.SearchMediaProduct(key, docIds)
|
|
|
+ if mediaErr != nil {
|
|
|
+ logger.Error("搜索相关媒体失败:%v,key:%s", mediaErr, key)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, mediaInfo := range medias {
|
|
|
+ list = append(list, convertMediaToSearchDTO(mediaInfo))
|
|
|
+ }
|
|
|
+ list = append(list, reportDomain.ProductSearchDTO{
|
|
|
+ HighLight: "",
|
|
|
+ SourceId: 165,
|
|
|
+ SourceType: "audio",
|
|
|
+ Score: 12.31,
|
|
|
+ })
|
|
|
+ }()
|
|
|
+ wg.Wait()
|
|
|
+ sort.Slice(list, func(i, j int) bool {
|
|
|
+ return list[i].Score > list[j].Score
|
|
|
+ })
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func LatestId() (latestId int64) {
|
|
|
+ return merchantService.LatestId()
|
|
|
+}
|
|
|
+
|
|
|
+func CountSearchPackageList(list []reportDomain.ProductSearchDTO) (total, latestId int64, permissionTotalMap map[int]*atomic.Int32) {
|
|
|
+ var productIdMap map[string][]int
|
|
|
+ for _, product := range list {
|
|
|
+ ids := productIdMap[product.SourceType]
|
|
|
+ ids = append(ids, product.SourceId)
|
|
|
+ productIdMap[product.SourceType] = ids
|
|
|
+ }
|
|
|
+ var wg sync.WaitGroup
|
|
|
+ wg.Add(len(productIdMap))
|
|
|
+ for key, ids := range productIdMap {
|
|
|
+ go func(k string, ids []int) {
|
|
|
+ var permissionMap map[int]int
|
|
|
+ switch k {
|
|
|
+ case "report":
|
|
|
+ permissionMap = reportService.CountPermissionWeight(ids)
|
|
|
+ case "audio", "video":
|
|
|
+ permissionMap = mediaService.CountPermissionWeight(ids)
|
|
|
+ }
|
|
|
+ for permissionId, weight := range permissionMap {
|
|
|
+ permissionTotalMap[permissionId].Add(int32(weight))
|
|
|
+ }
|
|
|
+ }(key, ids)
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+ total = int64(len(permissionTotalMap))
|
|
|
+ latestId = merchantService.LatestId()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func ProductListBySort(isSignal bool, list []reportDomain.ProductSearchDTO, weightMap map[int]*atomic.Int32, id int, info page.PageInfo) (resultList []ProductDTO, err error) {
|
|
|
+ var pdDTOS []merchantService.MerchantProductDTO
|
|
|
+ pdDTOS, err = merchantService.ProductListBySort(isSignal, list, weightMap, info)
|
|
|
+ var wg sync.WaitGroup
|
|
|
+ wg.Add(len(pdDTOS))
|
|
|
+ for _, pd := range pdDTOS {
|
|
|
+ go func(pd merchantService.MerchantProductDTO) {
|
|
|
+ productDTO := convertToProductDTO(pd)
|
|
|
+ productDTO.RiskLevel, productDTO.SourceTile, productDTO.Abstract, productDTO.CoverUrl, productDTO.Src, productDTO.PermissionNames, _, err = GetProductRiskLevel(pd)
|
|
|
+ }(pd)
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+ return
|
|
|
}
|