|
@@ -7,9 +7,7 @@ import (
|
|
"eta/eta_mobile/utils"
|
|
"eta/eta_mobile/utils"
|
|
"fmt"
|
|
"fmt"
|
|
"github.com/kgiannakakis/mp3duration/src/mp3duration"
|
|
"github.com/kgiannakakis/mp3duration/src/mp3duration"
|
|
- "github.com/rdlucklib/rdluck_tools/file"
|
|
|
|
"github.com/rdlucklib/rdluck_tools/http"
|
|
"github.com/rdlucklib/rdluck_tools/http"
|
|
- "io/ioutil"
|
|
|
|
"os"
|
|
"os"
|
|
"path"
|
|
"path"
|
|
"strconv"
|
|
"strconv"
|
|
@@ -43,11 +41,11 @@ func (this *VoiceController) Upload() {
|
|
}
|
|
}
|
|
reportId, err := this.GetInt("ReportId")
|
|
reportId, err := this.GetInt("ReportId")
|
|
if err != nil {
|
|
if err != nil {
|
|
- br.Msg = "获取资源信息失败"
|
|
|
|
- br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
|
|
|
|
|
|
+ br.Msg = "报告id异常"
|
|
|
|
+ br.ErrMsg = "报告id异常,Err:" + err.Error()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- report, err := models.GetReportItemById(reportId)
|
|
|
|
|
|
+ reportInfo, err := models.GetReportByReportId(reportId)
|
|
if err != nil {
|
|
if err != nil {
|
|
br.Msg = "获取报告信息失败"
|
|
br.Msg = "获取报告信息失败"
|
|
br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
|
|
br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
|
|
@@ -128,20 +126,39 @@ func (this *VoiceController) Upload() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- createTime := report.CreateTime.Format("0102")
|
|
|
|
- videoName := report.Title + "(" + createTime + ")"
|
|
|
|
|
|
|
|
- fileBody, err := ioutil.ReadFile(fpath)
|
|
|
|
|
|
+ fileBody, err := os.ReadFile(fpath)
|
|
videoSize := len(fileBody)
|
|
videoSize := len(fileBody)
|
|
sizeFloat := (float64(videoSize) / float64(1024)) / float64(1024)
|
|
sizeFloat := (float64(videoSize) / float64(1024)) / float64(1024)
|
|
sizeStr := utils.SubFloatToFloatStr(sizeFloat, 2)
|
|
sizeStr := utils.SubFloatToFloatStr(sizeFloat, 2)
|
|
|
|
|
|
- err = models.ModifyReportVideo(reportId, resourceUrl, videoName, sizeStr, playSeconds)
|
|
|
|
- if err != nil {
|
|
|
|
- br.Msg = "上传失败"
|
|
|
|
- br.ErrMsg = "上传失败,Err:" + err.Error()
|
|
|
|
- return
|
|
|
|
|
|
+ // 修改报告的音频信息
|
|
|
|
+ {
|
|
|
|
+ reportCreateTime, err := time.Parse(utils.FormatDateTime, reportInfo.CreateTime)
|
|
|
|
+ if err != nil {
|
|
|
|
+ br.Msg = "上传失败"
|
|
|
|
+ br.ErrMsg = "上传失败,Err:" + err.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ createTimeStr := reportCreateTime.Format("0102")
|
|
|
|
+ videoName := reportInfo.Title + "(" + createTimeStr + ")"
|
|
|
|
+
|
|
|
|
+ reportInfo.VideoUrl = resourceUrl
|
|
|
|
+ reportInfo.VideoName = videoName
|
|
|
|
+ reportInfo.VideoPlaySeconds = fmt.Sprint(playSeconds)
|
|
|
|
+ reportInfo.VideoSize = sizeStr
|
|
|
|
+ reportInfo.LastModifyAdminId = this.SysUser.AdminId
|
|
|
|
+ reportInfo.LastModifyAdminName = this.SysUser.RealName
|
|
|
|
+ reportInfo.ModifyTime = time.Now()
|
|
|
|
+ err = reportInfo.UpdateReport([]string{"VideoUrl", "VideoName", "VideoPlaySeconds", "VideoSize", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
|
|
|
|
+ if err != nil {
|
|
|
|
+ br.Msg = "上传失败"
|
|
|
|
+ br.ErrMsg = "修改报告的音频信息失败,Err:" + err.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
resp := new(models.ResourceResp)
|
|
resp := new(models.ResourceResp)
|
|
resp.Id = newId
|
|
resp.Id = newId
|
|
resp.ResourceUrl = resourceUrl
|
|
resp.ResourceUrl = resourceUrl
|
|
@@ -175,36 +192,80 @@ func (this *VoiceCommonController) Download() {
|
|
br.ErrMsg = "获取,ReportId,Err:" + err.Error()
|
|
br.ErrMsg = "获取,ReportId,Err:" + err.Error()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- report, err := models.GetReportById(reportId)
|
|
|
|
|
|
+ reportInfo, err := models.GetReportById(reportId)
|
|
if err != nil {
|
|
if err != nil {
|
|
br.Msg = "获取信息失败"
|
|
br.Msg = "获取信息失败"
|
|
br.ErrMsg = "获取信息失败,Err:" + err.Error()
|
|
br.ErrMsg = "获取信息失败,Err:" + err.Error()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- savePath := time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandString(5) + ".mp3"
|
|
|
|
- fileBody, err := http.Get(report.VideoUrl)
|
|
|
|
- if err != nil {
|
|
|
|
- br.Msg = "获取信息失败"
|
|
|
|
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
|
|
|
|
- return
|
|
|
|
|
|
+
|
|
|
|
+ savePath, fileName, err, errMsg := services.DownloadVoice(reportInfo)
|
|
|
|
+ // 如果生成了文件,那么就在退出的时候,删除该文件
|
|
|
|
+ if savePath != `` {
|
|
|
|
+ defer func() {
|
|
|
|
+ os.Remove(savePath)
|
|
|
|
+ }()
|
|
}
|
|
}
|
|
- err = file.SaveFile(fileBody, savePath)
|
|
|
|
|
|
+
|
|
if err != nil {
|
|
if err != nil {
|
|
- br.Msg = "保存信息失败"
|
|
|
|
- br.ErrMsg = "保存信息失败,Err:" + err.Error()
|
|
|
|
|
|
+ br.Msg = errMsg
|
|
|
|
+ br.ErrMsg = "下载失败,Err:" + err.Error()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- fileName := report.VideoName + ".mp3"
|
|
|
|
- this.Ctx.Output.Download(savePath, fileName)
|
|
|
|
- defer func() {
|
|
|
|
- os.Remove(savePath)
|
|
|
|
- }()
|
|
|
|
|
|
+
|
|
|
|
+ if savePath != `` {
|
|
|
|
+ this.Ctx.Output.Download(savePath, fileName)
|
|
|
|
+ }
|
|
|
|
+
|
|
br.Ret = 200
|
|
br.Ret = 200
|
|
br.Msg = "下载成功"
|
|
br.Msg = "下载成功"
|
|
br.Success = true
|
|
br.Success = true
|
|
|
|
+
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+//func (this *VoiceCommonController) Download() {
|
|
|
|
+// br := new(models.BaseResponse).Init()
|
|
|
|
+// defer func() {
|
|
|
|
+// this.Data["json"] = br
|
|
|
|
+// this.ServeJSON()
|
|
|
|
+// }()
|
|
|
|
+// reportId, err := this.GetInt("ReportId")
|
|
|
|
+// if err != nil {
|
|
|
|
+// br.Msg = "参数错误"
|
|
|
|
+// br.ErrMsg = "获取,ReportId,Err:" + err.Error()
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+// report, err := models.GetReportById(reportId)
|
|
|
|
+// if err != nil {
|
|
|
|
+// br.Msg = "获取信息失败"
|
|
|
|
+// br.ErrMsg = "获取信息失败,Err:" + err.Error()
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+// savePath := time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandString(5) + ".mp3"
|
|
|
|
+// fileBody, err := http.Get(report.VideoUrl)
|
|
|
|
+// if err != nil {
|
|
|
|
+// br.Msg = "获取信息失败"
|
|
|
|
+// br.ErrMsg = "获取信息失败,Err:" + err.Error()
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+// err = file.SaveFile(fileBody, savePath)
|
|
|
|
+// if err != nil {
|
|
|
|
+// br.Msg = "保存信息失败"
|
|
|
|
+// br.ErrMsg = "保存信息失败,Err:" + err.Error()
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+// fileName := report.VideoName + ".mp3"
|
|
|
|
+// this.Ctx.Output.Download(savePath, fileName)
|
|
|
|
+// defer func() {
|
|
|
|
+// os.Remove(savePath)
|
|
|
|
+// }()
|
|
|
|
+// br.Ret = 200
|
|
|
|
+// br.Msg = "下载成功"
|
|
|
|
+// br.Success = true
|
|
|
|
+// return
|
|
|
|
+//}
|
|
|
|
+
|
|
// ReportChapterDownload
|
|
// ReportChapterDownload
|
|
// @Title 报告章节列表音频下载
|
|
// @Title 报告章节列表音频下载
|
|
// @Description 音频下载接口
|
|
// @Description 音频下载接口
|