|
@@ -8,6 +8,8 @@ import (
|
|
|
reportService "eta_mini_ht_api/domian/report"
|
|
|
"eta_mini_ht_api/models"
|
|
|
mediaDao "eta_mini_ht_api/models/media"
|
|
|
+ "sort"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
const (
|
|
@@ -15,9 +17,9 @@ const (
|
|
|
ASC models.Order = "asc"
|
|
|
|
|
|
ESIndex = "media_index"
|
|
|
- ESColumn = "media_name"
|
|
|
- ESRangeColumn = "media_id"
|
|
|
- ConditionColumn = "media_type"
|
|
|
+ ESColumn = "mediaName"
|
|
|
+ ESRangeColumn = "mediaId"
|
|
|
+ ConditionColumn = "mediaType"
|
|
|
)
|
|
|
|
|
|
var (
|
|
@@ -36,80 +38,103 @@ type MediaDTO struct {
|
|
|
MediaName string `json:"mediaName"`
|
|
|
SourceType string `json:"sourceType"`
|
|
|
MediaPlaySeconds int `json:"mediaPlaySeconds"`
|
|
|
- PermissionIDs string `json:"permissionIDs"`
|
|
|
+ PublishedTime string `json:"publishedTime"`
|
|
|
+ PermissionIDs string `json:"permissionIds"`
|
|
|
PermissionNames []string `json:"permissionNames,omitempty"`
|
|
|
Highlight []string `json:"highlight,omitempty"`
|
|
|
}
|
|
|
|
|
|
func SearchMediaList(mediaType string, key string, from int, size int, max int64) (reports []MediaDTO, err error) {
|
|
|
//同步es
|
|
|
- sorts := append(sortField, "media_id:desc")
|
|
|
+ sorts := append(sortField, "publishedTime:desc")
|
|
|
request := matchRangeByCondition(key, from, size, max, sorts, ConditionColumn, mediaType)
|
|
|
re, err := elastic().Search(request)
|
|
|
if err != nil {
|
|
|
- logger.Error("es:%v", err)
|
|
|
+ logger.Error("es搜索失败:%v", err)
|
|
|
}
|
|
|
hits := elastic().GetSource(re.Hits)
|
|
|
for _, hit := range hits {
|
|
|
var content map[string][]string
|
|
|
err = json.Unmarshal(hit.Highlight, &content)
|
|
|
- report := MediaDTO{}
|
|
|
- report.Highlight = content[ESColumn]
|
|
|
- err = json.Unmarshal(hit.Source, &report)
|
|
|
+ meida := MediaDTO{}
|
|
|
+ err = json.Unmarshal(hit.Source, &meida)
|
|
|
if err != nil {
|
|
|
- logger.Error("解析研报数据失败:%v", err)
|
|
|
+ logger.Error("解析媒体数据失败:%v", err)
|
|
|
continue
|
|
|
}
|
|
|
- reports = append(reports, report)
|
|
|
+ meida.Highlight = content[ESColumn]
|
|
|
+ meida.PublishedTime = meida.PublishedTime[:10]
|
|
|
+ reports = append(reports, meida)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
-func SearchMaxMediaId(mediaType string) (mediaId int64) {
|
|
|
- sort := []string{"media_id:desc"}
|
|
|
- request := matchAllByCondition(sort, ConditionColumn, mediaType)
|
|
|
+func SearchMaxMediaId(mediaType string, key string) (total int64, latestId int64) {
|
|
|
+ sort := []string{"mediaId:desc"}
|
|
|
+ request := matchAllByCondition(sort, key, ConditionColumn, mediaType)
|
|
|
//同步es
|
|
|
- re, err := elastic().Search(request)
|
|
|
+ //re, err := elastic().Search(request)
|
|
|
+ re, err := elastic().Count(request)
|
|
|
if err != nil {
|
|
|
- logger.Error("es:%v", err)
|
|
|
+ logger.Error("es搜索失败:%v", err)
|
|
|
}
|
|
|
- hits := elastic().GetSource(re.Hits)
|
|
|
- if len(hits) > 0 {
|
|
|
+ count := re.Count
|
|
|
+ total = int64(count)
|
|
|
+ if total > 0 {
|
|
|
+ request = matchByCondition(sort, key, ConditionColumn, mediaType, 0, count)
|
|
|
+ re, err = elastic().Search(request)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("es搜索异常:%v", err)
|
|
|
+ }
|
|
|
+ hits := elastic().GetSource(re.Hits)
|
|
|
data := hits[0].Source
|
|
|
media := MediaDTO{}
|
|
|
err = json.Unmarshal(data, &media)
|
|
|
if err != nil {
|
|
|
- logger.Error("获取当前最大研报id失败:%v", err)
|
|
|
- return 0
|
|
|
+ logger.Error("获取当前最大媒体id失败:%v", err)
|
|
|
+ return
|
|
|
}
|
|
|
- return int64(media.MediaPlaySeconds)
|
|
|
+ total = int64(len(hits))
|
|
|
+ latestId = int64(media.MediaId)
|
|
|
+ return
|
|
|
}
|
|
|
- return 0
|
|
|
+ return
|
|
|
}
|
|
|
-func GetTotalPageCount(mediaType string) (count int64) {
|
|
|
+func GetMediaPermissionMappingByPermissionIds(mediaType string, permissionIds []int) (total int64, latestId int64, ids []int) {
|
|
|
+ ids, err := mediaDao.GetMediaPermissionMappingByPermissionId(mediaType, permissionIds)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取当前最大媒体id失败:%v", err)
|
|
|
+ return 0, 0, ids
|
|
|
+ }
|
|
|
+ sort.Slice(ids, func(i, j int) bool {
|
|
|
+ return ids[i] > ids[j]
|
|
|
+ })
|
|
|
+ return int64(len(ids)), int64(ids[0]), ids
|
|
|
+}
|
|
|
+func GetTotalPageCount(mediaType string) (count int64, latestId int64) {
|
|
|
return mediaDao.GetCountByMediaType(mediaType)
|
|
|
}
|
|
|
-func GetMediaPage(mediaType string, pageInfo page.PageInfo) (list []MediaDTO, err error) {
|
|
|
+func GetMediaPageByIds(mediaType string, pageInfo page.PageInfo, mediaIds []int) (list []MediaDTO, err error) {
|
|
|
offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
|
|
|
- reports, err := mediaDao.GetMediaPage(pageInfo.LatestId, pageInfo.PageSize, offset, mediaType)
|
|
|
- if err == nil && reports != nil {
|
|
|
- for _, report := range reports {
|
|
|
- dto := convertMediaDTO(report)
|
|
|
+ medias, err := mediaDao.GetMediaPageByIds(pageInfo.LatestId, pageInfo.PageSize, offset, mediaType, mediaIds)
|
|
|
+ if err == nil && medias != nil {
|
|
|
+ for _, media := range medias {
|
|
|
+ dto := convertMediaDTO(media)
|
|
|
list = append(list, dto)
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
-func convertMediaDTO(media mediaDao.Medias) MediaDTO {
|
|
|
+func convertMediaDTO(media mediaDao.Media) MediaDTO {
|
|
|
return MediaDTO{
|
|
|
- MediaId: media.ID,
|
|
|
+ MediaId: media.Id,
|
|
|
AuthorName: media.AuthorName,
|
|
|
- MediaType: media.MediaType,
|
|
|
+ MediaType: string(media.MediaType),
|
|
|
Src: media.Src,
|
|
|
MediaName: media.MediaName,
|
|
|
SourceType: media.SourceType,
|
|
|
MediaPlaySeconds: media.MediaPlaySeconds,
|
|
|
PermissionIDs: media.PermissionIDs,
|
|
|
+ PublishedTime: media.PublishedTime.Format(time.DateOnly),
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -117,12 +142,16 @@ func GetPermissionsByIds(ids []int) (permissionDTOs []reportService.PermissionDT
|
|
|
return reportService.GetFirstPermissionsByIds(ids)
|
|
|
}
|
|
|
|
|
|
-func matchAllByCondition(sorts []string, column string, value string) (request *es.ESQueryRequest) {
|
|
|
+func matchAllByCondition(sorts []string, key string, column string, value string) (request *es.ESQueryRequest) {
|
|
|
req := new(es.ESQueryRequest)
|
|
|
- return req.CreateESQueryRequest(ESIndex, "", "", 0, 1, sorts, es.MatchAllByCondition).ByCondition(column, value)
|
|
|
+ return req.CreateESQueryRequest(ESIndex, ESColumn, key, 0, 1, sorts, es.MatchAllByCondition).ByCondition(column, value)
|
|
|
}
|
|
|
|
|
|
+func matchByCondition(sorts []string, key string, column string, value string, from int, to int) (request *es.ESQueryRequest) {
|
|
|
+ req := new(es.ESQueryRequest)
|
|
|
+ return req.CreateESQueryRequest(ESIndex, ESColumn, key, from, to, sorts, es.MatchAllByCondition).ByCondition(column, value)
|
|
|
+}
|
|
|
func matchRangeByCondition(key string, from int, to int, max int64, sorts []string, column string, value string) (request *es.ESQueryRequest) {
|
|
|
req := new(es.ESQueryRequest)
|
|
|
- return req.CreateESQueryRequest(ESIndex, ESColumn, key, from, to, sorts, es.Range).Range(0, max, ESRangeColumn).ByCondition(column, value)
|
|
|
+ return req.CreateESQueryRequest(ESIndex, ESColumn, key, from, to, sorts, es.RangeByCondition).Range(0, max, ESRangeColumn).ByCondition(column, value)
|
|
|
}
|