Selaa lähdekoodia

Merge remote-tracking branch 'origin/master'

malijun 1 vuosi sitten
vanhempi
commit
e115ebf903

+ 7 - 6
state/wind/src/main/java/com/gyee/gaia/electricity/wind/service/Status8Service.java

@@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -71,7 +72,7 @@ public class Status8Service {
         //TODO 风机的8中原始状态
         String[] zttsUniformCodes = status8Properties.getZttsUniformCodes();
         QueryWrapper<TestingPoint> tpwrapper = new QueryWrapper<>();
-        tpwrapper.eq("station_id", stationId).in("uniform_code", zttsUniformCodes);
+        tpwrapper.eq("station_id", stationId).in("uniform_code", Arrays.asList(zttsUniformCodes));
         List<TestingPoint> list = testingPointService.list(tpwrapper);
         //List<TsPoint> pointList = sqlService.getTsPointByUniformCodes("station", stationId, zttsUniformCodes);
         for (TestingPoint tsPoint : list) {
@@ -98,8 +99,8 @@ public class Status8Service {
         Map<String, TagInfo> fjztMap = new HashMap<>();
         String fjztUniformCode = status8Properties.getFjztUniformCode();
         tpwrapper.clear();
-        tpwrapper.eq("thing_type", "windturbine").eq("uniform_code", fjztUniformCode)
-                .in("thing_id", wtIds);
+        tpwrapper.eq("thing_type", "windturbine").eq("uniform_code", Arrays.asList(fjztUniformCode))
+                .in("thing_id", Arrays.asList(wtIds));
         List<TestingPoint> tplist2 = testingPointService.list(tpwrapper);
         //List<TsPoint> pointList2 = sqlService.getTsPointByThingIds("windturbine", fjztUniformCode, wtIds);
         for (TestingPoint tsPoint : tplist2) {
@@ -117,8 +118,8 @@ public class Status8Service {
         Map<String, TagInfo> gzztMap = new HashMap<>();
         String gzztUniformCode = status8Properties.getGzztUniformCode();
         tpwrapper.clear();
-        tpwrapper.eq("thing_type", "windturbine").eq("uniform_code", fjztUniformCode)
-                .in("thing_id", wtIds);
+        tpwrapper.eq("thing_type", "windturbine").eq("uniform_code", Arrays.asList(fjztUniformCode))
+                .in("thing_id", Arrays.asList(wtIds));
         List<TestingPoint> tplist3 = testingPointService.list(tpwrapper);
         //List<TsPoint> pointList3 = sqlService.getTsPointByThingIds("windturbine", gzztUniformCode, wtIds);
         for (TestingPoint tsPoint : tplist3) {
@@ -172,7 +173,7 @@ public class Status8Service {
         log.info("加载风机测点, 风机号:" + wtInfo.getId());
         QueryWrapper<TestingPoint> tpwrapper = new QueryWrapper<>();
         tpwrapper.eq("thing_type", "windturbine").eq("thing_id", wtInfo.getId())
-                .in("uniform_code", strArr);
+                .in("uniform_code", Arrays.asList(strArr));
         List<TestingPoint> list = testingPointService.list(tpwrapper);
 
         //List<TsPoint> tsPointList = sqlService.getTsPointByUniformCodes("windturbine", wtInfo.getId(), strArr);

+ 132 - 14
timeseries/dao-simulator/src/main/java/com/gyee/gaia/dao/simulator/SimulatorHistoryDao.java

@@ -1,44 +1,162 @@
 package com.gyee.gaia.dao.simulator;
 
 import com.gyee.gaia.common.data.timeseries.*;
+import com.gyee.gaia.common.exception.WisdomException;
 import com.gyee.gaia.dao.timeseries.IHistoryDao;
 import com.gyee.gaia.dao.timeseries.SimulatorDao;
 import org.springframework.stereotype.Component;
 
-import java.util.List;
-import java.util.Map;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Blob;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.*;
+import java.util.concurrent.Future;
+import java.util.stream.Collectors;
 
 @Component
 @SimulatorDao
 public class SimulatorHistoryDao implements IHistoryDao {
 
-
+    private final Random random = new Random();
+    @Override
     public List<TsData> getTsDataHistory(TsQuery tsQuery) throws Exception {
+        if (tsQuery.getTsPoint().getTsDataType() == TsDataType.DOUBLE) {
+            return getDoubleTsDataHistory(tsQuery);
+        } else if (tsQuery.getTsPoint().getTsDataType() == TsDataType.BOOLEAN) {
+            return getBooleanTsDataHistory(tsQuery);
+        } else if (tsQuery.getTsPoint().getTsDataType() == TsDataType.LONG) {
+            return getLongTsDataHistory(tsQuery);
+        }
         return null;
     }
 
-    public List<TsData> getDoubleTsDataHistory(TsQuery tsQuery) throws Exception {
-        return null;
-    }
+    @Override
+    public List<DoubleStatData> getDoubleStatDataHistory(TsQuery tsQuery) throws Exception {
+        if (tsQuery.getTsPoint().getTsDataType() != TsDataType.DOUBLE) {
+            throw new WisdomException("无效的数据类型:" + tsQuery.getTsPoint().getTsDataType());
+        }
 
-    public List<TsData> getBooleanTsDataHistory(TsQuery tsQuery) throws Exception {
-        return null;
-    }
+        List<DoubleStatData> result = new ArrayList<>();
 
+        double v1 = generateRandomDouble(0.0, 1000.0);
+        double v2 = generateRandomDouble(0.0, 1000.0);
 
-    @Override
-    public List<DoubleStatData> getDoubleStatDataHistory(TsQuery tsQuery) throws Exception {
-        return null;
+        DoubleTsData maxData;
+        DoubleTsData minData;
+        if(v1>=v2){
+            maxData = new DoubleTsData(tsQuery.getStartTs(), (short) 1, v1);
+            minData = new DoubleTsData(tsQuery.getStartTs(), (short) 1, v2);
+        }else {
+            maxData = new DoubleTsData(tsQuery.getStartTs(), (short) 1, v2);
+            minData = new DoubleTsData(tsQuery.getStartTs(), (short) 1, v1);
+        }
+        DoubleTsData avgData = new DoubleTsData(tsQuery.getStartTs(), (short) 1, (v1+v2)/2);
+        DoubleStatData statData = new DoubleStatData(avgData, maxData, minData);
+        result.add(statData);
+
+        return result;
     }
 
     @Override
     public boolean writeHistoryValue(List<TsPointData> dataList) throws Exception {
-        return false;
+        return true;
     }
 
     @Override
     public Map<String, TsData> getHistorySection(List<TsPoint> tsPoints, Long ts) throws Exception {
-        return null;
+        Map<String, TsData> results = new LinkedHashMap<>();
+
+        Map<TsDataType, List<TsPoint>> pointGroup = tsPoints.stream().collect(Collectors.groupingBy(TsPoint::getTsDataType));
+        for (Map.Entry<TsDataType, List<TsPoint>> entry : pointGroup.entrySet()) {
+            String[] tagNames = entry.getValue().stream().map(TsPoint::getId).toArray(String[]::new);
+            if (entry.getKey() == TsDataType.DOUBLE)
+                for (String tag : tagNames) {
+                    results.put(tag,new DoubleTsData(ts, (short) 0, generateRandomDouble(0.0, 1000.0)));
+                }
+            if (entry.getKey() == TsDataType.BOOLEAN) {
+                for (String tag : tagNames) {
+                    results.put(tag,new BooleanTsData(ts, (short) 0, random.nextBoolean()));
+                }
+            }
+        }
+
+        return results;
     }
 
+    public List<TsData> getDoubleTsDataHistory(TsQuery tsQuery) throws Exception {
+        List<TsData> tsDataList = new ArrayList<>();
+
+        List<Long> timestampList = generateTimestampList(tsQuery.getStartTs(), tsQuery.getEndTs(), tsQuery.getInterval()*1000L);
+
+        for (Long aLong : timestampList) {
+            tsDataList.add(new DoubleTsData(aLong, (short) 0, generateRandomDouble(0.0, 1000.0)));
+        }
+
+        return tsDataList;
+    }
+
+
+    public List<TsData> getLongTsDataHistory(TsQuery tsQuery) throws Exception {
+        List<TsData> tsDataList = new ArrayList<>();
+
+        List<Long> timestampList = generateTimestampList(tsQuery.getStartTs(), tsQuery.getEndTs(), tsQuery.getInterval()*1000L);
+
+        for (Long aLong : timestampList) {
+            tsDataList.add(new LongTsData(aLong, (short) 0, generateRandomInt(0, 100000)));
+        }
+
+        return tsDataList;
+    }
+
+    public List<TsData> getBooleanTsDataHistory(TsQuery tsQuery) throws Exception {
+        List<TsData> tsDataList = new ArrayList<>();
+
+        List<Long> timestampList = generateTimestampList(tsQuery.getStartTs(), tsQuery.getEndTs(), tsQuery.getInterval()*1000L);
+
+        for (Long aLong : timestampList) {
+            tsDataList.add(new BooleanTsData(aLong, (short) 0, random.nextBoolean()));
+        }
+
+        return tsDataList;
+    }
+
+    /**
+     * 根据指定的开始时间戳、结束时间戳和数量生成随机的时间戳列表
+     *
+     * @param startTs 开始时间戳
+     * @param endTs   结束时间戳
+     * @param num     时间戳列表数量
+     * @return 随机的时间戳列表
+     */
+    public static List<Long> generateTimestampList(long startTs, long endTs, long num) {
+        List<Long> list = new ArrayList<>();
+        for (long timestamp = startTs; timestamp <= endTs; timestamp += num) {
+            list.add(timestamp);
+        }
+        return list;
+    }
+
+    /**
+     * 生成指定范围内的随机数
+     *
+     * @param min 随机数的最小值
+     * @param max 随机数的最大值
+     * @return 在指定范围内的随机数
+     */
+    public double generateRandomDouble(double min, double max) {
+        return min + (max - min) * random.nextDouble();
+    }
+    /**
+     * 生成指定范围内的随机整数
+     *
+     * @param min 随机数的最小值
+     * @param max 随机数的最大值
+     * @return 在指定范围内的随机整数
+     */
+    public int generateRandomInt(int min, int max) {
+        return random.nextInt(max - min + 1) + min;
+    }
 }