speech_recognition_menu.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. const (
  10. SpeechRecognitionMenuNodeTypeDefault = 0
  11. SpeechRecognitionMenuNodeTypeSpeech = 1
  12. )
  13. // SpeechRecognitionMenu 语音识别-目录表
  14. type SpeechRecognitionMenu struct {
  15. SpeechRecognitionMenuId int `orm:"column(speech_recognition_menu_id);pk"`
  16. UniqueCode string `description:"唯一编码"`
  17. MenuName string `description:"目录名称"`
  18. ParentId int `description:"父级ID"`
  19. Level int `description:"目录层级"`
  20. Sort int `description:"排序"`
  21. RootId int `description:"顶级ID"`
  22. CreateTime time.Time `description:"创建时间"`
  23. ModifyTime time.Time `description:"修改时间"`
  24. }
  25. var SpeechRecognitionMenuCols = struct {
  26. SpeechRecognitionMenuId string
  27. UniqueCode string
  28. MenuName string
  29. ParentId string
  30. Level string
  31. Sort string
  32. RootId string
  33. CreateTime string
  34. ModifyTime string
  35. }{
  36. SpeechRecognitionMenuId: "speech_recognition_menu_id",
  37. UniqueCode: "unique_code",
  38. MenuName: "menu_name",
  39. ParentId: "parent_id",
  40. Level: "level",
  41. Sort: "sort",
  42. RootId: "root_id",
  43. CreateTime: "create_time",
  44. ModifyTime: "modify_time",
  45. }
  46. func (m *SpeechRecognitionMenu) TableName() string {
  47. return "speech_recognition_menu"
  48. }
  49. func (m *SpeechRecognitionMenu) PrimaryId() string {
  50. return SpeechRecognitionMenuCols.SpeechRecognitionMenuId
  51. }
  52. func (m *SpeechRecognitionMenu) Create() (err error) {
  53. o := orm.NewOrm()
  54. id, err := o.Insert(m)
  55. if err != nil {
  56. return
  57. }
  58. m.SpeechRecognitionMenuId = int(id)
  59. return
  60. }
  61. func (m *SpeechRecognitionMenu) CreateMulti(items []*SpeechRecognitionMenu) (err error) {
  62. if len(items) == 0 {
  63. return
  64. }
  65. o := orm.NewOrm()
  66. _, err = o.InsertMulti(len(items), items)
  67. return
  68. }
  69. func (m *SpeechRecognitionMenu) Update(cols []string) (err error) {
  70. o := orm.NewOrm()
  71. _, err = o.Update(m, cols...)
  72. return
  73. }
  74. func (m *SpeechRecognitionMenu) Del() (err error) {
  75. o := orm.NewOrm()
  76. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  77. _, err = o.Raw(sql, m.SpeechRecognitionMenuId).Exec()
  78. return
  79. }
  80. func (m *SpeechRecognitionMenu) MultiDel(menuIds []int) (err error) {
  81. if len(menuIds) == 0 {
  82. return
  83. }
  84. o := orm.NewOrm()
  85. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  86. _, err = o.Raw(sql, menuIds).Exec()
  87. return
  88. }
  89. func (m *SpeechRecognitionMenu) GetItemById(id int) (item *SpeechRecognitionMenu, err error) {
  90. o := orm.NewOrm()
  91. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  92. err = o.Raw(sql, id).QueryRow(&item)
  93. return
  94. }
  95. func (m *SpeechRecognitionMenu) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SpeechRecognitionMenu, err error) {
  96. o := orm.NewOrm()
  97. order := ``
  98. if orderRule != "" {
  99. order = ` ORDER BY ` + orderRule
  100. }
  101. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  102. err = o.Raw(sql, pars).QueryRow(&item)
  103. return
  104. }
  105. func (m *SpeechRecognitionMenu) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  106. o := orm.NewOrm()
  107. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  108. err = o.Raw(sql, pars).QueryRow(&count)
  109. return
  110. }
  111. func (m *SpeechRecognitionMenu) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SpeechRecognitionMenu, err error) {
  112. o := orm.NewOrm()
  113. fields := strings.Join(fieldArr, ",")
  114. if len(fieldArr) == 0 {
  115. fields = `*`
  116. }
  117. order := `ORDER BY create_time DESC`
  118. if orderRule != "" {
  119. order = ` ORDER BY ` + orderRule
  120. }
  121. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  122. _, err = o.Raw(sql, pars).QueryRows(&items)
  123. return
  124. }
  125. func (m *SpeechRecognitionMenu) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SpeechRecognitionMenu, err error) {
  126. o := orm.NewOrm()
  127. fields := strings.Join(fieldArr, ",")
  128. if len(fieldArr) == 0 {
  129. fields = `*`
  130. }
  131. order := `ORDER BY create_time DESC`
  132. if orderRule != "" {
  133. order = ` ORDER BY ` + orderRule
  134. }
  135. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  136. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  137. return
  138. }
  139. // SpeechRecognitionMenuNodeItem 语音识别目录节点
  140. type SpeechRecognitionMenuNodeItem struct {
  141. UniqueCode string `description:"唯一编码"`
  142. NodeType int `description:"节点类型:0-目录;1-语音识别"`
  143. MenuId int `description:"目录ID"`
  144. MenuName string `description:"目录名称"`
  145. SpeechRecognitionId int `description:"语音识别ID"`
  146. SpeechRecognitionName string `description:"语音识别名称"`
  147. ParentId int `description:"父级ID"`
  148. Level int `description:"目录层级"`
  149. Sort int `description:"排序"`
  150. CreateTime string `description:"创建时间"`
  151. Children []*SpeechRecognitionMenuNodeItem `description:"子节点"`
  152. }
  153. // SpeechRecognitionMenuAddReq 新增语音识别目录
  154. type SpeechRecognitionMenuAddReq struct {
  155. ParentId int `description:"父级ID"`
  156. MenuName string `description:"目录名称"`
  157. }
  158. // SpeechRecognitionMenuEditReq 编辑语音识别目录
  159. type SpeechRecognitionMenuEditReq struct {
  160. MenuId int `description:"目录ID"`
  161. MenuName string `description:"目录名称"`
  162. }
  163. // SpeechRecognitionMenuRemoveReq 删除语音识别目录
  164. type SpeechRecognitionMenuRemoveReq struct {
  165. MenuId int `description:"目录ID"`
  166. }
  167. // SpeechRecognitionMenuMoveReq 移动目录请求体
  168. type SpeechRecognitionMenuMoveReq struct {
  169. MenuId int `description:"目录ID"`
  170. ParentMenuId int `description:"父级目录ID"`
  171. PrevMenuId int `description:"上一个兄弟节点目录ID"`
  172. NextMenuId int `description:"下一个兄弟节点目录ID"`
  173. SpeechId int `description:"语音识别ID, 大于0则表示移动语音识别"`
  174. PrevSpeechId int `description:"上一个语音识别ID"`
  175. NextSpeechId int `description:"下一个语音识别ID"`
  176. }