| | |
| | | "errors" |
| | | "github.com/gin-gonic/gin" |
| | | "strconv" |
| | | "strings" |
| | | "wms/extend/code" |
| | | "wms/extend/util" |
| | | "wms/models" |
| | |
| | | func (slf LocationController) AddLocation(c *gin.Context) { |
| | | var params models.Location |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误:"+err.Error()) |
| | | return |
| | | } |
| | | if err := slf.CheckLocation(params); err != nil { |
| | |
| | | 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 |
| | | } |
| | |
| | | // @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) { |
| | |
| | | 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 |
| | |
| | | } |
| | | params.JointName = first.JointName + "/" + params.Name |
| | | } else { |
| | | params.JointName = params.Name |
| | | params.JointName = strings.Split(params.JointName, "/")[0] + "/" + params.Name |
| | | } |
| | | err := models.NewLocationSearch().Update(¶ms) |
| | | if err != nil { |