ziwen 2 gadi atpakaļ
vecāks
revīzija
f1cb05656e
3 mainītis faili ar 50 papildinājumiem un 110 dzēšanām
  1. 23 2
      controllers/user.go
  2. 26 107
      models/micro_roadshow.go
  3. 1 1
      services/user.go

+ 23 - 2
controllers/user.go

@@ -7,6 +7,7 @@ import (
 	"hongze/hongze_clpt/models"
 	"hongze/hongze_clpt/services"
 	"hongze/hongze_clpt/utils"
+	"sort"
 	"strconv"
 	"strings"
 	"time"
@@ -1177,19 +1178,25 @@ func (this *UserController) Mycollect() {
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
 		return
 	}
-
+	collectVoiceMap := make(map[int]time.Time, 0)
+	collectVideoMap := make(map[int]time.Time, 0)
+	collectActivityVideoMap := make(map[int]time.Time, 0)
 	var audioIds []string
 	var videoIds []string
 	var activityVideoIds []string
 	for _, item := range listMycollect {
 		if item.ActivityVoiceId > 0 {
 			audioIds = append(audioIds, strconv.Itoa(item.ActivityVoiceId))
+			collectVoiceMap[item.ActivityVoiceId] = item.CreateTime
 		} else if item.VideoId > 0 {
 			videoIds = append(videoIds, strconv.Itoa(item.VideoId))
+			collectVideoMap[item.VideoId] = item.CreateTime
 		} else if item.ActivityVideoId > 0 {
 			activityVideoIds = append(activityVideoIds, strconv.Itoa(item.ActivityVideoId))
+			collectActivityVideoMap[item.ActivityVideoId] = item.CreateTime
 		}
 	}
+
 	if len(audioIds) == 0 && len(videoIds) == 0 && len(activityVideoIds) == 0 {
 		resp := new(models.MicroRoadShowListResp)
 		page := paging.GetPaging(currentIndex, pageSize, 0)
@@ -1224,6 +1231,9 @@ func (this *UserController) Mycollect() {
 			if count > 0 {
 				item.IsCollect = true
 			}
+			if v,ok := collectVoiceMap[item.Id]; ok{
+				item.CollectTime = v
+			}
 		} else if item.Type == 2 {
 			//活动视频
 			count, err := models.GetActivityVideoCollectCount(user.UserId, item.Id)
@@ -1235,6 +1245,9 @@ func (this *UserController) Mycollect() {
 			if count > 0 {
 				item.IsCollect = true
 			}
+			if v,ok := collectActivityVideoMap[item.Id]; ok{
+				item.CollectTime = v
+			}
 		} else if item.Type == 3 {
 			//微路演视频
 			count, err := models.GetVideoCollectCount(user.UserId, item.Id)
@@ -1246,6 +1259,9 @@ func (this *UserController) Mycollect() {
 			if count > 0 {
 				item.IsCollect = true
 			}
+			if v,ok := collectVideoMap[item.Id]; ok{
+				item.CollectTime = v
+			}
 		}
 	}
 	// 用户权限
@@ -1313,9 +1329,14 @@ func (this *UserController) Mycollect() {
 		}
 	}
 
+	var sortList models.MicroList
+
+	sortList = list
+	sort.Sort(sortList)
+
 	resp := new(models.MicroRoadShowListResp)
 	page := paging.GetPaging(currentIndex, pageSize, total)
-	resp.List = list
+	resp.List = sortList
 	resp.Paging = page
 
 	br.Ret = 200

+ 26 - 107
models/micro_roadshow.go

@@ -15,21 +15,22 @@ type MicroRoadShowListResp struct {
 
 // MicroRoadShowPageList 微路演列表
 type MicroRoadShowPageList struct {
-	Id                     int    `description:"音视频ID"`
-	Title                  string `description:"标题"`
-	ResourceUrl            string `description:"链接"`
-	Type                   int    `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
-	PublishTime            string `description:"发布时间"`
-	BackgroundImg          string `description:"背景图"`
-	ShareImg               string `description:"分享封面图"`
-	ChartPermissionId      int    `description:"行业ID"`
-	ChartPermissionName    string `description:"行业名称"`
-	IndustryName           string `description:"产业名称"`
-	PlaySeconds            string `description:"音视频时长"`
-	ActivityId             int    `description:"活动ID"`
-	IsCollect              bool   `description:"是否收藏"`
-	IndustrialManagementId int    `description:"产业ID"`
-	CreateTime             string `description:"视频创建时间"`
+	Id                     int       `description:"音视频ID"`
+	Title                  string    `description:"标题"`
+	ResourceUrl            string    `description:"链接"`
+	Type                   int       `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
+	PublishTime            string    `description:"发布时间"`
+	BackgroundImg          string    `description:"背景图"`
+	ShareImg               string    `description:"分享封面图"`
+	ChartPermissionId      int       `description:"行业ID"`
+	ChartPermissionName    string    `description:"行业名称"`
+	IndustryName           string    `description:"产业名称"`
+	PlaySeconds            string    `description:"音视频时长"`
+	ActivityId             int       `description:"活动ID"`
+	IsCollect              bool      `description:"是否收藏"`
+	IndustrialManagementId int       `description:"产业ID"`
+	CreateTime             string    `description:"视频创建时间"`
+	CollectTime            time.Time `description:"收藏时间"`
 	AuthInfo               *UserPermissionAuthInfo
 }
 
@@ -291,98 +292,16 @@ func GetMicroRoadShowVideoPageListV8(startSize, pageSize int, condition string,
 	return
 }
 
-// GetMicroRoadShowVideoPageList 获取微路演视频列表-分页 收藏用-更改排序字段
-func GetMicroRoadShowVideoPageListV9(startSize, pageSize int, condition string, pars []interface{}, conditionAct string, parsAct []interface{}, conditionAudio string, parsAudio []interface{}, audioId, videoId, activityVideoId, filter int) (total int, list []*MicroRoadShowPageList, err error) {
-	o := orm.NewOrm()
-	var sql string
-	//if audioId+activityVideoId == 0 && filter != 2 {
-	sql += `SELECT
-			video_id AS id,
-			video_name AS title,
-			video_url AS resource_url,
-			3 AS type,
-			publish_date AS publish_time,
-			chart_permission_id,
-			chart_permission_name,
-			video_duration AS play_seconds,
-			img_url AS background_img,            
-			industry_name,
+type MicroList []*MicroRoadShowPageList
 
-			share_img_url AS share_img,
-			industry_id AS industrial_management_id,
-			"" as  activity_id, 
-			create_time
-		FROM
-			cygx_micro_roadshow_video 
-		WHERE
-			publish_status = 1 `
-	if condition != `` {
-		sql += condition
-	}
-	//}
-	//if audioId+videoId+activityVideoId == 0 && filter != 2 {
-	sql += `  UNION ALL `
-	//}
+func (m MicroList) Len() int {
+	return len(m)
+}
 
-	//if audioId+videoId == 0 && filter != 2 {
-	sql += `
-		SELECT
-			video_id AS id,
-			video_name AS title,
-			video_url AS resource_url,
-			2 AS type,
-		art.activity_time as publish_time,
-			art.chart_permission_id,
-			art.chart_permission_name,
-			"" AS play_seconds,
-			"" AS background_img,
-			"" AS industry_name,
-			"" AS share_img,
-			0 AS industrial_management_id,
-			v.activity_id,
-			v.create_time 
-		FROM
-			cygx_activity_video as v
-			INNER JOIN cygx_activity as art on art.activity_id = v.activity_id WHERE 1= 1  `
-	if conditionAct != `` {
-		sql += conditionAct
-	}
-	//}
-	//if audioId+videoId+activityVideoId == 0 && filter == 0 {
-	sql += `  UNION ALL `
-	//}
+func (m MicroList) Less(i, j int) bool {
+	return m[i].CollectTime.After(m[j].CollectTime)
+}
 
-	//if videoId+activityVideoId == 0 && filter != 1 {
-	sql += `
-			SELECT
-			a.activity_voice_id AS id,
-			a.voice_name AS title,
-			a.voice_url AS resource_url,
-			1 AS type,
-			b.activity_time AS publish_time,
-			b.chart_permission_id,
-			b.chart_permission_name,
-			a.voice_play_seconds AS play_seconds,
-			a.img_url AS background_img,
-			"" AS industry_name,
-			"" AS share_img,
-			0 AS industrial_management_id,
-			a.activity_id,
-			a.create_time
-		FROM
-			cygx_activity_voice AS a
-			JOIN cygx_activity AS b ON a.activity_id = b.activity_id  WHERE 1= 1  `
-	if conditionAudio != `` {
-		sql += conditionAudio
-	}
-	//}
-	sql += ` ORDER BY create_time DESC`
-	totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
-	err = o.Raw(totalSql, pars, parsAct, parsAudio).QueryRow(&total)
-	if err != nil {
-		return
-	}
-	sql += ` LIMIT ?,?`
-	_, err = o.Raw(sql, pars, parsAct, parsAudio, startSize, pageSize).QueryRows(&list)
-	return
-}
+func (m MicroList) Swap(i, j int) {
+	m[i], m[j] = m[j], m[i]
+}

+ 1 - 1
services/user.go

@@ -391,7 +391,7 @@ func GetMicroRoadShowMycollect(pageSize, currentIndex int, audioIds, videoIds, a
 	}
 	videoCond += ` AND publish_status = 1`
 
-	total, videoList, e = models.GetMicroRoadShowVideoPageListV9(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars, 0, 0, 0, 0)
+	total, videoList, e = models.GetMicroRoadShowVideoPageListV8(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars, 0, 0, 0, 0)
 	if e != nil {
 		err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
 		return