123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462 |
- package com.gyee.power.fitting.common.spring;
- import com.alibaba.fastjson.JSON;
- import com.gyee.power.fitting.common.config.GyeeConfig;
- import com.gyee.power.fitting.common.util.FileUtil;
- import com.gyee.power.fitting.model.*;
- import com.gyee.power.fitting.model.agc.AgcDeviateConfig;
- import com.gyee.power.fitting.service.*;
- import com.gyee.power.fitting.service.impl.NewIvPvCurveFittingService;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.boot.CommandLineRunner;
- import org.springframework.core.annotation.Order;
- import org.springframework.stereotype.Component;
- import javax.annotation.Resource;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.function.Function;
- import java.util.stream.Collectors;
- /**
- * 服务启动前执行,进行全局变量初始化
- */
- @Slf4j
- @Component
- @Order(1)
- public class InitialRunner implements CommandLineRunner {
- @Resource
- GyeeConfig config;
- @Resource
- private WindturbineService windturbineService;
- @Resource
- private WindpowerstationService windpowerstationService;
- @Resource
- private Windturbinetestingpointai2Service pointService;
- @Resource
- private ProBasicEquipmentPointService pointService1;
- @Resource
- private EquipmentmodelService equipmentmodelService;
- @Resource
- private ModelpowerdetailsService modelpowerdetailsService;
- @Resource
- private PowermodelService powermodelService;
- @Resource
- private ProEconPowerModelService proEconPowerModelService;
- @Resource
- private NewIvPvCurveFittingService ipcfService;
- /**
- * 场站所有信息
- **/
- public static List<Windpowerstation> wpList = new ArrayList<>();
- /**
- * <MHS_FDC, 麻黄山风电场>
- **/
- public static Map<String, String> stationMap = new HashMap<>();
- /**
- * 所有的风机
- **/
- public static List<Windturbine> wtList = new ArrayList<>();
- /**
- * key:wtId NG01_01
- **/
- public static Map<String, Windturbine> wtMap = new HashMap<>();
- /**场站的风机 key:NSS_FDC**/
- public static Map<String, List<Windturbine>> wpMap = new HashMap<>();
- /**
- * 光伏
- */
- public static List<Windpowerstation> gfwpList = new ArrayList<>();
- public static Map<String, String> gfstationMap = new HashMap<>();
- public static List<Windturbine> gfwtList = new ArrayList<>();
- public static Map<String, Windturbine> gfwtMap = new HashMap<>();
- public static Map<String, List<Windturbine>> gfwpMap = new HashMap<>();
- /**
- * 光照强度-场站
- */
- public static Map<String, Windpowerstationtestingpoint2> zfsMap = new HashMap<>();
- /**
- * 组件温度-场站
- */
- public static Map<String, Windpowerstationtestingpoint2> zjwdMap = new HashMap<>();
- /**
- * 功率-场站
- */
- public static Map<String, List<Windturbinetestingpointai2>> zglMap = new HashMap<>();
- /**
- * 所有设备型号
- **/
- public static List<Equipmentmodel> equipmentList = new ArrayList<>();
- /**
- * key: NG01_01
- **/
- public static Map<String, List<Windturbinetestingpointai2>> pointMap = new HashMap<>();
- @Resource
- private IWindpowerstationtestingpoint2Service windpowerstationtestingpoint2Service;
- public static Map<String, Equipmentmodel> equipmentMap = new HashMap<>();
- /**
- * key: model UP82
- **/
- public static Map<String, List<Modelpowerdetails>> modelPowerDetailMap = new HashMap<>();
- /** key: NG01_01, speed, power**/
- public static Map<String, Map<Double, Double>> zsllglMap = new HashMap<>();
- public static Map<String, AgcDeviateConfig> powerPreMap = new HashMap<>();
- //--------------------------------------new-------------------------------------------
- @Resource
- private ProBasicEquipmentService proBasicEquipmentService;
- @Resource
- private ProBasicPowerstationService proBasicPowerstationService ;
- @Resource
- private ProBasicEquipmentPointService proBasicEquipmentPointService;
- @Resource
- private ProBasicPowerstationPointService proBasicPowerstationPointService;
- @Resource
- private ProEconEquipmentmodelService proEconEquipmentmodelService;
- @Resource
- private ProBasicModelPowerService proBasicModelPowerService;
- /**
- * 场站所有信息
- **/
- public static List<ProBasicPowerstation> wpNewList = new ArrayList<>();
- /**
- * <MHS_FDC, 麻黄山风电场>
- **/
- public static Map<String, String> stationNewMap = new HashMap<>();
- /**
- * 所有的风机
- **/
- public static List<ProBasicEquipment> wtNewList = new ArrayList<>();
- /**
- * key:wtId NG01_01
- **/
- public static Map<String, ProBasicEquipment> wtNewMap = new HashMap<>();
- /**场站的风机 key:NSS_FDC**/
- public static Map<String, List<ProBasicEquipment>> wpNewMap = new HashMap<>();
- /**
- * 光伏
- */
- public static List<ProBasicPowerstation> gfwpNewList = new ArrayList<>();
- public static Map<String, String> gfstationNewMap = new HashMap<>();
- public static List<ProBasicEquipment> gfwtNewList = new ArrayList<>();
- public static Map<String, ProBasicEquipment> gfwtNewMap = new HashMap<>();
- public static Map<String, List<ProBasicEquipment>> gfwpNewMap = new HashMap<>();
- /**
- * 光照强度-场站
- */
- public static Map<String, ProBasicPowerstationPoint> zfsNewMap = new HashMap<>();
- /**
- * 组件温度-场站
- */
- public static Map<String, ProBasicPowerstationPoint> zjwdNewMap = new HashMap<>();
- /**
- * 功率-场站
- */
- public static Map<String, List<ProBasicEquipmentPoint>> zglNewMap = new HashMap<>();
- /**
- * 所有设备型号
- **/
- public static List<ProEconEquipmentmodel> equipmentNewList = new ArrayList<>();
- /**
- * key: NG01_01
- **/
- public static Map<String, List<ProBasicEquipmentPoint>> pointNewMap = new HashMap<>();
- public static Map<String, ProEconEquipmentmodel> equipmentNewMap = new HashMap<>();
- /**
- * key: model UP82
- **/
- public static Map<String, List<ProBasicModelPower>> modelPowerDetailNewMap = new HashMap<>();
- /** key: NG01_01, speed, power**/
- public static Map<String, Map<Double, Double>> zsllglNewMap = new HashMap<>();
- /**
- * 功率-场站
- */
- public static Map<String, List<ProBasicEquipmentPoint>> newzglMap = new HashMap<>();
- public static Map<String, List<ProBasicEquipmentPoint>> newllglMap = new HashMap<>();
- public static Map<String, ProBasicPowerstationPoint> newzjwdMap = new HashMap<>();
- public static Map<String, ProBasicPowerstationPoint> newzfsMap = new HashMap<>();
- public static Map<String, ProBasicEquipment> newwtMap = new HashMap<>();
- public static List<ProBasicPowerstation> newwpList = new ArrayList<>();
- public static List<ProBasicEquipment> newwtList = new ArrayList<>();
- public static Map<String, List<ProBasicEquipment>> newwpMap = new HashMap<>();
- public static List<ProBasicPowerstation> newgfwpList = new ArrayList<>();
- public static Map<String, String> newstationMap = new HashMap<>();
- public static Map<String, String> newgfstationMap = new HashMap<>();
- public static Map<String, List<ProBasicEquipment>> newgfwpMap = new HashMap<>();
- public static List<ProBasicEquipment> newgfwtList = new ArrayList<>();
- public static Map<String, ProBasicEquipment> newgfwtMap = new HashMap<>();
- //---------------------------------------------------------------------------------
- @Override
- public void run(String... args) {
- System.out.println(">>>>>>>>>>>>>>>服务启动,正在缓存数据<<<<<<<<<<<<<<");
- // cacheStation();
- // cachePoints();
- // cacheEquipment();
- // // 耗时缓存
- // new Thread(){
- // @Override
- // public void run() {
- // super.run();
- // cacheModelPower();
- // cacheZSLLGL(null);
- // }
- // }.start();
- newcacheStation();
- cachePhotovoltaicInfo();
- cacheNewStation();
- cacheNewPoints();
- cacheNewEquipment();
- new Thread(){
- @Override
- public void run() {
- super.run();
- cacheNewModelPower();
- cacheZSLLGL(null);
- }
- }.start();
- System.out.println(">>>>>>>>>>>>>>>数据缓存完成<<<<<<<<<<<<<<");
- }
- /**
- * 缓存场站、风机数据
- * 数据新增或删除后需要更新,故每次清空
- */
- public void newcacheStation() {
- List<ProBasicPowerstation> stations = proBasicPowerstationService.selectList();
- newwpList = stations.stream().filter(f -> f.getId().contains("FDC_STA")).collect(Collectors.toList());
- newgfwpList = stations.stream().filter(f -> f.getId().contains("GDC_STA")).collect(Collectors.toList());
- newwpList.forEach(obj -> {
- List<ProBasicEquipment> wts = proBasicEquipmentService.selectList(obj.getId());
- newstationMap.put(obj.getId(), obj.getName());
- newwpMap.put(obj.getId(), wts);
- newwtList.addAll(wts);
- wts.forEach(u -> newwtMap.put(u.getId(), u));
- });
- newgfwpList.stream().forEach(obj -> {
- List<ProBasicEquipment> wts = proBasicEquipmentService.selectList(obj.getId());
- newgfstationMap.put(obj.getId(), obj.getName());
- newgfwpMap.put(obj.getId(), wts);
- newgfwtList.addAll(wts);
- wts.stream().forEach(u -> newgfwtMap.put(u.getId(), u));
- });
- log.info("场站数据缓存完成");
- }
- public void cacheStation() {
- List<Windpowerstation> stations = windpowerstationService.selectList();
- wpList = stations.stream().filter(f -> f.getId().contains("FDC")).collect(Collectors.toList());
- gfwpList = stations.stream().filter(f -> f.getId().contains("GDC")).collect(Collectors.toList());
- wpList.forEach(obj -> {
- List<Windturbine> wts = windturbineService.selectList(obj.getId());
- stationMap.put(obj.getId(), obj.getName());
- wpMap.put(obj.getId(), wts);
- wtList.addAll(wts);
- wts.forEach(u -> wtMap.put(u.getId(), u));
- });
- gfwpList.stream().forEach(obj -> {
- List<Windturbine> wts = windturbineService.selectList(obj.getId());
- gfstationMap.put(obj.getId(), obj.getName());
- gfwpMap.put(obj.getId(), wts);
- gfwtList.addAll(wts);
- wts.stream().forEach(u -> gfwtMap.put(u.getId(), u));
- });
- log.info("场站数据缓存完成");
- }
- /**
- * 缓存场站、风机数据
- * 数据新增或删除后需要更新,故每次清空
- */
- public void cacheNewStation() {
- List<ProBasicPowerstation> stations = proBasicPowerstationService.list();
- wpNewList = stations.stream().filter(f -> f.getId().contains("FDC")).collect(Collectors.toList());
- gfwpNewList = stations.stream().filter(f -> f.getId().contains("GDC")).collect(Collectors.toList());
- wpNewList.forEach(obj -> {
- List<ProBasicEquipment> wts =proBasicEquipmentService.list().stream().filter(w -> w.getWindpowerstationId().equals(obj.getId())).collect(Collectors.toList());;
- stationNewMap.put(obj.getId(), obj.getName());
- wpNewMap.put(obj.getId(), wts);
- wtNewList.addAll(wts);
- wts.forEach(u -> wtNewMap.put(u.getId(), u));
- });
- gfwpNewList.stream().forEach(obj -> {
- List<ProBasicEquipment> wts = proBasicEquipmentService.selectList(obj.getId());
- gfstationNewMap.put(obj.getId(), obj.getName());
- gfwpNewMap.put(obj.getId(), wts);
- gfwtNewList.addAll(wts);
- wts.stream().forEach(u -> gfwtNewMap.put(u.getId(), u));
- });
- log.info("场站数据缓存完成");
- }
- private void cachePhotovoltaicInfo() {
- List<ProBasicPowerstationPoint> zfsPoints = proBasicPowerstationPointService.getzfsPoints("GDC", ipcfService.getUniforcodes().get("光照强度"));
- List<ProBasicPowerstationPoint> zjwdPoints = proBasicPowerstationPointService.getzjwdPoints("GDC", ipcfService.getUniforcodes().get("组件温度"));
- newzfsMap = zfsPoints.stream().collect(Collectors.toMap(ProBasicPowerstationPoint::getWindpowerstationId, Function.identity()));
- newzjwdMap = zjwdPoints.stream().collect(Collectors.toMap(ProBasicPowerstationPoint::getWindpowerstationId, Function.identity()));
- List<ProBasicEquipmentPoint> zglPoints = pointService1.getPoints("GDC", null, ipcfService.getUniforcodes().get("功率"));
- newzglMap = zglPoints.stream().collect(Collectors.groupingBy(ProBasicEquipmentPoint::getWindpowerstationId));
- List<ProBasicEquipmentPoint> llglPoints = pointService1.getPoints("GDC", null, ipcfService.getUniforcodes().get("理论功率"));
- newllglMap = llglPoints.stream().collect(Collectors.groupingBy(ProBasicEquipmentPoint::getWindpowerstationId));
- }
- /**
- * 缓存测点数据
- */
- private void cachePoints() {
- List<Windturbinetestingpointai2> list = new ArrayList<>();
- wpList.stream().forEach(d -> list.addAll(pointService.selectList(d.getId(), config.getPoints())));
- pointMap.putAll(list.stream().collect(Collectors.groupingBy(u -> u.getWindturbineid())));
- log.info("cachePoints: " + pointMap.size());
- if (pointMap.size() == 0)
- log.error("cachePoints", "测点数据缓存失败");
- }
- /**
- * 缓存测点数据
- */
- private void cacheNewPoints() {
- List<ProBasicEquipmentPoint> list = new ArrayList<>();
- wpNewList.stream().forEach(d -> list.addAll(proBasicEquipmentPointService.selectList(d.getId(), config.getPoints())));
- pointNewMap.putAll(list.stream().collect(Collectors.groupingBy(u -> u.getWindturbineId())));
- log.info("cachePoints: " + pointNewMap.size());
- if (pointNewMap.size() == 0)
- log.error("cachePoints", "测点数据缓存失败");
- }
- /**
- * 缓存设备型号
- */
- private void cacheEquipment() {
- equipmentList.addAll(equipmentmodelService.selectList());
- for (Equipmentmodel eq : equipmentList)
- equipmentMap.put(eq.getId(), eq);
- log.info("设备型号数据缓存完成");
- }
- /**
- * 缓存设备型号
- */
- private void cacheNewEquipment() {
- equipmentNewList.addAll(proEconEquipmentmodelService.list());
- for (ProEconEquipmentmodel eq : equipmentNewList)
- equipmentNewMap.put(eq.getId(), eq);
- log.info("设备型号数据缓存完成");
- }
- private void cacheModelPower() {
- List<Modelpowerdetails> lsMPD = modelpowerdetailsService.selectList();
- modelPowerDetailMap.putAll(lsMPD.stream().collect(Collectors.groupingBy(u -> u.getModelid())));
- log.info("保证功率数据缓存完成");
- }
- private void cacheNewModelPower() {
- List<ProBasicModelPower> lsMPD = proBasicModelPowerService.list();
- modelPowerDetailNewMap.putAll(lsMPD.stream().collect(Collectors.groupingBy(u -> u.getModelId())));
- log.info("保证功率数据缓存完成");
- }
- /**
- * 自算理论功率
- */
- public void cacheZSLLGL(String wtId){
- if (StringUtils.isEmpty(wtId)){
- zsllglNewMap = proEconPowerModelService.selectList().stream()
- .collect(Collectors.groupingBy(ProEconPowerModel::getWindturbineId,
- Collectors.toMap(ProEconPowerModel::getSpeed, ProEconPowerModel::getPower)));
- }else{
- List<ProEconPowerModel> list = proEconPowerModelService.selectByWtId(wtId);
- Map<Double, Double> collect = list.stream().collect(Collectors.toMap(ProEconPowerModel::getSpeed, ProEconPowerModel::getPower));
- zsllglNewMap.replace(wtId, collect);
- }
- log.info("自算功率数据缓存完成");
- }
- /**
- * 功率预测相关测点
- */
- private void cacheFGL(){
- String str = FileUtil.getStringFromFile(config.getFilePathPower() + "fgl_info.json");
- AgcDeviateConfig[] object = JSON.parseObject(str, AgcDeviateConfig[].class);
- for (AgcDeviateConfig conf : object){
- powerPreMap.put(conf.getId(), conf);
- }
- log.info("自功率预测相关测点数据缓存完成");
- }
- }
|