WindturbineGoodnessService.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package com.gyee.generation.service;
  2. import com.gyee.generation.init.CacheContext;
  3. import com.gyee.generation.model.auto.ProBasicEquipment;
  4. import com.gyee.generation.model.auto.ProEconWindturbineGoodness;
  5. import com.gyee.generation.service.auto.IProEconWindturbineGoodnessService;
  6. import com.gyee.generation.util.DateUtils;
  7. import org.springframework.stereotype.Service;
  8. import javax.annotation.Resource;
  9. import java.util.*;
  10. import java.util.stream.Collectors;
  11. @Service
  12. public class WindturbineGoodnessService {
  13. @Resource
  14. private CoefficientService coefficientService;
  15. @Resource
  16. private GoodnessOfFitService goodnessOfFitService;
  17. @Resource
  18. private IProEconWindturbineGoodnessService proEconWindturbineGoodnessService;
  19. public void calWindturbineGoodness(Date recordDate) throws Exception {
  20. //判断是否有重复记录,先删除重复记录
  21. List<Long> idls = proEconWindturbineGoodnessService.list().stream()
  22. .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate))==0
  23. && CacheContext.wtmap.containsKey(i.getWindturbineId())).map(ProEconWindturbineGoodness::getId)
  24. .collect(Collectors.toList());
  25. if (idls.size() > 0) {
  26. proEconWindturbineGoodnessService.removeByIds(idls);
  27. }
  28. List<ProEconWindturbineGoodness> vos=new ArrayList<>();
  29. for(ProBasicEquipment wt: CacheContext.wtls)
  30. {
  31. Map<String, Map<String, Double>> coefficientMap=coefficientService.coefficient(wt.getId(),recordDate);
  32. Map<String, Map<String,Double>> fitMap=goodnessOfFitService.goodnessOfFit(wt.getId(),recordDate);
  33. ProEconWindturbineGoodness po=new ProEconWindturbineGoodness();
  34. po.setModelId(wt.getModelId());
  35. po.setWindturbineId(wt.getId());
  36. po.setRecordDate(DateUtils.truncate(recordDate));
  37. po.setWindtpowerstationId(wt.getWindpowerstationId());
  38. po.setCompanyId(wt.getCompanyId());
  39. if(wt.getWindpowerstationId().contains("FDC"))
  40. {
  41. po.setTypes("-1");
  42. }else
  43. {
  44. po.setTypes("-2");
  45. }
  46. po.setDayGoodness(0.0);
  47. po.setYearGoodness(0.0);
  48. po.setMonthGoodness(0.0);
  49. po.setDayCoefficient(0.0);
  50. po.setMonthCoefficient(0.0);
  51. po.setYearCoefficient(0.0);
  52. if(fitMap.containsKey(wt.getId()))
  53. {
  54. Map<String, Double> map=fitMap.get(wt.getId());
  55. po.setDayGoodness(map.get("day"));
  56. po.setYearGoodness(map.get("month"));
  57. po.setMonthGoodness(map.get("year"));
  58. }
  59. if(coefficientMap.containsKey(wt.getId()))
  60. {
  61. Map<String, Double> map=coefficientMap.get(wt.getId());
  62. po.setDayCoefficient(map.get("day"));
  63. po.setMonthCoefficient(map.get("month"));
  64. po.setMonthCoefficient(map.get("year"));
  65. }
  66. vos.add(po);
  67. // proEconWindturbineGoodnessService.save(po);
  68. }
  69. vos.sort(new Comparator<ProEconWindturbineGoodness>() {
  70. @Override
  71. public int compare(ProEconWindturbineGoodness o1, ProEconWindturbineGoodness o2) {
  72. double d1=o1.getDayGoodness()+o1.getDayCoefficient();
  73. double d2=o2.getDayGoodness()+o2.getDayCoefficient();
  74. if (d1 < d2)
  75. {
  76. return 1;
  77. }else if (d1 > d2){
  78. return 1;
  79. }else
  80. {
  81. return 0;
  82. }
  83. }
  84. });
  85. for(int i=0;i<vos.size();i++)
  86. {
  87. ProEconWindturbineGoodness vo=vos.get(i);
  88. vo.setDayTop(i+1);
  89. }
  90. vos.sort(new Comparator<ProEconWindturbineGoodness>() {
  91. @Override
  92. public int compare(ProEconWindturbineGoodness o1, ProEconWindturbineGoodness o2) {
  93. double d1=o1.getMonthGoodness()+o1.getMonthCoefficient();
  94. double d2=o2.getMonthGoodness()+o2.getMonthCoefficient();
  95. if (d1 < d2)
  96. {
  97. return 1;
  98. }else if (d1 > d2){
  99. return 1;
  100. }else
  101. {
  102. return 0;
  103. }
  104. }
  105. });
  106. for(int i=0;i<vos.size();i++)
  107. {
  108. ProEconWindturbineGoodness vo=vos.get(i);
  109. vo.setMonthTop(i+1);
  110. }
  111. vos.sort(new Comparator<ProEconWindturbineGoodness>() {
  112. @Override
  113. public int compare(ProEconWindturbineGoodness o1, ProEconWindturbineGoodness o2) {
  114. double d1=o1.getYearGoodness()+o1.getYearCoefficient();
  115. double d2=o2.getYearGoodness()+o2.getYearCoefficient();
  116. if (d1 < d2)
  117. {
  118. return 1;
  119. }else if (d1 > d2){
  120. return 1;
  121. }else
  122. {
  123. return 0;
  124. }
  125. }
  126. });
  127. for(int i=0;i<vos.size();i++)
  128. {
  129. ProEconWindturbineGoodness vo=vos.get(i);
  130. vo.setYearTop(i+1);
  131. }
  132. proEconWindturbineGoodnessService.saveBatch(vos);
  133. }
  134. }