speech_recognition_api_log.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package speech_recognition
  2. import (
  3. "eta/eta_mobile/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "strings"
  7. "time"
  8. )
  9. const (
  10. ApiRequestCodeSuccess = 0 // API成功状态码
  11. )
  12. // ApiErrMsgMapping API请求结果状态码对应错误提示
  13. var ApiErrMsgMapping = map[int]string{
  14. 10000: "转码失败,请确认音频格式是否符合标准",
  15. 10001: "识别失败",
  16. 10002: "语音时长太短",
  17. 10003: "语音时长太长",
  18. 10004: "无效的语音文件",
  19. 10005: "其他失败",
  20. 10006: "音轨个数不匹配",
  21. 10007: "音频下载失败",
  22. }
  23. // SpeechRecognitionApiLog 语音识别-API请求日志
  24. type SpeechRecognitionApiLog struct {
  25. Id int `orm:"column(id);pk"`
  26. SpeechRecognitionId int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  27. RequestId string `description:"API请求的唯一标识TaskId"`
  28. RequestCode int `description:"API请求结果状态码:-1-待请求;0-成功;其他-失败"`
  29. RequestResult string `description:"API请求结果-JSON"`
  30. CreateTime time.Time `description:"创建时间"`
  31. ModifyTime time.Time `description:"修改时间"`
  32. }
  33. var SpeechRecognitionApiLogCols = struct {
  34. Id string
  35. SpeechRecognitionId string
  36. RequestId string
  37. RequestCode string
  38. RequestResult string
  39. CreateTime string
  40. ModifyTime string
  41. }{
  42. Id: "id",
  43. SpeechRecognitionId: "speech_recognition_id",
  44. RequestId: "request_id",
  45. RequestCode: "request_code",
  46. RequestResult: "request_result",
  47. CreateTime: "create_time",
  48. ModifyTime: "modify_time",
  49. }
  50. func (m *SpeechRecognitionApiLog) TableName() string {
  51. return "speech_recognition_api_log"
  52. }
  53. func (m *SpeechRecognitionApiLog) PrimaryId() string {
  54. return SpeechRecognitionApiLogCols.Id
  55. }
  56. func (m *SpeechRecognitionApiLog) Create() (err error) {
  57. o := orm.NewOrm()
  58. id, err := o.Insert(m)
  59. if err != nil {
  60. return
  61. }
  62. m.Id = int(id)
  63. return
  64. }
  65. func (m *SpeechRecognitionApiLog) CreateMulti(items []*SpeechRecognitionApiLog) (err error) {
  66. if len(items) == 0 {
  67. return
  68. }
  69. o := orm.NewOrm()
  70. _, err = o.InsertMulti(len(items), items)
  71. return
  72. }
  73. func (m *SpeechRecognitionApiLog) Update(cols []string) (err error) {
  74. o := orm.NewOrm()
  75. _, err = o.Update(m, cols...)
  76. return
  77. }
  78. func (m *SpeechRecognitionApiLog) Del() (err error) {
  79. o := orm.NewOrm()
  80. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  81. _, err = o.Raw(sql, m.Id).Exec()
  82. return
  83. }
  84. func (m *SpeechRecognitionApiLog) MultiDel(menuIds []int) (err error) {
  85. if len(menuIds) == 0 {
  86. return
  87. }
  88. o := orm.NewOrm()
  89. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  90. _, err = o.Raw(sql, menuIds).Exec()
  91. return
  92. }
  93. func (m *SpeechRecognitionApiLog) GetItemById(id int) (item *SpeechRecognitionApiLog, err error) {
  94. o := orm.NewOrm()
  95. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  96. err = o.Raw(sql, id).QueryRow(&item)
  97. return
  98. }
  99. func (m *SpeechRecognitionApiLog) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SpeechRecognitionApiLog, err error) {
  100. o := orm.NewOrm()
  101. order := ``
  102. if orderRule != "" {
  103. order = ` ORDER BY ` + orderRule
  104. }
  105. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  106. err = o.Raw(sql, pars).QueryRow(&item)
  107. return
  108. }
  109. func (m *SpeechRecognitionApiLog) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  110. o := orm.NewOrm()
  111. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  112. err = o.Raw(sql, pars).QueryRow(&count)
  113. return
  114. }
  115. func (m *SpeechRecognitionApiLog) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SpeechRecognitionApiLog, err error) {
  116. o := orm.NewOrm()
  117. fields := strings.Join(fieldArr, ",")
  118. if len(fieldArr) == 0 {
  119. fields = `*`
  120. }
  121. order := `ORDER BY create_time DESC`
  122. if orderRule != "" {
  123. order = ` ORDER BY ` + orderRule
  124. }
  125. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  126. _, err = o.Raw(sql, pars).QueryRows(&items)
  127. return
  128. }
  129. func (m *SpeechRecognitionApiLog) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SpeechRecognitionApiLog, err error) {
  130. o := orm.NewOrm()
  131. fields := strings.Join(fieldArr, ",")
  132. if len(fieldArr) == 0 {
  133. fields = `*`
  134. }
  135. order := `ORDER BY create_time DESC`
  136. if orderRule != "" {
  137. order = ` ORDER BY ` + orderRule
  138. }
  139. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  140. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  141. return
  142. }