package com.gyee.generation.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.gyee.common.contant.Contant; import com.gyee.common.contant.ContantXk; import com.gyee.common.model.DNAStatVal; import com.gyee.common.model.DNAVal; import com.gyee.common.model.PointData; import com.gyee.generation.init.CacheContext; import com.gyee.generation.model.auto.*; 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.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @Service public class LimitEventService { @Resource private IProEconBrownoutsEventService proEconBrownoutsEventService; @Resource private IProEconMainBrownoutsService proEconMainBrownoutsService; @Resource private IProEconBrownoutsEvent2Service proEconBrownoutsEvent2Service; @Resource private IProEconMainBrownouts2Service proEconMainBrownouts2Service; @Resource private IEdosUtil edosUtil; //风机保证功率 private Map bzglDictionary; //<风场编号,风场状态点编号> public Map windPowerDictionary; //<风场编号,<风机编号,风机状态点编号>> public Map> windTurbineDictionary; //<风场编号/工程编号/线路编号,List<风机编号>> public Map> wplDictionary; //风场限电事件 public Map windpowerEvent; //风机限电事件 public Map windturbineEvent; //风场限电事件 当日 public Map windpowerEvent2; //风机限电事件 当日 public Map windturbineEvent2; //风机列表 public Map windturbines; //风机对应额定功率 public Map windturbinePowerProduction; //风机风速 public Map speedDictionary; //风机功率 public Map powerDictionary; //风场风速 public Map wSpeedDictionary; //风场功率 public Map wPowerDictionary; //风机拟合限电损失 public Map nhxdDictionary; //风机拟合功率 public Map nhDictionary; public void Init() { windPowerDictionary = new HashMap(); windTurbineDictionary = new HashMap>(); wplDictionary = new HashMap>(); windpowerEvent = new HashMap(); windturbineEvent = new HashMap(); windpowerEvent2 = new HashMap(); windturbineEvent2 = new HashMap(); speedDictionary = new HashMap(); powerDictionary = new HashMap(); wSpeedDictionary = new HashMap(); wPowerDictionary = new HashMap(); bzglDictionary = new HashMap(); windturbinePowerProduction = new HashMap(); nhDictionary = new HashMap(); nhxdDictionary = new HashMap(); Map tempWindPower = new HashMap<>(); Map tempWindPowerSpeed = new HashMap<>(); Map tempWindPowerPower = new HashMap<>(); Map> wppointmap = CacheContext.wppointmap; CacheContext.wpls.forEach(wp -> { Map wppmap = wppointmap.get(wp.getId()); if (wp.getId().contains("FDC")) { if (wppmap.containsKey(ContantXk.SBZT)) { ProBasicWppoint point = wppmap.get(ContantXk.SBZT); tempWindPower.put(wp.getId(), point); } if (wppmap.containsKey(ContantXk.SSPJFS)) { ProBasicWppoint point = wppmap.get(ContantXk.SSPJFS); tempWindPowerSpeed.put(wp.getId(), point); } if (wppmap.containsKey(ContantXk.SSZGL)) { ProBasicWppoint point = wppmap.get(ContantXk.SSZGL); tempWindPowerPower.put(wp.getId(), point); } } }); Map tempWindTurbine = new HashMap<>(); Map tempSpeed = new HashMap<>(); Map tempPower = new HashMap<>(); Map tempnh = new HashMap<>(); Map tempxd = new HashMap<>(); Map tempbzglDictionary = new HashMap<>(); List wtls = CacheContext.wtls; Map> wtpAimap = CacheContext.wtpAimap; wtls.stream().forEach(wt -> { if (wt.getWindpowerstationId().contains("FDC")) { //风机状态 Map windturbinetestingpointnewMap = wtpAimap.get(wt.getId()); if (windturbinetestingpointnewMap.containsKey(ContantXk.SBZT)) { ProBasicEquipmentPoint point = windturbinetestingpointnewMap.get(ContantXk.SBZT); tempWindTurbine.put(wt.getId(), point); } //风速 if (windturbinetestingpointnewMap.containsKey(ContantXk.CJ_SSFS)) { ProBasicEquipmentPoint point = windturbinetestingpointnewMap.get(ContantXk.CJ_SSFS); tempSpeed.put(wt.getId(), point); } //功率 if (windturbinetestingpointnewMap.containsKey(ContantXk.CJ_SSGL)) { ProBasicEquipmentPoint point = windturbinetestingpointnewMap.get(ContantXk.CJ_SSGL); tempPower.put(wt.getId(), point); } if (windturbinetestingpointnewMap.containsKey(ContantXk.ZSGL)) { ProBasicEquipmentPoint point = windturbinetestingpointnewMap.get(ContantXk.ZSGL); tempnh.put(wt.getId(), point); } if (windturbinetestingpointnewMap.containsKey(ContantXk.NXDTJSSDL)) { ProBasicEquipmentPoint point = windturbinetestingpointnewMap.get(ContantXk.NXDTJSSDL); tempxd.put(wt.getId(), point); } if (windturbinetestingpointnewMap.containsKey(ContantXk.BZGL)) { ProBasicEquipmentPoint point = windturbinetestingpointnewMap.get(ContantXk.BZGL); tempbzglDictionary.put(wt.getId(), point); } } }); for (String key : tempWindPowerSpeed.keySet()) { wSpeedDictionary.put(key, tempWindPowerSpeed.get(key).getNemCode()); if (tempWindPowerPower.containsKey(key)) { wPowerDictionary.put(key, tempWindPowerPower.get(key).getNemCode()); } } for (String key : tempSpeed.keySet()) { speedDictionary.put(key, tempSpeed.get(key).getNemCode()); if (tempPower.containsKey(key)) { powerDictionary.put(key, tempPower.get(key).getNemCode()); } if (tempbzglDictionary.containsKey(key)) { bzglDictionary.put(key, tempbzglDictionary.get(key).getNemCode()); } if (tempnh.containsKey(key)) { nhDictionary.put(key, tempnh.get(key).getNemCode()); } if (tempxd.containsKey(key)) { nhxdDictionary.put(key, tempxd.get(key).getNemCode()); } } windturbines = CacheContext.wtmap; Map modelMap = CacheContext.modelMap; for (String key : tempWindPower.keySet()) { windPowerDictionary.put(key, tempWindPower.get(key).getNemCode()); List tempMain = proEconMainBrownoutsService.list().stream().filter(i -> StringUtils.empty(i.getStartTime()) && i.getWindpowerstationId().equals(key)) .sorted(Comparator.comparing(ProEconMainBrownouts::getStopTime)).collect(Collectors.toList()); if (tempMain != null && tempMain.size() > 0) { for (int i = 1; i < tempMain.size(); i++) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("id", tempMain.get(i).getId()); String mainId = tempMain.get(i).getId(); proEconMainBrownoutsService.remove(wrapper); List tempSub = proEconBrownoutsEventService.list().stream().filter(x -> StringUtils.empty(x.getMainId().equals(mainId))) .map(ProEconBrownoutsEvent::getId).collect(Collectors.toList()); deleteSub(tempSub); } windpowerEvent.put(key, tempMain.get(0)); String mainid = tempMain.get(0).getId(); List tempSub1 = proEconBrownoutsEventService.list().stream().filter(x -> StringUtils.empty(x.getMainId().equals(mainid)) && StringUtils.empty(x.getStartTime())) .sorted(Comparator.comparing(ProEconBrownoutsEvent::getStopTime)).collect(Collectors.toList()); for (ProEconBrownoutsEvent item : tempSub1) { if (!windturbineEvent.containsKey(item.getWindturbineId())) windturbineEvent.put(item.getWindturbineId(), item); } } else { List tempSub = proEconBrownoutsEventService.list().stream().filter(x -> StringUtils.empty(x.getWindpowerstationId().equals(key)) && StringUtils.empty(x.getStartTime())) .map(ProEconBrownoutsEvent::getId).collect(Collectors.toList()); deleteSub(tempSub); windpowerEvent.put(key, null); } List tempMain2 = proEconMainBrownouts2Service.list().stream().filter(i -> StringUtils.empty(i.getStartTime()) && i.getWindpowerstationId().equals(key)) .sorted(Comparator.comparing(ProEconMainBrownouts2::getStopTime)).collect(Collectors.toList()); if (tempMain2 != null && tempMain2.size() > 0) { for (int i = 1; i < tempMain2.size(); i++) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("id", tempMain2.get(i).getId()); String mainId = tempMain2.get(i).getId(); proEconMainBrownouts2Service.remove(wrapper); List tempSub2 = proEconBrownoutsEvent2Service.list().stream().filter(x -> StringUtils.empty(x.getMainId().equals(mainId))) .map(ProEconBrownoutsEvent2::getId).collect(Collectors.toList()); deleteSub2(tempSub2); } windpowerEvent2.put(key, tempMain2.get(0)); String mainid = tempMain2.get(0).getId(); List tempSub1 = proEconBrownoutsEvent2Service.list().stream().filter(x -> StringUtils.empty(x.getMainId().equals(mainid)) && StringUtils.empty(x.getStartTime())) .sorted(Comparator.comparing(ProEconBrownoutsEvent2::getStopTime)).collect(Collectors.toList()); for (ProEconBrownoutsEvent2 item : tempSub1) { if (!windturbineEvent2.containsKey(item.getWindturbineId())) windturbineEvent2.put(item.getWindturbineId(), item); } } else { List tempSub2 = proEconBrownoutsEvent2Service.list().stream().filter(x -> StringUtils.empty(x.getWindpowerstationId().equals(key)) && StringUtils.empty(x.getStartTime())) .map(ProEconBrownoutsEvent2::getId).collect(Collectors.toList()); deleteSub(tempSub2); windpowerEvent2.put(key, null); } } for (ProBasicWindturbine item : windturbines.values()) { if (modelMap.containsKey(item.getModelId())) windturbinePowerProduction.put(item.getId(), modelMap.get(item.getModelId()).getPowerProduction()); else windturbinePowerProduction.put(item.getId(), 2100.0); newMethod(item.getWindpowerstationId(), item.getId()); newMethod(item.getProjectId(), item.getId()); newMethod(item.getLineId(), item.getId()); if (tempWindTurbine.containsKey(item.getId())) { if (!windTurbineDictionary.containsKey(item.getWindpowerstationId())) { windTurbineDictionary.put(item.getWindpowerstationId(), new HashMap()); } windTurbineDictionary.get(item.getWindpowerstationId()).put(item.getId(), tempWindTurbine.get(item.getId()).getId()); } if (!windturbineEvent.containsKey(item.getId())) { windpowerEvent.put(item.getId(), null); } } } private void deleteSub(List tempSub) { if (tempSub != null && tempSub.size() > 0) { proEconBrownoutsEventService.removeByIds(tempSub); } } private void deleteSub(ProEconBrownoutsEvent tempSub) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("id", tempSub.getId()); proEconBrownoutsEventService.remove(wrapper); } private void deleteSub2(List tempSub) { proEconBrownoutsEvent2Service.removeByIds(tempSub); } private void deleteSub2(ProEconBrownoutsEvent2 tempSub) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("id", tempSub.getId()); proEconBrownoutsEvent2Service.remove(wrapper); } private void newMethod(String key, String windtubineId) { if (!wplDictionary.containsKey(key)) { wplDictionary.put(key, new ArrayList()); } wplDictionary.get(key).add(windtubineId); } public void Exec() throws Exception { //风场限电事件 windpowerEvent.clear(); //风机限电事件 windturbineEvent.clear(); Date dt = new Date(); List tempMain = proEconMainBrownoutsService.list().stream().filter(i -> StringUtils.empty(i.getStartTime())) .sorted(Comparator.comparing(ProEconMainBrownouts::getStopTime)).collect(Collectors.toList()); for (ProEconMainBrownouts item : tempMain) { if (!windpowerEvent.containsKey(item.getWindpowerstationId())) { windpowerEvent.put(item.getWindpowerstationId(), item); } else { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("id", item.getId()); proEconMainBrownoutsService.remove(wrapper); } } List tempSub = proEconBrownoutsEventService.list().stream().filter(x -> StringUtils.empty(x.getStartTime())) .sorted(Comparator.comparing(ProEconBrownoutsEvent::getStopTime)).collect(Collectors.toList()); for (ProEconBrownoutsEvent item : tempSub) { if (!windturbineEvent.containsKey(item.getWindturbineId())) { windturbineEvent.put(item.getWindturbineId(), item); } else { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("id", item.getId()); proEconBrownoutsEventService.remove(wrapper); } } for (String key : windPowerDictionary.keySet()) { if (!windpowerEvent.containsKey(key)) { windpowerEvent.put(key, null); } if (windTurbineDictionary.containsKey(key)) { for (String wkey : windTurbineDictionary.get(key).keySet()) { if (!windturbineEvent.containsKey(wkey)) { windturbineEvent.put(wkey, null); } } } } for (String key : windPowerDictionary.keySet()) { double wpstate = edosUtil.getRealData(windPowerDictionary.get(key)).getPointValueInDouble(); if (wpstate == 5 || wpstate == 6) { //限电起始 if (windpowerEvent.get(key) == null) { //新增风机限电事件 ProEconMainBrownouts main = addMainBrownouts(dt, key); if (windTurbineDictionary.containsKey(key)) { Map windDic = windTurbineDictionary.get(key); for (String wkey : windDic.keySet()) { //新增风机限电事件 double windstate = edosUtil.getRealData(windDic.get(wkey)).getPointValueInDouble(); if (windstate == 5 || windstate == 6) { if (windturbineEvent.get(wkey) == null) { addBrownoutsEvent(dt, key, main, wkey, windstate); } } } } } //限电进行时 else { ProEconMainBrownouts main = windpowerEvent.get(key); if (windTurbineDictionary.containsKey(key)) { Map windDic = windTurbineDictionary.get(key); for (String wkey : windDic.keySet()) { double windstate = edosUtil.getRealData(windDic.get(wkey)).getPointValueInDouble(); if (windstate == 5 || windstate == 6) { if (windturbineEvent.get(wkey) == null) { //新增风机限电事件 addBrownoutsEvent(dt, key, main, wkey, windstate); } else { // 风机限电进行时 if (windturbineEvent.get(wkey).getMainId().equals(main.getId())) { double temp = main.getLossPower(); double tempvulue = buildBrownoutsEvent(new Date(0), key, wkey, dt); main.setLossPower(StringUtils.round(temp + tempvulue, 2)); } else { deleteSub(windturbineEvent.get(wkey)); } } } else { if (windturbineEvent.get(wkey) != null) { //风机限电结束时 if (windturbineEvent.get(wkey).getMainId().equals(main.getId())) { double temp = main.getLossPower(); double tempvulue = buildBrownoutsEvent(dt, key, wkey, dt); main.setLossPower(StringUtils.round(temp + tempvulue, 2)); windturbineEvent.put(wkey, null); } else { deleteSub(windturbineEvent.get(wkey)); } } } } } updateMainDateBase(new Date(0), main, dt);//需要修改 } } //限电结束时 else { if (windpowerEvent.get(key) != null) { ProEconMainBrownouts main = windpowerEvent.get(key); if (windTurbineDictionary.containsKey(key)) { Map windDic = windTurbineDictionary.get(key); for (String wkey : windDic.keySet()) { if (windturbineEvent.get(wkey) != null) { //风机限电结束时 if (windturbineEvent.get(wkey).getMainId().equals(main.getId())) { double temp = main.getLossPower(); double tempvulue = buildBrownoutsEvent(dt, key, wkey, dt); main.setLossPower(StringUtils.round(temp + tempvulue, 2)); windturbineEvent.put(wkey, null); } else { deleteSub(windturbineEvent.get(wkey)); } } } } updateMainDateBase(dt, main, dt);//需要修改 main.setStartTime(dt); } } } } //限电事件当天 public void Exec2() throws Exception { //风场限电事件 windpowerEvent2.clear(); //风机限电事件 windturbineEvent2.clear(); Date dt = new Date(); List tempMain = proEconMainBrownouts2Service.list().stream().filter(i -> StringUtils.empty(i.getStartTime())) .sorted(Comparator.comparing(ProEconMainBrownouts2::getStopTime)).collect(Collectors.toList()); for (ProEconMainBrownouts2 item : tempMain) { if (!windpowerEvent2.containsKey(item.getWindpowerstationId())) { windpowerEvent2.put(item.getWindpowerstationId(), item); } else { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("id", item.getId()); proEconMainBrownouts2Service.remove(wrapper); } } List tempSub = proEconBrownoutsEvent2Service.list().stream().filter(x -> StringUtils.empty(x.getStartTime())) .sorted(Comparator.comparing(ProEconBrownoutsEvent2::getStopTime)).collect(Collectors.toList()); for (ProEconBrownoutsEvent2 item : tempSub) { if (!windturbineEvent2.containsKey(item.getWindturbineId())) { windturbineEvent2.put(item.getWindturbineId(), item); } else { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("id", item.getId()); proEconBrownoutsEvent2Service.remove(wrapper); } } for (String key : windPowerDictionary.keySet()) { if (!windpowerEvent2.containsKey(key)) { windpowerEvent2.put(key, null); } if (windTurbineDictionary.containsKey(key)) { for (String wkey : windTurbineDictionary.get(key).keySet()) { if (!windturbineEvent2.containsKey(wkey)) { windturbineEvent2.put(wkey, null); } } } } for (String key : windPowerDictionary.keySet()) { double wpstate = edosUtil.getRealData(windPowerDictionary.get(key)).getPointValueInDouble(); if (wpstate == 5 || wpstate == 6) { //限电起始 if (windpowerEvent2.get(key) == null) { //新增风机限电事件 ProEconMainBrownouts2 main = addMainBrownouts2(dt, key); if (windTurbineDictionary.containsKey(key)) { Map windDic = windTurbineDictionary.get(key); for (String wkey : windDic.keySet()) { //新增风机限电事件 double windstate = edosUtil.getRealData(windDic.get(wkey)).getPointValueInDouble(); if (windstate == 5 || windstate == 6) { if (windturbineEvent2.get(wkey) == null) { addBrownoutsEvent2(dt, key, main, wkey, windstate); } } } } } //限电进行时 else { ProEconMainBrownouts2 main = windpowerEvent2.get(key); if (DateUtils.getDay(dt) != DateUtils.getDay(main.getStopTime())) { dt = DateUtils.truncate(dt); //region 跨天 //egion 前一天 if (windTurbineDictionary.containsKey(key)) { Map windDic = windTurbineDictionary.get(key); for (String wkey : windDic.keySet()) { if (windturbineEvent2.get(wkey) != null) { //风机限电结束时 if (windturbineEvent2.get(wkey).getMainId().equals(main.getId())) { double temp = main.getLossPower(); double tempvulue = buildBrownoutsEvent2(new Date(0), key, wkey, dt); main.setLossPower(StringUtils.round(temp + tempvulue, 2)); windturbineEvent2.put(wkey, null); } else { deleteSub2(windturbineEvent2.get(wkey)); } } } } updateMainDateBase2(dt, main, dt);//需要修改 main.setStartTime(dt); // windpowerEvent2.put(key, null); //后一天 ProEconMainBrownouts2 mainnow = addMainBrownouts2(dt, key); if (windTurbineDictionary.containsKey(key)) { Map windDic = windTurbineDictionary.get(key); for (String wkey : windDic.keySet()) { //新增风机限电事件 double windstate = edosUtil.getRealData(windDic.get(wkey)).getPointValueInDouble(); if (windstate == 5 || windstate == 6) { if (windturbineEvent2.get(wkey) == null) { addBrownoutsEvent2(dt, key, mainnow, wkey, windstate); } } } } } else { //当天 if (windTurbineDictionary.containsKey(key)) { Map windDic = windTurbineDictionary.get(key); for (String wkey : windDic.keySet()) { double windstate = edosUtil.getRealData((windDic.get(wkey))).getPointValueInDouble(); if (windstate == 5 || windstate == 6) { if (windturbineEvent2.get(wkey) == null) { //新增风机限电事件 addBrownoutsEvent2(dt, key, main, wkey, windstate); } else { if (windturbineEvent2.get(wkey).getMainId().equals(main.getId())) { double temp = main.getLossPower(); double tempvulue = buildBrownoutsEvent2(new Date(0), key, wkey, dt); main.setLossPower(StringUtils.round(temp + tempvulue, 2)); windturbineEvent2.put(wkey, null); } else { deleteSub2(windturbineEvent2.get(wkey)); } } } else { if (windturbineEvent2.get(wkey) != null) { //风机限电结束时 if (windturbineEvent2.get(wkey).getMainId().equals(main.getId())) { double temp = main.getLossPower(); double tempvulue = buildBrownoutsEvent2(dt, key, wkey, dt); main.setLossPower(StringUtils.round(temp + tempvulue, 2)); windturbineEvent2.put(wkey, null); } else { deleteSub2(windturbineEvent2.get(wkey)); } } } } } updateMainDateBase2(new Date(0), main, dt);//需要修改 } } } //限电结束时 else { if (windpowerEvent2.get(key) != null) { ProEconMainBrownouts2 main = windpowerEvent2.get(key); if (windTurbineDictionary.containsKey(key)) { Map windDic = windTurbineDictionary.get(key); for (String wkey : windDic.keySet()) { if (windturbineEvent2.get(wkey) != null) { //风机限电结束时 if (windturbineEvent2.get(wkey).getMainId().equals(main.getId())) { double temp = main.getLossPower(); double tempvulue = buildBrownoutsEvent2(dt, key, wkey, dt); main.setLossPower(StringUtils.round(temp + tempvulue, 2)); windturbineEvent2.put(wkey, null); } else { deleteSub2(windturbineEvent2.get(wkey)); } } } } updateMainDateBase2(dt, main, dt);//需要修改 main.setStartTime(dt); } } } } private Double buildBrownoutsEvent(Date dt, String key, String wkey, Date nowdt) throws Exception { ProEconBrownoutsEvent sub = windturbineEvent.get(wkey); if (!(dt.compareTo(new Date(0)) == 0)) { sub.setStartTime(dt); } DNAStatVal[] hsls = edosUtil.getHistStat(powerDictionary.get(wkey), sub.getStopTime().getTime() / 1000, dt.getTime() / 1000, 1); if (StringUtils.notEmp(hsls) && hsls.length > 0) { sub.setLimitLoad(hsls[0].avg.DValue); } sub.setStopHours(DateUtils.hoursDiff1(nowdt, sub.getStopTime())); double losspower = calcLossPower(wkey, sub.getStopTime(), nowdt, (double) sub.getStopHours(), windturbinePowerProduction.get(wkey));//需要修改 sub.setLossPower(losspower); if (nhxdDictionary.containsKey(wkey)) { hsls = edosUtil.getHistStat(nhxdDictionary.get(wkey), sub.getStopTime().getTime() / 1000, nowdt.getTime() / 1000, 1); if (StringUtils.notEmp(hsls) && hsls.length >0) { double max = hsls[0].max.DValue; double min = hsls[0].min.DValue; sub.setLossPower(StringUtils.round(max - min, 2)); } } return sub.getLossPower(); } private Double buildBrownoutsEvent2(Date dt, String key, String wkey, Date nowdt) throws Exception { ProEconBrownoutsEvent2 sub = windturbineEvent2.get(wkey); if (!(dt.compareTo(new Date(0)) == 0)) { sub.setStartTime(dt); } DNAStatVal[] hsls = edosUtil.getHistStat(powerDictionary.get(wkey), sub.getStopTime().getTime() / 1000, dt.getTime() / 1000, 1); if (StringUtils.notEmp(hsls) && hsls.length > 0) { sub.setLimitLoad(hsls[0].avg.DValue); } sub.setStopHours(DateUtils.hoursDiff1(nowdt, sub.getStopTime())); double losspower = calcLossPower(wkey, sub.getStopTime(), nowdt, (double) sub.getStopHours(), windturbinePowerProduction.get(wkey));//需要修改 sub.setLossPower(losspower); if (nhxdDictionary.containsKey(wkey)) { hsls = edosUtil.getHistStat(nhxdDictionary.get(wkey), sub.getStopTime().getTime() / 1000, nowdt.getTime() / 1000, 1); if (StringUtils.notEmp(hsls) && hsls.length >0) { double max = hsls[0].max.DValue; double min = hsls[0].min.DValue; sub.setLossPower(StringUtils.round(max - min, 2)); } } return sub.getLossPower(); } private void addBrownoutsEvent(Date dt, String key, ProEconMainBrownouts main, String wkey, double windstate) throws Exception { ProEconBrownoutsEvent sub = new ProEconBrownoutsEvent(); sub.setWindpowerstationId(key); sub.setWindturbineId(wkey); sub.setProjectId(windturbines.get(wkey).getProjectId()); sub.setLineId(windturbines.get(wkey).getLineId()); sub.setStopTime(dt); sub.setStartTime(null); sub.setStopHours(0.0); sub.setLossPower(0.0); if (windstate == 5) { sub.setStopTypeId("非停机限电"); } else { sub.setStopTypeId("停机限电"); } sub.setMainId(main.getId()); sub.setLimitLoad(edosUtil.getRealData(powerDictionary.get(wkey)).getPointValueInDouble()); sub.setWindSpeed(edosUtil.getRealData(speedDictionary.get(wkey)).getPointValueInDouble()); DNAStatVal[] hsls = edosUtil.getHistStat(powerDictionary.get(wkey), DateUtils.addMinutes(dt, -5).getTime() / 1000, dt.getTime() / 1000, 1); if (StringUtils.notEmp(hsls) && hsls.length > 0 && hsls.length >0) { sub.setThisLoad(hsls[0].max.DValue); } windturbineEvent.put(wkey, sub); proEconBrownoutsEventService.save(sub); } private void addBrownoutsEvent2(Date dt, String key, ProEconMainBrownouts2 main, String wkey, double windstate) throws Exception { ProEconBrownoutsEvent2 sub = new ProEconBrownoutsEvent2(); sub.setWindpowerstationId(key); sub.setWindturbineId(wkey); sub.setProjectId(windturbines.get(wkey).getProjectId()); sub.setLineId(windturbines.get(wkey).getLineId()); sub.setStopTime(dt); sub.setStartTime(null); sub.setStopHours(0.0); sub.setLossPower(0.0); if (windstate == 5) { sub.setStopTypeId("非停机限电"); } else { sub.setStopTypeId("停机限电"); } sub.setMainId(main.getId()); sub.setLimitLoad(edosUtil.getRealData(powerDictionary.get(wkey)).getPointValueInDouble()); sub.setWindSpeed(edosUtil.getRealData(speedDictionary.get(wkey)).getPointValueInDouble()); DNAStatVal[] hsls = edosUtil.getHistStat(powerDictionary.get(wkey), DateUtils.addMinutes(dt, -5).getTime() / 1000, dt.getTime() / 1000, 1); if (StringUtils.notEmp(hsls) && hsls.length > 0 && hsls.length >0) { sub.setThisLoad(hsls[0].max.DValue); } windturbineEvent2.put(wkey, sub); proEconBrownoutsEvent2Service.save(sub); } //修改后的限电损失统计,通过时序数据库历史切面计算 private Double calcLossPower(String windturbineId, Date startDate, Date endDate, double hours, Double maxPower) 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=0.0; double endvalue=0.0; 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=0.0; double endvalue=0.0; 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.truncDay(startDate)); c.add(Calendar.DAY_OF_MONTH,1); //获得1月1日零点值 Date endtime=c.getTime(); //年限电欠发损失电量 if(wtpointmap.containsKey(ContantXk.NXDTJSSDL) ) { double beginvalue=0.0; double endvalue=0.0; 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=0.0; double endvalue=0.0; 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); } } } //日限电欠发损失电量 if(wtpointmap.containsKey(ContantXk.NXDTJSSDL) ) { double endvalue=0.0; 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 beginvalue=0.0; double endvalue=0.0; 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; } //读取历史数据 public List getHisData(String szPoint, Date startTime, Date endTime) throws Exception { List result = edosUtil.getHistoryDatasSnap(szPoint, startTime.getTime() / 1000, endTime.getTime() / 1000); if (result.size() == 0) { //logger.ErrorFormat(" getHisData(String szPoint={0}, Date startTime={1}, Date endTime={2})", szPoint, startTime, endTime); PointData pa = new PointData(); pa.setPointValueInDouble(0.0); result.add(pa); } return result; } // //电量分析主要针对省公司和各风场的每月实际发电量与计划的对比分析,可以查看省公司及各风场每月计划的完成情况和总体的计划完成情况,可以同比和环比进行比较; // //对省公司和各风场的实际发电量与理论发电量的对比分析,利用标准功率曲线中的风速,理论功率,和固定时间段的风频进行统计,设计统计分析公式为: // //理论发电量=(T*f1/f)*P1+(T*f2/f)*P2+…………(T*fn/f)*Pn // //T是选取的时间段; // //f是所有风频的和; // //f1、f2、fn是某风速对应的风频; // //P1、Pn是某风速对应理论曲线上的功率。 // //必要性:如果理论电量能够实现计算的准确,调峰电量就可以用理论电量来减去实际电量得出。 // //b、可选一段时间内的实际功率和理论功率能够形成曲线形式展示对比,理论功率根据实际风速利用理论功率曲线得出。 // //c、风频数据取值时间段需要统一。 // private Double updateTheoryGeneration(List powerDataList, double hours, Double maxPower) { // //maxPower = maxPower * 1.2m; // Double result = 0.0; // Double T = (Double) hours; // Double f = Double.valueOf(powerDataList.size()); // // if (f != 0) { // for (int i = 0; i < f; i++) { // Double P = powerDataList.get(i).getPointValueInDouble(); // if (P >= 0 && P <= maxPower) // result += (T * 1 / f) * P; // } // } // return result; // } //需要修改 private void updateMainDateBase(Date dt, ProEconMainBrownouts main, Date nowdt) { if (!(dt.compareTo(new Date(0)) == 0)) { main.setStartTime(dt); } //main.LOSSPOWER=entities.ProEconBrownoutsEvent.Where(it => it.MAINID == main.ID).Sum(it => it.LOSSPOWER); main.setStopHours(DateUtils.hoursDiff1(nowdt, main.getStopTime())); } private void updateMainDateBase2(Date dt, ProEconMainBrownouts2 main, Date nowdt) { if (!(dt.compareTo(new Date(0)) == 0)) { main.setStartTime(dt); } //main.LOSSPOWER = entities.ProEconBrownoutsEvent2.Where(it => it.MAINID == main.ID).Sum(it => it.LOSSPOWER).Value; main.setStopHours(DateUtils.hoursDiff1(nowdt, main.getStopTime())); } private ProEconMainBrownouts addMainBrownouts(Date dt, String key) throws Exception { ProEconMainBrownouts main = new ProEconMainBrownouts(); main.setStopTime(dt); main.setStartTime(null); main.setStopTypeId("非停机限电"); main.setLimitLoad(edosUtil.getRealData(wPowerDictionary.get(key)).getPointValueInDouble()); main.setWindSpeed(edosUtil.getRealData(wSpeedDictionary.get(key)).getPointValueInDouble()); DNAStatVal[] hsls = edosUtil.getHistStat(wPowerDictionary.get(key), DateUtils.addMinutes(dt, -5).getTime() / 1000, dt.getTime() / 1000, 1); if (StringUtils.notEmp(hsls) && hsls.length > 0 && hsls.length >0) { main.setThisLoad(hsls[0].max.DValue); } main.setWindpowerstationId(key); main.setLossPower(0.0); main.setWindpowerstationId(key); windpowerEvent.put(key, main); proEconMainBrownoutsService.save(main); return main; } private ProEconMainBrownouts2 addMainBrownouts2(Date dt, String key) throws Exception { ProEconMainBrownouts2 main = new ProEconMainBrownouts2(); main.setStopTime(dt); main.setStartTime(null); main.setStopTypeId("非停机限电"); main.setLimitLoad(edosUtil.getRealData(wPowerDictionary.get(key)).getPointValueInDouble()); main.setWindSpeed(edosUtil.getRealData(wSpeedDictionary.get(key)).getPointValueInDouble()); DNAStatVal[] hsls = edosUtil.getHistStat(wPowerDictionary.get(key), DateUtils.addMinutes(dt, -5).getTime() / 1000, dt.getTime() / 1000, 1); if (StringUtils.notEmp(hsls) && hsls.length > 0 && hsls.length >0) { main.setThisLoad(hsls[0].max.DValue); } main.setWindpowerstationId(key); main.setLossPower(0.0); main.setWindpowerstationId(key); windpowerEvent2.put(key, main); proEconMainBrownouts2Service.save(main); return main; } }