1.自定义时刻周期

This commit is contained in:
邱贞招 2024-07-26 17:25:04 +08:00
parent 43676f28d7
commit 42442ec8ff
4 changed files with 53 additions and 9 deletions

View File

@ -464,7 +464,7 @@ public class AppVerifyController extends BaseController
@PostMapping("/device/return")
public AjaxResult returnVehicle(String orderNo,String returnType,String isBluetooth,String lon,String lat,String voltage,String isInParkingArea)
{
logger.info("【接收还车请求参数】:{},是否辅助还车:{},是否蓝牙控制:{},电压:{},是否在停车点内:{}", orderNo,returnType,isBluetooth,lon,lat,voltage,isInParkingArea);
logger.info("【接收还车请求参数】:orderNo={},是否辅助还车:{},是否蓝牙控制{},经度:{},纬度{},电压:{},是否在停车点内:{}", orderNo,returnType,isBluetooth,lon,lat,voltage,isInParkingArea);
Boolean aBoolean = asDeviceService.returnVehicle(orderNo,returnType,isBluetooth,lon,lat,voltage,isInParkingArea);
return success(aBoolean);
}

View File

@ -153,7 +153,7 @@ public class ServiceConstants {
/**
* 支付方式: ye-余额抵扣
*/
public static final String PAY_TYPE_YE = "yj";
public static final String PAY_TYPE_YE = "ye";
/**----------------------------支付类型end----------------------------*/

View File

@ -119,7 +119,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
"/appCaptcha",
"/appCodeLogin",
"/app/**",
"/appVerify/**",
// "/appVerify/**",
"/common/upload",
"/common/receive",
"/payment/callback/**",

View File

@ -41,6 +41,8 @@ import org.springframework.transaction.support.TransactionTemplate;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@ -1678,7 +1680,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
BigDecimal ridingFee;
if(cycle == 1){
order.setCycle(1);//在第几个计费周期内
ridingFee = calculateRidingFee(order.getUnlockTime(), order, rule, rule.getRidingRuleJson(), rentalUnit);
ridingFee = calculateRidingFee(order.getUnlockTime(), order.getReturnTime(), rule, rule.getRidingRuleJson(), rentalUnit);
}else {
// 判断一个计费周期是否超过封顶费用如果超出 骑行费 = (第几个周期 - 1) * 封顶费用 + 骑行费
// 如果不超出骑行费 = 骑行费
@ -1687,17 +1689,54 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
// 如果超出 骑行费 = (第几个周期 - 1) * 封顶费用 + 骑行费
order.setCycle(cycle);
Date afterXHours = DateUtils.getTimeAfterXHours(order.getUnlockTime(), Integer.parseInt(chargingCycleValue)*(cycle-1));
BigDecimal remainingFee = calculateRidingFee(afterXHours, order, rule, rule.getRidingRuleJson(),rentalUnit);
BigDecimal remainingFee = calculateRidingFee(afterXHours, order.getReturnTime(), rule, rule.getRidingRuleJson(),rentalUnit);
ridingFee = new BigDecimal(cycle - 1).multiply(rule.getCappedAmount()).add(remainingFee);
}else{
ridingFee = calculateRidingFee(order.getUnlockTime(), order, rule, rule.getRidingRuleJson(), rentalUnit);
ridingFee = calculateRidingFee(order.getUnlockTime(), order.getReturnTime(), rule, rule.getRidingRuleJson(), rentalUnit);
}
}
order.setRidingFee(ridingFee);
}else if(ServiceConstants.CHARGING_CYCLE_CUSTOM.equals(chargingCycle)){//自定义时刻
// todo 自定义计费周期时刻 获取到自定义时刻判断骑行的这段时间是否在自定义时刻里 ____.___.___|___________|
// 如果不在
SimpleDateFormat timeFormat = new SimpleDateFormat(DateUtils.DATE_FORMAT_HHMMSS);
Calendar calendar = Calendar.getInstance();
calendar.setTime(order.getUnlockTime());
// 将自定义时间点设为当天
Date customTime = null;
try {
customTime = timeFormat.parse(chargingCycleValue);
} catch (ParseException e) {
e.printStackTrace();
}
if (customTime != null) {
calendar.set(Calendar.HOUR_OF_DAY, customTime.getHours());
calendar.set(Calendar.MINUTE, customTime.getMinutes());
calendar.set(Calendar.SECOND, customTime.getSeconds());
}
Date customCycleTime = calendar.getTime();
BigDecimal ridingFee;
if (order.getUnlockTime().before(customCycleTime) && endTime.after(customCycleTime)) {//如果自定义时间在骑行时间段内分段计算骑行费用并考虑封顶费用
BigDecimal firstPeriodFee = calculateRidingFee(order.getUnlockTime(), customCycleTime, rule, rule.getRidingRuleJson(), rentalUnit);
BigDecimal secondPeriodFee = calculateRidingFee(customCycleTime, endTime, rule, rule.getRidingRuleJson(), rentalUnit);
if (firstPeriodFee.compareTo(rule.getCappedAmount()) > 0) {
firstPeriodFee = rule.getCappedAmount();
}
if (secondPeriodFee.compareTo(rule.getCappedAmount()) > 0) {
secondPeriodFee = rule.getCappedAmount();
}
ridingFee = firstPeriodFee.add(secondPeriodFee);
} else {// 如果自定义时间不在骑行时间段内直接计算骑行费用并考虑封顶费用
ridingFee = calculateRidingFee(order.getUnlockTime(), endTime, rule, rule.getRidingRuleJson(), rentalUnit);
if (ridingFee.compareTo(rule.getCappedAmount()) > 0) {
ridingFee = rule.getCappedAmount();
}
}
order.setRidingFee(ridingFee);
}else{
if(rentalUnit.equals(ServiceConstants.RENTAL_UNIT_DAY)){
@ -1773,12 +1812,17 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
/**
* 计算骑行费
* @param unlockTime 开锁时间
* @param returnTime 还车时间
* @param rule 计费规则
* @param ridingRuleJson 起步价规则
* @param rentalUnit 租赁单位
*/
@NotNull
private BigDecimal calculateRidingFee(Date unlockTime, EtOrder order, EtFeeRule rule, String ridingRuleJson,String rentalUnit) {
private BigDecimal calculateRidingFee(Date unlockTime,Date returnTime, EtFeeRule rule, String ridingRuleJson,String rentalUnit) {
BigDecimal ridingFee = BigDecimal.ZERO;
//没有预约根据订单中的开锁时间计算费用骑行费用 ((还车时间-开锁时间转成分钟数)/ 时长分钟)-起步价分钟数 * 时长费 + 起步价
Date returnTime = order.getReturnTime();//还车时间
// Date returnTime = order.getReturnTime();//还车时间
//在免费骑行时间内骑行费为0
Integer minutes = DateUtils.timeDifferenceInMinutes(returnTime,unlockTime);//计算相隔多少分钟