speech_recognition_api_log.go 6.5 KB

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