package com.gyee.generation.init; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.gyee.common.model.StringUtils; import com.gyee.generation.model.auto.*; import com.gyee.generation.service.auto.*; import com.gyee.generation.util.redis.RedisService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; /** * @ClassName : CacheContext * @Author : xieshengjie * @Date: 2021/5/18 9:35 * @Description : 缓存 */ @Component public class CacheContext implements CommandLineRunner { Logger logger = LoggerFactory.getLogger(CacheContext.class); @Resource private IWindturbineService windturbineService; @Resource private ILineService lineService; @Resource private IProjectService projectService; @Resource private IWindpowerstationService windpowerstationService; @Resource private IMeterpointService meterpointService; @Resource private IEquipmentmodelService equipmentmodelService; @Resource private IWindturbinestatusdiService windturbinestatusdiService; @Resource private IWindturbinepowerService windturbinepowerService; @Resource private RedisService redisService; @Resource private IWindturbinetestingpointaiService windturbinetestingpointaiService; @Resource private IWindpowerstationtestingpointService windpowerstationtestingpointService; @Resource private IWindturbinepowercurvefittingService windturbinepowercurvefittingService; @Value("${runWindpowerstation}") private String runWindpowerstation; @Resource private IWindturbinetestingpointdisService windturbinetestingpointdisService; public static List wtls = new ArrayList<>(); public static Map> wpwtmap = new HashMap<>(); public static Map> pjwtmap = new HashMap<>(); public static Map> lnwtmap = new HashMap<>(); public static List projects = new ArrayList<>(); public static List lines = new ArrayList<>(); public static List wpls = new ArrayList<>(); public static List meterpoints = new ArrayList<>(); public static Map meterpointMap = new HashMap<>(); public static Map> wppromap = new HashMap<>(); public static Map> prolinemap = new HashMap<>(); public static Map> linewtmap = new HashMap<>(); public static Map> wtpAimap = new HashMap<>();// 风电机测点AI表 public static Map> linepointmap = new HashMap<>(); public static Map> propointmap = new HashMap<>(); public static Map> wppointmap = new HashMap<>(); public static Map proMap = new HashMap<>(); public static Map> statusMap = new HashMap<>(); public static Map> zbzglMap = new HashMap<>(); public static Map modelMap = new HashMap<>(); public static Map> zzsglMap = new HashMap<>(); public static Map modelpower = new HashMap<>(); public static Map redisDbMap = new HashMap<>(); public static Map> wtPointmap = new HashMap<>();// 风电机测点AI表 public static Map> wpPointmap = new HashMap<>(); public static Map> curveFittingPowerMap = new HashMap<>(); public static List pointdis = new ArrayList<>(); public static Map< String,Map> pointdismap = new HashMap<>(); @Override public void run(String... args) throws Exception { logger.info("缓存开始------------------------------------------------------------"); // initial(); List runWpids = Arrays.asList(runWindpowerstation.split(",")); logger.info(runWpids.get(0) + "------------------" + runWpids.size()); List equipmentmodels = equipmentmodelService.list(); equipmentmodels.stream().forEach(e -> { modelMap.put(e.getId(), e); }); wtls = windturbineService.list().stream().filter(i -> runWpids.contains(i.getWindpowerstationid())).collect(Collectors.toList()); logger.info(wtls.size() + ""); wtls.forEach(wt -> { Equipmentmodel equipmentmodel = modelMap.get(wt.getModelid()); modelpower.put(wt.getId(), equipmentmodel.getPowerproduction()); String wtString = redisService.get(wt.getId()); Map stringWindturbinetestingpointnewMap = JSONObject.parseObject(wtString, new TypeReference>() { }); wtpAimap.put(wt.getId(), stringWindturbinetestingpointnewMap); if (linewtmap.containsKey(wt.getLineid())) { linewtmap.get(wt.getLineid()).add(wt); } else { List lines = new ArrayList<>(); lines.add(wt); linewtmap.put(wt.getLineid(), lines); } if (wpwtmap.containsKey(wt.getWindpowerstationid())){ wpwtmap.get(wt.getWindpowerstationid()).add(wt); }else { List wps = new ArrayList<>(); wps.add(wt); wpwtmap.put(wt.getWindpowerstationid(),wps); } if (pjwtmap.containsKey(wt.getProjectid())){ pjwtmap.get(wt.getProjectid()).add(wt); }else { List pjs = new ArrayList<>(); pjs.add(wt); pjwtmap.put(wt.getProjectid(),pjs); } if (lnwtmap.containsKey(wt.getLineid())){ lnwtmap.get(wt.getLineid()).add(wt); }else { List lnls = new ArrayList<>(); lnls.add(wt); lnwtmap.put(wt.getLineid(),lnls); } }); projects = projectService.list().stream().filter(i -> runWpids.contains(i.getWindpowerstationid())).collect(Collectors.toList()); projects.stream().forEach(p -> { proMap.put(p.getId(), p); if (wppromap.containsKey(p.getWindpowerstationid())) { wppromap.get(p.getWindpowerstationid()).add(p); } else { List prolist = new ArrayList<>(); prolist.add(p); wppromap.put(p.getWindpowerstationid(), prolist); } String pjString = redisService.get(p.getId()); Map stringWindpowerstationpointnewMap = JSONObject.parseObject(pjString, new TypeReference>() { }); propointmap.put(p.getId(), stringWindpowerstationpointnewMap); }); lines = lineService.list().stream().filter(i -> StringUtils.isNotNull(proMap.get(i.getProjectid())) && runWpids.contains(proMap.get(i.getProjectid()).getWindpowerstationid())).collect(Collectors.toList()); lines.stream().forEach(l -> { if (prolinemap.containsKey(l.getProjectid())) { prolinemap.get(l.getProjectid()).add(l); } else { List lineList = new ArrayList<>(); lineList.add(l); prolinemap.put(l.getProjectid(), lineList); } String lnString = redisService.get(l.getId()); Map stringWindpowerstationpointnewMap = JSONObject.parseObject(lnString, new TypeReference>() { }); linepointmap.put(l.getId(), stringWindpowerstationpointnewMap); }); wpls = windpowerstationService.list().stream().filter(i -> runWpids.contains(i.getId())).collect(Collectors.toList()); ; meterpoints = meterpointService.list().stream().filter(i -> runWpids.contains(i.getWindpowerstationid())).collect(Collectors.toList()); meterpoints.stream().forEach(meterpoint -> { meterpointMap.put(meterpoint.getId(), meterpoint); }); wpls.stream().forEach(wp -> { String wpString = redisService.get(wp.getId()); Map stringMapMap = JSONObject.parseObject(wpString, new TypeReference>() { }); wppointmap.put(wp.getId(), stringMapMap); }); String sszzt = redisService.get("SSZZT"); statusMap = JSONObject.parseObject(sszzt, new TypeReference>>() { }); String zbzgl = redisService.get("ZBZGL"); zbzglMap = JSONObject.parseObject(zbzgl, new TypeReference>>() { }); // List windturbinepowerList = windturbinepowerService.list().stream().filter(windturbinepower -> runWindpowerstation.contains(windturbinepower.getWindpowerstationid())).collect(Collectors.toList()); // windturbinepowerList.stream().forEach(w -> { // if (zzsglMap.containsKey(w.getWindturbineid())){ // zzsglMap.get(w.getWindturbineid()).put(w.getSpeed(),w.getTheorypower()); // }else { // Map tempMap = new HashMap<>(); // tempMap.put(w.getSpeed(),w.getTheorypower()); // zzsglMap.put(w.getWindturbineid(),tempMap); // } // // }); for (int i = 0; i < 8; i++) { Set keys = redisService.keys(i); for (String key : keys) { redisDbMap.put(key, i); } } // String wpString = redisService.get("PRODUCT-WP"); // wppointmap = JSONObject.parseObject(wpString, new TypeReference>>() { // }); // String pjString = redisService.get("PRODUCT-PJ"); // propointmap = JSONObject.parseObject(pjString, new TypeReference>>() { // }); // String lnString = redisService.get("PRODUCT-LN"); // linepointmap = JSONObject.parseObject(lnString, new TypeReference>>() { // }); // String wtString = redisService.get("PRODUCT-WT"); // wtpAimap = JSONObject.parseObject(wtString, new TypeReference>>() { // }); redisService.select(8); // initial(); String wtPointString = redisService.get("wtPointmap"); wtPointmap = JSONObject.parseObject(wtPointString, new TypeReference>>() { }); String wpPointString = redisService.get("wpPointmap"); wpPointmap = JSONObject.parseObject(wpPointString, new TypeReference>>() { }); String curveFittingPowerString = redisService.get("curveFittingPowerMap"); curveFittingPowerMap = JSONObject.parseObject(curveFittingPowerString, new TypeReference>>() { }); String pointdisString = redisService.get("pointdis"); pointdis = JSONObject.parseObject(pointdisString, new TypeReference>() { }); Map items = null; if (pointdis != null && !pointdis.isEmpty()) { for (int i = 0; i < pointdis.size(); i++) { Windturbinetestingpointdis point = pointdis.get(i); if (pointdismap.containsKey(point.getWindturbineid())) { items = pointdismap.get(point.getWindturbineid()); items.put(point.getUniformcode(), point); } else { items = new HashMap(); pointdismap.put(point.getWindturbineid(), items); items.put(point.getUniformcode(), point); } } } logger.info("缓存结束------------------------------------------------------------"); } public void initial() { List wtpointlist = windturbinetestingpointaiService.list(); Map> wtPointmap = new HashMap<>();// 风电机测点AI表 Map map = null; if (wtpointlist != null && !wtpointlist.isEmpty()) { for (Windturbinetestingpointai mp : wtpointlist) { if (wtPointmap.containsKey(mp.getWindturbineid())) { map = wtPointmap.get(mp.getWindturbineid()); map.put(mp.getUniformcode(), mp); } else { map = new HashMap<>(); map.put(mp.getUniformcode(), mp); wtPointmap.put(mp.getWindturbineid(), map); } } } String s = JSONObject.toJSONString(wtPointmap); redisService.set("wtPointmap", s); Map> wpPointmap = new HashMap<>(); List list = windpowerstationtestingpointService.list(); Map items = null; if (list != null && !list.isEmpty()) { for (int i = 0; i < list.size(); i++) { Windpowerstationtestingpoint point = list.get(i); if (wpPointmap.containsKey(point.getWindpowerstationid())) { items = wpPointmap.get(point.getWindpowerstationid()); items.put(point.getUniformcode(), point); } else { items = new HashMap(); wpPointmap.put(point.getWindpowerstationid(), items); items.put(point.getUniformcode(), point); } } } s = JSONObject.toJSONString(wpPointmap); redisService.set("wpPointmap", s); Map> curveFittingPowerMap = new HashMap<>(); List econWtPowerCurveFittings = windturbinepowercurvefittingService.list(); if (StringUtils.isNotNull(econWtPowerCurveFittings)) { econWtPowerCurveFittings.stream().forEach(curveFitting -> { if (curveFittingPowerMap.containsKey(curveFitting.getWindturbineid())) { curveFittingPowerMap.get(curveFitting.getWindturbineid()).put(curveFitting.getSpeed(), curveFitting); } else { Map powerMap = new HashMap<>(); powerMap.put(curveFitting.getSpeed(), curveFitting); curveFittingPowerMap.put(curveFitting.getWindturbineid(), powerMap); } }); } s = JSONObject.toJSONString(curveFittingPowerMap); redisService.set("curveFittingPowerMap", s); List pointdis = new ArrayList<>(); pointdis = windturbinetestingpointdisService.list(); s = JSONObject.toJSONString(pointdis); redisService.set("pointdis", s); } }