123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- package speech_recognition
- import (
- "eta/eta_api/utils"
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "strings"
- "time"
- )
- const (
- SpeechRecognitionFileRemoveFlag = 1 // 文件删除标记
- SpeechRecognitionStateWait = 1
- SpeechRecognitionStateSuccess = 2
- SpeechRecognitionStateFail = 3
- )
- // 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-转换失败"`
- Abstract string `description:"摘要,取前几段内容"`
- Sort int `description:"目录下的排序"`
- FileState int `description:"文件(非语音识别)删除状态:0-正常;1-删除(该字段作为软删标识)"`
- ConvertRemark int `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
- Sort string
- FileState string
- ConvertRemark 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",
- Sort: "sort",
- FileState: "file_state",
- ConvertRemark: "convert_remark",
- CreateTime: "create_time",
- ModifyTime: "modify_time",
- }
- func (m *SpeechRecognition) TableName() string {
- return "speech_recognition"
- }
- 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
- }
- // SpeechRecognitionItem 语音识别信息
- type SpeechRecognitionItem struct {
- SpeechRecognitionId int
- 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-转换失败"`
- Abstract string `description:"摘要,取前几段内容"`
- Sort int `description:"目录下的排序"`
- ConvertRemark int `description:"转写备注-失败原因"`
- CreateTime string `description:"创建时间"`
- ModifyTime string `description:"修改时间"`
- }
- func FormatSpeechRecognition2Item(origin *SpeechRecognition) (item *SpeechRecognitionItem) {
- if origin == nil {
- return
- }
- item = new(SpeechRecognitionItem)
- item.SpeechRecognitionId = origin.SpeechRecognitionId
- item.FileName = origin.FileName
- item.ResourceUrl = origin.ResourceUrl
- if origin.FileState == SpeechRecognitionFileRemoveFlag {
- item.ResourceUrl = ""
- }
- item.MenuId = origin.MenuId
- item.MenuPath = origin.MenuPath
- item.SysUserId = origin.SysUserId
- item.SysUserName = origin.SysUserName
- item.State = origin.State
- item.Abstract = origin.Abstract
- item.Sort = origin.Sort
- item.ConvertRemark = origin.ConvertRemark
- item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
- item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
- return
- }
- // SpeechRecognitionSaveReq 保存请求体
- type SpeechRecognitionSaveReq struct {
- FileName string
- }
- // SpeechRecognitionRenameReq 重命名
- type SpeechRecognitionRenameReq struct {
- SpeechRecognitionId int `description:"语音识别ID"`
- FileName string `description:"文件名称"`
- }
- // SpeechRecognitionRemoveReq 删除
- type SpeechRecognitionRemoveReq struct {
- SpeechRecognitionId int `description:"语音识别ID"`
- }
- // SpeechRecognitionRemoveFileReq 删除文件
- type SpeechRecognitionRemoveFileReq struct {
- SpeechRecognitionId int `description:"语音识别ID"`
- }
- // SpeechRecognitionSaveTagReq 保存标签
- type SpeechRecognitionSaveTagReq struct {
- SpeechRecognitionId int `description:"语音识别ID"`
- TagIds []int `description:"标签IDs"`
- }
- // SpeechRecognitionConvertReq 批量转写
- type SpeechRecognitionConvertReq struct {
- MenuId int `description:"目录ID"`
- Files []SpeechRecognitionConvertFiles `description:"转写文件"`
- }
- // SpeechRecognitionConvertFiles 批量转写文件
- type SpeechRecognitionConvertFiles struct {
- FileName string `description:"文件名称"`
- ResourceUrl string `description:"文件地址"`
- }
|