package com.gyee.impala.common.spring; import com.gyee.impala.model.master.*; import com.gyee.impala.model.master.diagnose.Diagnosepoint; import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory; import com.gyee.impala.service.master.*; import com.gyee.impala.service.master.diagnose.DiagnosepointService; import com.gyee.impala.service.master.diagnose.DiagnosetrainhistoryService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; /** * 服务启动前执行,进行全局变量初始化 */ @Component @Order(2) public class InitialRunner implements CommandLineRunner { @Resource private WindturbineService windturbineService; @Resource private WindpowerstationService windpowerstationService; @Autowired private KnowcategoryService faulttypeService; @Autowired private EquipmentmodelService modelService; @Autowired private DiagnosepointService diagnosepointService; @Autowired private DiagnosetrainhistoryService diagnosetrainhistoryService; /**场站所有信息**/ public static List wpList = new ArrayList<>(); /**场站的风机**/ public static Map> wpMap = new HashMap<>(); /** **/ public static Map stationMap = new HashMap<>(); /**所有的风机**/ public static List wtList = new ArrayList<>(); /** **/ public static Map wtMap = new HashMap<>(); /**功率曲线预处理数据表格数据 key:time+wtId value:当前风机的总条数 **/ public static Map scatterMap = new HashMap<>(); /***故障 类型*/ public static Map faultTypeMap = new HashMap<>(); public static List faultTypeList = new ArrayList<>(); /***scada预警 类型*/ public static Map scadaWarnMap = new HashMap<>(); public static List scadaWarnList = new ArrayList<>(); /***自定义预警 类型*/ public static Map customWarnMap = new HashMap<>(); public static List customWarnList = new ArrayList<>(); /** 设备型号配置 **/ public static Map modelMap = new HashMap<>(); /** 故障诊断 训练需要的测点**/ public static Map>> mapPoint = new HashMap<>(); /*** 故障训练历史模型 */ public static Map> historyModelMap = new HashMap<>(); public static List historyList = new ArrayList<>(); @Override public void run(String... args){ System.out.println(">>>>>>>>>>>>>>>服务启动,正在缓存数据<<<<<<<<<<<<<<"); cacheStation(); cacheKnowCategory(); cacheEquipmentModel(); cacheDiagnosePoint(); cacheHistory(); System.out.println(">>>>>>>>>>>>>>>数据缓存完成<<<<<<<<<<<<<<"); } /** * 缓存场站数据 * 数据新增或删除后需要更新,故每次清空 */ public void cacheStation(){ wpList.clear(); wtList.clear(); stationMap.clear(); wpMap.clear(); wtMap.clear(); List stations = windpowerstationService.getAll(); wpList = stations; stations.stream().forEach(obj -> { List wts = windturbineService.getWindTurbineId(obj.getId()); stationMap.put(obj.getId(), obj.getName()); wpMap.put(obj.getId(), wts); wtList.addAll(wts); wts.stream().forEach(o -> wtMap.put(o.getId(), o)); }); } /** * 缓存故障知识数据 */ public void cacheKnowCategory() { faultTypeList.clear(); scadaWarnList.clear(); customWarnList.clear(); faultTypeMap.clear(); scadaWarnMap.clear(); customWarnMap.clear(); List faultType = faulttypeService.getAll(); faultType.stream().forEach(obj -> { if (obj.getCategory().equals("GZ")) { faultTypeList.add(obj); faultTypeMap.put(obj.getCode(), obj.getName().toUpperCase()); } else if (obj.getCategory().equals("SCADABJ")) { scadaWarnList.add(obj); scadaWarnMap.put(obj.getCode(), obj.getName().toUpperCase()); } else if (obj.getCategory().equals("CUSTOMBJ")) { customWarnList.add(obj); customWarnMap.put(obj.getCode(), obj.getName().toUpperCase()); } }); } public void cacheEquipmentModel() { modelMap.clear(); List models = modelService.getAll(); models.stream().forEach(obj -> modelMap.put(obj.getId(), obj)); } public void cacheDiagnosePoint(){ mapPoint.clear(); List points = diagnosepointService.getDiagnosepointList(); mapPoint = points.stream().collect(Collectors.groupingBy(Diagnosepoint::getStationen, Collectors.groupingBy(Diagnosepoint::getModel))); } public void cacheHistory(){ historyModelMap.clear(); historyList.clear(); historyList = diagnosetrainhistoryService.getListAll(); historyModelMap = historyList.stream().collect(Collectors.groupingBy(Diagnosetrainhistory::getModel)); } }