speech_recognition_content.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package speech_recognition
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "fmt"
  6. "strings"
  7. "time"
  8. )
  9. // SpeechRecognitionContent 语音识别-内容表
  10. type SpeechRecognitionContent struct {
  11. SpeechRecognitionContentId int `orm:"column(speech_recognition_content_id);pk" gorm:"primaryKey"`
  12. SpeechRecognitionId int `description:"语音识别ID"`
  13. Sort int `description:"段落排序"`
  14. Content string `description:"段落内容"`
  15. StartMs int `description:"单句开始时间(毫秒)"`
  16. EndMs int `description:"单句结束时间(毫秒)"`
  17. IsUpdate int `description:"是否手动修改过:0-否;1-是"`
  18. CreateTime time.Time `description:"创建时间"`
  19. ModifyTime time.Time `description:"修改时间"`
  20. }
  21. var SpeechRecognitionContentCols = struct {
  22. SpeechRecognitionContentId string
  23. SpeechRecognitionId string
  24. Sort string
  25. Content string
  26. StartMs string
  27. EndMs string
  28. IsUpdate string
  29. CreateTime string
  30. ModifyTime string
  31. }{
  32. SpeechRecognitionContentId: "speech_recognition_content_id",
  33. SpeechRecognitionId: "speech_recognition_id",
  34. Sort: "sort",
  35. Content: "content",
  36. StartMs: "start_ms",
  37. EndMs: "end_ms",
  38. IsUpdate: "is_update",
  39. CreateTime: "create_time",
  40. ModifyTime: "modify_time",
  41. }
  42. func (m *SpeechRecognitionContent) TableName() string {
  43. return "speech_recognition_content"
  44. }
  45. func (m *SpeechRecognitionContent) PrimaryId() string {
  46. return SpeechRecognitionContentCols.SpeechRecognitionContentId
  47. }
  48. func (m *SpeechRecognitionContent) Create() (err error) {
  49. o := global.DbMap[utils.DbNameMaster]
  50. err = o.Create(m).Error
  51. return
  52. }
  53. func (m *SpeechRecognitionContent) CreateMulti(items []*SpeechRecognitionContent) (err error) {
  54. if len(items) == 0 {
  55. return
  56. }
  57. o := global.DbMap[utils.DbNameMaster]
  58. err = o.CreateInBatches(items, utils.MultiAddNum).Error
  59. return
  60. }
  61. func (m *SpeechRecognitionContent) Update(cols []string) (err error) {
  62. o := global.DbMap[utils.DbNameMaster]
  63. err = o.Select(cols).Updates(m).Error
  64. return
  65. }
  66. func (m *SpeechRecognitionContent) Del() (err error) {
  67. o := global.DbMap[utils.DbNameMaster]
  68. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  69. err = o.Exec(sql, m.SpeechRecognitionContentId).Error
  70. return
  71. }
  72. func (m *SpeechRecognitionContent) MultiDel(menuIds []int) (err error) {
  73. if len(menuIds) == 0 {
  74. return
  75. }
  76. o := global.DbMap[utils.DbNameMaster]
  77. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  78. err = o.Exec(sql, menuIds).Error
  79. return
  80. }
  81. func (m *SpeechRecognitionContent) GetItemById(id int) (item *SpeechRecognitionContent, err error) {
  82. o := global.DbMap[utils.DbNameMaster]
  83. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  84. err = o.Raw(sql, id).First(&item).Error
  85. return
  86. }
  87. func (m *SpeechRecognitionContent) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SpeechRecognitionContent, err error) {
  88. o := global.DbMap[utils.DbNameMaster]
  89. order := ``
  90. if orderRule != "" {
  91. order = ` ORDER BY ` + orderRule
  92. }
  93. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  94. err = o.Raw(sql, pars...).First(&item).Error
  95. return
  96. }
  97. func (m *SpeechRecognitionContent) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  98. o := global.DbMap[utils.DbNameMaster]
  99. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  100. err = o.Raw(sql, pars...).Scan(&count).Error
  101. return
  102. }
  103. func (m *SpeechRecognitionContent) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SpeechRecognitionContent, err error) {
  104. o := global.DbMap[utils.DbNameMaster]
  105. fields := strings.Join(fieldArr, ",")
  106. if len(fieldArr) == 0 {
  107. fields = `*`
  108. }
  109. order := `ORDER BY create_time DESC`
  110. if orderRule != "" {
  111. order = ` ORDER BY ` + orderRule
  112. }
  113. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  114. err = o.Raw(sql, pars...).Find(&items).Error
  115. return
  116. }
  117. func (m *SpeechRecognitionContent) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SpeechRecognitionContent, err error) {
  118. o := global.DbMap[utils.DbNameMaster]
  119. fields := strings.Join(fieldArr, ",")
  120. if len(fieldArr) == 0 {
  121. fields = `*`
  122. }
  123. order := `ORDER BY create_time DESC`
  124. if orderRule != "" {
  125. order = ` ORDER BY ` + orderRule
  126. }
  127. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  128. pars = append(pars, startSize, pageSize)
  129. err = o.Raw(sql, pars...).Find(&items).Error
  130. return
  131. }
  132. type SpeechRecognitionContentItem struct {
  133. SpeechRecognitionContentId int
  134. SpeechRecognitionId int `description:"语音识别ID"`
  135. Sort int `description:"段落排序"`
  136. Content string `description:"段落内容"`
  137. StartMs int `description:"单句开始时间(毫秒)"`
  138. EndMs int `description:"单句结束时间(毫秒)"`
  139. StartTime string `description:"开始时间, 格式HH:MM:SS"`
  140. CreateTime string `description:"创建时间"`
  141. ModifyTime string `description:"修改时间"`
  142. HideTimestamp bool `description:"前端用的, 默认false就行"`
  143. IsHover bool `description:"前端用的, 默认false就行"`
  144. }
  145. func FormatSpeechRecognitionContent2Item(origin *SpeechRecognitionContent) (item *SpeechRecognitionContentItem) {
  146. if origin == nil {
  147. return
  148. }
  149. item = new(SpeechRecognitionContentItem)
  150. item.SpeechRecognitionContentId = origin.SpeechRecognitionContentId
  151. item.SpeechRecognitionId = origin.SpeechRecognitionId
  152. item.Sort = origin.Sort
  153. item.Content = origin.Content
  154. item.StartMs = origin.StartMs
  155. item.EndMs = origin.EndMs
  156. item.StartTime = utils.MillisecondsToHHMMSS(origin.StartMs)
  157. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  158. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  159. return
  160. }
  161. // BatchUpdateContents 批量更新语音识别内容
  162. func (m *SpeechRecognitionContent) BatchUpdateContents(contents []SpeechRecognitionSaveContentReq) (err error) {
  163. if len(contents) == 0 {
  164. return
  165. }
  166. o := global.DbMap[utils.DbNameMaster]
  167. sql := fmt.Sprintf(`UPDATE %s SET %s = ?, %s = 1, %s = NOW() WHERE %s = ?`, m.TableName(), SpeechRecognitionContentCols.Content, SpeechRecognitionContentCols.IsUpdate, SpeechRecognitionContentCols.ModifyTime, SpeechRecognitionContentCols.SpeechRecognitionContentId)
  168. for _, v := range contents {
  169. err = o.Exec(sql, v.Content, v.SpeechRecognitionContentId).Error
  170. if err != nil {
  171. return
  172. }
  173. }
  174. return
  175. }
  176. // ClearContentBySpeechId 清除转写文件内容
  177. func (m *SpeechRecognitionContent) ClearContentBySpeechId(speechId int) (err error) {
  178. o := global.DbMap[utils.DbNameMaster]
  179. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ?`, m.TableName(), SpeechRecognitionContentCols.SpeechRecognitionId)
  180. err = o.Raw(sql, speechId).Error
  181. return
  182. }