Explorar o código

fix:章节报告合并生成音频

Roc hai 7 meses
pai
achega
5b21eca111
Modificáronse 2 ficheiros con 45 adicións e 3 borrados
  1. 18 0
      models/report.go
  2. 27 3
      services/report.go

+ 18 - 0
models/report.go

@@ -28,6 +28,7 @@ type Report struct {
 	VideoUrl           string    `description:"音频文件URL"`
 	VideoName          string    `description:"音频文件名称"`
 	VideoPlaySeconds   string    `description:"音频播放时长"`
+	VideoSize          string    `description:"音频文件大小,单位M"`
 	ContentSub         string    `description:"内容前两个章节"`
 	HasChapter         int       `description:"是否有章节 0-否 1-是"`
 	ChapterType        string    `description:"章节类型 day-晨报 week-周报"`
@@ -139,6 +140,23 @@ func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, play
 	return
 }
 
+// ModifyReportVideoByNoVideo
+// @Description: 修改无音频的报告音频信息
+// @author: Roc
+// @datetime 2024-07-25 18:03:05
+// @param reportId int
+// @param videoUrl string
+// @param videoName string
+// @param videoSize string
+// @param playSeconds float64
+// @return err error
+func ModifyReportVideoByNoVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? AND video_url=""`
+	_, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
+	return
+}
+
 type ReportChapterTypePermission struct {
 	Id                    int       `orm:"column(id);pk" description:"主键ID"`
 	ReportChapterTypeId   int       `description:"报告章节类型ID"`

+ 27 - 3
services/report.go

@@ -248,7 +248,7 @@ func handleByPublishReport(item *models.Report) {
 
 	if item.HasChapter == 1 {
 		// 生产报告章节音频
-		_ = UpdateChaptersVideoByReportId(item.Id)
+		_ = UpdateChaptersVideoByReportId(item)
 	} else {
 		// 生成音频
 		if item.VideoUrl == "" {
@@ -468,9 +468,11 @@ func ClearReportSaveLog(cont context.Context) (err error) {
 // @Description: 更新报告章节音频
 // @author: Roc
 // @datetime 2024-06-28 13:52:56
-// @param reportId int
+// @param reportInfo *models.Report
 // @return err error
-func UpdateChaptersVideoByReportId(reportId int) (err error) {
+func UpdateChaptersVideoByReportId(reportInfo *models.Report) (err error) {
+	reportId := reportInfo.Id
+
 	defer func() {
 		if err != nil {
 			utils.FileLog.Error("UpdateChaptersVideo, reportId:%v, Err:%s", reportId, err.Error())
@@ -481,12 +483,18 @@ func UpdateChaptersVideoByReportId(reportId int) (err error) {
 	if err != nil {
 		return
 	}
+
+	reportContent := ""
+
 	// 生成video
 	nowTime := time.Now()
 	updateCols := make([]string, 0)
 	updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds")
 	for i := 0; i < len(chapterList); i++ {
 		item := chapterList[i]
+		reportContent += item.Title + `。`
+		reportContent += item.Content + `。`
+
 		// 忽略已有音频的章节
 		if item.VideoUrl != "" && item.VideoName != "" && item.VideoSize != "" && item.VideoPlaySeconds != "" {
 			continue
@@ -505,6 +513,22 @@ func UpdateChaptersVideoByReportId(reportId int) (err error) {
 		}
 	}
 
+	// 生成汇总音频
+	{
+		if reportInfo.VideoUrl != "" && reportInfo.VideoName != "" && reportInfo.VideoSize != "" && reportInfo.VideoPlaySeconds != "" {
+			return
+		}
+		videoUrl, videoName, videoSize, videoPlaySeconds, e := CreateReportVideo(reportInfo.Title, html.UnescapeString(reportContent), time.Now().Format(utils.FormatDateTime))
+		if e != nil {
+			err = e
+			return
+		}
+
+		// 修改报告的音频信息
+		err = models.ModifyReportVideoByNoVideo(reportInfo.Id, videoUrl, videoName, videoSize, videoPlaySeconds)
+
+	}
+
 	return
 }