feat: 增加获取流域树形结构
This commit is contained in:
parent
9ed1837613
commit
78431d5db1
@ -71,6 +71,14 @@ public class SdRvcdDicController {
|
|||||||
return ResponseResult.successData(rvcdDicService.getById(rvcd));
|
return ResponseResult.successData(rvcdDicService.getById(rvcd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/tree")
|
||||||
|
@Operation(summary = "获取流域树形结构")
|
||||||
|
public ResponseResult getTree(
|
||||||
|
@RequestParam(required = false) String rvcd,
|
||||||
|
@RequestParam(required = false) String rvnm) {
|
||||||
|
return ResponseResult.successData(rvcdDicService.getTree(rvcd, rvnm));
|
||||||
|
}
|
||||||
|
|
||||||
// @Log(module = "流域管理", value = "新增流域")
|
// @Log(module = "流域管理", value = "新增流域")
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
@Operation(summary = "新增流域")
|
@Operation(summary = "新增流域")
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -114,4 +115,10 @@ public class SdRvcdDic implements Serializable {
|
|||||||
* 地图专题流域标识:1=是 0否
|
* 地图专题流域标识:1=是 0否
|
||||||
*/
|
*/
|
||||||
private Integer ismap;
|
private Integer ismap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子节点(用于树形结构,不映射数据库字段)
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<SdRvcdDic> children;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,4 +42,11 @@ public interface ISdRvcdDicService extends IService<SdRvcdDic> {
|
|||||||
* 删除流域
|
* 删除流域
|
||||||
*/
|
*/
|
||||||
boolean deleteRvcdDic(String rvcd);
|
boolean deleteRvcdDic(String rvcd);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取流域树形结构
|
||||||
|
* @param rvcd 流域编码(可选,为空则返回全部)
|
||||||
|
* @param rvnm 流域名称(可选,用于模糊搜索)
|
||||||
|
*/
|
||||||
|
List<SdRvcdDic> getTree(String rvcd, String rvnm);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,8 +6,10 @@ import com.yfd.platform.env.domain.SdRvcdDic;
|
|||||||
import com.yfd.platform.env.mapper.SdRvcdDicMapper;
|
import com.yfd.platform.env.mapper.SdRvcdDicMapper;
|
||||||
import com.yfd.platform.env.service.ISdRvcdDicService;
|
import com.yfd.platform.env.service.ISdRvcdDicService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -58,4 +60,58 @@ public class SdRvcdDicServiceImpl extends ServiceImpl<SdRvcdDicMapper, SdRvcdDic
|
|||||||
public boolean deleteRvcdDic(String rvcd) {
|
public boolean deleteRvcdDic(String rvcd) {
|
||||||
return this.removeById(rvcd);
|
return this.removeById(rvcd);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public List<SdRvcdDic> getTree(String rvcd, String rvnm) {
|
||||||
|
List<SdRvcdDic> result = new ArrayList<>();
|
||||||
|
|
||||||
|
List<SdRvcdDic> rootList;
|
||||||
|
Set<String> rootRvcdSet = new HashSet<>();
|
||||||
|
|
||||||
|
if (StringUtils.hasText(rvcd)) {
|
||||||
|
SdRvcdDic singleRvcd = this.getById(rvcd);
|
||||||
|
if (singleRvcd != null) {
|
||||||
|
rootList = new ArrayList<>();
|
||||||
|
rootList.add(singleRvcd);
|
||||||
|
rootRvcdSet.add(singleRvcd.getRvcd());
|
||||||
|
} else {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rootList = getRootList();
|
||||||
|
for (SdRvcdDic root : rootList) {
|
||||||
|
rootRvcdSet.add(root.getRvcd());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<SdRvcdDic> allList = this.lambdaQuery()
|
||||||
|
.like(StringUtils.hasText(rvnm), SdRvcdDic::getRvnm, rvnm)
|
||||||
|
.orderByAsc(SdRvcdDic::getOrderIndex)
|
||||||
|
.list();
|
||||||
|
|
||||||
|
Map<String, List<SdRvcdDic>> childrenMap = allList.stream()
|
||||||
|
.filter(item -> item.getPrvcd() != null)
|
||||||
|
.collect(Collectors.groupingBy(SdRvcdDic::getPrvcd));
|
||||||
|
|
||||||
|
for (SdRvcdDic root : rootList) {
|
||||||
|
if (rootRvcdSet.contains(root.getRvcd())) {
|
||||||
|
buildTreeRecursive(root, childrenMap, rootRvcdSet);
|
||||||
|
result.add(root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildTreeRecursive(SdRvcdDic parent, Map<String, List<SdRvcdDic>> childrenMap, Set<String> rootRvcdSet) {
|
||||||
|
List<SdRvcdDic> children = childrenMap.get(parent.getRvcd());
|
||||||
|
if (children != null && !children.isEmpty()) {
|
||||||
|
for (SdRvcdDic child : children) {
|
||||||
|
buildTreeRecursive(child, childrenMap, rootRvcdSet);
|
||||||
|
}
|
||||||
|
parent.setChildren(children);
|
||||||
|
} else {
|
||||||
|
parent.setChildren(new ArrayList<>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user