package com.gyee.generation.service; import com.gyee.common.contant.Contant; import com.gyee.common.model.PointData; import com.gyee.common.util.DateUtils; import com.gyee.generation.init.CacheContext; import com.gyee.generation.model.auto.*; import com.gyee.generation.util.realtimesource.IEdosUtil; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; /** * @ClassName : RealtimeSpeedPowerService * @Author : xieshengjie * @Date: 2022/4/24 8:49 * @Description : 场站实时风速,实时功率 */ @Service public class RealtimeSpeedPowerService { @Resource private IEdosUtil edosUtil; private List wpls; private Map> wppromap; private Map> prolinemap; private Map> linewtmap; private Date currentDate; private Map> wppointmap; private Map> linepointmap; private Map> propointmap; private Map> wtpAimap; private void init(){ wpls = CacheContext.wpls; wppromap = CacheContext.wppromap; prolinemap = CacheContext.prolinemap; linewtmap = CacheContext.linewtmap; wppointmap = CacheContext.wppointmap; linepointmap = CacheContext.linepointmap; propointmap = CacheContext.propointmap; wtpAimap = CacheContext.wtpAimap; currentDate = DateUtils.getCurrentDate(); } /** * 计算场站实时风速功率 */ public void calculateRealtimeSpeedPower() throws Exception { init(); List resultList = new ArrayList<>(); wpls.stream().forEach(wp->{ AtomicReference wpPower = new AtomicReference<>(0.0); Map wppointnewMap = wppointmap.get(wp.getId()); Windpowerstationpointnew wppowerpointnew = wppointnewMap.get(Contant.SSZGL); AtomicReference wpcount = new AtomicReference<>(0.0); wppromap.get(wp.getId()).stream().forEach(project -> { AtomicReference projectPower = new AtomicReference<>(0.0); Map propointnewMap = propointmap.get(project.getId()); Windpowerstationpointnew propowerpointnew = propointnewMap.get(Contant.SSZGL); AtomicReference procount = new AtomicReference<>(0.0); prolinemap.get(project.getId()).stream().forEach(line->{ AtomicReference linePower = new AtomicReference<>(0.0); Map linepointnewMap = linepointmap.get(line.getId()); Windpowerstationpointnew linepowerpointnew = linepointnewMap.get(Contant.SSZGL); AtomicReference count = new AtomicReference<>(0.0); if ( linewtmap.containsKey(line.getId())) { List inverters = linewtmap.get(line.getId()); inverters.stream().forEach(wt -> { Map windturbinetestingpointnewMap = wtpAimap.get(wt.getId()); Photovoltaictestingpointnew powerpoint = windturbinetestingpointnewMap.get(Contant.AIG013); Photovoltaictestingpointnew ztpoint = windturbinetestingpointnewMap.get(Contant.ZTMX); Boolean isOffline = false; try { Double ztvalue = edosUtil.getRealData(ztpoint).getPointValueInDouble(); if (ztvalue == 12.0) { isOffline = true; } if (!isOffline) { count.getAndSet(count.get() + 1); procount.getAndSet(procount.get() + 1); wpcount.getAndSet(wpcount.get() + 1); Double wtpower = 0.0; try { wtpower = edosUtil.getRealData(powerpoint).getPointValueInDouble(); Double finalWtpower = wtpower; linePower.updateAndGet(v -> new Double((double) (v + finalWtpower))); projectPower.updateAndGet(v -> new Double((double) (v + finalWtpower))); wpPower.updateAndGet(v -> new Double((double) (v + finalWtpower))); } catch (Exception e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } }); }else { } PointData linepowerPointData = createWpPointData(linepowerpointnew, linePower.get()); resultList.add(linepowerPointData); }); PointData projectpowerPointData = createWpPointData(propowerpointnew, projectPower.get()); resultList.add(projectpowerPointData); }); PointData wppowerPointData = createWpPointData(wppowerpointnew, wpPower.get()); resultList.add(wppowerPointData); }); edosUtil.sendMultiPoint(resultList); } private PointData createWpPointData(Windpowerstationpointnew linepointnew, double linespeed) { PointData pointData = new PointData(); pointData.setEdnaId(linepointnew.getCode()); pointData.setPointTime(currentDate.getTime()); pointData.setPointName(linepointnew.getName()); pointData.setPointValue(String.valueOf(linespeed)); pointData.setPointValueInDouble(linespeed); return pointData; } }