WtAlysisDayService.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. package com.gyee.generation.service;//package com.gyee.generation.service;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.gyee.common.contant.ContantXk;
  4. import com.gyee.common.model.PointData;
  5. import com.gyee.common.model.StringUtils;
  6. import com.gyee.generation.init.CacheContext;
  7. import com.gyee.generation.model.auto.*;
  8. import com.gyee.generation.service.auto.*;
  9. import com.gyee.generation.util.DateUtils;
  10. import com.gyee.generation.util.realtimesource.IEdosUtil;
  11. import com.gyee.generation.util.statisticcs.Initial;
  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.function.Function;
  18. import java.util.stream.Collectors;
  19. @Service
  20. public class WtAlysisDayService {
  21. // private static final Logger logger = LoggerFactory.getLogger(EquipmentInfo1Service.class);
  22. @Resource
  23. private IEdosUtil edosUtil;
  24. @Resource
  25. private IProEconWtAlysisDayService proEconWtAlysisDayService;
  26. @Resource
  27. private IProEconEquipmentInfoDay1Service proEconEquipmentInfoDay1Service;
  28. @Resource
  29. private IProEconEquipmentInfoDay2Service proEconEquipmentInfoDay2Service;
  30. @Resource
  31. private IProEconEquipmentInfoDay3Service proEconEquipmentInfoDay3Service;
  32. @Resource
  33. private IProEconEquipmentInfoDay4Service proEconEquipmentInfoDay4Service;
  34. private Map<String, ProEconEquipmentInfoDay1> queryEquipmentInfoDay1(Date recordDate) {
  35. QueryWrapper<ProEconEquipmentInfoDay1> queryWrapper = new QueryWrapper<>();
  36. queryWrapper.eq("record_date",DateUtils.truncate(recordDate));
  37. List<ProEconEquipmentInfoDay1> iostls= proEconEquipmentInfoDay1Service.list(queryWrapper);
  38. // .stream().filter(i-> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
  39. // )
  40. // .collect(Collectors.toList());
  41. //List转map
  42. Map<String, ProEconEquipmentInfoDay1> iostmap=iostls.stream().
  43. collect(Collectors.toMap(ProEconEquipmentInfoDay1::getWindturbineId, Function.identity(), (key1, key2) -> key2));
  44. return iostmap;
  45. }
  46. private Map<String, ProEconEquipmentInfoDay2> queryEquipmentInfoDay2(Date recordDate) {
  47. QueryWrapper<ProEconEquipmentInfoDay2> queryWrapper = new QueryWrapper<>();
  48. queryWrapper.eq("record_date",DateUtils.truncate(recordDate));
  49. List<ProEconEquipmentInfoDay2> iostls= proEconEquipmentInfoDay2Service.list(queryWrapper);
  50. // .stream().filter(i-> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
  51. // )
  52. // .collect(Collectors.toList());
  53. //List转map
  54. Map<String, ProEconEquipmentInfoDay2> iostmap=iostls.stream().
  55. collect(Collectors.toMap(ProEconEquipmentInfoDay2::getWindturbineId, Function.identity(), (key1, key2) -> key2));
  56. return iostmap;
  57. }
  58. private Map<String, ProEconEquipmentInfoDay3> queryEquipmentInfoDay3(Date recordDate) {
  59. QueryWrapper<ProEconEquipmentInfoDay3> queryWrapper = new QueryWrapper<>();
  60. queryWrapper.eq("record_date",DateUtils.truncate(recordDate));
  61. List<ProEconEquipmentInfoDay3> iostls= proEconEquipmentInfoDay3Service.list(queryWrapper);
  62. // .stream().filter(i-> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
  63. // )
  64. // .collect(Collectors.toList());
  65. //List转map
  66. Map<String, ProEconEquipmentInfoDay3> iostmap=iostls.stream().
  67. collect(Collectors.toMap(ProEconEquipmentInfoDay3::getWindturbineId, Function.identity(), (key1, key2) -> key2));
  68. return iostmap;
  69. }
  70. private Map<String, ProEconEquipmentInfoDay4> queryEquipmentInfoDay4(Date recordDate) {
  71. QueryWrapper<ProEconEquipmentInfoDay4> queryWrapper = new QueryWrapper<>();
  72. queryWrapper.eq("record_date",DateUtils.truncate(recordDate));
  73. List<ProEconEquipmentInfoDay4> iostls= proEconEquipmentInfoDay4Service.list(queryWrapper);
  74. // .stream().filter(i-> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
  75. // )
  76. // .collect(Collectors.toList());
  77. //List转map
  78. Map<String, ProEconEquipmentInfoDay4> iostmap=iostls.stream().
  79. collect(Collectors.toMap(ProEconEquipmentInfoDay4::getWindturbineId, Function.identity(), (key1, key2) -> key2));
  80. return iostmap;
  81. }
  82. /**
  83. * 计算设备日信息
  84. */
  85. public void calEquipmentInfoDay(Date recordDate) throws Exception {
  86. Calendar c=Calendar.getInstance();
  87. c.setTime(recordDate);
  88. Date end=c.getTime();
  89. Date begin= DateUtils.truncate(c.getTime());
  90. //判断是否有重复记录,
  91. QueryWrapper<ProEconWtAlysisDay> queryWrapper = new QueryWrapper<>();
  92. queryWrapper.eq("record_date",DateUtils.truncate(recordDate));
  93. List<Long> idls = proEconWtAlysisDayService.list(queryWrapper).stream()
  94. // .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate))==0
  95. // && CacheContext.wtmap.containsKey(i.getWindturbineId()))
  96. .map(ProEconWtAlysisDay::getId)
  97. .collect(Collectors.toList());
  98. if (idls.size() > 0) {
  99. proEconWtAlysisDayService.removeByIds(idls);
  100. }
  101. Map<String, ProEconEquipmentInfoDay1> eqday1map = queryEquipmentInfoDay1(recordDate);
  102. Map<String, ProEconEquipmentInfoDay2> eqday2map = queryEquipmentInfoDay2(recordDate);
  103. Map<String, ProEconEquipmentInfoDay3> eqday3map = queryEquipmentInfoDay3(recordDate);
  104. Map<String, ProEconEquipmentInfoDay4> eqday4map = queryEquipmentInfoDay4(recordDate);
  105. List<ProEconWtAlysisDay> dayls=new ArrayList<>();
  106. for(ProBasicEquipment wt:CacheContext.wtls)
  107. {
  108. ProEconWtAlysisDay pewp=new ProEconWtAlysisDay();
  109. Initial.initial(pewp);
  110. pewp.setRecordDate(DateUtils.truncate(recordDate));
  111. pewp.setWindturbineId(wt.getId());
  112. if(eqday1map.containsKey(wt.getId()))
  113. {
  114. ProEconEquipmentInfoDay1 dayinfo= eqday1map.get(wt.getId());
  115. pewp.setRfdl(dayinfo.getRfdl());
  116. pewp.setRpjfs(dayinfo.getRpjfs());
  117. pewp.setRpjgl(dayinfo.getRpjgl());
  118. pewp.setRyfdl(dayinfo.getRllfdl());
  119. double gzss=dayinfo.getRgzssdl();
  120. double jxss=dayinfo.getRjxssdl();
  121. double xnss=dayinfo.getRxnssdl();
  122. double xdss=dayinfo.getRxdtjssdl()+dayinfo.getRxdjclssdl();
  123. double slss=dayinfo.getRcwsltqssdl()+dayinfo.getRcwsldwssdl();
  124. double ssdl=gzss+jxss+xnss+xdss+slss;
  125. pewp.setRssdl(StringUtils.round(ssdl,2));
  126. pewp.setYfdl(dayinfo.getYfdl());
  127. pewp.setYpjfs(dayinfo.getYpjfs());
  128. pewp.setYpjgl(dayinfo.getYpjgl());
  129. pewp.setYyfdl(dayinfo.getYllfdl());
  130. gzss=dayinfo.getYgzssdl();
  131. jxss=dayinfo.getYjxssdl();
  132. xnss=dayinfo.getYxnssdl();
  133. xdss=dayinfo.getYxdtjssdl()+dayinfo.getYxdjclssdl();
  134. slss=dayinfo.getYcwsltqssdl()+dayinfo.getYcwsldwssdl();
  135. ssdl=gzss+jxss+xnss+xdss+slss;
  136. pewp.setYssdl(StringUtils.round(ssdl,2));
  137. pewp.setNfdl(dayinfo.getNfdl());
  138. pewp.setNpjfs(dayinfo.getNpjfs());
  139. pewp.setNpjgl(dayinfo.getNpjgl());
  140. pewp.setNyfdl(dayinfo.getNllfdl());
  141. gzss=dayinfo.getNgzssdl();
  142. jxss=dayinfo.getNjxssdl();
  143. xnss=dayinfo.getNxnssdl();
  144. xdss=dayinfo.getNxdtjssdl()+dayinfo.getNxdjclssdl();
  145. slss=dayinfo.getNcwsltqssdl()+dayinfo.getNcwsldwssdl();
  146. ssdl=gzss+jxss+xnss+xdss+slss;
  147. pewp.setNssdl(StringUtils.round(ssdl,2));
  148. }
  149. if(eqday2map.containsKey(wt.getId()))
  150. {
  151. ProEconEquipmentInfoDay2 dayinfo= eqday2map.get(wt.getId());
  152. pewp.setRyxxs(dayinfo.getRyxxs());
  153. pewp.setRgzxs(dayinfo.getRgztjxs());
  154. pewp.setRjxxs(dayinfo.getRjxtjxs());
  155. pewp.setRzdxs(dayinfo.getRxdxs());
  156. pewp.setRzdxs(dayinfo.getRtxzdxs());
  157. int dayTimes=24;
  158. double sbklyl = new BigDecimal(dayTimes-dayinfo.getRgztjxs()).divide(new BigDecimal(dayTimes), 2, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue();//风机平均设备可利用率
  159. pewp.setRsbklyl(StringUtils.round(sbklyl, 2));
  160. pewp.setYyxxs(dayinfo.getYyxxs());
  161. pewp.setYgzxs(dayinfo.getYgztjxs());
  162. pewp.setYjxxs(dayinfo.getYjxtjxs());
  163. pewp.setYzdxs(dayinfo.getYxdxs());
  164. pewp.setYzdxs(dayinfo.getYtxzdxs());
  165. c.setTime(recordDate);
  166. int days=c.get(Calendar.DAY_OF_MONTH);
  167. dayTimes=24*days;
  168. sbklyl = new BigDecimal(dayTimes-dayinfo.getYgztjxs()).divide(new BigDecimal(dayTimes), 2, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue();//风机平均设备可利用率
  169. pewp.setYsbklyl(StringUtils.round(sbklyl, 2));
  170. pewp.setNyxxs(dayinfo.getNyxxs());
  171. pewp.setNgzxs(dayinfo.getNgztjxs());
  172. pewp.setNjxxs(dayinfo.getNjxtjxs());
  173. pewp.setNzdxs(dayinfo.getNxdxs());
  174. pewp.setNzdxs(dayinfo.getNtxzdxs());
  175. days=c.get(Calendar.DAY_OF_YEAR);
  176. dayTimes=24*days;
  177. sbklyl = new BigDecimal(dayTimes-dayinfo.getNgztjxs()).divide(new BigDecimal(dayTimes), 2, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue();//风机平均设备可利用率
  178. pewp.setNsbklyl(StringUtils.round(sbklyl, 2));
  179. }
  180. if(eqday3map.containsKey(wt.getId()))
  181. {
  182. ProEconEquipmentInfoDay3 dayinfo= eqday3map.get(wt.getId());
  183. pewp.setRtjcs(dayinfo.getRgztjcs()+dayinfo.getRjxtjcs());
  184. pewp.setYtjcs(dayinfo.getYgztjcs()+dayinfo.getYjxtjcs());
  185. pewp.setNtjcs(dayinfo.getNgztjcs()+dayinfo.getNjxtjcs());
  186. }
  187. if(eqday4map.containsKey(wt.getId()))
  188. {
  189. ProEconEquipmentInfoDay4 dayinfo= eqday4map.get(wt.getId());
  190. pewp.setRnhyd(dayinfo.getRnhyd());
  191. pewp.setRsjbz(dayinfo.getRqxpcbbzsj());
  192. pewp.setRyxfs(dayinfo.getRyxfss());
  193. pewp.setYnhyd(dayinfo.getYnhyd());
  194. pewp.setYsjbz(dayinfo.getYqxpcbbzsj());
  195. pewp.setYyxfs(dayinfo.getYyxfss());
  196. pewp.setNnhyd(dayinfo.getNnhyd());
  197. pewp.setNsjbz(dayinfo.getNqxpcbbzsj());
  198. pewp.setNyxfs(dayinfo.getNyxfss());
  199. }
  200. //昨日的统计结果
  201. List<ProEconWtAlysisDay> pepidls =new ArrayList<>();
  202. Calendar cl=Calendar.getInstance();
  203. cl.setTime(recordDate);
  204. cl.add(Calendar.DAY_OF_MONTH,-1);
  205. if(cl.get(Calendar.DAY_OF_MONTH)!=1)
  206. {
  207. QueryWrapper<ProEconWtAlysisDay> queryWrapper2 = new QueryWrapper<>();
  208. queryWrapper2.eq("record_date",DateUtils.truncate(cl.getTime())).eq("windTurbine_Id",wt.getId());
  209. pepidls = proEconWtAlysisDayService.list(queryWrapper2);
  210. // .stream()
  211. // .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(cl.getTime())) == 0
  212. // && i.getWindturbineId().equals(wt.getId())
  213. // )
  214. // .collect(Collectors.toList());
  215. }
  216. calSimple(pewp, end, begin, wt, pepidls);
  217. dayls.add(pewp);
  218. }
  219. proEconWtAlysisDayService.saveBatch(dayls);
  220. }
  221. private void calSimple(ProEconWtAlysisDay pewp, Date end, Date begin, ProBasicEquipment wt, List<ProEconWtAlysisDay> pepidls) throws Exception {
  222. //*******************************************日信息统计*********************************************************/
  223. double lastState=-1;//上一分钟状态
  224. double bbhcs=0;//不饱和次数
  225. Map<String, Map<String, ProBasicEquipmentPoint>> wtpAimap = CacheContext.wtpAimap;
  226. Map<String, ProBasicEquipmentPoint> aimap=wtpAimap.get(wt.getId());
  227. if(aimap.containsKey(ContantXk.SSQFZT))
  228. {
  229. ProBasicEquipmentPoint point=aimap.get(ContantXk.SSQFZT);
  230. //按照分钟时间进行统计状态快照值
  231. List<PointData> pointls=edosUtil.getHistoryDatasSnap(point.getNemCode(), begin.getTime()/1000, end.getTime()/1000);
  232. if(!pointls.isEmpty()) {
  233. for (PointData po : pointls) {
  234. if (po.getPointValueInDouble() >=3) {
  235. if (lastState != po.getPointValueInDouble()) {
  236. //将当前状态保存到上一分钟状态
  237. lastState = po.getPointValueInDouble();
  238. //实时欠发大于等于3的次数加1
  239. bbhcs++;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. //日不饱和次数
  246. pewp.setRbbhcs(bbhcs);
  247. //*******************************************日信息统计*********************************************************/
  248. //*******************************************月信息统计*********************************************************/
  249. if(pepidls.isEmpty())
  250. {
  251. pewp.setYbbhcs(pewp.getRbbhcs());
  252. }else
  253. {
  254. ProEconWtAlysisDay pepid=pepidls.get(0);
  255. pewp.setYbbhcs(StringUtils.round(pepid.getYbbhcs()+pewp.getRbbhcs(),2));
  256. }
  257. //*******************************************月信息统计*********************************************************/
  258. //*******************************************年信息统计*********************************************************/
  259. if(pepidls.isEmpty())
  260. {
  261. pewp.setNbbhcs(pewp.getRbbhcs());
  262. }else
  263. {
  264. ProEconWtAlysisDay pepid=pepidls.get(0);
  265. pewp.setNbbhcs(StringUtils.round(pepid.getNbbhcs()+pewp.getRbbhcs(),2));
  266. }
  267. //*******************************************年信息统计*********************************************************/
  268. }
  269. }