eta_training_video.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package eta_training_video
  2. import (
  3. "fmt"
  4. "hongze/hz_crm_api/models/eta_training_video"
  5. "hongze/hz_crm_api/utils"
  6. "strconv"
  7. "strings"
  8. )
  9. // FormatVideosToVideoItems 格式化视频列表
  10. func FormatVideosToVideoItems(list []*eta_training_video.EtaTrainingVideo) (items []*eta_training_video.EtaTrainingVideoItem, err error) {
  11. items = make([]*eta_training_video.EtaTrainingVideoItem, 0)
  12. if len(list) == 0 {
  13. return
  14. }
  15. // 获取分类
  16. classifyMap := make(map[int]*eta_training_video.EtaTrainingVideoClassify)
  17. {
  18. classifyOB := new(eta_training_video.EtaTrainingVideoClassify)
  19. classifies, e := classifyOB.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  20. if e != nil {
  21. err = fmt.Errorf("获取分类列表失败, Err: %s", e.Error())
  22. return
  23. }
  24. for _, v := range classifies {
  25. classifyMap[v.EtaTrainingVideoClassifyId] = v
  26. }
  27. }
  28. // 获取标签
  29. tagMap := make(map[int]*eta_training_video.EtaTrainingVideoTag)
  30. {
  31. tagOB := new(eta_training_video.EtaTrainingVideoTag)
  32. tags, e := tagOB.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  33. if e != nil {
  34. err = fmt.Errorf("获取标签列表失败, Err: %s", e.Error())
  35. return
  36. }
  37. for _, v := range tags {
  38. tagMap[v.EtaTrainingVideoTagId] = v
  39. }
  40. }
  41. for _, v := range list {
  42. b := new(eta_training_video.EtaTrainingVideoItem)
  43. b.VideoId = v.EtaTrainingVideoId
  44. b.VideoCode = v.VideoCode
  45. b.Title = v.Title
  46. b.Introduce = v.Introduce
  47. b.CoverImg = v.CoverImg
  48. b.VideoUrl = v.VideoUrl
  49. b.PublishState = v.PublishState
  50. b.PublishTime = utils.TimeTransferString(utils.FormatDateTime, v.PublishTime)
  51. b.ViewTotal = v.ViewTotal
  52. b.CreateTime = utils.TimeTransferString(utils.FormatDateTime, v.CreateTime)
  53. b.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, v.ModifyTime)
  54. // 分类
  55. if v.ClassifyIds != "" {
  56. strClassifyIdArr := strings.Split(v.ClassifyIds, ",")
  57. if len(strClassifyIdArr) > 0 {
  58. arr := make([]*eta_training_video.EtaTrainingVideoClassifyItem, 0)
  59. for _, s := range strClassifyIdArr {
  60. id, _ := strconv.Atoi(s)
  61. c := classifyMap[id]
  62. if c != nil {
  63. arr = append(arr, &eta_training_video.EtaTrainingVideoClassifyItem{
  64. ClassifyId: c.EtaTrainingVideoClassifyId,
  65. ClassifyName: c.ClassifyName,
  66. ParentId: c.ParentId,
  67. Sort: c.Sort,
  68. })
  69. }
  70. }
  71. tree := GetClassifyTreeRecursive(arr, 0)
  72. if len(tree) > 0 {
  73. b.Classify = tree[0]
  74. }
  75. }
  76. }
  77. // 标签
  78. if v.TagIds != "" {
  79. strTagIdArr := strings.Split(v.TagIds, ",")
  80. if len(strTagIdArr) > 0 {
  81. b.Tags = make([]*eta_training_video.EtaTrainingVideoTagItem, 0)
  82. for _, s := range strTagIdArr {
  83. id, _ := strconv.Atoi(s)
  84. t := tagMap[id]
  85. if t != nil {
  86. b.Tags = append(b.Tags, &eta_training_video.EtaTrainingVideoTagItem{
  87. TagId: t.EtaTrainingVideoTagId,
  88. TagName: t.TagName,
  89. VideoTotal: t.VideoTotal,
  90. CreateTime: utils.TimeTransferString(utils.FormatDateTime, t.CreateTime),
  91. ModifyTime: utils.TimeTransferString(utils.FormatDateTime, t.ModifyTime),
  92. })
  93. }
  94. }
  95. }
  96. }
  97. items = append(items, b)
  98. }
  99. return
  100. }