12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package media
- import (
- "encoding/json"
- logger "eta/eta_mini_ht_api/common/component/log"
- )
- const (
- ChartESColumn = "chartName"
- ChartESRangeColumn = "chartInfoId"
- )
- // func SearchMediaList(_ string, key string, mediaIds []int, from int, size int, max int64) (medias []MediaDTO, err error) {
- // //同步es
- // var docIds []string
- // for _, id := range mediaIds {
- // docIds = append(docIds, strconv.Itoa(id))
- // }
- // sorts := append(sortField, "publishedTime:desc")
- // request := matchRangeWithDocIds(key, from, size, max, sorts, docIds)
- // re, err := elastic().Search(request)
- // if err != nil {
- // 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)
- // media := MediaDTO{}
- // err = json.Unmarshal(hit.Source, &media)
- // if err != nil {
- // logger.Error("解析媒体数据失败:%v", err)
- // continue
- // }
- // media.Highlight = content[ESColumn]
- // media.PublishedTime = media.PublishedTime[:10]
- // media.MediaTitle = media.Highlight[0]
- // medias = append(medias, media)
- // }
- // return
- // }
- type EsChartInfo struct {
- ChartInfoId int
- ChartName string
- ChartImage string
- UniqueCode string
- }
- // 同步es
- func AddChartToEs(esChart EsChartInfo) bool {
- return elastic().InsertOrUpdate(htConfig.GetChartIndex(), esChart.ChartInfoId, esChart)
- }
- func UpdateChartImage(image string, id int) bool {
- doc, err := elastic().Get(htConfig.GetChartIndex(), id)
- if err != nil {
- return false
- }
- var chartInfo EsChartInfo
- err = json.Unmarshal(doc.Source, &chartInfo)
- if err != nil {
- logger.Error("es获取图表数据失败:%v", err)
- return false
- }
- if chartInfo.ChartInfoId == 0 {
- logger.Error("es获取图表数据失败,chartInfoId:%d", id)
- return false
- }
- chartInfo.ChartImage = image
- return elastic().Update(htConfig.GetChartIndex(), chartInfo.ChartInfoId, chartInfo)
- }
- func GetChartById(id int) (chartInfo EsChartInfo, err error) {
- doc, err := elastic().Get(htConfig.GetChartIndex(), id)
- if err != nil {
- logger.Error("es获取图表数据失败:%v", err)
- return
- }
- err = json.Unmarshal(doc.Source, &chartInfo)
- if err != nil {
- logger.Error("序列化json数据失败,获取图表数据失败:%v", err)
- return
- }
- return
- }
|