From 16956a6501d8fe6a73d22db7841123382aa910a1 Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Mon, 22 May 2023 23:08:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E8=B4=B9=E6=A8=A1=E6=9D=BF=EF=BC=8C?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E9=80=89=E6=8B=A9=E4=BD=BF=E7=94=A8=E6=87=92?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E4=BC=98=E5=8C=96=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/ip/AreaController.java | 30 +++++++++++++++---- .../admin/ip/vo/LazyAreaNodeRespVO.java | 21 +++++++++++++ .../module/system/convert/ip/AreaConvert.java | 14 +++++++++ 3 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/ip/vo/LazyAreaNodeRespVO.java 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); + } }