|
|
|
@ -6,6 +6,7 @@ import com.internal.dto.ResponseResult;
|
|
|
|
|
import com.internal.request.ForecastPriceDTO;
|
|
|
|
|
import com.internal.response.DirectionResponse;
|
|
|
|
|
import com.internal.response.ForecastPriceResponse;
|
|
|
|
|
import com.internal.util.BigDecimalUtils;
|
|
|
|
|
import com.taxi.serviceprice.mapper.PriceRuleMapper;
|
|
|
|
|
import com.taxi.serviceprice.remote.ServiceMapClient;
|
|
|
|
|
import javafx.scene.effect.Light;
|
|
|
|
@ -30,6 +31,7 @@ public class ForecastPriceService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据 出发地和目的的经纬度,计算预估价格
|
|
|
|
|
*
|
|
|
|
|
* @param depLongitude
|
|
|
|
|
* @param depLatitude
|
|
|
|
|
* @param destLongitude
|
|
|
|
@ -37,7 +39,7 @@ public class ForecastPriceService {
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public ResponseResult forecastPrice(String depLongitude, String depLatitude,
|
|
|
|
|
String destLongitude, String destLatitude){
|
|
|
|
|
String destLongitude, String destLatitude) {
|
|
|
|
|
log.info("出发经度," + depLongitude);
|
|
|
|
|
log.info("出发纬度," + depLatitude);
|
|
|
|
|
log.info("目的地经度," + destLongitude);
|
|
|
|
@ -52,19 +54,23 @@ public class ForecastPriceService {
|
|
|
|
|
forecastPriceDTO.setDestLongitude(destLongitude);
|
|
|
|
|
forecastPriceDTO.setDestLatitude(destLatitude);
|
|
|
|
|
ResponseResult<DirectionResponse> directionResponse = serviceMapClient.direction(forecastPriceDTO);
|
|
|
|
|
log.info("距离"+directionResponse.getData().getDistance());
|
|
|
|
|
log.info("时间"+directionResponse.getData().getDuration());
|
|
|
|
|
log.info("距离" + directionResponse.getData().getDistance());
|
|
|
|
|
log.info("时间" + directionResponse.getData().getDuration());
|
|
|
|
|
log.info("读取计价规则");
|
|
|
|
|
Map<String,Object> queryMap = new HashMap<>();
|
|
|
|
|
queryMap.put("city_code","11000");
|
|
|
|
|
queryMap.put("vehicle_type","1");
|
|
|
|
|
List<PriceRule> pricetRules = priceRuleMapper.selectByMap(queryMap);
|
|
|
|
|
log.info("读取计价规则count = "+pricetRules.size());
|
|
|
|
|
if(pricetRules.size() < 1){
|
|
|
|
|
Map<String, Object> queryMap = new HashMap<>();
|
|
|
|
|
queryMap.put("city_code", "11000");
|
|
|
|
|
queryMap.put("vehicle_type", "1");
|
|
|
|
|
List<PriceRule> pricetRules = priceRuleMapper.selectByMap(queryMap);
|
|
|
|
|
log.info("读取计价规则count = " + pricetRules.size());
|
|
|
|
|
if (pricetRules.size() < 1) {
|
|
|
|
|
ResponseResult.fail(CommonStatusEnum.PRICE_RULE_EMPTY);
|
|
|
|
|
}else{
|
|
|
|
|
price = getPrice(directionResponse.getData().getDistance(),
|
|
|
|
|
directionResponse.getData().getDuration(),pricetRules.get(0));
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
price = getPrice(directionResponse.getData().getDistance(),
|
|
|
|
|
directionResponse.getData().getDuration(), pricetRules.get(0));
|
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.info("根据距离、时长,计价规则;计算价格");
|
|
|
|
|
ForecastPriceResponse forecastPriceResponse = new ForecastPriceResponse();
|
|
|
|
@ -80,43 +86,35 @@ public class ForecastPriceService {
|
|
|
|
|
* @param priceRule
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private double getPrice(Integer distance,Integer duration,PriceRule priceRule){
|
|
|
|
|
BigDecimal price = new BigDecimal(0);
|
|
|
|
|
private double getPrice(Integer distance, Integer duration, PriceRule priceRule) throws IllegalAccessException {
|
|
|
|
|
double price = 0.0;
|
|
|
|
|
//BigDecimal //起步价
|
|
|
|
|
Double startFare = priceRule.getStartFare();
|
|
|
|
|
BigDecimal startFareDecimal = new BigDecimal(startFare);
|
|
|
|
|
price = price.add(startFareDecimal);
|
|
|
|
|
double startFare = priceRule.getStartFare();
|
|
|
|
|
price = BigDecimalUtils.add(price, startFare);
|
|
|
|
|
//里程碑 m
|
|
|
|
|
BigDecimal distanceBigDecimal = new BigDecimal(distance);
|
|
|
|
|
//总里程 km
|
|
|
|
|
BigDecimal distanceMileDecimal = distanceBigDecimal.divide(new BigDecimal(1000),2,BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
double distanceMile = BigDecimalUtils.divide(distance, 1000);
|
|
|
|
|
//起步里程
|
|
|
|
|
Integer startMile = priceRule.getStartMile();
|
|
|
|
|
BigDecimal startMileDecimal = new BigDecimal(startMile);
|
|
|
|
|
double distanceSubtract = distanceMileDecimal.subtract(startMileDecimal).doubleValue();
|
|
|
|
|
int startMile = priceRule.getStartMile();
|
|
|
|
|
double distanceSubtract = BigDecimalUtils.subtract(distanceMile, startMile);
|
|
|
|
|
//最终收费里程数 km
|
|
|
|
|
Double mile = distanceSubtract < 0 ? 0:distanceSubtract;
|
|
|
|
|
BigDecimal mileDecimal = new BigDecimal(mile);
|
|
|
|
|
double mile = distanceSubtract < 0 ? 0 : distanceSubtract;
|
|
|
|
|
//计程单价 元/km
|
|
|
|
|
Double unitPricePerMile = priceRule.getUnitPricePerMile();
|
|
|
|
|
BigDecimal unitPricePerMilDecimal = new BigDecimal(unitPricePerMile);
|
|
|
|
|
//里程价格
|
|
|
|
|
BigDecimal mileFare = mileDecimal.multiply(unitPricePerMilDecimal).setScale(2,BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
price = price.add(mileFare);
|
|
|
|
|
double mileFare = BigDecimalUtils.multiply(mile, unitPricePerMile);
|
|
|
|
|
price = BigDecimalUtils.add(price, mileFare);
|
|
|
|
|
//时长费用
|
|
|
|
|
BigDecimal time = new BigDecimal(duration);
|
|
|
|
|
//时长的分钟数
|
|
|
|
|
BigDecimal timeDecimal = time.divide(new BigDecimal(60),2,BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
double time = BigDecimalUtils.divide(duration,60);
|
|
|
|
|
//计时单价
|
|
|
|
|
Double unitPricePerMinute = priceRule.getUnitPricePerMinute();
|
|
|
|
|
BigDecimal unitPricePerMinuteDecimal = new BigDecimal(unitPricePerMinute);
|
|
|
|
|
BigDecimal timeFare = timeDecimal.multiply(unitPricePerMinuteDecimal);
|
|
|
|
|
price = price.add(timeFare).setScale(2,BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
|
|
|
|
return price.doubleValue();
|
|
|
|
|
double timeFare = BigDecimalUtils.multiply(time,unitPricePerMinute);
|
|
|
|
|
price = BigDecimalUtils.add(price,timeFare);
|
|
|
|
|
return new BigDecimal(price).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// public static void main(String[] args) {
|
|
|
|
|
// public static void main(String[] args) throws IllegalAccessException {
|
|
|
|
|
// PriceRule priceRule = new PriceRule();
|
|
|
|
|
// priceRule.setUnitPricePerMile(1.8);
|
|
|
|
|
// priceRule.setUnitPricePerMinute(0.5);
|
|
|
|
|