|
|
@@ -37,7 +37,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
-public class TransferVehicleManage implements ApplicationContextAware {
|
|
|
+public class TransferVehicleManage {
|
|
|
|
|
|
@Resource
|
|
|
private TaosService taosService;
|
|
|
@@ -51,12 +51,12 @@ public class TransferVehicleManage implements ApplicationContextAware {
|
|
|
@Resource
|
|
|
private VehicleDataQueue vehicleDataQueue;
|
|
|
|
|
|
- private ApplicationContext applicationContext;
|
|
|
+// private ApplicationContext applicationContext;
|
|
|
|
|
|
- @Override
|
|
|
- public void setApplicationContext(@Nullable ApplicationContext applicationContext) throws BeansException {
|
|
|
- this.applicationContext = applicationContext;
|
|
|
- }
|
|
|
+// @Override
|
|
|
+// public void setApplicationContext(@Nullable ApplicationContext applicationContext) throws BeansException {
|
|
|
+// this.applicationContext = applicationContext;
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 接收单条数据,暂存到队列
|
|
|
@@ -70,40 +70,26 @@ public class TransferVehicleManage implements ApplicationContextAware {
|
|
|
if (CollectionUtils.isEmpty(vehicleDataList)) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- TransferVehicleManage proxy = applicationContext.getBean(TransferVehicleManage.class);
|
|
|
- proxy.batchSaveVehicle(vehicleDataList);
|
|
|
+ batchSaveVehicle(vehicleDataList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 插入车辆数据
|
|
|
*/
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
public void batchSaveVehicle(List<VehicleDataSaveRequest> vehicleDataList) {
|
|
|
- //1. 校验,筛选出需要新增的车辆
|
|
|
+ //mock数据
|
|
|
+ vehicleDataList.stream().forEach(vehicle -> {
|
|
|
+ vehicle.getVehicleDataVO().setCarNo("16939110775088937");
|
|
|
+ vehicle.setwOrderNo("W1709780533650");
|
|
|
+ });
|
|
|
List<VehicleData> newVehicles = checkVehicle(vehicleDataList);
|
|
|
-
|
|
|
- // 2. 记录时序库插入的唯一标识(用于补偿)
|
|
|
- List<String> taosUniqueKeys = Collections.emptyList();
|
|
|
-
|
|
|
- try {
|
|
|
- // 3. 先批量保存到时序数据库
|
|
|
- taosUniqueKeys = taosService.batchInsertVehicleData(vehicleDataList);
|
|
|
-
|
|
|
- // 4、再批量保存到关系库
|
|
|
- saveBatchVehicle(newVehicles);
|
|
|
- } catch (Exception e) {
|
|
|
- // 5. 补偿删除时序库数据
|
|
|
- try {
|
|
|
- if (!taosUniqueKeys.isEmpty()) {
|
|
|
- taosService.batchDelete(taosUniqueKeys);
|
|
|
- log.error("已补偿删除时序库数据,唯一标识:{}", taosUniqueKeys);
|
|
|
- }
|
|
|
- } catch (Exception ex) {
|
|
|
- log.error("补偿删除失败,需人工处理:", ex.getMessage());
|
|
|
- }
|
|
|
- throw new IotException(ErrorCodeEnum.DATA_SAVE_FAIL, "数据保存失败,已触发补偿", e);
|
|
|
+ // 批量保存到关系库
|
|
|
+ if (CollectionUtils.isNotEmpty(newVehicles)) {
|
|
|
+ vehicleDataService.saveBatch(newVehicles);
|
|
|
}
|
|
|
+
|
|
|
+ // 批量保存到时序数据库
|
|
|
+ taosService.batchInsertVehicleData(vehicleDataList);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -121,13 +107,13 @@ public class TransferVehicleManage implements ApplicationContextAware {
|
|
|
* 校验关系数据库中是否存在车辆
|
|
|
*/
|
|
|
private List<VehicleData> checkVehicle(List<VehicleDataSaveRequest> vehicleDataList) {
|
|
|
- //提取所有车牌
|
|
|
+ //提取所有车辆id
|
|
|
List<String> carNoList = vehicleDataList.stream()
|
|
|
.map(ve -> ve.getVehicleDataVO().getCarNo())
|
|
|
.distinct()
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
- // 2. 批量查询已存在的车牌
|
|
|
+ // 2. 批量查询已存在的车辆id
|
|
|
List<String> existCarNos = vehicleDataService.list(Wrappers.<VehicleData>lambdaQuery()
|
|
|
.in(VehicleData::getCarNo, carNoList))
|
|
|
.stream()
|
|
|
@@ -135,7 +121,6 @@ public class TransferVehicleManage implements ApplicationContextAware {
|
|
|
.collect(Collectors.toList());
|
|
|
log.info("查询关系数据库中已存在的车牌,结果:{}", existCarNos);
|
|
|
|
|
|
-
|
|
|
// 3. 筛选出需要新增的车辆
|
|
|
return vehicleDataList.stream()
|
|
|
.filter(ve -> !existCarNos.contains(ve.getVehicleDataVO().getCarNo()))
|
|
|
@@ -159,6 +144,8 @@ public class TransferVehicleManage implements ApplicationContextAware {
|
|
|
* 接收单条数据,暂存到队列
|
|
|
*/
|
|
|
public List<VehicleDataResp> queryVehicleDataList(VehicleDataRequest request) {
|
|
|
+ //mock数据
|
|
|
+ request.setwOrderNo("W1709780533650");
|
|
|
if (request == null || (StringUtils.isEmpty(request.getCarNo()) && StringUtils.isEmpty(request.getwOrderNo()))) {
|
|
|
throw new IotException(ErrorCodeEnum.ILLEGAL_PARAM, "接口参数为null!");
|
|
|
}
|
|
|
@@ -188,6 +175,8 @@ public class TransferVehicleManage implements ApplicationContextAware {
|
|
|
* 通过车牌查询实时经纬度
|
|
|
*/
|
|
|
public VehicleDataResp queryRealTimeLocation(VehicleDataRequest request) {
|
|
|
+ //mock数据
|
|
|
+ request.setCarNo("16939110775088937");
|
|
|
if (request == null || (StringUtils.isEmpty(request.getCarNo()))) {
|
|
|
throw new IotException(ErrorCodeEnum.ILLEGAL_PARAM, "车牌carNo不能为空!");
|
|
|
}
|