浏览代码

redis缓存

xieshengjie 2 年之前
父节点
当前提交
b20161a4ae

+ 10 - 0
realtime/generationXK-service/pom.xml

@@ -29,6 +29,10 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
             <optional>true</optional>
@@ -96,6 +100,12 @@
             <groupId>org.postgresql</groupId>
             <artifactId>postgresql</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi</artifactId>
+            <version>3.17</version>
+            <scope>compile</scope>
+        </dependency>
 
 
     </dependencies>

+ 159 - 0
realtime/generationXK-service/src/main/java/com/gyee/generation/service/initalcache/CacheService.java

@@ -0,0 +1,159 @@
+package com.gyee.generation.service.initalcache;/*
+@author   谢生杰
+@date   2022/11/3-9:14
+*/
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.gyee.common.model.auto.Windturbine;
+import com.gyee.common.service.IWindturbineService;
+import com.gyee.generation.model.auto.*;
+import com.gyee.generation.service.auto.*;
+import com.gyee.generation.util.redis.RedisService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@Service
+@Slf4j
+public class CacheService {
+
+    @Autowired
+    private RedisService redisService;
+    @Autowired
+    private IProBasicWindturbineService windturbineService;
+    @Autowired
+    private IProBasicLineService lineService;
+    @Autowired
+    private IProBasicProjectService projectService;
+    @Autowired
+    private IProBasicWindpowerstationService windpowerstationService;
+    @Autowired
+    private IProBasicEquipmentPointService windturbinetestingpointnewService;
+    @Autowired
+    private IProBasicWppointService windpowerstationpointnewService;
+    @Autowired
+    private IProBasicCompanyService companyService;
+    @Autowired
+    private IProBasicRegionService regionsService;
+
+
+    public void initRedisCache(){
+        log.info("--------------------------redisWT");
+        List<ProBasicWindturbine> windturbineList = windturbineService.list().stream().filter(i->i.getIsable().equals(1)).collect(Collectors.toList());
+        windturbineList.stream().forEach(i->{
+            Map<String, ProBasicEquipmentPoint> codeaimap = new HashMap<>();
+            QueryWrapper<ProBasicEquipmentPoint> qw = new QueryWrapper<>();
+            qw.eq("windturbine_id",i.getId());
+            List<ProBasicEquipmentPoint> windturbinetestingpointai2List = windturbinetestingpointnewService.list(qw);
+            windturbinetestingpointai2List.stream().forEach(x->{
+                codeaimap.put(x.getUniformCode(),x);
+            });
+            String s = JSONObject.toJSONString(codeaimap);
+            redisService.set(i.getId(),s);
+        });
+
+        log.info("--------------------------redisLN");
+        List<ProBasicLine> lineList = lineService.list().stream().filter(i->i.getIsAble().equals(1)).collect(Collectors.toList());
+        lineList.stream().forEach(i->{
+            Map<String, ProBasicWppoint> codeaimap = new HashMap<>();
+            QueryWrapper<ProBasicWppoint> qw = new QueryWrapper<>();
+            qw.eq("windpowerstation_id",i.getId());
+            List<ProBasicWppoint> windpowerstationtestingpoint2List = windpowerstationpointnewService.list(qw);
+            windpowerstationtestingpoint2List.stream().forEach(x->{
+                codeaimap.put(x.getUniformCode(),x);
+            });
+            String s = JSONObject.toJSONString(codeaimap);
+            redisService.set(i.getId(),s);
+        });
+
+        log.info("--------------------------redisPJ");
+        List<ProBasicProject> projectList = projectService.list().stream().filter(i->i.getIsAble().equals(1)).collect(Collectors.toList());
+        projectList.stream().forEach(i->{
+            Map<String,ProBasicWppoint> codeaimap = new HashMap<>();
+            QueryWrapper<ProBasicWppoint> qw = new QueryWrapper<>();
+            qw.eq("windpowerstation_id",i.getId());
+            List<ProBasicWppoint> windpowerstationtestingpoint2List = windpowerstationpointnewService.list(qw);
+            windpowerstationtestingpoint2List.stream().forEach(x->{
+                codeaimap.put(x.getUniformCode(),x);
+            });
+            String s = JSONObject.toJSONString(codeaimap);
+            redisService.set(i.getId(),s);
+        });
+
+        log.info("--------------------------redisWP");
+        List<ProBasicWindpowerstation> wpList = windpowerstationService.list().stream().filter(i->i.getIsAble().equals(1)).collect(Collectors.toList());
+
+        wpList.stream().forEach(i->{
+            Map<String, ProBasicWppoint> codeaimap = new HashMap<>();
+            QueryWrapper<ProBasicWppoint> qw = new QueryWrapper<>();
+            qw.eq("windpowerstation_id",i.getId());
+            List<ProBasicWppoint> windpowerstationtestingpoint2List = windpowerstationpointnewService.list(qw);
+            windpowerstationtestingpoint2List.stream().forEach(x->{
+                codeaimap.put(x.getUniformCode(),x);
+            });
+            String s = JSONObject.toJSONString(codeaimap);
+            redisService.set(i.getId(),s);
+        });
+
+        log.info("--------------------------redisCOMPANY");
+        List<ProBasicCompany> coms = companyService.list().stream().filter(i->i.getIsAble().equals(1)).collect(Collectors.toList());
+        List<String> comList = coms.stream().map(i->i.getId()).collect(Collectors.toList());
+        coms.stream().forEach(company -> {
+            comList.add(company.getId()+"0");
+            comList.add(company.getId()+"-1");
+            comList.add(company.getId()+"-2");
+        });
+        comList.stream().forEach(i->{
+            Map<String, ProBasicWppoint> codeaimap = new HashMap<>();
+            QueryWrapper<ProBasicWppoint> qw = new QueryWrapper<>();
+            qw.eq("windpowerstation_id",i);
+            List<ProBasicWppoint> windpowerstationtestingpoint2List = windpowerstationpointnewService.list(qw);
+            windpowerstationtestingpoint2List.stream().forEach(x->{
+                codeaimap.put(x.getUniformCode(),x);
+            });
+            String s = JSONObject.toJSONString(codeaimap);
+            redisService.set(i,s);
+        });
+
+        log.info("--------------------------redisREGION");
+        List<ProBasicRegion> regs = regionsService.list().stream().filter(i->i.getIsAble().equals(1)).collect(Collectors.toList());
+        List<String> regList = regs.stream().map(i->i.getId()).collect(Collectors.toList());
+        regs.stream().forEach(region -> {
+            regList.add(region.getId()+"0");
+            regList.add(region.getId()+"-1");
+            regList.add(region.getId()+"-2");
+        });
+        regList.stream().forEach(i->{
+            Map<String, ProBasicWppoint> codeaimap = new HashMap<>();
+            QueryWrapper<ProBasicWppoint> qw = new QueryWrapper<>();
+            qw.eq("windpowerstation_id",i);
+            List<ProBasicWppoint> windpowerstationtestingpoint2List = windpowerstationpointnewService.list(qw);
+            windpowerstationtestingpoint2List.stream().forEach(x->{
+                codeaimap.put(x.getUniformCode(),x);
+            });
+            String s = JSONObject.toJSONString(codeaimap);
+            redisService.set(i,s);
+        });
+
+//        log.info("--------------------------redis十三种状态");
+//        Map<String,List<Windturbinestatusdi>> sszztMap = new HashMap<>();
+//        List<Windturbinestatusdi> windturbinestatusdis = windturbinestatusdiService.list();
+//        windturbinestatusdis.stream().forEach(w->{
+//            if (sszztMap.containsKey(w.getWindturbineid())){
+//                sszztMap.get(w.getWindturbineid()).add(w);
+//            }else {
+//                List<Windturbinestatusdi> wdisList = new ArrayList<>();
+//                wdisList.add(w);
+//                sszztMap.put(w.getWindturbineid(),wdisList);
+//            }
+//        });
+//        redisService.set("SSZZT",JSONObject.toJSONString(sszztMap));
+    }
+}

+ 16 - 0
realtime/generationXK-service/src/main/java/com/gyee/generation/service/realtimelibrary/ElectricityMeteringService.java

@@ -0,0 +1,16 @@
+package com.gyee.generation.service.realtimelibrary;
+
+/*
+@author   谢生杰
+@date   2022/11/1-9:38
+*/
+
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class ElectricityMeteringService {
+
+//    public void cal
+
+}

文件差异内容过多而无法显示
+ 0 - 1337
realtime/generationXK-service/src/main/java/com/gyee/generation/util/realtimesource/EdosUtilTd.java


+ 37 - 13
realtime/generationXK-service/src/main/resources/application-dev.yml

@@ -1,5 +1,5 @@
 server:
-  port: 7011
+  port: 7012
   servlet:
     context-path: /
 
@@ -9,13 +9,13 @@ spring:
     allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册
   #redis集群
   redis:
-    host: 10.83.68.94
+    host: 192.168.11.250
     port: 6379
     timeout: 100000
     #    集群环境打开下面注释,单机不需要打开
     #    cluster:
-    #      集群信息
-    #      nodes: xxx.xxx.xxx.xxx:xxxx,xxx.xxx.xxx.xxx:xxxx,xxx.xxx.xxx.xxx:xxxx
+    #      #集群信息
+    #      nodes: 10.83.68.151:6379,10.83.68.152:6379,10.83.68.153:6379,10.83.68.154:6379,10.83.68.155:6379,10.83.68.156:6379,10.83.68.157:6379,10.83.68.158:6379,10.83.68.159:6379
     #      #默认值是5 一般当此值设置过大时,容易报:Too many Cluster redirections
     #      maxRedirects: 3
     password:
@@ -27,16 +27,18 @@ spring:
         min-idle: 0
         max-idle: 8
         max-wait: -1
-    database: 19
+    database: 9
   autoconfigure:
     exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
   datasource:
     type: com.alibaba.druid.pool.DruidDataSource
-    driver-class-name: oracle.jdbc.OracleDriver
-    #外网
-    url: jdbc:oracle:thin:@10.83.68.165:1521:gdsj
-    username: gdprod
-    password: gd123
+    driver-class-name: org.postgresql.Driver
+    #    url: jdbc:postgresql://192.168.11.248:5432/eng_mctl
+    #    username: postgres
+    #    password: postgres
+    url: jdbc:postgresql://192.168.11.248:5432/IMS_NEM
+    username: postgres
+    password: postgres
     oracle-schema=:
     #    type: com.alibaba.druid.pool.DruidDataSource
     #    url: jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&serverTimezone=UTC
@@ -82,12 +84,34 @@ logging:
   level:
     root: info
     com.example: debug
+#db url
+db:
+  url: http://10.81.3.152:8011/ts
+#参与计算的场站
+runWindpowerstation: HN_GDDL_HZJ_GDC_STA,HN_GDDL_MHS_FDC_STA,HN_LYDL_MCH_GDC_STA,HN_LYDL_NSS_FDC_STA
+#计算状态用ai或者di
+clauStatus:
+  ai: GJY03_GC,YLZ01_GC,PTZ02_GC   #配置期次
+  di: GJY01_GC,GJY02_GC,DJY01_GC,DJY02_GC,YF01_GC,YF02_GC,HSM01_GC,PTZ01_GC,ZK01_GC,NJL01_GC,YTY01_GC,PDL01_GC
+#判断数据终端
+second: 1800
+#判断降出力
+AI134: 17.4    #叶轮转速给定
+AI178: 17.4    #转矩给定
+#AI443:容量
+
+#功率曲线拟合
+curvefitting:
+  #维度
+  dimension: 20
+  #尺度
+  scale: 0.01
+shutdown:
+  keystr: test1,test2
+
 
 
-db:
-  url: http://10.83.68.205:8011/ts
 
-runWindpowerstation: CL_FDC,KB_FDC,DX_FDC,SY_FDC
 
 
 

+ 2 - 1
realtime/generationXK-service/src/main/resources/application.yml

@@ -1,5 +1,6 @@
 spring:
   profiles:
-    active: xk
+    active: dev
+#    active: xk
 
 #    active: td

+ 49 - 89
realtime/generationXK-service/src/test/java/com/gyee/generation/GenerationTest.java

@@ -1,89 +1,49 @@
-//package com.gyee.generation;
-//
-//import com.gyee.common.model.PointData;
-//import com.gyee.common.model.algorithm.PointVo;
-//import com.gyee.common.util.algorithm.LineBuild;
-//import com.gyee.generation.init.CacheContext;
-//import com.gyee.generation.model.auto.ProBasicEquipmentPoint;
-//import com.gyee.generation.service.*;
-//import com.gyee.generation.util.realtimesource.EdosUtil;
-//import com.gyee.generation.util.redis.RedisService;
-//import org.junit.Test;
-//import org.junit.runner.RunWith;
-//import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-//import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
-//import org.springframework.boot.test.context.SpringBootTest;
-//import org.springframework.test.context.junit4.SpringRunner;
-//
-//import javax.annotation.Resource;
-//import java.util.*;
-//
-///**
-// * @ClassName : GenerationTest
-// * @Author : xieshengjie
-// * @Date: 2022/3/8 9:17
-// * @Description :
-// */
-//@SpringBootTest
-//@RunWith(SpringRunner.class)
-//@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
-//public class GenerationTest {
-//    @Resource
-//    private GenerationService generationService;
-//    @Resource
-//    private StatusService statusService;
-//    @Resource
-//    private AverageAndGeneratingService averageAndGeneratingService;
-//    @Resource
-//    private RealtimeSpeedPowerService realtimeSpeedPowerService;
-//    @Resource
-//    private TheorypowerService theorypowerService;
-//    @Resource
-//    private EdosUtil edosUtil;
-//    @Resource
-//    private RedisService redisService;
-//    @Resource
-//    private FiveLossesService fiveLossesService;
-//    @Resource
-//    private SafetyService safetyService;
-//    @Test
-//    public void test1() throws Exception {
-////        averageAndGeneratingService.saveAvespeedAndAvepowerAndScada();
-//        statusService.calculateStatus();
-////        realtimeSpeedPowerService.calculateRealtimeSpeedPower();
-////        generationService.saveMeterpointValueRealtime();
-////        theorypowerService.fittingPower();
-////        theorypowerService.theropower();
-////        averageAndGeneratingService.saveAvespeedAndAvepowerAndScada();
-////        fiveLossesService.lossesReal();
-////        fiveLossesService.saveShutdownevent();
-////        safetyService.safetyReatimel();
-////        fiveLossesService.lossesReal();
-//    }
-//
-//
-//    @Test
-//    public void test2() throws Exception {
-//        ProBasicEquipmentPoint windturbinetestingpointnew = CacheContext.wtpAimap.get("GJY01_027").get("AI022");
-//        ProBasicEquipmentPoint windturbinetestingpointnew1 = CacheContext.wtpAimap.get("GJY01_027").get("AI130");
-//        Date date = new Date();
-//
-//        Calendar cal = Calendar.getInstance();
-//        cal.setTime(date);
-//        cal.add(Calendar.MONTH, -1);
-//        Date begin = cal.getTime();
-//
-//        List<PointData> speedpoints = edosUtil.getHistoryDatasSnap(windturbinetestingpointnew, begin.getTime()/1000 , date.getTime()/1000 , null, 3600l);
-//        List<PointData> powerpoints = edosUtil.getHistoryDatasSnap(windturbinetestingpointnew1, begin.getTime()/1000 , date.getTime()/1000 , null, 3600l);
-//        Collections.sort(speedpoints, Comparator.comparing(PointData::getPointValueInDouble));
-//        Collections.sort(powerpoints, Comparator.comparing(PointData::getPointValueInDouble));
-//        double[] speeds = speedpoints.stream().map(i -> i.getPointValueInDouble()).mapToDouble(Double::doubleValue).toArray();
-//        double[] powers = powerpoints.stream().map(i -> i.getPointValueInDouble()).mapToDouble(Double::doubleValue).toArray();
-//
-////        List<PointVo> pointVoList = LineBuild.buildLine(speeds, powers, speeds.length, 20, 0.01);
-//    }
-//
-//    @Test
-//    public void test3() throws Exception {
-//    }
-//}
+package com.gyee.generation;
+
+import com.gyee.common.model.PointData;
+import com.gyee.common.model.algorithm.PointVo;
+import com.gyee.common.util.algorithm.LineBuild;
+import com.gyee.generation.init.CacheContext;
+import com.gyee.generation.model.auto.ProBasicEquipmentPoint;
+import com.gyee.generation.service.*;
+import com.gyee.generation.service.initalcache.CacheService;
+import com.gyee.generation.util.realtimesource.EdosUtil;
+import com.gyee.generation.util.redis.RedisService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+import java.util.*;
+
+/**
+ * @ClassName : GenerationTest
+ * @Author : xieshengjie
+ * @Date: 2022/3/8 9:17
+ * @Description :
+ */
+@SpringBootTest
+@RunWith(SpringRunner.class)
+@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
+public class GenerationTest {
+    @Resource
+    private CacheService cacheService;
+
+    @Test
+    public void test1() throws Exception {
+        cacheService.initRedisCache();
+    }
+
+
+    @Test
+    public void test2() throws Exception {
+
+    }
+
+    @Test
+    public void test3() throws Exception {
+    }
+}