123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182 |
- 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<String, String> bzglDictionary;
- //<风场编号,风场状态点编号>
- public Map<String, String> windPowerDictionary;
- //<风场编号,<风机编号,风机状态点编号>>
- public Map<String, Map<String, String>> windTurbineDictionary;
- //<风场编号/工程编号/线路编号,List<风机编号>>
- public Map<String, List<String>> wplDictionary;
- //风场限电事件
- public Map<String, ProEconMainBrownouts> windpowerEvent;
- //风机限电事件
- public Map<String, ProEconBrownoutsEvent> windturbineEvent;
- //风场限电事件 当日
- public Map<String, ProEconMainBrownouts2> windpowerEvent2;
- //风机限电事件 当日
- public Map<String, ProEconBrownoutsEvent2> windturbineEvent2;
- //风机列表
- public Map<String, ProBasicWindturbine> windturbines;
- //风机对应额定功率
- public Map<String, Double> windturbinePowerProduction;
- //风机风速
- public Map<String, String> speedDictionary;
- //风机功率
- public Map<String, String> powerDictionary;
- //风场风速
- public Map<String, String> wSpeedDictionary;
- //风场功率
- public Map<String, String> wPowerDictionary;
- //风机拟合限电损失
- public Map<String, String> nhxdDictionary;
- //风机拟合功率
- public Map<String, String> nhDictionary;
- public void Init() {
- windPowerDictionary = new HashMap<String, String>();
- windTurbineDictionary = new HashMap<String, Map<String, String>>();
- wplDictionary = new HashMap<String, List<String>>();
- windpowerEvent = new HashMap<String, ProEconMainBrownouts>();
- windturbineEvent = new HashMap<String, ProEconBrownoutsEvent>();
- windpowerEvent2 = new HashMap<String, ProEconMainBrownouts2>();
- windturbineEvent2 = new HashMap<String, ProEconBrownoutsEvent2>();
- speedDictionary = new HashMap<String, String>();
- powerDictionary = new HashMap<String, String>();
- wSpeedDictionary = new HashMap<String, String>();
- wPowerDictionary = new HashMap<String, String>();
- bzglDictionary = new HashMap<String, String>();
- windturbinePowerProduction = new HashMap<String, Double>();
- nhDictionary = new HashMap<String, String>();
- nhxdDictionary = new HashMap<String, String>();
- Map<String, ProBasicWppoint> tempWindPower = new HashMap<>();
- Map<String, ProBasicWppoint> tempWindPowerSpeed = new HashMap<>();
- Map<String, ProBasicWppoint> tempWindPowerPower = new HashMap<>();
- Map<String, Map<String, ProBasicWppoint>> wppointmap = CacheContext.wppointmap;
- CacheContext.wpls.forEach(wp -> {
- Map<String, ProBasicWppoint> 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<String, ProBasicEquipmentPoint> tempWindTurbine = new HashMap<>();
- Map<String, ProBasicEquipmentPoint> tempSpeed = new HashMap<>();
- Map<String, ProBasicEquipmentPoint> tempPower = new HashMap<>();
- Map<String, ProBasicEquipmentPoint> tempnh = new HashMap<>();
- Map<String, ProBasicEquipmentPoint> tempxd = new HashMap<>();
- Map<String, ProBasicEquipmentPoint> tempbzglDictionary = new HashMap<>();
- List<ProBasicWindturbine> wtls = CacheContext.wtls;
- Map<String, Map<String, ProBasicEquipmentPoint>> wtpAimap = CacheContext.wtpAimap;
- wtls.stream().forEach(wt -> {
- if (wt.getWindpowerstationId().contains("FDC")) {
- //风机状态
- Map<String, ProBasicEquipmentPoint> 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<String, ProEconEquipmentmodel> modelMap = CacheContext.modelMap;
- for (String key : tempWindPower.keySet()) {
- windPowerDictionary.put(key, tempWindPower.get(key).getNemCode());
- List<ProEconMainBrownouts> 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<ProEconMainBrownouts> wrapper = new QueryWrapper<>();
- wrapper.eq("id", tempMain.get(i).getId());
- String mainId = tempMain.get(i).getId();
- proEconMainBrownoutsService.remove(wrapper);
- List<String> 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<ProEconBrownoutsEvent> 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<String> 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<ProEconMainBrownouts2> 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<ProEconMainBrownouts2> wrapper = new QueryWrapper<>();
- wrapper.eq("id", tempMain2.get(i).getId());
- String mainId = tempMain2.get(i).getId();
- proEconMainBrownouts2Service.remove(wrapper);
- List<String> 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<ProEconBrownoutsEvent2> 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<String> 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<String, String>());
- }
- 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<String> tempSub) {
- if (tempSub != null && tempSub.size() > 0) {
- proEconBrownoutsEventService.removeByIds(tempSub);
- }
- }
- private void deleteSub(ProEconBrownoutsEvent tempSub) {
- QueryWrapper<ProEconBrownoutsEvent> wrapper = new QueryWrapper<>();
- wrapper.eq("id", tempSub.getId());
- proEconBrownoutsEventService.remove(wrapper);
- }
- private void deleteSub2(List<String> tempSub) {
- proEconBrownoutsEvent2Service.removeByIds(tempSub);
- }
- private void deleteSub2(ProEconBrownoutsEvent2 tempSub) {
- QueryWrapper<ProEconBrownoutsEvent2> 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<String>());
- }
- wplDictionary.get(key).add(windtubineId);
- }
- public void Exec() throws Exception {
- //风场限电事件
- windpowerEvent.clear();
- //风机限电事件
- windturbineEvent.clear();
- Date dt = new Date();
- List<ProEconMainBrownouts> 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<ProEconMainBrownouts> wrapper = new QueryWrapper<>();
- wrapper.eq("id", item.getId());
- proEconMainBrownoutsService.remove(wrapper);
- }
- }
- List<ProEconBrownoutsEvent> 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<ProEconBrownoutsEvent> 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<String, String> 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<String, String> 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<String, String> 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<ProEconMainBrownouts2> 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<ProEconMainBrownouts2> wrapper = new QueryWrapper<>();
- wrapper.eq("id", item.getId());
- proEconMainBrownouts2Service.remove(wrapper);
- }
- }
- List<ProEconBrownoutsEvent2> 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<ProEconBrownoutsEvent2> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, Map<String, ProBasicEquipmentPoint>> wtpAimap = CacheContext.wtpAimap;
- Map<String, ProBasicEquipmentPoint> 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<String> pointid=new ArrayList<>();
- pointid.add(wtpointmap.get(ContantXk.NXDTJSSDL).getNemCode());
- List<PointData> xdbegin=edosUtil.getHistMatrix(pointid,startDate.getTime()/1000);
- List<PointData> 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<String> pointid=new ArrayList<>();
- pointid.add(wtpointmap.get(ContantXk.NXDJCLSSDL).getNemCode());
- List<PointData> xdbegin=edosUtil.getHistMatrix(pointid,startDate.getTime()/1000);
- List<PointData> 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<String> pointid=new ArrayList<>();
- pointid.add(wtpointmap.get(ContantXk.NXDTJSSDL).getNemCode());
- List<PointData> xdbegin=edosUtil.getHistMatrix(pointid,startDate.getTime()/1000);
- List<PointData> 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<String> pointid=new ArrayList<>();
- pointid.add(wtpointmap.get(ContantXk.NXDJCLSSDL).getNemCode());
- List<PointData> xdbegin=edosUtil.getHistMatrix(pointid,startDate.getTime()/1000);
- List<PointData> 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<String> pointid=new ArrayList<>();
- pointid.add(wtpointmap.get(ContantXk.NXDTJSSDL).getNemCode());
- List<PointData> 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<String> pointid=new ArrayList<>();
- pointid.add(wtpointmap.get(ContantXk.NXDJCLSSDL).getNemCode());
- List<PointData> 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<PointData> getHisData(String szPoint, Date startTime, Date endTime) throws Exception {
- List<PointData> 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<PointData> 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;
- }
- }
|