|
@@ -11,6 +11,13 @@ import com.siwei.apply.service.TdgyService;
|
|
|
import com.siwei.common.core.utils.bean.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import com.siwei.apply.domain.LandType;
|
|
|
+import com.siwei.apply.domain.res.LandTypeTreeRes;
|
|
|
+import com.siwei.apply.mapper.LandTypeMapper;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.siwei.apply.common.Common.UserId;
|
|
|
|
|
@@ -23,6 +30,8 @@ public class TdgyImpl implements TdgyService {
|
|
|
private TdgyMapper tdgyMapper;
|
|
|
@Autowired
|
|
|
private ProjectMapper projectMapper;
|
|
|
+ @Autowired
|
|
|
+ private LandTypeMapper landTypeMapper;
|
|
|
|
|
|
@Override
|
|
|
public Boolean isExit(String projectId) {
|
|
@@ -58,4 +67,26 @@ public class TdgyImpl implements TdgyService {
|
|
|
public void update(TdgyUpdateVo tdgyUpdateVo) {
|
|
|
tdgyMapper.update(tdgyUpdateVo);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<LandTypeTreeRes> getLandTypeTree() {
|
|
|
+ List<LandType> all = landTypeMapper.selectAll();
|
|
|
+ // 转换为节点
|
|
|
+ List<LandTypeTreeRes> nodes = all.stream().map(type -> {
|
|
|
+ LandTypeTreeRes node = new LandTypeTreeRes();
|
|
|
+ node.setCode(type.getCode());
|
|
|
+ node.setName(type.getName());
|
|
|
+ node.setParentCode(type.getParentCode());
|
|
|
+ return node;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ // 构建树
|
|
|
+ Map<String, LandTypeTreeRes> nodeMap = nodes.stream().collect(Collectors.toMap(LandTypeTreeRes::getCode, n -> n));
|
|
|
+ List<LandTypeTreeRes> roots = nodes.stream().filter(n -> n.getParentCode() == null || n.getParentCode().isEmpty() || !nodeMap.containsKey(n.getParentCode())).collect(Collectors.toList());
|
|
|
+ nodes.forEach(n -> {
|
|
|
+ if (n.getParentCode() != null && nodeMap.containsKey(n.getParentCode())) {
|
|
|
+ nodeMap.get(n.getParentCode()).getChildren().add(n);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return roots;
|
|
|
+ }
|
|
|
}
|