|
|
|
@@ -1,14 +1,13 @@ |
|
|
|
package com.iformall.service.helper; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.iformall.domain.po.WxEnergyFees; |
|
|
|
import com.iformall.domain.po.WxRentContract; |
|
|
|
import com.iformall.domain.vo.WxBillFeesStandardsListVo; |
|
|
|
import com.iformall.enums.*; |
|
|
|
import com.iformall.service.impl.WxRentContractServiceImpl; |
|
|
|
import com.iformall.utils.Constant; |
|
|
|
import com.iformall.utils.DateUtils; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Calendar; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.joda.time.DateTime; |
|
|
|
import org.joda.time.Months; |
|
|
|
@@ -17,13 +16,24 @@ import org.joda.time.format.DateTimeFormatter; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Calendar; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.iformall.domain.dto.NeedPayDTO; |
|
|
|
import com.iformall.domain.po.WxEnergyFees; |
|
|
|
import com.iformall.domain.po.WxRentContract; |
|
|
|
import com.iformall.domain.vo.WxBillFeesStandardsListVo; |
|
|
|
import com.iformall.enums.EnumContractReceivePeriodUnit; |
|
|
|
import com.iformall.enums.EnumFeesStandardsCalcuteUnit; |
|
|
|
import com.iformall.enums.EnumPriceUnit; |
|
|
|
import com.iformall.enums.EnumRentContractAdjustPeriod; |
|
|
|
import com.iformall.enums.EnumRentContractAdjustRatioWay; |
|
|
|
import com.iformall.enums.EnumRentContractRentInputWay; |
|
|
|
import com.iformall.enums.EnumRentContractType; |
|
|
|
import com.iformall.enums.EnumRentDayPriceCalcute; |
|
|
|
import com.iformall.enums.EnumYesOrNo; |
|
|
|
import com.iformall.service.impl.WxRentContractServiceImpl; |
|
|
|
import com.iformall.utils.Constant; |
|
|
|
import com.iformall.utils.DateUtils; |
|
|
|
|
|
|
|
public class WxRentContractHelper { |
|
|
|
|
|
|
|
@@ -340,17 +350,18 @@ public class WxRentContractHelper { |
|
|
|
} |
|
|
|
|
|
|
|
//查询月账单需要支付的金额 |
|
|
|
public static String getNeedPayMoney(WxRentContract wxRentContract,String price,Date startDate,Date endDate,int i,int billTimeVoListSize,boolean saveDb,int dayType,int receivePeriod,boolean part,boolean monthCalDay){ |
|
|
|
public static String getNeedPayMoney(List<Date> freeDays,WxRentContract wxRentContract,String price,Date startDate,Date endDate,int i,int billTimeVoListSize,boolean saveDb,int dayType,int receivePeriod){ |
|
|
|
String needpay; |
|
|
|
if (null == wxRentContract.getDecimalSize()) { |
|
|
|
wxRentContract.setDecimalSize(Constant.default_short_decimal_size); |
|
|
|
} |
|
|
|
EnumRentDayPriceCalcute priceCalcute = EnumRentDayPriceCalcute.getEnum(wxRentContract.getDayPriceCalcute()); |
|
|
|
|
|
|
|
//按日 |
|
|
|
if (wxRentContract.getPriceUnit().equals(EnumPriceUnit.D.getCode())){ |
|
|
|
BigDecimal priceD = new BigDecimal(price); |
|
|
|
|
|
|
|
String needpayD = WxRentContractHelper.getNeedPay(Constant.default_long_decimal_size,new BigDecimal(0),priceD,startDate,endDate,priceCalcute,wxRentContract.getMonthAverageDays()); |
|
|
|
String needpayD = WxRentContractHelper.getNeedPay(freeDays,Constant.default_long_decimal_size,new BigDecimal(0),priceD,startDate,endDate,priceCalcute,wxRentContract.getMonthAverageDays()); |
|
|
|
//取整 |
|
|
|
//needpay = new Double(needpayD).longValue(); |
|
|
|
//四舍五入 |
|
|
|
@@ -365,66 +376,13 @@ public class WxRentContractHelper { |
|
|
|
//生成金额直接计算 |
|
|
|
if(!saveDb){ |
|
|
|
//needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,part)).longValue(); |
|
|
|
needpay = new BigDecimal(getMonthNeedPay(Constant.default_long_decimal_size,priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays(),part)).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); |
|
|
|
needpay = new BigDecimal(getMonthNeedPay(freeDays,Constant.default_long_decimal_size,priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays())).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); |
|
|
|
return needpay; |
|
|
|
} |
|
|
|
|
|
|
|
SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM"); |
|
|
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
|
|
|
if(i == billTimeVoListSize - 1){//最后 |
|
|
|
//判断是否满足整月 |
|
|
|
Calendar instance = Calendar.getInstance(); |
|
|
|
instance.setTime(startDate); |
|
|
|
// instance.add(dayType, receivePeriod); |
|
|
|
// instance.add(Calendar.DATE, -1); |
|
|
|
instance = EnumContractReceivePeriodUnit.getAfterCalendarDay(instance, receivePeriod, dayType); |
|
|
|
if(sd.format(instance.getTime()).equals(sd.format(endDate))){ |
|
|
|
int months = WxRentContractHelper.getMonths(sdM.format(startDate)+"-01",sdM.format(DateUtils.getDaySet(endDate,Calendar.DATE,1))+"-01"); |
|
|
|
needpay = new BigDecimal(months).multiply(priceD).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); |
|
|
|
}else{ |
|
|
|
//needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue(); |
|
|
|
needpay = new BigDecimal(getMonthNeedPay(Constant.default_long_decimal_size,priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays(),false)) |
|
|
|
.setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); |
|
|
|
} |
|
|
|
}else if(i == 0){//第一期 |
|
|
|
if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ |
|
|
|
if(isFirstDay(startDate)){ |
|
|
|
int months = WxRentContractHelper.getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); |
|
|
|
months++; |
|
|
|
needpay = new BigDecimal(months).multiply(priceD).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); |
|
|
|
}else{ |
|
|
|
//needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue(); |
|
|
|
needpay = new BigDecimal(getMonthNeedPay(Constant.default_long_decimal_size,priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays(),false)) |
|
|
|
.setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
if(isFirstDay(startDate)){ |
|
|
|
int months = WxRentContractHelper.getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); |
|
|
|
if(isFirstDay(startDate)){ |
|
|
|
months++; |
|
|
|
} |
|
|
|
needpay = new BigDecimal(months).multiply(priceD).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); |
|
|
|
}else{ |
|
|
|
//needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue(); |
|
|
|
needpay = new BigDecimal(getMonthNeedPay(Constant.default_long_decimal_size,priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays(),false)) |
|
|
|
.setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); |
|
|
|
} |
|
|
|
} |
|
|
|
}else{//中间 |
|
|
|
int months = WxRentContractHelper.getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); |
|
|
|
if(isFirstDay(startDate)){ |
|
|
|
months++; |
|
|
|
} |
|
|
|
//如果当月费用需要按天计算 |
|
|
|
if (monthCalDay) { |
|
|
|
//needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue(); |
|
|
|
needpay = new BigDecimal(getMonthNeedPay(Constant.default_long_decimal_size,priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays(),false)) |
|
|
|
.setScale(wxRentContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP).toPlainString(); |
|
|
|
}else { |
|
|
|
needpay = new BigDecimal(months).multiply(priceD).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); |
|
|
|
} |
|
|
|
} |
|
|
|
//判断是否满足整月 |
|
|
|
needpay = new BigDecimal(getMonthNeedPay(freeDays,Constant.default_long_decimal_size,priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays())) |
|
|
|
.setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); |
|
|
|
} |
|
|
|
return needpay; |
|
|
|
} |
|
|
|
@@ -479,71 +437,113 @@ public class WxRentContractHelper { |
|
|
|
* @param end |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public static String getMonthNeedPay(Integer decimalSize,BigDecimal price,Date start,Date end,int dayType,int receivePeriod,Integer dayPriceCalcute,Integer monthAvageDays,boolean part){ |
|
|
|
public static String getMonthNeedPay(List<Date> freeDays,Integer decimalSize,BigDecimal price,Date start,Date end,int dayType,int receivePeriod,Integer dayPriceCalcute,Integer monthAvageDays){ |
|
|
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM"); |
|
|
|
SimpleDateFormat sdD = new SimpleDateFormat("d"); |
|
|
|
BigDecimal total = new BigDecimal(0); |
|
|
|
int[] diff; |
|
|
|
|
|
|
|
List<Date> allDaysFrees = DateUtils.getAllDays(start, end); |
|
|
|
if (null == allDaysFrees) { |
|
|
|
return "0"; |
|
|
|
} |
|
|
|
List<Date> validDays = new ArrayList<Date>(); |
|
|
|
validDays.addAll(allDaysFrees); |
|
|
|
if (null != freeDays && freeDays.size() > 0 ) { |
|
|
|
allDaysFrees.retainAll(freeDays); |
|
|
|
} |
|
|
|
if (null != freeDays && freeDays.size() > 0 && null != allDaysFrees && allDaysFrees.size() > 0 ) { |
|
|
|
validDays.removeAll(allDaysFrees); |
|
|
|
} |
|
|
|
if (validDays.size() <= 0 ) { |
|
|
|
return "0"; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//同一天 |
|
|
|
if(sd.format(start).equals(sd.format(end))){ |
|
|
|
int dayCount = getRealDays(dayPriceCalcute, monthAvageDays, start); |
|
|
|
return price.divide(new BigDecimal(dayCount),decimalSize,BigDecimal.ROUND_HALF_UP).toPlainString(); |
|
|
|
|
|
|
|
if (validDays.contains(start)) { |
|
|
|
int dayCount = getRealDays(dayPriceCalcute, monthAvageDays, start); |
|
|
|
return price.divide(new BigDecimal(dayCount),decimalSize,BigDecimal.ROUND_HALF_UP).toPlainString(); |
|
|
|
}else { |
|
|
|
return "0"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//同月 |
|
|
|
if(sdM.format(start).equals(sdM.format(end))){ |
|
|
|
|
|
|
|
diff = DateUtils.getDiff(start,end); |
|
|
|
int dayCount = getRealDays(dayPriceCalcute, monthAvageDays, start); |
|
|
|
total = total.add(new BigDecimal((diff[1]+1)).multiply(price).divide(new BigDecimal(dayCount),decimalSize,BigDecimal.ROUND_HALF_UP)); |
|
|
|
return total.toPlainString(); |
|
|
|
NeedPayDTO np = getMonthPay(start, end, price, decimalSize, validDays, dayPriceCalcute, monthAvageDays); |
|
|
|
return np.getMoney().toPlainString(); |
|
|
|
} |
|
|
|
|
|
|
|
//判断是否满足整月 |
|
|
|
boolean isFullMonth = false; |
|
|
|
if(part){ |
|
|
|
int startInt = Integer.parseInt(sdD.format(start)); |
|
|
|
int endInt = Integer.parseInt(sdD.format(DateUtils.getDaySet(end,Calendar.DATE,1))); |
|
|
|
if(startInt == endInt){ |
|
|
|
isFullMonth = true; |
|
|
|
} |
|
|
|
}else{ |
|
|
|
Calendar instance = Calendar.getInstance(); |
|
|
|
instance.setTime(start); |
|
|
|
// instance.add(dayType, receivePeriod); |
|
|
|
// instance.add(Calendar.DATE, -1); |
|
|
|
instance = EnumContractReceivePeriodUnit.getAfterCalendarDay(instance, receivePeriod, dayType); |
|
|
|
if(sd.format(instance.getTime()).equals(sd.format(end))){ |
|
|
|
isFullMonth = true; |
|
|
|
} |
|
|
|
Calendar instance = Calendar.getInstance(); |
|
|
|
instance.setTime(start); |
|
|
|
instance = EnumContractReceivePeriodUnit.getAfterCalendarDay(instance, receivePeriod, dayType); |
|
|
|
if(sd.format(instance.getTime()).equals(sd.format(end))){ |
|
|
|
//不是一个月的。但是按整月算的 |
|
|
|
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()); |
|
|
|
} |
|
|
|
return total.toPlainString(); |
|
|
|
} |
|
|
|
|
|
|
|
if(isFullMonth){ |
|
|
|
int months = getMonths(sdM.format(start)+"-01",sdM.format(DateUtils.getDaySet(end,Calendar.DATE,1))+"-01"); |
|
|
|
return new BigDecimal(months).multiply(price).setScale(decimalSize, RoundingMode.HALF_UP).toPlainString(); |
|
|
|
} |
|
|
|
|
|
|
|
//第一个月 |
|
|
|
|
|
|
|
//开始到这个月底 |
|
|
|
Date lastMonthDay = DateUtils.getLastDayForMonth(start); |
|
|
|
diff = DateUtils.getDiff(start,lastMonthDay); |
|
|
|
int dayCount = getRealDays(dayPriceCalcute, monthAvageDays, start); |
|
|
|
total = total.add(new BigDecimal((diff[1]+1)).multiply(price).divide(new BigDecimal(dayCount),decimalSize,BigDecimal.ROUND_HALF_UP)); |
|
|
|
|
|
|
|
NeedPayDTO np = getMonthPay(start, lastMonthDay, price, decimalSize, validDays, dayPriceCalcute, monthAvageDays); |
|
|
|
total = total.add(np.getMoney()); |
|
|
|
|
|
|
|
//中间月份 |
|
|
|
Date newStartDate = DateUtils.getDaySet(lastMonthDay,Calendar.DATE,1); |
|
|
|
int months = getMonths(sdM.format(newStartDate)+"-01",sdM.format(end)+"-01"); |
|
|
|
total = total.add(new BigDecimal(months).multiply(price)); |
|
|
|
|
|
|
|
int months = getMonths(sdM.format(newStartDate)+"-01",sdM.format(end)+"-01"); |
|
|
|
for (int i = 0 ; i < months; i++) { |
|
|
|
Date currentMonthEnd = DateUtils.getLastDayForMonth(newStartDate); |
|
|
|
NeedPayDTO _np = getMonthPay(newStartDate, currentMonthEnd, price, decimalSize, validDays, dayPriceCalcute, monthAvageDays); |
|
|
|
newStartDate = DateUtils.getDaySet(currentMonthEnd,Calendar.DATE,1); |
|
|
|
total = total.add(_np.getMoney()); |
|
|
|
} |
|
|
|
|
|
|
|
//最后一个月 |
|
|
|
diff = DateUtils.getDiff(DateUtils.getFirstDayForCurrMonth(end),end); |
|
|
|
dayCount = getRealDays(dayPriceCalcute, monthAvageDays, end); |
|
|
|
total = total.add(new BigDecimal((diff[1]+1)).multiply(price).divide(new BigDecimal(dayCount),decimalSize,BigDecimal.ROUND_HALF_UP)); |
|
|
|
if (newStartDate.before(end)) { |
|
|
|
NeedPayDTO enp = getMonthPay(DateUtils.getFirstDayForCurrMonth(end), end, price, decimalSize, validDays, dayPriceCalcute, monthAvageDays); |
|
|
|
total = total.add(enp.getMoney()); |
|
|
|
} |
|
|
|
return total.toPlainString(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static NeedPayDTO getMonthPay(Date start,Date end, BigDecimal priceMonth,Integer decimalSize,List<Date> validDays,Integer dayPriceCalcute,Integer monthAvageDays) { |
|
|
|
NeedPayDTO np = new NeedPayDTO(); |
|
|
|
//当月实际天数 |
|
|
|
int md = DateUtils.getMonthDayCount(start);; |
|
|
|
//在有效的时间里面有多少天 |
|
|
|
int ms = getDays(end,validDays); |
|
|
|
|
|
|
|
//计算天数 |
|
|
|
int dayCount = getRealDays(dayPriceCalcute, monthAvageDays, start); |
|
|
|
int sed = DateUtils.daysBetween(start,end)+1; |
|
|
|
|
|
|
|
//满月 |
|
|
|
if (md == sed) { |
|
|
|
//如果有免租的,则按天算 |
|
|
|
if (ms == md) { |
|
|
|
np.setFullMonth(true); |
|
|
|
np.setMoney(priceMonth); |
|
|
|
}else { |
|
|
|
np.setFullMonth(false); |
|
|
|
np.setMoney(new BigDecimal(ms).multiply(priceMonth).divide(new BigDecimal(dayCount),decimalSize,BigDecimal.ROUND_HALF_UP)); |
|
|
|
} |
|
|
|
}else { |
|
|
|
np.setFullMonth(false); |
|
|
|
np.setMoney(new BigDecimal(ms).multiply(priceMonth).divide(new BigDecimal(dayCount),decimalSize,BigDecimal.ROUND_HALF_UP)); |
|
|
|
} |
|
|
|
return np; |
|
|
|
} |
|
|
|
|
|
|
|
private static int getRealDays(Integer dayPriceCalcute,Integer monthAvageDays,Date start) { |
|
|
|
//是不是按实际天数来计算 |
|
|
|
boolean isRealDays = true; |
|
|
|
@@ -582,12 +582,30 @@ public class WxRentContractHelper { |
|
|
|
* @param end |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public static String getNeedPay(Integer decimalSize,BigDecimal monthPrice,BigDecimal dayPrice,Date start,Date end,EnumRentDayPriceCalcute priceCalcute,Integer monthDays){ |
|
|
|
public static String getNeedPay(List<Date> freeDays,Integer decimalSize,BigDecimal monthPrice,BigDecimal dayPrice,Date start,Date end,EnumRentDayPriceCalcute priceCalcute,Integer monthDays){ |
|
|
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM"); |
|
|
|
BigDecimal total; |
|
|
|
int[] diff; |
|
|
|
|
|
|
|
List<Date> allDaysFrees = DateUtils.getAllDays(start, end); |
|
|
|
if (null == allDaysFrees) { |
|
|
|
return "0"; |
|
|
|
} |
|
|
|
List<Date> validDays = new ArrayList<Date>(); |
|
|
|
validDays.addAll(allDaysFrees); |
|
|
|
//取交集 |
|
|
|
if (null != freeDays && freeDays.size() > 0 ) { |
|
|
|
allDaysFrees.retainAll(freeDays); |
|
|
|
} |
|
|
|
//剩下的都是计费的 |
|
|
|
if (null != freeDays && freeDays.size() > 0 && null != allDaysFrees && allDaysFrees.size() > 0 ) { |
|
|
|
validDays.removeAll(allDaysFrees); |
|
|
|
} |
|
|
|
if (validDays.size() <= 0 ) { |
|
|
|
return "0"; |
|
|
|
} |
|
|
|
|
|
|
|
int dayCount = getRealMonthDays(priceCalcute,monthDays,start); |
|
|
|
BigDecimal price; |
|
|
|
if(monthPrice.compareTo(new BigDecimal(0)) > 0){ |
|
|
|
@@ -598,17 +616,25 @@ public class WxRentContractHelper { |
|
|
|
|
|
|
|
//同一天 |
|
|
|
if(sd.format(start).equals(sd.format(end))){ |
|
|
|
return price.toPlainString(); //算1天 |
|
|
|
if (validDays.contains(start)) { |
|
|
|
return price.toPlainString(); //算1天 |
|
|
|
}else { |
|
|
|
return "0"; |
|
|
|
} |
|
|
|
} |
|
|
|
//同月 |
|
|
|
if(sdM.format(start).equals(sdM.format(end))){ |
|
|
|
diff = DateUtils.getDiff(start,end); |
|
|
|
return new BigDecimal((diff[1]+1)).multiply(price).setScale(decimalSize, BigDecimal.ROUND_HALF_UP).toPlainString(); |
|
|
|
//diff = DateUtils.getDiff(start,end); |
|
|
|
//return new BigDecimal((diff[1]+1)).multiply(price).setScale(decimalSize, BigDecimal.ROUND_HALF_UP).toPlainString(); |
|
|
|
return new BigDecimal(validDays.size()).multiply(price).setScale(decimalSize, BigDecimal.ROUND_HALF_UP).toPlainString(); |
|
|
|
} |
|
|
|
|
|
|
|
//当月截止 |
|
|
|
Date currEnd = DateUtils.getLastDayForMonth(start); |
|
|
|
diff = DateUtils.getDiff(start,currEnd); |
|
|
|
total = new BigDecimal((diff[1]+1)).multiply(price).setScale(decimalSize, BigDecimal.ROUND_HALF_UP); |
|
|
|
//diff = DateUtils.getDiff(start,currEnd); |
|
|
|
//total = new BigDecimal((diff[1]+1)).multiply(price).setScale(decimalSize, BigDecimal.ROUND_HALF_UP); |
|
|
|
int ds = getDays(currEnd,validDays); |
|
|
|
total = new BigDecimal(ds).multiply(price).setScale(decimalSize, BigDecimal.ROUND_HALF_UP); |
|
|
|
|
|
|
|
int warnCount = 0; |
|
|
|
while (true){ |
|
|
|
@@ -623,13 +649,17 @@ public class WxRentContractHelper { |
|
|
|
|
|
|
|
//最后一个月 |
|
|
|
if(sdM.format(monthStartDate).equals(sdM.format(end))){ |
|
|
|
diff = DateUtils.getDiff(monthStartDate,end); |
|
|
|
total = total.add(price.multiply(new BigDecimal((diff[1]+1))).setScale(decimalSize, BigDecimal.ROUND_HALF_UP)); |
|
|
|
int ms = getDays(end,validDays); |
|
|
|
//diff = DateUtils.getDiff(monthStartDate,end); |
|
|
|
//total = total.add(price.multiply(new BigDecimal((diff[1]+1))).setScale(decimalSize, BigDecimal.ROUND_HALF_UP)); |
|
|
|
total = total.add(price.multiply(new BigDecimal(ms)).setScale(decimalSize, BigDecimal.ROUND_HALF_UP)); |
|
|
|
break; |
|
|
|
}else{ |
|
|
|
currEnd = DateUtils.getLastDayForMonth(monthStartDate); |
|
|
|
diff = DateUtils.getDiff(monthStartDate,currEnd); |
|
|
|
total = total.add(price.multiply(new BigDecimal((diff[1]+1))).setScale(decimalSize, BigDecimal.ROUND_HALF_UP)); |
|
|
|
//diff = DateUtils.getDiff(monthStartDate,currEnd); |
|
|
|
//total = total.add(price.multiply(new BigDecimal((diff[1]+1))).setScale(decimalSize, BigDecimal.ROUND_HALF_UP)); |
|
|
|
int ms = getDays(currEnd,validDays); |
|
|
|
total = total.add(price.multiply(new BigDecimal(ms)).setScale(decimalSize, BigDecimal.ROUND_HALF_UP)); |
|
|
|
} |
|
|
|
|
|
|
|
//预警 |
|
|
|
@@ -642,5 +672,25 @@ public class WxRentContractHelper { |
|
|
|
} |
|
|
|
return total.setScale(decimalSize, BigDecimal.ROUND_HALF_UP).toPlainString(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static int getDays(Date end,List<Date> allDays) { |
|
|
|
if (null == allDays || allDays.size() <= 0 ) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
List<Date> _tempList = new ArrayList<Date>(); |
|
|
|
_tempList.addAll(allDays); |
|
|
|
Date _end = DateUtils.getDayBegin(end); |
|
|
|
for (int i = 0 ; i < _tempList.size(); i ++) { |
|
|
|
Date a = _tempList.get(i); |
|
|
|
if (a.equals(_end)) { |
|
|
|
allDays.remove(a); |
|
|
|
return i+1; |
|
|
|
}else if (a.after(_end)) { |
|
|
|
return i; |
|
|
|
}else { |
|
|
|
allDays.remove(a); |
|
|
|
} |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |