Commit 16956a6501d8fe6a73d22db7841123382aa910a1
1 parent
3672c217
运费模板,区域选择使用懒加载优化性能
Showing
3 changed files
with
59 additions
and
6 deletions
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; | @@ -6,18 +6,18 @@ import cn.iocoder.yudao.framework.ip.core.Area; | ||
| 6 | import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; | 6 | import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; |
| 7 | import cn.iocoder.yudao.framework.ip.core.utils.IPUtils; | 7 | import cn.iocoder.yudao.framework.ip.core.utils.IPUtils; |
| 8 | import cn.iocoder.yudao.module.system.controller.admin.ip.vo.AreaNodeRespVO; | 8 | import cn.iocoder.yudao.module.system.controller.admin.ip.vo.AreaNodeRespVO; |
| 9 | +import cn.iocoder.yudao.module.system.controller.admin.ip.vo.LazyAreaNodeRespVO; | ||
| 9 | import cn.iocoder.yudao.module.system.convert.ip.AreaConvert; | 10 | import cn.iocoder.yudao.module.system.convert.ip.AreaConvert; |
| 10 | import io.swagger.v3.oas.annotations.Operation; | 11 | import io.swagger.v3.oas.annotations.Operation; |
| 11 | import io.swagger.v3.oas.annotations.Parameter; | 12 | import io.swagger.v3.oas.annotations.Parameter; |
| 12 | import io.swagger.v3.oas.annotations.tags.Tag; | 13 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 13 | import org.springframework.validation.annotation.Validated; | 14 | import org.springframework.validation.annotation.Validated; |
| 14 | -import org.springframework.web.bind.annotation.GetMapping; | ||
| 15 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 16 | -import org.springframework.web.bind.annotation.RequestParam; | ||
| 17 | -import org.springframework.web.bind.annotation.RestController; | 15 | +import org.springframework.web.bind.annotation.*; |
| 18 | 16 | ||
| 17 | +import java.util.ArrayList; | ||
| 19 | import java.util.Arrays; | 18 | import java.util.Arrays; |
| 20 | import java.util.List; | 19 | import java.util.List; |
| 20 | +import java.util.Set; | ||
| 21 | 21 | ||
| 22 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 22 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 23 | 23 | ||
| @@ -29,10 +29,28 @@ public class AreaController { | @@ -29,10 +29,28 @@ public class AreaController { | ||
| 29 | 29 | ||
| 30 | @GetMapping("/tree") | 30 | @GetMapping("/tree") |
| 31 | @Operation(summary = "获得地区树") | 31 | @Operation(summary = "获得地区树") |
| 32 | - public CommonResult<List<AreaNodeRespVO>> getAreaTree(Integer id) { | 32 | + public CommonResult<List<AreaNodeRespVO>> getAreaTree() { |
| 33 | + Area area = AreaUtils.getArea(Area.ID_CHINA); | ||
| 34 | + Assert.notNull(area, "获取不到中国"); | ||
| 35 | + return success(AreaConvert.INSTANCE.convertList(area.getChildren())); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + @GetMapping("/getChildrenArea") | ||
| 39 | + @Operation(summary = "获得地区的下级区域") | ||
| 40 | + public CommonResult<List<LazyAreaNodeRespVO>> getChildrenArea(Integer id) { | ||
| 33 | Area area = AreaUtils.getArea(id); | 41 | Area area = AreaUtils.getArea(id); |
| 34 | Assert.notNull(area, String.format("获取不到 id : %d的区域", id)); | 42 | Assert.notNull(area, String.format("获取不到 id : %d的区域", id)); |
| 35 | - return success(AreaConvert.INSTANCE.convertList(Arrays.asList(area))); | 43 | + return success(AreaConvert.INSTANCE.convertList2(area.getChildren())); |
| 44 | + } | ||
| 45 | + | ||
| 46 | + @PostMapping("/list") | ||
| 47 | + @Operation(summary = "通过区域ids获得地区列表") | ||
| 48 | + public CommonResult<List<LazyAreaNodeRespVO>> list(@RequestBody Set<Integer> areaIds) { | ||
| 49 | + List<Area> areaList = new ArrayList<>(areaIds.size()); | ||
| 50 | + for (Integer areaId : areaIds) { | ||
| 51 | + areaList.add(AreaUtils.getArea(areaId)); | ||
| 52 | + } | ||
| 53 | + return success(AreaConvert.INSTANCE.convertList2(areaList)); | ||
| 36 | } | 54 | } |
| 37 | 55 | ||
| 38 | @GetMapping("/get-by-ip") | 56 | @GetMapping("/get-by-ip") |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/ip/vo/LazyAreaNodeRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.system.controller.admin.ip.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * @author jason | ||
| 8 | + */ | ||
| 9 | +@Schema(description = "管理后台 - 懒加载地区节点 Response VO") | ||
| 10 | +@Data | ||
| 11 | +public class LazyAreaNodeRespVO { | ||
| 12 | + | ||
| 13 | + @Schema(description = "编号", required = true, example = "110000") | ||
| 14 | + private Integer id; | ||
| 15 | + | ||
| 16 | + @Schema(description = "名字", required = true, example = "北京") | ||
| 17 | + private String name; | ||
| 18 | + | ||
| 19 | + @Schema(description = "是否叶子节点", required = true, example = "false") | ||
| 20 | + private Boolean leaf = Boolean.FALSE; | ||
| 21 | +} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/ip/AreaConvert.java
| 1 | package cn.iocoder.yudao.module.system.convert.ip; | 1 | package cn.iocoder.yudao.module.system.convert.ip; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.ip.core.Area; | 3 | import cn.iocoder.yudao.framework.ip.core.Area; |
| 4 | +import cn.iocoder.yudao.framework.ip.core.enums.AreaTypeEnum; | ||
| 4 | import cn.iocoder.yudao.module.system.controller.admin.ip.vo.AreaNodeRespVO; | 5 | import cn.iocoder.yudao.module.system.controller.admin.ip.vo.AreaNodeRespVO; |
| 6 | +import cn.iocoder.yudao.module.system.controller.admin.ip.vo.LazyAreaNodeRespVO; | ||
| 5 | import org.mapstruct.Mapper; | 7 | import org.mapstruct.Mapper; |
| 8 | +import org.mapstruct.Mapping; | ||
| 9 | +import org.mapstruct.Named; | ||
| 6 | import org.mapstruct.factory.Mappers; | 10 | import org.mapstruct.factory.Mappers; |
| 11 | +import org.springframework.context.annotation.Lazy; | ||
| 7 | 12 | ||
| 8 | import java.util.List; | 13 | import java.util.List; |
| 14 | +import java.util.Objects; | ||
| 9 | 15 | ||
| 10 | @Mapper | 16 | @Mapper |
| 11 | public interface AreaConvert { | 17 | public interface AreaConvert { |
| @@ -14,4 +20,12 @@ public interface AreaConvert { | @@ -14,4 +20,12 @@ public interface AreaConvert { | ||
| 14 | 20 | ||
| 15 | List<AreaNodeRespVO> convertList(List<Area> list); | 21 | List<AreaNodeRespVO> convertList(List<Area> list); |
| 16 | 22 | ||
| 23 | + List<LazyAreaNodeRespVO> convertList2(List<Area> list); | ||
| 24 | + | ||
| 25 | + @Mapping(source = "type", target = "leaf") | ||
| 26 | + LazyAreaNodeRespVO convert(Area area); | ||
| 27 | + | ||
| 28 | + default Boolean convertAreaType(Integer type){ | ||
| 29 | + return Objects.equals(AreaTypeEnum.DISTRICT.getType(),type); | ||
| 30 | + } | ||
| 17 | } | 31 | } |