diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/ip/AreaController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/ip/AreaController.java index c7363c994..87e6e0bfd 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/ip/AreaController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/ip/AreaController.java @@ -6,18 +6,18 @@ import cn.iocoder.yudao.framework.ip.core.Area; import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import cn.iocoder.yudao.framework.ip.core.utils.IPUtils; import cn.iocoder.yudao.module.system.controller.admin.ip.vo.AreaNodeRespVO; +import cn.iocoder.yudao.module.system.controller.admin.ip.vo.LazyAreaNodeRespVO; import cn.iocoder.yudao.module.system.convert.ip.AreaConvert; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Set; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -29,10 +29,28 @@ public class AreaController { @GetMapping("/tree") @Operation(summary = "获得地区树") - public CommonResult> getAreaTree(Integer id) { + public CommonResult> getAreaTree() { + Area area = AreaUtils.getArea(Area.ID_CHINA); + Assert.notNull(area, "获取不到中国"); + return success(AreaConvert.INSTANCE.convertList(area.getChildren())); + } + + @GetMapping("/getChildrenArea") + @Operation(summary = "获得地区的下级区域") + public CommonResult> getChildrenArea(Integer id) { Area area = AreaUtils.getArea(id); Assert.notNull(area, String.format("获取不到 id : %d的区域", id)); - return success(AreaConvert.INSTANCE.convertList(Arrays.asList(area))); + return success(AreaConvert.INSTANCE.convertList2(area.getChildren())); + } + + @PostMapping("/list") + @Operation(summary = "通过区域ids获得地区列表") + public CommonResult> list(@RequestBody Set areaIds) { + List areaList = new ArrayList<>(areaIds.size()); + for (Integer areaId : areaIds) { + areaList.add(AreaUtils.getArea(areaId)); + } + return success(AreaConvert.INSTANCE.convertList2(areaList)); } @GetMapping("/get-by-ip") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/ip/vo/LazyAreaNodeRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/ip/vo/LazyAreaNodeRespVO.java new file mode 100644 index 000000000..fd184b307 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/ip/vo/LazyAreaNodeRespVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.system.controller.admin.ip.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * @author jason + */ +@Schema(description = "管理后台 - 懒加载地区节点 Response VO") +@Data +public class LazyAreaNodeRespVO { + + @Schema(description = "编号", required = true, example = "110000") + private Integer id; + + @Schema(description = "名字", required = true, example = "北京") + private String name; + + @Schema(description = "是否叶子节点", required = true, example = "false") + private Boolean leaf = Boolean.FALSE; +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/ip/AreaConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/ip/AreaConvert.java index 0cedf8785..540272e12 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/ip/AreaConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/ip/AreaConvert.java @@ -1,11 +1,17 @@ package cn.iocoder.yudao.module.system.convert.ip; import cn.iocoder.yudao.framework.ip.core.Area; +import cn.iocoder.yudao.framework.ip.core.enums.AreaTypeEnum; import cn.iocoder.yudao.module.system.controller.admin.ip.vo.AreaNodeRespVO; +import cn.iocoder.yudao.module.system.controller.admin.ip.vo.LazyAreaNodeRespVO; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; import org.mapstruct.factory.Mappers; +import org.springframework.context.annotation.Lazy; import java.util.List; +import java.util.Objects; @Mapper public interface AreaConvert { @@ -14,4 +20,12 @@ public interface AreaConvert { List convertList(List list); + List convertList2(List list); + + @Mapping(source = "type", target = "leaf") + LazyAreaNodeRespVO convert(Area area); + + default Boolean convertAreaType(Integer type){ + return Objects.equals(AreaTypeEnum.DISTRICT.getType(),type); + } }