From f67945d53b20f6a45ae50b27d74c966eb1355bb4 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期日, 16 十一月 2025 22:53:54 +0800
Subject: [PATCH] feat: 增加分段GPS计算行程距离
---
ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/GpsSyncTask.java | 100 ++++++++-----------------------------------------
1 files changed, 17 insertions(+), 83 deletions(-)
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/GpsSyncTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/GpsSyncTask.java
index 70b8789..ac0f9f2 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/GpsSyncTask.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/GpsSyncTask.java
@@ -3,16 +3,13 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
+import java.util.stream.Collectors;
-import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import com.ruoyi.system.domain.GpsDevice;
-import com.ruoyi.system.domain.GpsDeviceListResponse;
-import com.ruoyi.system.domain.GpsGroup;
import com.ruoyi.system.domain.GpsLastPosition;
import com.ruoyi.system.domain.GpsLastPositionRequest;
import com.ruoyi.system.domain.GpsLastPositionResponse;
@@ -40,33 +37,31 @@
private IVehicleGpsService vehicleGpsService;
/**
- * 鍚屾璁惧鍒楄〃鍜孏PS浣嶇疆
+ * 鍚屾GPS浣嶇疆
*/
public void syncGpsData() {
try {
log.info("寮�濮嬪悓姝PS鏁版嵁...");
- // 1. 鑾峰彇璁惧鍒楄〃锛岃繖浼氳嚜鍔ㄦ洿鏂拌溅杈嗕俊鎭腑鐨勮澶嘔D
- GpsDeviceListResponse response = gpsCollectService.getDeviceList();
- // 鏇存柊杞﹁締璁惧ID
- updateVehicleDeviceIds(response);
-
- // 2. 鑾峰彇鎵�鏈夎溅杈嗕俊鎭�
+ // 1. 鑾峰彇鎵�鏈夎溅杈嗕俊鎭�
List<VehicleInfo> vehicleList = vehicleInfoService.selectVehicleInfoList(new VehicleInfo());
- //鍦ㄨ繖閲岃幏寰楁墍鏈夎溅杈嗙殑GPS鏈�鍚庝綅缃�
- GpsLastPositionResponse gpsLastPositionResponse = gpsCollectService.getLastPosition(new GpsLastPositionRequest());
+ List<String> deviceIds = vehicleList.stream().map(VehicleInfo::getDeviceId).collect(Collectors.toList());
+ // 2. 鑾峰彇鎵�鏈夎溅杈嗙殑GPS鏈�鍚庝綅缃�
+ GpsLastPositionRequest request = new GpsLastPositionRequest();
+// request.setDeviceids(deviceIds);
+ GpsLastPositionResponse gpsLastPositionResponse = gpsCollectService.getLastPosition(request);
// 3. 閬嶅巻杞﹁締鍒楄〃锛岃幏鍙栨瘡涓溅杈嗙殑GPS浣嶇疆
for (VehicleInfo vehicle : vehicleList) {
if (vehicle.getDeviceId() != null && !vehicle.getDeviceId().isEmpty()) {
try {
// 鑾峰彇杞﹁締鐨勬渶鍚庝綅缃�
- gpsLastPositionResponse.getRecords().stream().filter(e->e.getDeviceid().equals(vehicle.getDeviceId())).forEach(record -> {
+ gpsLastPositionResponse.getRecords().stream()
+ .filter(e -> e.getDeviceid().equals(vehicle.getDeviceId()))
+ .forEach(record -> {
updateVehicleGpsPositions(vehicle, record);
-
- });
-
+ });
} catch (Exception e) {
log.error("鑾峰彇杞﹁締[{}]GPS浣嶇疆澶辫触: {}", vehicle.getVehicleNo(), e.getMessage());
}
@@ -77,57 +72,6 @@
} catch (Exception e) {
log.error("GPS鏁版嵁鍚屾澶辫触: {}", e.getMessage());
}
- }
-
- /**
- * 鏇存柊杞﹁締璁惧ID
- */
- private void updateVehicleDeviceIds(GpsDeviceListResponse response) {
- if (response.getStatus() != 0 || response.getGroups() == null) {
- return;
- }
-
- for (GpsGroup group : response.getGroups()) {
- for (GpsDevice device : group.getDevices()) {
- String deviceName = device.getDevicename();
- String remark = device.getRemark();
- String deviceId = device.getDeviceid();
-
- if (StringUtils.isNotEmpty(deviceName) || StringUtils.isNotEmpty(remark)) {
- String plateNumber = extractPlateNumber(deviceName, remark);
- if (StringUtils.isNotEmpty(plateNumber)) {
- VehicleInfo vehicleInfo = vehicleInfoService.selectVehicleInfoByPlateNumber(plateNumber);
- if (vehicleInfo != null) {
- vehicleInfo.setDeviceId(deviceId);
- //鑾峰緱鏁版嵁瀛楀吀涓殑骞冲彴缂栫爜
-
- vehicleInfo.setPlatformCode("GPS51");
- vehicleInfoService.updateVehicleInfo(vehicleInfo);
- } else {
- VehicleInfo newVehicle = new VehicleInfo();
- newVehicle.setVehicleNo(plateNumber);
- newVehicle.setDeviceId(deviceId);
- newVehicle.setStatus("0");
- newVehicle.setPlatformCode("GPS51");
- vehicleInfoService.insertVehicleInfo(newVehicle);
- }
- }
- }
- }
- }
- }
-
- /**
- * 浠庤澶囧悕绉板拰澶囨敞涓彁鍙栬溅鐗屽彿
- */
- private String extractPlateNumber(String deviceName, String remark) {
- if (StringUtils.isNotEmpty(deviceName)) {
- return deviceName;
- }
- if (StringUtils.isNotEmpty(remark)) {
- return remark;
- }
- return null;
}
/**
@@ -144,19 +88,15 @@
gps.setSpeed(position.getSpeed());
gps.setDirection(Double.valueOf(position.getCourse()));
- //devicetime 杩欎釜鏄竴涓猯inux鏃堕棿鎴筹紝瑕佽浆鎹㈡垚鍖椾含鏃堕棿锛屽啀杞垚yyyy-MM-dd HH:mm:ss鏍煎紡
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- //getArrivedtime 杩欎釜鏄竴涓猯inux鏃堕棿鎴筹紝瑕佽浆鎹㈡垚鍖椾含鏃堕棿锛屽啀杞垚yyyy-MM-dd HH:mm:ss鏍煎紡
+ // 澶勭悊鍒拌揪鏃堕棿
long arrivedTime = position.getArrivedtime();
Date arrivedDate;
- // 妫�鏌ユ椂闂存埑鏄惁鏈夋晥锛堝ぇ浜�0锛�
if (arrivedTime > 0) {
arrivedDate = new Date(arrivedTime);
- // 鍑忓幓8灏忔椂
arrivedDate.setTime(arrivedDate.getTime() - 8 * 60 * 60 * 1000);
} else {
- // 鏃堕棿鎴虫棤鏁堬紝浣跨敤褰撳墠鏃堕棿
arrivedDate = new Date();
}
gps.setPlatformProcessTime(sdf.format(arrivedDate));
@@ -164,31 +104,25 @@
// 璁惧涓婃姤鏃堕棿
long deviceTime = position.getDevicetime();
Date date;
- // 妫�鏌ユ椂闂存埑鏄惁鏈夋晥锛堝ぇ浜�0锛�
if (deviceTime > 0) {
date = new Date(deviceTime);
- // 鍑忓幓8灏忔椂
date.setTime(date.getTime() - 8 * 60 * 60 * 1000);
} else {
- // 鏃堕棿鎴虫棤鏁堬紝浣跨敤褰撳墠鏃堕棿
date = arrivedDate;
}
gps.setDeviceReportTime(sdf.format(date));
-
-
// 閲囬泦鏃堕棿锛堜娇鐢ㄨ澶囦笂鎶ユ椂闂达級
- gps.setCollectTime(sdf.format(new Date( )));
+ gps.setCollectTime(sdf.format(new Date()));
// 淇濆瓨GPS浣嶇疆淇℃伅
vehicleGpsService.insertVehicleGps(gps);
- log.info("杞﹁締[{}]GPS浣嶇疆宸叉洿鏂�: 缁忓害={}, 绾害={}, 璁惧鏃堕棿={}, 澶勭悊鏃堕棿={}",
- vehicle.getVehicleNo(), position.getCallon(), position.getCallat(),
- gps.getDeviceReportTime(), gps.getPlatformProcessTime());
+// log.info("杞﹁締[{}]GPS浣嶇疆宸叉洿鏂�: 缁忓害={}, 绾害={}, 璁惧鏃堕棿={}, 澶勭悊鏃堕棿={}",
+// vehicle.getVehicleNo(), position.getCallon(), position.getCallat(),
+// gps.getDeviceReportTime(), gps.getPlatformProcessTime());
} catch (Exception e) {
log.error("鏇存柊杞﹁締[{}]GPS浣嶇疆澶辫触: {}", vehicle.getVehicleNo(), e.getMessage());
}
}
-
}
--
Gitblit v1.9.1