TimelinessRateService.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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.ProBasicEquipment;
  5. import com.gyee.generation.model.auto.ProEconFaultLiminatedefects;
  6. import com.gyee.generation.model.auto.ProEconShutdownEvent;
  7. import com.gyee.generation.service.auto.IProEconFaultLiminatedefectsService;
  8. import com.gyee.generation.service.auto.IProEconShutdownEventService;
  9. import com.gyee.generation.util.DateUtils;
  10. import com.gyee.generation.util.StringUtils;
  11. import com.gyee.generation.util.realtimesource.IEdosUtil;
  12. import org.springframework.stereotype.Service;
  13. import javax.annotation.Resource;
  14. import java.math.BigDecimal;
  15. import java.math.RoundingMode;
  16. import java.util.*;
  17. import java.util.stream.Collectors;
  18. @Service
  19. public class TimelinessRateService {
  20. // private static final Logger logger = LoggerFactory.getLogger(TimelinessRateService.class);
  21. @Resource
  22. private IEdosUtil edosUtil;
  23. @Resource
  24. private IProEconFaultLiminatedefectsService proEconFaultLiminatedefectsService;
  25. @Resource
  26. private IProEconShutdownEventService proEconShutdownEventService;
  27. public void calEquipmentInfoDay(Date currentDate) throws Exception {
  28. failRate(currentDate);
  29. }
  30. //故障消缺及时率
  31. public void failRate(Date recordDate) {
  32. Map<Date, Map<String, ProEconFaultLiminatedefects>> dtDictionary = new HashMap<>();
  33. Calendar c = Calendar.getInstance();
  34. c.setTime(DateUtils.truncate(recordDate));//本月
  35. c.set(Calendar.DAY_OF_MONTH, 1);
  36. Date begin = c.getTime();
  37. c.add(Calendar.MONTH, 1);
  38. c.add(Calendar.DAY_OF_MONTH, -1);
  39. Date end = c.getTime();
  40. QueryWrapper<ProEconFaultLiminatedefects> queryWrapper = new QueryWrapper<>();
  41. queryWrapper.ge("date_time",recordDate).le("date_time",recordDate);
  42. List<Long> deleteitems = proEconFaultLiminatedefectsService.list(queryWrapper)
  43. .stream()
  44. // .filter(i ->
  45. // (i.getDateTime().compareTo(begin) == 0 || i.getDateTime().after(begin))
  46. // && (i.getDateTime().compareTo(end) == 0 || i.getDateTime().before(end))
  47. // )
  48. .map(ProEconFaultLiminatedefects::getId).collect(Collectors.toList());
  49. List<Long> tempids=new ArrayList<>();
  50. for(int i=0;i<deleteitems.size();i++)
  51. {
  52. tempids.add(deleteitems.get(i));
  53. if(tempids.size()==100)
  54. {
  55. proEconFaultLiminatedefectsService.removeByIds(tempids);
  56. tempids=new ArrayList<>();
  57. }
  58. }
  59. if(!tempids.isEmpty())
  60. {
  61. proEconFaultLiminatedefectsService.removeByIds(tempids);
  62. }
  63. // if (!deleteitems.isEmpty()) {
  64. // proEconFaultLiminatedefectsService.removeByIds(deleteitems);
  65. // }
  66. QueryWrapper<ProEconShutdownEvent> queryWrapper2 = new QueryWrapper<>();
  67. queryWrapper2.ge("stop_Time",begin).le("stop_Time",end)
  68. .isNotNull("stoptype_id").isNotNull("stop_Hours").ne("stoptype_id","wh");
  69. List<ProEconShutdownEvent> st2 = proEconShutdownEventService.list(queryWrapper2);
  70. // .stream()
  71. // .filter(i ->
  72. // (i.getStopTime().compareTo(begin) == 0 || i.getStopTime().after(begin))
  73. // && (i.getStopTime().compareTo(end) == 0 || i.getStopTime().before(end))
  74. // ).collect(Collectors.toList());
  75. for (ProEconShutdownEvent item : st2) {
  76. Date dt = item.getStopTime();
  77. Map<String, ProEconFaultLiminatedefects> fdDictionary;
  78. if (dtDictionary.containsKey(dt)) {
  79. fdDictionary = dtDictionary.get(dt);
  80. } else {
  81. fdDictionary = new HashMap<>();
  82. dtDictionary.put(dt, fdDictionary);
  83. }
  84. ProEconFaultLiminatedefects fs;
  85. if (fdDictionary.containsKey(item.getWindturbineId())) {
  86. fs = fdDictionary.get(item.getWindturbineId());
  87. double temp = fs.getFaultCount();
  88. temp = temp + 1;
  89. fs.setFaultCount(temp);
  90. } else {
  91. fs = new ProEconFaultLiminatedefects();
  92. fs.setWindturbineId(item.getWindturbineId());
  93. fs.setRate(0.0);
  94. fs.setRightCount(0.0);
  95. fs.setFaultCount(0.0);
  96. if (CacheContext.wtmap.containsKey(item.getWindturbineId())) {
  97. ProBasicEquipment wt = CacheContext.wtmap.get(item.getWindturbineId());
  98. fs.setWindpowerstationId(wt.getWindpowerstationId());
  99. fs.setProjectId(wt.getProjectId());
  100. fs.setLineId(wt.getLineId());
  101. }
  102. fs.setDateTime(dt);
  103. double temp = fs.getFaultCount();
  104. temp = temp + 1;
  105. fs.setFaultCount(temp);
  106. fs.setClassifyId("-1");
  107. if (!StringUtils.notEmp(fs.getRightCount())) {
  108. fs.setRightCount(0.0);
  109. }
  110. fdDictionary.put(item.getWindturbineId(), fs);
  111. }
  112. if (item.getStopHours() < 24) {
  113. double temp = fs.getRightCount();
  114. temp = temp + 1;
  115. fs.setRightCount(temp);
  116. }
  117. if (fs.getFaultCount() != 0) {
  118. double temp = BigDecimal.valueOf(fs.getRightCount()).divide(BigDecimal.valueOf(fs.getFaultCount()), 2, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue();
  119. fs.setRate(temp);
  120. }
  121. }
  122. for (Map<String, ProEconFaultLiminatedefects> items : dtDictionary.values()) {
  123. for (ProEconFaultLiminatedefects item : items.values()) {
  124. proEconFaultLiminatedefectsService.save(item);
  125. }
  126. }
  127. }
  128. }