Ver código fonte

word update delete

yinbangzhong 2 anos atrás
pai
commit
be7a1df7cf
7 arquivos alterados com 262 adições e 7 exclusões
  1. 64 0
      controllers/text.go
  2. 72 1
      docs/docs.go
  3. 72 1
      docs/swagger.json
  4. 47 1
      docs/swagger.yaml
  5. 2 2
      models/audio.go
  6. 1 0
      request/text.go
  7. 4 2
      router/router.go

+ 64 - 0
controllers/text.go

@@ -3,6 +3,7 @@ package controllers
 import (
 	"errors"
 	"github.com/gin-gonic/gin"
+	"gorm.io/gorm"
 	"speechAnalysis/extend/code"
 	"speechAnalysis/extend/util"
 	"speechAnalysis/models"
@@ -45,6 +46,69 @@ func (slf TextCtl) AddText(c *gin.Context) {
 	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("参数缺失")

+ 72 - 1
docs/docs.go

@@ -529,6 +529,36 @@ const docTemplate = `{
                 }
             }
         },
+        "/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": [
@@ -582,6 +612,36 @@ const docTemplate = `{
                     }
                 }
             }
+        },
+        "/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"
+                        }
+                    }
+                }
+            }
         }
     },
     "definitions": {
@@ -690,6 +750,10 @@ const docTemplate = `{
                         }
                     ]
                 },
+                "kilometerMarker": {
+                    "description": "公里标",
+                    "type": "string"
+                },
                 "locomotiveNumber": {
                     "description": "机车号",
                     "type": "string"
@@ -701,6 +765,10 @@ const docTemplate = `{
                 "occurrenceTime": {
                     "type": "string"
                 },
+                "routeNumber": {
+                    "description": "交路号",
+                    "type": "string"
+                },
                 "score": {
                     "description": "置信度",
                     "type": "number"
@@ -710,7 +778,7 @@ const docTemplate = `{
                     "type": "integer"
                 },
                 "station": {
-                    "description": "公里标",
+                    "description": "车站",
                     "type": "string"
                 },
                 "trainNumber": {
@@ -798,6 +866,9 @@ const docTemplate = `{
                     "description": "音频名称",
                     "type": "string"
                 },
+                "id": {
+                    "type": "integer"
+                },
                 "locomotiveNumber": {
                     "description": "机车号",
                     "type": "string"

+ 72 - 1
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": [
@@ -571,6 +601,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"
+                        }
+                    }
+                }
+            }
         }
     },
     "definitions": {
@@ -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"

+ 47 - 1
docs/swagger.yaml

@@ -74,6 +74,9 @@ definitions:
         allOf:
         - $ref: '#/definitions/constvar.BoolType'
         description: 是否关注 1关注 2未关注
+      kilometerMarker:
+        description: 公里标
+        type: string
       locomotiveNumber:
         description: 机车号
         type: string
@@ -82,6 +85,9 @@ definitions:
         type: string
       occurrenceTime:
         type: string
+      routeNumber:
+        description: 交路号
+        type: string
       score:
         description: 置信度
         type: number
@@ -89,7 +95,7 @@ definitions:
         description: 音频大小
         type: integer
       station:
-        description: 公里标
+        description: 车站
         type: string
       trainNumber:
         description: 车次
@@ -145,6 +151,8 @@ definitions:
       content:
         description: 音频名称
         type: string
+      id:
+        type: integer
       locomotiveNumber:
         description: 机车号
         type: string
@@ -530,6 +538,25 @@ paths:
       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 @@ paths:
       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"

+ 2 - 2
models/audio.go

@@ -22,8 +22,8 @@ type (
 		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未关注

+ 1 - 0
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"` // 机车号
 }

+ 4 - 2
router/router.go

@@ -42,8 +42,10 @@ func NewRouter() *gin.Engine {
 	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) // 删除文字
 
 	}