|
@@ -0,0 +1,188 @@
|
|
|
+package com.gyee.cache.init;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.gyee.cache.model.auto.*;
|
|
|
+import com.gyee.cache.service.RedisService;
|
|
|
+import com.gyee.cache.service.auto.*;
|
|
|
+
|
|
|
+
|
|
|
+import com.gyee.common.util.JSONUtil;
|
|
|
+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 java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ClassName : CacheContext
|
|
|
+ * @Author : xieshengjie
|
|
|
+ * @Date: 2021/5/18 9:35
|
|
|
+ * @Description : 缓存
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class CacheContext implements CommandLineRunner {
|
|
|
+ @Autowired
|
|
|
+ private RedisService redisService;
|
|
|
+ @Autowired
|
|
|
+ private IDatacenterService datacenterService;
|
|
|
+ @Autowired
|
|
|
+ private IDatacenterpointService datacenterpointService;
|
|
|
+ @Autowired
|
|
|
+ private IWindturbinetestingpointaiService windturbinetestingpointai2Service;
|
|
|
+ @Autowired
|
|
|
+ private IWindturbineService windturbineService;
|
|
|
+ @Autowired
|
|
|
+ private ILineService lineService;
|
|
|
+ @Autowired
|
|
|
+ private IWindpowerstationtestingpointService windpowerstationtestingpoint2Service;
|
|
|
+ @Autowired
|
|
|
+ private IProjectService projectService;
|
|
|
+ @Autowired
|
|
|
+ private IWindpowerstationService windpowerstationService;
|
|
|
+ @Autowired
|
|
|
+ private IModelpowerrdService modelpowerrdService;
|
|
|
+
|
|
|
+ public static Map<String, Map<String, Windturbinetestingpointai>> wtpointMap = new HashMap<>();
|
|
|
+ public static List<Windturbine> wtls = new ArrayList<>();
|
|
|
+ @Override
|
|
|
+ public void run(String... args) throws Exception {
|
|
|
+
|
|
|
+ Logger logger= LoggerFactory.getLogger(CacheContext.class);
|
|
|
+// logger.info("----------------------缓存开始");
|
|
|
+// wtls = windturbineService.list();
|
|
|
+// List<Windturbinetestingpointai> wtplist = windturbinetestingpointai2Service.list();
|
|
|
+// for (Windturbinetestingpointai pointai : wtplist) {
|
|
|
+// if (wtpointMap.containsKey(pointai.getWindturbineid())){
|
|
|
+// wtpointMap.get(pointai.getWindturbineid()).put(pointai.getUniformcode(),pointai);
|
|
|
+// }else{
|
|
|
+// Map<String, Windturbinetestingpointai> map = new HashMap<>();
|
|
|
+// map.put(pointai.getUniformcode(),pointai);
|
|
|
+// wtpointMap.put(pointai.getWindturbineid(),map);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// logger.info("----------------------缓存结束");
|
|
|
+
|
|
|
+
|
|
|
+// logger.info("----------------------数据中心点开始");
|
|
|
+// //缓存golden 所有点
|
|
|
+// List<Datacenter> datacenterList = datacenterService.list();
|
|
|
+//
|
|
|
+// datacenterList.stream().forEach(i->{
|
|
|
+// if (!redisService.hasKey(i.getTableid())){
|
|
|
+// QueryWrapper<Datacenterpoint> queryWrapper = new QueryWrapper<>();
|
|
|
+// queryWrapper.eq("tid",i.getTableid());
|
|
|
+// List<Datacenterpoint> realtimedataList = datacenterpointService.list(queryWrapper);
|
|
|
+// String s = null;
|
|
|
+// try {
|
|
|
+// s = JSONUtil.objectToJson(realtimedataList);
|
|
|
+// } catch (IOException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// redisService.set(i.getTableid(),s);
|
|
|
+// }
|
|
|
+// });
|
|
|
+// logger.info("----------------------数据中心点结束");
|
|
|
+ logger.info("----------------------设备点开始");
|
|
|
+ //缓存设备点
|
|
|
+ if (!redisService.hasKey("WT")){
|
|
|
+ Map<String,Map<String,Windturbinetestingpointai>> wtaimap = new HashMap<>();
|
|
|
+ List<Windturbine> windturbineList = windturbineService.list();
|
|
|
+ windturbineList.stream().forEach(i->{
|
|
|
+ Map<String,Windturbinetestingpointai> codeaimap = new HashMap<>();
|
|
|
+ QueryWrapper<Windturbinetestingpointai> qw = new QueryWrapper<>();
|
|
|
+ qw.eq("windturbineid",i.getId());
|
|
|
+ List<Windturbinetestingpointai> windturbinetestingpointai2List = windturbinetestingpointai2Service.list(qw);
|
|
|
+ windturbinetestingpointai2List.stream().forEach(x->{
|
|
|
+ codeaimap.put(x.getUniformcode(),x);
|
|
|
+ });
|
|
|
+ wtaimap.put(i.getId(),codeaimap);
|
|
|
+ });
|
|
|
+ String s = JSONObject.toJSONString(wtaimap);
|
|
|
+ redisService.set("WT",s);
|
|
|
+ };
|
|
|
+ logger.info("----------------------设备点结束");
|
|
|
+ logger.info("----------------------线路点开始");
|
|
|
+ //缓存线路点
|
|
|
+ if (!redisService.hasKey("LN")){
|
|
|
+ Map<String,Map<String, Windpowerstationtestingpoint>> lnaimap = new HashMap<>();
|
|
|
+ List<Line> lineList = lineService.list();
|
|
|
+ lineList.stream().forEach(i->{
|
|
|
+ Map<String,Windpowerstationtestingpoint> codeaimap = new HashMap<>();
|
|
|
+ QueryWrapper<Windpowerstationtestingpoint> qw = new QueryWrapper<>();
|
|
|
+ qw.eq("windpowerstationid",i.getId());
|
|
|
+ List<Windpowerstationtestingpoint> windpowerstationtestingpoint2List = windpowerstationtestingpoint2Service.list(qw);
|
|
|
+ windpowerstationtestingpoint2List.stream().forEach(x->{
|
|
|
+ codeaimap.put(x.getUniformcode(),x);
|
|
|
+ });
|
|
|
+ lnaimap.put(i.getId(),codeaimap);
|
|
|
+ });
|
|
|
+ String s = JSONObject.toJSONString(lnaimap);
|
|
|
+ redisService.set("LN",s);
|
|
|
+ };
|
|
|
+ logger.info("----------------------线路点结束");
|
|
|
+ logger.info("----------------------工程点开始");
|
|
|
+ //缓存工程点
|
|
|
+ if (!redisService.hasKey("PJ")){
|
|
|
+ Map<String,Map<String, Windpowerstationtestingpoint>> pjaimap = new HashMap<>();
|
|
|
+ List<Project> projectList = projectService.list();
|
|
|
+ projectList.stream().forEach(i->{
|
|
|
+ Map<String,Windpowerstationtestingpoint> codeaimap = new HashMap<>();
|
|
|
+ QueryWrapper<Windpowerstationtestingpoint> qw = new QueryWrapper<>();
|
|
|
+ qw.eq("windpowerstationid",i.getId());
|
|
|
+ List<Windpowerstationtestingpoint> windpowerstationtestingpoint2List = windpowerstationtestingpoint2Service.list(qw);
|
|
|
+ windpowerstationtestingpoint2List.stream().forEach(x->{
|
|
|
+ codeaimap.put(x.getUniformcode(),x);
|
|
|
+ });
|
|
|
+ pjaimap.put(i.getId(),codeaimap);
|
|
|
+ });
|
|
|
+ String s = JSONObject.toJSONString(pjaimap);
|
|
|
+ redisService.set("PJ",s);
|
|
|
+ };
|
|
|
+ logger.info("----------------------工程点结束");
|
|
|
+ logger.info("----------------------场站点开始");
|
|
|
+ //缓存场站点
|
|
|
+ if (!redisService.hasKey("WP")){
|
|
|
+ Map<String,Map<String, Windpowerstationtestingpoint>> wpaimap = new HashMap<>();
|
|
|
+ List<Windpowerstation> wpList = windpowerstationService.list();
|
|
|
+ List<String> wpids = wpList.stream().map(i -> i.getId()).collect(Collectors.toList());
|
|
|
+ wpids.add("0");
|
|
|
+ wpids.add("-1");
|
|
|
+ wpids.add("-2");
|
|
|
+ wpids.stream().forEach(i->{
|
|
|
+ Map<String,Windpowerstationtestingpoint> codeaimap = new HashMap<>();
|
|
|
+ QueryWrapper<Windpowerstationtestingpoint> qw = new QueryWrapper<>();
|
|
|
+ qw.eq("windpowerstationid",i);
|
|
|
+ List<Windpowerstationtestingpoint> windpowerstationtestingpoint2List = windpowerstationtestingpoint2Service.list(qw);
|
|
|
+ windpowerstationtestingpoint2List.stream().forEach(x->{
|
|
|
+ codeaimap.put(x.getUniformcode(),x);
|
|
|
+ });
|
|
|
+ wpaimap.put(i,codeaimap);
|
|
|
+ });
|
|
|
+ String s = JSONObject.toJSONString(wpaimap);
|
|
|
+
|
|
|
+ redisService.set("WP",s);
|
|
|
+ };
|
|
|
+ logger.info("----------------------场站点结束");
|
|
|
+ logger.info("----------------------MODELPOWERRD表开始");
|
|
|
+ if (!redisService.hasKey("MPRD")){
|
|
|
+ List<Modelpowerrd> mordlist = modelpowerrdService.list();
|
|
|
+ String s = JSONObject.toJSONString(mordlist);
|
|
|
+ redisService.set("MPRD",s);
|
|
|
+ }
|
|
|
+ logger.info("----------------------MODELPOWERRD表结束");
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|