From 8b005a808d6ab8fae1480ed57bdfd68af2dafcd4 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期六, 01 十一月 2025 23:07:49 +0800
Subject: [PATCH] feat:输入出入地址时,会自动计算距离
---
app/pages/task/create-emergency.vue | 86 ++++++++++++++++++---
app/pages/login.vue | 2
sql/legacy_status_sync_job.sql | 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleGpsController.java | 81 ++++++++++++++++++-
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/LegacySystemSyncServiceImpl.java | 3
ruoyi-admin/src/main/resources/application.yml | 4
ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/GpsSyncTask.java | 6
sql/task_status_push_job.sql | 2
app/App.vue | 19 +++-
ruoyi-system/src/main/resources/mapper/system/HospDataMapper.xml | 2
10 files changed, 173 insertions(+), 34 deletions(-)
diff --git a/app/App.vue b/app/App.vue
index 650a7fd..298be3a 100644
--- a/app/App.vue
+++ b/app/App.vue
@@ -15,6 +15,17 @@
this.lastToken = getToken()
this.initApp()
+ // 鐩戝惉鐢ㄦ埛鐧诲綍浜嬩欢
+ uni.$on('user-login', () => {
+ console.log('鎺ユ敹鍒扮敤鎴风櫥褰曚簨浠讹紝鍚姩娑堟伅杞')
+ const token = getToken()
+ if (token) {
+ this.lastToken = token
+ this.updateUnreadMessageBadge()
+ this.startMessagePolling()
+ }
+ })
+
// 鐩戝惉鐢ㄦ埛鐧诲嚭浜嬩欢
uni.$on('user-logout', () => {
console.log('鎺ユ敹鍒扮敤鎴风櫥鍑轰簨浠讹紝鍋滄娑堟伅杞')
@@ -64,12 +75,8 @@
this.checkLogin()
//#endif
- // 濡傛灉宸茬櫥褰曪紝鍚姩鏈娑堟伅杞
- if (getToken()) {
- this.updateUnreadMessageBadge()
- // 姣�30绉掕疆璇竴娆�
- this.startMessagePolling()
- }
+ // 娉ㄦ剰锛氫笉鍦ㄥ簲鐢ㄥ惎鍔ㄦ椂鑷姩鍚姩杞
+ // 鍙湁鍦ㄧ敤鎴蜂富鍔ㄧ櫥褰曟垚鍔熷悗鎵嶅惎鍔紙閫氳繃 user-login 浜嬩欢瑙﹀彂锛�
},
initConfig() {
this.globalData.config = config
diff --git a/app/pages/login.vue b/app/pages/login.vue
index 53aa8a8..3e85fce 100644
--- a/app/pages/login.vue
+++ b/app/pages/login.vue
@@ -125,6 +125,8 @@
loginSuccess(result) {
// 璁剧疆鐢ㄦ埛淇℃伅
this.$store.dispatch('GetInfo').then(res => {
+ // 瑙﹀彂鐧诲綍鎴愬姛浜嬩欢锛屽惎鍔ㄦ秷鎭疆璇�
+ uni.$emit('user-login')
this.$tab.reLaunch('/pages/index')
})
}
diff --git a/app/pages/task/create-emergency.vue b/app/pages/task/create-emergency.vue
index 2e0cf48..a0f758a 100644
--- a/app/pages/task/create-emergency.vue
+++ b/app/pages/task/create-emergency.vue
@@ -78,7 +78,7 @@
<view class="form-item">
- <view class="form-label">杞繍鏃堕棿</view>
+ <view class="form-label required">杞繍鏃堕棿</view>
<uni-datetime-picker
v-model="taskForm.transferTime"
type="datetime"
@@ -443,7 +443,7 @@
import uniPopup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue'
import { addTask } from "@/api/task"
import { listAvailableVehicles, getUserBoundVehicle } from "@/api/vehicle"
-import { calculateDistance } from "@/api/map"
+import { calculateDistance, baiduDistanceByAddress } from "@/api/map"
import { searchHospitals } from "@/api/hospital"
import { listUser } from "@/api/system/user"
import { searchIcd10 } from "@/api/icd10"
@@ -560,6 +560,9 @@
}
},
onLoad(options) {
+ // 璁剧疆榛樿杞繍鏃堕棿涓哄綋鍓嶆椂闂�
+ this.setDefaultTransferTime()
+
// 鍏堝姞杞借溅杈嗗垪琛紝鐒跺悗鍔犺浇缁戝畾杞﹁締淇℃伅
this.getAvailableVehicles().then(() => {
this.getUserBoundVehicleInfo()
@@ -902,15 +905,12 @@
this.showHospitalOutResults = false
this.hospitalOutResults = []
- // 濡傛灉鏈塆PS鍧愭爣锛屼繚瀛樹笅鏉�
- // 娉ㄦ剰锛欻ospData琛ㄤ腑鍙兘娌℃湁GPS鍧愭爣锛岄渶瑕佹牴鎹湴鍧�杩涜鍦扮悊缂栫爜
- // 杩欓噷鍏堢疆涓簄ull锛屽悗缁彲浠ラ�氳繃鍦板潃瑙f瀽鑾峰彇
- this.addressCoordinates.hospitalOutAddress = null
+ // 淇濆瓨杞嚭鍖婚櫌鐨勫煄甯備俊鎭�
+ this.taskForm.hospitalOut.city = hospital.hopsCity || ''
// 濡傛灉涓や釜鍖婚櫌閮藉凡閫夋嫨锛岃嚜鍔ㄨ绠楄窛绂�
if (this.taskForm.hospitalIn.address) {
- // 杩欓噷鍙互璋冪敤鍦板潃瑙f瀽鍜岃窛绂昏绠�
- // 鏆傛椂鐣欑┖锛岀敱鐢ㄦ埛鎵嬪姩杈撳叆璺濈
+ this.calculateHospitalDistance()
}
},
@@ -986,13 +986,12 @@
this.showHospitalInResults = false
this.hospitalInResults = []
- // 濡傛灉鏈塆PS鍧愭爣锛屼繚瀛樹笅鏉�
- this.addressCoordinates.hospitalInAddress = null
+ // 淇濆瓨杞叆鍖婚櫌鐨勫煄甯備俊鎭�
+ this.taskForm.hospitalIn.city = hospital.hopsCity || ''
// 濡傛灉涓や釜鍖婚櫌閮藉凡閫夋嫨锛岃嚜鍔ㄨ绠楄窛绂�
if (this.taskForm.hospitalOut.address) {
- // 杩欓噷鍙互璋冪敤鍦板潃瑙f瀽鍜岃窛绂昏绠�
- // 鏆傛椂鐣欑┖锛岀敱鐢ㄦ埛鎵嬪姩杈撳叆璺濈
+ this.calculateHospitalDistance()
}
},
@@ -1271,6 +1270,20 @@
this.selectedDiseases.splice(index, 1)
},
+ // 璁剧疆榛樿杞繍鏃堕棿涓哄綋鍓嶆椂闂�
+ setDefaultTransferTime() {
+ const now = new Date()
+ const year = now.getFullYear()
+ const month = String(now.getMonth() + 1).padStart(2, '0')
+ const day = String(now.getDate()).padStart(2, '0')
+ const hours = String(now.getHours()).padStart(2, '0')
+ const minutes = String(now.getMinutes()).padStart(2, '0')
+ const seconds = String(now.getSeconds()).padStart(2, '0')
+
+ // 鏍煎紡鍖栦负 YYYY-MM-DD HH:mm:ss
+ this.taskForm.transferTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
+ },
+
validateForm() {
if (!this.selectedVehicleId) {
this.$modal.showToast('璇烽�夋嫨浠诲姟杞﹁締')
@@ -1284,6 +1297,11 @@
if (!this.selectedDocumentType) {
this.$modal.showToast('璇烽�夋嫨鍗曟嵁绫诲瀷')
+ return false
+ }
+
+ if (!this.taskForm.transferTime) {
+ this.$modal.showToast('璇烽�夋嫨杞繍鏃堕棿')
return false
}
@@ -1447,6 +1465,50 @@
parts.push(hospital.hospAddress)
}
return parts.join('')
+ },
+
+ // 鑷姩璁$畻涓や釜鍖婚櫌涔嬮棿鐨勮窛绂�
+ calculateHospitalDistance() {
+ const fromAddress = this.taskForm.hospitalOut.address
+ const fromCity = this.taskForm.hospitalOut.city
+ const toAddress = this.taskForm.hospitalIn.address
+ const toCity = this.taskForm.hospitalIn.city
+
+ if (!fromAddress || !toAddress) {
+ console.log('鍦板潃淇℃伅涓嶅畬鏁达紝鏃犳硶璁$畻璺濈')
+ return
+ }
+
+ console.log('寮�濮嬭绠楄窛绂�:', fromAddress, '->', toAddress)
+
+ // 鏄剧ず鍔犺浇鎻愮ず
+ uni.showLoading({
+ title: '璁$畻璺濈涓�...'
+ })
+
+ // 璋冪敤鐧惧害鍦板浘API璁$畻璺濈
+ baiduDistanceByAddress(fromAddress, fromCity, toAddress, toCity)
+ .then(response => {
+ uni.hideLoading()
+
+ if (response.code === 200 && response.data) {
+ const distanceInMeters = response.data.distance
+ // 杞崲涓哄叕閲岋紝淇濈暀1浣嶅皬鏁�
+ const distanceInKm = (distanceInMeters / 1000).toFixed(1)
+ this.taskForm.transferDistance = distanceInKm
+
+ console.log('璺濈璁$畻鎴愬姛:', distanceInKm, 'km')
+ this.$modal.showToast(`璺濈璁$畻鎴愬姛: ${distanceInKm}鍏噷`)
+ } else {
+ console.error('璺濈璁$畻澶辫触:', response.msg)
+ this.$modal.showToast('璺濈璁$畻澶辫触锛岃鎵嬪姩杈撳叆')
+ }
+ })
+ .catch(error => {
+ uni.hideLoading()
+ console.error('璺濈璁$畻澶辫触:', error)
+ this.$modal.showToast('璺濈璁$畻澶辫触锛岃鎵嬪姩杈撳叆')
+ })
}
}
}
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleGpsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleGpsController.java
index 5ae3359..ac0efe6 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleGpsController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleGpsController.java
@@ -575,6 +575,17 @@
String geocodingResponse1 = HttpUtils.sendGet(geocodingUrl1, geocodingParams1);
logger.info("璧风偣鍦扮悊缂栫爜鍝嶅簲: {}", geocodingResponse1);
+ // 瑙f瀽璧风偣鍧愭爣
+ com.alibaba.fastjson2.JSONObject geocodingJson1 = com.alibaba.fastjson2.JSONObject.parseObject(geocodingResponse1);
+ if (geocodingJson1.getInteger("status") != 0) {
+ logger.error("璧风偣鍦扮悊缂栫爜澶辫触: {}", geocodingResponse1);
+ return AjaxResult.error("璧风偣鍦板潃瑙f瀽澶辫触");
+ }
+ com.alibaba.fastjson2.JSONObject location1 = geocodingJson1.getJSONObject("result").getJSONObject("location");
+ double fromLat = location1.getDouble("lat");
+ double fromLng = location1.getDouble("lng");
+ logger.info("璧风偣鍧愭爣: lat={}, lng={}", fromLat, fromLng);
+
// 绗簩姝ワ細缁堢偣鍦板潃杞潗鏍�
String geocodingUrl2 = "https://api.map.baidu.com/geocoding/v3/";
String geocodingParams2 = "address=" + URLEncoder.encode(toAddress, StandardCharsets.UTF_8.toString()) +
@@ -586,14 +597,70 @@
String geocodingResponse2 = HttpUtils.sendGet(geocodingUrl2, geocodingParams2);
logger.info("缁堢偣鍦扮悊缂栫爜鍝嶅簲: {}", geocodingResponse2);
- // 瑙f瀽鍧愭爣锛堣繖閲岀畝鍖栧鐞嗭紝瀹為檯搴旇瑙f瀽JSON锛�
- // 娉ㄦ剰锛氶渶瑕佷粠鍝嶅簲涓彁鍙栧潗鏍囷紝杩欓噷杩斿洖涓棿缁撴灉渚涘墠绔鐞�
- Map<String, Object> result = new HashMap<>();
- result.put("fromGeocoding", geocodingResponse1);
- result.put("toGeocoding", geocodingResponse2);
- result.put("message", "璇疯В鏋愬潗鏍囧悗璋冪敤 /baidu/route/driving 鎺ュ彛璁$畻璺濈");
+ // 瑙f瀽缁堢偣鍧愭爣
+ com.alibaba.fastjson2.JSONObject geocodingJson2 = com.alibaba.fastjson2.JSONObject.parseObject(geocodingResponse2);
+ if (geocodingJson2.getInteger("status") != 0) {
+ logger.error("缁堢偣鍦扮悊缂栫爜澶辫触: {}", geocodingResponse2);
+ return AjaxResult.error("缁堢偣鍦板潃瑙f瀽澶辫触");
+ }
+ com.alibaba.fastjson2.JSONObject location2 = geocodingJson2.getJSONObject("result").getJSONObject("location");
+ double toLat = location2.getDouble("lat");
+ double toLng = location2.getDouble("lng");
+ logger.info("缁堢偣鍧愭爣: lat={}, lng={}", toLat, toLng);
- return AjaxResult.success("鍦扮悊缂栫爜鎴愬姛", result);
+ // 绗笁姝ワ細璋冪敤璺嚎瑙勫垝鎺ュ彛璁$畻璺濈
+ String routeUrl = "https://api.map.baidu.com/directionlite/v1/driving";
+ String origin = fromLat + "," + fromLng;
+ String destination = toLat + "," + toLng;
+ String routeParams = "origin=" + origin +
+ "&destination=" + destination +
+ "&ak=" + baiduMapConfig.getAk();
+
+ logger.info("璺嚎瑙勫垝璇锋眰: origin={}, destination={}", origin, destination);
+ String routeResponse = HttpUtils.sendGet(routeUrl, routeParams);
+ logger.info("璺嚎瑙勫垝鍝嶅簲: {}", routeResponse);
+
+ // 瑙f瀽璺濈缁撴灉
+ com.alibaba.fastjson2.JSONObject routeJson = com.alibaba.fastjson2.JSONObject.parseObject(routeResponse);
+ if (routeJson.getInteger("status") != 0) {
+ logger.error("璺嚎瑙勫垝澶辫触: {}", routeResponse);
+ return AjaxResult.error("璺嚎瑙勫垝澶辫触");
+ }
+
+ // 鎻愬彇璺濈淇℃伅锛堝崟浣嶏細绫筹級
+ com.alibaba.fastjson2.JSONObject result = routeJson.getJSONObject("result");
+ com.alibaba.fastjson2.JSONArray routes = result.getJSONArray("routes");
+ if (routes == null || routes.isEmpty()) {
+ logger.error("鏈壘鍒拌矾绾夸俊鎭�");
+ return AjaxResult.error("鏈壘鍒拌矾绾夸俊鎭�");
+ }
+
+ com.alibaba.fastjson2.JSONObject route = routes.getJSONObject(0);
+ int distance = route.getInteger("distance"); // 璺濈锛屽崟浣嶏細绫�
+ int duration = route.getInteger("duration"); // 鏃堕暱锛屽崟浣嶏細绉�
+
+ logger.info("璁$畻鎴愬姛: 璺濈={}绫�, 鏃堕暱={}绉�", distance, duration);
+
+ // 鏋勫缓杩斿洖缁撴灉
+ Map<String, Object> resultMap = new HashMap<>();
+ resultMap.put("distance", distance); // 璺濈锛堢背锛�
+ resultMap.put("duration", duration); // 鏃堕暱锛堢锛�
+ resultMap.put("distanceKm", String.format("%.1f", distance / 1000.0)); // 璺濈锛堝叕閲岋級
+ resultMap.put("durationMin", duration / 60); // 鏃堕暱锛堝垎閽燂級
+
+ // 璧风偣鍧愭爣
+ Map<String, Object> fromLocation = new HashMap<>();
+ fromLocation.put("lat", fromLat);
+ fromLocation.put("lng", fromLng);
+ resultMap.put("fromLocation", fromLocation);
+
+ // 缁堢偣鍧愭爣
+ Map<String, Object> toLocation = new HashMap<>();
+ toLocation.put("lat", toLat);
+ toLocation.put("lng", toLng);
+ resultMap.put("toLocation", toLocation);
+
+ return AjaxResult.success("璁$畻鎴愬姛", resultMap);
} catch (Exception e) {
logger.error("璁$畻鍦板潃璺濈澶辫触", e);
return AjaxResult.error("璁$畻璺濈澶辫触锛�" + e.getMessage());
diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml
index bd357ff..413d0c9 100644
--- a/ruoyi-admin/src/main/resources/application.yml
+++ b/ruoyi-admin/src/main/resources/application.yml
@@ -56,7 +56,7 @@
basename: i18n/messages
profiles:
# 鐜 dev|test|prod
- active: prod
+ active: dev
# 鏂囦欢涓婁紶
servlet:
multipart:
@@ -159,4 +159,4 @@
# 鐧惧害鍦板浘閰嶇疆
baidu:
map:
- ak: YOUR_BAIDU_MAP_AK_HERE # 璇锋浛鎹负鎮ㄧ殑鐧惧害鍦板浘API Key
+ ak: GX7G1RmAbTEQHor9NKpzRiB2jerqaY1E # 璇锋浛鎹负鎮ㄧ殑鐧惧害鍦板浘API Key
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 692c14f..bb1e178 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
@@ -114,9 +114,9 @@
// 淇濆瓨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());
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/LegacySystemSyncServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/LegacySystemSyncServiceImpl.java
index 828459a..612d67a 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/LegacySystemSyncServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/LegacySystemSyncServiceImpl.java
@@ -383,7 +383,7 @@
while (true) {
// 鍒嗛〉鏌ヨ宸插悓姝ユ湇鍔″崟浣嗘湭鍚屾璋冨害鍗曠殑浠诲姟
List<SysTaskEmergency> pendingTasks = sysTaskEmergencyService.selectPendingDispatchSyncTasks(offset, pageSize);
-
+ log.info("鏌ヨ鍒版湭鍚屾璋冨害鍗曠殑浠诲姟鏁伴噺: {}", pendingTasks.size());
if (pendingTasks == null || pendingTasks.isEmpty()) {
log.info("娌℃湁鏇村闇�瑕佸悓姝ヨ皟搴﹀崟鐨勪换鍔★紝offset: {}", offset);
break; // 娌℃湁鏇村鏁版嵁锛岄��鍑哄惊鐜�
@@ -393,6 +393,7 @@
int pageSuccessCount = 0;
for (SysTaskEmergency emergency : pendingTasks) {
+ log.info("寮�濮嬪悓姝ヨ皟搴﹀崟锛屼换鍔D: {}", emergency.getTaskId());
Long dispatchOrdId = syncDispatchOrderToLegacy(emergency.getTaskId());
if (dispatchOrdId != null && dispatchOrdId > 0) {
pageSuccessCount++;
diff --git a/ruoyi-system/src/main/resources/mapper/system/HospDataMapper.xml b/ruoyi-system/src/main/resources/mapper/system/HospDataMapper.xml
index 389c2fa..d3470a2 100644
--- a/ruoyi-system/src/main/resources/mapper/system/HospDataMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/HospDataMapper.xml
@@ -23,7 +23,7 @@
</resultMap>
<select id="searchHospitals" resultMap="HospDataResult">
- SELECT TOP 100
+ SELECT TOP 1000
HospID, HospName, HospCityID, HospShort,
HopsProvince, HopsCity, HopsArea, HospAddress,
HospTEL, HospUnitID, HospState, HospOAID,
diff --git a/sql/legacy_status_sync_job.sql b/sql/legacy_status_sync_job.sql
index 50e06b3..b71f91c 100644
--- a/sql/legacy_status_sync_job.sql
+++ b/sql/legacy_status_sync_job.sql
@@ -40,7 +40,7 @@
`update_time`,
`remark`
) VALUES (
- '浠诲姟鐘舵�佸悓姝�',
+ '浠诲姟鐘舵�佹棫鍒版柊鍚屾',
'DEFAULT',
'legacySystemSyncTask.syncTaskStatusFromLegacy()',
'0 0/5 * * * ?',
diff --git a/sql/task_status_push_job.sql b/sql/task_status_push_job.sql
index 1f2b710..fc7197d 100644
--- a/sql/task_status_push_job.sql
+++ b/sql/task_status_push_job.sql
@@ -3,5 +3,5 @@
-- ----------------------------
INSERT INTO sys_job (job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, update_by, update_time, remark)
VALUES
-('浠诲姟鐘舵�佹帹閫�', 'DEFAULT', 'legacySystemSyncTask.pushTaskStatusToLegacy()', '0 0/3 * * * ?', '3', '1', '1', 'admin', sysdate(), 'admin', sysdate(),
+('浠诲姟鐘舵�佹帹閫佹柊鍒版棫', 'DEFAULT', 'legacySystemSyncTask.pushTaskStatusToLegacy()', '0 0/3 * * * ?', '3', '1', '1', 'admin', sysdate(), 'admin', sysdate(),
'姣�3鍒嗛挓鎵ц涓�娆★紝灏嗘柊绯荤粺涓姸鎬佸凡鍙樺寲鐨勪换鍔℃帹閫佸埌鏃х郴缁熴�傛帹閫佽鍒欙細鍑哄彂涓�->4锛屼换鍔′腑->6锛岃繑绋嬩腑->7锛屽凡瀹屾垚->8锛屽凡鍙栨秷->10銆傛棫绯荤粺鐘舵��>=鐩爣鐘舵�佹椂涓嶆帹閫併��');
--
Gitblit v1.9.1