eta_training_video.go 2.9 KB

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