xushili 2 дней назад
Родитель
Сommit
e69cfe25e7

+ 39 - 2
dao/dao-simulator/src/main/java/com/gyee/wisdom/dao/simulator/SimulatorHistoryDao.java

@@ -8,9 +8,12 @@ import com.gyee.wisdom.dao.timeseries.SimulatorDao;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Random;
 
 @Component
 @SimulatorDao
@@ -19,15 +22,49 @@ public class SimulatorHistoryDao implements IHistoryDao {
 
 
     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);
+        }
         return null;
     }
 
     public List<TsData> getDoubleTsDataHistory(TsQuery tsQuery) throws Exception {
-        return null;
+        List<TsData> tsDataList = new ArrayList<>();
+        long start = tsQuery.getStartTs();
+        long end = tsQuery.getEndTs();
+        int pointCount = 100; // 模拟数据点数量
+
+        // 生成等间隔时间戳的模拟数据
+        long interval = (end - start) / pointCount;
+        for (int i = 0; i < pointCount; i++) {
+            long timestamp = start + i * interval;
+            // 生成正弦波模拟数据(范围0-100)
+            double value = 50 + 50 * Math.sin(2 * Math.PI * i / pointCount);
+            tsDataList.add(new DoubleTsData(timestamp, (short) 0, value));
+        }
+
+        return tsDataList;
     }
 
     public List<TsData> getBooleanTsDataHistory(TsQuery tsQuery) throws Exception {
-        return null;
+        List<TsData> tsDataList = new ArrayList<>();
+        long start = tsQuery.getStartTs();
+        long end = tsQuery.getEndTs();
+        int pointCount = 100; // 模拟数据点数量
+
+        // 生成等间隔时间戳的模拟数据
+        long interval = (end - start) / pointCount;
+        Random random = new Random();
+        for (int i = 0; i < pointCount; i++) {
+            long timestamp = start + i * interval;
+            // 随机生成布尔值(约70% true,30% false)
+            boolean value = random.nextDouble() > 0.3;
+            tsDataList.add(new BooleanTsData(timestamp, (short) 0, value));
+        }
+
+        return tsDataList;
     }