package speech_recognition import ( "eta/eta_api/utils" "fmt" "github.com/beego/beego/v2/client/orm" "strings" "time" ) const ( SpeechRecognitionMenuNodeTypeDefault = 0 SpeechRecognitionMenuNodeTypeSpeech = 1 ) // SpeechRecognitionMenu 语音识别-目录表 type SpeechRecognitionMenu struct { SpeechRecognitionMenuId int `orm:"column(speech_recognition_menu_id);pk"` MenuName string `description:"目录名称"` ParentId int `description:"父级ID"` Level int `description:"目录层级"` Sort int `description:"排序"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` } var SpeechRecognitionMenuCols = struct { SpeechRecognitionMenuId string MenuName string ParentId string Level string Sort string CreateTime string ModifyTime string }{ SpeechRecognitionMenuId: "speech_recognition_menu_id", MenuName: "menu_name", ParentId: "parent_id", Level: "level", Sort: "sort", CreateTime: "create_time", ModifyTime: "modify_time", } func (m *SpeechRecognitionMenu) TableName() string { return "speech_recognition_menu" } func (m *SpeechRecognitionMenu) PrimaryId() string { return SpeechRecognitionMenuCols.SpeechRecognitionMenuId } func (m *SpeechRecognitionMenu) Create() (err error) { o := orm.NewOrm() id, err := o.Insert(m) if err != nil { return } m.SpeechRecognitionMenuId = int(id) return } func (m *SpeechRecognitionMenu) CreateMulti(items []*SpeechRecognitionMenu) (err error) { if len(items) == 0 { return } o := orm.NewOrm() _, err = o.InsertMulti(len(items), items) return } func (m *SpeechRecognitionMenu) Update(cols []string) (err error) { o := orm.NewOrm() _, err = o.Update(m, cols...) return } func (m *SpeechRecognitionMenu) 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.SpeechRecognitionMenuId).Exec() return } func (m *SpeechRecognitionMenu) 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 *SpeechRecognitionMenu) GetItemById(id int) (item *SpeechRecognitionMenu, 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 *SpeechRecognitionMenu) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SpeechRecognitionMenu, 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 *SpeechRecognitionMenu) 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 *SpeechRecognitionMenu) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SpeechRecognitionMenu, 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 *SpeechRecognitionMenu) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SpeechRecognitionMenu, 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 } // SpeechRecognitionMenuNodeItem 语音识别目录节点 type SpeechRecognitionMenuNodeItem struct { NodeType int `description:"节点类型:0-目录;1-语音识别"` MenuId int `description:"目录ID"` MenuName string `description:"目录名称"` SpeechRecognitionId int `description:"语音识别ID"` SpeechRecognitionName string `description:"语音识别名称"` ParentId int `description:"父级ID"` Sort int `description:"排序"` CreateTime string `description:"创建时间"` Children []*SpeechRecognitionMenuNodeItem `description:"子节点"` } // SpeechRecognitionMenuAddReq 新增语音识别目录 type SpeechRecognitionMenuAddReq struct { ParentId int `description:"父级ID"` MenuName string `description:"目录名称"` } // SpeechRecognitionMenuEditReq 编辑语音识别目录 type SpeechRecognitionMenuEditReq struct { MenuId int `description:"目录ID"` MenuName string `description:"目录名称"` } // SpeechRecognitionMenuRemoveReq 删除语音识别目录 type SpeechRecognitionMenuRemoveReq struct { MenuId int `description:"目录ID"` }