speech_recognition.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. // SpeechRecognition 语音识别主表
  10. type SpeechRecognition struct {
  11. SpeechRecognitionId int `orm:"column(speech_recognition_id);pk"`
  12. FileName string `description:"文件名称"`
  13. ResourceUrl string `description:"文件路径"`
  14. MenuId int `description:"目录ID"`
  15. MenuPath string `description:"所属目录位置,例:/一级目录ID/二级目录ID"`
  16. SysUserId int `description:"创建人ID"`
  17. SysUserName string `description:"创建人姓名"`
  18. State int `description:"状态:1-待转换;2-转换中;3-转换完成;4-转换失败"`
  19. Abstract string `description:"摘要,取前几段内容"`
  20. CreateTime time.Time `description:"创建时间"`
  21. ModifyTime time.Time `description:"修改时间"`
  22. }
  23. var SpeechRecognitionCols = struct {
  24. SpeechRecognitionId string
  25. FileName string
  26. ResourceUrl string
  27. MenuId string
  28. MenuPath string
  29. SysUserId string
  30. SysUserName string
  31. State string
  32. Abstract string
  33. CreateTime string
  34. ModifyTime string
  35. }{
  36. SpeechRecognitionId: "speech_recognition_id",
  37. FileName: "file_name",
  38. ResourceUrl: "resource_url",
  39. MenuId: "menu_id",
  40. MenuPath: "menu_path",
  41. SysUserId: "sys_user_id",
  42. SysUserName: "sys_user_name",
  43. State: "state",
  44. Abstract: "abstract",
  45. CreateTime: "create_time",
  46. ModifyTime: "modify_time",
  47. }
  48. func (m *SpeechRecognition) TableName() string {
  49. return "speech_recognition_id"
  50. }
  51. func (m *SpeechRecognition) PrimaryId() string {
  52. return SpeechRecognitionCols.SpeechRecognitionId
  53. }
  54. func (m *SpeechRecognition) Create() (err error) {
  55. o := orm.NewOrm()
  56. id, err := o.Insert(m)
  57. if err != nil {
  58. return
  59. }
  60. m.SpeechRecognitionId = int(id)
  61. return
  62. }
  63. func (m *SpeechRecognition) CreateMulti(items []*SpeechRecognition) (err error) {
  64. if len(items) == 0 {
  65. return
  66. }
  67. o := orm.NewOrm()
  68. _, err = o.InsertMulti(len(items), items)
  69. return
  70. }
  71. func (m *SpeechRecognition) Update(cols []string) (err error) {
  72. o := orm.NewOrm()
  73. _, err = o.Update(m, cols...)
  74. return
  75. }
  76. func (m *SpeechRecognition) Del() (err error) {
  77. o := orm.NewOrm()
  78. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  79. _, err = o.Raw(sql, m.SpeechRecognitionId).Exec()
  80. return
  81. }
  82. func (m *SpeechRecognition) MultiDel(menuIds []int) (err error) {
  83. if len(menuIds) == 0 {
  84. return
  85. }
  86. o := orm.NewOrm()
  87. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  88. _, err = o.Raw(sql, menuIds).Exec()
  89. return
  90. }
  91. func (m *SpeechRecognition) GetItemById(id int) (item *SpeechRecognition, err error) {
  92. o := orm.NewOrm()
  93. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  94. err = o.Raw(sql, id).QueryRow(&item)
  95. return
  96. }
  97. func (m *SpeechRecognition) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SpeechRecognition, err error) {
  98. o := orm.NewOrm()
  99. order := ``
  100. if orderRule != "" {
  101. order = ` ORDER BY ` + orderRule
  102. }
  103. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  104. err = o.Raw(sql, pars).QueryRow(&item)
  105. return
  106. }
  107. func (m *SpeechRecognition) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  108. o := orm.NewOrm()
  109. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  110. err = o.Raw(sql, pars).QueryRow(&count)
  111. return
  112. }
  113. func (m *SpeechRecognition) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SpeechRecognition, err error) {
  114. o := orm.NewOrm()
  115. fields := strings.Join(fieldArr, ",")
  116. if len(fieldArr) == 0 {
  117. fields = `*`
  118. }
  119. order := `ORDER BY create_time DESC`
  120. if orderRule != "" {
  121. order = ` ORDER BY ` + orderRule
  122. }
  123. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  124. _, err = o.Raw(sql, pars).QueryRows(&items)
  125. return
  126. }
  127. func (m *SpeechRecognition) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SpeechRecognition, err error) {
  128. o := orm.NewOrm()
  129. fields := strings.Join(fieldArr, ",")
  130. if len(fieldArr) == 0 {
  131. fields = `*`
  132. }
  133. order := `ORDER BY create_time DESC`
  134. if orderRule != "" {
  135. order = ` ORDER BY ` + orderRule
  136. }
  137. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  138. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  139. return
  140. }
  141. // SpeechRecognitionSaveReq 保存请求体
  142. type SpeechRecognitionSaveReq struct {
  143. FileName string
  144. }