| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- 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<String, Windturbine> wtmap = new HashMap<String, Windturbine>(); // 风电机MAP
- public static Map<String, Healthpoint> hpmap = new HashMap<>();
- public static Map<String, Windpowerstation> wpmap = new HashMap<>();
- public static List<Windpowerstation> wpls = new ArrayList<Windpowerstation>(); // 风电场LIST集合
- public static List<Windturbine> wtls = new ArrayList<Windturbine>(); // 风电机LIST集合
- public static Map<String, Map<String, Windturbinetestingpointnew>> wtpAimap = new HashMap<>();// 风电机测点AI表
- public static Map<String,Map<String, Windpowerstationpointnew>> wppointmap =new HashMap<>();
- public static List<Project> projects = new ArrayList<>();
- public static List<Line> lines = new ArrayList<>();
- public static Map<String, List<Windturbine>> wtsmap = new HashMap<String, List<Windturbine>>(); // 风电场MAP风电机LIST集合
- public static List<Equipmentmodel> mlls = new ArrayList<Equipmentmodel>();// 风电机模型LIST集合
- public static Map<String, Equipmentmodel> mlmap = new HashMap<String, Equipmentmodel>();// 风电机模型
- @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<Windturbine> 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<Windturbine>();
- list.add(wt);
- wtsmap.put(wt.getWindpowerstationid(), list);
- }
- }
- }
- List<Windturbinetestingpointnew> WindturbinetestingpointaiList = windturbinetestingpointnewService.list();
- Map<String, Windturbinetestingpointnew> 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<String, Windturbinetestingpointnew>();
- map.put(mp.getUniformcode(), mp);
- wtpAimap.put(mp.getWindturbineid(), map);
- }
- }
- }
- List<Windpowerstationpointnew> wplist = windpowerstationpointnewService.list();
- for (Windpowerstationpointnew Windpowerstationpointnew : wplist) {
- if (wppointmap.containsKey(Windpowerstationpointnew.getWindpowerstationid())){
- wppointmap.get(Windpowerstationpointnew.getWindpowerstationid()).put(Windpowerstationpointnew.getUniformcode(),Windpowerstationpointnew);
- }else{
- Map<String,Windpowerstationpointnew> 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<String, Map<String, Windturbinetestingpoint>> wtpAimap = new HashMap<>();// 风电机测点表
- //
- // @Override
- // public void run(String... args) {
- // logger.info("--------------------------------缓存开始--------------------------------");
- // if (redisService.hasKey("WT")){
- // String wt = redisService.get("WT");
- // wtpAimap = (Map<String, Map<String, Windturbinetestingpoint>>) JSONUtils.parse(wt);
- // }else {
- // List<Windturbinetestingpoint> windturbinetestingpointList = windturbinetestingpointService.list();
- // Map<String, Windturbinetestingpoint> 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<String, Windturbinetestingpoint>();
- // map.put(mp.getUniformcode(), mp);
- // wtpAimap.put(mp.getWindturbineid(), map);
- // }
- // }
- // }
- // }
- // logger.info("--------------------------------缓存结束--------------------------------");
- // }
- }
|