init
This commit is contained in:
@@ -82,12 +82,19 @@ public class SettingAppController {
|
||||
}
|
||||
|
||||
@GetMapping("/areaCode/tree")
|
||||
@Operation(summary = "获取所有省市区编码")
|
||||
@Operation(summary = "获取所有省市区编码(树形结构)")
|
||||
public R<List<AreaCodeTree>> areaCodeTree(){
|
||||
List<AreaCodeTree> node = areaCodeService.tree();
|
||||
return R.ok(node);
|
||||
}
|
||||
|
||||
@GetMapping("/areaCode/city/tree")
|
||||
@Operation(summary = "获取所有省市编码(树形结构)")
|
||||
public R<List<AreaCodeTree>> areaCodeCityTree(){
|
||||
List<AreaCodeTree> node = areaCodeService.treeCity();
|
||||
return R.ok(node);
|
||||
}
|
||||
|
||||
@GetMapping("/customerService/pic")
|
||||
@Operation(summary = "获取客服二维码")
|
||||
@SaIgnore
|
||||
|
||||
@@ -7,7 +7,7 @@ public enum AreaCodeLevelEnum {
|
||||
COUNTRY("country","国家"),
|
||||
PROVINCE("province","省份"),
|
||||
CITY("city","市"),
|
||||
DISTRICT("city","区县"),
|
||||
DISTRICT("district","区县"),
|
||||
;
|
||||
private final String code;
|
||||
private final String text;
|
||||
|
||||
@@ -22,4 +22,6 @@ public interface AreaCodeService extends IService<AreaCode> {
|
||||
|
||||
List<AreaCodeTree> tree();
|
||||
|
||||
List<AreaCodeTree> treeCity();
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.ruoyi.xq.domain.AreaCode;
|
||||
import com.ruoyi.xq.dto.admin.areacode.AreaCodeAdminTree;
|
||||
import com.ruoyi.xq.dto.app.areacode.AreaCodeQuery;
|
||||
import com.ruoyi.xq.dto.app.areacode.AreaCodeTree;
|
||||
import com.ruoyi.xq.enums.common.AreaCodeLevelEnum;
|
||||
import com.ruoyi.xq.mapper.AreaCodeMapper;
|
||||
import com.ruoyi.xq.service.AreaCodeService;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -83,4 +84,31 @@ public class AreaCodeServiceImpl extends ServiceImpl<AreaCodeMapper,AreaCode> im
|
||||
}
|
||||
return new ArrayList<>(roots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AreaCodeTree> treeCity() {
|
||||
List<AreaCode> list = this.list(Wrappers.lambdaQuery(AreaCode.class)
|
||||
.in(AreaCode::getLevel, AreaCodeLevelEnum.PROVINCE,AreaCodeLevelEnum.CITY));
|
||||
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