NewtreeService.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package com.gyee.backconfig.service;
  2. import com.gyee.backconfig.config.CacheContext;
  3. import com.gyee.backconfig.model.auto.*;
  4. import org.springframework.stereotype.Service;
  5. import java.util.List;
  6. import java.util.stream.Collectors;
  7. @Service
  8. public class NewtreeService {
  9. public List<Companys> cpls(String tag) {
  10. List<Companys> cpls = CacheContext.cpls;//公司
  11. List<Region> rels = CacheContext.regions;//区域
  12. List<Windpowerstation> wpls = CacheContext.wpls;//场站
  13. List<Project> prols = CacheContext.prols;//期次
  14. List<Line> lines = CacheContext.lines;//线路
  15. //公司-区域
  16. cpls.forEach(regls -> {
  17. List<Region> collect = rels.stream().filter(r -> r.getCompanyid().equals(regls.getId())).collect(Collectors.toList());
  18. if (null != regls.getChildren()) {
  19. regls.getChildren().clear();
  20. }
  21. collect.stream().forEach(c -> {
  22. c.getChildren().clear();
  23. });
  24. regls.getChildren().addAll(collect);
  25. });
  26. if ("1".equals(tag)) {
  27. return cpls;
  28. }
  29. //区域-场站
  30. rels.forEach(czls -> {
  31. List<Windpowerstation> collect = wpls.stream().filter(w -> null != w.getCompanyid() && w.getCompanyid().equals(czls.getCompanyid()) && null != w.getRegionid() && w.getRegionid().equals(czls.getId())).collect(Collectors.toList());
  32. if (null != czls.getChildren()) {
  33. czls.getChildren().clear();
  34. }
  35. collect.stream().forEach(d -> {
  36. d.getChildren().clear();
  37. });
  38. czls.getChildren().addAll(collect);
  39. });
  40. if ("2".equals(tag)) {
  41. return cpls;
  42. }
  43. //场站-期次
  44. wpls.forEach(qcls -> {
  45. List<Project> collect = prols.stream().filter(w -> null != w.getWindpowerstationid() && w.getWindpowerstationid().equals(qcls.getId())).collect(Collectors.toList());
  46. if (null != qcls.getChildren()) {
  47. qcls.getChildren().clear();
  48. }
  49. collect.stream().forEach(e -> {
  50. e.getChildren().clear();
  51. });
  52. qcls.getChildren().addAll(collect);
  53. });
  54. if ("3".equals(tag)) {
  55. return cpls;
  56. }
  57. //期次-线路
  58. prols.forEach(xlls -> {
  59. List<Line> collect = lines.stream().filter(w -> null != w.getProjectid() && w.getProjectid().equals(xlls.getId())).collect(Collectors.toList());
  60. xlls.getChildren().addAll(collect);
  61. });
  62. return cpls;
  63. }
  64. }