123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- 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<String, List<Windturbine>> wtmap = new HashMap<>();
- public static Map<String,Windturbine> wmap = new HashMap<>();
- public static Map<String, Windpowerstation> wpmap = new HashMap<>();
- public static List<Windpowerstation> wplist = new ArrayList<>();
- public static List<Windturbine> wtls = new ArrayList<>();
- public static Map<String, Map<String, Windturbinetestingpointnew>> wtpAimap = new HashMap<>();// 风电机测点AI表
- public static Map<String,Map<String, Windpowerstationpointnew>> wppointmap =new HashMap<>();
- public static Map<String,Map<String, Windpowerstationpointnew>> pjPointmap =new HashMap<>();
- public static Map<String,Map<String, Windpowerstationpointnew>> lnPointmap =new HashMap<>();
- public static Map<String,Double> wtrlmap =new HashMap<>();
- public static List<Project> projects = new ArrayList<>();
- public static List<Line> 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<Windturbine> wts = new ArrayList<>();
- wts.add(wt);
- wtmap.put(wt.getWindpowerstationid(),wts);
- }
- QueryWrapper<Equipmentmodel> queryWrapper= new QueryWrapper<>();
- queryWrapper.eq("id",wt.getModelid());
- Optional<Equipmentmodel> 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<Map<String, Map<String, Windpowerstationpointnew>>>() {
- });
- String pjString = redisService.get("PRODUCT-PJ");
- pjPointmap = JSONObject.parseObject(pjString, new TypeReference<Map<String, Map<String, Windpowerstationpointnew>>>() {
- });
- String lnString = redisService.get("PRODUCT-LN");
- lnPointmap = JSONObject.parseObject(lnString, new TypeReference<Map<String, Map<String, Windpowerstationpointnew>>>() {
- });
- String wtString = redisService.get("PRODUCT-WT");
- wtpAimap = JSONObject.parseObject(wtString, new TypeReference<Map<String, Map<String, Windturbinetestingpointnew>>>() {
- });
- log.info("-------------------------------缓存结束--------------------------------------");
- }
- }
|