package com.gyee.ghost.init; import com.gyee.common.model.StringUtils; import com.gyee.common.util.DateUtils; import com.gyee.ghost.model.auto.*; import com.gyee.ghost.service.RealtimeService; import com.gyee.ghost.service.auto.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.CommandLineRunner; 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; /** * @ClassName : CacheContext * @Author : xieshengjie * @Date: 2021/5/18 9:35 * @Description : 缓存 */ @Component public class CacheContext implements CommandLineRunner { @Resource private RealtimeService realtimeService; @Resource private IWindturbineService windturbineService; @Resource private IProjectService projectService; @Resource private IWindpowerstationService windpowerstationService; @Resource private IStoptypeService stoptypeService; @Resource private IWindturbinetestingpointaiService windturbinetestingpointaiService; @Resource private IFreedomService freedomService; @Resource private IEquipmentmodelService equipmentmodelService; @Resource private IProEconStatusmxService proEconStatusmxService; public static List wtls = new ArrayList<>(); public static Map wtmap = new HashMap<>(); public static Map promap = new HashMap<>(); public static Map wpmap = new HashMap<>(); public static List wpls = new ArrayList<>(); public static Map stopmap = new HashMap<>(); public static Map> wtpAimap = new HashMap(); public static Map wtcap = new HashMap<>(); public static Map statusmxMap = new HashMap<>(); // public static Map freedomMap = new HashMap<>(); @Override public void run(String... args) throws Exception { List equipmentmodelList = equipmentmodelService.list(); wtls = windturbineService.list(); wtls.stream().forEach(wt->{ wtmap.put(wt.getId(),wt); Double powerproduction = equipmentmodelList.stream().filter(e -> e.getId().equals(wt.getModelid())).findFirst().get().getPowerproduction(); wtcap.put(wt.getId(),powerproduction); }); wpls = windpowerstationService.list(); wpls.stream().forEach(windpowerstation -> { wpmap.put(windpowerstation.getId(),windpowerstation); }); List stoptypes = stoptypeService.list(); stoptypes.forEach(stoptype -> { stopmap.put(stoptype.getId(),stoptype.getName()); }); List WindturbinetestingpointaiList = windturbinetestingpointaiService.list(); Map map = null; if(StringUtils.isNotEmpty(WindturbinetestingpointaiList)){ for(Windturbinetestingpointai mp : WindturbinetestingpointaiList){ if(wtpAimap.containsKey(mp.getWindturbineid())){ map = wtpAimap.get(mp.getWindturbineid()); map.put(mp.getUniformcode(), mp); }else{ map = new HashMap<>(); map.put(mp.getUniformcode(), mp); wtpAimap.put(mp.getWindturbineid(), map); } } } List projectList = projectService.list(); projectList.stream().forEach(project -> { promap.put(project.getId(),project); }); List statusmxList = proEconStatusmxService.list(); statusmxList.stream().forEach(mx->{ statusmxMap.put(mx.getId(),mx.getName()); }); // List freedoms = freedomService.list(); // freedoms.stream().forEach(f->{ // freedomMap.put(f.getId(),f.getName()); // }); String yesterday = DateUtils.getYesterdayStr("yyyy-MM-dd"); try { // realtimeService.saveWindturbineStatus2(); realtimeService.saveWindstationStatus(yesterday,yesterday); } catch (Exception e) { e.printStackTrace(); } } }