From ae1e467411a786c37fb20b9bce2a7a4da64aa412 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期一, 10 十一月 2025 21:35:55 +0800
Subject: [PATCH] feat:在app中增加成交价的自动计算
---
app/pages/task/create-emergency.vue | 54 ++++++++++
app/api/price.js | 18 +++
ruoyi-system/src/main/java/com/ruoyi/system/service/IPriceCalculateService.java | 20 ++++
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/PriceCalculateController.java | 59 +++++++++++
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PriceCalculateServiceImpl.java | 49 +++++++++
ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/PriceCalculateVO.java | 73 ++++++++++++++
6 files changed, 273 insertions(+), 0 deletions(-)
diff --git a/app/api/price.js b/app/api/price.js
new file mode 100644
index 0000000..2242a2d
--- /dev/null
+++ b/app/api/price.js
@@ -0,0 +1,18 @@
+import request from '@/utils/request'
+
+/**
+ * 璁$畻杞繍鎴愪氦浠�
+ * @param {Object} params - 璁$畻鍙傛暟
+ * @param {String} params.fromAddress - 璧峰鍦板潃
+ * @param {String} params.toAddress - 鐩殑鍦板潃
+ * @param {Number} params.distance - 璺濈锛堝叕閲岋級
+ * @param {String} params.region - 鍦板煙锛堝彲閫夛級
+ * @returns {Promise} 杩斿洖鎴愪氦浠�
+ */
+export function calculateTransferPrice(params) {
+ return request({
+ url: '/api/price/calculate',
+ method: 'post',
+ data: params
+ })
+}
diff --git a/app/pages/task/create-emergency.vue b/app/pages/task/create-emergency.vue
index 933ece3..a5876c9 100644
--- a/app/pages/task/create-emergency.vue
+++ b/app/pages/task/create-emergency.vue
@@ -342,6 +342,7 @@
type="digit"
placeholder="璇疯緭鍏ヨ浆杩愬叕閲屾暟"
v-model="taskForm.transferDistance"
+ @blur="onDistanceChange"
/>
</view>
@@ -509,6 +510,7 @@
import { searchHospitals, getFrequentOutHospitals, getFrequentInHospitals, searchHospitalsByDeptRegion } from "@/api/hospital"
import { listBranchUsers } from "@/api/system/user"
import { searchIcd10 } from "@/api/icd10"
+import { calculateTransferPrice } from "@/api/price"
import { getDicts } from "@/api/dict"
import { getServiceOrdAreaTypes, getServiceOrderTypes, getHospitalDepartments } from "@/api/dictionary"
@@ -1592,6 +1594,9 @@
console.log('璺濈璁$畻鎴愬姛:', distanceInKm, 'km')
this.$modal.showToast(`璺濈: ${distanceInKm}鍏噷`)
+
+ // 璺濈璁$畻鎴愬姛鍚庯紝鑷姩璁$畻鎴愪氦浠�
+ this.calculatePrice()
} else {
console.error('璺濈璁$畻澶辫触:', response.msg)
this.$modal.showToast('璺濈璁$畻澶辫触,璇锋墜鍔ㄨ緭鍏�')
@@ -1602,6 +1607,52 @@
console.error('璺濈璁$畻澶辫触:', error)
this.$modal.showToast('璺濈璁$畻澶辫触,璇锋墜鍔ㄨ緭鍏�')
})
+ },
+
+ // 璺濈杈撳叆妗嗗け鐒︽椂瑙﹀彂鎴愪氦浠疯绠�
+ onDistanceChange() {
+ this.calculatePrice()
+ },
+
+ // 璁$畻鎴愪氦浠�
+ calculatePrice() {
+ const fromAddress = this.taskForm.hospitalOut.address
+ const toAddress = this.taskForm.hospitalIn.address
+ const distance = this.taskForm.transferDistance
+
+ // 濡傛灉鍦板潃鎴栬窛绂讳笉瀹屾暣锛屼笉杩涜璁$畻
+ if (!fromAddress || !toAddress || !distance || parseFloat(distance) <= 0) {
+ console.log('鍦板潃鎴栬窛绂讳俊鎭笉瀹屾暣锛岃烦杩囨垚浜や环璁$畻')
+ return
+ }
+
+ console.log('寮�濮嬭绠楁垚浜や环:', fromAddress, '->', toAddress, '璺濈:', distance)
+
+ // 璋冪敤鎴愪氦浠疯绠楁帴鍙�
+ calculateTransferPrice({
+ fromAddress: fromAddress,
+ toAddress: toAddress,
+ distance: parseFloat(distance),
+ region: this.selectedRegion || ''
+ }).then(response => {
+ if (response.code === 200 && response.data) {
+ const price = response.data.price
+
+ // 鍙湁褰撹繑鍥炵殑浠锋牸澶т簬0鏃讹紝鎵嶈嚜鍔ㄥ~鍏呮垚浜や环
+ if (price && price > 0) {
+ this.taskForm.price = price.toFixed(2)
+ console.log('鎴愪氦浠疯绠楁垚鍔�:', price)
+ this.$modal.showToast(`鎴愪氦浠�: 楼${price.toFixed(2)}`)
+ } else {
+ console.log('鎴愪氦浠蜂负0锛屼笉鑷姩濉厖')
+ }
+ } else {
+ console.log('鎴愪氦浠疯绠楀け璐ワ紝淇濇寔鎵嬪姩杈撳叆')
+ }
+ }).catch(error => {
+ console.error('鎴愪氦浠疯绠楀け璐�:', error)
+ // 璁$畻澶辫触鏃朵笉鎻愮ず鐢ㄦ埛锛屽厑璁哥敤鎴锋墜鍔ㄨ緭鍏�
+ })
},
// ==================== 鐥呮儏閫夋嫨鐩稿叧鏂规硶 ====================
@@ -1954,6 +2005,9 @@
console.log('璺濈璁$畻鎴愬姛:', distanceInKm, 'km')
// this.$modal.showToast(`璺濈璁$畻鎴愬姛: ${distanceInKm}鍏噷`)
+
+ // 璺濈璁$畻鎴愬姛鍚庯紝鑷姩璁$畻鎴愪氦浠�
+ this.calculatePrice()
} else {
console.error('璺濈璁$畻澶辫触:', response.msg)
this.$modal.showToast('璺濈璁$畻澶辫触锛岃鎵嬪姩杈撳叆')
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/PriceCalculateController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/PriceCalculateController.java
new file mode 100644
index 0000000..73b585b
--- /dev/null
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/PriceCalculateController.java
@@ -0,0 +1,59 @@
+package com.ruoyi.web.controller.api;
+
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.system.domain.vo.PriceCalculateVO;
+import com.ruoyi.system.service.IPriceCalculateService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 浠锋牸璁$畻API
+ *
+ * @author ruoyi
+ */
+@RestController
+@RequestMapping("/api/price")
+public class PriceCalculateController extends BaseController {
+
+ @Autowired
+ private IPriceCalculateService priceCalculateService;
+
+ /**
+ * 璁$畻杞繍浠锋牸
+ *
+ * @param vo 璁$畻鍙傛暟
+ * @return 杩斿洖璁$畻鍚庣殑浠锋牸
+ */
+ @PostMapping("/calculate")
+ public AjaxResult calculatePrice(@RequestBody PriceCalculateVO vo) {
+ logger.info("鏀跺埌浠锋牸璁$畻璇锋眰: {}", vo);
+
+ // 鍙傛暟鏍¢獙
+ if (vo.getFromAddress() == null || vo.getFromAddress().trim().isEmpty()) {
+ return AjaxResult.error("璧峰鍦板潃涓嶈兘涓虹┖");
+ }
+ if (vo.getToAddress() == null || vo.getToAddress().trim().isEmpty()) {
+ return AjaxResult.error("鐩殑鍦板潃涓嶈兘涓虹┖");
+ }
+ if (vo.getDistance() == null || vo.getDistance().compareTo(BigDecimal.ZERO) <= 0) {
+ return AjaxResult.error("璺濈蹇呴』澶т簬0");
+ }
+
+ // 璋冪敤鏈嶅姟璁$畻浠锋牸
+ BigDecimal price = priceCalculateService.calculateTransferPrice(vo);
+
+ // 杩斿洖缁撴灉
+ Map<String, Object> result = new HashMap<>();
+ result.put("price", price);
+
+ return AjaxResult.success(result);
+ }
+}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/PriceCalculateVO.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/PriceCalculateVO.java
new file mode 100644
index 0000000..6276c8d
--- /dev/null
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/PriceCalculateVO.java
@@ -0,0 +1,73 @@
+package com.ruoyi.system.domain.vo;
+
+import java.math.BigDecimal;
+
+/**
+ * 浠锋牸璁$畻VO
+ *
+ * @author ruoyi
+ */
+public class PriceCalculateVO {
+
+ /**
+ * 璧峰鍦板潃
+ */
+ private String fromAddress;
+
+ /**
+ * 鐩殑鍦板潃
+ */
+ private String toAddress;
+
+ /**
+ * 璺濈锛堝叕閲岋級
+ */
+ private BigDecimal distance;
+
+ /**
+ * 鍦板煙锛堝彲閫夛級
+ */
+ private String region;
+
+ public String getFromAddress() {
+ return fromAddress;
+ }
+
+ public void setFromAddress(String fromAddress) {
+ this.fromAddress = fromAddress;
+ }
+
+ public String getToAddress() {
+ return toAddress;
+ }
+
+ public void setToAddress(String toAddress) {
+ this.toAddress = toAddress;
+ }
+
+ public BigDecimal getDistance() {
+ return distance;
+ }
+
+ public void setDistance(BigDecimal distance) {
+ this.distance = distance;
+ }
+
+ public String getRegion() {
+ return region;
+ }
+
+ public void setRegion(String region) {
+ this.region = region;
+ }
+
+ @Override
+ public String toString() {
+ return "PriceCalculateVO{" +
+ "fromAddress='" + fromAddress + '\'' +
+ ", toAddress='" + toAddress + '\'' +
+ ", distance=" + distance +
+ ", region='" + region + '\'' +
+ '}';
+ }
+}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IPriceCalculateService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IPriceCalculateService.java
new file mode 100644
index 0000000..932a1b6
--- /dev/null
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IPriceCalculateService.java
@@ -0,0 +1,20 @@
+package com.ruoyi.system.service;
+
+import com.ruoyi.system.domain.vo.PriceCalculateVO;
+import java.math.BigDecimal;
+
+/**
+ * 浠锋牸璁$畻鏈嶅姟鎺ュ彛
+ *
+ * @author ruoyi
+ */
+public interface IPriceCalculateService {
+
+ /**
+ * 璁$畻杞繍浠锋牸
+ *
+ * @param vo 璁$畻鍙傛暟
+ * @return 璁$畻鍚庣殑浠锋牸锛堝厓锛�
+ */
+ BigDecimal calculateTransferPrice(PriceCalculateVO vo);
+}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PriceCalculateServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PriceCalculateServiceImpl.java
new file mode 100644
index 0000000..4933540
--- /dev/null
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PriceCalculateServiceImpl.java
@@ -0,0 +1,49 @@
+package com.ruoyi.system.service.impl;
+
+import com.ruoyi.system.domain.vo.PriceCalculateVO;
+import com.ruoyi.system.service.IPriceCalculateService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+
+/**
+ * 浠锋牸璁$畻鏈嶅姟瀹炵幇
+ *
+ * @author ruoyi
+ */
+@Service
+public class PriceCalculateServiceImpl implements IPriceCalculateService {
+
+ private static final Logger log = LoggerFactory.getLogger(PriceCalculateServiceImpl.class);
+
+ /**
+ * 璁$畻杞繍浠锋牸
+ *
+ * TODO: 杩欐槸涓�涓┖瀹炵幇锛岀洰鍓嶈繑鍥�0锛屽悗缁増鏈渶瑕佹牴鎹疄闄呬笟鍔¤鍒欏疄鐜颁环鏍艰绠楅�昏緫
+ *
+ * 鍙兘鐨勮绠楄鍒欙細
+ * 1. 鍩虹浠锋牸 + 璺濈浠锋牸锛堟瘡鍏噷鍗曚环 * 璺濈锛�
+ * 2. 鏍规嵁鍦板煙璁剧疆涓嶅悓鐨勪环鏍兼爣鍑�
+ * 3. 鏍规嵁璧峰鍦板潃鍜岀洰鐨勫湴鍧�鐨勭壒娈婅鍒欒绠�
+ * 4. 鏃堕棿娈靛樊寮傦紙澶滈棿銆佽妭鍋囨棩鍔犱环锛�
+ * 5. 杞﹁締绫诲瀷宸紓
+ *
+ * @param vo 璁$畻鍙傛暟
+ * @return 璁$畻鍚庣殑浠锋牸锛堝厓锛夛紝褰撳墠杩斿洖0
+ */
+ @Override
+ public BigDecimal calculateTransferPrice(PriceCalculateVO vo) {
+ log.info("璁$畻杞繍浠锋牸 - 璧峰鍦板潃: {}, 鐩殑鍦板潃: {}, 璺濈: {}km, 鍦板煙: {}",
+ vo.getFromAddress(), vo.getToAddress(), vo.getDistance(), vo.getRegion());
+
+ // TODO: 瀹炵幇鍏蜂綋鐨勪环鏍艰绠楅�昏緫
+ // 褰撳墠杩斿洖0锛岃〃绀轰笉鑷姩濉厖浠锋牸锛岀敱鐢ㄦ埛鎵嬪姩杈撳叆
+
+ BigDecimal price = BigDecimal.ZERO;
+
+ log.info("璁$畻缁撴灉: {}鍏�", price);
+ return price;
+ }
+}
--
Gitblit v1.9.1