yinbentan
2024-07-16 93c71a94d77ffe1f36654decc0bada0a2ac27c88
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的grpc服务信息")
   }
   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)
}