yinbangzhong
2024-06-18 be7a1df7cf42ef9386c7fe7ef3a51c9f6f64dc95
word update delete
7个文件已修改
269 ■■■■■ 已修改文件
controllers/text.go 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/audio.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/text.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/text.go
@@ -3,6 +3,7 @@
import (
    "errors"
    "github.com/gin-gonic/gin"
    "gorm.io/gorm"
    "speechAnalysis/extend/code"
    "speechAnalysis/extend/util"
    "speechAnalysis/models"
@@ -45,6 +46,69 @@
    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("参数缺失")
docs/docs.go
@@ -529,6 +529,36 @@
                }
            }
        },
        "/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": [
@@ -578,6 +608,36 @@
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/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"
                        }
                    }
                }
@@ -690,6 +750,10 @@
                        }
                    ]
                },
                "kilometerMarker": {
                    "description": "公里标",
                    "type": "string"
                },
                "locomotiveNumber": {
                    "description": "机车号",
                    "type": "string"
@@ -701,6 +765,10 @@
                "occurrenceTime": {
                    "type": "string"
                },
                "routeNumber": {
                    "description": "交路号",
                    "type": "string"
                },
                "score": {
                    "description": "置信度",
                    "type": "number"
@@ -710,7 +778,7 @@
                    "type": "integer"
                },
                "station": {
                    "description": "公里标",
                    "description": "车站",
                    "type": "string"
                },
                "trainNumber": {
@@ -798,6 +866,9 @@
                    "description": "音频名称",
                    "type": "string"
                },
                "id": {
                    "type": "integer"
                },
                "locomotiveNumber": {
                    "description": "机车号",
                    "type": "string"
docs/swagger.json
@@ -518,6 +518,36 @@
                }
            }
        },
        "/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": [
@@ -567,6 +597,36 @@
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/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"
                        }
                    }
                }
@@ -679,6 +739,10 @@
                        }
                    ]
                },
                "kilometerMarker": {
                    "description": "公里标",
                    "type": "string"
                },
                "locomotiveNumber": {
                    "description": "机车号",
                    "type": "string"
@@ -690,6 +754,10 @@
                "occurrenceTime": {
                    "type": "string"
                },
                "routeNumber": {
                    "description": "交路号",
                    "type": "string"
                },
                "score": {
                    "description": "置信度",
                    "type": "number"
@@ -699,7 +767,7 @@
                    "type": "integer"
                },
                "station": {
                    "description": "公里标",
                    "description": "车站",
                    "type": "string"
                },
                "trainNumber": {
@@ -787,6 +855,9 @@
                    "description": "音频名称",
                    "type": "string"
                },
                "id": {
                    "type": "integer"
                },
                "locomotiveNumber": {
                    "description": "机车号",
                    "type": "string"
docs/swagger.yaml
@@ -74,6 +74,9 @@
        allOf:
        - $ref: '#/definitions/constvar.BoolType'
        description: 是否关注 1关注 2未关注
      kilometerMarker:
        description: 公里标
        type: string
      locomotiveNumber:
        description: 机车号
        type: string
@@ -82,6 +85,9 @@
        type: string
      occurrenceTime:
        type: string
      routeNumber:
        description: 交路号
        type: string
      score:
        description: 置信度
        type: number
@@ -89,7 +95,7 @@
        description: 音频大小
        type: integer
      station:
        description: 公里标
        description: 车站
        type: string
      trainNumber:
        description: 车次
@@ -145,6 +151,8 @@
      content:
        description: 音频名称
        type: string
      id:
        type: integer
      locomotiveNumber:
        description: 机车号
        type: string
@@ -530,6 +538,25 @@
      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:
@@ -562,4 +589,23 @@
      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"
models/audio.go
@@ -22,8 +22,8 @@
        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未关注
request/text.go
@@ -1,6 +1,7 @@
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"` // 机车号
}
router/router.go
@@ -42,8 +42,10 @@
    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) // 删除文字
    }