123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860 |
- package speech_recognition
- import (
- "encoding/json"
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- "eta/eta_api/models/speech_recognition"
- "eta/eta_api/services"
- "eta/eta_api/services/alarm_msg"
- "eta/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strings"
- "time"
- )
- type SpeechRecognitionController struct {
- controllers.BaseAuthController
- }
- type SpeechRecognitionCommonController struct {
- controllers.BaseCommonController
- }
- // RecTaskCallback
- // @Title 语音识别回调
- // @Description 语音识别回调
- // @Param request body services.TencentRecTaskCallback true "type json string"
- // @Success 200 string "操作成功"
- // @router /rec_task/callback [post]
- func (this *SpeechRecognitionCommonController) RecTaskCallback() {
- // 此接口返回指定响应体
- br := new(services.TencentRecTaskCallbackResp)
- var errMsg string
- 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)
- }()
- code, _ := this.GetInt("code", -1)
- requestId, _ := this.GetInt("requestId", 0)
- 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 {
- 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
- }
- contents := make([]*speech_recognition.SpeechRecognitionContent, 0)
- sorts := 0 // API返回的结果本身是已排过序的
- var abstract string
- var abstractLimit int
- 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)
- // 取前几段作为摘要保存
- if abstractLimit < 5 {
- abstractLimit += 1
- abstract += v.FinalSentence
- }
- }
- speechItem.Abstract = abstract
- speechItem.State = speech_recognition.SpeechRecognitionStateSuccess
- speechItem.ModifyTime = nowTime
- speechCols := []string{speech_recognition.SpeechRecognitionCols.Abstract, speech_recognition.SpeechRecognitionCols.State, speech_recognition.SpeechRecognitionCols.ModifyTime}
- apiLog.RequestCode = code
- apiLog.RequestResult = detail
- apiLog.ModifyTime = time.Now().Local()
- 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(` AND %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
- }
- resp := make([]*speech_recognition.SpeechRecognitionItem, 0)
- for _, v := range list {
- resp = append(resp, speech_recognition.FormatSpeechRecognition2Item(v))
- }
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // Save
- // @Title 保存内容
- // @Description 保存内容
- // @Param request body speech_recognition.SpeechRecognitionSaveReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /save [post]
- func (this *SpeechRecognitionController) Save() {
- 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
- }
- if req.SpeechRecognitionId <= 0 {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
- return
- }
- if len(req.Contents) == 0 {
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- 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
- }
- // 批量修改内容
- contentOb := new(speech_recognition.SpeechRecognitionContent)
- if e = contentOb.BatchUpdateContents(req.Contents); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "批量修改内容失败, Err: " + e.Error()
- return
- }
- 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.Error() == utils.ErrNoRow() {
- br.Msg = "转写文件不存在,请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
- return
- }
- 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.Error() == utils.ErrNoRow() {
- br.Msg = "转写文件不存在,请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
- return
- }
- // 重名校验
- {
- cond := fmt.Sprintf(` AND %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
- }
- br.Ret = 200
- br.Success = true
- 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 = "操作成功"
- }
- // List
- // @Title 语音识别列表
- // @Description 语音识别列表
- // @Param FileName query string false "文件名称"
- // @Param StartTime query string false "开始时间"
- // @Param EndTime query string false "结束时间"
- // @Param CreateUserId query int false "创建人ID"
- // @Param TagId query int false "标签ID"
- // @Success 200 {object} speech_recognition.SpeechRecognitionListResp
- // @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
- }
- params := new(speech_recognition.SpeechRecognitionListReq)
- if e := this.ParseForm(params); e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "参数解析失败, Err: " + e.Error()
- return
- }
- params.FileName = strings.TrimSpace(params.FileName)
- dataResp := new(speech_recognition.SpeechRecognitionListResp)
- cond := ``
- pars := make([]interface{}, 0)
- // 筛选项
- {
- if params.FileName != "" {
- cond += fmt.Sprintf(` AND %s LIKE ?`, speech_recognition.SpeechRecognitionCols.FileName)
- pars = append(pars, fmt.Sprint("%", params.FileName, "%"))
- }
- if params.StartTime != "" && params.EndTime != "" {
- _, e := time.Parse(utils.FormatDate, params.StartTime)
- if e != nil {
- br.Msg = "开始时间格式有误"
- return
- }
- _, e = time.Parse(utils.FormatDate, params.EndTime)
- if e != nil {
- br.Msg = "结束时间格式有误"
- return
- }
- st := fmt.Sprintf("%s 00:00:00", params.StartTime)
- ed := fmt.Sprintf("%s 23:59:59", params.EndTime)
- cond += fmt.Sprintf(` AND (%s BETWEEN ? AND ?)`, speech_recognition.SpeechRecognitionCols.CreateTime)
- pars = append(pars, st, ed)
- }
- if params.CreateUserId > 0 {
- cond += fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionCols.SysUserId)
- pars = append(pars, params.CreateUserId)
- }
- // 标签筛选
- if params.TagId > 0 {
- mappingOb := new(speech_recognition.SpeechRecognitionTagMapping)
- tagSpeechIds, e := mappingOb.GetSpeechIdsByTagId(params.TagId)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取标签关联语音识别失败, Err: " + e.Error()
- return
- }
- if len(tagSpeechIds) == 0 {
- br.Data = dataResp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- cond += fmt.Sprintf(` AND %s IN (%s)`, speech_recognition.SpeechRecognitionCols.SpeechRecognitionId, utils.GetOrmInReplace(len(tagSpeechIds)))
- pars = append(pars, tagSpeechIds)
- }
- }
- // 分页列表
- speechOb := new(speech_recognition.SpeechRecognition)
- total, e := speechOb.GetCountByCondition(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取语音识别列表总数失败, Err: " + e.Error()
- return
- }
- var startSize int
- if params.PageSize <= 0 {
- params.PageSize = utils.PageSize20
- }
- if params.CurrentIndex <= 0 {
- params.CurrentIndex = 1
- }
- startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
- list, e := speechOb.GetPageItemsByCondition(cond, pars, []string{}, "", startSize, params.PageSize)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取语音识别列表失败, Err: " + e.Error()
- return
- }
- // 获取标签
- speechIds := make([]int, 0)
- for _, v := range list {
- speechIds = append(speechIds, v.SpeechRecognitionId)
- }
- mappingTags, e := speech_recognition.GetSpeechRecognitionTagsBySpeechIds(speechIds)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取语音识别列表标签失败, Err: " + e.Error()
- return
- }
- speechDetailTags := make(map[int][]*speech_recognition.SpeechRecognitionDetailTag)
- for _, v := range mappingTags {
- if speechDetailTags[v.SpeechRecognitionId] == nil {
- speechDetailTags[v.SpeechRecognitionId] = make([]*speech_recognition.SpeechRecognitionDetailTag, 0)
- }
- speechDetailTags[v.SpeechRecognitionId] = append(speechDetailTags[v.SpeechRecognitionId], &speech_recognition.SpeechRecognitionDetailTag{
- TagId: v.TagId,
- TagName: v.TagName,
- })
- }
- respList := make([]*speech_recognition.SpeechRecognitionDetailItem, 0)
- for _, v := range list {
- t := speech_recognition.FormatSpeechRecognition2DetailItem(v, make([]*speech_recognition.SpeechRecognitionContentItem, 0), speechDetailTags[v.SpeechRecognitionId])
- respList = append(respList, t)
- }
- page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
- dataResp.Paging = page
- dataResp.List = respList
- br.Data = dataResp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // Detail
- // @Title 语音识别详情
- // @Description 语音识别详情
- // @Param SpeechRecognitionId query int true "语音识别ID"
- // @Success 200 {object} speech_recognition.SpeechRecognitionDetailItem
- // @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
- }
- speechId, _ := this.GetInt("SpeechRecognitionId")
- if speechId <= 0 {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", speechId)
- return
- }
- speechOb := new(speech_recognition.SpeechRecognition)
- speechItem, e := speechOb.GetItemById(speechId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "转写文件不存在,请刷新页面"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
- return
- }
- // 获取内容
- contents := make([]*speech_recognition.SpeechRecognitionContentItem, 0)
- {
- contentOb := new(speech_recognition.SpeechRecognitionContent)
- cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionContentCols.SpeechRecognitionId)
- pars := make([]interface{}, 0)
- pars = append(pars, speechId)
- list, e := contentOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf("%s ASC", speech_recognition.SpeechRecognitionContentCols.Sort))
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取语音识别内容失败, Err: " + e.Error()
- return
- }
- for _, v := range list {
- contents = append(contents, speech_recognition.FormatSpeechRecognitionContent2Item(v))
- }
- }
- // 获取标签
- tags, e := speech_recognition.GetSpeechRecognitionTagBySpeechId(speechId)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取语音识别标签失败, Err: " + e.Error()
- return
- }
- detail := speech_recognition.FormatSpeechRecognition2DetailItem(speechItem, contents, tags)
- br.Data = detail
- 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 = "操作成功"
- }
|