package com.gyee.generation.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.gyee.common.contant.ContantXk; import com.gyee.common.model.PointData; import com.gyee.generation.init.CacheContext; import com.gyee.generation.model.auto.*; import com.gyee.generation.model.vo.StatData; import com.gyee.generation.model.vo.StatusDetailValue; import com.gyee.generation.model.vo.StatusValue; import com.gyee.generation.service.auto.IProEconBrownoutsEvent2Service; import com.gyee.generation.service.auto.IProEconBrownoutsEventService; import com.gyee.generation.service.auto.IProEconMainBrownouts2Service; import com.gyee.generation.service.auto.IProEconMainBrownoutsService; import com.gyee.generation.util.DateUtils; import com.gyee.generation.util.StringUtils; import com.gyee.generation.util.realtimesource.IEdosUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @Service public class LimitEventnewService { @Resource private IProEconBrownoutsEventService proEconBrownoutsEventService; @Resource private IProEconMainBrownoutsService proEconMainBrownoutsService; @Resource private IProEconBrownoutsEvent2Service proEconBrownoutsEvent2Service; @Resource private IProEconMainBrownouts2Service proEconMainBrownouts2Service; @Resource private IEdosUtil edosUtil; @Value("${frequency.powerrationing}") private Integer frequency; public static Logger logger = LoggerFactory.getLogger(ShutdownnewService.class); public void execBrownouts(Date recordDate) throws Exception { Map oldBrownoutsStatusMap = new HashMap<>(); Map oldBrownoutsStatus2Map = new HashMap<>(); Map oldMainBrownoutsMap = new HashMap<>(); Map oldMainBrownouts2Map = new HashMap<>(); List wpStatusIdLs = new ArrayList<>(); List wtStatusIdLs = new ArrayList<>(); List wpSpeedIdLs = new ArrayList<>(); List wtSpeedIdLs = new ArrayList<>(); List wpPowerIdLs = new ArrayList<>(); List wtPowerIdLs = new ArrayList<>(); Map wpStatusMap = new HashMap<>(); Map wtStatusMap = new HashMap<>(); Map wpSpeedMap = new HashMap<>(); Map wtSpeedMap = new HashMap<>(); Map wpPowerMap = new HashMap<>(); Map wtPowerMap = new HashMap<>(); List wpls=new ArrayList<>(); for (ProBasicPowerstation wp : CacheContext.wpls) { if(wp.getId().contains("GDC")) { continue; } wpls.add(wp); } for (ProBasicPowerstation wp :wpls) { //初始化将所有风场编号作为key,value全部赋值为null oldMainBrownoutsMap.put(wp.getId(), null); oldMainBrownouts2Map.put(wp.getId(), null); Map wppointmap = CacheContext.wppointmap.get(wp.getId()); //取实时状态数据 赋值给status if (wppointmap.containsKey(ContantXk.CZZT)) { ProBasicPowerstationPoint mxztPoint = wppointmap.get(ContantXk.CZZT); wpStatusIdLs.add(mxztPoint.getNemCode()); } //取实时风速数据 if (wppointmap.containsKey(ContantXk.SSPJFS)) { ProBasicPowerstationPoint mxztPoint = wppointmap.get(ContantXk.SSPJFS); wpSpeedIdLs.add(mxztPoint.getNemCode()); } //取实时功率数据 if (wppointmap.containsKey(ContantXk.SSZGL)) { ProBasicPowerstationPoint mxztPoint = wppointmap.get(ContantXk.SSZGL); wpPowerIdLs.add(mxztPoint.getNemCode()); } } List wpStatusLs = edosUtil.getHistMatrix(wpStatusIdLs,recordDate.getTime()/1000); List wpSpeedLs = edosUtil.getHistMatrix(wpSpeedIdLs,recordDate.getTime()/1000); List wpPowerLs = edosUtil.getHistMatrix(wpPowerIdLs,recordDate.getTime()/1000); if (wpStatusLs.size() == wpls.size() && wpSpeedLs.size() ==wpls.size() && wpPowerLs.size() == wpls.size()) { for (int i = 0; i < wpls.size(); i++) { ProBasicPowerstation wp = wpls.get(i); wpStatusMap.put(wp.getId(), wpStatusLs.get(i)); wpSpeedMap.put(wp.getId(), wpSpeedLs.get(i)); wpPowerMap.put(wp.getId(), wpPowerLs.get(i)); } } List wtls=new ArrayList<>(); for (ProBasicEquipment wt : CacheContext.wtls) { if(wt.getWindpowerstationId().contains("GDC")) { continue; } wtls.add(wt); } for (ProBasicEquipment wt :wtls) { //初始化将所有风机编号作为key,value全部赋值为null oldBrownoutsStatusMap.put(wt.getId(), null); oldBrownoutsStatus2Map.put(wt.getId(), null); Map windturbinetestingpointnewMap = CacheContext.wtpAimap.get(wt.getId()); //取实时状态数据 赋值给status if (windturbinetestingpointnewMap.containsKey(ContantXk.MXZT)) { ProBasicEquipmentPoint mxztPoint = windturbinetestingpointnewMap.get(ContantXk.MXZT); wtStatusIdLs.add(mxztPoint.getNemCode()); } //取实时风速数据 if (windturbinetestingpointnewMap.containsKey(ContantXk.CJ_SSFS)) { ProBasicEquipmentPoint mxztPoint = windturbinetestingpointnewMap.get(ContantXk.CJ_SSFS); wtSpeedIdLs.add(mxztPoint.getNemCode()); } //取实时功率数据 if (windturbinetestingpointnewMap.containsKey(ContantXk.CJ_SSGL)) { ProBasicEquipmentPoint mxztPoint = windturbinetestingpointnewMap.get(ContantXk.CJ_SSGL); wtPowerIdLs.add(mxztPoint.getNemCode()); } } List wtStatusLs = edosUtil.getRealData(wtStatusIdLs); List wtSpeedLs = edosUtil.getRealData(wtSpeedIdLs); List wtPowerLs = edosUtil.getRealData(wtPowerIdLs); if (wtStatusLs.size() == wtls.size() && wtSpeedLs.size() == wtls.size() && wtPowerLs.size() == wtls.size()) { for (int i = 0; i < wtls.size(); i++) { ProBasicEquipment wt = wtls.get(i); wtStatusMap.put(wt.getId(), wtStatusLs.get(i)); wtSpeedMap.put(wt.getId(), wtSpeedLs.get(i)); wtPowerMap.put(wt.getId(), wtPowerLs.get(i)); } } //******************************************************************************************************/ //读取数据库存在的恢复时间为NULL的数据,并通过风机编号把数据遍历到对应的map QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.isNull("start_Time"); queryWrapper.orderByDesc("stop_Time"); List oldStatusQuery = proEconMainBrownoutsService.list(queryWrapper).stream().collect(Collectors.toList()); for (ProEconMainBrownouts oldMainBrownouts : oldStatusQuery) { if (oldMainBrownoutsMap.containsKey(oldMainBrownouts.getWindpowerstationId())) { oldMainBrownoutsMap.put(oldMainBrownouts.getWindpowerstationId(), oldMainBrownouts); } } QueryWrapper queryWrapper2 = new QueryWrapper<>(); queryWrapper2.isNull("start_Time"); queryWrapper2.orderByDesc("stop_Time"); List oldStatus2Query = proEconMainBrownouts2Service.list(queryWrapper2).stream().collect(Collectors.toList()); for (ProEconMainBrownouts2 oldMainBrownouts2 : oldStatus2Query) { if (oldMainBrownouts2Map.containsKey(oldMainBrownouts2.getWindpowerstationId())) { oldMainBrownouts2Map.put(oldMainBrownouts2.getWindpowerstationId(), oldMainBrownouts2); } } QueryWrapper queryWrapper3 = new QueryWrapper<>(); queryWrapper3.isNull("start_Time"); queryWrapper3.orderByDesc("stop_Time"); List oldStatus3Query = proEconBrownoutsEventService.list(queryWrapper3).stream().collect(Collectors.toList()); for (ProEconBrownoutsEvent oldBrownouts : oldStatus3Query) { if (oldBrownoutsStatusMap.containsKey(oldBrownouts.getWindturbineId())) { oldBrownoutsStatusMap.put(oldBrownouts.getWindturbineId(), oldBrownouts); } } QueryWrapper queryWrapper4 = new QueryWrapper<>(); queryWrapper4.isNull("start_Time"); queryWrapper3.orderByDesc("stop_Time"); List oldStatus4Query = proEconBrownoutsEvent2Service.list(queryWrapper4).stream().collect(Collectors.toList()); for (ProEconBrownoutsEvent2 oldBrownouts2 : oldStatus4Query) { if (oldBrownoutsStatus2Map.containsKey(oldBrownouts2.getWindturbineId())) { oldBrownoutsStatus2Map.put(oldBrownouts2.getWindturbineId(), oldBrownouts2); } } //*************************主表数据计算*****************************************************************************/ List updateMainBrownouts2ls = new ArrayList<>(); List updateMainBrownoutsls = new ArrayList<>(); List insertMainBrownouts2ls = new ArrayList<>(); List insertMainBrownoutsls = new ArrayList<>(); //遍历PG数据库中存在的记录,恢复时间为空的集合 for (String wpId : oldMainBrownoutsMap.keySet()) { ProEconMainBrownouts mainBrownouts = null; ProEconMainBrownouts2 mainBrownouts2 = null; if (oldMainBrownoutsMap.containsKey(wpId)) { mainBrownouts = oldMainBrownoutsMap.get(wpId); } if (oldMainBrownouts2Map.containsKey(wpId)) { mainBrownouts2 = oldMainBrownouts2Map.get(wpId); } if (wpStatusMap.containsKey(wpId)) { PointData wpPoint = wpStatusMap.get(wpId); //获取当前时间 Date currentTime = recordDate; if (wpPoint.getPointValueInDouble() == StatusValue.XD.getCode() ) { if (StringUtils.empty(mainBrownouts)) { mainBrownouts=new ProEconMainBrownouts(); intialMainBrownouts(insertMainBrownoutsls, wpId, wpStatusMap, wpSpeedMap, wpPowerMap, currentTime, mainBrownouts); } if (StringUtils.empty(mainBrownouts2)) { mainBrownouts2=new ProEconMainBrownouts2(); intialMainBrownouts2(insertMainBrownouts2ls, wpId, wpStatusMap, wpSpeedMap, wpPowerMap, currentTime, mainBrownouts2); } }else { if (StringUtils.notEmp(mainBrownouts) ) { finishMainBrownouts(updateMainBrownoutsls, wpId, mainBrownouts, currentTime); } if (StringUtils.notEmp(mainBrownouts2)) { finishMainBrownouts2(updateMainBrownouts2ls, wpId, wpStatusMap, wpSpeedMap, wpPowerMap, mainBrownouts2, currentTime); } } } List templs = new ArrayList<>(); for (ProEconMainBrownouts vo : insertMainBrownoutsls) { templs.add(vo); if (templs.size() == 100) { proEconMainBrownoutsService.saveBatch(templs); templs = new ArrayList<>(); } } if (!templs.isEmpty()) { proEconMainBrownoutsService.saveBatch(templs); } List templs2 = new ArrayList<>(); for (ProEconMainBrownouts2 vo : insertMainBrownouts2ls) { templs2.add(vo); if (templs2.size() == 100) { proEconMainBrownouts2Service.saveBatch(templs2); templs2 = new ArrayList<>(); } } if (!templs2.isEmpty()) { proEconMainBrownouts2Service.saveBatch(templs2); } for (ProEconMainBrownouts vo : updateMainBrownoutsls) { UpdateWrapper updateWrapper = new UpdateWrapper<>(); // updateWrapper.set("start_time", vo.getStartTime()); // updateWrapper.set("loss_power", vo.getLossPower()); // updateWrapper.set("stop_hours", vo.getStopHours()); // proEconMainBrownoutsService.update(vo, updateWrapper); proEconMainBrownoutsService.updateMainBrownouts(vo.getStartTime(),vo.getLossPower(),vo.getStopHours(),vo.getId()); } for (ProEconMainBrownouts2 vo : updateMainBrownouts2ls) { UpdateWrapper updateWrapper = new UpdateWrapper<>(); // updateWrapper.set("start_time", vo.getStartTime()); // updateWrapper.set("loss_power", vo.getLossPower()); // updateWrapper.set("stop_hours", vo.getStopHours()); // proEconMainBrownouts2Service.update(vo, updateWrapper); proEconMainBrownouts2Service.updateMainBrownouts2(vo.getStartTime(),vo.getLossPower(),vo.getStopHours(),vo.getId()); } } //*************************主表数据计算*****************************************************************************/ //*************************子表数据计算*****************************************************************************/ extractedBrownouts(oldBrownoutsStatusMap, wtStatusMap, wtSpeedMap, wtPowerMap, insertMainBrownoutsls); extractedBrownouts(oldBrownoutsStatusMap, wtStatusMap, wtSpeedMap, wtPowerMap, updateMainBrownoutsls); extractedBrownouts2(oldBrownoutsStatus2Map, wtStatusMap, wtSpeedMap, wtPowerMap, insertMainBrownouts2ls); extractedBrownouts2(oldBrownoutsStatus2Map, wtStatusMap, wtSpeedMap, wtPowerMap, updateMainBrownouts2ls); //*************************子表数据计算*****************************************************************************/ //******************************************************************************************************/ } private void extractedBrownouts(Map oldBrownoutsStatusMap, Map wtStatusMap, Map wtSpeedMap, Map wtPowerMap, List mainBrownoutsls) throws Exception { //遍历PG数据库中存在的记录,恢复时间为空的集合 for (ProEconMainBrownouts mb : mainBrownoutsls) { List wtls = CacheContext.wpwtmap.get(mb.getWindpowerstationId()); List updateBrownoutsEventls = new ArrayList<>(); List insertBrownoutsEventls = new ArrayList<>(); for (ProBasicEquipment wt : wtls) { extractedProBasicEquipment(mb, oldBrownoutsStatusMap, wtStatusMap, wtSpeedMap, wtPowerMap, updateBrownoutsEventls, insertBrownoutsEventls, wt); } List templs = new ArrayList<>(); for (ProEconBrownoutsEvent vo : insertBrownoutsEventls) { templs.add(vo); if (templs.size() == 100) { proEconBrownoutsEventService.saveBatch(templs); templs = new ArrayList<>(); } } if (!templs.isEmpty()) { proEconBrownoutsEventService.saveBatch(templs); } for (ProEconBrownoutsEvent vo : updateBrownoutsEventls) { UpdateWrapper updateWrapper = new UpdateWrapper<>(); // updateWrapper.set("start_time", vo.getStartTime()); // updateWrapper.set("loss_power", vo.getLossPower()); // updateWrapper.set("stop_hours", vo.getStopHours()); // proEconBrownoutsEventService.update(vo, updateWrapper); proEconBrownoutsEventService.updateBrownouts(vo.getStartTime(),vo.getLossPower(),vo.getStopHours(),vo.getId()); } } } private void extractedBrownouts2( Map oldBrownoutsStatus2Map, Map wtStatusMap, Map wtSpeedMap, Map wtPowerMap, List mainBrownouts2ls) throws Exception { //遍历PG数据库中存在的记录,恢复时间为空的集合 for (ProEconMainBrownouts2 mb : mainBrownouts2ls) { List wtls = CacheContext.wpwtmap.get(mb.getWindpowerstationId()); List updateBrownoutsEvent2ls = new ArrayList<>(); List updateBrownoutsEventls = new ArrayList<>(); List insertBrownoutsEvent2ls = new ArrayList<>(); List insertBrownoutsEventls = new ArrayList<>(); for (ProBasicEquipment wt : wtls) { extractedProBasicEquipment(mb, oldBrownoutsStatus2Map, wtStatusMap, wtSpeedMap, wtPowerMap, updateBrownoutsEvent2ls, insertBrownoutsEvent2ls, wt); } List templs2 = new ArrayList<>(); for (ProEconBrownoutsEvent2 vo : insertBrownoutsEvent2ls) { templs2.add(vo); if (templs2.size() == 100) { proEconBrownoutsEvent2Service.saveBatch(templs2); templs2 = new ArrayList<>(); } } if (!templs2.isEmpty()) { proEconBrownoutsEvent2Service.saveBatch(templs2); } for (ProEconBrownoutsEvent2 vo : updateBrownoutsEvent2ls) { UpdateWrapper updateWrapper = new UpdateWrapper<>(); // updateWrapper.set("start_time", vo.getStartTime()); // updateWrapper.set("loss_power", vo.getLossPower()); // updateWrapper.set("stop_hours", vo.getStopHours()); // proEconBrownoutsEvent2Service.update(vo, updateWrapper); proEconBrownoutsEvent2Service.updateBrownouts2(vo.getStartTime(),vo.getLossPower(),vo.getStopHours(),vo.getId()); } } } private void extractedProBasicEquipment(ProEconMainBrownouts mb, Map oldBrownoutsStatusMap, Map wtStatusMap, Map wtSpeedMap, Map wtPowerMap, List updateBrownoutsEventls, List insertBrownoutsEventls, ProBasicEquipment wt) throws Exception { String wtId = wt.getId(); ProEconBrownoutsEvent brownouts = null; if (oldBrownoutsStatusMap.containsKey(wtId)) { brownouts = oldBrownoutsStatusMap.get(wtId); } if (wtStatusMap.containsKey(wtId)) { PointData wtPoint = wtStatusMap.get(wtId); //获取当前时间 Date currentTime = new Date(wtPoint.getPointTime()); if (wtPoint.getPointValueInDouble() == StatusDetailValue.XDJCL.getCode() || wtPoint.getPointValueInDouble() == StatusDetailValue.XDTJ.getCode()) { if (StringUtils.empty(brownouts)) { brownouts=new ProEconBrownoutsEvent(); intialBrownoutsEvent(mb, insertBrownoutsEventls, wtId, wtStatusMap, wtSpeedMap, wtPowerMap, currentTime, brownouts); } } else { if (StringUtils.notEmp(brownouts)) { finishBrownoutsEvent(updateBrownoutsEventls, wtId, brownouts, currentTime); } } } } private void extractedProBasicEquipment(ProEconMainBrownouts2 mb, Map oldBrownoutsStatus2Map, Map wtStatusMap, Map wtSpeedMap, Map wtPowerMap, List updateBrownoutsEvent2ls, List insertBrownoutsEvent2ls, ProBasicEquipment wt) throws Exception { String wtId = wt.getId(); ProEconBrownoutsEvent2 brownouts2 = null; if (oldBrownoutsStatus2Map.containsKey(wtId)) { brownouts2 = oldBrownoutsStatus2Map.get(wtId); } if (wtStatusMap.containsKey(wtId)) { PointData wtPoint = wtStatusMap.get(wtId); //获取当前时间 Date currentTime = new Date(wtPoint.getPointTime()); if (wtPoint.getPointValueInDouble() == StatusDetailValue.XDJCL.getCode() || wtPoint.getPointValueInDouble() == StatusDetailValue.XDTJ.getCode()) { if (StringUtils.empty(brownouts2)) { brownouts2=new ProEconBrownoutsEvent2(); intialBrownoutsEvent2(mb, insertBrownoutsEvent2ls, wtId, wtStatusMap, wtSpeedMap, wtPowerMap, currentTime, brownouts2); } } else { if (StringUtils.notEmp(brownouts2)) { finishBrownoutsEvent2(mb, updateBrownoutsEvent2ls, wtId, wtStatusMap, wtSpeedMap, wtPowerMap, brownouts2, currentTime); } } } } private void intialBrownoutsEvent(ProEconMainBrownouts mb, List insertBrownoutsEventls, String wtId, Map wtStatusMap, Map wtSpeedMap, Map wtPowerMap, Date currentTime, ProEconBrownoutsEvent brownouts) throws Exception { brownouts.setMainId(mb.getId()); brownouts.setId(StringUtils.getUUID()); brownouts.setStopTime(currentTime); brownouts.setStartTime(null); if (wtStatusMap.get(wtId).getPointValueInDouble() == StatusDetailValue.XDTJ.getCode()) { brownouts.setStopTypeId(StatusDetailValue.XDTJ.getName()); } if (wtStatusMap.get(wtId).getPointValueInDouble() == StatusDetailValue.XDJCL.getCode()) { brownouts.setStopTypeId(StatusDetailValue.XDJCL.getName()); } if (wtSpeedMap.containsKey(wtId)) { brownouts.setWindSpeed(StringUtils.round(wtSpeedMap.get(wtId).getPointValueInDouble(), 2)); } if (wtPowerMap.containsKey(wtId)) { brownouts.setLimitLoad(StringUtils.round(wtPowerMap.get(wtId).getPointValueInDouble(), 2)); } Map wtpointmap = CacheContext.wtpAimap.get(wtId); long pried = DateUtils.secondsDiff(DateUtils.addMinutes(currentTime, -5), currentTime); List hsls = edosUtil.getHistStat(wtpointmap.get(ContantXk.SSZGL), DateUtils.addMinutes(currentTime, -5).getTime() / 1000, currentTime.getTime() / 1000, 1L, pried, StatData.MAX.getValue()); if (StringUtils.notEmp(hsls) && hsls.size() > 0) { brownouts.setThisLoad(hsls.get(0).getPointValueInDouble()); } brownouts.setWindpowerstationId(wtId); brownouts.setLossPower(0.0); insertBrownoutsEventls.add(brownouts); } private void intialBrownoutsEvent2(ProEconMainBrownouts2 mb, List insertBrownoutsEvent2ls, String wtId, Map wtStatusMap, Map wtSpeedMap, Map wtPowerMap, Date currentTime, ProEconBrownoutsEvent2 brownouts) throws Exception { brownouts.setMainId(mb.getId()); brownouts.setId(StringUtils.getUUID()); brownouts.setStopTime(currentTime); brownouts.setStartTime(null); if (wtStatusMap.get(wtId).getPointValueInDouble() == StatusDetailValue.XDTJ.getCode()) { brownouts.setStopTypeId(StatusDetailValue.XDTJ.getName()); } if (wtStatusMap.get(wtId).getPointValueInDouble() == StatusDetailValue.XDJCL.getCode()) { brownouts.setStopTypeId(StatusDetailValue.XDJCL.getName()); } if (wtSpeedMap.containsKey(wtId)) { brownouts.setWindSpeed(StringUtils.round(wtSpeedMap.get(wtId).getPointValueInDouble(), 2)); } if (wtPowerMap.containsKey(wtId)) { brownouts.setLimitLoad(StringUtils.round(wtPowerMap.get(wtId).getPointValueInDouble(), 2)); } Map wtpointmap = CacheContext.wtpAimap.get(wtId); long pried = DateUtils.secondsDiff(DateUtils.addMinutes(currentTime, -5), currentTime); List hsls = edosUtil.getHistStat(wtpointmap.get(ContantXk.SSZGL), DateUtils.addMinutes(currentTime, -5).getTime() / 1000, currentTime.getTime() / 1000, 1L, pried, StatData.MAX.getValue()); if (StringUtils.notEmp(hsls) && hsls.size() > 0) { brownouts.setThisLoad(hsls.get(0).getPointValueInDouble()); } brownouts.setWindpowerstationId(wtId); brownouts.setLossPower(0.0); insertBrownoutsEvent2ls.add(brownouts); } private ProEconBrownoutsEvent2 intialBrownoutsEventnew2(ProEconMainBrownouts2 mb, String wtId, Map wtStatusMap, Map wtSpeedMap, Map wtPowerMap, Date currentTime) throws Exception { ProEconBrownoutsEvent2 brownouts=new ProEconBrownoutsEvent2(); brownouts.setMainId(mb.getId()); brownouts.setId(StringUtils.getUUID()); brownouts.setStopTime(currentTime); brownouts.setStartTime(null); if (wtStatusMap.get(wtId).getPointValueInDouble() == StatusDetailValue.XDTJ.getCode()) { brownouts.setStopTypeId(StatusDetailValue.XDTJ.getName()); } if (wtStatusMap.get(wtId).getPointValueInDouble() == StatusDetailValue.XDJCL.getCode()) { brownouts.setStopTypeId(StatusDetailValue.XDJCL.getName()); } if (wtSpeedMap.containsKey(wtId)) { brownouts.setWindSpeed(StringUtils.round(wtSpeedMap.get(wtId).getPointValueInDouble(), 2)); } if (wtPowerMap.containsKey(wtId)) { brownouts.setLimitLoad(StringUtils.round(wtPowerMap.get(wtId).getPointValueInDouble(), 2)); } Map wtpointmap = CacheContext.wtpAimap.get(wtId); long pried = DateUtils.secondsDiff(DateUtils.addMinutes(currentTime, -5), currentTime); List hsls = edosUtil.getHistStat(wtpointmap.get(ContantXk.SSZGL), DateUtils.addMinutes(currentTime, -5).getTime() / 1000, currentTime.getTime() / 1000, 1L, pried, StatData.MAX.getValue()); if (StringUtils.notEmp(hsls) && hsls.size() > 0) { brownouts.setThisLoad(hsls.get(0).getPointValueInDouble()); } brownouts.setWindpowerstationId(wtId); brownouts.setLossPower(0.0); return brownouts; } private void finishBrownoutsEvent2(ProEconMainBrownouts2 mb, List proEconBrownoutsEvent2ls, String wtId, Map wtStatusMap, Map wtSpeedMap, Map wtPowerMap, ProEconBrownoutsEvent2 brownouts2, Date currentTime) throws Exception { brownouts2.setStartTime(currentTime); double timehour = DateUtils.hoursDiff2(brownouts2.getStartTime(), brownouts2.getStopTime()); brownouts2.setStopHours(timehour); double losspower = calWpLossPower(wtId, brownouts2.getStartTime(), brownouts2.getStopTime()); brownouts2.setLossPower(losspower); if (timehour <= 24) { proEconBrownoutsEvent2ls.add(brownouts2); } else { int days = DateUtils.daysDiff1(brownouts2.getStartTime(), brownouts2.getStopTime()); Calendar c = Calendar.getInstance(); Date startTime = brownouts2.getStartTime(); c.setTime(brownouts2.getStopTime()); c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); for (int i = 0; i < days; i++) { if (i == 0) { brownouts2.setStartTime(c.getTime()); losspower = calLossPower(wtId, brownouts2.getStartTime(), brownouts2.getStopTime()); brownouts2.setLossPower(losspower); proEconBrownoutsEvent2ls.add(brownouts2); } else { ProEconBrownoutsEvent2 newto =intialBrownoutsEventnew2(mb, wtId, wtStatusMap, wtSpeedMap, wtPowerMap, DateUtils.truncate(c.getTime())); if (i == days - 1) { newto.setStartTime(startTime); } else { newto.setStartTime(c.getTime()); } losspower = calLossPower(wtId, newto.getStartTime(), newto.getStopTime()); newto.setLossPower(losspower); proEconBrownoutsEvent2ls.add(newto); } c.add(Calendar.DAY_OF_MONTH, 1); } } } private void finishBrownoutsEvent(List proEconBrownoutsEventls, String wtId, ProEconBrownoutsEvent item, Date currentTime) throws Exception { // if(currentStatus != 4 ) // { item.setStartTime(currentTime); double timehour = DateUtils.hoursDiff2(item.getStartTime(), item.getStopTime()); item.setStopHours(timehour); double losspower = calLossPower(wtId, item.getStartTime(), item.getStopTime()); item.setLossPower(losspower); proEconBrownoutsEventls.add(item); } private void intialMainBrownouts(List insertMainBrownoutsls, String wpId, Map wpStatusMap, Map wpSpeedMap, Map wpPowerMap, Date currentTime, ProEconMainBrownouts mainBrownouts) throws Exception { mainBrownouts.setId(StringUtils.getUUID()); mainBrownouts.setStopTime(currentTime); mainBrownouts.setStartTime(null); if (wpStatusMap.get(wpId).getPointValueInDouble() == StatusValue.XD.getCode()) { mainBrownouts.setStopTypeId(StatusValue.XD.getName()); } if (wpStatusMap.get(wpId).getPointValueInDouble() == StatusValue.XD.getCode()) { mainBrownouts.setStopTypeId(StatusValue.XD.getName()); } if (wpSpeedMap.containsKey(wpId)) { mainBrownouts.setWindSpeed(StringUtils.round(wpSpeedMap.get(wpId).getPointValueInDouble(), 2)); } if (wpPowerMap.containsKey(wpId)) { mainBrownouts.setLimitLoad(StringUtils.round(wpPowerMap.get(wpId).getPointValueInDouble(), 2)); } Map wppointmap = CacheContext.wppointmap.get(wpId); long pried = DateUtils.secondsDiff(DateUtils.addMinutes(currentTime, -5), currentTime); List hsls = edosUtil.getHistStat(wppointmap.get(ContantXk.SSZGL), DateUtils.addMinutes(currentTime, -5).getTime() / 1000, currentTime.getTime() / 1000, 1L, pried, StatData.MAX.getValue()); if (StringUtils.notEmp(hsls) && hsls.size() > 0) { mainBrownouts.setThisLoad(hsls.get(0).getPointValueInDouble()); } mainBrownouts.setWindpowerstationId(wpId); mainBrownouts.setLossPower(0.0); insertMainBrownoutsls.add(mainBrownouts); } private void intialMainBrownouts2(List insertMainBrownouts2ls, String wpId, Map wpStatusMap, Map wpSpeedMap, Map wpPowerMap, Date currentTime, ProEconMainBrownouts2 mainBrownouts) throws Exception { mainBrownouts.setId(StringUtils.getUUID()); mainBrownouts.setStopTime(currentTime); mainBrownouts.setStartTime(null); if (wpStatusMap.get(wpId).getPointValueInDouble() ==StatusValue.XD.getCode()) { mainBrownouts.setStopTypeId(StatusValue.XD.getName()); } if (wpStatusMap.get(wpId).getPointValueInDouble() == StatusValue.XD.getCode()) { mainBrownouts.setStopTypeId(StatusValue.XD.getName()); } if (wpSpeedMap.containsKey(wpId)) { mainBrownouts.setWindSpeed(StringUtils.round(wpSpeedMap.get(wpId).getPointValueInDouble(), 2)); } if (wpPowerMap.containsKey(wpId)) { mainBrownouts.setLimitLoad(StringUtils.round(wpPowerMap.get(wpId).getPointValueInDouble(), 2)); } Map wppointmap = CacheContext.wppointmap.get(wpId); long pried = DateUtils.secondsDiff(DateUtils.addMinutes(currentTime, -5), currentTime); List hsls = edosUtil.getHistStat(wppointmap.get(ContantXk.SSZGL), DateUtils.addMinutes(currentTime, -5).getTime() / 1000, currentTime.getTime() / 1000, 1L, pried, StatData.MAX.getValue()); if (StringUtils.notEmp(hsls) && hsls.size() > 0) { mainBrownouts.setThisLoad(hsls.get(0).getPointValueInDouble()); } mainBrownouts.setWindpowerstationId(wpId); mainBrownouts.setLossPower(0.0); insertMainBrownouts2ls.add(mainBrownouts); } private ProEconMainBrownouts2 intialMainBrownoutsnew2(String wpId, Map wpStatusMap, Map wpSpeedMap, Map wpPowerMap, Date currentTime) throws Exception { ProEconMainBrownouts2 mainBrownouts=new ProEconMainBrownouts2(); mainBrownouts.setId(StringUtils.getUUID()); mainBrownouts.setStopTime(currentTime); mainBrownouts.setStartTime(null); if (wpStatusMap.get(wpId).getPointValueInDouble() == StatusValue.XD.getCode()) { mainBrownouts.setStopTypeId(StatusValue.XD.getName()); } if (wpStatusMap.get(wpId).getPointValueInDouble() == StatusValue.XD.getCode()) { mainBrownouts.setStopTypeId(StatusValue.XD.getName()); } if (wpSpeedMap.containsKey(wpId)) { mainBrownouts.setWindSpeed(StringUtils.round(wpSpeedMap.get(wpId).getPointValueInDouble(), 2)); } if (wpPowerMap.containsKey(wpId)) { mainBrownouts.setLimitLoad(StringUtils.round(wpPowerMap.get(wpId).getPointValueInDouble(), 2)); } Map wppointmap = CacheContext.wppointmap.get(wpId); long pried = DateUtils.secondsDiff(DateUtils.addMinutes(currentTime, -5), currentTime); List hsls = edosUtil.getHistStat(wppointmap.get(ContantXk.SSZGL), DateUtils.addMinutes(currentTime, -5).getTime() / 1000, currentTime.getTime() / 1000, 1L, pried, StatData.MAX.getValue()); if (StringUtils.notEmp(hsls) && hsls.size() > 0) { mainBrownouts.setThisLoad(hsls.get(0).getPointValueInDouble()); } mainBrownouts.setWindpowerstationId(wpId); mainBrownouts.setLossPower(0.0); return mainBrownouts; } private void finishMainBrownouts2(List proEconMainBrownouts2ls, String wpId, Map wpStatusMap, Map wpSpeedMap, Map wpPowerMap, ProEconMainBrownouts2 mainBrownouts2, Date currentTime) throws Exception { mainBrownouts2.setStartTime(currentTime); double timehour = DateUtils.hoursDiff2(mainBrownouts2.getStartTime(), mainBrownouts2.getStopTime()); mainBrownouts2.setStopHours(timehour); double losspower = calWpLossPower(wpId, mainBrownouts2.getStartTime(), mainBrownouts2.getStopTime()); mainBrownouts2.setLossPower(losspower); if (timehour <= 24) { proEconMainBrownouts2ls.add(mainBrownouts2); } else { int days = DateUtils.daysDiff1(mainBrownouts2.getStartTime(), mainBrownouts2.getStopTime()); Calendar c = Calendar.getInstance(); Date startTime = mainBrownouts2.getStartTime(); c.setTime(mainBrownouts2.getStopTime()); c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); for (int i = 0; i < days; i++) { if (i == 0) { mainBrownouts2.setStartTime(c.getTime()); losspower = calWpLossPower(wpId, mainBrownouts2.getStartTime(), mainBrownouts2.getStopTime()); mainBrownouts2.setLossPower(losspower); proEconMainBrownouts2ls.add(mainBrownouts2); } else { ProEconMainBrownouts2 newpo = intialMainBrownoutsnew2(wpId, wpStatusMap, wpSpeedMap, wpPowerMap, DateUtils.truncate(c.getTime())); if (i == days - 1) { newpo.setStartTime(startTime); } else { newpo.setStartTime(c.getTime()); } losspower = calWpLossPower(wpId, newpo.getStartTime(), newpo.getStopTime()); newpo.setLossPower(losspower); proEconMainBrownouts2ls.add(newpo); } c.add(Calendar.DAY_OF_MONTH, 1); } } } private void finishMainBrownouts(List proEconMainBrownoutsls, String wpId, ProEconMainBrownouts item, Date currentTime) throws Exception { // if(currentStatus != 4 ) // { item.setStartTime(currentTime); double timehour = DateUtils.hoursDiff2(item.getStartTime(), item.getStopTime()); item.setStopHours(timehour); double losspower = calWpLossPower(wpId, item.getStartTime(), item.getStopTime()); item.setLossPower(losspower); proEconMainBrownoutsls.add(item); } //修改后的限电损失统计,通过时序数据库历史切面计算 private Double calWpLossPower(String wpId, Date startDate, Date endDate) throws Exception { double result = 0.0; Map> wppointmap = CacheContext.wppointmap; Map pointmap = wppointmap.get(wpId); Calendar c1 = Calendar.getInstance(); c1.setTime(startDate); Calendar c2 = Calendar.getInstance(); c2.setTime(endDate); //判定限电是否跨年 if (endDate.after(startDate) && c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR)) { //年限电欠发损失电量 if (pointmap.containsKey(ContantXk.NXDTJSSDL)) { double beginvalue; double endvalue; List pointid = new ArrayList<>(); pointid.add(pointmap.get(ContantXk.NXDTJSSDL).getNemCode()); List xdbegin = edosUtil.getHistMatrix(pointid, startDate.getTime() / 1000); List xdend = edosUtil.getHistMatrix(pointid, endDate.getTime() / 1000); if (xdbegin.size() == 1 && xdend.size() == 1) { beginvalue = xdbegin.get(0).getPointValueInDouble(); endvalue = xdend.get(0).getPointValueInDouble(); if (endvalue > beginvalue) { result = result + (endvalue - beginvalue); } } } //年限电损失电量 if (pointmap.containsKey(ContantXk.NXDJCLSSDL)) { double beginvalue; double endvalue; List pointid = new ArrayList<>(); pointid.add(pointmap.get(ContantXk.NXDJCLSSDL).getNemCode()); List xdbegin = edosUtil.getHistMatrix(pointid, startDate.getTime() / 1000); List xdend = edosUtil.getHistMatrix(pointid, endDate.getTime() / 1000); if (xdbegin.size() == 1 && xdend.size() == 1) { beginvalue = xdbegin.get(0).getPointValueInDouble(); endvalue = xdend.get(0).getPointValueInDouble(); if (endvalue > beginvalue) { result = result + (endvalue - beginvalue); } } } } else { Calendar c = Calendar.getInstance(); c.setTime(DateUtils.truncate(startDate)); c.add(Calendar.DAY_OF_MONTH, 1); //获得1月1日零点值 Date endtime = c.getTime(); //年限电欠发损失电量 if (pointmap.containsKey(ContantXk.NXDTJSSDL)) { double beginvalue; double endvalue; List pointid = new ArrayList<>(); pointid.add(pointmap.get(ContantXk.NXDTJSSDL).getNemCode()); List xdbegin = edosUtil.getHistMatrix(pointid, startDate.getTime() / 1000); List xdend = edosUtil.getHistMatrix(pointid, endtime.getTime() / 1000); if (xdbegin.size() == 1 && xdend.size() == 1) { beginvalue = xdbegin.get(0).getPointValueInDouble(); endvalue = xdend.get(0).getPointValueInDouble(); if (endvalue > beginvalue) { result = result + (endvalue - beginvalue); } } } //年限电损失电量 if (pointmap.containsKey(ContantXk.NXDJCLSSDL)) { double beginvalue; double endvalue; List pointid = new ArrayList<>(); pointid.add(pointmap.get(ContantXk.NXDJCLSSDL).getNemCode()); List xdbegin = edosUtil.getHistMatrix(pointid, startDate.getTime() / 1000); List xdend = edosUtil.getHistMatrix(pointid, endtime.getTime() / 1000); if (xdbegin.size() == 1 && xdend.size() == 1) { beginvalue = xdbegin.get(0).getPointValueInDouble(); endvalue = xdend.get(0).getPointValueInDouble(); if (endvalue > beginvalue) { result = result + (endvalue - beginvalue); } } } //日限电欠发损失电量 if (pointmap.containsKey(ContantXk.NXDTJSSDL)) { double endvalue; List pointid = new ArrayList<>(); pointid.add(pointmap.get(ContantXk.NXDTJSSDL).getNemCode()); List xdend = edosUtil.getHistMatrix(pointid, endDate.getTime() / 1000); if (xdend.size() == 1) { endvalue = xdend.get(0).getPointValueInDouble(); if (endvalue > 0) { result = result + endvalue; } } } //日限电损失电量 if (pointmap.containsKey(ContantXk.NXDJCLSSDL)) { double endvalue; List pointid = new ArrayList<>(); pointid.add(pointmap.get(ContantXk.NXDJCLSSDL).getNemCode()); List xdend = edosUtil.getHistMatrix(pointid, endDate.getTime() / 1000); if (xdend.size() == 1) { endvalue = xdend.get(0).getPointValueInDouble(); if (endvalue > 0) { result = result + endvalue; } } } } return result; } //修改后的限电损失统计,通过时序数据库历史切面计算 private Double calLossPower(String windturbineId, Date startDate, Date endDate) throws Exception { double result = 0.0; Map> wtpAimap = CacheContext.wtpAimap; Map wtpointmap = wtpAimap.get(windturbineId); Calendar c1 = Calendar.getInstance(); c1.setTime(startDate); Calendar c2 = Calendar.getInstance(); c2.setTime(endDate); //判定限电是否跨年 if (endDate.after(startDate) && c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR)) { //年限电欠发损失电量 if (wtpointmap.containsKey(ContantXk.NXDTJSSDL)) { double beginvalue; double endvalue; List pointid = new ArrayList<>(); pointid.add(wtpointmap.get(ContantXk.NXDTJSSDL).getNemCode()); List xdbegin = edosUtil.getHistMatrix(pointid, startDate.getTime() / 1000); List xdend = edosUtil.getHistMatrix(pointid, endDate.getTime() / 1000); if (xdbegin.size() == 1 && xdend.size() == 1) { beginvalue = xdbegin.get(0).getPointValueInDouble(); endvalue = xdend.get(0).getPointValueInDouble(); if (endvalue > beginvalue) { result = result + (endvalue - beginvalue); } } } //年限电损失电量 if (wtpointmap.containsKey(ContantXk.NXDJCLSSDL)) { double beginvalue; double endvalue; List pointid = new ArrayList<>(); pointid.add(wtpointmap.get(ContantXk.NXDJCLSSDL).getNemCode()); List xdbegin = edosUtil.getHistMatrix(pointid, startDate.getTime() / 1000); List xdend = edosUtil.getHistMatrix(pointid, endDate.getTime() / 1000); if (xdbegin.size() == 1 && xdend.size() == 1) { beginvalue = xdbegin.get(0).getPointValueInDouble(); endvalue = xdend.get(0).getPointValueInDouble(); if (endvalue > beginvalue) { result = result + (endvalue - beginvalue); } } } } else { Calendar c = Calendar.getInstance(); c.setTime(DateUtils.truncate(startDate)); c.add(Calendar.DAY_OF_MONTH, 1); //获得1月1日零点值 Date endtime = c.getTime(); //年限电欠发损失电量 if (wtpointmap.containsKey(ContantXk.NXDTJSSDL)) { double beginvalue; double endvalue; List pointid = new ArrayList<>(); pointid.add(wtpointmap.get(ContantXk.NXDTJSSDL).getNemCode()); List xdbegin = edosUtil.getHistMatrix(pointid, startDate.getTime() / 1000); List xdend = edosUtil.getHistMatrix(pointid, endtime.getTime() / 1000); if (xdbegin.size() == 1 && xdend.size() == 1) { beginvalue = xdbegin.get(0).getPointValueInDouble(); endvalue = xdend.get(0).getPointValueInDouble(); if (endvalue > beginvalue) { result = result + (endvalue - beginvalue); } } } //年限电损失电量 if (wtpointmap.containsKey(ContantXk.NXDJCLSSDL)) { double beginvalue; double endvalue; List pointid = new ArrayList<>(); pointid.add(wtpointmap.get(ContantXk.NXDJCLSSDL).getNemCode()); List xdbegin = edosUtil.getHistMatrix(pointid, startDate.getTime() / 1000); List xdend = edosUtil.getHistMatrix(pointid, endtime.getTime() / 1000); if (xdbegin.size() == 1 && xdend.size() == 1) { beginvalue = xdbegin.get(0).getPointValueInDouble(); endvalue = xdend.get(0).getPointValueInDouble(); if (endvalue > beginvalue) { result = result + (endvalue - beginvalue); } } } //日限电欠发损失电量 if (wtpointmap.containsKey(ContantXk.NXDTJSSDL)) { double endvalue; List pointid = new ArrayList<>(); pointid.add(wtpointmap.get(ContantXk.NXDTJSSDL).getNemCode()); List xdend = edosUtil.getHistMatrix(pointid, endDate.getTime() / 1000); if (xdend.size() == 1) { endvalue = xdend.get(0).getPointValueInDouble(); if (endvalue > 0) { result = result + endvalue; } } } //日限电损失电量 if (wtpointmap.containsKey(ContantXk.NXDJCLSSDL)) { double endvalue; List pointid = new ArrayList<>(); pointid.add(wtpointmap.get(ContantXk.NXDJCLSSDL).getNemCode()); List xdend = edosUtil.getHistMatrix(pointid, endDate.getTime() / 1000); if (xdend.size() == 1) { endvalue = xdend.get(0).getPointValueInDouble(); if (endvalue > 0) { result = result + endvalue; } } } } return result; } }