| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- package com.gyee.power.fitting.common.spring;
- import com.gyee.power.fitting.common.config.GyeeConfig;
- import com.gyee.power.fitting.model.*;
- import com.gyee.power.fitting.service.*;
- 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.scheduling.annotation.Async;
- 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 EquipmentmodelService equipmentmodelService;
- @Resource
- private ModelpowerdetailsService modelpowerdetailsService;
- @Resource
- private PowermodelService powermodelService;
- /**
- * 场站所有信息
- **/
- 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<>();
- //--------------------------------------new-------------------------------------------
- @Resource
- private ProBasicEquipmentService proBasicEquipmentService;
- @Resource
- private ProBasicPowerstationService proBasicPowerstationService ;
- @Resource
- private ProBasicEquipmentPointService proBasicEquipmentPointService;
- @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<>();
- //---------------------------------------------------------------------------------
- @Override
- public void run(String... args) {
- System.out.println(">>>>>>>>>>>>>>>服务启动,正在缓存数据<<<<<<<<<<<<<<");
- // cacheStation();
- // cachePoints();
- // cacheEquipment();
- // // 耗时缓存
- // new Thread(){
- // @Override
- // public void run() {
- // super.run();
- // cacheModelPower();
- // cacheZSLLGL(null);
- // }
- // }.start();
- cacheNewStation();
- cacheNewPoints();
- cacheNewEquipment();
- cacheNewModelPower();
- System.out.println(">>>>>>>>>>>>>>>数据缓存完成<<<<<<<<<<<<<<");
- }
- /**
- * 缓存场站、风机数据
- * 数据新增或删除后需要更新,故每次清空
- */
- 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());
- 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));
- });
- log.info("场站数据缓存完成");
- }
- /**
- * 缓存测点数据
- */
- 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)){
- zsllglMap = powermodelService.selectList().stream()
- .collect(Collectors.groupingBy(Powermodel::getWindturbineid,
- Collectors.toMap(Powermodel::getSpeed, Powermodel::getPower)));
- }else{
- List<Powermodel> list = powermodelService.selectByWtId(wtId);
- Map<Double, Double> collect = list.stream().collect(Collectors.toMap(Powermodel::getSpeed, Powermodel::getPower));
- zsllglMap.replace(wtId, collect);
- }
- log.info("自算功率数据缓存完成");
- }
- }
|