fx239 6 days ago
parent
commit
5758957652

+ 1 - 1
data-adapter/pom.xml

@@ -9,7 +9,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.gyee</groupId>
     <artifactId>data-adapter</artifactId>
-    <version>1.0.0-SNAPSHOT</version>
+<!--    <version>1.0.0-SNAPSHOT</version>-->
     <name>data-adapter</name>
     <description>data-adapter</description>
     <properties>

+ 0 - 4
data-adapter/src/main/java/com/gyee/dataadapter/controller/AdapterController.java

@@ -45,10 +45,6 @@ public class AdapterController {
     }
 
     @PostMapping("/latest")
-    public Map<String, PointData> getLatest(@RequestBody List<String> keys) {
-        return tsDataService.getLatest(keys);
-    }
-    @PostMapping("/latestp")
     public Map<String, PointData> getLatestp(@RequestBody String keys) {
         return tsDataService.getLatest(keys);
     }

+ 8 - 4
data-adapter/src/main/java/com/gyee/dataadapter/dao_mqtt_influxdb_taos/TaosDataService.java

@@ -154,12 +154,16 @@ public class TaosDataService implements IHistoryDao {
         Statement st = config.getInstance().createStatement();
         String collect = tagNames.stream().map(s -> "'" + s.toLowerCase() + "'").collect(Collectors.joining(","));
         StringBuilder sql = new StringBuilder();
-        sql.append("select interp(val,1),tbname from ").append(config.getDbName()).append(".")
-                .append(config.getAIStableName()).append(" where tbname in (").append(collect)
-                .append(") partition by tbname range(").append(ts.getTime()).append(") fill(prev)");
+//        sql.append("select interp(val,1),tbname from ").append(config.getDbName()).append(".")
+//                .append(config.getAIStableName()).append(" where tbname in (").append(collect)
+//                .append(") partition by tbname range(").append(ts.getTime()).append(") fill(prev)");
+        sql.append("select last_row(*),tbname from ").append(config.getDbName()).append(".")
+                .append(config.getAIStableName()).append(" where ts <= ").append(ts.getTime())
+                .append(" and tbname in (").append(collect).append(") group by tbname");
+
         ResultSet rs = st.executeQuery(sql.toString());
         while (rs.next()) {
-            tsDataMap.put(rs.getString(2).toUpperCase(), new PointData(ts, rs.getDouble(1)));
+            tsDataMap.put(rs.getString(3).toUpperCase(), new PointData(rs.getDate(1), rs.getDouble(2)));
         }
         return tsDataMap;
     }

+ 10 - 8
data-adapter/src/main/java/com/gyee/dataadapter/entity/PointData.java

@@ -1,7 +1,6 @@
 package com.gyee.dataadapter.entity;
 
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.*;
 import com.gyee.dataadapter.dao.TsDataType;
 
 import java.util.Date;
@@ -14,20 +13,23 @@ public class PointData {
      * 时间戳
      */
     private long ts;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private Date time;
-    //@JsonInclude(JsonInclude.Include.NON_NULL)
     private String tagName;
     /**
      * 数据
      */
     @JsonInclude(JsonInclude.Include.NON_NULL)
+//    @JsonSetter(nulls = Nulls.SKIP)
     private Double doubleValue;
     /**
      * Boolean 数据
      */
     @JsonInclude(JsonInclude.Include.NON_NULL)
+//    @JsonSetter(nulls = Nulls.SKIP)
     private Boolean booleanValue;
     @JsonInclude(JsonInclude.Include.NON_NULL)
+//    @JsonSetter(nulls = Nulls.SKIP)
     private Long longValue;
 
     public PointData() {
@@ -51,9 +53,9 @@ public class PointData {
 
     @JsonIgnore
     public TsDataType getDataType() {
-        if (booleanValue != null) {
+        if (booleanValue != null && booleanValue) {
             return TsDataType.BOOLEAN;
-        } else if (longValue != null) {
+        } else if (longValue != null && longValue != 0) {
             return TsDataType.LONG;
         }
         return TsDataType.DOUBLE;
@@ -105,9 +107,9 @@ public class PointData {
 
     @JsonIgnore
     public Double getValue() {
-        if (booleanValue != null) {
-            return booleanValue ? 1.0 : 0.0;
-        } else if (longValue != null) {
+        if (booleanValue != null && booleanValue) {
+            return 1.0;
+        } else if (longValue != null && longValue != 0) {
             doubleValue = Double.valueOf(longValue);
         }
         return doubleValue;

+ 3 - 2
data-adapter/src/main/java/com/gyee/dataadapter/service/TsDataService.java

@@ -32,8 +32,9 @@ public class TsDataService {
     }
 
     public Map<String, PointData> getLatest(List<String> tagNames) {
+        Map<String, PointData> latest = new HashMap<>();
+        if(CollUtil.isEmpty(tagNames)) return latest;
         Map<Boolean, List<String>> nxFgs = tagNames.stream().collect(Collectors.groupingBy(tn -> tn.startsWith("NX_FGS_")));
-        Map<String, PointData> latest = null;
         try {
             latest = historyDao.getLatest(nxFgs.get(true));
         } catch (Exception e) {
@@ -151,7 +152,7 @@ public class TsDataService {
         Map<String, PointData> result = new HashMap<>();
         if(StrUtil.isBlank(tagNames)) return result;
         Map<Boolean, List<String>> nxFgs = Arrays.stream(tagNames.split(",")).collect(
-                Collectors.groupingBy(tn -> tn.startsWith("NX_FGS_")));
+                Collectors.groupingBy(tn -> tn.toUpperCase().startsWith("NX_FGS_")));
         try {
             Map<String, PointData> latest = historyDao.getHistorySection(time, nxFgs.get(true));
             result.putAll(latest);

+ 2 - 2
data-adapter/src/main/java/com/gyee/dataadapter/service/impl/AdapterServiceImpl.java

@@ -61,8 +61,8 @@ public class AdapterServiceImpl implements IAdapterService {
 
     @Override
     public TotalPointData getTotalData(Date start, Date end, Integer sampleType, Integer sampleRate, String paths, String pageIndex, String pageSize, Boolean isDesc) {
-        start = DateUtil.offsetHour(start, -8);
-        end = DateUtil.offsetHour(end, -8);
+//        start = DateUtil.offsetHour(start, -8);
+//        end = DateUtil.offsetHour(end, -8);
 
         String uStart = DateUtil.formatDateTime(start);
         String uEnd = DateUtil.formatDateTime(end);