Browse Source

no message

xingzai 2 years ago
parent
commit
8d5c534eef
5 changed files with 417 additions and 14 deletions
  1. 43 1
      controllers/micro_roadshow.go
  2. 157 0
      models/micro_roadshow.go
  3. 2 0
      services/elastic.go
  4. 29 4
      services/elasticsearch.go
  5. 186 9
      services/micro_roadshow.go

+ 43 - 1
controllers/micro_roadshow.go

@@ -61,13 +61,55 @@ func (this *MicroRoadShowController) List() {
 		currentIndex = 1
 	}
 
+	keyWordArr, err := services.GetIndustryMapNameSliceV3(keywords)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取分词失败,GetIndustryMapNameSliceV3 Err: " + err.Error()
+		return
+	}
+	keyWordArr = services.RemoveDuplicatesAndEmpty(keyWordArr)
+
+	//keyWordLen := len(keyWordArr)
+	var list []*models.MicroRoadShowPageList
+	var total int
+	var e error
 	// 微路演列表
-	list, total, e := services.GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activityVideoId, filter, keywords, audioIds, videoIds, activityVideoIds)
+	list, total, e = services.GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activityVideoId, filter, keywords, audioIds, videoIds, activityVideoIds)
 	if e != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
 		return
 	}
+	//var pageSizeIk int
+	//var currentIndexIk int
+	//pageSizeIk = pageSize - len(list)
+	//
+	//currentIndexIk = currentIndex - (total / pageSize) - 1
+	////获取总的数量
+	//totalIk, e := services.CountMicroRoadShowPageListIkWord(audioId, videoId, activityVideoId, filter, keyWordArr, audioIds, videoIds, activityVideoIds)
+	//if e != nil {
+	//	br.Msg = "获取失败"
+	//	br.ErrMsg = "获取微路演联想词列表失败, Err: " + e.Error()
+	//	return
+	//}
+	//
+	////startSize, pageSize,
+	//startSize := utils.StartIndex(currentIndex, pageSize)
+	//
+	//lisIk, e := services.GetMicroRoadShowPageListIkWord(pageSizeIk, currentIndexIk, audioId, videoId, activityVideoId, filter, keyWordArr, audioIds, videoIds, activityVideoIds)
+	//if e != nil {
+	//	br.Msg = "获取失败"
+	//	br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
+	//	return
+	//}
+	//
+	//total = totalIk
+	//if keyWordLen > 1 && pageSizeIk > 0 {
+	//	for _, item := range listIk {
+	//		list = append(list, item)
+	//	}
+	//}
+	//return
 	for _, item := range list {
 		if item.Type == 1 {
 			//音频

+ 157 - 0
models/micro_roadshow.go

@@ -120,6 +120,163 @@ func GetMicroRoadShowVideoPageListV8(startSize, pageSize int, condition string,
 	return
 }
 
+// CountMicroRoadShowVideoPageList 获取微路演视频数量
+func CountMicroRoadShowVideoPageList(condition string, pars []interface{}, conditionAct string, parsAct []interface{}, conditionAudio string, parsAudio []interface{}) (total int, err error) {
+	o := orm.NewOrm()
+	var sql string
+	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,
+			share_img_url AS share_img,
+			"" as  activity_id
+		FROM
+			cygx_micro_roadshow_video 
+		WHERE
+			publish_status = 1 `
+	if condition != `` {
+		sql += condition
+	}
+	sql += `  UNION ALL `
+	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,
+			v.activity_id
+		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
+	}
+	sql += `  UNION ALL `
+	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,
+			a.activity_id 
+		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 publish_time DESC`
+	totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
+	err = o.Raw(totalSql, pars, parsAct, parsAudio).QueryRow(&total)
+	return
+}
+
+// GetMicroRoadShowVideoPageList 获取微路演视频列表-分页
+func GetMicroRoadShowVideoPageListIkWord(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,
+			share_img_url AS share_img,
+			"" as  activity_id
+		FROM
+			cygx_micro_roadshow_video 
+		WHERE
+			publish_status = 1 `
+		if condition != `` {
+			sql += condition
+		}
+	}
+	if audioId+videoId+activityVideoId == 0 && filter != 2 {
+		sql += `  UNION ALL `
+	}
+
+	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,
+			v.activity_id
+		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 `
+	}
+
+	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,
+			a.activity_id 
+		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 publish_time DESC`
+	sql += ` LIMIT ?,?`
+	_, err = o.Raw(sql, pars, parsAct, parsAudio, startSize, pageSize).QueryRows(&list)
+	return
+}
+
 type AddVideoHistoryReq struct {
 	VideoId     int `description:"视频ID"`
 	PlaySeconds int `description:"播放时长"`

+ 2 - 0
services/elastic.go

@@ -896,11 +896,13 @@ func EsArticleSearch(keyWord string, startSize, pageSize int, orderColumn string
 	client := utils.Client
 	keyWordArr, err := GetIndustryMapNameSliceV3(keyWord)
 	keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
+	fmt.Println(keyWordArr)
 	keyWordLen := len(keyWordArr)
 	if keyWordLen <= 0 {
 		keyWordArr = append(keyWordArr, keyWord)
 		keyWordLen = len(keyWordArr)
 	}
+	fmt.Println(keyWordArr)
 	mustMap := make([]interface{}, 0)
 	shouldMap := make(map[string]interface{}, 0)
 	//shouldMapquery := make(map[string]interface{}, 0)

+ 29 - 4
services/elasticsearch.go

@@ -263,7 +263,7 @@ func SearchByKeyWordBack02(keyWord string) (result []*models.SearchItem, err err
 	return
 }
 
-func SearchByKeyWordBack(indexName,keyWord string,startSize, pageSize,userId int) (result []*models.SearchItem,total int, err error) {
+func SearchByKeyWordBack(indexName, keyWord string, startSize, pageSize, userId int) (result []*models.SearchItem, total int, err error) {
 	keyWordArr, err := GetIndustryMapNameSlice(keyWord)
 	if err != nil {
 		go utils.SendEmail(utils.APPNAME+" "+utils.RunMode+"异常提醒:", "GetIndustryMapNameSlice:"+err.Error(), utils.EmailSendToUsers)
@@ -292,18 +292,18 @@ func SearchByKeyWordBack(indexName,keyWord string,startSize, pageSize,userId int
 		highlight = highlight.PreTags("<font color='red'>").PostTags("</font>")
 		searchByMatch, err := client.Search(esIndex).Highlight(highlight).Size(pageSize).Query(boolquery).Do(context.Background())
 		if err != nil {
-			return result,0, err
+			return result, 0, err
 		}
 		if searchByMatch.Hits != nil {
 			for _, v := range searchByMatch.Hits.Hits {
 				articleJson, err := v.Source.MarshalJSON()
 				if err != nil {
-					return nil,0, err
+					return nil, 0, err
 				}
 				article := new(models.CygxArticle)
 				err = json.Unmarshal(articleJson, &article)
 				if err != nil {
-					return nil,0, err
+					return nil, 0, err
 				}
 				if _, ok := searchMap[article.ArticleId]; !ok {
 					searchItem := new(models.SearchItem)
@@ -397,6 +397,31 @@ func RemoveDuplicatesAndEmpty(a []string) (ret []string) {
 	return
 }
 
+//KeyWordArrSqlRegexp 预处理ik联想词的模糊查询语句
+func KeyWordArrSqlRegexp(a []string) (ret string) {
+	a_len := len(a)
+	for i := 0; i < a_len; i++ {
+		if i == 0 {
+			continue
+		}
+		ret += a[i] + "|"
+	}
+	ret = strings.TrimRight(ret, "|")
+	ret = "'" + ret + "'"
+	return
+}
+
+//KeyWordArrSqlRegexp 预处理ik联想词的模糊查询语句
+func KeyWordArrSqlRegexpAll(a []string) (ret string) {
+	a_len := len(a)
+	for i := 0; i < a_len; i++ {
+		ret += a[i] + "|"
+	}
+	ret = strings.TrimRight(ret, "|")
+	ret = "'" + ret + "'"
+	return
+}
+
 func init21123() {
 	fmt.Println("start")
 	client, err := elastic.NewClient(elastic.SetURL(ES_URL), elastic.SetBasicAuth(ES_USERNAME, ES_PASSWORD), elastic.SetSniff(false))

+ 186 - 9
services/micro_roadshow.go

@@ -3,7 +3,6 @@ package services
 import (
 	"encoding/json"
 	"errors"
-	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
 	"strings"
@@ -177,9 +176,7 @@ func GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activi
 	var audioCond string
 	var audioPars []interface{}
 	// 如果筛选条件为指定视频ID或只看视频则不做音频查询
-	fmt.Println("filter:", filter)
 	if videoId > 0 || activityVideoId > 0 || filter == 1 {
-		fmt.Println("11111")
 		audioCond = ""
 	} else {
 		// 活动已发布且已结束
@@ -212,7 +209,6 @@ func GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activi
 	var videoPars []interface{}
 	var videoParsAct []interface{}
 	if audioId > 0 || filter == 2 {
-		fmt.Println("22222")
 		videoCond = ""
 	} else {
 		if keywords != "" {
@@ -246,11 +242,6 @@ func GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activi
 		if activityVideoId > 0 {
 			videoCond += ` AND video_id = 0 `
 		}
-		//if videoId == 0 {
-		//	endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
-		//	videoCondAct += ` AND art.activity_time > ? `
-		//	videoParsAct = append(videoParsAct, endTime)
-		//}
 		if videoIds != "" {
 			sliceId := strings.Split(videoIds, ",")
 			var idSqlStr string
@@ -271,6 +262,192 @@ func GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activi
 	return
 }
 
+// GetMicroRoadShowPageListIkWord  添加IK分词联想词 获取微路演列表添加活动视频 更新与8.1版本
+func CountMicroRoadShowPageListIkWord(audioId, videoId, activityVideoId, filter int, keywordArr []string, audioIds, videoIds, activityVideoIds string) (total int, err error) {
+	var e error
+	var keywords string
+	if len(keywordArr) > 1 {
+		keywords = KeyWordArrSqlRegexpAll(keywordArr)
+	}
+	//音频的查询
+	var audioCond string
+	var audioPars []interface{}
+	// 如果筛选条件为指定视频ID或只看视频则不做音频查询
+	if videoId > 0 || activityVideoId > 0 || filter == 1 {
+		audioCond += ` AND a.activity_voice_id  = 0 `
+	} else {
+		// 活动已发布且已结束
+		audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
+		if keywords != "" {
+			audioCond += ` AND a.voice_name REGEXP ? OR b.label REGEXP ?`
+			audioPars = append(audioPars, keywords, keywords)
+		}
+		if audioId > 0 {
+			audioCond += ` AND a.activity_voice_id = ?`
+			audioPars = append(audioPars, audioId)
+		}
+		if audioIds != "" {
+			sliceId := strings.Split(audioIds, ",")
+			var idSqlStr string
+			for _, v := range sliceId {
+				idSqlStr += "'" + v + "',"
+			}
+			idSqlStr = strings.TrimRight(idSqlStr, ",")
+			audioCond += ` AND a.activity_voice_id IN (` + idSqlStr + `)`
+		}
+	}
+	//视频的处理
+	var videoCond string
+	var videoCondAct string
+	var videoPars []interface{}
+	var videoParsAct []interface{}
+	if audioId > 0 || filter == 2 {
+		videoCond = ""
+	} else {
+		if keywords != "" {
+			videoCond += ` AND video_name REGEXP ?`
+			videoPars = append(videoPars, keywords)
+			videoCondAct += ` AND video_name LIKE ?`
+			videoParsAct = append(videoParsAct, keywords)
+		}
+		if videoId > 0 {
+			videoCond += ` AND video_id = ?`
+			videoPars = append(videoPars, videoId)
+		}
+		if activityVideoId > 0 {
+			videoCondAct += ` AND video_id = ?`
+			videoParsAct = append(videoParsAct, activityVideoId)
+		}
+		if activityVideoIds != "" {
+			sliceId := strings.Split(activityVideoIds, ",")
+			var idSqlStr string
+			for _, v := range sliceId {
+				idSqlStr += "'" + v + "',"
+			}
+			idSqlStr = strings.TrimRight(idSqlStr, ",")
+			videoCondAct += ` AND v.video_id IN (` + idSqlStr + `)`
+		}
+
+		//如果传了路演的或者活动的视频ID只查询一个
+		if videoId > 0 {
+			videoCondAct += ` AND video_id = 0 `
+		}
+		if activityVideoId > 0 {
+			videoCond += ` AND video_id = 0 `
+		}
+
+		if videoIds != "" {
+			sliceId := strings.Split(videoIds, ",")
+			var idSqlStr string
+			for _, v := range sliceId {
+				idSqlStr += "'" + v + "',"
+			}
+			idSqlStr = strings.TrimRight(idSqlStr, ",")
+			videoCond += ` AND video_id IN (` + idSqlStr + `)`
+		}
+		videoCond += ` AND publish_status = 1`
+	}
+	total, e = models.CountMicroRoadShowVideoPageList(videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars)
+	if e != nil {
+		err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
+		return
+	}
+	return
+}
+
+// GetMicroRoadShowPageListIkWord  添加IK分词联想词 获取微路演列表添加活动视频 更新与8.1版本
+func GetMicroRoadShowPageListIkWord(pageSize, currentIndex, audioId, videoId, activityVideoId, filter int, keywordArr []string, audioIds, videoIds, activityVideoIds string) (total int, err error) {
+	var e error
+	var keywords string
+	if len(keywordArr) > 1 {
+		keywords = KeyWordArrSqlRegexp(keywordArr)
+	}
+	//音频的查询
+	var audioCond string
+	var audioPars []interface{}
+	// 如果筛选条件为指定视频ID或只看视频则不做音频查询
+	if videoId > 0 || activityVideoId > 0 || filter == 1 {
+		audioCond += ` AND a.activity_voice_id  = 0 `
+	} else {
+		// 活动已发布且已结束
+		audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
+		if keywords != "" {
+			audioCond += ` AND a.voice_name REGEXP ? OR b.label REGEXP ?`
+			audioPars = append(audioPars, keywords, keywords)
+		}
+		if audioId > 0 {
+			audioCond += ` AND a.activity_voice_id = ?`
+			audioPars = append(audioPars, audioId)
+		}
+		if audioIds != "" {
+			sliceId := strings.Split(audioIds, ",")
+			var idSqlStr string
+			for _, v := range sliceId {
+				idSqlStr += "'" + v + "',"
+			}
+			idSqlStr = strings.TrimRight(idSqlStr, ",")
+			audioCond += ` AND a.activity_voice_id IN (` + idSqlStr + `)`
+		}
+	}
+	//视频的处理
+	var videoCond string
+	var videoCondAct string
+	var videoPars []interface{}
+	var videoParsAct []interface{}
+	if audioId > 0 || filter == 2 {
+		videoCond = ""
+	} else {
+		if keywords != "" {
+			videoCond += ` AND video_name REGEXP ?`
+			videoPars = append(videoPars, keywords)
+			videoCondAct += ` AND video_name LIKE ?`
+			videoParsAct = append(videoParsAct, keywords)
+		}
+		if videoId > 0 {
+			videoCond += ` AND video_id = ?`
+			videoPars = append(videoPars, videoId)
+		}
+		if activityVideoId > 0 {
+			videoCondAct += ` AND video_id = ?`
+			videoParsAct = append(videoParsAct, activityVideoId)
+		}
+		if activityVideoIds != "" {
+			sliceId := strings.Split(activityVideoIds, ",")
+			var idSqlStr string
+			for _, v := range sliceId {
+				idSqlStr += "'" + v + "',"
+			}
+			idSqlStr = strings.TrimRight(idSqlStr, ",")
+			videoCondAct += ` AND v.video_id IN (` + idSqlStr + `)`
+		}
+
+		//如果传了路演的或者活动的视频ID只查询一个
+		if videoId > 0 {
+			videoCondAct += ` AND video_id = 0 `
+		}
+		if activityVideoId > 0 {
+			videoCond += ` AND video_id = 0 `
+		}
+
+		if videoIds != "" {
+			sliceId := strings.Split(videoIds, ",")
+			var idSqlStr string
+			for _, v := range sliceId {
+				idSqlStr += "'" + v + "',"
+			}
+			idSqlStr = strings.TrimRight(idSqlStr, ",")
+			videoCond += ` AND video_id IN (` + idSqlStr + `)`
+		}
+		videoCond += ` AND publish_status = 1`
+	}
+	total, e = models.CountMicroRoadShowVideoPageList(videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars)
+	if e != nil {
+		err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
+		return
+	}
+	return
+}
+
 // 我的收藏
 func GetMicroRoadShowMycollect(pageSize, currentIndex int, audioIds, videoIds, activityVideoIds string) (respList []*models.MicroRoadShowPageList, total int, err error) {
 	var e error