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 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<>(); //--------------------------------------new------------------------------------------- @Resource private ProBasicEquipmentService proBasicEquipmentService; @Resource private ProBasicPowerstationService proBasicPowerstationService ; @Resource private ProBasicEquipmentPointService proBasicEquipmentPointService; @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<>(); //--------------------------------------------------------------------------------- @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 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()); 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)); }); log.info("场站数据缓存完成"); } /** * 缓存测点数据 */ 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)){ zsllglMap = powermodelService.selectList().stream() .collect(Collectors.groupingBy(Powermodel::getWindturbineid, Collectors.toMap(Powermodel::getSpeed, Powermodel::getPower))); }else{ List list = powermodelService.selectByWtId(wtId); Map collect = list.stream().collect(Collectors.toMap(Powermodel::getSpeed, Powermodel::getPower)); zsllglMap.replace(wtId, collect); } log.info("自算功率数据缓存完成"); } }