speech_recognition.go 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. package speech_recognition
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/controllers"
  5. "eta/eta_mobile/models"
  6. "eta/eta_mobile/models/speech_recognition"
  7. "eta/eta_mobile/services"
  8. "eta/eta_mobile/services/alarm_msg"
  9. "eta/eta_mobile/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. }
  328. // 取前几段作为摘要保存
  329. var abstractNum int
  330. var abstract string
  331. for _, v := range req.Contents {
  332. if abstractNum < 5 {
  333. abstractNum += 1
  334. abstract += v.Content
  335. }
  336. }
  337. speechItem.FileName = req.FileName
  338. speechItem.Abstract = abstract
  339. speechItem.ModifyTime = time.Now().Local()
  340. speechCols := []string{speech_recognition.SpeechRecognitionCols.FileName, speech_recognition.SpeechRecognitionCols.Abstract, speech_recognition.SpeechRecognitionCols.ModifyTime}
  341. // 标签
  342. tagMappings := make([]*speech_recognition.SpeechRecognitionTagMapping, 0)
  343. for _, v := range req.TagIds {
  344. tagMappings = append(tagMappings, &speech_recognition.SpeechRecognitionTagMapping{
  345. SpeechRecognitionId: req.SpeechRecognitionId,
  346. TagId: v,
  347. })
  348. }
  349. // 保存修改
  350. if e = speechOb.SpeechSave(speechItem, speechCols, req.Contents, tagMappings); e != nil {
  351. br.Msg = "操作失败"
  352. br.ErrMsg = "语音识别保存失败, Err: " + e.Error()
  353. return
  354. }
  355. br.Ret = 200
  356. br.Success = true
  357. br.Msg = "操作成功"
  358. }
  359. // RemoveFile
  360. // @Title (软)删除文件
  361. // @Description (软)删除文件
  362. // @Param request body speech_recognition.SpeechRecognitionRemoveFileReq true "type json string"
  363. // @Success 200 string "操作成功"
  364. // @router /remove_file [post]
  365. func (this *SpeechRecognitionController) RemoveFile() {
  366. br := new(models.BaseResponse).Init()
  367. defer func() {
  368. if br.ErrMsg == "" {
  369. br.IsSendEmail = false
  370. }
  371. this.Data["json"] = br
  372. this.ServeJSON()
  373. }()
  374. sysUser := this.SysUser
  375. if sysUser == nil {
  376. br.Msg = "请登录"
  377. br.ErrMsg = "请登录,SysUser Is Empty"
  378. br.Ret = 408
  379. return
  380. }
  381. var req speech_recognition.SpeechRecognitionRemoveFileReq
  382. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  383. br.Msg = "参数有误"
  384. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  385. return
  386. }
  387. if req.SpeechRecognitionId <= 0 {
  388. br.Msg = "参数有误"
  389. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
  390. return
  391. }
  392. speechOb := new(speech_recognition.SpeechRecognition)
  393. speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
  394. if e != nil {
  395. if e.Error() == utils.ErrNoRow() {
  396. br.Msg = "转写文件不存在,请刷新页面"
  397. return
  398. }
  399. br.Msg = "操作失败"
  400. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  401. return
  402. }
  403. speechItem.FileState = speech_recognition.SpeechRecognitionFileRemoveFlag
  404. speechItem.ModifyTime = time.Now().Local()
  405. updateCols := []string{speech_recognition.SpeechRecognitionCols.FileState, speech_recognition.SpeechRecognitionCols.ModifyTime}
  406. if e = speechItem.Update(updateCols); e != nil {
  407. br.Msg = "操作失败"
  408. br.ErrMsg = "软删除转写文件失败, Err: " + e.Error()
  409. return
  410. }
  411. br.Ret = 200
  412. br.Success = true
  413. br.Msg = "操作成功"
  414. }
  415. // Rename
  416. // @Title 重命名
  417. // @Description 重命名
  418. // @Param request body speech_recognition.SpeechRecognitionRenameReq true "type json string"
  419. // @Success 200 string "操作成功"
  420. // @router /rename [post]
  421. func (this *SpeechRecognitionController) Rename() {
  422. br := new(models.BaseResponse).Init()
  423. defer func() {
  424. if br.ErrMsg == "" {
  425. br.IsSendEmail = false
  426. }
  427. this.Data["json"] = br
  428. this.ServeJSON()
  429. }()
  430. sysUser := this.SysUser
  431. if sysUser == nil {
  432. br.Msg = "请登录"
  433. br.ErrMsg = "请登录,SysUser Is Empty"
  434. br.Ret = 408
  435. return
  436. }
  437. var req speech_recognition.SpeechRecognitionRenameReq
  438. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  439. br.Msg = "参数有误"
  440. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  441. return
  442. }
  443. if req.SpeechRecognitionId <= 0 {
  444. br.Msg = "参数有误"
  445. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
  446. return
  447. }
  448. req.FileName = strings.TrimSpace(req.FileName)
  449. if req.FileName == "" {
  450. br.Msg = "请输入文件名称"
  451. return
  452. }
  453. speechOb := new(speech_recognition.SpeechRecognition)
  454. speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
  455. if e != nil {
  456. if e.Error() == utils.ErrNoRow() {
  457. br.Msg = "转写文件不存在,请刷新页面"
  458. return
  459. }
  460. br.Msg = "操作失败"
  461. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  462. return
  463. }
  464. // 重名校验
  465. {
  466. cond := fmt.Sprintf(` AND %s = ? AND %s <> ?`, speech_recognition.SpeechRecognitionCols.FileName, speech_recognition.SpeechRecognitionCols.SpeechRecognitionId)
  467. pars := make([]interface{}, 0)
  468. pars = append(pars, req.FileName, req.SpeechRecognitionId)
  469. exists, e := speechOb.GetItemByCondition(cond, pars, "")
  470. if e != nil && e.Error() != utils.ErrNoRow() {
  471. br.Msg = "操作失败"
  472. br.ErrMsg = "获取同名转写文件失败, Err: " + e.Error()
  473. return
  474. }
  475. if exists != nil && exists.SpeechRecognitionId > 0 {
  476. br.Msg = "文件名称已存在,请重新输入"
  477. return
  478. }
  479. }
  480. speechItem.FileName = req.FileName
  481. speechItem.ModifyTime = time.Now().Local()
  482. updateCols := []string{speech_recognition.SpeechRecognitionCols.FileName, speech_recognition.SpeechRecognitionCols.ModifyTime}
  483. if e = speechItem.Update(updateCols); e != nil {
  484. br.Msg = "操作失败"
  485. br.ErrMsg = "转写文件重命名失败, Err: " + e.Error()
  486. return
  487. }
  488. br.Ret = 200
  489. br.Success = true
  490. br.Msg = "操作成功"
  491. }
  492. // Remove
  493. // @Title 删除
  494. // @Description 删除
  495. // @Param request body speech_recognition.SpeechRecognitionRemoveReq true "type json string"
  496. // @Success 200 string "操作成功"
  497. // @router /remove [post]
  498. func (this *SpeechRecognitionController) Remove() {
  499. br := new(models.BaseResponse).Init()
  500. defer func() {
  501. if br.ErrMsg == "" {
  502. br.IsSendEmail = false
  503. }
  504. this.Data["json"] = br
  505. this.ServeJSON()
  506. }()
  507. sysUser := this.SysUser
  508. if sysUser == nil {
  509. br.Msg = "请登录"
  510. br.ErrMsg = "请登录,SysUser Is Empty"
  511. br.Ret = 408
  512. return
  513. }
  514. var req speech_recognition.SpeechRecognitionRemoveReq
  515. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  516. br.Msg = "参数有误"
  517. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  518. return
  519. }
  520. if req.SpeechRecognitionId <= 0 {
  521. br.Msg = "参数有误"
  522. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
  523. return
  524. }
  525. speechOb := new(speech_recognition.SpeechRecognition)
  526. speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
  527. if e != nil {
  528. if e.Error() == utils.ErrNoRow() {
  529. br.Ret = 200
  530. br.Success = true
  531. br.Msg = "操作成功"
  532. return
  533. }
  534. br.Msg = "操作失败"
  535. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  536. return
  537. }
  538. if e = speechItem.Del(); e != nil {
  539. br.Msg = "操作失败"
  540. br.ErrMsg = "删除转写文件失败, Err: " + e.Error()
  541. return
  542. }
  543. // 清除关联
  544. go func() {
  545. contentOb := new(speech_recognition.SpeechRecognitionContent)
  546. _ = contentOb.ClearContentBySpeechId(req.SpeechRecognitionId)
  547. mappingOb := new(speech_recognition.SpeechRecognitionTagMapping)
  548. _ = mappingOb.ClearMappingBySpeechId(req.SpeechRecognitionId)
  549. }()
  550. br.Ret = 200
  551. br.Success = true
  552. br.Msg = "操作成功"
  553. }
  554. // SaveTag
  555. // @Title 保存标签
  556. // @Description 保存标签
  557. // @Param request body speech_recognition.SpeechRecognitionSaveTagReq true "type json string"
  558. // @Success 200 string "操作成功"
  559. // @router /save_tag [post]
  560. func (this *SpeechRecognitionController) SaveTag() {
  561. br := new(models.BaseResponse).Init()
  562. defer func() {
  563. if br.ErrMsg == "" {
  564. br.IsSendEmail = false
  565. }
  566. this.Data["json"] = br
  567. this.ServeJSON()
  568. }()
  569. sysUser := this.SysUser
  570. if sysUser == nil {
  571. br.Msg = "请登录"
  572. br.ErrMsg = "请登录,SysUser Is Empty"
  573. br.Ret = 408
  574. return
  575. }
  576. var req speech_recognition.SpeechRecognitionSaveTagReq
  577. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  578. br.Msg = "参数有误"
  579. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  580. return
  581. }
  582. if req.SpeechRecognitionId <= 0 {
  583. br.Msg = "参数有误"
  584. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
  585. return
  586. }
  587. speechOb := new(speech_recognition.SpeechRecognition)
  588. _, e := speechOb.GetItemById(req.SpeechRecognitionId)
  589. if e != nil {
  590. if e.Error() == utils.ErrNoRow() {
  591. br.Msg = "转写文件不存在,请刷新页面"
  592. return
  593. }
  594. br.Msg = "操作失败"
  595. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  596. return
  597. }
  598. // 清除原标签
  599. mappingOb := new(speech_recognition.SpeechRecognitionTagMapping)
  600. if e = mappingOb.ClearMappingBySpeechId(req.SpeechRecognitionId); e != nil {
  601. br.Msg = "操作失败"
  602. br.ErrMsg = "清除转写文件标签失败, Err: " + e.Error()
  603. return
  604. }
  605. // 保存新标签
  606. if len(req.TagIds) > 0 {
  607. mappings := make([]*speech_recognition.SpeechRecognitionTagMapping, 0)
  608. for _, v := range req.TagIds {
  609. if v <= 0 {
  610. continue
  611. }
  612. mappings = append(mappings, &speech_recognition.SpeechRecognitionTagMapping{
  613. TagId: v,
  614. SpeechRecognitionId: req.SpeechRecognitionId,
  615. })
  616. }
  617. if e = mappingOb.CreateMulti(mappings); e != nil {
  618. br.Msg = "操作失败"
  619. br.ErrMsg = "批量新增转写文件标签失败, Err: " + e.Error()
  620. return
  621. }
  622. }
  623. br.Ret = 200
  624. br.Success = true
  625. br.Msg = "操作成功"
  626. }
  627. // List
  628. // @Title 语音识别列表
  629. // @Description 语音识别列表
  630. // @Param FileName query string false "文件名称"
  631. // @Param StartTime query string false "开始时间"
  632. // @Param EndTime query string false "结束时间"
  633. // @Param CreateUserIds query string false "创建人ID"
  634. // @Param TagId query int false "标签ID"
  635. // @Param TagIds query string false "标签ID"
  636. // @Param MenuId query int false "目录ID"
  637. // @Param IsTagMenu query bool false "是否为标签目录"
  638. // @Success 200 {object} speech_recognition.SpeechRecognitionListResp
  639. // @router /list [get]
  640. func (this *SpeechRecognitionController) List() {
  641. br := new(models.BaseResponse).Init()
  642. defer func() {
  643. if br.ErrMsg == "" {
  644. br.IsSendEmail = false
  645. }
  646. this.Data["json"] = br
  647. this.ServeJSON()
  648. }()
  649. sysUser := this.SysUser
  650. if sysUser == nil {
  651. br.Msg = "请登录"
  652. br.ErrMsg = "请登录,SysUser Is Empty"
  653. br.Ret = 408
  654. return
  655. }
  656. params := new(speech_recognition.SpeechRecognitionListReq)
  657. if e := this.ParseForm(params); e != nil {
  658. br.Msg = "获取失败"
  659. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  660. return
  661. }
  662. params.FileName = strings.TrimSpace(params.FileName)
  663. dataResp := new(speech_recognition.SpeechRecognitionListResp)
  664. cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionCols.State)
  665. pars := make([]interface{}, 0)
  666. pars = append(pars, speech_recognition.SpeechRecognitionStateSuccess)
  667. // 筛选项
  668. {
  669. if params.FileName != "" {
  670. cond += fmt.Sprintf(` AND %s LIKE ?`, speech_recognition.SpeechRecognitionCols.FileName)
  671. pars = append(pars, fmt.Sprint("%", params.FileName, "%"))
  672. }
  673. if params.StartTime != "" && params.EndTime != "" {
  674. _, e := time.Parse(utils.FormatDate, params.StartTime)
  675. if e != nil {
  676. br.Msg = "开始时间格式有误"
  677. return
  678. }
  679. _, e = time.Parse(utils.FormatDate, params.EndTime)
  680. if e != nil {
  681. br.Msg = "结束时间格式有误"
  682. return
  683. }
  684. st := fmt.Sprintf("%s 00:00:00", params.StartTime)
  685. ed := fmt.Sprintf("%s 23:59:59", params.EndTime)
  686. cond += fmt.Sprintf(` AND (%s BETWEEN ? AND ?)`, speech_recognition.SpeechRecognitionCols.CreateTime)
  687. pars = append(pars, st, ed)
  688. }
  689. if params.CreateUserId != "" {
  690. userArr := strings.Split(strings.TrimSpace(params.CreateUserId), ",")
  691. if len(userArr) > 0 {
  692. userIds := make([]int, 0)
  693. for _, v := range userArr {
  694. t, _ := strconv.Atoi(v)
  695. userIds = append(userIds, t)
  696. }
  697. if len(userIds) == 0 {
  698. br.Data = dataResp
  699. br.Ret = 200
  700. br.Success = true
  701. br.Msg = "获取成功"
  702. return
  703. }
  704. cond += fmt.Sprintf(` AND %s IN (%s)`, speech_recognition.SpeechRecognitionCols.SysUserId, utils.GetOrmInReplace(len(userIds)))
  705. pars = append(pars, userIds)
  706. }
  707. }
  708. // 语音识别目录-筛选子目录集合
  709. if params.MenuId > 0 && !params.IsTagMenu {
  710. {
  711. menuOb := new(speech_recognition.SpeechRecognitionMenu)
  712. menus, e := menuOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  713. if e != nil {
  714. br.Msg = "获取失败"
  715. br.ErrMsg = "获取语音识别目录列表失败, Err: " + e.Error()
  716. return
  717. }
  718. childIds := services.GetSpeechRecognitionMenuChildrenRecursive(menus, params.MenuId)
  719. menuIds := make([]int, 0)
  720. menuIds = append(menuIds, params.MenuId)
  721. if len(childIds) > 0 {
  722. menuIds = append(menuIds, childIds...)
  723. }
  724. cond += fmt.Sprintf(` AND %s IN (%s)`, speech_recognition.SpeechRecognitionCols.MenuId, utils.GetOrmInReplace(len(menuIds)))
  725. pars = append(pars, menuIds)
  726. }
  727. }
  728. // 标签目录-筛选目录下所有标签
  729. tagIds := make([]int, 0)
  730. if params.MenuId > 0 && params.IsTagMenu {
  731. {
  732. menuOb := new(speech_recognition.SpeechRecognitionTagMenu)
  733. menus, e := menuOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  734. if e != nil {
  735. br.Msg = "获取失败"
  736. br.ErrMsg = "获取标签目录列表失败, Err: " + e.Error()
  737. return
  738. }
  739. childIds := services.GetSpeechRecognitionTagMenuChildrenRecursive(menus, params.MenuId)
  740. menuIds := make([]int, 0)
  741. menuIds = append(menuIds, params.MenuId)
  742. if len(childIds) > 0 {
  743. menuIds = append(menuIds, childIds...)
  744. }
  745. // 获取目录下所有标签
  746. tagOb := new(speech_recognition.SpeechRecognitionTag)
  747. ids, e := tagOb.GetTagIdsByMenuIds(menuIds)
  748. if e != nil {
  749. br.Msg = "获取失败"
  750. br.ErrMsg = "通过目录IDs获取标签IDs失败, Err: " + e.Error()
  751. return
  752. }
  753. // 此处查询无结果直接返回
  754. if len(ids) == 0 {
  755. br.Data = dataResp
  756. br.Ret = 200
  757. br.Success = true
  758. br.Msg = "获取成功"
  759. return
  760. }
  761. tagIds = ids
  762. }
  763. }
  764. // 标签筛选
  765. if params.TagId > 0 && params.TagIds == "" {
  766. tagIds = append(tagIds, params.TagId)
  767. }
  768. if params.TagId <= 0 && params.TagIds != "" {
  769. tagArr := strings.Split(params.TagIds, ",")
  770. if len(tagArr) > 0 {
  771. for _, v := range tagArr {
  772. t, _ := strconv.Atoi(v)
  773. tagIds = append(tagIds, t)
  774. }
  775. }
  776. }
  777. if len(tagIds) > 0 {
  778. mappingOb := new(speech_recognition.SpeechRecognitionTagMapping)
  779. tagSpeechIds, e := mappingOb.GetSpeechIdsByTagIds(tagIds)
  780. if e != nil {
  781. br.Msg = "获取失败"
  782. br.ErrMsg = "获取标签关联语音识别失败, Err: " + e.Error()
  783. return
  784. }
  785. if len(tagSpeechIds) == 0 {
  786. br.Data = dataResp
  787. br.Ret = 200
  788. br.Success = true
  789. br.Msg = "获取成功"
  790. return
  791. }
  792. cond += fmt.Sprintf(` AND %s IN (%s)`, speech_recognition.SpeechRecognitionCols.SpeechRecognitionId, utils.GetOrmInReplace(len(tagSpeechIds)))
  793. pars = append(pars, tagSpeechIds)
  794. }
  795. }
  796. // 分页列表
  797. speechOb := new(speech_recognition.SpeechRecognition)
  798. total, e := speechOb.GetCountByCondition(cond, pars)
  799. if e != nil {
  800. br.Msg = "获取失败"
  801. br.ErrMsg = "获取语音识别列表总数失败, Err: " + e.Error()
  802. return
  803. }
  804. var startSize int
  805. if params.PageSize <= 0 {
  806. params.PageSize = utils.PageSize20
  807. }
  808. if params.CurrentIndex <= 0 {
  809. params.CurrentIndex = 1
  810. }
  811. startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
  812. list, e := speechOb.GetPageItemsByCondition(cond, pars, []string{}, "", startSize, params.PageSize)
  813. if e != nil {
  814. br.Msg = "获取失败"
  815. br.ErrMsg = "获取语音识别列表失败, Err: " + e.Error()
  816. return
  817. }
  818. // 获取标签
  819. speechIds := make([]int, 0)
  820. for _, v := range list {
  821. speechIds = append(speechIds, v.SpeechRecognitionId)
  822. }
  823. mappingTags, e := speech_recognition.GetSpeechRecognitionTagsBySpeechIds(speechIds)
  824. if e != nil {
  825. br.Msg = "获取失败"
  826. br.ErrMsg = "获取语音识别列表标签失败, Err: " + e.Error()
  827. return
  828. }
  829. speechDetailTags := make(map[int][]*speech_recognition.SpeechRecognitionDetailTag)
  830. for _, v := range mappingTags {
  831. if speechDetailTags[v.SpeechRecognitionId] == nil {
  832. speechDetailTags[v.SpeechRecognitionId] = make([]*speech_recognition.SpeechRecognitionDetailTag, 0)
  833. }
  834. speechDetailTags[v.SpeechRecognitionId] = append(speechDetailTags[v.SpeechRecognitionId], &speech_recognition.SpeechRecognitionDetailTag{
  835. TagId: v.TagId,
  836. TagName: v.TagName,
  837. })
  838. }
  839. respList := make([]*speech_recognition.SpeechRecognitionDetailItem, 0)
  840. for _, v := range list {
  841. t := speech_recognition.FormatSpeechRecognition2DetailItem(v, make([]*speech_recognition.SpeechRecognitionContentItem, 0), speechDetailTags[v.SpeechRecognitionId], make([]*speech_recognition.SpeechRecognitionMenuItem, 0))
  842. respList = append(respList, t)
  843. }
  844. page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
  845. dataResp.Paging = page
  846. dataResp.List = respList
  847. br.Data = dataResp
  848. br.Ret = 200
  849. br.Success = true
  850. br.Msg = "获取成功"
  851. }
  852. // Detail
  853. // @Title 语音识别详情
  854. // @Description 语音识别详情
  855. // @Param SpeechRecognitionId query int true "语音识别ID"
  856. // @Success 200 {object} speech_recognition.SpeechRecognitionDetailItem
  857. // @router /detail [get]
  858. func (this *SpeechRecognitionController) Detail() {
  859. br := new(models.BaseResponse).Init()
  860. defer func() {
  861. if br.ErrMsg == "" {
  862. br.IsSendEmail = false
  863. }
  864. this.Data["json"] = br
  865. this.ServeJSON()
  866. }()
  867. sysUser := this.SysUser
  868. if sysUser == nil {
  869. br.Msg = "请登录"
  870. br.ErrMsg = "请登录,SysUser Is Empty"
  871. br.Ret = 408
  872. return
  873. }
  874. speechId, _ := this.GetInt("SpeechRecognitionId")
  875. if speechId <= 0 {
  876. br.Msg = "参数有误"
  877. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", speechId)
  878. return
  879. }
  880. speechOb := new(speech_recognition.SpeechRecognition)
  881. speechItem, e := speechOb.GetItemById(speechId)
  882. if e != nil {
  883. if e.Error() == utils.ErrNoRow() {
  884. br.Msg = "转写文件不存在,请刷新页面"
  885. return
  886. }
  887. br.Msg = "获取失败"
  888. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  889. return
  890. }
  891. // 获取内容
  892. contents := make([]*speech_recognition.SpeechRecognitionContentItem, 0)
  893. {
  894. contentOb := new(speech_recognition.SpeechRecognitionContent)
  895. cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionContentCols.SpeechRecognitionId)
  896. pars := make([]interface{}, 0)
  897. pars = append(pars, speechId)
  898. list, e := contentOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf("%s ASC", speech_recognition.SpeechRecognitionContentCols.Sort))
  899. if e != nil {
  900. br.Msg = "获取失败"
  901. br.ErrMsg = "获取语音识别内容失败, Err: " + e.Error()
  902. return
  903. }
  904. for _, v := range list {
  905. if v.Content == "" {
  906. continue
  907. }
  908. contents = append(contents, speech_recognition.FormatSpeechRecognitionContent2Item(v))
  909. }
  910. }
  911. // 跟踪目录路径
  912. menuPath := make([]*speech_recognition.SpeechRecognitionMenuItem, 0)
  913. {
  914. menuOb := new(speech_recognition.SpeechRecognitionMenu)
  915. menus, e := menuOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, fmt.Sprintf("%s ASC, %s ASC", speech_recognition.SpeechRecognitionMenuCols.ParentId, speech_recognition.SpeechRecognitionMenuCols.Sort))
  916. if e != nil {
  917. br.Msg = "获取失败"
  918. br.ErrMsg = "获取目录列表失败, Err: " + e.Error()
  919. return
  920. }
  921. menuPath = services.GetSpeechRecognitionMenuPathRecursive(menus, speechItem.MenuId)
  922. sort.Slice(menuPath, func(i, j int) bool {
  923. return menuPath[i].Level < menuPath[j].Level
  924. })
  925. }
  926. // 获取标签
  927. tags, e := speech_recognition.GetSpeechRecognitionTagBySpeechId(speechId)
  928. if e != nil {
  929. br.Msg = "获取失败"
  930. br.ErrMsg = "获取语音识别标签失败, Err: " + e.Error()
  931. return
  932. }
  933. detail := speech_recognition.FormatSpeechRecognition2DetailItem(speechItem, contents, tags, menuPath)
  934. br.Data = detail
  935. br.Ret = 200
  936. br.Success = true
  937. br.Msg = "获取成功"
  938. }
  939. // Export
  940. // @Title 导出内容
  941. // @Description 导出内容
  942. // @Param request body speech_recognition.SpeechRecognitionContentExportReq true "type json string"
  943. // @Success 200 string "操作成功"
  944. // @router /export [get]
  945. func (this *SpeechRecognitionController) Export() {
  946. br := new(models.BaseResponse).Init()
  947. defer func() {
  948. if br.ErrMsg == "" {
  949. br.IsSendEmail = false
  950. }
  951. this.Data["json"] = br
  952. this.ServeJSON()
  953. }()
  954. sysUser := this.SysUser
  955. if sysUser == nil {
  956. br.Msg = "请登录"
  957. br.ErrMsg = "请登录,SysUser Is Empty"
  958. br.Ret = 408
  959. return
  960. }
  961. req := new(speech_recognition.SpeechRecognitionContentExportReq)
  962. if e := this.ParseForm(req); e != nil {
  963. br.Msg = "参数有误"
  964. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  965. return
  966. }
  967. if req.SpeechRecognitionId <= 0 {
  968. br.Msg = "参数有误"
  969. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
  970. return
  971. }
  972. speechOb := new(speech_recognition.SpeechRecognition)
  973. speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
  974. if e != nil {
  975. if e.Error() == utils.ErrNoRow() {
  976. br.Msg = "转写文件不存在,请刷新页面"
  977. return
  978. }
  979. br.Msg = "获取失败"
  980. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  981. return
  982. }
  983. contentOb := new(speech_recognition.SpeechRecognitionContent)
  984. cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionContentCols.SpeechRecognitionId)
  985. pars := make([]interface{}, 0)
  986. pars = append(pars, req.SpeechRecognitionId)
  987. contents, e := contentOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf("%s ASC", speech_recognition.SpeechRecognitionContentCols.Sort))
  988. if e != nil {
  989. br.Msg = "导出失败"
  990. br.ErrMsg = "获取语音识别内容失败, Err: " + e.Error()
  991. return
  992. }
  993. if len(contents) == 0 {
  994. br.Msg = "无内容导出"
  995. return
  996. }
  997. if req.ExportType != services.SpeechRecognitionExportTypeTxt && req.ExportType != services.SpeechRecognitionExportTypeDocx && req.ExportType != services.SpeechRecognitionExportTypePdf {
  998. br.Msg = "导出类型有误"
  999. return
  1000. }
  1001. suffixMap := map[int]string{services.SpeechRecognitionExportTypeTxt: ".txt", services.SpeechRecognitionExportTypeDocx: ".docx", services.SpeechRecognitionExportTypePdf: ".pdf"}
  1002. suffix := suffixMap[req.ExportType]
  1003. if suffix == "" {
  1004. suffix = ".txt"
  1005. }
  1006. downloadPath, e := services.SpeechRecognitionContentExport(req.ExportType, req.Timestamp, speechItem.FileName, contents)
  1007. if e != nil {
  1008. br.Msg = "导出文件失败"
  1009. br.ErrMsg = "导出语音识别内容文件失败, Err: " + e.Error()
  1010. _ = os.Remove(downloadPath)
  1011. return
  1012. }
  1013. defer func() {
  1014. _ = os.Remove(downloadPath)
  1015. }()
  1016. downloadName := fmt.Sprintf("%s%s", speechItem.FileName, suffix)
  1017. this.Ctx.Output.Download(downloadPath, downloadName)
  1018. }
  1019. // CheckFileName
  1020. // @Title 文件重名校验
  1021. // @Description 文件重名校验
  1022. // @Param request body speech_recognition.SpeechRecognitionConvertCheckNameReq true "type json string"
  1023. // @Success 200 string "操作成功"
  1024. // @router /convert/check_name [post]
  1025. func (this *SpeechRecognitionController) CheckFileName() {
  1026. br := new(models.BaseResponse).Init()
  1027. defer func() {
  1028. if br.ErrMsg == "" {
  1029. br.IsSendEmail = false
  1030. }
  1031. this.Data["json"] = br
  1032. this.ServeJSON()
  1033. }()
  1034. sysUser := this.SysUser
  1035. if sysUser == nil {
  1036. br.Msg = "请登录"
  1037. br.ErrMsg = "请登录,SysUser Is Empty"
  1038. br.Ret = 408
  1039. return
  1040. }
  1041. var req speech_recognition.SpeechRecognitionConvertCheckNameReq
  1042. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1043. br.Msg = "参数有误"
  1044. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1045. return
  1046. }
  1047. req.FileName = strings.TrimSpace(req.FileName)
  1048. if req.FileName == "" {
  1049. br.Msg = "参数有误"
  1050. br.ErrMsg = fmt.Sprintf("参数有误, FileName: %s", req.FileName)
  1051. return
  1052. }
  1053. checkResult := true
  1054. speechOb := new(speech_recognition.SpeechRecognition)
  1055. cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionCols.FileName)
  1056. pars := make([]interface{}, 0)
  1057. pars = append(pars, req.FileName)
  1058. exists, e := speechOb.GetItemByCondition(cond, pars, "")
  1059. if e != nil && e.Error() != utils.ErrNoRow() {
  1060. br.Msg = "操作失败"
  1061. br.ErrMsg = "获取同名转写文件失败, Err: " + e.Error()
  1062. return
  1063. }
  1064. if exists != nil && exists.SpeechRecognitionId > 0 {
  1065. checkResult = false
  1066. br.Data = checkResult
  1067. br.Msg = fmt.Sprintf("相同文件名称已存在: %s", req.FileName)
  1068. return
  1069. }
  1070. br.Data = checkResult
  1071. br.Ret = 200
  1072. br.Success = true
  1073. br.Msg = "操作成功"
  1074. }