package speech_recognition import ( "eta_gn/eta_api/global" "eta_gn/eta_api/utils" "fmt" "strings" "time" ) const ( ApiRequestCodeSuccess = 0 // API成功状态码 ) // ApiErrMsgMapping API请求结果状态码对应错误提示 var ApiErrMsgMapping = map[int]string{ 10000: "转码失败,请确认音频格式是否符合标准", 10001: "识别失败", 10002: "语音时长太短", 10003: "语音时长太长", 10004: "无效的语音文件", 10005: "其他失败", 10006: "音轨个数不匹配", 10007: "音频下载失败", } type SpeechRecognitionApiLog struct { Id int `gorm:"primaryKey;column:id;type:int(10) unsigned;not null"` SpeechRecognitionId int `gorm:"index:idx_speech_id;column:speech_recognition_id;type:int(10) unsigned;not null;default:0"` // 语音识别Id RequestId string `gorm:"column:request_id;type:varchar(64);not null;default:''"` // Api请求的唯一标识TaskId RequestCode int `gorm:"column:request_code;type:int(10);not null;default:-1"` // Api请求结果状态码:0-成功;其他-失败 RequestResult string `gorm:"column:request_result;type:mediumtext"` // Api请求结果-JSON CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间 ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 更新时间 } var SpeechRecognitionApiLogCols = struct { Id string SpeechRecognitionId string RequestId string RequestCode string RequestResult string CreateTime string ModifyTime string }{ Id: "id", SpeechRecognitionId: "speech_recognition_id", RequestId: "request_id", RequestCode: "request_code", RequestResult: "request_result", CreateTime: "create_time", ModifyTime: "modify_time", } func (m *SpeechRecognitionApiLog) TableName() string { return "speech_recognition_api_log" } func (m *SpeechRecognitionApiLog) PrimaryId() string { return SpeechRecognitionApiLogCols.Id } func (m *SpeechRecognitionApiLog) Create() (err error) { err = global.DEFAULT_DmSQL.Create(m).Error return } func (m *SpeechRecognitionApiLog) CreateMulti(items []*SpeechRecognitionApiLog) (err error) { if len(items) == 0 { return } err = global.DEFAULT_DmSQL.CreateInBatches(items, utils.MultiAddNum).Error return } func (m *SpeechRecognitionApiLog) Update(cols []string) (err error) { err = global.DEFAULT_DmSQL.Select(cols).Updates(m).Error return } func (m *SpeechRecognitionApiLog) Del() (err error) { sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId()) err = global.DEFAULT_DmSQL.Exec(sql, m.Id).Error return } func (m *SpeechRecognitionApiLog) MultiDel(menuIds []int) (err error) { if len(menuIds) == 0 { return } sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds))) err = global.DEFAULT_DmSQL.Exec(sql, menuIds).Error return } func (m *SpeechRecognitionApiLog) GetItemById(id int) (item *SpeechRecognitionApiLog, err error) { sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId()) err = global.DEFAULT_DmSQL.Raw(sql, id).First(&item).Error return } func (m *SpeechRecognitionApiLog) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SpeechRecognitionApiLog, err error) { order := `` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order) err = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&item).Error return } func (m *SpeechRecognitionApiLog) GetCountByCondition(condition string, pars []interface{}) (count int, err error) { sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition) err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error return } func (m *SpeechRecognitionApiLog) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SpeechRecognitionApiLog, err error) { fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := `ORDER BY create_time DESC` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order) err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error return } func (m *SpeechRecognitionApiLog) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SpeechRecognitionApiLog, err error) { fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := `ORDER BY create_time DESC` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order) err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error return }