eta_media_task.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package report
  2. import (
  3. "eta/eta_mini_ht_api/common/component/es"
  4. "eta/eta_mini_ht_api/models/media"
  5. "eta/eta_mini_ht_api/task/base"
  6. "strconv"
  7. "strings"
  8. "time"
  9. )
  10. var (
  11. taskName base.TaskType = "ETAMediaDataTask"
  12. cron = "0/10 * * * * *"
  13. )
  14. // Execute Task ETA取研报的数据
  15. func (re *MediaTask) Execute(taskDetail *base.TaskDetail) error {
  16. lists := media.GetlIST()
  17. for _, list := range lists {
  18. ids := strings.Split(list.PermissionIDs, ",")
  19. for _, item := range ids {
  20. x, _ := strconv.Atoi(item)
  21. aa := media.MediaPermissionMapping{
  22. MediaID: list.Id,
  23. MediaType: list.MediaType,
  24. PermissionID: x,
  25. }
  26. media.InsertMediaPermissionMapping(aa)
  27. }
  28. }
  29. es1 := convert(lists)
  30. for _, item := range es1 {
  31. es.GetInstance().AddOrUpdate("media_index", item.MediaId, item)
  32. }
  33. return nil
  34. }
  35. func convert(list []media.Media) []ESMedia {
  36. var esMedia []ESMedia
  37. for _, item := range list {
  38. esMedia = append(esMedia, ESMedia{
  39. MediaId: item.Id,
  40. AuthorId: item.AuthorID,
  41. AuthorName: item.AuthorName,
  42. MediaType: string(item.MediaType),
  43. Src: item.Src,
  44. MediaName: item.MediaName,
  45. SourceType: item.SourceType,
  46. MediaPlayMilliseconds: item.MediaPlayMilliseconds,
  47. PermissionIDs: item.PermissionIDs,
  48. PublishedTime: item.PublishedTime.Format(time.DateTime),
  49. })
  50. }
  51. return esMedia
  52. }
  53. type ESMedia struct {
  54. MediaId int `json:"mediaId"`
  55. AuthorId int `json:"authorId"`
  56. AuthorName string `json:"authorName"`
  57. MediaType string `json:"mediaType"`
  58. Src string `json:"src"`
  59. MediaName string `json:"mediaName"`
  60. SourceType string `json:"sourceType"`
  61. MediaPlayMilliseconds int `json:"mediaPlayMilliseconds"`
  62. PermissionIDs string `json:"permissionIds"`
  63. PublishedTime string `json:"publishedTime"`
  64. }
  65. type MediaTask struct {
  66. }
  67. func init() {
  68. reportTask := base.NewTask(taskName, cron, new(MediaTask), base.FORBIDDEN)
  69. base.RegisterTask(&reportTask)
  70. }