|
@@ -3,6 +3,7 @@ package controllers
|
|
|
import (
|
|
import (
|
|
|
"errors"
|
|
"errors"
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
+ "gorm.io/gorm"
|
|
|
"speechAnalysis/extend/code"
|
|
"speechAnalysis/extend/code"
|
|
|
"speechAnalysis/extend/util"
|
|
"speechAnalysis/extend/util"
|
|
|
"speechAnalysis/models"
|
|
"speechAnalysis/models"
|
|
@@ -45,6 +46,69 @@ func (slf TextCtl) AddText(c *gin.Context) {
|
|
|
util.ResponseFormat(c, code.Success, "添加成功")
|
|
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) {
|
|
func (slf TextCtl) paramsCheck(text models.Word) (err error) {
|
|
|
if text.Content == "" || text.LocomotiveNumber == "" {
|
|
if text.Content == "" || text.LocomotiveNumber == "" {
|
|
|
return errors.New("参数缺失")
|
|
return errors.New("参数缺失")
|