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 wpList = new ArrayList<>(); /** * **/ public static Map stationMap = new HashMap<>(); /** * 所有的风机 **/ public static List wtList = new ArrayList<>(); /** * key:wtId NG01_01 **/ public static Map wtMap = new HashMap<>(); /**场站的风机 key:NSS_FDC**/ public static Map> wpMap = new HashMap<>(); /** * 光伏 */ public static List gfwpList = new ArrayList<>(); public static Map gfstationMap = new HashMap<>(); public static List gfwtList = new ArrayList<>(); public static Map gfwtMap = new HashMap<>(); public static Map> gfwpMap = new HashMap<>(); /** * 光照强度-场站 */ public static Map zfsMap = new HashMap<>(); /** * 组件温度-场站 */ public static Map zjwdMap = new HashMap<>(); /** * 功率-场站 */ public static Map> zglMap = new HashMap<>(); /** * 所有设备型号 **/ public static List equipmentList = new ArrayList<>(); /** * key: NG01_01 **/ public static Map> pointMap = new HashMap<>(); @Resource private IWindpowerstationtestingpoint2Service windpowerstationtestingpoint2Service; public static Map equipmentMap = new HashMap<>(); /** * key: model UP82 **/ public static Map> modelPowerDetailMap = new HashMap<>(); /** key: NG01_01, speed, power**/ public static Map> zsllglMap = new HashMap<>(); public static Map 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 wpNewList = new ArrayList<>(); /** * **/ public static Map stationNewMap = new HashMap<>(); /** * 所有的风机 **/ public static List wtNewList = new ArrayList<>(); /** * key:wtId NG01_01 **/ public static Map wtNewMap = new HashMap<>(); /**场站的风机 key:NSS_FDC**/ public static Map> wpNewMap = new HashMap<>(); /** * 光伏 */ public static List gfwpNewList = new ArrayList<>(); public static Map gfstationNewMap = new HashMap<>(); public static List gfwtNewList = new ArrayList<>(); public static Map gfwtNewMap = new HashMap<>(); public static Map> gfwpNewMap = new HashMap<>(); /** * 光照强度-场站 */ public static Map zfsNewMap = new HashMap<>(); /** * 组件温度-场站 */ public static Map zjwdNewMap = new HashMap<>(); /** * 功率-场站 */ public static Map> zglNewMap = new HashMap<>(); /** * 所有设备型号 **/ public static List equipmentNewList = new ArrayList<>(); /** * key: NG01_01 **/ public static Map> pointNewMap = new HashMap<>(); public static Map equipmentNewMap = new HashMap<>(); /** * key: model UP82 **/ public static Map> modelPowerDetailNewMap = new HashMap<>(); /** key: NG01_01, speed, power**/ public static Map> zsllglNewMap = new HashMap<>(); /** * 功率-场站 */ public static Map> newzglMap = new HashMap<>(); public static Map> newllglMap = new HashMap<>(); public static Map newzjwdMap = new HashMap<>(); public static Map newzfsMap = new HashMap<>(); public static Map newwtMap = new HashMap<>(); public static List newwpList = new ArrayList<>(); public static List newwtList = new ArrayList<>(); public static Map> newwpMap = new HashMap<>(); public static List newgfwpList = new ArrayList<>(); public static Map newstationMap = new HashMap<>(); public static Map newgfstationMap = new HashMap<>(); public static Map> newgfwpMap = new HashMap<>(); public static List newgfwtList = new ArrayList<>(); public static Map 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 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 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 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 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 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 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 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 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 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 zfsPoints = proBasicPowerstationPointService.getzfsPoints("GDC", ipcfService.getUniforcodes().get("光照强度")); List 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 zglPoints = pointService1.getPoints("GDC", null, ipcfService.getUniforcodes().get("功率")); newzglMap = zglPoints.stream().collect(Collectors.groupingBy(ProBasicEquipmentPoint::getWindpowerstationId)); List llglPoints = pointService1.getPoints("GDC", null, ipcfService.getUniforcodes().get("理论功率")); newllglMap = llglPoints.stream().collect(Collectors.groupingBy(ProBasicEquipmentPoint::getWindpowerstationId)); } /** * 缓存测点数据 */ private void cachePoints() { List 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 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 lsMPD = modelpowerdetailsService.selectList(); modelPowerDetailMap.putAll(lsMPD.stream().collect(Collectors.groupingBy(u -> u.getModelid()))); log.info("保证功率数据缓存完成"); } private void cacheNewModelPower() { List 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 list = proEconPowerModelService.selectByWtId(wtId); Map 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("自功率预测相关测点数据缓存完成"); } }