Browse Source

Merge branch 'cygx/cygx_12.7' of http://8.136.199.33:3000/hongze/hz_crm_api

xingzai 1 year ago
parent
commit
ebe66140e4

+ 11 - 2
controllers/cygx/askserie_video.go

@@ -47,6 +47,7 @@ func (this *AskserieVideoController) PreserveAndPublish() {
 		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
+	req.VideoName = utils.RemoveFileSuffixName(req.VideoName) //去掉后缀名称
 	askserieVideoId := req.AskserieVideoId
 	videoName := req.VideoName
 	videoUrl := req.VideoUrl
@@ -78,13 +79,15 @@ func (this *AskserieVideoController) PreserveAndPublish() {
 	item.ChartPermissionName = chartPermissionName
 	item.PublishStatus = 1
 	item.BackgroundImg = backgroundImg
-	item.ShareImg = shareImg
+
 	item.AdminId = sysUser.AdminId
 	item.ModifyDate = time.Now()
 	item.PublishDate = time.Now()
 	item.CreateTime = time.Now()
 
 	if askserieVideoId == 0 {
+		shareImg, _ = cygxService.MakeCygxMp3HtmlImg(videoDuration) //生成分享图片
+		item.ShareImg = shareImg
 		//新增
 		newId, err := cygx.AddCygxAskserieVideo(item, industrialManagementIds)
 		if err != nil {
@@ -95,12 +98,18 @@ func (this *AskserieVideoController) PreserveAndPublish() {
 		askserieVideoId = int(newId)
 	} else {
 		//更新
-		_, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
+		detail, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
 		if err != nil {
 			br.Msg = "详情不存在"
 			br.ErrMsg = "获取失败,Err:" + err.Error()
 			return
 		}
+		//如果时长有变更就更新分享图片
+		if detail.VideoDuration != videoDuration {
+			shareImg, _ = cygxService.MakeCygxMp3HtmlImg(videoDuration) //生成分享图片
+			item.ShareImg = shareImg
+		}
+
 		err = cygx.UpdateCygxAskserieVideo(item, industrialManagementIds)
 		if err != nil {
 			br.Msg = "保存失败"

+ 3 - 1
controllers/cygx/micro_roadshow.go

@@ -254,7 +254,9 @@ func (this *MicroRoadshowController) Add() {
 			return
 		}
 	}
-
+	shareImg, _ := cygxService.MakeCygxMp4HtmlImg(req.VideoDuration) //生成分享图片
+	req.ShareImgUrl = shareImg
+	nameItem.IndustryName = utils.RemoveFileSuffixName(nameItem.IndustryName) //去掉后缀名称
 	if req.VideoId > 0 {
 		//更新
 		item := cygx.CygxMicroRoadshowVideo{

+ 11 - 0
models/cygx/activity_video.go

@@ -172,6 +172,17 @@ func GetActivityVideoList(condition string, pars []interface{}) (items []*CygxAc
 	return
 }
 
+// 列表
+func GetCygxActivityVideoList(condition string, pars []interface{}) (items []*CygxActivityVideo, err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	sql := ` SELECT  * FROM  cygx_activity_video  WHERE  1=1  `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
 // MicroRoadShowDefaultImgList 微路演行业默认背景图列表
 type MicroRoadShowDefaultImgList struct {
 	Audio []*MicroRoadShowDefaultImg `description:"音频"`

+ 16 - 0
models/cygx/askserie_video.go

@@ -205,3 +205,19 @@ func EditCygxAskserieVideoStatus(status, askserieVideoId int) (err error) {
 	_, err = o.Raw(sql, status, askserieVideoId).Exec()
 	return
 }
+
+// 修改分享图片
+func EditCygxAskserieVideoShareImg(shareImg string, askserieVideoId int) (err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	sql := `UPDATE cygx_askserie_video SET share_img=?   WHERE askserie_video_id=? `
+	_, err = o.Raw(sql, shareImg, askserieVideoId).Exec()
+	return
+}
+
+// 修改文件名称
+func EditCygxAskserieVideoVideoName(videoName string, askserieVideoId int) (err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	sql := `UPDATE cygx_askserie_video SET video_name=?   WHERE askserie_video_id=? `
+	_, err = o.Raw(sql, videoName, askserieVideoId).Exec()
+	return
+}

+ 26 - 0
models/cygx/micro_roadshow.go

@@ -68,6 +68,17 @@ func GetMicroRoadshowVideoList(condition, sortStr string, pars []interface{}, st
 	return
 }
 
+func GetCygxMicroRoadshowVideoList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxMicroRoadshowVideo, err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	sql := ` SELECT * FROM cygx_micro_roadshow_video as v  WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` LIMIT ?,? `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
 func GetMicroRoadshowVideoListCount(condition string, pars []interface{}) (count int, err error) {
 	o := orm.NewOrmUsingDB("hz_cygx")
 	sql := `SELECT COUNT(1) AS count FROM cygx_micro_roadshow_video WHERE 1=1 `
@@ -131,6 +142,21 @@ func EditVideo(item *CygxMicroRoadshowVideo) (err error) {
 	return
 }
 
+// 修改
+func UpdateCygxMicroRoadshowVideo(item *CygxMicroRoadshowVideo) (err error) {
+	to := orm.NewOrmUsingDB("hz_cygx")
+	updateParams := make(map[string]interface{})
+	updateParams["ShareImgUrl"] = item.ShareImgUrl
+	ptrStructOrTableName := "cygx_micro_roadshow_video"
+	whereParam := map[string]interface{}{"video_id": item.VideoId}
+	qs := to.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range whereParam {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err = qs.Update(updateParams)
+	return
+}
+
 func PublishVideoCancel(videoId, publishOrCancle int) (err error) {
 
 	if publishOrCancle == 0 {

+ 9 - 2
services/cygx/activity_ocr.go

@@ -175,7 +175,6 @@ func UpdateActivityVideoAndVoice(activityInfo *cygx.ActivityDetail, itemVoice *c
 			err = errors.New("GetCygxActivityVoiceCount" + e.Error())
 			return
 		}
-
 		activityId := itemVoice.ActivityId
 		//获取活动详情
 		activityInfo, e := cygx.GetAddActivityInfoById(activityId)
@@ -190,6 +189,10 @@ func UpdateActivityVideoAndVoice(activityInfo *cygx.ActivityDetail, itemVoice *c
 			itemVoice.FileType = 2
 		}
 
+		shareImg, _ := MakeCygxMp3HtmlImg(itemVoice.VoicePlaySeconds) //生成分享图片
+		itemVoice.ShareImg = shareImg
+		itemVoice.VoiceName = utils.RemoveFileSuffixName(itemVoice.VoiceName) //去掉后缀名称
+
 		//如果等于0就新增,反之就修改
 		if total == 0 {
 			newId, e := cygx.AddCygxActivityVoice(itemVoice)
@@ -229,7 +232,6 @@ func UpdateActivityVideoAndVoice(activityInfo *cygx.ActivityDetail, itemVoice *c
 				err = errors.New("DeleteCygxActivityVoice" + e.Error())
 				return
 			}
-
 			go UpdateActivityVoiceResourceData(voiceDetail.ActivityVoiceId) //写入首页最新  cygx_resource_data 表
 		}
 	}
@@ -256,6 +258,11 @@ func UpdateActivityVideoAndVoice(activityInfo *cygx.ActivityDetail, itemVoice *c
 		} else {
 			itemVideo.FileType = 2
 		}
+
+		shareImg, _ := MakeCygxMp4HtmlImg(itemVideo.VideoDuration) //生成分享图片
+		itemVideo.ShareImg = shareImg
+		itemVideo.VideoName = utils.RemoveFileSuffixName(itemVideo.VideoName) //去掉后缀名称
+
 		//视频文件更换阿里云oss地址 避免卡顿
 		var newOssUrl string
 		newOssUrl = strings.Replace(itemVideo.VideoUrl, "https://hzstatic.hzinsights.com", "https://hzchart.oss-accelerate.aliyuncs.com", -1)

+ 95 - 0
services/cygx/activity_poster.go

@@ -21,6 +21,8 @@ import (
 var (
 	ServerUrl                = "http://127.0.0.1:5008/"
 	Cygx_activity_sigin_html = "cygx_activity_sigin_html"
+	Cygx_mp3_html            = "cygx_mp3_html"
+	Cygx_mp4_html            = "cygx_mp4_html"
 )
 
 type Html2ImgResp struct {
@@ -233,3 +235,96 @@ func MakeActivitySigninImg(activityId int) (imgUrl string, err error) {
 	err = cygx.AddCygxActivityPoster(item)
 	return
 }
+
+// 生成音视频分享封面图
+func MakeCygxMp3HtmlImg(videoDuration string) (imgUrl string, err error) {
+	var msg string
+	defer func() {
+		if err != nil || msg != "" {
+			fmt.Println(err)
+			go alarm_msg.SendAlarmMsg("生成音视频分享封面图,失败 MakeCygxMp3HtmlImg:"+err.Error()+";msg:"+msg, 3)
+		}
+	}()
+	detailConfig, e := cygx.GetCygxConfigDetailByCode(Cygx_mp3_html)
+	if e != nil {
+		err = errors.New("GetCygxConfigDetailByCode 获取配置生成音视频分享封面图格式信息失败, Err: " + e.Error())
+		return
+	}
+	// 处理时长带有小数点的字符串
+	slice := strings.Split(videoDuration, ".")
+	for k, v := range slice {
+		if k != 0 {
+			continue
+		}
+		videoDuration = v
+	}
+	//先转换时长展示样式再替换
+	secondNum, _ := strconv.Atoi(videoDuration)
+	videoDuration = utils.HideSecondsToMs(secondNum)
+
+	configValue := detailConfig.ConfigValue
+	configValue = strings.Replace(configValue, "{{TIME}}", videoDuration, -1)
+	htm2ImgReq := make(map[string]interface{})
+	htm2ImgReq["html_content"] = configValue
+	htm2ImgReq["width"] = 1364
+	htm2ImgReq["height"] = 2060
+	res, err := postHtml2Img(htm2ImgReq)
+	if err != nil || res == nil {
+		msg = "html转图片请求失败"
+		return
+	}
+	if res.Code != 200 {
+		msg = "html转图片请求失败"
+		err = errors.New("html转图片失败: " + res.Msg)
+		return
+	}
+	imgUrl = res.Data
+	return
+}
+
+// 生成音视频分享封面图
+func MakeCygxMp4HtmlImg(videoDuration string) (imgUrl string, err error) {
+	var msg string
+	defer func() {
+		if err != nil || msg != "" {
+			fmt.Println(err)
+			go alarm_msg.SendAlarmMsg("生成音视频分享封面图,失败 MakeCygxMp4HtmlImg:"+err.Error()+";msg:"+msg, 3)
+		}
+	}()
+	detailConfig, e := cygx.GetCygxConfigDetailByCode(Cygx_mp4_html)
+	if e != nil {
+		err = errors.New("GetCygxConfigDetailByCode 获取配置生成音视频分享封面图格式信息失败, Err: " + e.Error())
+		return
+	}
+
+	// 处理时长带有小数点的字符串
+	slice := strings.Split(videoDuration, ".")
+	for k, v := range slice {
+		if k != 0 {
+			continue
+		}
+		videoDuration = v
+	}
+	//先转换时长展示样式再替换
+	secondNum, _ := strconv.Atoi(videoDuration)
+	videoDuration = utils.HideSecondsToMs(secondNum)
+
+	configValue := detailConfig.ConfigValue
+	configValue = strings.Replace(configValue, "{{TIME}}", videoDuration, -1)
+	htm2ImgReq := make(map[string]interface{})
+	htm2ImgReq["html_content"] = configValue
+	htm2ImgReq["width"] = 1364
+	htm2ImgReq["height"] = 2060
+	res, err := postHtml2Img(htm2ImgReq)
+	if err != nil || res == nil {
+		msg = "html转图片请求失败"
+		return
+	}
+	if res.Code != 200 {
+		msg = "html转图片请求失败"
+		err = errors.New("html转图片失败: " + res.Msg)
+		return
+	}
+	imgUrl = res.Data
+	return
+}

+ 148 - 0
services/cygx/askserie_video.go

@@ -135,3 +135,151 @@ func init12() {
 		}
 	}
 }
+
+// 修改分享图片脚本
+func initpy() {
+
+	//python3 main.py
+	var condition string
+	var pars []interface{}
+	listVoice, err := cygx.GetActivityVoiceList(condition, pars)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		fmt.Println(err)
+		return
+	}
+
+	for _, v := range listVoice {
+		shareImg, _ := MakeCygxMp3HtmlImg(v.VoicePlaySeconds) //生成分享图片
+		v.ShareImg = shareImg
+		err = cygx.UpdateCygxActivityVoice(v)
+		if err != nil {
+			err = errors.New("UpdateCygxActivityVoice" + err.Error())
+			return
+		}
+		fmt.Println(err)
+	}
+
+	listVideo, err := cygx.GetCygxActivityVideoList(condition, pars)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		fmt.Println(err)
+		return
+	}
+
+	for _, v := range listVideo {
+		shareImg, _ := MakeCygxMp4HtmlImg(v.VideoDuration) //生成分享图片
+		v.ShareImg = shareImg
+		err = cygx.UpdateCygxActivityVideo(v)
+		if err != nil {
+			err = errors.New("UpdateCygxActivityVideo" + err.Error())
+			return
+		}
+		fmt.Println(err)
+	}
+
+	listVideoRoadshow, err := cygx.GetCygxMicroRoadshowVideoList(condition, pars, 0, 1000)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		fmt.Println(err)
+		return
+	}
+
+	for _, v := range listVideoRoadshow {
+		shareImg, _ := MakeCygxMp4HtmlImg(v.VideoDuration) //生成分享图片
+		v.ShareImgUrl = shareImg
+		err = cygx.UpdateCygxMicroRoadshowVideo(v)
+		if err != nil {
+			err = errors.New("UpdateCygxMicroRoadshowVideo" + err.Error())
+			return
+		}
+		fmt.Println(err)
+	}
+
+	listAskserVoice, err := cygx.GetCygxAskserieVideoList(condition, pars, 0, 1000)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		fmt.Println(err)
+		return
+	}
+
+	for _, v := range listAskserVoice {
+		shareImg, _ := MakeCygxMp3HtmlImg(v.VideoDuration) //生成分享图片
+		v.ShareImg = shareImg
+		err = cygx.EditCygxAskserieVideoShareImg(shareImg, v.AskserieVideoId)
+		if err != nil {
+			err = errors.New("EditCygxAskserieVideoShareImg" + err.Error())
+			return
+		}
+		fmt.Println(err)
+	}
+
+	return
+}
+
+// 去掉后缀名脚本
+func initFileName() {
+	var condition string
+	var pars []interface{}
+	listVoice, err := cygx.GetActivityVoiceList(condition, pars)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		fmt.Println(err)
+		return
+	}
+
+	for _, v := range listVoice {
+		v.VoiceName = utils.RemoveFileSuffixName(v.VoiceName) //去掉后缀名称
+		err = cygx.UpdateCygxActivityVoice(v)
+		if err != nil {
+			err = errors.New("UpdateCygxActivityVoice" + err.Error())
+			return
+		}
+		fmt.Println(err)
+	}
+
+	listVideo, err := cygx.GetCygxActivityVideoList(condition, pars)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		fmt.Println(err)
+		return
+	}
+
+	for _, v := range listVideo {
+		v.VideoName = utils.RemoveFileSuffixName(v.VideoName) //去掉后缀名称
+		err = cygx.UpdateCygxActivityVideo(v)
+		if err != nil {
+			err = errors.New("UpdateCygxActivityVideo" + err.Error())
+			return
+		}
+		fmt.Println(err)
+	}
+
+	listVideoRoadshow, err := cygx.GetCygxMicroRoadshowVideoList(condition, pars, 0, 1000)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		fmt.Println(err)
+		return
+	}
+
+	for _, v := range listVideoRoadshow {
+		v.VideoName = utils.RemoveFileSuffixName(v.VideoName) //去掉后缀名称
+		err = cygx.UpdateCygxMicroRoadshowVideo(v)
+		if err != nil {
+			err = errors.New("UpdateCygxMicroRoadshowVideo" + err.Error())
+			return
+		}
+		fmt.Println(err)
+	}
+
+	listAskserVoice, err := cygx.GetCygxAskserieVideoList(condition, pars, 0, 1000)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		fmt.Println(err)
+		return
+	}
+
+	for _, v := range listAskserVoice {
+		v.VideoName = utils.RemoveFileSuffixName(v.VideoName) //去掉后缀名称
+		err = cygx.EditCygxAskserieVideoVideoName(v.VideoName, v.AskserieVideoId)
+		if err != nil {
+			err = errors.New("EditCygxAskserieVideoShareImg" + err.Error())
+			return
+		}
+		fmt.Println(err)
+	}
+
+	return
+}

+ 41 - 1
utils/common.go

@@ -1095,6 +1095,30 @@ func GetAttendanceDetailSeconds(secondNum int) string {
 	return timeStr
 }
 
+// 音视频时长秒转换成 分秒字符串样式
+func HideSecondsToMs(secondNum int) string {
+	var formatString string
+	m := secondNum / 60
+	s := secondNum % 60
+
+	if m == 0 {
+		formatString = fmt.Sprint("00:")
+	} else if m > 0 && m < 10 {
+		formatString = fmt.Sprint("0", m, ":")
+	} else {
+		formatString = fmt.Sprint(m, ":")
+	}
+
+	if s == 0 {
+		formatString += fmt.Sprint("00")
+	} else if s > 0 && s < 10 {
+		formatString += fmt.Sprint("0", s)
+	} else {
+		formatString += fmt.Sprint(s)
+	}
+	return formatString
+}
+
 // SubStr 截取字符串(中文)
 func SubStr(str string, subLen int) string {
 	strRune := []rune(str)
@@ -2110,4 +2134,20 @@ func ArticleHasImgUrl(body string) (hasImg bool, err error) {
 		hasImg = true
 	})
 	return
-}
+}
+
+// 移除文件后缀名称
+func RemoveFileSuffixName(fileName string) (removedName string) {
+	if strings.Contains(fileName, ".") {
+		slice := strings.Split(fileName, ".")
+		var suffixName string
+		for _, v := range slice {
+			suffixName = v
+		}
+		suffixName = "." + suffixName
+		removedName = strings.TrimRight(fileName, suffixName)
+	} else {
+		removedName = fileName
+	}
+	return
+}