init
This commit is contained in:
@@ -6,6 +6,7 @@ import com.ruoyi.common.core.domain.R;
|
|||||||
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
import com.ruoyi.xq.domain.AreaCode;
|
import com.ruoyi.xq.domain.AreaCode;
|
||||||
import com.ruoyi.xq.dto.app.areacode.AreaCodeQuery;
|
import com.ruoyi.xq.dto.app.areacode.AreaCodeQuery;
|
||||||
|
import com.ruoyi.xq.dto.app.areacode.AreaCodeTree;
|
||||||
import com.ruoyi.xq.dto.app.setting.AgreementDTO;
|
import com.ruoyi.xq.dto.app.setting.AgreementDTO;
|
||||||
import com.ruoyi.xq.service.AgreementSettingService;
|
import com.ruoyi.xq.service.AgreementSettingService;
|
||||||
import com.ruoyi.xq.service.AreaCodeService;
|
import com.ruoyi.xq.service.AreaCodeService;
|
||||||
@@ -61,4 +62,12 @@ public class SettingAppController {
|
|||||||
return R.ok(list);
|
return R.ok(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/areaCode/tree")
|
||||||
|
@Operation(summary = "获取所有省市区编码")
|
||||||
|
@Log(title = "获取所有省市区编码", businessType = BusinessType.OTHER, isSaveDb = false)
|
||||||
|
public R<List<AreaCodeTree>> areaCodeTree(){
|
||||||
|
List<AreaCodeTree> node = areaCodeService.tree();
|
||||||
|
return R.ok(node);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.ruoyi.xq.dto.app.areacode;
|
||||||
|
|
||||||
|
import com.ruoyi.xq.domain.AreaCode;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
public class AreaCodeTree extends AreaCode {
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
/**
|
||||||
|
* 名字
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* country:国家、province:省份(直辖市会在province和city显示)、city:市(直辖市会在province和city显示)、district:区县
|
||||||
|
*/
|
||||||
|
private String level;
|
||||||
|
/**
|
||||||
|
* 所属上级行政区划代码
|
||||||
|
*/
|
||||||
|
private Integer pcode;
|
||||||
|
/**
|
||||||
|
* 所属行政区划名字
|
||||||
|
*/
|
||||||
|
private String pname;
|
||||||
|
|
||||||
|
private List<AreaCode> childrenArea;
|
||||||
|
public void addChild(AreaCodeTree child) {
|
||||||
|
if (childrenArea == null) {
|
||||||
|
childrenArea = new ArrayList<>();
|
||||||
|
}
|
||||||
|
childrenArea.add(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package com.ruoyi.xq.service;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.ruoyi.xq.domain.AreaCode;
|
import com.ruoyi.xq.domain.AreaCode;
|
||||||
import com.ruoyi.xq.dto.app.areacode.AreaCodeQuery;
|
import com.ruoyi.xq.dto.app.areacode.AreaCodeQuery;
|
||||||
|
import com.ruoyi.xq.dto.app.areacode.AreaCodeTree;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -15,4 +16,7 @@ import java.util.List;
|
|||||||
public interface AreaCodeService extends IService<AreaCode> {
|
public interface AreaCodeService extends IService<AreaCode> {
|
||||||
|
|
||||||
List<AreaCode> listAreaCode(AreaCodeQuery query);
|
List<AreaCode> listAreaCode(AreaCodeQuery query);
|
||||||
|
|
||||||
|
List<AreaCodeTree> tree();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,17 @@ package com.ruoyi.xq.service.impl;
|
|||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.ruoyi.common.utils.BeanConvertUtil;
|
||||||
import com.ruoyi.xq.domain.AreaCode;
|
import com.ruoyi.xq.domain.AreaCode;
|
||||||
import com.ruoyi.xq.dto.app.areacode.AreaCodeQuery;
|
import com.ruoyi.xq.dto.app.areacode.AreaCodeQuery;
|
||||||
|
import com.ruoyi.xq.dto.app.areacode.AreaCodeTree;
|
||||||
import com.ruoyi.xq.mapper.AreaCodeMapper;
|
import com.ruoyi.xq.mapper.AreaCodeMapper;
|
||||||
import com.ruoyi.xq.service.AreaCodeService;
|
import com.ruoyi.xq.service.AreaCodeService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 行政区划Service业务层处理
|
* 行政区划Service业务层处理
|
||||||
@@ -27,4 +31,27 @@ public class AreaCodeServiceImpl extends ServiceImpl<AreaCodeMapper,AreaCode> im
|
|||||||
.eq(StringUtils.isNotBlank(query.getLevel()),AreaCode::getLevel,query.getLevel()));
|
.eq(StringUtils.isNotBlank(query.getLevel()),AreaCode::getLevel,query.getLevel()));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AreaCodeTree> tree() {
|
||||||
|
List<AreaCode> list = this.list();
|
||||||
|
List<AreaCodeTree> nodeList = BeanConvertUtil.convertListTo(list, AreaCodeTree::new);
|
||||||
|
Map<Integer, AreaCodeTree> nodeMap = new HashMap<>();
|
||||||
|
Set<AreaCodeTree> roots = new HashSet<>();
|
||||||
|
// 遍历列表构建节点映射表
|
||||||
|
for (AreaCodeTree node : nodeList) {
|
||||||
|
nodeMap.put(node.getCode(), node);
|
||||||
|
if (node.getPcode() == 0 || !nodeMap.containsKey(node.getPcode())) {
|
||||||
|
roots.add(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 建立父子关系
|
||||||
|
for (AreaCodeTree node : nodeList) {
|
||||||
|
if (nodeMap.containsKey(node.getPcode())) {
|
||||||
|
AreaCodeTree parentNode = nodeMap.get(node.getPcode());
|
||||||
|
parentNode.addChild(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ArrayList<>(roots);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user