WindturbineGoodnessService.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. package com.gyee.generation.service;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.gyee.generation.init.CacheContext;
  4. import com.gyee.generation.model.auto.ProEconEquipmentInfoDay1;
  5. import com.gyee.generation.model.auto.ProEconWindturbineGoodness;
  6. import com.gyee.generation.service.auto.IProEconEquipmentInfoDay1Service;
  7. import com.gyee.generation.service.auto.IProEconWindturbineGoodnessService;
  8. import com.gyee.generation.task.thread.GoodnessOfFitThread;
  9. import com.gyee.generation.util.DateUtils;
  10. import org.springframework.stereotype.Service;
  11. import javax.annotation.Resource;
  12. import java.util.*;
  13. import java.util.concurrent.CountDownLatch;
  14. import java.util.concurrent.Executor;
  15. import java.util.stream.Collectors;
  16. @Service
  17. public class WindturbineGoodnessService {
  18. @Resource
  19. private CoefficientService coefficientService;
  20. @Resource
  21. private GoodnessOfFitService goodnessOfFitService;
  22. @Resource
  23. private IProEconWindturbineGoodnessService proEconWindturbineGoodnessService;
  24. @Resource
  25. private IProEconEquipmentInfoDay1Service proEconEquipmentInfoDay1Service;
  26. @Resource
  27. private Executor executor;
  28. public void calWindturbineGoodness(Date recordDate) throws Exception {
  29. // //判断是否有重复记录,先删除重复记录
  30. // QueryWrapper<ProEconWindturbineGoodness> queryWrapper = new QueryWrapper<>();
  31. // queryWrapper.eq("record_date",DateUtils.truncate(recordDate));
  32. // List<Long> idls = proEconWindturbineGoodnessService.list(queryWrapper).stream()
  33. //// .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate))==0
  34. //// && CacheContext.wtmap.containsKey(i.getWindturbineId()))
  35. // .map(ProEconWindturbineGoodness::getId)
  36. // .collect(Collectors.toList());
  37. //
  38. //// if (idls.size() > 0) {
  39. ////
  40. //// proEconWindturbineGoodnessService.removeByIds(idls);
  41. ////
  42. //// }
  43. // List<Long> tempids=new ArrayList<>();
  44. //
  45. // for(int i=0;i<idls.size();i++)
  46. // {
  47. // tempids.add(idls.get(i));
  48. // if(tempids.size()==1000)
  49. // {
  50. // proEconWindturbineGoodnessService.removeByIds(tempids);
  51. // tempids=new ArrayList<>();
  52. // }
  53. // }
  54. //
  55. // if(!tempids.isEmpty())
  56. // {
  57. // proEconWindturbineGoodnessService.removeByIds(tempids);
  58. // }
  59. QueryWrapper<ProEconEquipmentInfoDay1> queryWrapper2 = new QueryWrapper<>();
  60. queryWrapper2.eq("record_date",DateUtils.truncate(recordDate));
  61. List<ProEconEquipmentInfoDay1> ed1ls= proEconEquipmentInfoDay1Service.list(queryWrapper2);
  62. Map<String,ProEconEquipmentInfoDay1> equipmentInfoDay1Map=new HashMap<>();
  63. if(!ed1ls.isEmpty())
  64. {
  65. for(ProEconEquipmentInfoDay1 ed1:ed1ls)
  66. {
  67. equipmentInfoDay1Map.put(ed1.getWindturbineId(),ed1);
  68. }
  69. }
  70. List<ProEconWindturbineGoodness> vos=new ArrayList<>();
  71. System.out.println("拟合优度风机数量"+CacheContext.wtfdls.size());
  72. final CountDownLatch latch = new CountDownLatch(+CacheContext.wtfdls.size());
  73. for(int i=0;i<CacheContext.wtfdls.size();i++)
  74. {
  75. new Thread(new GoodnessOfFitThread(executor, i, recordDate, coefficientService,
  76. goodnessOfFitService,
  77. equipmentInfoDay1Map, vos,latch)).start();
  78. // proEconWindturbineGoodnessService.save(po);
  79. }
  80. latch.await();
  81. vos.sort(new Comparator<ProEconWindturbineGoodness>() {
  82. @Override
  83. public int compare(ProEconWindturbineGoodness o1, ProEconWindturbineGoodness o2) {
  84. double d1=o1.getDayGoodness()+o1.getDayCoefficient();
  85. double d2=o2.getDayGoodness()+o2.getDayCoefficient();
  86. if (d1 < d2)
  87. {
  88. return 1;
  89. }else if (d1 > d2){
  90. return 1;
  91. }else
  92. {
  93. return 0;
  94. }
  95. }
  96. });
  97. for(int i=0;i<vos.size();i++)
  98. {
  99. ProEconWindturbineGoodness vo=vos.get(i);
  100. vo.setDayTop(i+1);
  101. }
  102. vos.sort(new Comparator<ProEconWindturbineGoodness>() {
  103. @Override
  104. public int compare(ProEconWindturbineGoodness o1, ProEconWindturbineGoodness o2) {
  105. double d1=o1.getMonthGoodness()+o1.getMonthCoefficient();
  106. double d2=o2.getMonthGoodness()+o2.getMonthCoefficient();
  107. if (d1 < d2)
  108. {
  109. return 1;
  110. }else if (d1 > d2){
  111. return 1;
  112. }else
  113. {
  114. return 0;
  115. }
  116. }
  117. });
  118. for(int i=0;i<vos.size();i++)
  119. {
  120. ProEconWindturbineGoodness vo=vos.get(i);
  121. vo.setMonthTop(i+1);
  122. }
  123. vos.sort(new Comparator<ProEconWindturbineGoodness>() {
  124. @Override
  125. public int compare(ProEconWindturbineGoodness o1, ProEconWindturbineGoodness o2) {
  126. double d1=o1.getYearGoodness()+o1.getYearCoefficient();
  127. double d2=o2.getYearGoodness()+o2.getYearCoefficient();
  128. if (d1 < d2)
  129. {
  130. return 1;
  131. }else if (d1 > d2){
  132. return 1;
  133. }else
  134. {
  135. return 0;
  136. }
  137. }
  138. });
  139. for(int i=0;i<vos.size();i++)
  140. {
  141. ProEconWindturbineGoodness vo=vos.get(i);
  142. vo.setYearTop(i+1);
  143. }
  144. System.out.println("拟合优度风机存储数量"+vos.size());
  145. //判断是否有重复记录,先删除重复记录
  146. QueryWrapper<ProEconWindturbineGoodness> queryWrapper = new QueryWrapper<>();
  147. queryWrapper.eq("record_date",DateUtils.truncate(recordDate));
  148. List<Long> idls = proEconWindturbineGoodnessService.list(queryWrapper).stream()
  149. // .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate))==0
  150. // && CacheContext.wtmap.containsKey(i.getWindturbineId()))
  151. .map(ProEconWindturbineGoodness::getId)
  152. .collect(Collectors.toList());
  153. // if (idls.size() > 0) {
  154. //
  155. // proEconWindturbineGoodnessService.removeByIds(idls);
  156. //
  157. // }
  158. List<Long> tempids=new ArrayList<>();
  159. for(int i=0;i<idls.size();i++)
  160. {
  161. tempids.add(idls.get(i));
  162. if(tempids.size()==1000)
  163. {
  164. proEconWindturbineGoodnessService.removeByIds(tempids);
  165. tempids=new ArrayList<>();
  166. }
  167. }
  168. if(!tempids.isEmpty())
  169. {
  170. proEconWindturbineGoodnessService.removeByIds(tempids);
  171. }
  172. List<ProEconWindturbineGoodness> templs=new ArrayList<>();
  173. for(ProEconWindturbineGoodness vo:vos)
  174. {
  175. templs.add(vo);
  176. if(templs.size()==1000)
  177. {
  178. proEconWindturbineGoodnessService.saveBatch(templs);
  179. templs=new ArrayList<>();
  180. }
  181. }
  182. if(!templs.isEmpty())
  183. {
  184. proEconWindturbineGoodnessService.saveBatch(templs);
  185. }
  186. System.out.println("拟合优度风机存储结束");
  187. }
  188. }