From 93c71a94d77ffe1f36654decc0bada0a2ac27c88 Mon Sep 17 00:00:00 2001 From: yinbentan <yinbentan@live.com> Date: 星期二, 16 七月 2024 20:14:10 +0800 Subject: [PATCH] 添加方法,获取庄口列表 --- controllers/dict_controller.go | 75 +++++++++++++++++++++++++++++++++++++ 1 files changed, 74 insertions(+), 1 deletions(-) diff --git a/controllers/dict_controller.go b/controllers/dict_controller.go index 7366885..a9c1a8e 100644 --- a/controllers/dict_controller.go +++ b/controllers/dict_controller.go @@ -1,6 +1,8 @@ package controllers import ( + "context" + "errors" "github.com/gin-gonic/gin" "gorm.io/gorm" "strconv" @@ -8,6 +10,8 @@ "wms/extend/util" "wms/models" "wms/pkg/logx" + "wms/proto/init_client" + "wms/proto/user" "wms/request" ) @@ -35,6 +39,12 @@ if len(params.Name) == 0 { util.ResponseFormat(c, code.RequestParamError, "鍚嶇О涓虹┖") + return + } + + _, err := models.NewMiniDictSearch().SetType(params.Type).SetName(params.Name).First() + if !errors.Is(err, gorm.ErrRecordNotFound) { + util.ResponseFormat(c, code.NameExistedError, "鍚嶇О宸插瓨鍦�") return } @@ -181,7 +191,7 @@ // @Tags 鏁版嵁瀛楀吀 // @Summary 鑾峰彇瀛楀吀淇℃伅鍒楄〃 // @Produce application/json -// @Param object body request.GetMiniDictList true "鍙傛暟" +// @Param object body request.GetMiniDictList true "鍙傛暟" // @Success 200 {object} util.ResponseList{data=[]models.MiniDict} "鎴愬姛" // @Router /api-wms/v1/dict/getDictList [post] func (slf DictController) GetMiniDictList(c *gin.Context) { @@ -208,3 +218,66 @@ util.ResponseFormatList(c, code.Success, list, int(total)) } + +// GetSilkDictList +// +// @Tags 鏁版嵁瀛楀吀 +// @Summary 鑾峰彇搴勫彛鍒楄〃 +// @Produce application/json +// @Param Authorization header string true "token" +// @Param type path string true "瀛楀吀绫诲瀷" +// @Success 200 {object} util.ResponseList{data=[]models.SilkDict} "鎴愬姛" +// @Router /api-wms/v1/dict/getSilkDictList/{type} [get] +func (slf DictController) GetSilkDictList(c *gin.Context) { + + dictType, err := strconv.Atoi(c.Param("type")) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "璇蜂紶鍏ユ纭殑瀛楀吀绫诲瀷") + return + } + + list, err := models.NewSilkDictSearch().SetDictType(models.SilkDictType(dictType)).FindAll() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触") + return + } + util.ResponseFormat(c, code.Success, list) +} + +// GetUserList +// @Tags 鏁版嵁瀛楀吀 +// @Summary 鑾峰彇鐢ㄦ埛鍒楄〃 +// @Produce application/json +// @Param object query user.GetUserRequest true "鍙傛暟" +// @Success 200 {object} util.ResponseList{data=[]user.GetUserRequest} "鎴愬姛" +// @Router /api-wms/v1/dict/getUserList [get] +func (slf DictController) GetUserList(c *gin.Context) { + if init_client.AdminConn == nil { + util.ResponseFormat(c, code.InternalError, "璇峰厛閰嶇疆Admin鐨刧rpc鏈嶅姟淇℃伅") + } + query := new(user.GetUserRequest) + if c.Query("id") != "" { + query.Id = c.Query("id") + } + if c.Query("userName") != "" { + query.UserName = c.Query("userName") + } + if c.Query("nickName") != "" { + query.NickName = c.Query("nickName") + } + if c.Query("parentId") != "" { + query.ParentId = c.Query("parentId") + } + if userType, err := strconv.Atoi(c.Query("userType")); err == nil && userType > 0 { + query.UserType = int32(userType) + } + + cli := user.NewUserServiceClient(init_client.AdminConn) + list, err := cli.GetUserList(context.Background(), query) + if err != nil { + util.ResponseFormat(c, code.InternalError, "鍐呴儴閿欒") + logx.Error("grpc璋冪敤澶辫触, GetPersonnelList err : " + err.Error()) + return + } + util.ResponseFormat(c, code.Success, list.List) +} -- Gitblit v1.8.0