Browse Source

null问题

xushili 6 months ago
parent
commit
38a26332a0

+ 10 - 1
data-adapter/src/main/java/com/gyee/dataadapter/dao_mqtt_influxdb_taos/TaosDataService.java

@@ -1,5 +1,7 @@
 package com.gyee.dataadapter.dao_mqtt_influxdb_taos;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
 import com.gyee.dataadapter.dao.IHistoryDao;
 import com.gyee.dataadapter.entity.PointData;
 import org.springframework.stereotype.Service;
@@ -20,6 +22,7 @@ public class TaosDataService implements IHistoryDao {
     @Override
     public Map<String, PointData> getLatest(List<String> tagNames) throws Exception {
         Map<String, PointData> tsDataMap = new HashMap<>();
+        if(CollUtil.isEmpty(tagNames)) return tsDataMap;
         Statement st = config.getInstance().createStatement();
         String collect = tagNames.stream().map(s -> "'" + s.toLowerCase() + "'").collect(Collectors.joining(","));
         StringBuilder sql = new StringBuilder();
@@ -35,6 +38,7 @@ public class TaosDataService implements IHistoryDao {
     @Override
     public List<PointData> getHistoryRaw(String tagName, Date startTime, Date endTime) throws Exception {
         List<PointData> tsDataList = new ArrayList<>();
+        if(StrUtil.isBlank(tagName)) return tsDataList;
         Statement st = config.getInstance().createStatement();
         String sql = getHistoryRawSql(tagName, startTime.getTime(), endTime.getTime());
         ResultSet rs = st.executeQuery(sql);
@@ -62,6 +66,7 @@ public class TaosDataService implements IHistoryDao {
     @Override
     public List<PointData> getHistorySnap(String tagName, Date startTime, Date endTime, Integer interval) throws Exception {
         List<PointData> tsDataList = new ArrayList<>();
+        if(StrUtil.isBlank(tagName)) return tsDataList;
         Statement st = config.getInstance().createStatement();
         String sql = getHistorySnapSql(tagName, startTime.getTime(), endTime.getTime(), interval);
         ResultSet rs = st.executeQuery(sql);
@@ -74,6 +79,7 @@ public class TaosDataService implements IHistoryDao {
     @Override
     public List<PointData> getHistoryStat(String tagName, Date startTime, Date endTime, Integer interval, Integer type) throws Exception {
         List<PointData> result = new ArrayList<>();
+        if(StrUtil.isBlank(tagName)) return result;
         Statement st = config.getInstance().createStatement();
         StringBuilder sb = new StringBuilder();
         if (type == 2) {
@@ -95,6 +101,8 @@ public class TaosDataService implements IHistoryDao {
 
     @Override
     public PointData getHistoryStat0(String tagName, Date startTime, Date endTime, Integer type) throws Exception {
+        PointData pd = new PointData(endTime, 0);
+        if(StrUtil.isBlank(tagName)) return pd;
         Statement st = config.getInstance().createStatement();
         StringBuilder sb = new StringBuilder();
         if (type == 2) {
@@ -110,12 +118,13 @@ public class TaosDataService implements IHistoryDao {
         while (rs.next()) {
             return new PointData(endTime, rs.getDouble(1));
         }
-        return new PointData(endTime, 0);
+        return pd;
     }
 
     @Override
     public Map<String, PointData> getHistorySection(Date ts, List<String> tagNames) throws Exception {
         Map<String, PointData> tsDataMap = new HashMap<>();
+        if(CollUtil.isEmpty(tagNames)) return tsDataMap;
         Statement st = config.getInstance().createStatement();
         String collect = tagNames.stream().map(s -> "'" + s.toLowerCase() + "'").collect(Collectors.joining(","));
         StringBuilder sql = new StringBuilder();

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

@@ -1,5 +1,6 @@
 package com.gyee.dataadapter.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
@@ -123,9 +124,7 @@ public class AdapterServiceImpl implements IAdapterService {
     @Override
     public Map<String, PointInfo> getLatestData(String paths) {
         Map<String, PointInfo> map = new HashMap<>();
-        if (null == paths || paths.isEmpty()) {
-            return map;
-        }
+        if (StrUtil.isBlank(paths)) return map;
         String[] split = paths.split(",");
         for (String s : split) {
             PointInfo pintInfo = MqttCache.subData.get(s);
@@ -143,7 +142,7 @@ public class AdapterServiceImpl implements IAdapterService {
     @Override
     public Map<String, PointData> getLatestData2(List<String> tagNames) {
         Map<String, PointData> map = new HashMap<>();
-        if (tagNames == null||tagNames.isEmpty()) return map;
+        if (CollUtil.isEmpty(tagNames)) return map;
         for (String path : tagNames) {
             PointData pd = MqttCache.subData2.get(path);
             map.put(path, pd);