package com.gyee.backconfig.service; import com.gyee.backconfig.config.CacheContext; import com.gyee.backconfig.model.auto.*; import org.springframework.stereotype.Service; import java.util.List; import java.util.stream.Collectors; @Service public class NewtreeService { public List cpls(String tag) { List cpls = CacheContext.cpls;//公司 List rels = CacheContext.regions;//区域 List wpls = CacheContext.wpls;//场站 List prols = CacheContext.prols;//期次 List lines = CacheContext.lines;//线路 //公司-区域 cpls.forEach(regls -> { List collect = rels.stream().filter(r -> r.getCompanyid().equals(regls.getId())).collect(Collectors.toList()); if (null != regls.getChildren()) { regls.getChildren().clear(); } collect.stream().forEach(c -> { c.getChildren().clear(); }); regls.getChildren().addAll(collect); }); if ("1".equals(tag)) { return cpls; } //区域-场站 rels.forEach(czls -> { List collect = wpls.stream().filter(w -> null != w.getCompanyid() && w.getCompanyid().equals(czls.getCompanyid()) && null != w.getRegionid() && w.getRegionid().equals(czls.getId())).collect(Collectors.toList()); if (null != czls.getChildren()) { czls.getChildren().clear(); } collect.stream().forEach(d -> { d.getChildren().clear(); }); czls.getChildren().addAll(collect); }); if ("2".equals(tag)) { return cpls; } //场站-期次 wpls.forEach(qcls -> { List collect = prols.stream().filter(w -> null != w.getWindpowerstationid() && w.getWindpowerstationid().equals(qcls.getId())).collect(Collectors.toList()); if (null != qcls.getChildren()) { qcls.getChildren().clear(); } collect.stream().forEach(e -> { e.getChildren().clear(); }); qcls.getChildren().addAll(collect); }); if ("3".equals(tag)) { return cpls; } //期次-线路 prols.forEach(xlls -> { List collect = lines.stream().filter(w -> null != w.getProjectid() && w.getProjectid().equals(xlls.getId())).collect(Collectors.toList()); xlls.getChildren().addAll(collect); }); return cpls; } }