123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- package services
- import (
- "eta/eta_docs/models/crm"
- "eta/eta_docs/models/response"
- "eta/eta_docs/utils"
- "fmt"
- "strconv"
- "strings"
- )
- // FormatVideosToVideoItems 格式化视频列表
- func FormatVideosToVideoItems(list []*crm.EtaTrainingVideo) (items []*response.EtaTrainingVideoItem, err error) {
- items = make([]*response.EtaTrainingVideoItem, 0)
- if len(list) == 0 {
- return
- }
- // 获取分类
- classifyMap := make(map[int]*crm.EtaTrainingVideoClassify)
- {
- classifyOB := new(crm.EtaTrainingVideoClassify)
- classifies, e := classifyOB.GetItemsByCondition(``, make([]interface{}, 0), "")
- if e != nil {
- err = fmt.Errorf("获取分类列表失败, Err: %s", e.Error())
- return
- }
- for _, v := range classifies {
- classifyMap[v.EtaTrainingVideoClassifyId] = v
- }
- }
- // 获取标签
- tagMap := make(map[int]*crm.EtaTrainingVideoTag)
- {
- tagOB := new(crm.EtaTrainingVideoTag)
- tags, e := tagOB.GetItemsByCondition(``, make([]interface{}, 0), "")
- 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(response.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([]*response.EtaTrainingVideoClassifyItem, 0)
- for _, s := range strClassifyIdArr {
- id, _ := strconv.Atoi(s)
- c := classifyMap[id]
- if c != nil {
- arr = append(arr, &response.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([]*response.EtaTrainingVideoTagItem, 0)
- for _, s := range strTagIdArr {
- id, _ := strconv.Atoi(s)
- t := tagMap[id]
- if t != nil {
- b.Tags = append(b.Tags, &response.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
- }
|