12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package com.gyee.datacenter.init;
- import com.alibaba.fastjson.JSONObject;
- import com.alibaba.fastjson.TypeReference;
- import com.gyee.common.model.StringUtils;
- import com.gyee.common.util.JSONUtil;
- import com.gyee.datacenter.model.auto.*;
- import com.gyee.datacenter.service.auto.IDatacenterService;
- import com.gyee.datacenter.service.auto.IUniformcodeService;
- import com.gyee.datacenter.service.auto.IWindpowerstationService;
- import com.gyee.datacenter.service.auto.IWindturbineService;
- import com.gyee.datacenter.util.redis.RedisService;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- 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: 2022/2/21 18:20
- * @Description :
- */
- @Component
- public class CacheContext implements CommandLineRunner {
- private static final Logger log = LoggerFactory.getLogger(CacheContext.class);
- @Resource
- private RedisService redisService;
- @Resource
- private IUniformcodeService uniformcodeService;
- @Resource
- private IDatacenterService datacenterService;
- @Resource
- private IWindturbineService windturbineService;
- @Resource
- private IWindpowerstationService windpowerstationService;
- public static List<Datacenter> tableList = new ArrayList<>();
- public static Map<String, List<Datacenterpoint>> pointmap = new HashMap<>();
- public static Map<String,String> inmap = new HashMap<>();
- public static List<Uniformcode> codeList = new ArrayList<>();
- public static Map<String,String> codemap = new HashMap<>();
- public static Map<String,String> wpmap = new HashMap<>();
- public static Map<String, Map<String, Windturbinetestingpointnew>> wtpointmap = new HashMap<>();
- public static Map<String,String> wtmap = new HashMap<>();
- @Override
- public void run(String... args) throws Exception {
- log.info("-------------------------------缓存开始--------------------------------------");
- tableList = datacenterService.list();
- tableList.stream().forEach(i->{
- List<Datacenterpoint> realtimedataList = JSONUtil.jsonToList(redisService.get(i.getTableid()), Datacenterpoint.class);
- if(StringUtils.isNotNull(realtimedataList)){
- pointmap.put(i.getTableid(),realtimedataList);
- realtimedataList.stream().forEach(x->{
- inmap.put(x.getId(),x.getName());
- });
- }
- });
- List<Windpowerstation> wpls = windpowerstationService.list();
- wpls.stream().forEach(i->{
- wpmap.put(i.getId(),i.getName());
- });
- codeList = uniformcodeService.list();
- codeList.stream().forEach(i->{
- codemap.put(i.getCode(),i.getDescription());
- });
- List<Windturbine> wtls = windturbineService.list();
- wtls.stream().forEach(i->{
- wtmap.put(i.getId(),i.getName());
- });
- String wtjson = redisService.get("PRODUCT-WT");
- wtpointmap = JSONObject.parseObject(wtjson, new TypeReference<Map<String, Map<String, Windturbinetestingpointnew>>>() {
- });
- log.info("-------------------------------缓存结束--------------------------------------");
- }
- }
|