package speech_recognition import ( "eta/eta_api/utils" "fmt" "github.com/beego/beego/v2/client/orm" "strings" "time" ) // SpeechRecognition 语音识别主表 type SpeechRecognition struct { SpeechRecognitionId int `orm:"column(speech_recognition_id);pk"` FileName string `description:"文件名称"` ResourceUrl string `description:"文件路径"` MenuId int `description:"目录ID"` MenuPath string `description:"所属目录位置,例:/一级目录ID/二级目录ID"` SysUserId int `description:"创建人ID"` SysUserName string `description:"创建人姓名"` State int `description:"状态:1-待转换;2-转换中;3-转换完成;4-转换失败"` Abstract string `description:"摘要,取前几段内容"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` } var SpeechRecognitionCols = struct { SpeechRecognitionId string FileName string ResourceUrl string MenuId string MenuPath string SysUserId string SysUserName string State string Abstract string CreateTime string ModifyTime string }{ SpeechRecognitionId: "speech_recognition_id", FileName: "file_name", ResourceUrl: "resource_url", MenuId: "menu_id", MenuPath: "menu_path", SysUserId: "sys_user_id", SysUserName: "sys_user_name", State: "state", Abstract: "abstract", CreateTime: "create_time", ModifyTime: "modify_time", } func (m *SpeechRecognition) TableName() string { return "speech_recognition_id" } func (m *SpeechRecognition) PrimaryId() string { return SpeechRecognitionCols.SpeechRecognitionId } func (m *SpeechRecognition) Create() (err error) { o := orm.NewOrm() id, err := o.Insert(m) if err != nil { return } m.SpeechRecognitionId = int(id) return } func (m *SpeechRecognition) CreateMulti(items []*SpeechRecognition) (err error) { if len(items) == 0 { return } o := orm.NewOrm() _, err = o.InsertMulti(len(items), items) return } func (m *SpeechRecognition) Update(cols []string) (err error) { o := orm.NewOrm() _, err = o.Update(m, cols...) return } func (m *SpeechRecognition) Del() (err error) { o := orm.NewOrm() sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId()) _, err = o.Raw(sql, m.SpeechRecognitionId).Exec() return } func (m *SpeechRecognition) MultiDel(menuIds []int) (err error) { if len(menuIds) == 0 { return } o := orm.NewOrm() sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds))) _, err = o.Raw(sql, menuIds).Exec() return } func (m *SpeechRecognition) GetItemById(id int) (item *SpeechRecognition, err error) { o := orm.NewOrm() sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId()) err = o.Raw(sql, id).QueryRow(&item) return } func (m *SpeechRecognition) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SpeechRecognition, err error) { o := orm.NewOrm() 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 = o.Raw(sql, pars).QueryRow(&item) return } func (m *SpeechRecognition) GetCountByCondition(condition string, pars []interface{}) (count int, err error) { o := orm.NewOrm() sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition) err = o.Raw(sql, pars).QueryRow(&count) return } func (m *SpeechRecognition) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SpeechRecognition, err error) { o := orm.NewOrm() 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 = o.Raw(sql, pars).QueryRows(&items) return } func (m *SpeechRecognition) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SpeechRecognition, err error) { o := orm.NewOrm() 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 = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items) return } // SpeechRecognitionSaveReq 保存请求体 type SpeechRecognitionSaveReq struct { FileName string }