speech_recognition.go 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. package speech_recognition
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/speech_recognition"
  7. "eta/eta_api/services"
  8. "eta/eta_api/services/alarm_msg"
  9. "eta/eta_api/utils"
  10. "fmt"
  11. "github.com/rdlucklib/rdluck_tools/paging"
  12. "os"
  13. "sort"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. type SpeechRecognitionController struct {
  19. controllers.BaseAuthController
  20. }
  21. type SpeechRecognitionCommonController struct {
  22. controllers.BaseCommonController
  23. }
  24. // RecTaskCallback
  25. // @Title 语音识别回调
  26. // @Description 语音识别回调
  27. // @Param request body services.TencentRecTaskCallback true "type json string"
  28. // @Success 200 string "操作成功"
  29. // @router /rec_task/callback [post]
  30. func (this *SpeechRecognitionCommonController) RecTaskCallback() {
  31. // 此接口返回指定响应体
  32. br := new(services.TencentRecTaskCallbackResp)
  33. var errMsg string
  34. defer func() {
  35. if errMsg != "" {
  36. br.Code = 403
  37. br.Message = "回调失败"
  38. go alarm_msg.SendAlarmMsg(fmt.Sprintf("语音识别回调失败, ErrMsg: %s", errMsg), 1)
  39. } else {
  40. br.Code = 0
  41. br.Message = "success"
  42. }
  43. _ = this.JSON(br, false, false)
  44. }()
  45. code, _ := this.GetInt("code", -1)
  46. requestId, _ := this.GetInt("requestId", 0)
  47. detail := this.GetString("resultDetail")
  48. utils.FileLog.Info(fmt.Sprintf("RecTaskCallback, requestId: %d", requestId))
  49. // 获取taskId对应的API请求及语音识别
  50. logOb := new(speech_recognition.SpeechRecognitionApiLog)
  51. cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionApiLogCols.RequestId)
  52. pars := make([]interface{}, 0)
  53. pars = append(pars, requestId)
  54. apiLog, e := logOb.GetItemByCondition(cond, pars, "")
  55. if e != nil {
  56. errMsg = "获取API记录失败"
  57. utils.FileLog.Info("API回调-获取请求记录失败, Err: " + e.Error())
  58. return
  59. }
  60. speechOb := new(speech_recognition.SpeechRecognition)
  61. speechItem, e := speechOb.GetItemById(apiLog.SpeechRecognitionId)
  62. if e != nil {
  63. errMsg = "获取语音识别失败"
  64. utils.FileLog.Info("获取语音识别失败, Err: " + e.Error())
  65. return
  66. }
  67. // API结果返回有误
  68. nowTime := time.Now().Local()
  69. if code != speech_recognition.ApiRequestCodeSuccess {
  70. convertRemark := speech_recognition.ApiErrMsgMapping[code]
  71. if convertRemark == "" {
  72. convertRemark = fmt.Sprintf("未知错误: %d", code)
  73. }
  74. speechItem.ConvertRemark = convertRemark
  75. speechItem.State = speech_recognition.SpeechRecognitionStateFail
  76. speechItem.ModifyTime = nowTime
  77. speechCols := []string{speech_recognition.SpeechRecognitionCols.ConvertRemark, speech_recognition.SpeechRecognitionCols.State, speech_recognition.SpeechRecognitionCols.ModifyTime}
  78. apiLog.RequestCode = code
  79. apiLog.RequestResult = convertRemark
  80. apiLog.ModifyTime = nowTime
  81. apiLogCols := []string{speech_recognition.SpeechRecognitionApiLogCols.RequestCode, speech_recognition.SpeechRecognitionApiLogCols.RequestResult, speech_recognition.SpeechRecognitionApiLogCols.ModifyTime}
  82. // 更新语音识别及API记录
  83. if e := speech_recognition.UpdateSpeechAndApiLog(speechItem, speechCols, apiLog, apiLogCols); e != nil {
  84. errMsg = "更新API返回结果失败"
  85. utils.FileLog.Info("更新API返回结果失败, Err: " + e.Error())
  86. }
  87. return
  88. }
  89. // 解析转写段落内容
  90. sentences := make([]*services.TencentRecTaskSentenceDetail, 0)
  91. if e := json.Unmarshal([]byte(detail), &sentences); e != nil {
  92. errMsg = "解析语音识别内容失败"
  93. utils.FileLog.Info("解析语音识别内容失败, Err: " + e.Error())
  94. return
  95. }
  96. contents := make([]*speech_recognition.SpeechRecognitionContent, 0)
  97. sorts := 0 // API返回的结果本身是已排过序的
  98. var abstract string
  99. var abstractLimit int
  100. for _, v := range sentences {
  101. sorts += 1
  102. t := new(speech_recognition.SpeechRecognitionContent)
  103. t.SpeechRecognitionId = speechItem.SpeechRecognitionId
  104. t.Sort = sorts
  105. t.Content = v.FinalSentence
  106. t.StartMs = v.StartMs
  107. t.EndMs = v.EndMs
  108. t.CreateTime = nowTime
  109. t.ModifyTime = nowTime
  110. contents = append(contents, t)
  111. // 取前几段作为摘要保存
  112. if abstractLimit < 5 {
  113. abstractLimit += 1
  114. abstract += v.FinalSentence
  115. }
  116. }
  117. speechItem.Abstract = abstract
  118. speechItem.State = speech_recognition.SpeechRecognitionStateSuccess
  119. speechItem.ModifyTime = nowTime
  120. speechCols := []string{speech_recognition.SpeechRecognitionCols.Abstract, speech_recognition.SpeechRecognitionCols.State, speech_recognition.SpeechRecognitionCols.ModifyTime}
  121. apiLog.RequestCode = code
  122. apiLog.RequestResult = detail
  123. apiLog.ModifyTime = time.Now().Local()
  124. apiLogCols := []string{speech_recognition.SpeechRecognitionApiLogCols.RequestCode, speech_recognition.SpeechRecognitionApiLogCols.RequestResult, speech_recognition.SpeechRecognitionApiLogCols.ModifyTime}
  125. // 新增解析内容并更新语音识别及API记录
  126. if e := speech_recognition.CreateContentAndUpdateSpeechAndApiLog(contents, speechItem, speechCols, apiLog, apiLogCols); e != nil {
  127. errMsg = "新增API返回结果失败"
  128. utils.FileLog.Info("新增API返回结果失败, Err: " + e.Error())
  129. }
  130. }
  131. // Convert
  132. // @Title 语音转换
  133. // @Description 语音转换
  134. // @Param request body speech_recognition.SpeechRecognitionConvertReq true "type json string"
  135. // @Success 200 string "操作成功"
  136. // @router /convert [post]
  137. func (this *SpeechRecognitionController) Convert() {
  138. br := new(models.BaseResponse).Init()
  139. defer func() {
  140. if br.ErrMsg == "" {
  141. br.IsSendEmail = false
  142. }
  143. this.Data["json"] = br
  144. this.ServeJSON()
  145. }()
  146. sysUser := this.SysUser
  147. if sysUser == nil {
  148. br.Msg = "请登录"
  149. br.ErrMsg = "请登录,SysUser Is Empty"
  150. br.Ret = 408
  151. return
  152. }
  153. var req speech_recognition.SpeechRecognitionConvertReq
  154. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  155. br.Msg = "参数有误"
  156. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  157. return
  158. }
  159. if req.MenuId <= 0 {
  160. br.Msg = "请选择目录"
  161. return
  162. }
  163. if len(req.Files) == 0 {
  164. br.Msg = "请上传转写文件"
  165. return
  166. }
  167. for _, r := range req.Files {
  168. if r.FileName == "" && r.ResourceUrl == "" {
  169. br.Msg = "转写文件有误,请检查"
  170. return
  171. }
  172. }
  173. sortMax, e := services.GetSpeechMenuMaxSort(req.MenuId)
  174. if e != nil {
  175. br.Msg = "操作失败"
  176. br.ErrMsg = "获取语音识别目录下最大排序失败, Err: " + e.Error()
  177. return
  178. }
  179. speeches := make([]*speech_recognition.SpeechRecognition, 0)
  180. nowTime := time.Now().Local()
  181. for _, v := range req.Files {
  182. sortMax += 1
  183. t := new(speech_recognition.SpeechRecognition)
  184. t.FileName = v.FileName
  185. t.ResourceUrl = v.ResourceUrl
  186. t.MenuId = req.MenuId
  187. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  188. t.UniqueCode = utils.MD5(fmt.Sprintf("%s_%s", t.TableName(), timestamp))
  189. t.SysUserId = sysUser.AdminId
  190. t.SysUserName = sysUser.RealName
  191. t.State = speech_recognition.SpeechRecognitionStateWait
  192. t.Sort = sortMax
  193. t.FileSecond = v.FileSecond
  194. t.FileSize = v.FileSize
  195. t.CreateTime = nowTime
  196. t.ModifyTime = nowTime
  197. // CreateMulti拿不到主键, 此处用循环新增获取
  198. if e := t.Create(); e != nil {
  199. br.Msg = "操作失败"
  200. br.ErrMsg = "批量新增转写文件失败, Err: " + e.Error()
  201. return
  202. }
  203. speeches = append(speeches, t)
  204. }
  205. // 批量转写语音
  206. go func() {
  207. services.BatchConvertSpeech(speeches)
  208. }()
  209. br.Ret = 200
  210. br.Success = true
  211. br.Msg = "操作成功"
  212. }
  213. // ConvertList
  214. // @Title 转换列表
  215. // @Description 转换列表
  216. // @Success 200 {object} speech_recognition.SpeechRecognitionItem
  217. // @router /convert_list [get]
  218. func (this *SpeechRecognitionController) ConvertList() {
  219. br := new(models.BaseResponse).Init()
  220. defer func() {
  221. if br.ErrMsg == "" {
  222. br.IsSendEmail = false
  223. }
  224. this.Data["json"] = br
  225. this.ServeJSON()
  226. }()
  227. sysUser := this.SysUser
  228. if sysUser == nil {
  229. br.Msg = "请登录"
  230. br.ErrMsg = "请登录,SysUser Is Empty"
  231. br.Ret = 408
  232. return
  233. }
  234. // 仅取待转换和转换失败的
  235. states := []int{speech_recognition.SpeechRecognitionStateWait, speech_recognition.SpeechRecognitionStateFail}
  236. speechOb := new(speech_recognition.SpeechRecognition)
  237. cond := fmt.Sprintf(` AND %s = ? AND %s IN (%s)`, speech_recognition.SpeechRecognitionCols.SysUserId, speech_recognition.SpeechRecognitionCols.State, utils.GetOrmInReplace(len(states)))
  238. pars := make([]interface{}, 0)
  239. pars = append(pars, sysUser.AdminId, states)
  240. list, e := speechOb.GetItemsByCondition(cond, pars, []string{}, "")
  241. if e != nil {
  242. br.Msg = "获取失败"
  243. br.ErrMsg = "获取转写文件列表失败, Err: " + e.Error()
  244. return
  245. }
  246. resp := make([]*speech_recognition.SpeechRecognitionItem, 0)
  247. for _, v := range list {
  248. resp = append(resp, speech_recognition.FormatSpeechRecognition2Item(v))
  249. }
  250. br.Data = resp
  251. br.Ret = 200
  252. br.Success = true
  253. br.Msg = "获取成功"
  254. }
  255. // Save
  256. // @Title 保存内容
  257. // @Description 保存内容
  258. // @Param request body speech_recognition.SpeechRecognitionSaveReq true "type json string"
  259. // @Success 200 string "操作成功"
  260. // @router /save [post]
  261. func (this *SpeechRecognitionController) Save() {
  262. br := new(models.BaseResponse).Init()
  263. defer func() {
  264. if br.ErrMsg == "" {
  265. br.IsSendEmail = false
  266. }
  267. this.Data["json"] = br
  268. this.ServeJSON()
  269. }()
  270. sysUser := this.SysUser
  271. if sysUser == nil {
  272. br.Msg = "请登录"
  273. br.ErrMsg = "请登录,SysUser Is Empty"
  274. br.Ret = 408
  275. return
  276. }
  277. var req speech_recognition.SpeechRecognitionSaveReq
  278. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  279. br.Msg = "参数有误"
  280. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  281. return
  282. }
  283. if req.SpeechRecognitionId <= 0 {
  284. br.Msg = "参数有误"
  285. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
  286. return
  287. }
  288. if len(req.Contents) == 0 {
  289. br.Ret = 200
  290. br.Success = true
  291. br.Msg = "操作成功"
  292. return
  293. }
  294. req.FileName = strings.TrimSpace(req.FileName)
  295. if req.FileName == "" {
  296. br.Msg = "请输入文件名称"
  297. return
  298. }
  299. speechOb := new(speech_recognition.SpeechRecognition)
  300. speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
  301. if e != nil {
  302. if e.Error() == utils.ErrNoRow() {
  303. br.Msg = "转写文件不存在,请刷新页面"
  304. return
  305. }
  306. br.Msg = "操作失败"
  307. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  308. return
  309. }
  310. if req.FileName != speechItem.FileName {
  311. // 校验重名
  312. {
  313. cond := fmt.Sprintf(` AND %s = ? AND %s <> ?`, speech_recognition.SpeechRecognitionCols.FileName, speech_recognition.SpeechRecognitionCols.SpeechRecognitionId)
  314. pars := make([]interface{}, 0)
  315. pars = append(pars, req.FileName, req.SpeechRecognitionId)
  316. exists, e := speechOb.GetItemByCondition(cond, pars, "")
  317. if e != nil && e.Error() != utils.ErrNoRow() {
  318. br.Msg = "操作失败"
  319. br.ErrMsg = "获取同名转写文件失败, Err: " + e.Error()
  320. return
  321. }
  322. if exists != nil && exists.SpeechRecognitionId > 0 {
  323. br.Msg = "文件名称已存在,请重新输入"
  324. return
  325. }
  326. }
  327. speechItem.FileName = req.FileName
  328. speechItem.ModifyTime = time.Now().Local()
  329. updateCols := []string{speech_recognition.SpeechRecognitionCols.FileName, speech_recognition.SpeechRecognitionCols.ModifyTime}
  330. if e = speechItem.Update(updateCols); e != nil {
  331. br.Msg = "操作失败"
  332. br.ErrMsg = "更新转写文件名称失败, Err: " + e.Error()
  333. return
  334. }
  335. }
  336. // 批量修改内容
  337. contentOb := new(speech_recognition.SpeechRecognitionContent)
  338. if e = contentOb.BatchUpdateContents(req.Contents); e != nil {
  339. br.Msg = "操作失败"
  340. br.ErrMsg = "批量修改内容失败, Err: " + e.Error()
  341. return
  342. }
  343. // 更新标签
  344. mappingOb := new(speech_recognition.SpeechRecognitionTagMapping)
  345. if e = mappingOb.ClearMappingBySpeechId(req.SpeechRecognitionId); e != nil {
  346. br.Msg = "操作失败"
  347. br.ErrMsg = "清除语音识别标签失败, Err: " + e.Error()
  348. return
  349. }
  350. tagMappings := make([]*speech_recognition.SpeechRecognitionTagMapping, 0)
  351. for _, v := range req.TagIds {
  352. tagMappings = append(tagMappings, &speech_recognition.SpeechRecognitionTagMapping{
  353. SpeechRecognitionId: req.SpeechRecognitionId,
  354. TagId: v,
  355. })
  356. }
  357. if e = mappingOb.CreateMulti(tagMappings); e != nil {
  358. br.Msg = "操作失败"
  359. br.ErrMsg = "批量新增语音识别标签失败, Err: " + e.Error()
  360. return
  361. }
  362. br.Ret = 200
  363. br.Success = true
  364. br.Msg = "操作成功"
  365. }
  366. // RemoveFile
  367. // @Title (软)删除文件
  368. // @Description (软)删除文件
  369. // @Param request body speech_recognition.SpeechRecognitionRemoveFileReq true "type json string"
  370. // @Success 200 string "操作成功"
  371. // @router /remove_file [post]
  372. func (this *SpeechRecognitionController) RemoveFile() {
  373. br := new(models.BaseResponse).Init()
  374. defer func() {
  375. if br.ErrMsg == "" {
  376. br.IsSendEmail = false
  377. }
  378. this.Data["json"] = br
  379. this.ServeJSON()
  380. }()
  381. sysUser := this.SysUser
  382. if sysUser == nil {
  383. br.Msg = "请登录"
  384. br.ErrMsg = "请登录,SysUser Is Empty"
  385. br.Ret = 408
  386. return
  387. }
  388. var req speech_recognition.SpeechRecognitionRemoveFileReq
  389. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  390. br.Msg = "参数有误"
  391. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  392. return
  393. }
  394. if req.SpeechRecognitionId <= 0 {
  395. br.Msg = "参数有误"
  396. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
  397. return
  398. }
  399. speechOb := new(speech_recognition.SpeechRecognition)
  400. speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
  401. if e != nil {
  402. if e.Error() == utils.ErrNoRow() {
  403. br.Msg = "转写文件不存在,请刷新页面"
  404. return
  405. }
  406. br.Msg = "操作失败"
  407. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  408. return
  409. }
  410. speechItem.FileState = speech_recognition.SpeechRecognitionFileRemoveFlag
  411. speechItem.ModifyTime = time.Now().Local()
  412. updateCols := []string{speech_recognition.SpeechRecognitionCols.FileState, speech_recognition.SpeechRecognitionCols.ModifyTime}
  413. if e = speechItem.Update(updateCols); e != nil {
  414. br.Msg = "操作失败"
  415. br.ErrMsg = "软删除转写文件失败, Err: " + e.Error()
  416. return
  417. }
  418. br.Ret = 200
  419. br.Success = true
  420. br.Msg = "操作成功"
  421. }
  422. // Rename
  423. // @Title 重命名
  424. // @Description 重命名
  425. // @Param request body speech_recognition.SpeechRecognitionRenameReq true "type json string"
  426. // @Success 200 string "操作成功"
  427. // @router /rename [post]
  428. func (this *SpeechRecognitionController) Rename() {
  429. br := new(models.BaseResponse).Init()
  430. defer func() {
  431. if br.ErrMsg == "" {
  432. br.IsSendEmail = false
  433. }
  434. this.Data["json"] = br
  435. this.ServeJSON()
  436. }()
  437. sysUser := this.SysUser
  438. if sysUser == nil {
  439. br.Msg = "请登录"
  440. br.ErrMsg = "请登录,SysUser Is Empty"
  441. br.Ret = 408
  442. return
  443. }
  444. var req speech_recognition.SpeechRecognitionRenameReq
  445. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  446. br.Msg = "参数有误"
  447. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  448. return
  449. }
  450. if req.SpeechRecognitionId <= 0 {
  451. br.Msg = "参数有误"
  452. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
  453. return
  454. }
  455. req.FileName = strings.TrimSpace(req.FileName)
  456. if req.FileName == "" {
  457. br.Msg = "请输入文件名称"
  458. return
  459. }
  460. speechOb := new(speech_recognition.SpeechRecognition)
  461. speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
  462. if e != nil {
  463. if e.Error() == utils.ErrNoRow() {
  464. br.Msg = "转写文件不存在,请刷新页面"
  465. return
  466. }
  467. br.Msg = "操作失败"
  468. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  469. return
  470. }
  471. // 重名校验
  472. {
  473. cond := fmt.Sprintf(` AND %s = ? AND %s <> ?`, speech_recognition.SpeechRecognitionCols.FileName, speech_recognition.SpeechRecognitionCols.SpeechRecognitionId)
  474. pars := make([]interface{}, 0)
  475. pars = append(pars, req.FileName, req.SpeechRecognitionId)
  476. exists, e := speechOb.GetItemByCondition(cond, pars, "")
  477. if e != nil && e.Error() != utils.ErrNoRow() {
  478. br.Msg = "操作失败"
  479. br.ErrMsg = "获取同名转写文件失败, Err: " + e.Error()
  480. return
  481. }
  482. if exists != nil && exists.SpeechRecognitionId > 0 {
  483. br.Msg = "文件名称已存在,请重新输入"
  484. return
  485. }
  486. }
  487. speechItem.FileName = req.FileName
  488. speechItem.ModifyTime = time.Now().Local()
  489. updateCols := []string{speech_recognition.SpeechRecognitionCols.FileName, speech_recognition.SpeechRecognitionCols.ModifyTime}
  490. if e = speechItem.Update(updateCols); e != nil {
  491. br.Msg = "操作失败"
  492. br.ErrMsg = "转写文件重命名失败, Err: " + e.Error()
  493. return
  494. }
  495. br.Ret = 200
  496. br.Success = true
  497. br.Msg = "操作成功"
  498. }
  499. // Remove
  500. // @Title 删除
  501. // @Description 删除
  502. // @Param request body speech_recognition.SpeechRecognitionRemoveReq true "type json string"
  503. // @Success 200 string "操作成功"
  504. // @router /remove [post]
  505. func (this *SpeechRecognitionController) Remove() {
  506. br := new(models.BaseResponse).Init()
  507. defer func() {
  508. if br.ErrMsg == "" {
  509. br.IsSendEmail = false
  510. }
  511. this.Data["json"] = br
  512. this.ServeJSON()
  513. }()
  514. sysUser := this.SysUser
  515. if sysUser == nil {
  516. br.Msg = "请登录"
  517. br.ErrMsg = "请登录,SysUser Is Empty"
  518. br.Ret = 408
  519. return
  520. }
  521. var req speech_recognition.SpeechRecognitionRemoveReq
  522. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  523. br.Msg = "参数有误"
  524. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  525. return
  526. }
  527. if req.SpeechRecognitionId <= 0 {
  528. br.Msg = "参数有误"
  529. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
  530. return
  531. }
  532. speechOb := new(speech_recognition.SpeechRecognition)
  533. speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
  534. if e != nil {
  535. if e.Error() == utils.ErrNoRow() {
  536. br.Ret = 200
  537. br.Success = true
  538. br.Msg = "操作成功"
  539. return
  540. }
  541. br.Msg = "操作失败"
  542. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  543. return
  544. }
  545. if e = speechItem.Del(); e != nil {
  546. br.Msg = "操作失败"
  547. br.ErrMsg = "删除转写文件失败, Err: " + e.Error()
  548. return
  549. }
  550. // 清除关联
  551. go func() {
  552. contentOb := new(speech_recognition.SpeechRecognitionContent)
  553. _ = contentOb.ClearContentBySpeechId(req.SpeechRecognitionId)
  554. mappingOb := new(speech_recognition.SpeechRecognitionTagMapping)
  555. _ = mappingOb.ClearMappingBySpeechId(req.SpeechRecognitionId)
  556. }()
  557. br.Ret = 200
  558. br.Success = true
  559. br.Msg = "操作成功"
  560. }
  561. // SaveTag
  562. // @Title 保存标签
  563. // @Description 保存标签
  564. // @Param request body speech_recognition.SpeechRecognitionSaveTagReq true "type json string"
  565. // @Success 200 string "操作成功"
  566. // @router /save_tag [post]
  567. func (this *SpeechRecognitionController) SaveTag() {
  568. br := new(models.BaseResponse).Init()
  569. defer func() {
  570. if br.ErrMsg == "" {
  571. br.IsSendEmail = false
  572. }
  573. this.Data["json"] = br
  574. this.ServeJSON()
  575. }()
  576. sysUser := this.SysUser
  577. if sysUser == nil {
  578. br.Msg = "请登录"
  579. br.ErrMsg = "请登录,SysUser Is Empty"
  580. br.Ret = 408
  581. return
  582. }
  583. var req speech_recognition.SpeechRecognitionSaveTagReq
  584. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  585. br.Msg = "参数有误"
  586. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  587. return
  588. }
  589. if req.SpeechRecognitionId <= 0 {
  590. br.Msg = "参数有误"
  591. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
  592. return
  593. }
  594. speechOb := new(speech_recognition.SpeechRecognition)
  595. _, e := speechOb.GetItemById(req.SpeechRecognitionId)
  596. if e != nil {
  597. if e.Error() == utils.ErrNoRow() {
  598. br.Msg = "转写文件不存在,请刷新页面"
  599. return
  600. }
  601. br.Msg = "操作失败"
  602. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  603. return
  604. }
  605. // 清除原标签
  606. mappingOb := new(speech_recognition.SpeechRecognitionTagMapping)
  607. if e = mappingOb.ClearMappingBySpeechId(req.SpeechRecognitionId); e != nil {
  608. br.Msg = "操作失败"
  609. br.ErrMsg = "清除转写文件标签失败, Err: " + e.Error()
  610. return
  611. }
  612. // 保存新标签
  613. if len(req.TagIds) > 0 {
  614. mappings := make([]*speech_recognition.SpeechRecognitionTagMapping, 0)
  615. for _, v := range req.TagIds {
  616. if v <= 0 {
  617. continue
  618. }
  619. mappings = append(mappings, &speech_recognition.SpeechRecognitionTagMapping{
  620. TagId: v,
  621. SpeechRecognitionId: req.SpeechRecognitionId,
  622. })
  623. }
  624. if e = mappingOb.CreateMulti(mappings); e != nil {
  625. br.Msg = "操作失败"
  626. br.ErrMsg = "批量新增转写文件标签失败, Err: " + e.Error()
  627. return
  628. }
  629. }
  630. br.Ret = 200
  631. br.Success = true
  632. br.Msg = "操作成功"
  633. }
  634. // List
  635. // @Title 语音识别列表
  636. // @Description 语音识别列表
  637. // @Param FileName query string false "文件名称"
  638. // @Param StartTime query string false "开始时间"
  639. // @Param EndTime query string false "结束时间"
  640. // @Param CreateUserIds query string false "创建人ID"
  641. // @Param TagId query int false "标签ID"
  642. // @Param TagIds query string false "标签ID"
  643. // @Param MenuId query int false "目录ID"
  644. // @Param IsTagMenu query bool false "是否为标签目录"
  645. // @Success 200 {object} speech_recognition.SpeechRecognitionListResp
  646. // @router /list [get]
  647. func (this *SpeechRecognitionController) List() {
  648. br := new(models.BaseResponse).Init()
  649. defer func() {
  650. if br.ErrMsg == "" {
  651. br.IsSendEmail = false
  652. }
  653. this.Data["json"] = br
  654. this.ServeJSON()
  655. }()
  656. sysUser := this.SysUser
  657. if sysUser == nil {
  658. br.Msg = "请登录"
  659. br.ErrMsg = "请登录,SysUser Is Empty"
  660. br.Ret = 408
  661. return
  662. }
  663. params := new(speech_recognition.SpeechRecognitionListReq)
  664. if e := this.ParseForm(params); e != nil {
  665. br.Msg = "获取失败"
  666. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  667. return
  668. }
  669. params.FileName = strings.TrimSpace(params.FileName)
  670. dataResp := new(speech_recognition.SpeechRecognitionListResp)
  671. cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionCols.State)
  672. pars := make([]interface{}, 0)
  673. pars = append(pars, speech_recognition.SpeechRecognitionStateSuccess)
  674. // 筛选项
  675. {
  676. if params.FileName != "" {
  677. cond += fmt.Sprintf(` AND %s LIKE ?`, speech_recognition.SpeechRecognitionCols.FileName)
  678. pars = append(pars, fmt.Sprint("%", params.FileName, "%"))
  679. }
  680. if params.StartTime != "" && params.EndTime != "" {
  681. _, e := time.Parse(utils.FormatDate, params.StartTime)
  682. if e != nil {
  683. br.Msg = "开始时间格式有误"
  684. return
  685. }
  686. _, e = time.Parse(utils.FormatDate, params.EndTime)
  687. if e != nil {
  688. br.Msg = "结束时间格式有误"
  689. return
  690. }
  691. st := fmt.Sprintf("%s 00:00:00", params.StartTime)
  692. ed := fmt.Sprintf("%s 23:59:59", params.EndTime)
  693. cond += fmt.Sprintf(` AND (%s BETWEEN ? AND ?)`, speech_recognition.SpeechRecognitionCols.CreateTime)
  694. pars = append(pars, st, ed)
  695. }
  696. if params.CreateUserId != "" {
  697. userArr := strings.Split(strings.TrimSpace(params.CreateUserId), ",")
  698. if len(userArr) > 0 {
  699. userIds := make([]int, 0)
  700. for _, v := range userArr {
  701. t, _ := strconv.Atoi(v)
  702. userIds = append(userIds, t)
  703. }
  704. if len(userIds) == 0 {
  705. br.Data = dataResp
  706. br.Ret = 200
  707. br.Success = true
  708. br.Msg = "获取成功"
  709. return
  710. }
  711. cond += fmt.Sprintf(` AND %s IN (%s)`, speech_recognition.SpeechRecognitionCols.SysUserId, utils.GetOrmInReplace(len(userIds)))
  712. pars = append(pars, userIds)
  713. }
  714. }
  715. // 语音识别目录-筛选子目录集合
  716. if params.MenuId > 0 && !params.IsTagMenu {
  717. {
  718. menuOb := new(speech_recognition.SpeechRecognitionMenu)
  719. menus, e := menuOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  720. if e != nil {
  721. br.Msg = "获取失败"
  722. br.ErrMsg = "获取语音识别目录列表失败, Err: " + e.Error()
  723. return
  724. }
  725. childIds := services.GetSpeechRecognitionMenuChildrenRecursive(menus, params.MenuId)
  726. menuIds := make([]int, 0)
  727. menuIds = append(menuIds, params.MenuId)
  728. if len(childIds) > 0 {
  729. menuIds = append(menuIds, childIds...)
  730. }
  731. cond += fmt.Sprintf(` AND %s IN (%s)`, speech_recognition.SpeechRecognitionCols.MenuId, utils.GetOrmInReplace(len(menuIds)))
  732. pars = append(pars, menuIds)
  733. }
  734. }
  735. // 标签目录-筛选目录下所有标签
  736. tagIds := make([]int, 0)
  737. if params.MenuId > 0 && params.IsTagMenu {
  738. {
  739. menuOb := new(speech_recognition.SpeechRecognitionTagMenu)
  740. menus, e := menuOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  741. if e != nil {
  742. br.Msg = "获取失败"
  743. br.ErrMsg = "获取标签目录列表失败, Err: " + e.Error()
  744. return
  745. }
  746. childIds := services.GetSpeechRecognitionTagMenuChildrenRecursive(menus, params.MenuId)
  747. menuIds := make([]int, 0)
  748. menuIds = append(menuIds, params.MenuId)
  749. if len(childIds) > 0 {
  750. menuIds = append(menuIds, childIds...)
  751. }
  752. // 获取目录下所有标签
  753. tagOb := new(speech_recognition.SpeechRecognitionTag)
  754. ids, e := tagOb.GetTagIdsByMenuIds(menuIds)
  755. if e != nil {
  756. br.Msg = "获取失败"
  757. br.ErrMsg = "通过目录IDs获取标签IDs失败, Err: " + e.Error()
  758. return
  759. }
  760. // 此处查询无结果直接返回
  761. if len(ids) == 0 {
  762. br.Data = dataResp
  763. br.Ret = 200
  764. br.Success = true
  765. br.Msg = "获取成功"
  766. return
  767. }
  768. tagIds = ids
  769. }
  770. }
  771. // 标签筛选
  772. if params.TagId > 0 && params.TagIds == "" {
  773. tagIds = append(tagIds, params.TagId)
  774. }
  775. if params.TagId <= 0 && params.TagIds != "" {
  776. tagArr := strings.Split(params.TagIds, ",")
  777. if len(tagArr) > 0 {
  778. for _, v := range tagArr {
  779. t, _ := strconv.Atoi(v)
  780. tagIds = append(tagIds, t)
  781. }
  782. }
  783. }
  784. if len(tagIds) > 0 {
  785. mappingOb := new(speech_recognition.SpeechRecognitionTagMapping)
  786. tagSpeechIds, e := mappingOb.GetSpeechIdsByTagIds(tagIds)
  787. if e != nil {
  788. br.Msg = "获取失败"
  789. br.ErrMsg = "获取标签关联语音识别失败, Err: " + e.Error()
  790. return
  791. }
  792. if len(tagSpeechIds) == 0 {
  793. br.Data = dataResp
  794. br.Ret = 200
  795. br.Success = true
  796. br.Msg = "获取成功"
  797. return
  798. }
  799. cond += fmt.Sprintf(` AND %s IN (%s)`, speech_recognition.SpeechRecognitionCols.SpeechRecognitionId, utils.GetOrmInReplace(len(tagSpeechIds)))
  800. pars = append(pars, tagSpeechIds)
  801. }
  802. }
  803. // 分页列表
  804. speechOb := new(speech_recognition.SpeechRecognition)
  805. total, e := speechOb.GetCountByCondition(cond, pars)
  806. if e != nil {
  807. br.Msg = "获取失败"
  808. br.ErrMsg = "获取语音识别列表总数失败, Err: " + e.Error()
  809. return
  810. }
  811. var startSize int
  812. if params.PageSize <= 0 {
  813. params.PageSize = utils.PageSize20
  814. }
  815. if params.CurrentIndex <= 0 {
  816. params.CurrentIndex = 1
  817. }
  818. startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
  819. list, e := speechOb.GetPageItemsByCondition(cond, pars, []string{}, "", startSize, params.PageSize)
  820. if e != nil {
  821. br.Msg = "获取失败"
  822. br.ErrMsg = "获取语音识别列表失败, Err: " + e.Error()
  823. return
  824. }
  825. // 获取标签
  826. speechIds := make([]int, 0)
  827. for _, v := range list {
  828. speechIds = append(speechIds, v.SpeechRecognitionId)
  829. }
  830. mappingTags, e := speech_recognition.GetSpeechRecognitionTagsBySpeechIds(speechIds)
  831. if e != nil {
  832. br.Msg = "获取失败"
  833. br.ErrMsg = "获取语音识别列表标签失败, Err: " + e.Error()
  834. return
  835. }
  836. speechDetailTags := make(map[int][]*speech_recognition.SpeechRecognitionDetailTag)
  837. for _, v := range mappingTags {
  838. if speechDetailTags[v.SpeechRecognitionId] == nil {
  839. speechDetailTags[v.SpeechRecognitionId] = make([]*speech_recognition.SpeechRecognitionDetailTag, 0)
  840. }
  841. speechDetailTags[v.SpeechRecognitionId] = append(speechDetailTags[v.SpeechRecognitionId], &speech_recognition.SpeechRecognitionDetailTag{
  842. TagId: v.TagId,
  843. TagName: v.TagName,
  844. })
  845. }
  846. respList := make([]*speech_recognition.SpeechRecognitionDetailItem, 0)
  847. for _, v := range list {
  848. t := speech_recognition.FormatSpeechRecognition2DetailItem(v, make([]*speech_recognition.SpeechRecognitionContentItem, 0), speechDetailTags[v.SpeechRecognitionId], make([]*speech_recognition.SpeechRecognitionMenuItem, 0))
  849. respList = append(respList, t)
  850. }
  851. page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
  852. dataResp.Paging = page
  853. dataResp.List = respList
  854. br.Data = dataResp
  855. br.Ret = 200
  856. br.Success = true
  857. br.Msg = "获取成功"
  858. }
  859. // Detail
  860. // @Title 语音识别详情
  861. // @Description 语音识别详情
  862. // @Param SpeechRecognitionId query int true "语音识别ID"
  863. // @Success 200 {object} speech_recognition.SpeechRecognitionDetailItem
  864. // @router /detail [get]
  865. func (this *SpeechRecognitionController) Detail() {
  866. br := new(models.BaseResponse).Init()
  867. defer func() {
  868. if br.ErrMsg == "" {
  869. br.IsSendEmail = false
  870. }
  871. this.Data["json"] = br
  872. this.ServeJSON()
  873. }()
  874. sysUser := this.SysUser
  875. if sysUser == nil {
  876. br.Msg = "请登录"
  877. br.ErrMsg = "请登录,SysUser Is Empty"
  878. br.Ret = 408
  879. return
  880. }
  881. speechId, _ := this.GetInt("SpeechRecognitionId")
  882. if speechId <= 0 {
  883. br.Msg = "参数有误"
  884. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", speechId)
  885. return
  886. }
  887. speechOb := new(speech_recognition.SpeechRecognition)
  888. speechItem, e := speechOb.GetItemById(speechId)
  889. if e != nil {
  890. if e.Error() == utils.ErrNoRow() {
  891. br.Msg = "转写文件不存在,请刷新页面"
  892. return
  893. }
  894. br.Msg = "获取失败"
  895. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  896. return
  897. }
  898. // 获取内容
  899. contents := make([]*speech_recognition.SpeechRecognitionContentItem, 0)
  900. {
  901. contentOb := new(speech_recognition.SpeechRecognitionContent)
  902. cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionContentCols.SpeechRecognitionId)
  903. pars := make([]interface{}, 0)
  904. pars = append(pars, speechId)
  905. list, e := contentOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf("%s ASC", speech_recognition.SpeechRecognitionContentCols.Sort))
  906. if e != nil {
  907. br.Msg = "获取失败"
  908. br.ErrMsg = "获取语音识别内容失败, Err: " + e.Error()
  909. return
  910. }
  911. for _, v := range list {
  912. if v.Content == "" {
  913. continue
  914. }
  915. contents = append(contents, speech_recognition.FormatSpeechRecognitionContent2Item(v))
  916. }
  917. }
  918. // 跟踪目录路径
  919. menuPath := make([]*speech_recognition.SpeechRecognitionMenuItem, 0)
  920. {
  921. menuOb := new(speech_recognition.SpeechRecognitionMenu)
  922. menus, e := menuOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, fmt.Sprintf("%s ASC, %s ASC", speech_recognition.SpeechRecognitionMenuCols.ParentId, speech_recognition.SpeechRecognitionMenuCols.Sort))
  923. if e != nil {
  924. br.Msg = "获取失败"
  925. br.ErrMsg = "获取目录列表失败, Err: " + e.Error()
  926. return
  927. }
  928. menuPath = services.GetSpeechRecognitionMenuPathRecursive(menus, speechItem.MenuId)
  929. sort.Slice(menuPath, func(i, j int) bool {
  930. return menuPath[i].Level < menuPath[j].Level
  931. })
  932. }
  933. // 获取标签
  934. tags, e := speech_recognition.GetSpeechRecognitionTagBySpeechId(speechId)
  935. if e != nil {
  936. br.Msg = "获取失败"
  937. br.ErrMsg = "获取语音识别标签失败, Err: " + e.Error()
  938. return
  939. }
  940. detail := speech_recognition.FormatSpeechRecognition2DetailItem(speechItem, contents, tags, menuPath)
  941. br.Data = detail
  942. br.Ret = 200
  943. br.Success = true
  944. br.Msg = "获取成功"
  945. }
  946. // Export
  947. // @Title 导出内容
  948. // @Description 导出内容
  949. // @Param request body speech_recognition.SpeechRecognitionContentExportReq true "type json string"
  950. // @Success 200 string "操作成功"
  951. // @router /export [get]
  952. func (this *SpeechRecognitionController) Export() {
  953. br := new(models.BaseResponse).Init()
  954. defer func() {
  955. if br.ErrMsg == "" {
  956. br.IsSendEmail = false
  957. }
  958. this.Data["json"] = br
  959. this.ServeJSON()
  960. }()
  961. sysUser := this.SysUser
  962. if sysUser == nil {
  963. br.Msg = "请登录"
  964. br.ErrMsg = "请登录,SysUser Is Empty"
  965. br.Ret = 408
  966. return
  967. }
  968. req := new(speech_recognition.SpeechRecognitionContentExportReq)
  969. if e := this.ParseForm(req); e != nil {
  970. br.Msg = "参数有误"
  971. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  972. return
  973. }
  974. if req.SpeechRecognitionId <= 0 {
  975. br.Msg = "参数有误"
  976. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
  977. return
  978. }
  979. speechOb := new(speech_recognition.SpeechRecognition)
  980. speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
  981. if e != nil {
  982. if e.Error() == utils.ErrNoRow() {
  983. br.Msg = "转写文件不存在,请刷新页面"
  984. return
  985. }
  986. br.Msg = "获取失败"
  987. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  988. return
  989. }
  990. contentOb := new(speech_recognition.SpeechRecognitionContent)
  991. cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionContentCols.SpeechRecognitionId)
  992. pars := make([]interface{}, 0)
  993. pars = append(pars, req.SpeechRecognitionId)
  994. contents, e := contentOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf("%s ASC", speech_recognition.SpeechRecognitionContentCols.Sort))
  995. if e != nil {
  996. br.Msg = "导出失败"
  997. br.ErrMsg = "获取语音识别内容失败, Err: " + e.Error()
  998. return
  999. }
  1000. if len(contents) == 0 {
  1001. br.Msg = "无内容导出"
  1002. return
  1003. }
  1004. if req.ExportType != services.SpeechRecognitionExportTypeTxt && req.ExportType != services.SpeechRecognitionExportTypeDocx && req.ExportType != services.SpeechRecognitionExportTypePdf {
  1005. br.Msg = "导出类型有误"
  1006. return
  1007. }
  1008. suffixMap := map[int]string{services.SpeechRecognitionExportTypeTxt: ".txt", services.SpeechRecognitionExportTypeDocx: ".docx", services.SpeechRecognitionExportTypePdf: ".pdf"}
  1009. suffix := suffixMap[req.ExportType]
  1010. if suffix == "" {
  1011. suffix = ".txt"
  1012. }
  1013. downloadPath, e := services.SpeechRecognitionContentExport(req.ExportType, req.Timestamp, speechItem.FileName, contents)
  1014. if e != nil {
  1015. br.Msg = "导出文件失败"
  1016. br.ErrMsg = "导出语音识别内容文件失败, Err: " + e.Error()
  1017. _ = os.Remove(downloadPath)
  1018. return
  1019. }
  1020. defer func() {
  1021. _ = os.Remove(downloadPath)
  1022. }()
  1023. downloadName := fmt.Sprintf("%s%s", speechItem.FileName, suffix)
  1024. this.Ctx.Output.Download(downloadPath, downloadName)
  1025. }
  1026. // CheckFileName
  1027. // @Title 文件重名校验
  1028. // @Description 文件重名校验
  1029. // @Param request body speech_recognition.SpeechRecognitionConvertCheckNameReq true "type json string"
  1030. // @Success 200 string "操作成功"
  1031. // @router /convert/check_name [post]
  1032. func (this *SpeechRecognitionController) CheckFileName() {
  1033. br := new(models.BaseResponse).Init()
  1034. defer func() {
  1035. if br.ErrMsg == "" {
  1036. br.IsSendEmail = false
  1037. }
  1038. this.Data["json"] = br
  1039. this.ServeJSON()
  1040. }()
  1041. sysUser := this.SysUser
  1042. if sysUser == nil {
  1043. br.Msg = "请登录"
  1044. br.ErrMsg = "请登录,SysUser Is Empty"
  1045. br.Ret = 408
  1046. return
  1047. }
  1048. var req speech_recognition.SpeechRecognitionConvertCheckNameReq
  1049. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1050. br.Msg = "参数有误"
  1051. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1052. return
  1053. }
  1054. req.FileName = strings.TrimSpace(req.FileName)
  1055. if req.FileName == "" {
  1056. br.Msg = "参数有误"
  1057. br.ErrMsg = fmt.Sprintf("参数有误, FileName: %s", req.FileName)
  1058. return
  1059. }
  1060. checkResult := true
  1061. speechOb := new(speech_recognition.SpeechRecognition)
  1062. cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionCols.FileName)
  1063. pars := make([]interface{}, 0)
  1064. pars = append(pars, req.FileName)
  1065. exists, e := speechOb.GetItemByCondition(cond, pars, "")
  1066. if e != nil && e.Error() != utils.ErrNoRow() {
  1067. br.Msg = "操作失败"
  1068. br.ErrMsg = "获取同名转写文件失败, Err: " + e.Error()
  1069. return
  1070. }
  1071. if exists != nil && exists.SpeechRecognitionId > 0 {
  1072. checkResult = false
  1073. br.Data = checkResult
  1074. br.Msg = fmt.Sprintf("相同文件名称已存在: %s", req.FileName)
  1075. return
  1076. }
  1077. br.Data = checkResult
  1078. br.Ret = 200
  1079. br.Success = true
  1080. br.Msg = "操作成功"
  1081. }