123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- package eta_training_video
- import (
- "fmt"
- "hongze/hz_crm_api/models/eta_training_video"
- "hongze/hz_crm_api/utils"
- "strconv"
- "strings"
- )
- // FormatVideosToVideoItems 格式化视频列表
- func FormatVideosToVideoItems(list []*eta_training_video.EtaTrainingVideo) (items []*eta_training_video.EtaTrainingVideoItem, err error) {
- items = make([]*eta_training_video.EtaTrainingVideoItem, 0)
- if len(list) == 0 {
- return
- }
- // 获取分类
- classifyMap := make(map[int]*eta_training_video.EtaTrainingVideoClassify)
- {
- classifyOB := new(eta_training_video.EtaTrainingVideoClassify)
- classifies, e := classifyOB.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
- if e != nil {
- err = fmt.Errorf("获取分类列表失败, Err: %s", e.Error())
- return
- }
- for _, v := range classifies {
- classifyMap[v.EtaTrainingVideoClassifyId] = v
- }
- }
- // 获取标签
- tagMap := make(map[int]*eta_training_video.EtaTrainingVideoTag)
- {
- tagOB := new(eta_training_video.EtaTrainingVideoTag)
- tags, e := tagOB.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
- if e != nil {
- err = fmt.Errorf("获取标签列表失败, Err: %s", e.Error())
- return
- }
- for _, v := range tags {
- tagMap[v.EtaTrainingVideoTagId] = v
- }
- }
- for _, v := range list {
- b := new(eta_training_video.EtaTrainingVideoItem)
- b.VideoId = v.EtaTrainingVideoId
- b.VideoCode = v.VideoCode
- b.Title = v.Title
- b.Introduce = v.Introduce
- b.CoverImg = v.CoverImg
- b.VideoUrl = v.VideoUrl
- b.PublishState = v.PublishState
- b.PublishTime = utils.TimeTransferString(utils.FormatDateTime, v.PublishTime)
- b.ViewTotal = v.ViewTotal
- b.CreateTime = utils.TimeTransferString(utils.FormatDateTime, v.CreateTime)
- b.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, v.ModifyTime)
- // 分类
- if v.ClassifyIds != "" {
- strClassifyIdArr := strings.Split(v.ClassifyIds, ",")
- if len(strClassifyIdArr) > 0 {
- arr := make([]*eta_training_video.EtaTrainingVideoClassifyItem, 0)
- for _, s := range strClassifyIdArr {
- id, _ := strconv.Atoi(s)
- c := classifyMap[id]
- if c != nil {
- arr = append(arr, &eta_training_video.EtaTrainingVideoClassifyItem{
- ClassifyId: c.EtaTrainingVideoClassifyId,
- ClassifyName: c.ClassifyName,
- ParentId: c.ParentId,
- Sort: c.Sort,
- })
- }
- }
- tree := GetClassifyTreeRecursive(arr, 0)
- if len(tree) > 0 {
- b.Classify = tree[0]
- }
- }
- }
- // 标签
- if v.TagIds != "" {
- strTagIdArr := strings.Split(v.TagIds, ",")
- if len(strTagIdArr) > 0 {
- b.Tags = make([]*eta_training_video.EtaTrainingVideoTagItem, 0)
- for _, s := range strTagIdArr {
- id, _ := strconv.Atoi(s)
- t := tagMap[id]
- if t != nil {
- b.Tags = append(b.Tags, &eta_training_video.EtaTrainingVideoTagItem{
- TagId: t.EtaTrainingVideoTagId,
- TagName: t.TagName,
- VideoTotal: t.VideoTotal,
- CreateTime: utils.TimeTransferString(utils.FormatDateTime, t.CreateTime),
- ModifyTime: utils.TimeTransferString(utils.FormatDateTime, t.ModifyTime),
- })
- }
- }
- }
- }
- items = append(items, b)
- }
- return
- }
|