speech_recognition_api_log.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package speech_recognition
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "fmt"
  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" gorm:"primaryKey"`
  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 := global.DbMap[utils.DbNameMaster]
  58. err = o.Create(m).Error
  59. return
  60. }
  61. func (m *SpeechRecognitionApiLog) CreateMulti(items []*SpeechRecognitionApiLog) (err error) {
  62. if len(items) == 0 {
  63. return
  64. }
  65. o := global.DbMap[utils.DbNameMaster]
  66. err = o.CreateInBatches(items, utils.MultiAddNum).Error
  67. return
  68. }
  69. func (m *SpeechRecognitionApiLog) Update(cols []string) (err error) {
  70. o := global.DbMap[utils.DbNameMaster]
  71. err = o.Select(cols).Updates(m).Error
  72. return
  73. }
  74. func (m *SpeechRecognitionApiLog) Del() (err error) {
  75. o := global.DbMap[utils.DbNameMaster]
  76. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  77. err = o.Exec(sql, m.Id).Error
  78. return
  79. }
  80. func (m *SpeechRecognitionApiLog) MultiDel(menuIds []int) (err error) {
  81. if len(menuIds) == 0 {
  82. return
  83. }
  84. o := global.DbMap[utils.DbNameMaster]
  85. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  86. err = o.Exec(sql, menuIds).Error
  87. return
  88. }
  89. func (m *SpeechRecognitionApiLog) GetItemById(id int) (item *SpeechRecognitionApiLog, err error) {
  90. o := global.DbMap[utils.DbNameMaster]
  91. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  92. err = o.Raw(sql, id).First(&item).Error
  93. return
  94. }
  95. func (m *SpeechRecognitionApiLog) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SpeechRecognitionApiLog, err error) {
  96. o := global.DbMap[utils.DbNameMaster]
  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...).First(&item).Error
  103. return
  104. }
  105. func (m *SpeechRecognitionApiLog) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  106. o := global.DbMap[utils.DbNameMaster]
  107. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  108. err = o.Raw(sql, pars...).Scan(&count).Error
  109. return
  110. }
  111. func (m *SpeechRecognitionApiLog) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SpeechRecognitionApiLog, err error) {
  112. o := global.DbMap[utils.DbNameMaster]
  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...).Find(&items).Error
  123. return
  124. }
  125. func (m *SpeechRecognitionApiLog) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SpeechRecognitionApiLog, err error) {
  126. o := global.DbMap[utils.DbNameMaster]
  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. pars = append(pars, startSize, pageSize)
  137. err = o.Raw(sql, pars...).Find(&items).Error
  138. return
  139. }