|
@@ -1,9 +1,13 @@
|
|
|
package com.ylx.massage.utils;
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.ylx.massage.domain.TFareSetting;
|
|
|
+import com.ylx.massage.service.TFareSettingService;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
@@ -13,7 +17,7 @@ import java.math.RoundingMode;
|
|
|
*/
|
|
|
|
|
|
@Component
|
|
|
-public class MassageUtil {
|
|
|
+public class MassageUtil {
|
|
|
|
|
|
@Value("${fare.base-fare}")
|
|
|
private BigDecimal baseFare;
|
|
@@ -24,15 +28,27 @@ public class MassageUtil {
|
|
|
@Value("${fare.base-distance-km}")
|
|
|
private BigDecimal baseDistanceKm;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private TFareSettingService fareSettingService;
|
|
|
+
|
|
|
/**
|
|
|
* 计算出租车费用
|
|
|
+ *
|
|
|
* @param distance 全程距离(公里)
|
|
|
* @return 费用总额(元)
|
|
|
*/
|
|
|
- public BigDecimal calculateTaxiFare(BigDecimal distance) {
|
|
|
- final BigDecimal BASE_FARE = baseFare; // 起步价
|
|
|
- final BigDecimal ADDITIONAL_FARE_PER_KM = additionalFarePerKm; // 超出起步价后每公里费用
|
|
|
- final BigDecimal BASE_DISTANCE_KM = baseDistanceKm; // 起步距离(公里)
|
|
|
+ public BigDecimal calculateTaxiFare(BigDecimal distance, String deptId) {
|
|
|
+ BigDecimal BASE_FARE = baseFare; // 起步价
|
|
|
+ BigDecimal ADDITIONAL_FARE_PER_KM = additionalFarePerKm; // 超出起步价后每公里费用
|
|
|
+ BigDecimal BASE_DISTANCE_KM = baseDistanceKm; // 起步距离(公里)
|
|
|
+ LambdaQueryWrapper<TFareSetting> tFareSettingLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ tFareSettingLambdaQueryWrapper.eq(TFareSetting::getDeptId, deptId).eq(TFareSetting::getEnable, 1);
|
|
|
+ TFareSetting fareSetting = fareSettingService.getOne(tFareSettingLambdaQueryWrapper);
|
|
|
+ if (null != fareSetting) {
|
|
|
+ BASE_FARE = fareSetting.getBaseFare();
|
|
|
+ ADDITIONAL_FARE_PER_KM = fareSetting.getAdditionalFarePer();
|
|
|
+ BASE_DISTANCE_KM = fareSetting.getBaseDistance();
|
|
|
+ }
|
|
|
|
|
|
// 计算超出起步价的公里数,注意应该向上取整,因为不足1公里也要按1公里计费
|
|
|
BigDecimal extraKms = distance.subtract(BASE_DISTANCE_KM).setScale(0, RoundingMode.UP);
|
|
@@ -40,8 +56,8 @@ public class MassageUtil {
|
|
|
// 计算总费用
|
|
|
|
|
|
BigDecimal totalFare = BASE_FARE;
|
|
|
- if(extraKms.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- totalFare= totalFare.add(extraKms.multiply(ADDITIONAL_FARE_PER_KM));
|
|
|
+ if (extraKms.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ totalFare = totalFare.add(extraKms.multiply(ADDITIONAL_FARE_PER_KM));
|
|
|
}
|
|
|
return totalFare.multiply(new BigDecimal("2"));
|
|
|
}
|