|
@@ -2,12 +2,17 @@ package com.platform.api.manager;
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.platform.api.config.VehicleDataQueue;
|
|
import com.platform.api.config.VehicleDataQueue;
|
|
|
|
|
+import com.platform.api.request.VehicleDataRequest;
|
|
|
import com.platform.api.request.VehicleDataSaveRequest;
|
|
import com.platform.api.request.VehicleDataSaveRequest;
|
|
|
|
|
+import com.platform.api.response.VehicleDataResp;
|
|
|
import com.platform.entity.VehicleData;
|
|
import com.platform.entity.VehicleData;
|
|
|
|
|
+import com.platform.entity.VehicleTimeSeriesData;
|
|
|
import com.platform.enums.ErrorCodeEnum;
|
|
import com.platform.enums.ErrorCodeEnum;
|
|
|
import com.platform.exception.IotException;
|
|
import com.platform.exception.IotException;
|
|
|
|
|
+import com.platform.exception.PageResult;
|
|
|
import com.platform.mapper.TaosMapper;
|
|
import com.platform.mapper.TaosMapper;
|
|
|
import com.platform.service.VehicleDataService;
|
|
import com.platform.service.VehicleDataService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
@@ -59,7 +64,7 @@ public class TransferVehicleManage implements ApplicationContextAware {
|
|
|
// 2. 检查是否达到批量阈值,若达到则批量保存
|
|
// 2. 检查是否达到批量阈值,若达到则批量保存
|
|
|
List<VehicleDataSaveRequest> vehicleDataList = vehicleDataQueue.takeBatchIfReached();
|
|
List<VehicleDataSaveRequest> vehicleDataList = vehicleDataQueue.takeBatchIfReached();
|
|
|
if (CollectionUtils.isEmpty(vehicleDataList)) {
|
|
if (CollectionUtils.isEmpty(vehicleDataList)) {
|
|
|
- return;
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
TransferVehicleManage proxy = applicationContext.getBean(TransferVehicleManage.class);
|
|
TransferVehicleManage proxy = applicationContext.getBean(TransferVehicleManage.class);
|
|
@@ -81,7 +86,7 @@ public class TransferVehicleManage implements ApplicationContextAware {
|
|
|
// 批量保存到时序数据库
|
|
// 批量保存到时序数据库
|
|
|
taosMapper.batchInsertVehicleData(vehicleDataList);
|
|
taosMapper.batchInsertVehicleData(vehicleDataList);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- throw new IotException(ErrorCodeEnum.TD_SAVE_FAIL, "批量保存车辆数据到时序数据库失败");
|
|
|
|
|
|
|
+ throw new IotException(ErrorCodeEnum.TD_SAVE_FAIL, "批量保存车辆数据到时序数据库失败");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -104,8 +109,8 @@ public class TransferVehicleManage implements ApplicationContextAware {
|
|
|
|
|
|
|
|
// 3. 筛选出需要新增的车辆
|
|
// 3. 筛选出需要新增的车辆
|
|
|
return vehicleDataList.stream()
|
|
return vehicleDataList.stream()
|
|
|
- .filter(req -> !existCarNos.contains(req.getVehicleDataVO().getCarNo()))
|
|
|
|
|
- .map(req -> VehicleData.toVehicleData(req.getVehicleDataVO()))
|
|
|
|
|
|
|
+ .filter(ve -> !existCarNos.contains(ve.getVehicleDataVO().getCarNo()))
|
|
|
|
|
+ .map(ve -> VehicleData.toVehicleData(ve.getVehicleDataVO()))
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -122,5 +127,28 @@ public class TransferVehicleManage implements ApplicationContextAware {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 接收单条数据,暂存到队列
|
|
|
|
|
+ */
|
|
|
|
|
+ public PageResult<VehicleDataResp> pageVehicleDataList(VehicleDataRequest request) {
|
|
|
|
|
+ if (request == null || (StringUtils.isEmpty(request.getCarNo())) && StringUtils.isEmpty(request.getWOrderNo())) {
|
|
|
|
|
+ throw new IotException(ErrorCodeEnum.ILLEGAL_PARAM, "接口参数为null!");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ List<VehicleTimeSeriesData> timeSeriesData;
|
|
|
|
|
+ //通过运单号查询车辆信息
|
|
|
|
|
+ if (StringUtils.isNotEmpty(request.getWOrderNo())) {
|
|
|
|
|
+ timeSeriesData = taosMapper.selectByWOrderNo(request.getWOrderNo(),request.getStartTime(), request.getEndTime());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //通过车牌查询车辆信息
|
|
|
|
|
+ String subTableName = "vehicle_data_" + request.getCarNo().trim();
|
|
|
|
|
+ timeSeriesData = taosMapper.selectByCarNo(subTableName, request.getCarNo(),request.getStartTime(), request.getEndTime());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //参数转换
|
|
|
|
|
+ List<VehicleDataResp> vehicleDataRespList = timeSeriesData.stream().map(VehicleDataResp::toIotPageResp)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ return PageResult.of(vehicleDataRespList.size(), request.getPageNum(), request.getPageSize(), vehicleDataRespList);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|