| | |
| | | import ( |
| | | "errors" |
| | | "github.com/gin-gonic/gin" |
| | | "gorm.io/gorm" |
| | | "speechAnalysis/extend/code" |
| | | "speechAnalysis/extend/util" |
| | | "speechAnalysis/models" |
| | |
| | | util.ResponseFormat(c, code.Success, "添加成功") |
| | | } |
| | | |
| | | // UpdateText |
| | | // @Tags 文字库 |
| | | // @Summary 修改文字 |
| | | // @Produce application/json |
| | | // @Param object body request.AddTextReq true "参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-sa/v1/text/update [post] |
| | | func (slf TextCtl) UpdateText(c *gin.Context) { |
| | | var req request.AddTextReq |
| | | if err := c.BindJSON(&req); err != nil { |
| | | logx.Errorf("add text params err:%v", err) |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | text := models.Word{ |
| | | Model: gorm.Model{ |
| | | ID: req.Id, |
| | | }, |
| | | Content: req.Content, |
| | | LocomotiveNumber: req.LocomotiveNumber, |
| | | } |
| | | |
| | | if err := slf.paramsCheck(text); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | if req.Id == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, errors.New("ID不能为空")) |
| | | return |
| | | } |
| | | |
| | | if err := models.NewWordSearch().Save(&text); err != nil { |
| | | util.ResponseFormat(c, code.SaveFail, "修改失败,请检查是否重复") |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormat(c, code.Success, "修改成功") |
| | | } |
| | | |
| | | // DeleteText |
| | | // @Tags 文字库 |
| | | // @Summary 修改文字 |
| | | // @Produce application/json |
| | | // @Param object body request.AddTextReq true "参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-sa/v1/text/delete [delete] |
| | | func (slf TextCtl) DeleteText(c *gin.Context) { |
| | | var req request.AddTextReq |
| | | if err := c.BindJSON(&req); err != nil { |
| | | logx.Errorf("add text params err:%v", err) |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | if err := models.NewWordSearch().SetID(req.Id).Delete(); err != nil { |
| | | util.ResponseFormat(c, code.SaveFail, "删除失败,请检查是否重复") |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormat(c, code.Success, "删除成功") |
| | | } |
| | | |
| | | func (slf TextCtl) paramsCheck(text models.Word) (err error) { |
| | | if text.Content == "" || text.LocomotiveNumber == "" { |
| | | return errors.New("参数缺失") |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api-sa/v1/text/delete": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "文字库" |
| | | ], |
| | | "summary": "修改文字", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddTextReq" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-sa/v1/text/list": { |
| | | "get": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-sa/v1/text/update": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "文字库" |
| | | ], |
| | | "summary": "修改文字", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddTextReq" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | ] |
| | | }, |
| | | "kilometerMarker": { |
| | | "description": "公里标", |
| | | "type": "string" |
| | | }, |
| | | "locomotiveNumber": { |
| | | "description": "机车号", |
| | | "type": "string" |
| | |
| | | "occurrenceTime": { |
| | | "type": "string" |
| | | }, |
| | | "routeNumber": { |
| | | "description": "交路号", |
| | | "type": "string" |
| | | }, |
| | | "score": { |
| | | "description": "置信度", |
| | | "type": "number" |
| | |
| | | "type": "integer" |
| | | }, |
| | | "station": { |
| | | "description": "公里标", |
| | | "description": "车站", |
| | | "type": "string" |
| | | }, |
| | | "trainNumber": { |
| | |
| | | "description": "音频名称", |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "locomotiveNumber": { |
| | | "description": "机车号", |
| | | "type": "string" |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api-sa/v1/text/delete": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "文字库" |
| | | ], |
| | | "summary": "修改文字", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddTextReq" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-sa/v1/text/list": { |
| | | "get": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-sa/v1/text/update": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "文字库" |
| | | ], |
| | | "summary": "修改文字", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddTextReq" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | ] |
| | | }, |
| | | "kilometerMarker": { |
| | | "description": "公里标", |
| | | "type": "string" |
| | | }, |
| | | "locomotiveNumber": { |
| | | "description": "机车号", |
| | | "type": "string" |
| | |
| | | "occurrenceTime": { |
| | | "type": "string" |
| | | }, |
| | | "routeNumber": { |
| | | "description": "交路号", |
| | | "type": "string" |
| | | }, |
| | | "score": { |
| | | "description": "置信度", |
| | | "type": "number" |
| | |
| | | "type": "integer" |
| | | }, |
| | | "station": { |
| | | "description": "公里标", |
| | | "description": "车站", |
| | | "type": "string" |
| | | }, |
| | | "trainNumber": { |
| | |
| | | "description": "音频名称", |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "locomotiveNumber": { |
| | | "description": "机车号", |
| | | "type": "string" |
| | |
| | | allOf: |
| | | - $ref: '#/definitions/constvar.BoolType' |
| | | description: 是否关注 1关注 2未关注 |
| | | kilometerMarker: |
| | | description: 公里标 |
| | | type: string |
| | | locomotiveNumber: |
| | | description: 机车号 |
| | | type: string |
| | |
| | | type: string |
| | | occurrenceTime: |
| | | type: string |
| | | routeNumber: |
| | | description: 交路号 |
| | | type: string |
| | | score: |
| | | description: 置信度 |
| | | type: number |
| | |
| | | description: 音频大小 |
| | | type: integer |
| | | station: |
| | | description: 公里标 |
| | | description: 车站 |
| | | type: string |
| | | trainNumber: |
| | | description: 车次 |
| | |
| | | content: |
| | | description: 音频名称 |
| | | type: string |
| | | id: |
| | | type: integer |
| | | locomotiveNumber: |
| | | description: 机车号 |
| | | type: string |
| | |
| | | summary: 新增文字 |
| | | tags: |
| | | - 文字库 |
| | | /api-sa/v1/text/delete: |
| | | delete: |
| | | parameters: |
| | | - description: 参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.AddTextReq' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | $ref: '#/definitions/util.Response' |
| | | summary: 修改文字 |
| | | tags: |
| | | - 文字库 |
| | | /api-sa/v1/text/list: |
| | | get: |
| | | parameters: |
| | |
| | | summary: 文字库列表 |
| | | tags: |
| | | - 文字库 |
| | | /api-sa/v1/text/update: |
| | | post: |
| | | parameters: |
| | | - description: 参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.AddTextReq' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | $ref: '#/definitions/util.Response' |
| | | summary: 修改文字 |
| | | tags: |
| | | - 文字库 |
| | | swagger: "2.0" |
| | |
| | | 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"` // 司机号 |
| | | Station string `gorm:"index;type:varchar(255);not null;default:'';comment:车站号" json:"station"` // 车站 |
| | | RouteNumber string `gorm:"index;type:varchar(255);not null;default:'';comment:交路号" json:"station"` // 交路号 |
| | | KilometerMarker string `gorm:"index;type:varchar(255);not null;default:'';comment:公里标" json:"station"` // 公里标 |
| | | RouteNumber string `gorm:"index;type:varchar(255);not null;default:'';comment:交路号" json:"routeNumber"` // 交路号 |
| | | KilometerMarker string `gorm:"index;type:varchar(255);not null;default:'';comment:公里标" json:"kilometerMarker"` // 公里标 |
| | | OccurrenceAt time.Time `json:"-"` |
| | | OccurrenceTime string `json:"occurrenceTime" gorm:"-"` |
| | | IsFollowed constvar.BoolType `gorm:"type:tinyint;not null;default:2;comment:是否关注"` //是否关注 1关注 2未关注 |
| | |
| | | package request |
| | | |
| | | type AddTextReq struct { |
| | | Id uint `gorm:"primaryKey;autoIncrement:true" json:"id"` |
| | | Content string `gorm:"type:varchar(255);not null;default:'';comment:音频名称" json:"content" binding:"required"` // 音频名称 |
| | | LocomotiveNumber string `gorm:"index;type:varchar(255);not null;default:'';comment:机车号" json:"locomotiveNumber" binding:"required"` // 机车号 |
| | | } |
| | |
| | | textCtl := new(controllers.TextCtl) |
| | | textApi := r.Group(urlPrefix + "/text") |
| | | { |
| | | textApi.POST("add", textCtl.AddText) // 添加文字 |
| | | textApi.GET("list", textCtl.List) // 文字列表 |
| | | textApi.POST("add", textCtl.AddText) // 添加文字 |
| | | textApi.POST("update", textCtl.UpdateText) // 添加文字 |
| | | textApi.GET("list", textCtl.List) // 文字列表 |
| | | textApi.DELETE("delete", textCtl.DeleteText) // 删除文字 |
| | | |
| | | } |
| | | |