123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package report
- import (
- "eta/eta_mini_ht_api/common/component/es"
- "eta/eta_mini_ht_api/models/media"
- "eta/eta_mini_ht_api/task/base"
- "strconv"
- "strings"
- "time"
- )
- var (
- taskName base.TaskType = "ETAMediaDataTask"
- cron = "0/10 * * * * *"
- )
- // Execute Task ETA取研报的数据
- func (re *MediaTask) Execute(taskDetail *base.TaskDetail) error {
- lists := media.GetlIST()
- for _, list := range lists {
- ids := strings.Split(list.PermissionIDs, ",")
- for _, item := range ids {
- x, _ := strconv.Atoi(item)
- aa := media.MediaPermissionMapping{
- MediaID: list.Id,
- MediaType: list.MediaType,
- PermissionID: x,
- }
- media.InsertMediaPermissionMapping(aa)
- }
- }
- es1 := convert(lists)
- for _, item := range es1 {
- es.GetInstance().AddOrUpdate("media_index", item.MediaId, item)
- }
- return nil
- }
- func convert(list []media.Media) []ESMedia {
- var esMedia []ESMedia
- for _, item := range list {
- esMedia = append(esMedia, ESMedia{
- MediaId: item.Id,
- AuthorId: item.AuthorID,
- AuthorName: item.AuthorName,
- MediaType: string(item.MediaType),
- Src: item.Src,
- MediaName: item.MediaName,
- SourceType: item.SourceType,
- MediaPlayMilliseconds: item.MediaPlayMilliseconds,
- PermissionIDs: item.PermissionIDs,
- PublishedTime: item.PublishedTime.Format(time.DateTime),
- })
- }
- return esMedia
- }
- type ESMedia struct {
- MediaId int `json:"mediaId"`
- AuthorId int `json:"authorId"`
- AuthorName string `json:"authorName"`
- MediaType string `json:"mediaType"`
- Src string `json:"src"`
- MediaName string `json:"mediaName"`
- SourceType string `json:"sourceType"`
- MediaPlayMilliseconds int `json:"mediaPlayMilliseconds"`
- PermissionIDs string `json:"permissionIds"`
- PublishedTime string `json:"publishedTime"`
- }
- type MediaTask struct {
- }
- func init() {
- reportTask := base.NewTask(taskName, cron, new(MediaTask), base.FORBIDDEN)
- base.RegisterTask(&reportTask)
- }
|