zhangqian
2024-06-12 e5df488268e29b272932e6cc1d2b1e7034590ba0
controllers/location.go
@@ -4,6 +4,7 @@
   "errors"
   "github.com/gin-gonic/gin"
   "strconv"
   "strings"
   "wms/extend/code"
   "wms/extend/util"
   "wms/models"
@@ -23,7 +24,7 @@
func (slf LocationController) AddLocation(c *gin.Context) {
   var params models.Location
   if err := c.BindJSON(&params); err != nil {
      util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
      util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误:"+err.Error())
      return
   }
   if err := slf.CheckLocation(params); err != nil {
@@ -38,6 +39,19 @@
         return
      }
      params.JointName = first.JointName + "/" + params.Name
      if first.WarehouseId != 0 {
         params.WarehouseId = first.Id
      } else {
         //根据仓库缩写查询仓库
         houseCode := strings.Split(first.JointName, "/")[0]
         warehouse, err := models.NewWarehouseSearch().SetCode(houseCode).First()
         if err != nil {
            util.ResponseFormat(c, code.RequestParamError, err)
            return
         }
         params.WarehouseId = warehouse.Id
      }
   } else {
      params.JointName = params.Name
   }
@@ -54,7 +68,7 @@
// @Tags      位置
// @Summary   获取位置列表
// @Produce   application/json
// @Param     object  body  request.GetProductList true  "查询参数"
// @Param     object  body  request.GetLocationList true  "查询参数"
// @Success   200 {object} util.ResponseList{data=[]models.Location}   "成功"
// @Router    /api-wms/v1/location/getLocationList [post]
func (slf LocationController) GetLocationList(c *gin.Context) {
@@ -67,13 +81,50 @@
   if params.PageInfo.Check() {
      search.SetPage(params.Page, params.PageSize)
   }
   list, total, err := search.SetKeyword(params.KeyWord).SetOrder("created_at desc").Find()
   list, total, err := search.SetKeyword(params.KeyWord).SetType(params.Type).SetJointName(params.JointName).
      SetIsScrapLocation(params.IsScrapLocation).SetOrder("created_at desc").Find()
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "查找失败")
      return
   }
   util.ResponseFormatList(c, code.Success, list, int(total))
}
// GetLocationTreeList
// @Tags      位置
// @Summary   获取位置列表树
// @Produce   application/json
// @Success   200 {object} util.ResponseList{data=[]models.Location}   "成功"
// @Router    /api-wms/v1/location/getLocationTreeList [get]
func (slf LocationController) GetLocationTreeList(c *gin.Context) {
   all, err := models.NewLocationSearch().SetType(3).FindAll()
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "查找失败")
      return
   }
   var tree []*models.Location
   m := make(map[int]*models.Location)
   for _, location := range all {
      m[location.Id] = location
   }
   for _, location := range all {
      if location.ParentId == 0 {
         tree = append(tree, location)
      } else {
         if _, ok := m[location.ParentId]; !ok {
            tree = append(tree, location)
            continue
         }
         if m[location.ParentId].Children == nil {
            m[location.ParentId].Children = make([]*models.Location, 0)
         }
         m[location.ParentId].Children = append(m[location.ParentId].Children, location)
      }
   }
   util.ResponseFormat(c, code.Success, tree)
}
// GetLocationDetails
@@ -131,7 +182,7 @@
      }
      params.JointName = first.JointName + "/" + params.Name
   } else {
      params.JointName = params.Name
      params.JointName = strings.Split(params.JointName, "/")[0] + "/" + params.Name
   }
   err := models.NewLocationSearch().Update(&params)
   if err != nil {