speech_recognition_api_log.go 5.1 KB

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