停车场管理中,最普遍最简单的计费规则当属24小时计费,也就是在按停车小时数计费. 收费规则设置界面如下
24小时计费规则并不复杂,方法输入车辆进出时间startTime、endTime文章来源:https://www.toymoban.com/news/detail-614830.html
参考代码Java文章来源地址https://www.toymoban.com/news/detail-614830.html
public static BigDecimal chargin(HourChargingRule rule,LocalDateTime inTime,LocalDateTime endTime){
Duration between = Duration.between(inTime, endTime);
//相差分钟数
long minutes = between.toMinutes();
if(rule.getFreeMin() >= minutes){
//未到收费时长
return new BigDecimal(ChargingFinal.ZERO_FREE);
}
//停车时长在一天内
if(minutes <= dayMin){
//判断多少个小时
int s = (int)minutes / 60;
if(minutes % 60 >= rule.getTwoMin()){
s+=1;
}
return rule.getChargingHours().get(s - 1);
}
//1.计算满24小时第一天费用
BigDecimal totalMoney = rule.getChargingHours().get(23);//第一天费用
//2.计算24小时后费用
int day = (int) minutes / dayMin;
if(rule.getExceedMode() == 0 ){ //重复24小时计费
totalMoney = totalMoney.multiply(new BigDecimal(day - 1));
//计算最后一个未满24小时车费
int lastMin = (int) minutes % dayMin;
if(lastMin > rule.getTwoMin()){
int hours = lastMin / 60;
if(lastMin % 60 >= rule.getTwoMin()){
hours+=1;
}
totalMoney = totalMoney.add(rule.getChargingHours().get(hours - 1));
}
}else if(rule.getExceedMode() == 1){//每小时收费
int lastMin = (int)minutes % dayMin;
if(lastMin >= rule.getTwoMin()){
int hours = lastMin / 60;
if(lastMin % 60 >= rule.getTwoMin()){
hours+=1;
}
totalMoney = totalMoney.add(BigDecimal.valueOf(hours * rule.getExceedValue()));
}
}else if(rule.getExceedValue() == 2){
totalMoney = totalMoney.multiply(new BigDecimal(day - 1));
int lastMin = (int)minutes % dayMin;
if(lastMin >= rule.getTwoMin()){
totalMoney = totalMoney.add(rule.getChargingHours().get(23));
}
}
return totalMoney;
}
到了这里,关于应用于停车场的24小时计费算法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!