package com.gyee.benchmarkinghistroy.init; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.gyee.benchmarkinghistroy.model.auto.*; import com.gyee.benchmarkinghistroy.service.auto.*; import com.gyee.benchmarkinghistroy.util.redis.RedisService; 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.*; /** * @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 IWindturbinetestingpointnewService windturbinetestingpointnewService; @Autowired private IWindpowerstationpointnewService windpowerstationpointnewService; @Resource private RedisService redisService; @Resource private IEquipmentmodelService equipmentmodelService; public static Map> wtmap = new HashMap<>(); public static Map wmap = new HashMap<>(); public static Map wpmap = new HashMap<>(); public static List wplist = new ArrayList<>(); public static List wtls = new ArrayList<>(); public static Map> wtpAimap = new HashMap<>();// 风电机测点AI表 public static Map> wppointmap =new HashMap<>(); public static Map> pjPointmap =new HashMap<>(); public static Map> lnPointmap =new HashMap<>(); public static Map wtrlmap =new HashMap<>(); public static List projects = new ArrayList<>(); public static List lines = new ArrayList<>(); @Override public void run(String... args) throws Exception { log.info("-------------------------------缓存开始--------------------------------------"); wplist = windpowerstationService.list(); wplist.stream().filter(i->i.getId().endsWith("FDC")).forEach(i->{ wpmap.put(i.getId(),i); }); projects = projectService.list(); lines = lineService.list(); wtls = windturbineService.list(); wtls.stream().forEach(wt->{ wmap.put(wt.getId(),wt); if (wtmap.containsKey(wt.getWindpowerstationid())){ wtmap.get(wt.getWindpowerstationid()).add(wt); }else{ List wts = new ArrayList<>(); wts.add(wt); wtmap.put(wt.getWindpowerstationid(),wts); } QueryWrapper queryWrapper= new QueryWrapper<>(); queryWrapper.eq("id",wt.getModelid()); Optional first = equipmentmodelService.list(queryWrapper).stream().findFirst(); if (first.isPresent()){ wtrlmap.put(wt.getId(),first.get().getPowerproduction()); } }); String wpString = redisService.get("PRODUCT-WP"); wppointmap = JSONObject.parseObject(wpString, new TypeReference>>() { }); String pjString = redisService.get("PRODUCT-PJ"); pjPointmap = JSONObject.parseObject(pjString, new TypeReference>>() { }); String lnString = redisService.get("PRODUCT-LN"); lnPointmap = JSONObject.parseObject(lnString, new TypeReference>>() { }); String wtString = redisService.get("PRODUCT-WT"); wtpAimap = JSONObject.parseObject(wtString, new TypeReference>>() { }); log.info("-------------------------------缓存结束--------------------------------------"); } }