From 88e9c71aa2ebd85fa811f113b26f942ad621d37c Mon Sep 17 00:00:00 2001 From: HuangZhi Date: Wed, 5 Jul 2023 09:58:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E5=85=B8=E4=B8=8A=E4=B8=8B=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bean/vo/request/dict.go | 5 +++++ src/controller/dict.go | 25 +++++++++++++++++++++++++ src/router/dict.go | 1 + src/service/component_dict.go | 28 ++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/src/bean/vo/request/dict.go b/src/bean/vo/request/dict.go index 8534ae2..e59f614 100644 --- a/src/bean/vo/request/dict.go +++ b/src/bean/vo/request/dict.go @@ -45,3 +45,8 @@ type DictManageListReq struct { MinVal string `json:"min_val" form:"min_val"` //最大值 MaxVal string `json:"max_val" form:"max_val"` //最小值 } + +type DictSortInput struct { + Id string `json:"id"` //id + Sort int `json:"sort"` //排序 +} diff --git a/src/controller/dict.go b/src/controller/dict.go index 872658c..28e2d5b 100644 --- a/src/controller/dict.go +++ b/src/controller/dict.go @@ -169,6 +169,31 @@ func (d Dict) ClassList(c *gin.Context) { SendJsonResponse(c, resp.OK, classList) } +func (d Dict) DictSort(c *gin.Context) { + + var ( + err error + req []request.DictSortInput + ) + + err = c.ShouldBind(&req) + if err != nil { + SendJsonResponse(c, resp.InvalidParam.WithError(err), "") + return + } + + svc := new(service.Dict) + svc.Ctx = c + svc.User = header.GetUser(c) + err = svc.DictSort(req) + if err != nil { + SendJsonResponse(c, resp.FAIL.WithError(err), "") + return + } + + SendJsonResponse(c, resp.OK, "") +} + // List 组件列表 //func (d Dict) ManageList(c *gin.Context) { // diff --git a/src/router/dict.go b/src/router/dict.go index 15be12c..03b2fcf 100644 --- a/src/router/dict.go +++ b/src/router/dict.go @@ -21,6 +21,7 @@ func initDictRoute(e *gin.Engine) { base.GET("", dict.List) //字典列表 base.GET("/tree", dict.DictTree) //字典列表-树结构 base.GET("/classList", dict.ClassList) //字典分类列表 + base.PUT("/sort", dict.DictSort) //字典排序 //base.GET("/manage_list", dict.ManageList) //字典管理列表 } diff --git a/src/service/component_dict.go b/src/service/component_dict.go index a8667af..710f4af 100644 --- a/src/service/component_dict.go +++ b/src/service/component_dict.go @@ -5,9 +5,12 @@ import ( "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/util" + "go.uber.org/zap" + "xorm.io/xorm" "github.com/gin-gonic/gin" "github.com/pkg/errors" @@ -235,6 +238,31 @@ func (c *Dict) ClassList(className string) (classList []response.ClassListRes, e return } +func (c *Dict) DictSort(req []request.DictSortInput) error { + db, err := client.GetDbClient() + if err != nil { + return resp.DbConnectError.ErrorDetail(err) + } + + _, err = db.Transaction(func(x *xorm.Session) (interface{}, error) { + for _, v := range req { + _, err := x.Table("dict").Cols("sort, updated_at, updated_by").Where("id = ? and is_delete = 0", v.Id).Update( + &entity.Dict{ + Sort: v.Sort, + UpdatedBy: c.User.Id, + UpdatedAt: jsontime.Time(time.Now()), + }) + if err != nil { + conf.Logger.Error("排序失败", zap.Error(err)) + return nil, resp.DbUpdateError.ErrorDetail(err) + } + } + return nil, nil + }) + + return err +} + //func (c *Dict) ManageList(req request.DictManageListReq) (componentDictTreeRes []*response.DictListRes, err error) { // listReq := request.DictReq{ // Class: req.Class, -- 2.26.0