运费模板,区域选择使用懒加载优化性能

This commit is contained in:
jason 2023-05-22 23:08:21 +08:00
parent 3672c217f8
commit 16956a6501
3 changed files with 59 additions and 6 deletions

View File

@ -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.AreaUtils;
import cn.iocoder.yudao.framework.ip.core.utils.IPUtils; 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.AreaNodeRespVO;
import cn.iocoder.yudao.module.system.controller.admin.ip.vo.LazyAreaNodeRespVO;
import cn.iocoder.yudao.module.system.convert.ip.AreaConvert; import cn.iocoder.yudao.module.system.convert.ip.AreaConvert;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -29,10 +29,28 @@ public class AreaController {
@GetMapping("/tree") @GetMapping("/tree")
@Operation(summary = "获得地区树") @Operation(summary = "获得地区树")
public CommonResult<List<AreaNodeRespVO>> getAreaTree(Integer id) { public CommonResult<List<AreaNodeRespVO>> getAreaTree() {
Area area = AreaUtils.getArea(Area.ID_CHINA);
Assert.notNull(area, "获取不到中国");
return success(AreaConvert.INSTANCE.convertList(area.getChildren()));
}
@GetMapping("/getChildrenArea")
@Operation(summary = "获得地区的下级区域")
public CommonResult<List<LazyAreaNodeRespVO>> getChildrenArea(Integer id) {
Area area = AreaUtils.getArea(id); Area area = AreaUtils.getArea(id);
Assert.notNull(area, String.format("获取不到 id : %d的区域", 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<LazyAreaNodeRespVO>> list(@RequestBody Set<Integer> areaIds) {
List<Area> areaList = new ArrayList<>(areaIds.size());
for (Integer areaId : areaIds) {
areaList.add(AreaUtils.getArea(areaId));
}
return success(AreaConvert.INSTANCE.convertList2(areaList));
} }
@GetMapping("/get-by-ip") @GetMapping("/get-by-ip")

View File

@ -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;
}

View File

@ -1,11 +1,17 @@
package cn.iocoder.yudao.module.system.convert.ip; package cn.iocoder.yudao.module.system.convert.ip;
import cn.iocoder.yudao.framework.ip.core.Area; 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.AreaNodeRespVO;
import cn.iocoder.yudao.module.system.controller.admin.ip.vo.LazyAreaNodeRespVO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import org.springframework.context.annotation.Lazy;
import java.util.List; import java.util.List;
import java.util.Objects;
@Mapper @Mapper
public interface AreaConvert { public interface AreaConvert {
@ -14,4 +20,12 @@ public interface AreaConvert {
List<AreaNodeRespVO> convertList(List<Area> list); List<AreaNodeRespVO> convertList(List<Area> list);
List<LazyAreaNodeRespVO> convertList2(List<Area> list);
@Mapping(source = "type", target = "leaf")
LazyAreaNodeRespVO convert(Area area);
default Boolean convertAreaType(Integer type){
return Objects.equals(AreaTypeEnum.DISTRICT.getType(),type);
}
} }