|
@@ -63,7 +63,7 @@ func BroadcastList(c *gin.Context) {
|
|
|
|
|
|
isVoiceAdmin, _, err := services.GetVoiceAdminByUserInfo(userinfo)
|
|
|
if err != nil && err != utils.ErrNoRow {
|
|
|
- response.FailMsg("获取语音管理员信息失败"+err.Error(), "QuestionList ErrMsg:"+err.Error(), c)
|
|
|
+ response.FailMsg("获取语音管理员信息失败", "QuestionList ErrMsg:"+err.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
var resp voiceResp.BroadcastListResp
|
|
@@ -253,91 +253,22 @@ func DelBroadcast(c *gin.Context) {
|
|
|
// @failure 400 {string} string "新增失败"
|
|
|
// @Router /statistics/add [post]
|
|
|
func AddStatistics(c *gin.Context) {
|
|
|
- broadcastName := c.PostForm("broadcast_name")
|
|
|
- fmt.Println("broadcastName:",broadcastName)
|
|
|
- nsectionId := c.PostForm("section_id")
|
|
|
- sectionId, _ := strconv.Atoi(nsectionId)
|
|
|
- sectionName := c.PostForm("section_name")
|
|
|
- nvarietyId := c.PostForm("variety_id")
|
|
|
- varietyId, _ := strconv.Atoi(nvarietyId)
|
|
|
- varietyName := c.PostForm("variety_name")
|
|
|
- nauthorId := c.PostForm("author_id")
|
|
|
- authorId, _ := strconv.Atoi(nauthorId)
|
|
|
- author := c.PostForm("author")
|
|
|
- file, err := c.FormFile("file")
|
|
|
- if err != nil {
|
|
|
- response.FailMsg("获取资源失败", "获取资源失败, Err:"+err.Error(), c)
|
|
|
+ var req request.AddBroadcastStatisticsReq
|
|
|
+ if err := c.Bind(&req); err != nil {
|
|
|
+ response.Fail("参数有误", c)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- ext := path.Ext(file.Filename)
|
|
|
- if ext != ".mp3" {
|
|
|
- response.Fail("暂仅支持mp3格式", c)
|
|
|
- return
|
|
|
- }
|
|
|
- dateDir := time.Now().Format("20060102")
|
|
|
- localDir := global.CONFIG.Serve.StaticDir + "hongze/" + dateDir
|
|
|
- if err := os.MkdirAll(localDir, 0766); err != nil {
|
|
|
- response.FailMsg("存储目录创建失败", "QuestionUploadAudio 存储目录创建失败, Err:"+err.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- randStr := utils.GetRandStringNoSpecialChar(28)
|
|
|
- filtName := randStr + ext
|
|
|
- fpath := localDir + "/" + filtName
|
|
|
- defer func() {
|
|
|
- _ = os.Remove(fpath)
|
|
|
- }()
|
|
|
- // 生成文件至指定目录
|
|
|
- if err := c.SaveUploadedFile(file, fpath); err != nil {
|
|
|
- response.FailMsg("文件生成失败", "QuestionUploadAudio 文件生成失败, Err:"+err.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- // 获取音频文件时长
|
|
|
- fByte, err := ioutil.ReadFile(fpath)
|
|
|
- if err != nil {
|
|
|
- response.FailMsg("读取本地文件失败", "QuestionUploadAudio 读取本地文件失败", c)
|
|
|
- return
|
|
|
- }
|
|
|
- if len(fByte) <= 0 {
|
|
|
- response.FailMsg("文件大小有误", "QuestionUploadAudio 文件大小有误", c)
|
|
|
- return
|
|
|
- }
|
|
|
- seconds, err := services.GetMP3PlayDuration(fByte)
|
|
|
- if err != nil {
|
|
|
- response.FailMsg("读取文件时长失败", "QuestionUploadAudio 读取文件时长失败", c)
|
|
|
- return
|
|
|
- }
|
|
|
- // 音频大小MB
|
|
|
- fi, err := os.Stat(fpath)
|
|
|
- if err != nil {
|
|
|
- response.FailMsg("读取文件大小失败", "QuestionUploadAudio 读取文件大小失败", c)
|
|
|
- return
|
|
|
- }
|
|
|
- mb := utils.Bit2MB(fi.Size(), 2)
|
|
|
- // 上传文件至阿里云
|
|
|
- ossDir := "yb_wx/voice_broadcast/"
|
|
|
- resourceUrl, err := services.UploadAliyunToDir(filtName, fpath, ossDir)
|
|
|
- if err != nil {
|
|
|
- response.FailMsg("文件上传失败", "QuestionUploadAudio 文件上传失败, Err:"+err.Error(), c)
|
|
|
- return
|
|
|
+ if req.UserId <= 0{
|
|
|
+ response.Fail("参数有误", c)
|
|
|
}
|
|
|
|
|
|
- voiceBroadcast := voice_broadcast.VoiceBroadcast{
|
|
|
- BroadcastName: broadcastName,
|
|
|
- SectionId: sectionId,
|
|
|
- SectionName: sectionName,
|
|
|
- VarietyId: varietyId,
|
|
|
- VarietyName: varietyName,
|
|
|
- AuthorId: authorId,
|
|
|
- Author: author,
|
|
|
- VoiceUrl: resourceUrl,
|
|
|
- VoicePlaySeconds: fmt.Sprint(seconds),
|
|
|
- VoiceSize: fmt.Sprint(mb),
|
|
|
- CreateTime: time.Now().Format(utils.FormatDateTime),
|
|
|
- }
|
|
|
- err = voiceBroadcast.AddVoiceBroadcast()
|
|
|
- if err != nil {
|
|
|
- fmt.Println("AddUserViewHistory err", err.Error())
|
|
|
+ if req.BroadcastId <= 0{
|
|
|
+ response.Fail("参数有误", c)
|
|
|
}
|
|
|
- response.Ok("发布成功", c)
|
|
|
+ userinfo := user.GetInfoByClaims(c)
|
|
|
+
|
|
|
+ go services.AddBroadcastRecord(userinfo, req.Source, req.BroadcastId)
|
|
|
+
|
|
|
+ response.Ok("新增记录成功", c)
|
|
|
}
|