| app/api/price.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| app/pages/task/create-emergency.vue | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/PriceCalculateController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/PriceCalculateVO.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| ruoyi-system/src/main/java/com/ruoyi/system/service/IPriceCalculateService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PriceCalculateServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
app/api/price.js
New file @@ -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 }) } 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('距离计算失败,请手动输入') ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/PriceCalculateController.java
New file @@ -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); } } ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/PriceCalculateVO.java
New file @@ -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 + '\'' + '}'; } } ruoyi-system/src/main/java/com/ruoyi/system/service/IPriceCalculateService.java
New file @@ -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); } ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PriceCalculateServiceImpl.java
New file @@ -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; } }