speech_recognition.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. package speech_recognition
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "strings"
  8. "time"
  9. )
  10. const (
  11. SpeechRecognitionFileRemoveFlag = 1 // 文件删除标记
  12. SpeechRecognitionStateWait = 1
  13. SpeechRecognitionStateSuccess = 2
  14. SpeechRecognitionStateFail = 3
  15. )
  16. // SpeechRecognition 语音识别主表
  17. type SpeechRecognition struct {
  18. SpeechRecognitionId int `orm:"column(speech_recognition_id);pk"`
  19. UniqueCode string `description:"唯一编码"`
  20. FileName string `description:"文件名称"`
  21. ResourceUrl string `description:"文件路径"`
  22. MenuId int `description:"目录ID"`
  23. SysUserId int `description:"创建人ID"`
  24. SysUserName string `description:"创建人姓名"`
  25. State int `description:"状态:1-待转换;2-转换完成;3-转换失败"`
  26. Abstract string `description:"摘要,取前几段内容"`
  27. Sort int `description:"目录下的排序"`
  28. FileState int `description:"文件(非语音识别)删除状态:0-正常;1-删除(该字段作为软删标识)"`
  29. FileSecond int `description:"文件时长(秒)"`
  30. FileSize int `description:"文件大小(byte)"`
  31. ConvertRemark string `description:"转写备注-失败原因"`
  32. CreateTime time.Time `description:"创建时间"`
  33. ModifyTime time.Time `description:"修改时间"`
  34. }
  35. var SpeechRecognitionCols = struct {
  36. SpeechRecognitionId string
  37. UniqueCode string
  38. FileName string
  39. ResourceUrl string
  40. MenuId string
  41. MenuPath string
  42. SysUserId string
  43. SysUserName string
  44. State string
  45. Abstract string
  46. Sort string
  47. FileState string
  48. FileSecond string
  49. FileSize string
  50. ConvertRemark string
  51. CreateTime string
  52. ModifyTime string
  53. }{
  54. SpeechRecognitionId: "speech_recognition_id",
  55. UniqueCode: "unique_code",
  56. FileName: "file_name",
  57. ResourceUrl: "resource_url",
  58. MenuId: "menu_id",
  59. MenuPath: "menu_path",
  60. SysUserId: "sys_user_id",
  61. SysUserName: "sys_user_name",
  62. State: "state",
  63. Abstract: "abstract",
  64. Sort: "sort",
  65. FileState: "file_state",
  66. FileSecond: "file_second",
  67. FileSize: "file_size",
  68. ConvertRemark: "convert_remark",
  69. CreateTime: "create_time",
  70. ModifyTime: "modify_time",
  71. }
  72. func (m *SpeechRecognition) TableName() string {
  73. return "speech_recognition"
  74. }
  75. func (m *SpeechRecognition) PrimaryId() string {
  76. return SpeechRecognitionCols.SpeechRecognitionId
  77. }
  78. func (m *SpeechRecognition) Create() (err error) {
  79. o := orm.NewOrm()
  80. id, err := o.Insert(m)
  81. if err != nil {
  82. return
  83. }
  84. m.SpeechRecognitionId = int(id)
  85. return
  86. }
  87. func (m *SpeechRecognition) CreateMulti(items []*SpeechRecognition) (err error) {
  88. if len(items) == 0 {
  89. return
  90. }
  91. o := orm.NewOrm()
  92. _, err = o.InsertMulti(len(items), items)
  93. return
  94. }
  95. func (m *SpeechRecognition) Update(cols []string) (err error) {
  96. o := orm.NewOrm()
  97. _, err = o.Update(m, cols...)
  98. return
  99. }
  100. func (m *SpeechRecognition) Del() (err error) {
  101. o := orm.NewOrm()
  102. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  103. _, err = o.Raw(sql, m.SpeechRecognitionId).Exec()
  104. return
  105. }
  106. func (m *SpeechRecognition) MultiDel(menuIds []int) (err error) {
  107. if len(menuIds) == 0 {
  108. return
  109. }
  110. o := orm.NewOrm()
  111. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  112. _, err = o.Raw(sql, menuIds).Exec()
  113. return
  114. }
  115. func (m *SpeechRecognition) GetItemById(id int) (item *SpeechRecognition, err error) {
  116. o := orm.NewOrm()
  117. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  118. err = o.Raw(sql, id).QueryRow(&item)
  119. return
  120. }
  121. func (m *SpeechRecognition) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SpeechRecognition, err error) {
  122. o := orm.NewOrm()
  123. order := ``
  124. if orderRule != "" {
  125. order = ` ORDER BY ` + orderRule
  126. }
  127. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  128. err = o.Raw(sql, pars).QueryRow(&item)
  129. return
  130. }
  131. func (m *SpeechRecognition) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  132. o := orm.NewOrm()
  133. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  134. err = o.Raw(sql, pars).QueryRow(&count)
  135. return
  136. }
  137. func (m *SpeechRecognition) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SpeechRecognition, err error) {
  138. o := orm.NewOrm()
  139. fields := strings.Join(fieldArr, ",")
  140. if len(fieldArr) == 0 {
  141. fields = `*`
  142. }
  143. order := `ORDER BY create_time DESC`
  144. if orderRule != "" {
  145. order = ` ORDER BY ` + orderRule
  146. }
  147. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  148. _, err = o.Raw(sql, pars).QueryRows(&items)
  149. return
  150. }
  151. func (m *SpeechRecognition) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SpeechRecognition, err error) {
  152. o := orm.NewOrm()
  153. fields := strings.Join(fieldArr, ",")
  154. if len(fieldArr) == 0 {
  155. fields = `*`
  156. }
  157. order := `ORDER BY create_time DESC`
  158. if orderRule != "" {
  159. order = ` ORDER BY ` + orderRule
  160. }
  161. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  162. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  163. return
  164. }
  165. // SpeechRecognitionItem 语音识别信息
  166. type SpeechRecognitionItem struct {
  167. SpeechRecognitionId int
  168. UniqueCode string `description:"唯一编码"`
  169. FileName string `description:"文件名称"`
  170. ResourceUrl string `description:"文件路径"`
  171. MenuId int `description:"目录ID"`
  172. SysUserId int `description:"创建人ID"`
  173. SysUserName string `description:"创建人姓名"`
  174. State int `description:"状态:1-待转换;2-转换完成;3-转换失败"`
  175. Abstract string `description:"摘要,取前几段内容"`
  176. Sort int `description:"目录下的排序"`
  177. ConvertRemark string `description:"转写备注-失败原因"`
  178. CreateTime string `description:"创建时间"`
  179. ModifyTime string `description:"修改时间"`
  180. }
  181. func FormatSpeechRecognition2Item(origin *SpeechRecognition) (item *SpeechRecognitionItem) {
  182. if origin == nil {
  183. return
  184. }
  185. item = new(SpeechRecognitionItem)
  186. item.SpeechRecognitionId = origin.SpeechRecognitionId
  187. item.UniqueCode = origin.UniqueCode
  188. item.FileName = origin.FileName
  189. item.ResourceUrl = origin.ResourceUrl
  190. if origin.FileState == SpeechRecognitionFileRemoveFlag {
  191. item.ResourceUrl = ""
  192. }
  193. item.MenuId = origin.MenuId
  194. item.SysUserId = origin.SysUserId
  195. item.SysUserName = origin.SysUserName
  196. item.State = origin.State
  197. item.Abstract = origin.Abstract
  198. item.Sort = origin.Sort
  199. item.ConvertRemark = origin.ConvertRemark
  200. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  201. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  202. return
  203. }
  204. // SpeechRecognitionSaveReq 保存请求体
  205. type SpeechRecognitionSaveReq struct {
  206. SpeechRecognitionId int `description:"语音识别ID"`
  207. FileName string `description:"文件名称"`
  208. TagIds []int `description:"标签IDs"`
  209. Contents []SpeechRecognitionSaveContentReq `description:"保存内容"`
  210. }
  211. // SpeechRecognitionSaveContentReq 保存内容
  212. type SpeechRecognitionSaveContentReq struct {
  213. SpeechRecognitionContentId int `description:"语音识别内容ID"`
  214. Content string `description:"段落内容"`
  215. }
  216. // SpeechRecognitionRenameReq 重命名
  217. type SpeechRecognitionRenameReq struct {
  218. SpeechRecognitionId int `description:"语音识别ID"`
  219. FileName string `description:"文件名称"`
  220. }
  221. // SpeechRecognitionRemoveReq 删除
  222. type SpeechRecognitionRemoveReq struct {
  223. SpeechRecognitionId int `description:"语音识别ID"`
  224. }
  225. // SpeechRecognitionRemoveFileReq 删除文件
  226. type SpeechRecognitionRemoveFileReq struct {
  227. SpeechRecognitionId int `description:"语音识别ID"`
  228. }
  229. // SpeechRecognitionSaveTagReq 保存标签
  230. type SpeechRecognitionSaveTagReq struct {
  231. SpeechRecognitionId int `description:"语音识别ID"`
  232. TagIds []int `description:"标签IDs"`
  233. }
  234. // SpeechRecognitionConvertReq 批量转写
  235. type SpeechRecognitionConvertReq struct {
  236. MenuId int `description:"目录ID"`
  237. Files []SpeechRecognitionConvertFiles `description:"转写文件"`
  238. }
  239. // SpeechRecognitionConvertFiles 批量转写文件
  240. type SpeechRecognitionConvertFiles struct {
  241. FileName string `description:"文件名称"`
  242. ResourceUrl string `description:"文件地址"`
  243. FileSecond int `description:"文件时长(秒)"`
  244. FileSize int `description:"文件大小(byte)"`
  245. }
  246. // UpdateSpeechAndApiLog 更新语音识别及API记录
  247. func UpdateSpeechAndApiLog(speechItem *SpeechRecognition, speechCols []string, apiLogItem *SpeechRecognitionApiLog, logCols []string) (err error) {
  248. if speechItem == nil || apiLogItem == nil {
  249. err = fmt.Errorf("speechItem nil or apiLogItem nil")
  250. return
  251. }
  252. o := orm.NewOrm()
  253. tx, err := o.Begin()
  254. if err != nil {
  255. return
  256. }
  257. defer func() {
  258. if err != nil {
  259. _ = tx.Rollback()
  260. } else {
  261. _ = tx.Commit()
  262. }
  263. }()
  264. _, e := tx.Update(speechItem, speechCols...)
  265. if e != nil {
  266. err = fmt.Errorf("update speech err: %s", e.Error())
  267. return
  268. }
  269. _, e = tx.Update(apiLogItem, logCols...)
  270. if e != nil {
  271. err = fmt.Errorf("update api log err: %s", e.Error())
  272. return
  273. }
  274. return
  275. }
  276. // CreateContentAndUpdateSpeechAndApiLog 新增语音识别内容并更新语音识别及API记录
  277. func CreateContentAndUpdateSpeechAndApiLog(contents []*SpeechRecognitionContent, speechItem *SpeechRecognition, speechCols []string, apiLogItem *SpeechRecognitionApiLog, logCols []string) (err error) {
  278. if speechItem == nil || apiLogItem == nil {
  279. err = fmt.Errorf("speechItem nil or apiLogItem nil")
  280. return
  281. }
  282. o := orm.NewOrm()
  283. tx, err := o.Begin()
  284. if err != nil {
  285. return
  286. }
  287. defer func() {
  288. if err != nil {
  289. _ = tx.Rollback()
  290. } else {
  291. _ = tx.Commit()
  292. }
  293. }()
  294. _, e := tx.Update(speechItem, speechCols...)
  295. if e != nil {
  296. err = fmt.Errorf("update speech err: %s", e.Error())
  297. return
  298. }
  299. _, e = tx.Update(apiLogItem, logCols...)
  300. if e != nil {
  301. err = fmt.Errorf("update api log err: %s", e.Error())
  302. return
  303. }
  304. if len(contents) > 0 {
  305. _, e = tx.InsertMulti(len(contents), contents)
  306. if e != nil {
  307. err = fmt.Errorf("insert multi contents err: %s", e.Error())
  308. return
  309. }
  310. }
  311. return
  312. }
  313. // SpeechRecognitionDetailItem 语音识别详情信息
  314. type SpeechRecognitionDetailItem struct {
  315. SpeechRecognitionId int
  316. UniqueCode string `description:"唯一编码"`
  317. FileName string `description:"文件名称"`
  318. FileExt string `description:"文件后缀名"`
  319. ResourceUrl string `description:"文件地址"`
  320. MenuId int `description:"目录ID"`
  321. MenuPath []*SpeechRecognitionMenuItem `description:"目录全路径, 多级并列为一个数组"`
  322. SysUserId int `description:"创建人ID"`
  323. SysUserName string `description:"创建人姓名"`
  324. Abstract string `description:"摘要,取前几段内容"`
  325. Sort int `description:"目录下的排序"`
  326. FileSecond string `description:"文件时长(HH:MM:SS/MM:SS)"`
  327. FileSize string `description:"文件大小(MB)"`
  328. CreateTime string `description:"创建时间"`
  329. ModifyTime string `description:"修改时间"`
  330. Contents []*SpeechRecognitionContentItem `description:"语音识别内容"`
  331. Tags []*SpeechRecognitionDetailTag `description:"标签"`
  332. }
  333. func FormatSpeechRecognition2DetailItem(origin *SpeechRecognition, contents []*SpeechRecognitionContentItem, tags []*SpeechRecognitionDetailTag, menuPath []*SpeechRecognitionMenuItem) (item *SpeechRecognitionDetailItem) {
  334. if origin == nil {
  335. return
  336. }
  337. item = new(SpeechRecognitionDetailItem)
  338. item.SpeechRecognitionId = origin.SpeechRecognitionId
  339. item.UniqueCode = origin.UniqueCode
  340. item.FileName = origin.FileName
  341. item.ResourceUrl = origin.ResourceUrl
  342. if item.ResourceUrl != "" {
  343. pointArr := strings.Split(item.ResourceUrl, ".")
  344. if len(pointArr) > 0 {
  345. item.FileExt = pointArr[len(pointArr)-1]
  346. }
  347. }
  348. item.ResourceUrl = origin.ResourceUrl
  349. if origin.FileState == SpeechRecognitionFileRemoveFlag {
  350. item.ResourceUrl = ""
  351. }
  352. item.MenuId = origin.MenuId
  353. item.MenuPath = menuPath
  354. item.SysUserId = origin.SysUserId
  355. item.SysUserName = origin.SysUserName
  356. item.Abstract = origin.Abstract
  357. item.Sort = origin.Sort
  358. item.FileSecond = utils.SecondsToHHMMSS(origin.FileSecond)
  359. item.FileSize = fmt.Sprintf("%.2fM", utils.ByteToMB(origin.FileSize))
  360. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  361. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  362. item.Contents = contents
  363. item.Tags = tags
  364. return
  365. }
  366. // SpeechRecognitionDetailTag 语音识别详情标签
  367. type SpeechRecognitionDetailTag struct {
  368. TagId int `description:"标签ID"`
  369. TagName string `description:"标签名称"`
  370. }
  371. // GetSpeechRecognitionTagBySpeechId 获取语音识别标签
  372. func GetSpeechRecognitionTagBySpeechId(speechId int) (items []*SpeechRecognitionDetailTag, err error) {
  373. o := orm.NewOrm()
  374. sql := `SELECT a.speech_recognition_tag_id AS tag_id, a.tag_name FROM speech_recognition_tag AS a
  375. JOIN speech_recognition_tag_mapping AS b ON a.speech_recognition_tag_id = b.tag_id
  376. WHERE b.speech_recognition_id = ?`
  377. _, err = o.Raw(sql, speechId).QueryRows(&items)
  378. return
  379. }
  380. // SpeechRecognitionMappingTags 语音识别标签
  381. type SpeechRecognitionMappingTags struct {
  382. SpeechRecognitionId int `description:"语音识别ID"`
  383. TagId int `description:"标签ID"`
  384. TagName string `description:"标签名称"`
  385. }
  386. // GetSpeechRecognitionTagsBySpeechIds 根据语音识别IDs获取标签
  387. func GetSpeechRecognitionTagsBySpeechIds(speechIds []int) (items []*SpeechRecognitionMappingTags, err error) {
  388. if len(speechIds) == 0 {
  389. return
  390. }
  391. o := orm.NewOrm()
  392. sql := fmt.Sprintf(`SELECT a.speech_recognition_id, a.tag_id, b.tag_name FROM speech_recognition_tag_mapping AS a
  393. JOIN speech_recognition_tag AS b ON a.tag_id = b.speech_recognition_tag_id
  394. WHERE a.speech_recognition_id IN (%s)`, utils.GetOrmInReplace(len(speechIds)))
  395. _, err = o.Raw(sql, speechIds).QueryRows(&items)
  396. return
  397. }
  398. // SpeechRecognitionListReq 语音识别列表请求体
  399. type SpeechRecognitionListReq struct {
  400. PageSize int `form:"PageSize"`
  401. CurrentIndex int `form:"CurrentIndex"`
  402. FileName string `form:"FileName" description:"文件名称"`
  403. StartTime string `form:"StartTime" description:"开始时间"`
  404. EndTime string `form:"EndTime" description:"结束时间"`
  405. CreateUserId string `form:"CreateUserId" description:"创建人IDs"`
  406. TagId int `form:"TagId" description:"标签ID"`
  407. TagIds string `form:"TagIds" description:"标签IDs, 英文逗号分隔"`
  408. MenuId int `form:"MenuId" description:"目录ID"`
  409. IsTagMenu bool `form:"IsTagMenu" description:"是否为标签目录"`
  410. }
  411. // SpeechRecognitionListResp 语音识别列表响应体
  412. type SpeechRecognitionListResp struct {
  413. List []*SpeechRecognitionDetailItem
  414. Paging *paging.PagingItem `description:"分页数据"`
  415. }
  416. // SpeechRecognitionContentExportReq 导出内容
  417. type SpeechRecognitionContentExportReq struct {
  418. SpeechRecognitionId int `description:"语音识别ID"`
  419. ExportType int `description:"导出类型:1-txt;2-doc;3-pdf"`
  420. Timestamp bool `description:"是否显示时间戳"`
  421. }
  422. // UpdateSortByMenuId 根据分类ID更新排序
  423. func (m *SpeechRecognition) UpdateSortByMenuId(menuId, nowSort int, prevSpeechId int, updateSort string) (err error) {
  424. o := orm.NewOrm()
  425. sql := fmt.Sprintf(`UPDATE %s SET %s = %s WHERE %s = ? `, m.TableName(), SpeechRecognitionCols.Sort, updateSort, SpeechRecognitionCols.MenuId)
  426. if prevSpeechId > 0 {
  427. sql += fmt.Sprintf(` AND (%s > ? OR (%s > %d AND %s = %d))`, SpeechRecognitionCols.Sort, SpeechRecognitionCols.SpeechRecognitionId, prevSpeechId, SpeechRecognitionCols.Sort, nowSort)
  428. } else {
  429. sql += fmt.Sprintf(` AND %s > ?`, SpeechRecognitionCols.Sort)
  430. }
  431. _, err = o.Raw(sql, menuId, nowSort).Exec()
  432. return
  433. }
  434. // GetMaxSortByMenuId 获取分类下最大Sort
  435. func (m *SpeechRecognition) GetMaxSortByMenuId(menuId int) (sort int, err error) {
  436. o := orm.NewOrm()
  437. sql := fmt.Sprintf(`SELECT MAX(sort) AS sort FROM %s WHERE %s = ?`, m.TableName(), SpeechRecognitionCols.MenuId)
  438. err = o.Raw(sql, menuId).QueryRow(&sort)
  439. return
  440. }
  441. // GetFirstByMenuId 获取目录下排序第一的数据
  442. func (m *SpeechRecognition) GetFirstByMenuId(menuId int) (item *SpeechRecognition, err error) {
  443. o := orm.NewOrm()
  444. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? ORDER BY %s ASC, %s ASC LIMIT 1`, m.TableName(), SpeechRecognitionCols.MenuId, SpeechRecognitionCols.Sort, SpeechRecognitionCols.SpeechRecognitionId)
  445. err = o.Raw(sql, menuId).QueryRow(&item)
  446. return
  447. }
  448. // SpeechRecognitionConvertCheckNameReq 校验文件重名请求体
  449. type SpeechRecognitionConvertCheckNameReq struct {
  450. FileName string `description:"文件名称"`
  451. }
  452. // SpeechSave 更新内容、摘要及标签
  453. func (m *SpeechRecognition) SpeechSave(speechItem *SpeechRecognition, speechCols []string, contents []SpeechRecognitionSaveContentReq, tagMappings []*SpeechRecognitionTagMapping) (err error) {
  454. if speechItem == nil {
  455. err = fmt.Errorf("speech nil")
  456. return
  457. }
  458. o := orm.NewOrm()
  459. tx, e := o.Begin()
  460. if e != nil {
  461. err = fmt.Errorf("transaction begin err: %s", e.Error())
  462. return
  463. }
  464. defer func() {
  465. if err != nil {
  466. _ = tx.Rollback()
  467. return
  468. }
  469. _ = tx.Commit()
  470. }()
  471. // 转写文件
  472. if len(speechCols) > 0 {
  473. _, e = tx.Update(speechItem, speechCols...)
  474. if e != nil {
  475. err = fmt.Errorf("update speech err: %s", e.Error())
  476. return
  477. }
  478. }
  479. // 转写内容
  480. if len(contents) > 0 {
  481. sql := fmt.Sprintf(`UPDATE %s SET %s = ?, %s = 1, %s = NOW() WHERE %s = ?`, "speech_recognition_content", SpeechRecognitionContentCols.Content, SpeechRecognitionContentCols.IsUpdate, SpeechRecognitionContentCols.ModifyTime, SpeechRecognitionContentCols.SpeechRecognitionContentId)
  482. p, e := tx.Raw(sql).Prepare()
  483. if e != nil {
  484. err = fmt.Errorf("update prepare err: %s", e.Error())
  485. return
  486. }
  487. defer func() {
  488. _ = p.Close()
  489. }()
  490. for _, v := range contents {
  491. _, e = p.Exec(v.Content, v.SpeechRecognitionContentId)
  492. if e != nil {
  493. err = fmt.Errorf("update exec err: %s", e.Error())
  494. return
  495. }
  496. }
  497. }
  498. // 标签
  499. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ?`, "speech_recognition_tag_mapping", SpeechRecognitionTagMappingCols.SpeechRecognitionId)
  500. _, e = tx.Raw(sql, speechItem.SpeechRecognitionId).Exec()
  501. if e != nil {
  502. err = fmt.Errorf("remove tag mappings err: %s", e.Error())
  503. return
  504. }
  505. if len(tagMappings) > 0 {
  506. _, e = tx.InsertMulti(len(tagMappings), tagMappings)
  507. if e != nil {
  508. err = fmt.Errorf("insert tag mappings err: %s", e.Error())
  509. return
  510. }
  511. }
  512. return
  513. }