|
|
|
@@ -468,29 +468,65 @@ public class WxRentContractHelper { |
|
|
|
if (null == validDays || validDays.size() <= 0 ) { |
|
|
|
return "0"; |
|
|
|
} |
|
|
|
NeedPayDTO np = getMonthPay(start, end, price, decimalSize, validDays, dayPriceCalcute, monthAvageDays); |
|
|
|
NeedPayDTO np = getCurrentMonthPay(start, end, price, decimalSize, validDays, dayPriceCalcute, monthAvageDays); |
|
|
|
return np.getMoney().toPlainString(); |
|
|
|
} |
|
|
|
|
|
|
|
Calendar instance = Calendar.getInstance(); |
|
|
|
instance.setTime(start); |
|
|
|
instance = EnumContractReceivePeriodUnit.getAfterCalendarDay(instance, receivePeriod, dayType); |
|
|
|
if(sd.format(instance.getTime()).equals(sd.format(end))){ |
|
|
|
List<Date> validDays = getValidDays(start,end,freeDays); |
|
|
|
if (null == validDays || validDays.size() <= 0 ) { |
|
|
|
return "0"; |
|
|
|
} |
|
|
|
//不是一个月的。但是按整月算的 |
|
|
|
int months = getMonths(sdM.format(start)+"-01",sdM.format(DateUtils.getDaySet(end,Calendar.DATE,1))+"-01"); |
|
|
|
for (int i = 0 ; i < months; i++) { |
|
|
|
//当前时间到当前月底 |
|
|
|
Date currentMonthEnd = DateUtils.getLastDayForMonth(start); |
|
|
|
NeedPayDTO np = getMonthPay(start, currentMonthEnd, price, decimalSize, validDays, dayPriceCalcute, monthAvageDays); |
|
|
|
start = DateUtils.getDaySet(currentMonthEnd,Calendar.DATE,1); |
|
|
|
total = total.add(np.getMoney()); |
|
|
|
//TODO 这个月底到下个月 |
|
|
|
//正好是一个周期开始 |
|
|
|
boolean isPeriodStart = false; |
|
|
|
//如果是按自然季度,如果start不是1号,则也不是一个周期 |
|
|
|
if (EnumContractReceivePeriodUnit.QUARTER.getCode().intValue() == dayType) { |
|
|
|
String startday = sdD.format(start); |
|
|
|
if ("1".equals(startday)) { |
|
|
|
isPeriodStart = true; |
|
|
|
} |
|
|
|
return total.toPlainString(); |
|
|
|
}else { |
|
|
|
isPeriodStart = true; |
|
|
|
} |
|
|
|
if (isPeriodStart) { |
|
|
|
Calendar instance = Calendar.getInstance(); |
|
|
|
instance.setTime(start); |
|
|
|
instance = EnumContractReceivePeriodUnit.getAfterCalendarDay(instance, receivePeriod, dayType); |
|
|
|
if(sd.format(instance.getTime()).equals(sd.format(end))){ |
|
|
|
List<Date> validDays = getValidDays(start,end,freeDays); |
|
|
|
if (null == validDays || validDays.size() <= 0 ) { |
|
|
|
return "0"; |
|
|
|
} |
|
|
|
//如果该周期内是全部有效的,则用月份*金额 |
|
|
|
int allDays = DateUtils.daysBetween(start,end)+1; |
|
|
|
boolean isFull = false; |
|
|
|
if (allDays == validDays.size()) { |
|
|
|
isFull = true; |
|
|
|
} |
|
|
|
//不是一个月的。但是按整月算的 |
|
|
|
int months = getMonths(sdM.format(start)+"-01",sdM.format(DateUtils.getDaySet(end,Calendar.DATE,1))+"-01"); |
|
|
|
if (isFull) { |
|
|
|
return price.multiply(new BigDecimal(months)).toPlainString(); |
|
|
|
} |
|
|
|
//计费每个周期开始时间 |
|
|
|
Calendar periodStart = Calendar.getInstance(); |
|
|
|
periodStart.setTime(start); |
|
|
|
for (int i = 0 ; i < months; i++) { |
|
|
|
//每个计费1个月结束时间,可能是跨月的 |
|
|
|
Date periodEnd = EnumContractReceivePeriodUnit.getAfterCalendarDay(periodStart, i+1, EnumContractReceivePeriodUnit.MONTH.getCode()).getTime(); |
|
|
|
|
|
|
|
//当前开始时间到当前月底 |
|
|
|
Date currentMonthEnd = DateUtils.getLastDayForMonth(start); |
|
|
|
NeedPayDTO np = getCurrentMonthPay(start, currentMonthEnd, price, decimalSize, validDays, dayPriceCalcute, monthAvageDays); |
|
|
|
total = total.add(np.getMoney()); |
|
|
|
|
|
|
|
if(periodEnd.after(currentMonthEnd)) { |
|
|
|
start = DateUtils.getDaySet(currentMonthEnd,Calendar.DATE,1); |
|
|
|
NeedPayDTO lnp = getCurrentMonthPay(start, periodEnd, price, decimalSize, validDays, dayPriceCalcute, monthAvageDays); |
|
|
|
total = total.add(lnp.getMoney()); |
|
|
|
}else { |
|
|
|
start = DateUtils.getDaySet(currentMonthEnd,Calendar.DATE,1); |
|
|
|
periodStart.setTime(start); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return total.toPlainString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//开始到这个月底 |
|
|
|
@@ -499,7 +535,7 @@ public class WxRentContractHelper { |
|
|
|
if (null == currValidDays || currValidDays.size() <= 0 ) { |
|
|
|
return "0"; |
|
|
|
} |
|
|
|
NeedPayDTO np = getMonthPay(start, lastMonthDay, price, decimalSize, currValidDays, dayPriceCalcute, monthAvageDays); |
|
|
|
NeedPayDTO np = getCurrentMonthPay(start, lastMonthDay, price, decimalSize, currValidDays, dayPriceCalcute, monthAvageDays); |
|
|
|
total = total.add(np.getMoney()); |
|
|
|
System.out.println("首1月>>>>"+DateUtils.date2String(start)+">>>"+DateUtils.date2String(lastMonthDay)+">>>>"+total.toPlainString()); |
|
|
|
|
|
|
|
@@ -511,7 +547,7 @@ public class WxRentContractHelper { |
|
|
|
List<Date> _validDays = getValidDays(newStartDate,currentMonthEnd,freeDays); |
|
|
|
if (null == _validDays ||_validDays.size() <= 0 ) { |
|
|
|
}else { |
|
|
|
NeedPayDTO _np = getMonthPay(newStartDate, currentMonthEnd, price, decimalSize, _validDays, dayPriceCalcute, monthAvageDays); |
|
|
|
NeedPayDTO _np = getCurrentMonthPay(newStartDate, currentMonthEnd, price, decimalSize, _validDays, dayPriceCalcute, monthAvageDays); |
|
|
|
System.out.println(i+2+"月>>>>"+DateUtils.date2String(newStartDate)+">>>>"+DateUtils.date2String(currentMonthEnd)+">>>>"+_np.getMoney().toPlainString()); |
|
|
|
newStartDate = DateUtils.getDaySet(currentMonthEnd,Calendar.DATE,1); |
|
|
|
total = total.add(_np.getMoney()); |
|
|
|
@@ -525,7 +561,7 @@ public class WxRentContractHelper { |
|
|
|
if (null == lastValidDays || lastValidDays.size() <= 0 ) { |
|
|
|
return "0"; |
|
|
|
} |
|
|
|
NeedPayDTO enp = getMonthPay(last, end, price, decimalSize, lastValidDays, dayPriceCalcute, monthAvageDays); |
|
|
|
NeedPayDTO enp = getCurrentMonthPay(last, end, price, decimalSize, lastValidDays, dayPriceCalcute, monthAvageDays); |
|
|
|
total = total.add(enp.getMoney()); |
|
|
|
System.out.println("末月>>>>"+DateUtils.date2String(last)+">>>"+DateUtils.date2String(end)+">>>>"+enp.getMoney().toPlainString()); |
|
|
|
} |
|
|
|
@@ -551,7 +587,8 @@ public class WxRentContractHelper { |
|
|
|
return validDays; |
|
|
|
} |
|
|
|
|
|
|
|
private static NeedPayDTO getMonthPay(Date start,Date end, BigDecimal priceMonth,Integer decimalSize,List<Date> validDays,Integer dayPriceCalcute,Integer monthAvageDays) { |
|
|
|
//查询当前月内的金额 |
|
|
|
private static NeedPayDTO getCurrentMonthPay(Date start,Date end, BigDecimal priceMonth,Integer decimalSize,List<Date> validDays,Integer dayPriceCalcute,Integer monthAvageDays) { |
|
|
|
NeedPayDTO np = new NeedPayDTO(); |
|
|
|
//当月实际天数 |
|
|
|
int md = DateUtils.getMonthDayCount(start);; |
|
|
|
@@ -762,7 +799,6 @@ public class WxRentContractHelper { |
|
|
|
|
|
|
|
//String monthMoney = getMonthNeedPay(freeDays, 2, new BigDecimal(2000), start, end, EnumContractReceivePeriodUnit.QUARTER.getCode(), 1, EnumRentDayPriceCalcute.AVERAGE_DAYS.getCode(), 30); |
|
|
|
//System.out.println(monthMoney); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |