上传音频时保存车站号,车次,车站到火车信息表,提供火车信息查询接口
| | |
| | | func (slf BoolType) Bool() bool { |
| | | return slf == BoolTypeTrue |
| | | } |
| | | |
| | | type Class int |
| | | |
| | | const ( |
| | | ClassLocomotive Class = 1 //机车 |
| | | ClassTrain Class = 2 //车次 |
| | | ClassStation Class = 3 //车站 |
| | | ) |
| | |
| | | LocomotiveNumber: arr[0], |
| | | TrainNumber: arr[1], |
| | | DriverNumber: arr[2], |
| | | StationNumber: arr[3], |
| | | Station: arr[3], |
| | | OccurrenceAt: t, |
| | | IsFollowed: 0, |
| | | } |
| | |
| | | util.ResponseFormat(c, code.SaveFail, "上传失败") |
| | | return |
| | | } |
| | | go func() { |
| | | |
| | | var trainInfoNames = []string{arr[0], arr[1], arr[3]} |
| | | |
| | | var ( |
| | | info *models.TrainInfo |
| | | err error |
| | | parent models.TrainInfo |
| | | ) |
| | | for i := 0; i < 3; i++ { |
| | | name := trainInfoNames[i] |
| | | class := constvar.Class(i + 1) |
| | | info, err = models.NewTrainInfoSearch().SetName(name).SetClass(class).First() |
| | | if err == gorm.ErrRecordNotFound { |
| | | info = &models.TrainInfo{ |
| | | Name: name, |
| | | Class: class, |
| | | ParentID: parent.ID, |
| | | } |
| | | _ = models.NewTrainInfoSearch().Create(info) |
| | | } |
| | | parent = *info |
| | | } |
| | | |
| | | }() |
| | | |
| | | util.ResponseFormat(c, code.Success, "添加成功") |
| | | } |
| | |
| | | return errors.New("文件格式错误") |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | // TrainInfoList |
| | | // @Tags 音频 |
| | | // @Summary 获取火车信息 |
| | | // @Produce application/json |
| | | // @Param object query request.GetTrainInfoList true "参数" |
| | | // @Success 200 {object} util.ResponseList{data=[]models.TrainInfo} "成功" |
| | | // @Router /api-sa/v1/audio/trainInfoList [get] |
| | | func (slf AudioCtl) TrainInfoList(c *gin.Context) { |
| | | var params request.GetTrainInfoList |
| | | if err := c.ShouldBindQuery(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | if !params.PageInfo.Check() { |
| | | util.ResponseFormat(c, code.RequestParamError, "分页参数错误") |
| | | return |
| | | } |
| | | |
| | | list, total, err := models.NewTrainInfoSearch(). |
| | | SetPage(params.Page, params.PageSize). |
| | | SetClass(params.Class). |
| | | SetParentId(params.ParentID). |
| | | Find() |
| | | |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查找失败") |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormatList(c, code.Success, list, total) |
| | | } |
| | | |
| | | // List |
| | |
| | | SetLocomotiveNumber(params.LocomotiveNumber). |
| | | SetTrainNumber(params.TrainNumber). |
| | | SetDriverNumber(params.DriverNumber). |
| | | SetStationNumber(params.StationNumber). |
| | | SetStation(params.StationNumber). |
| | | Find() |
| | | |
| | | if err != nil { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api-sa/v1/audio/trainInfoList": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "音频" |
| | | ], |
| | | "summary": "获取火车信息", |
| | | "parameters": [ |
| | | { |
| | | "enum": [ |
| | | 1, |
| | | 2, |
| | | 3 |
| | | ], |
| | | "type": "integer", |
| | | "x-enum-comments": { |
| | | "ClassLocomotive": "机车", |
| | | "ClassStation": "车站", |
| | | "ClassTrain": "车次" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "ClassLocomotive", |
| | | "ClassTrain", |
| | | "ClassStation" |
| | | ], |
| | | "description": "信息分类 1机车2车次3车站", |
| | | "name": "class", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "页码", |
| | | "name": "page", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "每页大小", |
| | | "name": "pageSize", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "上级id", |
| | | "name": "parentID", |
| | | "in": "query" |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/util.ResponseList" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/models.TrainInfo" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-sa/v1/audio/upload": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | "BoolTypeFalse" |
| | | ] |
| | | }, |
| | | "constvar.Class": { |
| | | "type": "integer", |
| | | "enum": [ |
| | | 1, |
| | | 2, |
| | | 3 |
| | | ], |
| | | "x-enum-comments": { |
| | | "ClassLocomotive": "机车", |
| | | "ClassStation": "车站", |
| | | "ClassTrain": "车次" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "ClassLocomotive", |
| | | "ClassTrain", |
| | | "ClassStation" |
| | | ] |
| | | }, |
| | | "gorm.DeletedAt": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "description": "音频大小", |
| | | "type": "integer" |
| | | }, |
| | | "stationNumber": { |
| | | "description": "车站号", |
| | | "station": { |
| | | "description": "车站", |
| | | "type": "string" |
| | | }, |
| | | "trainNumber": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "models.TrainInfo": { |
| | | "type": "object", |
| | | "properties": { |
| | | "class": { |
| | | "description": "分类", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.Class" |
| | | } |
| | | ] |
| | | }, |
| | | "createdAt": { |
| | | "type": "string" |
| | | }, |
| | | "deletedAt": { |
| | | "$ref": "#/definitions/gorm.DeletedAt" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "description": "名称", |
| | | "type": "string" |
| | | }, |
| | | "parentID": { |
| | | "description": "上级id", |
| | | "type": "integer" |
| | | }, |
| | | "updatedAt": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddTextReq": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api-sa/v1/audio/trainInfoList": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "音频" |
| | | ], |
| | | "summary": "获取火车信息", |
| | | "parameters": [ |
| | | { |
| | | "enum": [ |
| | | 1, |
| | | 2, |
| | | 3 |
| | | ], |
| | | "type": "integer", |
| | | "x-enum-comments": { |
| | | "ClassLocomotive": "机车", |
| | | "ClassStation": "车站", |
| | | "ClassTrain": "车次" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "ClassLocomotive", |
| | | "ClassTrain", |
| | | "ClassStation" |
| | | ], |
| | | "description": "信息分类 1机车2车次3车站", |
| | | "name": "class", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "页码", |
| | | "name": "page", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "每页大小", |
| | | "name": "pageSize", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "上级id", |
| | | "name": "parentID", |
| | | "in": "query" |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/util.ResponseList" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/models.TrainInfo" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-sa/v1/audio/upload": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | "BoolTypeFalse" |
| | | ] |
| | | }, |
| | | "constvar.Class": { |
| | | "type": "integer", |
| | | "enum": [ |
| | | 1, |
| | | 2, |
| | | 3 |
| | | ], |
| | | "x-enum-comments": { |
| | | "ClassLocomotive": "机车", |
| | | "ClassStation": "车站", |
| | | "ClassTrain": "车次" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "ClassLocomotive", |
| | | "ClassTrain", |
| | | "ClassStation" |
| | | ] |
| | | }, |
| | | "gorm.DeletedAt": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "description": "音频大小", |
| | | "type": "integer" |
| | | }, |
| | | "stationNumber": { |
| | | "description": "车站号", |
| | | "station": { |
| | | "description": "车站", |
| | | "type": "string" |
| | | }, |
| | | "trainNumber": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "models.TrainInfo": { |
| | | "type": "object", |
| | | "properties": { |
| | | "class": { |
| | | "description": "分类", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.Class" |
| | | } |
| | | ] |
| | | }, |
| | | "createdAt": { |
| | | "type": "string" |
| | | }, |
| | | "deletedAt": { |
| | | "$ref": "#/definitions/gorm.DeletedAt" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "description": "名称", |
| | | "type": "string" |
| | | }, |
| | | "parentID": { |
| | | "description": "上级id", |
| | | "type": "integer" |
| | | }, |
| | | "updatedAt": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddTextReq": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | x-enum-varnames: |
| | | - BoolTypeTrue |
| | | - BoolTypeFalse |
| | | constvar.Class: |
| | | enum: |
| | | - 1 |
| | | - 2 |
| | | - 3 |
| | | type: integer |
| | | x-enum-comments: |
| | | ClassLocomotive: 机车 |
| | | ClassStation: 车站 |
| | | ClassTrain: 车次 |
| | | x-enum-varnames: |
| | | - ClassLocomotive |
| | | - ClassTrain |
| | | - ClassStation |
| | | gorm.DeletedAt: |
| | | properties: |
| | | time: |
| | |
| | | size: |
| | | description: 音频大小 |
| | | type: integer |
| | | stationNumber: |
| | | description: 车站号 |
| | | station: |
| | | description: 车站 |
| | | type: string |
| | | trainNumber: |
| | | description: 车次 |
| | |
| | | locomotiveNumber: |
| | | description: 机车号 |
| | | type: string |
| | | updatedAt: |
| | | type: string |
| | | type: object |
| | | models.TrainInfo: |
| | | properties: |
| | | class: |
| | | allOf: |
| | | - $ref: '#/definitions/constvar.Class' |
| | | description: 分类 |
| | | createdAt: |
| | | type: string |
| | | deletedAt: |
| | | $ref: '#/definitions/gorm.DeletedAt' |
| | | id: |
| | | type: integer |
| | | name: |
| | | description: 名称 |
| | | type: string |
| | | parentID: |
| | | description: 上级id |
| | | type: integer |
| | | updatedAt: |
| | | type: string |
| | | type: object |
| | |
| | | summary: 处理音频 |
| | | tags: |
| | | - 音频 |
| | | /api-sa/v1/audio/trainInfoList: |
| | | get: |
| | | parameters: |
| | | - description: 信息分类 1机车2车次3车站 |
| | | enum: |
| | | - 1 |
| | | - 2 |
| | | - 3 |
| | | in: query |
| | | name: class |
| | | type: integer |
| | | x-enum-comments: |
| | | ClassLocomotive: 机车 |
| | | ClassStation: 车站 |
| | | ClassTrain: 车次 |
| | | x-enum-varnames: |
| | | - ClassLocomotive |
| | | - ClassTrain |
| | | - ClassStation |
| | | - description: 页码 |
| | | in: query |
| | | name: page |
| | | type: integer |
| | | - description: 每页大小 |
| | | in: query |
| | | name: pageSize |
| | | type: integer |
| | | - description: 上级id |
| | | in: query |
| | | name: parentID |
| | | type: integer |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | allOf: |
| | | - $ref: '#/definitions/util.ResponseList' |
| | | - properties: |
| | | data: |
| | | items: |
| | | $ref: '#/definitions/models.TrainInfo' |
| | | type: array |
| | | type: object |
| | | summary: 获取火车信息 |
| | | tags: |
| | | - 音频 |
| | | /api-sa/v1/audio/upload: |
| | | post: |
| | | parameters: |
| | |
| | | LocomotiveNumber string `gorm:"index;type:varchar(255);not null;default:'';comment:机车号" json:"locomotiveNumber"` // 机车号 |
| | | TrainNumber string `gorm:"index;type:varchar(255);not null;default:'';comment:车次" json:"trainNumber"` // 车次 |
| | | DriverNumber string `gorm:"index;type:varchar(255);not null;default:'';comment:司机号" json:"driverNumber"` // 司机号 |
| | | StationNumber string `gorm:"index;type:varchar(255);not null;default:'';comment:车站号" json:"stationNumber"` // 车站号 |
| | | Station string `gorm:"index;type:varchar(255);not null;default:'';comment:车站号" json:"station"` // 车站 |
| | | OccurrenceAt time.Time `json:"-"` |
| | | OccurrenceTime string `json:"occurrenceTime" gorm:"-"` |
| | | IsFollowed constvar.BoolType `gorm:"type:tinyint;not null;default:2;comment:是否关注"` //是否关注 1关注 2未关注 |
| | |
| | | slf.DriverNumber = name |
| | | return slf |
| | | } |
| | | func (slf *AudioSearch) SetStationNumber(name string) *AudioSearch { |
| | | slf.StationNumber = name |
| | | func (slf *AudioSearch) SetStation(name string) *AudioSearch { |
| | | slf.Station = name |
| | | return slf |
| | | } |
| | | |
| | |
| | | |
| | | if slf.Keyword != "" { |
| | | kw := "%" + slf.Keyword + "%" |
| | | db = db.Where("name like ? or locomotive_number like ? or train_number like ? or driver_number like ? or station_number like ?", kw, kw, kw, kw, kw) |
| | | db = db.Where("name like ? or locomotive_number like ? or train_number like ? or driver_number like ? or station like ?", kw, kw, kw, kw, kw) |
| | | } |
| | | |
| | | if slf.Name != "" { |
| | |
| | | db = db.Where("driver_number like ?", slf.DriverNumber) |
| | | } |
| | | |
| | | if slf.StationNumber != "" { |
| | | db = db.Where("station_number like ?", slf.StationNumber) |
| | | if slf.Station != "" { |
| | | db = db.Where("station like ?", slf.Station) |
| | | } |
| | | |
| | | if len(slf.IDs) > 0 { |
| | |
| | | Audio{}, |
| | | AudioText{}, |
| | | Text{}, |
| | | TrainInfo{}, |
| | | ) |
| | | return err |
| | | } |
New file |
| | |
| | | package models |
| | | |
| | | import ( |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | "speechAnalysis/constvar" |
| | | "speechAnalysis/pkg/mysqlx" |
| | | ) |
| | | |
| | | type ( |
| | | // TrainInfo 火车信息 |
| | | TrainInfo struct { |
| | | gorm.Model |
| | | Name string `gorm:"type:varchar(255);not null;default:'';comment:名称" json:"name"` //名称 |
| | | Class constvar.Class `gorm:"type:tinyint;not null;default:0;comment:分类" json:"class"` //分类 |
| | | ParentID uint `gorm:"type:int;not null;default 0; comment:上级id" json:"parentID"` //上级id |
| | | } |
| | | |
| | | TrainInfoSearch struct { |
| | | TrainInfo |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | Keyword string |
| | | IDs []uint |
| | | } |
| | | ) |
| | | |
| | | func (slf *TrainInfo) TableName() string { |
| | | return "train_info" |
| | | } |
| | | |
| | | func NewTrainInfoSearch() *TrainInfoSearch { |
| | | return &TrainInfoSearch{Orm: mysqlx.GetDB()} |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) SetOrm(tx *gorm.DB) *TrainInfoSearch { |
| | | slf.Orm = tx |
| | | return slf |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) SetPage(page, size int) *TrainInfoSearch { |
| | | slf.PageNum, slf.PageSize = page, size |
| | | return slf |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) SetOrder(order string) *TrainInfoSearch { |
| | | slf.Order = order |
| | | return slf |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) SetID(id uint) *TrainInfoSearch { |
| | | slf.ID = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) SetIDs(ids []uint) *TrainInfoSearch { |
| | | slf.IDs = ids |
| | | return slf |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) SetKeyword(kw string) *TrainInfoSearch { |
| | | slf.Keyword = kw |
| | | return slf |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) SetName(name string) *TrainInfoSearch { |
| | | slf.Name = name |
| | | return slf |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) SetClass(class constvar.Class) *TrainInfoSearch { |
| | | slf.Class = class |
| | | return slf |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) SetParentId(id uint) *TrainInfoSearch { |
| | | slf.ParentID = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Table(slf.TableName()) |
| | | |
| | | if slf.ID != 0 { |
| | | db = db.Where("id = ?", slf.ID) |
| | | } |
| | | |
| | | if slf.Order != "" { |
| | | db = db.Order(slf.Order) |
| | | } |
| | | |
| | | if slf.Keyword != "" { |
| | | kw := "%" + slf.Keyword + "%" |
| | | db = db.Where("name like ? ", kw) |
| | | } |
| | | |
| | | if len(slf.IDs) > 0 { |
| | | db = db.Where("id in ?", slf.IDs) |
| | | } |
| | | |
| | | if slf.Name != "" { |
| | | db = db.Where("name = ?", slf.Name) |
| | | } |
| | | |
| | | if slf.Class != 0 { |
| | | db = db.Where("class = ?", slf.Class) |
| | | } |
| | | |
| | | if slf.ParentID != 0 { |
| | | db = db.Where("parent_id = ?", slf.ParentID) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | | // Create 单条插入 |
| | | func (slf *TrainInfoSearch) Create(record *TrainInfo) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Create(record).Error; err != nil { |
| | | return fmt.Errorf("create err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | // CreateBatch 批量插入 |
| | | func (slf *TrainInfoSearch) CreateBatch(records []*TrainInfo) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Create(&records).Error; err != nil { |
| | | return fmt.Errorf("create batch err: %v, records: %+v", err, records) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) Save(record *TrainInfo) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Omit("CreatedAt").Save(record).Error; err != nil { |
| | | return fmt.Errorf("save err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) UpdateByMap(upMap map[string]interface{}) error { |
| | | var ( |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Updates(upMap).Error; err != nil { |
| | | return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) UpdateByQuery(query string, args []interface{}, upMap map[string]interface{}) error { |
| | | var ( |
| | | db = slf.Orm.Table(slf.TableName()).Where(query, args...) |
| | | ) |
| | | |
| | | if err := db.Updates(upMap).Error; err != nil { |
| | | return fmt.Errorf("update by query err: %v, query: %s, args: %+v, upMap: %+v", err, query, args, upMap) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) Delete() error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Delete(&TrainInfo{}).Error; err != nil { |
| | | return err |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) First() (*TrainInfo, error) { |
| | | var ( |
| | | record = new(TrainInfo) |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.First(record).Error; err != nil { |
| | | return record, err |
| | | } |
| | | |
| | | return record, nil |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) Find() ([]*TrainInfo, int, error) { |
| | | var ( |
| | | records = make([]*TrainInfo, 0) |
| | | total int64 |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return records, int(total), fmt.Errorf("find count err: %v", err) |
| | | } |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, int(total), fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |
| | | return records, int(total), nil |
| | | } |
| | | |
| | | func (slf *TrainInfoSearch) FindNotTotal() ([]*TrainInfo, error) { |
| | | var ( |
| | | records = make([]*TrainInfo, 0) |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |
| | | return records, nil |
| | | } |
| | | |
| | | // FindByQuery 指定条件查询. |
| | | func (slf *TrainInfoSearch) FindByQuery(query string, args []interface{}) ([]*TrainInfo, int64, error) { |
| | | var ( |
| | | records = make([]*TrainInfo, 0) |
| | | total int64 |
| | | db = slf.Orm.Table(slf.TableName()).Where(query, args...) |
| | | ) |
| | | |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return records, total, fmt.Errorf("find by query count err: %v", err) |
| | | } |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, total, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args) |
| | | } |
| | | |
| | | return records, total, nil |
| | | } |
| | | |
| | | // FindAll 指定条件查询&不分页. |
| | | func (slf *TrainInfoSearch) FindAll(query string, args []interface{}) ([]*TrainInfo, error) { |
| | | var ( |
| | | records = make([]*TrainInfo, 0) |
| | | db = slf.Orm.Table(slf.TableName()).Where(query, args...) |
| | | ) |
| | | |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args) |
| | | } |
| | | |
| | | return records, nil |
| | | } |
| | |
| | | package request |
| | | |
| | | import "speechAnalysis/constvar" |
| | | |
| | | type GetAudioList struct { |
| | | PageInfo |
| | | Keyword string `form:"keyword"` // 关键字 |
| | | Keyword string `form:"keyword"` // 关键字 |
| | | LocomotiveNumber string `gorm:"index;type:varchar(255);not null;default:'';comment:机车号" form:"locomotiveNumber"` // 机车号 |
| | | TrainNumber string `gorm:"index;type:varchar(255);not null;default:'';comment:车次" form:"trainNumber"` // 车次 |
| | | TrainNumber string `gorm:"index;type:varchar(255);not null;default:'';comment:车次" form:"trainNumber"` // 车次 |
| | | DriverNumber string `gorm:"index;type:varchar(255);not null;default:'';comment:司机号" form:"driverNumber"` // 司机号 |
| | | StationNumber string `gorm:"index;type:varchar(255);not null;default:'';comment:车站号" form:"stationNumber"` // 车站号 |
| | | } |
| | |
| | | type FollowReq struct { |
| | | ID uint `json:"id" binding:"required"` |
| | | } |
| | | |
| | | type GetTrainInfoList struct { |
| | | PageInfo |
| | | Class constvar.Class `form:"class" json:"class"` //信息分类 1机车2车次3车站 |
| | | ParentID uint `form:"parentID" json:"parentID"` //上级id |
| | | } |
| | |
| | | audioCtl := new(controllers.AudioCtl) |
| | | audioAPi := r.Group(urlPrefix + "/audio") |
| | | { |
| | | audioAPi.POST("upload", audioCtl.Upload) // 上传音频 |
| | | audioAPi.GET("list", audioCtl.List) // 音频检索 |
| | | audioAPi.POST("process", audioCtl.Process) // 音频处理 |
| | | audioAPi.POST("batchProcess", audioCtl.BatchProcess) // 音频批量处理 |
| | | audioAPi.DELETE("delete", audioCtl.Delete) // 音频删除 |
| | | audioAPi.DELETE("batchDelete", audioCtl.BatchDelete) // 音频批量删除 |
| | | audioAPi.POST("follow", audioCtl.Follow) // 关注/取消关注 |
| | | audioAPi.POST("upload", audioCtl.Upload) // 上传音频 |
| | | audioAPi.GET("list", audioCtl.List) // 音频检索 |
| | | audioAPi.GET("trainInfoList", audioCtl.TrainInfoList) // 火车信息列表 |
| | | audioAPi.POST("process", audioCtl.Process) // 音频处理 |
| | | audioAPi.POST("batchProcess", audioCtl.BatchProcess) // 音频批量处理 |
| | | audioAPi.DELETE("delete", audioCtl.Delete) // 音频删除 |
| | | audioAPi.DELETE("batchDelete", audioCtl.BatchDelete) // 音频批量删除 |
| | | audioAPi.POST("follow", audioCtl.Follow) // 关注/取消关注 |
| | | |
| | | } |
| | | |