package com.gyee.failurestatistics.init; import com.gyee.failurestatistics.model.auto.*; import com.gyee.failurestatistics.service.HealthpointsService; import com.gyee.failurestatistics.service.auto.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; 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/9/29 17:33 * @Description : 初始化 */ @Component public class CacheContext implements CommandLineRunner { private static final Logger log = LoggerFactory.getLogger(CacheContext.class); @Autowired private IWindturbineService windturbineService; @Autowired private IWindpowerstationService windpowerstationService; @Autowired private IProjectService projectService; @Autowired private ILineService lineService; @Autowired private IEquipmentmodelService equipmentmodelService; @Autowired private IWindturbinetestingpointnewService windturbinetestingpointnewService; @Autowired private IWindpowerstationpointnewService windpowerstationpointnewService; @Resource private HealthpointsService healthpointsService; public static Map wtmap = new HashMap(); // 风电机MAP public static Map hpmap = new HashMap<>(); public static Map wpmap = new HashMap<>(); public static List wpls = new ArrayList(); // 风电场LIST集合 public static List wtls = new ArrayList(); // 风电机LIST集合 public static Map> wtpAimap = new HashMap<>();// 风电机测点AI表 public static Map> wppointmap =new HashMap<>(); public static List projects = new ArrayList<>(); public static List lines = new ArrayList<>(); public static Map> wtsmap = new HashMap>(); // 风电场MAP风电机LIST集合 public static List mlls = new ArrayList();// 风电机模型LIST集合 public static Map mlmap = new HashMap();// 风电机模型 @Override public void run(String... args) throws Exception { log.info("-------------------------------缓存开始--------------------------------------"); hpmap=healthpointsService.findAllMap(); wpls = windpowerstationService.list(); wpls.stream().filter(i->i.getId().endsWith("FDC")).forEach(i->{ wpmap.put(i.getId(),i); }); projects = projectService.list(); lines = lineService.list(); wtls = windturbineService.list(); mlls = equipmentmodelService.list(); if (!mlls.isEmpty()) { for (Equipmentmodel model : mlls) { mlmap.put(model.getId(), model); } } if (!wtls.isEmpty()) { List list = null; for (Windturbine wt : wtls) { wtmap.put(wt.getId(), wt); if (wtsmap.containsKey(wt.getWindpowerstationid())) { list = wtsmap.get(wt.getWindpowerstationid()); list.add(wt); } else { list = new ArrayList(); list.add(wt); wtsmap.put(wt.getWindpowerstationid(), list); } } } List WindturbinetestingpointaiList = windturbinetestingpointnewService.list(); Map map = null; if(WindturbinetestingpointaiList != null && !WindturbinetestingpointaiList.isEmpty()){ for(Windturbinetestingpointnew 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 wplist = windpowerstationpointnewService.list(); for (Windpowerstationpointnew Windpowerstationpointnew : wplist) { if (wppointmap.containsKey(Windpowerstationpointnew.getWindpowerstationid())){ wppointmap.get(Windpowerstationpointnew.getWindpowerstationid()).put(Windpowerstationpointnew.getUniformcode(),Windpowerstationpointnew); }else{ Map wpmap = new HashMap<>(); wpmap.put(Windpowerstationpointnew.getUniformcode(),Windpowerstationpointnew); wppointmap.put(Windpowerstationpointnew.getWindpowerstationid(),wpmap); } } log.info("-------------------------------缓存结束--------------------------------------"); } // 取redis // private Logger logger = LoggerFactory.getLogger(CacheContext.class); // @Resource // private IWindturbinetestingpointService windturbinetestingpointService; // @Resource // private RedisService redisService; // // public static Map> wtpAimap = new HashMap<>();// 风电机测点表 // // @Override // public void run(String... args) { // logger.info("--------------------------------缓存开始--------------------------------"); // if (redisService.hasKey("WT")){ // String wt = redisService.get("WT"); // wtpAimap = (Map>) JSONUtils.parse(wt); // }else { // List windturbinetestingpointList = windturbinetestingpointService.list(); // Map map = null; // // if(windturbinetestingpointList != null && !windturbinetestingpointList.isEmpty()){ // for(Windturbinetestingpoint mp : windturbinetestingpointList){ // 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); // } // } // } // } // logger.info("--------------------------------缓存结束--------------------------------"); // } }