|
@@ -6,9 +6,10 @@ import (
|
|
"eta/eta_api/models"
|
|
"eta/eta_api/models"
|
|
"eta/eta_api/models/speech_recognition"
|
|
"eta/eta_api/models/speech_recognition"
|
|
"eta/eta_api/services"
|
|
"eta/eta_api/services"
|
|
|
|
+ "eta/eta_api/services/alarm_msg"
|
|
"eta/eta_api/utils"
|
|
"eta/eta_api/utils"
|
|
"fmt"
|
|
"fmt"
|
|
- "strconv"
|
|
|
|
|
|
+ "strings"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -27,61 +28,235 @@ type SpeechRecognitionCommonController struct {
|
|
// @Success 200 string "操作成功"
|
|
// @Success 200 string "操作成功"
|
|
// @router /rec_task/callback [post]
|
|
// @router /rec_task/callback [post]
|
|
func (this *SpeechRecognitionCommonController) RecTaskCallback() {
|
|
func (this *SpeechRecognitionCommonController) RecTaskCallback() {
|
|
- utils.FileLog.Info("RecTaskCallback, -1")
|
|
|
|
// 此接口返回指定响应体
|
|
// 此接口返回指定响应体
|
|
br := new(services.TencentRecTaskCallbackResp)
|
|
br := new(services.TencentRecTaskCallbackResp)
|
|
|
|
+ var errMsg string
|
|
defer func() {
|
|
defer func() {
|
|
|
|
+ if errMsg != "" {
|
|
|
|
+ br.Code = 403
|
|
|
|
+ br.Message = "回调失败"
|
|
|
|
+ go alarm_msg.SendAlarmMsg(fmt.Sprintf("语音识别回调失败, ErrMsg: %s", errMsg), 1)
|
|
|
|
+ } else {
|
|
|
|
+ br.Code = 0
|
|
|
|
+ br.Message = "success"
|
|
|
|
+ }
|
|
_ = this.JSON(br, false, false)
|
|
_ = this.JSON(br, false, false)
|
|
}()
|
|
}()
|
|
- var req services.TencentRecTaskCallback
|
|
|
|
-
|
|
|
|
- utils.FileLog.Info("RecTaskCallback, 0")
|
|
|
|
|
|
|
|
- code, _ := this.GetInt("code", 0)
|
|
|
|
- req.Code = code
|
|
|
|
|
|
+ code, _ := this.GetInt("code", -1)
|
|
requestId, _ := this.GetInt("requestId", 0)
|
|
requestId, _ := this.GetInt("requestId", 0)
|
|
- req.RequestId = uint64(requestId)
|
|
|
|
- text := this.GetString("text")
|
|
|
|
- req.Text = text
|
|
|
|
- resultDetail := this.GetString("resultDetail")
|
|
|
|
- req.ResultDetail = resultDetail
|
|
|
|
-
|
|
|
|
- //utils.FileLog.Info("RecTaskCallback, body: " + string(this.Ctx.Input.RequestBody))
|
|
|
|
- //if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
|
- // br.Code = 403
|
|
|
|
- // br.Message = "参数解析失败"
|
|
|
|
- // return
|
|
|
|
- //}
|
|
|
|
- utils.FileLog.Info("RecTaskCallback, 1")
|
|
|
|
-
|
|
|
|
- // TODO:处理回调结果
|
|
|
|
- apiLog := new(speech_recognition.SpeechRecognitionApiLog)
|
|
|
|
- apiLog.RequestId = strconv.Itoa(int(req.RequestId))
|
|
|
|
- j, e := json.Marshal(req)
|
|
|
|
|
|
+ detail := this.GetString("resultDetail")
|
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("RecTaskCallback, requestId: %d", requestId))
|
|
|
|
+
|
|
|
|
+ // 获取taskId对应的API请求及语音识别
|
|
|
|
+ logOb := new(speech_recognition.SpeechRecognitionApiLog)
|
|
|
|
+ cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionApiLogCols.RequestId)
|
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
|
+ pars = append(pars, requestId)
|
|
|
|
+ apiLog, e := logOb.GetItemByCondition(cond, pars, "")
|
|
if e != nil {
|
|
if e != nil {
|
|
- utils.FileLog.Info("RecTaskCallback, 2 " + e.Error())
|
|
|
|
|
|
+ errMsg = "获取API记录失败"
|
|
|
|
+ utils.FileLog.Info("API回调-获取请求记录失败, Err: " + e.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ speechOb := new(speech_recognition.SpeechRecognition)
|
|
|
|
+ speechItem, e := speechOb.GetItemById(apiLog.SpeechRecognitionId)
|
|
|
|
+ if e != nil {
|
|
|
|
+ errMsg = "获取语音识别失败"
|
|
|
|
+ utils.FileLog.Info("获取语音识别失败, Err: " + e.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // API结果返回有误
|
|
|
|
+ nowTime := time.Now().Local()
|
|
|
|
+ if code != speech_recognition.ApiRequestCodeSuccess {
|
|
|
|
+ convertRemark := speech_recognition.ApiErrMsgMapping[code]
|
|
|
|
+ if convertRemark == "" {
|
|
|
|
+ convertRemark = fmt.Sprintf("未知错误: %d", code)
|
|
|
|
+ }
|
|
|
|
+ speechItem.ConvertRemark = convertRemark
|
|
|
|
+ speechItem.State = speech_recognition.SpeechRecognitionStateFail
|
|
|
|
+ speechItem.ModifyTime = nowTime
|
|
|
|
+ speechCols := []string{speech_recognition.SpeechRecognitionCols.ConvertRemark, speech_recognition.SpeechRecognitionCols.State, speech_recognition.SpeechRecognitionCols.ModifyTime}
|
|
|
|
+
|
|
|
|
+ apiLog.RequestCode = code
|
|
|
|
+ apiLog.RequestResult = convertRemark
|
|
|
|
+ apiLog.ModifyTime = nowTime
|
|
|
|
+ apiLogCols := []string{speech_recognition.SpeechRecognitionApiLogCols.RequestCode, speech_recognition.SpeechRecognitionApiLogCols.RequestResult, speech_recognition.SpeechRecognitionApiLogCols.ModifyTime}
|
|
|
|
+
|
|
|
|
+ // 更新语音识别及API记录
|
|
|
|
+ if e := speech_recognition.UpdateSpeechAndApiLog(speechItem, speechCols, apiLog, apiLogCols); e != nil {
|
|
|
|
+ errMsg = "更新API返回结果失败"
|
|
|
|
+ utils.FileLog.Info("更新API返回结果失败, Err: " + e.Error())
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 解析转写段落内容
|
|
|
|
+ sentences := make([]*services.TencentRecTaskSentenceDetail, 0)
|
|
|
|
+ if e := json.Unmarshal([]byte(detail), &sentences); e != nil {
|
|
|
|
+ errMsg = "解析语音识别内容失败"
|
|
|
|
+ utils.FileLog.Info("解析语音识别内容失败, Err: " + e.Error())
|
|
|
|
+ return
|
|
}
|
|
}
|
|
- apiLog.RequestResult = string(j)
|
|
|
|
- apiLog.CreateTime = time.Now().Local()
|
|
|
|
|
|
+ contents := make([]*speech_recognition.SpeechRecognitionContent, 0)
|
|
|
|
+ sorts := 0 // API返回的结果本身是已排过序的
|
|
|
|
+ for _, v := range sentences {
|
|
|
|
+ sorts += 1
|
|
|
|
+ t := new(speech_recognition.SpeechRecognitionContent)
|
|
|
|
+ t.SpeechRecognitionId = speechItem.SpeechRecognitionId
|
|
|
|
+ t.Sort = sorts
|
|
|
|
+ t.Content = v.FinalSentence
|
|
|
|
+ t.StartMs = v.StartMs
|
|
|
|
+ t.EndMs = v.EndMs
|
|
|
|
+ t.CreateTime = nowTime
|
|
|
|
+ t.ModifyTime = nowTime
|
|
|
|
+ contents = append(contents, t)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ speechItem.State = speech_recognition.SpeechRecognitionStateSuccess
|
|
|
|
+ speechItem.ModifyTime = nowTime
|
|
|
|
+ speechCols := []string{speech_recognition.SpeechRecognitionCols.State, speech_recognition.SpeechRecognitionCols.ModifyTime}
|
|
|
|
+
|
|
|
|
+ apiLog.RequestCode = code
|
|
|
|
+ apiLog.RequestResult = detail
|
|
apiLog.ModifyTime = time.Now().Local()
|
|
apiLog.ModifyTime = time.Now().Local()
|
|
- if e := apiLog.Create(); e != nil {
|
|
|
|
- br.Code = 403
|
|
|
|
- br.Message = "获取回调结果失败"
|
|
|
|
|
|
+ apiLogCols := []string{speech_recognition.SpeechRecognitionApiLogCols.RequestCode, speech_recognition.SpeechRecognitionApiLogCols.RequestResult, speech_recognition.SpeechRecognitionApiLogCols.ModifyTime}
|
|
|
|
+
|
|
|
|
+ // 新增解析内容并更新语音识别及API记录
|
|
|
|
+ if e := speech_recognition.CreateContentAndUpdateSpeechAndApiLog(contents, speechItem, speechCols, apiLog, apiLogCols); e != nil {
|
|
|
|
+ errMsg = "新增API返回结果失败"
|
|
|
|
+ utils.FileLog.Info("新增API返回结果失败, Err: " + e.Error())
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Convert
|
|
|
|
+// @Title 语音转换
|
|
|
|
+// @Description 语音转换
|
|
|
|
+// @Param request body speech_recognition.SpeechRecognitionConvertReq true "type json string"
|
|
|
|
+// @Success 200 string "操作成功"
|
|
|
|
+// @router /convert [post]
|
|
|
|
+func (this *SpeechRecognitionController) Convert() {
|
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
|
+ defer func() {
|
|
|
|
+ if br.ErrMsg == "" {
|
|
|
|
+ br.IsSendEmail = false
|
|
|
|
+ }
|
|
|
|
+ this.Data["json"] = br
|
|
|
|
+ this.ServeJSON()
|
|
|
|
+ }()
|
|
|
|
+ sysUser := this.SysUser
|
|
|
|
+ if sysUser == nil {
|
|
|
|
+ br.Msg = "请登录"
|
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
|
+ br.Ret = 408
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ var req speech_recognition.SpeechRecognitionConvertReq
|
|
|
|
+ if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
|
+ br.Msg = "参数有误"
|
|
|
|
+ br.ErrMsg = "参数解析失败, Err: " + e.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if req.MenuId <= 0 {
|
|
|
|
+ br.Msg = "请选择目录"
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if len(req.Files) == 0 {
|
|
|
|
+ br.Msg = "请上传转写文件"
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ for _, r := range req.Files {
|
|
|
|
+ if r.FileName == "" && r.ResourceUrl == "" {
|
|
|
|
+ br.Msg = "转写文件有误,请检查"
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ speeches := make([]*speech_recognition.SpeechRecognition, 0)
|
|
|
|
+ nowTime := time.Now().Local()
|
|
|
|
+ for _, v := range req.Files {
|
|
|
|
+ t := new(speech_recognition.SpeechRecognition)
|
|
|
|
+ t.FileName = v.FileName
|
|
|
|
+ t.ResourceUrl = v.ResourceUrl
|
|
|
|
+ t.MenuId = req.MenuId
|
|
|
|
+ // TODO:所属目录位置
|
|
|
|
+ t.SysUserId = sysUser.AdminId
|
|
|
|
+ t.SysUserName = sysUser.RealName
|
|
|
|
+ t.State = speech_recognition.SpeechRecognitionStateWait
|
|
|
|
+ t.CreateTime = nowTime
|
|
|
|
+ t.ModifyTime = nowTime
|
|
|
|
+ // CreateMulti拿不到主键, 此处用循环新增获取
|
|
|
|
+ if e := t.Create(); e != nil {
|
|
|
|
+ br.Msg = "操作失败"
|
|
|
|
+ br.ErrMsg = "批量新增转写文件失败, Err: " + e.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ speeches = append(speeches, t)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 批量转写语音
|
|
|
|
+ go func() {
|
|
|
|
+ services.BatchConvertSpeech(speeches)
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ br.Ret = 200
|
|
|
|
+ br.Success = true
|
|
|
|
+ br.Msg = "操作成功"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// ConvertList
|
|
|
|
+// @Title 转换列表
|
|
|
|
+// @Description 转换列表
|
|
|
|
+// @Success 200 {object} speech_recognition.SpeechRecognitionItem
|
|
|
|
+// @router /convert_list [get]
|
|
|
|
+func (this *SpeechRecognitionController) ConvertList() {
|
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
|
+ defer func() {
|
|
|
|
+ if br.ErrMsg == "" {
|
|
|
|
+ br.IsSendEmail = false
|
|
|
|
+ }
|
|
|
|
+ this.Data["json"] = br
|
|
|
|
+ this.ServeJSON()
|
|
|
|
+ }()
|
|
|
|
+ sysUser := this.SysUser
|
|
|
|
+ if sysUser == nil {
|
|
|
|
+ br.Msg = "请登录"
|
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
|
+ br.Ret = 408
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 仅取待转换和转换失败的
|
|
|
|
+ states := []int{speech_recognition.SpeechRecognitionStateWait, speech_recognition.SpeechRecognitionStateFail}
|
|
|
|
+ speechOb := new(speech_recognition.SpeechRecognition)
|
|
|
|
+ cond := fmt.Sprintf(` %s = ? AND %s IN (%s)`, speech_recognition.SpeechRecognitionCols.SysUserId, speech_recognition.SpeechRecognitionCols.State, utils.GetOrmInReplace(len(states)))
|
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
|
+ pars = append(pars, sysUser.AdminId, states)
|
|
|
|
+ list, e := speechOb.GetItemsByCondition(cond, pars, []string{}, "")
|
|
|
|
+ if e != nil {
|
|
|
|
+ br.Msg = "获取失败"
|
|
|
|
+ br.ErrMsg = "获取转写文件列表失败, Err: " + e.Error()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- utils.FileLog.Info("RecTaskCallback, 3")
|
|
|
|
|
|
+ resp := make([]*speech_recognition.SpeechRecognitionItem, 0)
|
|
|
|
+ for _, v := range list {
|
|
|
|
+ resp = append(resp, speech_recognition.FormatSpeechRecognition2Item(v))
|
|
|
|
+ }
|
|
|
|
|
|
- br.Code = 0
|
|
|
|
- br.Message = "success"
|
|
|
|
|
|
+ br.Data = resp
|
|
|
|
+ br.Ret = 200
|
|
|
|
+ br.Success = true
|
|
|
|
+ br.Msg = "获取成功"
|
|
}
|
|
}
|
|
|
|
|
|
-// Save
|
|
|
|
-// @Title 保存
|
|
|
|
-// @Description 保存
|
|
|
|
|
|
+// TODO:Save
|
|
|
|
+// @Title 保存内容
|
|
|
|
+// @Description 保存内容
|
|
// @Param request body speech_recognition.SpeechRecognitionSaveReq true "type json string"
|
|
// @Param request body speech_recognition.SpeechRecognitionSaveReq true "type json string"
|
|
// @Success 200 string "操作成功"
|
|
// @Success 200 string "操作成功"
|
|
// @router /save [post]
|
|
// @router /save [post]
|
|
-func (this *SpeechRecognitionCommonController) Save() {
|
|
|
|
|
|
+func (this *SpeechRecognitionController) Save() {
|
|
br := new(models.BaseResponse).Init()
|
|
br := new(models.BaseResponse).Init()
|
|
defer func() {
|
|
defer func() {
|
|
if br.ErrMsg == "" {
|
|
if br.ErrMsg == "" {
|
|
@@ -90,13 +265,13 @@ func (this *SpeechRecognitionCommonController) Save() {
|
|
this.Data["json"] = br
|
|
this.Data["json"] = br
|
|
this.ServeJSON()
|
|
this.ServeJSON()
|
|
}()
|
|
}()
|
|
- //sysUser := this.SysUser
|
|
|
|
- //if sysUser == nil {
|
|
|
|
- // br.Msg = "请登录"
|
|
|
|
- // br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
|
- // br.Ret = 408
|
|
|
|
- // return
|
|
|
|
- //}
|
|
|
|
|
|
+ sysUser := this.SysUser
|
|
|
|
+ if sysUser == nil {
|
|
|
|
+ br.Msg = "请登录"
|
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
|
+ br.Ret = 408
|
|
|
|
+ return
|
|
|
|
+ }
|
|
var req speech_recognition.SpeechRecognitionSaveReq
|
|
var req speech_recognition.SpeechRecognitionSaveReq
|
|
if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
br.Msg = "参数有误"
|
|
br.Msg = "参数有误"
|
|
@@ -104,27 +279,436 @@ func (this *SpeechRecognitionCommonController) Save() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- conf, e := models.GetBusinessConf()
|
|
|
|
|
|
+ br.Ret = 200
|
|
|
|
+ br.Success = true
|
|
|
|
+ br.Msg = "操作成功"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// RemoveFile
|
|
|
|
+// @Title (软)删除文件
|
|
|
|
+// @Description (软)删除文件
|
|
|
|
+// @Param request body speech_recognition.SpeechRecognitionRemoveFileReq true "type json string"
|
|
|
|
+// @Success 200 string "操作成功"
|
|
|
|
+// @router /remove_file [post]
|
|
|
|
+func (this *SpeechRecognitionController) RemoveFile() {
|
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
|
+ defer func() {
|
|
|
|
+ if br.ErrMsg == "" {
|
|
|
|
+ br.IsSendEmail = false
|
|
|
|
+ }
|
|
|
|
+ this.Data["json"] = br
|
|
|
|
+ this.ServeJSON()
|
|
|
|
+ }()
|
|
|
|
+ sysUser := this.SysUser
|
|
|
|
+ if sysUser == nil {
|
|
|
|
+ br.Msg = "请登录"
|
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
|
+ br.Ret = 408
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ var req speech_recognition.SpeechRecognitionRemoveFileReq
|
|
|
|
+ if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
|
+ br.Msg = "参数有误"
|
|
|
|
+ br.ErrMsg = "参数解析失败, Err: " + e.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if req.SpeechRecognitionId <= 0 {
|
|
|
|
+ br.Msg = "参数有误"
|
|
|
|
+ br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ speechOb := new(speech_recognition.SpeechRecognition)
|
|
|
|
+ speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
|
|
if e != nil {
|
|
if e != nil {
|
|
|
|
+ if e.Error() == utils.ErrNoRow() {
|
|
|
|
+ br.Msg = "转写文件不存在,请刷新页面"
|
|
|
|
+ return
|
|
|
|
+ }
|
|
br.Msg = "操作失败"
|
|
br.Msg = "操作失败"
|
|
- br.ErrMsg = "获取配置失败, Err: " + e.Error()
|
|
|
|
|
|
+ br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- var taskReq services.TencentRecTaskReq
|
|
|
|
- taskReq.FileUrl = req.FileName
|
|
|
|
- taskReq.SecretId = conf[models.BusinessConfTencentApiSecretId]
|
|
|
|
- taskReq.SecretKey = conf[models.BusinessConfTencentApiSecretKey]
|
|
|
|
- taskReq.CallbackUrl = conf[models.BusinessConfTencentApiRecTaskCallbackUrl]
|
|
|
|
- taskId, e := services.TencentCreateRecTask(taskReq)
|
|
|
|
|
|
+ speechItem.FileState = speech_recognition.SpeechRecognitionFileRemoveFlag
|
|
|
|
+ speechItem.ModifyTime = time.Now().Local()
|
|
|
|
+ updateCols := []string{speech_recognition.SpeechRecognitionCols.FileState, speech_recognition.SpeechRecognitionCols.ModifyTime}
|
|
|
|
+ if e = speechItem.Update(updateCols); e != nil {
|
|
|
|
+ br.Msg = "操作失败"
|
|
|
|
+ br.ErrMsg = "软删除转写文件失败, Err: " + e.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ br.Ret = 200
|
|
|
|
+ br.Success = true
|
|
|
|
+ br.Msg = "操作成功"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Rename
|
|
|
|
+// @Title 重命名
|
|
|
|
+// @Description 重命名
|
|
|
|
+// @Param request body speech_recognition.SpeechRecognitionRenameReq true "type json string"
|
|
|
|
+// @Success 200 string "操作成功"
|
|
|
|
+// @router /rename [post]
|
|
|
|
+func (this *SpeechRecognitionController) Rename() {
|
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
|
+ defer func() {
|
|
|
|
+ if br.ErrMsg == "" {
|
|
|
|
+ br.IsSendEmail = false
|
|
|
|
+ }
|
|
|
|
+ this.Data["json"] = br
|
|
|
|
+ this.ServeJSON()
|
|
|
|
+ }()
|
|
|
|
+ sysUser := this.SysUser
|
|
|
|
+ if sysUser == nil {
|
|
|
|
+ br.Msg = "请登录"
|
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
|
+ br.Ret = 408
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ var req speech_recognition.SpeechRecognitionRenameReq
|
|
|
|
+ if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
|
+ br.Msg = "参数有误"
|
|
|
|
+ br.ErrMsg = "参数解析失败, Err: " + e.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if req.SpeechRecognitionId <= 0 {
|
|
|
|
+ br.Msg = "参数有误"
|
|
|
|
+ br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ req.FileName = strings.TrimSpace(req.FileName)
|
|
|
|
+ if req.FileName == "" {
|
|
|
|
+ br.Msg = "请输入文件名称"
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ speechOb := new(speech_recognition.SpeechRecognition)
|
|
|
|
+ speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
|
|
if e != nil {
|
|
if e != nil {
|
|
|
|
+ if e.Error() == utils.ErrNoRow() {
|
|
|
|
+ br.Msg = "转写文件不存在,请刷新页面"
|
|
|
|
+ return
|
|
|
|
+ }
|
|
br.Msg = "操作失败"
|
|
br.Msg = "操作失败"
|
|
- br.ErrMsg = fmt.Sprintf("TencentCreateRecTask err: %s", e.Error())
|
|
|
|
|
|
+ br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 重名校验
|
|
|
|
+ {
|
|
|
|
+ cond := fmt.Sprintf(` %s = ? AND %s <> ?`, speech_recognition.SpeechRecognitionCols.FileName, speech_recognition.SpeechRecognitionCols.SpeechRecognitionId)
|
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
|
+ pars = append(pars, req.FileName, req.SpeechRecognitionId)
|
|
|
|
+ exists, e := speechOb.GetItemByCondition(cond, pars, "")
|
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
|
+ br.Msg = "操作失败"
|
|
|
|
+ br.ErrMsg = "获取同名转写文件失败, Err: " + e.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if exists != nil && exists.SpeechRecognitionId > 0 {
|
|
|
|
+ br.Msg = "分类名称已存在,请重新输入"
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ speechItem.FileName = req.FileName
|
|
|
|
+ speechItem.ModifyTime = time.Now().Local()
|
|
|
|
+ updateCols := []string{speech_recognition.SpeechRecognitionCols.FileName, speech_recognition.SpeechRecognitionCols.ModifyTime}
|
|
|
|
+ if e = speechItem.Update(updateCols); e != nil {
|
|
|
|
+ br.Msg = "操作失败"
|
|
|
|
+ br.ErrMsg = "转写文件重命名失败, Err: " + e.Error()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- br.Data = taskId
|
|
|
|
br.Ret = 200
|
|
br.Ret = 200
|
|
br.Success = true
|
|
br.Success = true
|
|
br.Msg = "操作成功"
|
|
br.Msg = "操作成功"
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// Remove
|
|
|
|
+// @Title 删除
|
|
|
|
+// @Description 删除
|
|
|
|
+// @Param request body speech_recognition.SpeechRecognitionRemoveReq true "type json string"
|
|
|
|
+// @Success 200 string "操作成功"
|
|
|
|
+// @router /remove [post]
|
|
|
|
+func (this *SpeechRecognitionController) Remove() {
|
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
|
+ defer func() {
|
|
|
|
+ if br.ErrMsg == "" {
|
|
|
|
+ br.IsSendEmail = false
|
|
|
|
+ }
|
|
|
|
+ this.Data["json"] = br
|
|
|
|
+ this.ServeJSON()
|
|
|
|
+ }()
|
|
|
|
+ sysUser := this.SysUser
|
|
|
|
+ if sysUser == nil {
|
|
|
|
+ br.Msg = "请登录"
|
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
|
+ br.Ret = 408
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ var req speech_recognition.SpeechRecognitionRemoveReq
|
|
|
|
+ if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
|
+ br.Msg = "参数有误"
|
|
|
|
+ br.ErrMsg = "参数解析失败, Err: " + e.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if req.SpeechRecognitionId <= 0 {
|
|
|
|
+ br.Msg = "参数有误"
|
|
|
|
+ br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ speechOb := new(speech_recognition.SpeechRecognition)
|
|
|
|
+ speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
|
|
|
|
+ if e != nil {
|
|
|
|
+ if e.Error() == utils.ErrNoRow() {
|
|
|
|
+ br.Ret = 200
|
|
|
|
+ br.Success = true
|
|
|
|
+ br.Msg = "操作成功"
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ br.Msg = "操作失败"
|
|
|
|
+ br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if e = speechItem.Del(); e != nil {
|
|
|
|
+ br.Msg = "操作失败"
|
|
|
|
+ br.ErrMsg = "删除转写文件失败, Err: " + e.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 清除标签关联
|
|
|
|
+ go func() {
|
|
|
|
+ mappingOb := new(speech_recognition.SpeechRecognitionTagMapping)
|
|
|
|
+ _ = mappingOb.ClearMappingBySpeechId(req.SpeechRecognitionId)
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ br.Ret = 200
|
|
|
|
+ br.Success = true
|
|
|
|
+ br.Msg = "操作成功"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// SaveTag
|
|
|
|
+// @Title 保存标签
|
|
|
|
+// @Description 保存标签
|
|
|
|
+// @Param request body speech_recognition.SpeechRecognitionSaveTagReq true "type json string"
|
|
|
|
+// @Success 200 string "操作成功"
|
|
|
|
+// @router /save_tag [post]
|
|
|
|
+func (this *SpeechRecognitionController) SaveTag() {
|
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
|
+ defer func() {
|
|
|
|
+ if br.ErrMsg == "" {
|
|
|
|
+ br.IsSendEmail = false
|
|
|
|
+ }
|
|
|
|
+ this.Data["json"] = br
|
|
|
|
+ this.ServeJSON()
|
|
|
|
+ }()
|
|
|
|
+ sysUser := this.SysUser
|
|
|
|
+ if sysUser == nil {
|
|
|
|
+ br.Msg = "请登录"
|
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
|
+ br.Ret = 408
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ var req speech_recognition.SpeechRecognitionSaveTagReq
|
|
|
|
+ if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
|
+ br.Msg = "参数有误"
|
|
|
|
+ br.ErrMsg = "参数解析失败, Err: " + e.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if req.SpeechRecognitionId <= 0 {
|
|
|
|
+ br.Msg = "参数有误"
|
|
|
|
+ br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ speechOb := new(speech_recognition.SpeechRecognition)
|
|
|
|
+ _, e := speechOb.GetItemById(req.SpeechRecognitionId)
|
|
|
|
+ if e != nil {
|
|
|
|
+ if e.Error() == utils.ErrNoRow() {
|
|
|
|
+ br.Msg = "转写文件不存在,请刷新页面"
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ br.Msg = "操作失败"
|
|
|
|
+ br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 清除原标签
|
|
|
|
+ mappingOb := new(speech_recognition.SpeechRecognitionTagMapping)
|
|
|
|
+ if e = mappingOb.ClearMappingBySpeechId(req.SpeechRecognitionId); e != nil {
|
|
|
|
+ br.Msg = "操作失败"
|
|
|
|
+ br.ErrMsg = "清除转写文件标签失败, Err: " + e.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 保存新标签
|
|
|
|
+ if len(req.TagIds) > 0 {
|
|
|
|
+ mappings := make([]*speech_recognition.SpeechRecognitionTagMapping, 0)
|
|
|
|
+ for _, v := range req.TagIds {
|
|
|
|
+ if v <= 0 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ mappings = append(mappings, &speech_recognition.SpeechRecognitionTagMapping{
|
|
|
|
+ TagId: v,
|
|
|
|
+ SpeechRecognitionId: req.SpeechRecognitionId,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ if e = mappingOb.CreateMulti(mappings); e != nil {
|
|
|
|
+ br.Msg = "操作失败"
|
|
|
|
+ br.ErrMsg = "批量新增转写文件标签失败, Err: " + e.Error()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ br.Ret = 200
|
|
|
|
+ br.Success = true
|
|
|
|
+ br.Msg = "操作成功"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// TODO:List
|
|
|
|
+// @Title 语音识别列表
|
|
|
|
+// @Description 语音识别列表
|
|
|
|
+// @Param ParentId query int false "父级ID"
|
|
|
|
+// @Success 200 {object} speech_recognition.SpeechRecognitionMenuNodeItem
|
|
|
|
+// @router /list [get]
|
|
|
|
+func (this *SpeechRecognitionController) List() {
|
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
|
+ defer func() {
|
|
|
|
+ if br.ErrMsg == "" {
|
|
|
|
+ br.IsSendEmail = false
|
|
|
|
+ }
|
|
|
|
+ this.Data["json"] = br
|
|
|
|
+ this.ServeJSON()
|
|
|
|
+ }()
|
|
|
|
+ sysUser := this.SysUser
|
|
|
|
+ if sysUser == nil {
|
|
|
|
+ br.Msg = "请登录"
|
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
|
+ br.Ret = 408
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // TODO:标签列表
|
|
|
|
+
|
|
|
|
+ br.Ret = 200
|
|
|
|
+ br.Success = true
|
|
|
|
+ br.Msg = "获取成功"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// TODO:Detail
|
|
|
|
+// @Title 语音识别详情
|
|
|
|
+// @Description 语音识别详情
|
|
|
|
+// @Param SpeechRecognitionId query int true "语音识别ID"
|
|
|
|
+// @Success 200 {object} speech_recognition.SpeechRecognitionMenuNodeItem
|
|
|
|
+// @router /detail [get]
|
|
|
|
+func (this *SpeechRecognitionController) Detail() {
|
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
|
+ defer func() {
|
|
|
|
+ if br.ErrMsg == "" {
|
|
|
|
+ br.IsSendEmail = false
|
|
|
|
+ }
|
|
|
|
+ this.Data["json"] = br
|
|
|
|
+ this.ServeJSON()
|
|
|
|
+ }()
|
|
|
|
+ sysUser := this.SysUser
|
|
|
|
+ if sysUser == nil {
|
|
|
|
+ br.Msg = "请登录"
|
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
|
+ br.Ret = 408
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // TODO:标签详情
|
|
|
|
+
|
|
|
|
+ br.Ret = 200
|
|
|
|
+ br.Success = true
|
|
|
|
+ br.Msg = "获取成功"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// TODO:Move
|
|
|
|
+// @Title 移动语音识别/目录
|
|
|
|
+// @Description 移动标签/目录
|
|
|
|
+// @Param request body speech_recognition.SpeechRecognitionTagRemoveReq true "type json string"
|
|
|
|
+// @Success 200 string "操作成功"
|
|
|
|
+// @router /move [post]
|
|
|
|
+func (this *SpeechRecognitionController) Move() {
|
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
|
+ defer func() {
|
|
|
|
+ if br.ErrMsg == "" {
|
|
|
|
+ br.IsSendEmail = false
|
|
|
|
+ }
|
|
|
|
+ this.Data["json"] = br
|
|
|
|
+ this.ServeJSON()
|
|
|
|
+ }()
|
|
|
|
+ sysUser := this.SysUser
|
|
|
|
+ if sysUser == nil {
|
|
|
|
+ br.Msg = "请登录"
|
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
|
+ br.Ret = 408
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // TODO:移动语音识别/目录
|
|
|
|
+
|
|
|
|
+ br.Ret = 200
|
|
|
|
+ br.Success = true
|
|
|
|
+ br.Msg = "操作成功"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//// TestConvert
|
|
|
|
+//// @Title 转写测试
|
|
|
|
+//// @Description 转写测试
|
|
|
|
+//// @Param request body speech_recognition.SpeechRecognitionSaveReq true "type json string"
|
|
|
|
+//// @Success 200 string "操作成功"
|
|
|
|
+//// @router /test_convert [post]
|
|
|
|
+//func (this *SpeechRecognitionCommonController) TestConvert() {
|
|
|
|
+// br := new(models.BaseResponse).Init()
|
|
|
|
+// defer func() {
|
|
|
|
+// if br.ErrMsg == "" {
|
|
|
|
+// br.IsSendEmail = false
|
|
|
|
+// }
|
|
|
|
+// this.Data["json"] = br
|
|
|
|
+// this.ServeJSON()
|
|
|
|
+// }()
|
|
|
|
+// //sysUser := this.SysUser
|
|
|
|
+// //if sysUser == nil {
|
|
|
|
+// // br.Msg = "请登录"
|
|
|
|
+// // br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
|
+// // br.Ret = 408
|
|
|
|
+// // return
|
|
|
|
+// //}
|
|
|
|
+// var req speech_recognition.SpeechRecognitionSaveReq
|
|
|
|
+// if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
|
+// br.Msg = "参数有误"
|
|
|
|
+// br.ErrMsg = "参数解析失败, Err: " + e.Error()
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// conf, e := models.GetBusinessConf()
|
|
|
|
+// if e != nil {
|
|
|
|
+// br.Msg = "操作失败"
|
|
|
|
+// br.ErrMsg = "获取配置失败, Err: " + e.Error()
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// var taskReq services.TencentRecTaskReq
|
|
|
|
+// taskReq.FileUrl = req.FileName
|
|
|
|
+// taskReq.SecretId = conf[models.BusinessConfTencentApiSecretId]
|
|
|
|
+// taskReq.SecretKey = conf[models.BusinessConfTencentApiSecretKey]
|
|
|
|
+// taskReq.CallbackUrl = conf[models.BusinessConfTencentApiRecTaskCallbackUrl]
|
|
|
|
+// taskId, e := services.TencentCreateRecTask(taskReq)
|
|
|
|
+// if e != nil {
|
|
|
|
+// br.Msg = "操作失败"
|
|
|
|
+// br.ErrMsg = fmt.Sprintf("TencentCreateRecTask err: %s", e.Error())
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// br.Data = taskId
|
|
|
|
+// br.Ret = 200
|
|
|
|
+// br.Success = true
|
|
|
|
+// br.Msg = "操作成功"
|
|
|
|
+//}
|