speech_recognition_content.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package speech_recognition
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "strings"
  7. "time"
  8. )
  9. // SpeechRecognitionContent 语音识别-内容表
  10. type SpeechRecognitionContent struct {
  11. SpeechRecognitionContentId int `orm:"column(speech_recognition_content_id);pk"`
  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 := orm.NewOrm()
  50. id, err := o.Insert(m)
  51. if err != nil {
  52. return
  53. }
  54. m.SpeechRecognitionContentId = int(id)
  55. return
  56. }
  57. func (m *SpeechRecognitionContent) CreateMulti(items []*SpeechRecognitionContent) (err error) {
  58. if len(items) == 0 {
  59. return
  60. }
  61. o := orm.NewOrm()
  62. _, err = o.InsertMulti(len(items), items)
  63. return
  64. }
  65. func (m *SpeechRecognitionContent) Update(cols []string) (err error) {
  66. o := orm.NewOrm()
  67. _, err = o.Update(m, cols...)
  68. return
  69. }
  70. func (m *SpeechRecognitionContent) Del() (err error) {
  71. o := orm.NewOrm()
  72. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  73. _, err = o.Raw(sql, m.SpeechRecognitionContentId).Exec()
  74. return
  75. }
  76. func (m *SpeechRecognitionContent) MultiDel(menuIds []int) (err error) {
  77. if len(menuIds) == 0 {
  78. return
  79. }
  80. o := orm.NewOrm()
  81. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  82. _, err = o.Raw(sql, menuIds).Exec()
  83. return
  84. }
  85. func (m *SpeechRecognitionContent) GetItemById(id int) (item *SpeechRecognitionContent, err error) {
  86. o := orm.NewOrm()
  87. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  88. err = o.Raw(sql, id).QueryRow(&item)
  89. return
  90. }
  91. func (m *SpeechRecognitionContent) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SpeechRecognitionContent, err error) {
  92. o := orm.NewOrm()
  93. order := ``
  94. if orderRule != "" {
  95. order = ` ORDER BY ` + orderRule
  96. }
  97. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  98. err = o.Raw(sql, pars).QueryRow(&item)
  99. return
  100. }
  101. func (m *SpeechRecognitionContent) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  102. o := orm.NewOrm()
  103. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  104. err = o.Raw(sql, pars).QueryRow(&count)
  105. return
  106. }
  107. func (m *SpeechRecognitionContent) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SpeechRecognitionContent, err error) {
  108. o := orm.NewOrm()
  109. fields := strings.Join(fieldArr, ",")
  110. if len(fieldArr) == 0 {
  111. fields = `*`
  112. }
  113. order := `ORDER BY create_time DESC`
  114. if orderRule != "" {
  115. order = ` ORDER BY ` + orderRule
  116. }
  117. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  118. _, err = o.Raw(sql, pars).QueryRows(&items)
  119. return
  120. }
  121. func (m *SpeechRecognitionContent) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SpeechRecognitionContent, err error) {
  122. o := orm.NewOrm()
  123. fields := strings.Join(fieldArr, ",")
  124. if len(fieldArr) == 0 {
  125. fields = `*`
  126. }
  127. order := `ORDER BY create_time DESC`
  128. if orderRule != "" {
  129. order = ` ORDER BY ` + orderRule
  130. }
  131. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  132. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  133. return
  134. }