|
@@ -7,7 +7,12 @@ import (
|
|
|
"eta/eta_api/models/smart_report"
|
|
|
"eta/eta_api/services"
|
|
|
"eta/eta_api/utils"
|
|
|
+ "fmt"
|
|
|
+ "github.com/kgiannakakis/mp3duration/src/mp3duration"
|
|
|
"html"
|
|
|
+ "io/ioutil"
|
|
|
+ "os"
|
|
|
+ "path"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
|
@@ -534,6 +539,13 @@ func (this *ReportController) GetReportChapterList() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ reportInfo, err := models.GetReportByReportId(reportId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取报告信息失败"
|
|
|
+ br.ErrMsg = "获取报告信息失败, Err: " + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
// 获取章节列表
|
|
|
chapterList, err := models.GetChapterListByReportId(reportId)
|
|
|
if err != nil {
|
|
@@ -687,6 +699,9 @@ func (this *ReportController) GetReportChapterList() {
|
|
|
tmpChapterItem.Editor = markStatus.Editor
|
|
|
}
|
|
|
|
|
|
+ // 报告章节的操作权限
|
|
|
+ tmpChapterItem.IsAuth = services.CheckChapterAuthByAdminIdList(sysUser.AdminId, reportInfo.AdminId, tmpChapterIdGrandList)
|
|
|
+
|
|
|
resp = append(resp, tmpChapterItem)
|
|
|
}
|
|
|
}
|
|
@@ -1018,3 +1033,211 @@ func (this *ReportController) GetSunCode() {
|
|
|
br.Success = true
|
|
|
br.Msg = "操作成功"
|
|
|
}
|
|
|
+
|
|
|
+// VoiceUpload
|
|
|
+// @Title 音频上传
|
|
|
+// @Description 音频上传接口
|
|
|
+// @Param file query file true "文件"
|
|
|
+// @Param ReportId query int true "报告ID"
|
|
|
+// @Param ReportChapterId query int true "报告章节ID"
|
|
|
+// @Success Ret=200 上传成功
|
|
|
+// @router /chapter/voice/upload [post]
|
|
|
+func (this *ReportController) VoiceUpload() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ f, h, err := this.GetFile("file")
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取资源信息失败"
|
|
|
+ br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 报告章节id
|
|
|
+ reportChapterId, err := this.GetInt("ReportChapterId", 0)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "报告章节ID异常"
|
|
|
+ br.ErrMsg = "报告章节ID异常,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 报告章节信息
|
|
|
+ reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取报告章节信息失败"
|
|
|
+ br.ErrMsg = "获取报告章节信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 报告信息
|
|
|
+ reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取报告信息失败"
|
|
|
+ br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果不是自己创建的报告,那么要去校验是否属于授权用户
|
|
|
+ if this.SysUser.AdminId == reportInfo.AdminId {
|
|
|
+ isAuth, err := services.CheckChapterAuthByReportChapterInfo(this.SysUser.AdminId, reportChapterInfo)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取报告权限失败"
|
|
|
+ br.ErrMsg = "获取报告权限失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !isAuth {
|
|
|
+ br.Msg = "无操作权限"
|
|
|
+ br.ErrMsg = "无操作权限"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ext := path.Ext(h.Filename)
|
|
|
+ dateDir := time.Now().Format("20060102")
|
|
|
+ uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
|
|
|
+ err = os.MkdirAll(uploadDir, utils.DIR_MOD)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "存储目录创建失败"
|
|
|
+ br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ randStr := utils.GetRandStringNoSpecialChar(28)
|
|
|
+ fileName := randStr + ext
|
|
|
+ fpath := uploadDir + "/" + fileName
|
|
|
+ defer f.Close() //关闭上传文件
|
|
|
+ err = this.SaveToFile("file", fpath)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "文件上传失败"
|
|
|
+ br.ErrMsg = "文件上传失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ resourceUrl := ``
|
|
|
+ //上传到阿里云 和 minio
|
|
|
+ //if utils.ObjectStorageClient == "minio" {
|
|
|
+ // resourceUrl, err = services.UploadAudioToMinIo(fileName, fpath)
|
|
|
+ // if err != nil {
|
|
|
+ // br.Msg = "文件上传失败"
|
|
|
+ // br.ErrMsg = "文件上传失败,Err:" + err.Error()
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ //} else {
|
|
|
+ // resourceUrl, err = services.UploadAudioAliyun(fileName, fpath)
|
|
|
+ // if err != nil {
|
|
|
+ // br.Msg = "文件上传失败"
|
|
|
+ // br.ErrMsg = "文件上传失败,Err:" + err.Error()
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ ossClient := services.NewOssClient()
|
|
|
+ if ossClient == nil {
|
|
|
+ br.Msg = "上传失败"
|
|
|
+ br.ErrMsg = "初始化OSS服务失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resourceUrl, err = ossClient.UploadFile(fileName, fpath, "")
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "文件上传失败"
|
|
|
+ br.ErrMsg = "文件上传失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ defer func() {
|
|
|
+ os.Remove(fpath)
|
|
|
+ }()
|
|
|
+ item := new(models.Resource)
|
|
|
+ item.ResourceUrl = resourceUrl
|
|
|
+ item.ResourceType = 2
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ newId, err := models.AddResource(item)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "资源上传失败"
|
|
|
+ br.ErrMsg = "资源上传失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var playSeconds float64
|
|
|
+ playSeconds, err = mp3duration.Calculate(fpath)
|
|
|
+ if playSeconds <= 0 {
|
|
|
+ playSeconds, err = utils.GetVideoPlaySeconds(fpath)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取音频时间失败"
|
|
|
+ br.ErrMsg = "获取音频时间失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fileBody, err := ioutil.ReadFile(fpath)
|
|
|
+ videoSize := len(fileBody)
|
|
|
+ sizeFloat := (float64(videoSize) / float64(1024)) / float64(1024)
|
|
|
+ sizeStr := utils.SubFloatToFloatStr(sizeFloat, 2)
|
|
|
+
|
|
|
+ if reportChapterId > 0 {
|
|
|
+ reportChapterCreateTime, err := time.Parse(utils.FormatDateTime, reportChapterInfo.CreateTime)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "上传失败"
|
|
|
+ br.ErrMsg = "上传失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ createTimeStr := reportChapterCreateTime.Format("0102")
|
|
|
+ videoName := reportChapterInfo.Title + "(" + createTimeStr + ")"
|
|
|
+
|
|
|
+ reportChapterInfo.VideoUrl = resourceUrl
|
|
|
+ reportChapterInfo.VideoName = videoName
|
|
|
+ reportChapterInfo.VideoPlaySeconds = fmt.Sprint(playSeconds)
|
|
|
+ reportChapterInfo.VideoSize = sizeStr
|
|
|
+ reportChapterInfo.LastModifyAdminId = this.SysUser.AdminId
|
|
|
+ reportChapterInfo.LastModifyAdminName = this.SysUser.RealName
|
|
|
+ reportChapterInfo.ModifyTime = time.Now()
|
|
|
+ err = reportChapterInfo.UpdateChapter([]string{"VideoUrl", "VideoName", "VideoPlaySeconds", "VideoSize", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "上传失败"
|
|
|
+ br.ErrMsg = "修改报告章节的音频信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ reportInfo.LastModifyAdminId = this.SysUser.AdminId
|
|
|
+ reportInfo.LastModifyAdminName = this.SysUser.RealName
|
|
|
+ reportInfo.ModifyTime = time.Now()
|
|
|
+ err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "上传失败"
|
|
|
+ br.ErrMsg = "修改报告最后更新人信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ 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.Id = newId
|
|
|
+ resp.ResourceUrl = resourceUrl
|
|
|
+ br.Msg = "上传成功"
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Data = resp
|
|
|
+ return
|
|
|
+}
|