停車場管理中,最普遍最簡單的計費(fèi)規(guī)則當(dāng)屬24小時計費(fèi),也就是在按停車小時數(shù)計費(fèi). 收費(fèi)規(guī)則設(shè)置界面如下
24小時計費(fèi)規(guī)則并不復(fù)雜,方法輸入車輛進(jìn)出時間startTime、endTime文章來源:http://www.zghlxwxcb.cn/news/detail-614830.html
參考代碼Java文章來源地址http://www.zghlxwxcb.cn/news/detail-614830.html
public static BigDecimal chargin(HourChargingRule rule,LocalDateTime inTime,LocalDateTime endTime){
Duration between = Duration.between(inTime, endTime);
//相差分鐘數(shù)
long minutes = between.toMinutes();
if(rule.getFreeMin() >= minutes){
//未到收費(fèi)時長
return new BigDecimal(ChargingFinal.ZERO_FREE);
}
//停車時長在一天內(nèi)
if(minutes <= dayMin){
//判斷多少個小時
int s = (int)minutes / 60;
if(minutes % 60 >= rule.getTwoMin()){
s+=1;
}
return rule.getChargingHours().get(s - 1);
}
//1.計算滿24小時第一天費(fèi)用
BigDecimal totalMoney = rule.getChargingHours().get(23);//第一天費(fèi)用
//2.計算24小時后費(fèi)用
int day = (int) minutes / dayMin;
if(rule.getExceedMode() == 0 ){ //重復(fù)24小時計費(fèi)
totalMoney = totalMoney.multiply(new BigDecimal(day - 1));
//計算最后一個未滿24小時車費(fèi)
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){//每小時收費(fèi)
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;
}
到了這里,關(guān)于應(yīng)用于停車場的24小時計費(fèi)算法的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!