speech_recognition_api_log.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. // SpeechRecognitionApiLog 语音识别-API请求日志
  10. type SpeechRecognitionApiLog struct {
  11. Id int `orm:"column(id);pk"`
  12. SpeechRecognitionId int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  13. RequestId string `description:"API请求的唯一标识TaskId"`
  14. RequestResult string `description:"API请求结果-JSON"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"修改时间"`
  17. }
  18. var SpeechRecognitionApiLogCols = struct {
  19. Id string
  20. SpeechRecognitionId string
  21. RequestId string
  22. RequestResult string
  23. CreateTime string
  24. ModifyTime string
  25. }{
  26. Id: "id",
  27. SpeechRecognitionId: "speech_recognition_id",
  28. RequestId: "request_id",
  29. RequestResult: "request_result",
  30. CreateTime: "create_time",
  31. ModifyTime: "modify_time",
  32. }
  33. func (m *SpeechRecognitionApiLog) TableName() string {
  34. return "speech_recognition_api_log"
  35. }
  36. func (m *SpeechRecognitionApiLog) PrimaryId() string {
  37. return SpeechRecognitionApiLogCols.Id
  38. }
  39. func (m *SpeechRecognitionApiLog) Create() (err error) {
  40. o := orm.NewOrm()
  41. id, err := o.Insert(m)
  42. if err != nil {
  43. return
  44. }
  45. m.Id = int(id)
  46. return
  47. }
  48. func (m *SpeechRecognitionApiLog) CreateMulti(items []*SpeechRecognitionApiLog) (err error) {
  49. if len(items) == 0 {
  50. return
  51. }
  52. o := orm.NewOrm()
  53. _, err = o.InsertMulti(len(items), items)
  54. return
  55. }
  56. func (m *SpeechRecognitionApiLog) Update(cols []string) (err error) {
  57. o := orm.NewOrm()
  58. _, err = o.Update(m, cols...)
  59. return
  60. }
  61. func (m *SpeechRecognitionApiLog) Del() (err error) {
  62. o := orm.NewOrm()
  63. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  64. _, err = o.Raw(sql, m.Id).Exec()
  65. return
  66. }
  67. func (m *SpeechRecognitionApiLog) MultiDel(menuIds []int) (err error) {
  68. if len(menuIds) == 0 {
  69. return
  70. }
  71. o := orm.NewOrm()
  72. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  73. _, err = o.Raw(sql, menuIds).Exec()
  74. return
  75. }
  76. func (m *SpeechRecognitionApiLog) GetItemById(id int) (item *SpeechRecognitionApiLog, err error) {
  77. o := orm.NewOrm()
  78. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  79. err = o.Raw(sql, id).QueryRow(&item)
  80. return
  81. }
  82. func (m *SpeechRecognitionApiLog) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SpeechRecognitionApiLog, err error) {
  83. o := orm.NewOrm()
  84. order := ``
  85. if orderRule != "" {
  86. order = ` ORDER BY ` + orderRule
  87. }
  88. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  89. err = o.Raw(sql, pars).QueryRow(&item)
  90. return
  91. }
  92. func (m *SpeechRecognitionApiLog) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  93. o := orm.NewOrm()
  94. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  95. err = o.Raw(sql, pars).QueryRow(&count)
  96. return
  97. }
  98. func (m *SpeechRecognitionApiLog) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SpeechRecognitionApiLog, err error) {
  99. o := orm.NewOrm()
  100. fields := strings.Join(fieldArr, ",")
  101. if len(fieldArr) == 0 {
  102. fields = `*`
  103. }
  104. order := `ORDER BY create_time DESC`
  105. if orderRule != "" {
  106. order = ` ORDER BY ` + orderRule
  107. }
  108. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  109. _, err = o.Raw(sql, pars).QueryRows(&items)
  110. return
  111. }
  112. func (m *SpeechRecognitionApiLog) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SpeechRecognitionApiLog, err error) {
  113. o := orm.NewOrm()
  114. fields := strings.Join(fieldArr, ",")
  115. if len(fieldArr) == 0 {
  116. fields = `*`
  117. }
  118. order := `ORDER BY create_time DESC`
  119. if orderRule != "" {
  120. order = ` ORDER BY ` + orderRule
  121. }
  122. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  123. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  124. return
  125. }