speech_recognition_api_log.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package speech_recognition
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/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. type SpeechRecognitionApiLog struct {
  24. Id int `gorm:"primaryKey;column:id;type:int(10) unsigned;not null"`
  25. SpeechRecognitionId int `gorm:"index:idx_speech_id;column:speech_recognition_id;type:int(10) unsigned;not null;default:0"` // 语音识别Id
  26. RequestId string `gorm:"column:request_id;type:varchar(64);not null;default:''"` // Api请求的唯一标识TaskId
  27. RequestCode int `gorm:"column:request_code;type:int(10);not null;default:-1"` // Api请求结果状态码:0-成功;其他-失败
  28. RequestResult string `gorm:"column:request_result;type:mediumtext"` // Api请求结果-JSON
  29. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  30. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 更新时间
  31. }
  32. var SpeechRecognitionApiLogCols = struct {
  33. Id string
  34. SpeechRecognitionId string
  35. RequestId string
  36. RequestCode string
  37. RequestResult string
  38. CreateTime string
  39. ModifyTime string
  40. }{
  41. Id: "id",
  42. SpeechRecognitionId: "speech_recognition_id",
  43. RequestId: "request_id",
  44. RequestCode: "request_code",
  45. RequestResult: "request_result",
  46. CreateTime: "create_time",
  47. ModifyTime: "modify_time",
  48. }
  49. func (m *SpeechRecognitionApiLog) TableName() string {
  50. return "speech_recognition_api_log"
  51. }
  52. func (m *SpeechRecognitionApiLog) PrimaryId() string {
  53. return SpeechRecognitionApiLogCols.Id
  54. }
  55. func (m *SpeechRecognitionApiLog) Create() (err error) {
  56. err = global.DEFAULT_DmSQL.Create(m).Error
  57. return
  58. }
  59. func (m *SpeechRecognitionApiLog) CreateMulti(items []*SpeechRecognitionApiLog) (err error) {
  60. if len(items) == 0 {
  61. return
  62. }
  63. err = global.DEFAULT_DmSQL.CreateInBatches(items, utils.MultiAddNum).Error
  64. return
  65. }
  66. func (m *SpeechRecognitionApiLog) Update(cols []string) (err error) {
  67. err = global.DEFAULT_DmSQL.Select(cols).Updates(m).Error
  68. return
  69. }
  70. func (m *SpeechRecognitionApiLog) Del() (err error) {
  71. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  72. err = global.DEFAULT_DmSQL.Exec(sql, m.Id).Error
  73. return
  74. }
  75. func (m *SpeechRecognitionApiLog) MultiDel(menuIds []int) (err error) {
  76. if len(menuIds) == 0 {
  77. return
  78. }
  79. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  80. err = global.DEFAULT_DmSQL.Exec(sql, menuIds).Error
  81. return
  82. }
  83. func (m *SpeechRecognitionApiLog) GetItemById(id int) (item *SpeechRecognitionApiLog, err error) {
  84. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  85. err = global.DEFAULT_DmSQL.Raw(sql, id).First(&item).Error
  86. return
  87. }
  88. func (m *SpeechRecognitionApiLog) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SpeechRecognitionApiLog, err error) {
  89. order := ``
  90. if orderRule != "" {
  91. order = ` ORDER BY ` + orderRule
  92. }
  93. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  94. err = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&item).Error
  95. return
  96. }
  97. func (m *SpeechRecognitionApiLog) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  98. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  99. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
  100. return
  101. }
  102. func (m *SpeechRecognitionApiLog) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SpeechRecognitionApiLog, err error) {
  103. fields := strings.Join(fieldArr, ",")
  104. if len(fieldArr) == 0 {
  105. fields = `*`
  106. }
  107. order := `ORDER BY create_time DESC`
  108. if orderRule != "" {
  109. order = ` ORDER BY ` + orderRule
  110. }
  111. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  112. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  113. return
  114. }
  115. func (m *SpeechRecognitionApiLog) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SpeechRecognitionApiLog, err error) {
  116. fields := strings.Join(fieldArr, ",")
  117. if len(fieldArr) == 0 {
  118. fields = `*`
  119. }
  120. order := `ORDER BY create_time DESC`
  121. if orderRule != "" {
  122. order = ` ORDER BY ` + orderRule
  123. }
  124. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  125. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
  126. return
  127. }