speech_recognition.go 20 KB

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