| | |
| | | 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 { |
| | | m[location.ParentId].Children = append(m[location.ParentId].Children, location) |
| | | } |
| | | } |
| | | |
| | | util.ResponseFormat(c, code.Success, tree) |
| | | } |
| | | |
| | | // GetLocationDetails |
| | | // @Tags 位置 |
| | | // @Summary 获取位置详情 |