Procházet zdrojové kódy

查询实时经纬度接口,优化查询不存在的子表

donglang před 2 měsíci
rodič
revize
7cfcb1132d

+ 10 - 1
iot-platform-manager/src/main/java/com/platform/api/manager/TransferVehicleManage.java

@@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeansException;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
+import org.springframework.jdbc.UncategorizedSQLException;
 import org.springframework.lang.Nullable;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
@@ -104,7 +105,7 @@ public class TransferVehicleManage implements ApplicationContextAware {
                 .stream()
                 .map(VehicleData::getCarNo)
                 .collect(Collectors.toList());
-        log.info("查询关系数据库中已存在的车牌,结果:{}",existCarNos);
+        log.info("查询关系数据库中已存在的车牌,结果:{}", existCarNos);
 
 
         // 3. 筛选出需要新增的车辆
@@ -162,6 +163,14 @@ public class TransferVehicleManage implements ApplicationContextAware {
         if (request == null || (StringUtils.isEmpty(request.getCarNo()))) {
             throw new IotException(ErrorCodeEnum.ILLEGAL_PARAM, "车牌carNo不能为空!");
         }
+
+        // 查询车辆id关系数据中是否存在
+        VehicleData vehicleData = vehicleDataService.getOne(Wrappers.<VehicleData>lambdaQuery().eq(VehicleData::getCarNo, request.getCarNo()));
+        if (vehicleData == null) {
+            log.info("子表 {} 不存在,返回空结果", "vehicle_data_" + request.getCarNo().trim());
+            return new VehicleDataResp();
+        }
+
         String subTableName = "vehicle_data_" + request.getCarNo().trim();
         VehicleTimeSeriesData realTimeLocation = taosService.selectRealTimeLocation(subTableName, request.getCarNo());
 

+ 5 - 5
iot-platform-manager/src/main/java/com/platform/api/response/VehicleDataResp.java

@@ -99,11 +99,11 @@ public class VehicleDataResp {
         devicePageResp.setFuelLevel(seriesData.getFuelLevel());
         devicePageResp.setMileage(seriesData.getMileage());
         devicePageResp.setEngineTemp(seriesData.getEngineTemp());
-        devicePageResp.setBatteryVoltage(getInstance().getBatteryVoltage());
-        devicePageResp.setStatus(getInstance().getStatus());
-        devicePageResp.setWOrderNo(getInstance().getWOrderNo());
-        devicePageResp.setAlarmCode(getInstance().getAlarmCode());
-        devicePageResp.setCarNo(getInstance().getCarNo());
+        devicePageResp.setBatteryVoltage(seriesData.getBatteryVoltage());
+        devicePageResp.setStatus(seriesData.getStatus());
+        devicePageResp.setWOrderNo(seriesData.getWOrderNo());
+        devicePageResp.setAlarmCode(seriesData.getAlarmCode());
+        devicePageResp.setCarNo(seriesData.getCarNo());
         return devicePageResp;
     }
 }

+ 1 - 1
iot-platform-manager/src/main/resources/mapper/TaosMapper.xml

@@ -115,7 +115,7 @@
         SELECT
             longitude,
             latitude,
-            ts AS latestTs,
+            ts,
             '${carNo}' AS carNo
         FROM ${subTableName}
         ORDER BY ts DESC