@@ -450,10 +450,22 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
List<WxBillProperty> resultList = new ArrayList<>();
for (int i = 0; i < size; i++) {
Calendar instance = Calendar.getInstance();
instance.setTime(rentalStartDate);
//开始时间
instance.add(Calendar.MONTH, month * i);
Map<String, Object> resultMap = buildRent(leaseArr[i], receivePeriod, priceArr[i], instance.getTime(), Calendar.MONTH, wxPropertyContract, userId, wxMerchant, billcount, isPreview, shopInfo);
Date startDate;
//自然月
if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){
if(i == 0){ //第一期
startDate = rentalStartDate;
}else{
instance.setTime(rentalStartDate);
instance.add(Calendar.MONTH, month * i);
startDate = DateUtils.getFirstDayForCurrMonth(instance.getTime());
}
}else{
instance.setTime(rentalStartDate);
instance.add(Calendar.MONTH, month * i);
startDate = instance.getTime();
}
Map<String, Object> resultMap = buildRent(leaseArr[i], receivePeriod, priceArr[i], startDate, Calendar.MONTH, wxPropertyContract, userId, wxMerchant, billcount, isPreview, shopInfo,i==size-1?true:false);
List<WxBillProperty> billRentList = (List<WxBillProperty>)resultMap.get("billList");
billcount = (Integer)resultMap.get("billcount");
resultList.addAll(billRentList);
@@ -461,7 +473,15 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
return resultList;
}
public Map<String, Object> buildRent(int lease, int receivePeriod, int price, Date startdate, int dayType, WxPropertyContract wxPropertyContract, Long userId, WxMerchant wxMerchant, int billcount, Integer isPreview, Map<String, Object> shopInfo) {
public boolean isFirstDay(Date date){
int dateInt = Integer.parseInt(new SimpleDateFormat("d").format(date));
if(dateInt == 1){
return true;
}
return false;
}
public Map<String, Object> buildRent(int lease, int receivePeriod, int price, Date startdate, int dayType, WxPropertyContract wxPropertyContract, Long userId, WxMerchant wxMerchant, int billcount, Integer isPreview, Map<String, Object> shopInfo,boolean isLastYesr) {
Map<String,Object> resultMap = new HashedMap();
List<WxBillProperty> resultList = new ArrayList<>();
int extralease = lease % receivePeriod;
@@ -469,11 +489,15 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
int paycount = lease / receivePeriod + extracount;
int index = paycount - 1;
final IdWorker idWorker = IdWorker.get();
//自然月,周期为一个月 n+1
if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode()) && receivePeriod <= 1){
//自然月,而且残月,周期整除,n+1,最后一个周期作为残月
if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())
&& !isFirstDay(wxPropertyContract.getRentalStartDate())
&& (wxPropertyContract.getLease() % wxPropertyContract.getReceivePeriod() == 0)
&& isLastYesr
){
paycount ++;
}
for (int i = 0; i < paycount; i++) {
for(int i = 0; i < paycount; i++){
WxBillProperty wxBillProperty = new WxBillProperty();
wxBillProperty.setIsPreview(isPreview);
@@ -486,14 +510,18 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
Calendar instance = Calendar.getInstance();
instance.setTime(startdate);
instance.add(dayType, receivePeriod * i);
instance.add(Calendar.DAY_OF_MONTH, -1);
if(!wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) {
instance.add(Calendar.DAY_OF_MONTH, -1);
}
Date time = instance.getTime();
wxBillProperty.setReceiveDate(time);
//账单开始时间
instance.clear();
instance.setTime(wxBillProperty.getReceiveDate());
instance.add(Calendar.DAY_OF_MONTH, 1);
if(!wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) {
instance.add(Calendar.DAY_OF_MONTH, 1);
}
wxBillProperty.setStarttime(instance.getTime());
//账单结束时间
instance.clear();
@@ -506,7 +534,9 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
//账单开始时间
instance.clear();
instance.setTime(wxBillProperty.getReceiveDate());
instance.add(Calendar.DAY_OF_MONTH, 1);
if(!wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) {
instance.add(Calendar.DAY_OF_MONTH, 1);
}
wxBillProperty.setStarttime(instance.getTime());
//账单结束时间
instance.clear();
@@ -519,26 +549,48 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
//自然月,开始日期、缴款日,结束日期
if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){
int rentStartDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxPropertyContract.getRentalStartDate()));
int startDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxBillProperty.getStarttime()));
int endDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxPropertyContract.getRentalEndDate()));
if(i == 0){//第一周期
wxBillProperty.setReceiveDate(wxPropertyContract.getRentalStartDate());
wxBillProperty.setStarttime(wxPropertyContract.getRentalStartDate());
double oneDayProce = (double) price / DateUtils.getMonthDayCount(wxPropertyContract.getRentalStartDate());
int startDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxPropertyContract.getRentalStartDate()));
double oneDayProce = (double) price / DateUtils.getMonthDayCount(wxBillProperty.getStarttime());
double needPayDouble;
if(receivePeriod <= 1) {//周期为一个月
wxBillProperty.setEndtime(DateUtils.getLastDayForMonth(wxPropertyContract .getRental StartDa te()));
needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxPropertyContract .getRental StartDa te())-startDateInt+1);
wxBillProperty.setEndtime(DateUtils.getLastDayForMonth(wxBill Property.getStarttim e()));
needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxBill Property.getStarttim e())-startDateInt+1);
}else{ //周期大于一个月
wxBillProperty.setEndtime(DateUtils.getLastDayForMonth(wxPropertyContract.getRentalStartDate(),receivePeriod - 1));
// [A/31 *(31-12+1)]+A+A
needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxPropertyContract.getRentalStartDate())-startDateInt+1);
needPayDouble += price * (receivePeriod - 1);
Date firstDay = DateUtils.getFirstDayForCurrMonth(wxBillProperty.getStarttime());
instance.clear();
instance.setTime(firstDay);
//最后一个期有余,加上残月,不整除时,最后一个月有余,否则为0
if(extralease > 0 && (i == paycount - 1)){
instance.add(dayType, extralease);
instance.add(Calendar.DAY_OF_MONTH, rentStartDateInt-1);
}else{
instance.add(dayType, receivePeriod);
}
instance.add(Calendar.DAY_OF_MONTH, -1);
wxBillProperty.setEndtime(instance.getTime());
if(isLastYesr && (i == paycount - 1)){ //最后一年 最后一期
needPayDouble = 0;
oneDayProce = (double) price/DateUtils.getMonthDayCount(wxBillProperty.getEndtime());
if(receivePeriod > 1) {
needPayDouble += price * extralease;
}
needPayDouble += oneDayProce * endDateInt;
}else{
//[A/31 *(31-12+1)]+A+A
needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxBillProperty.getStarttime())-startDateInt+1);
needPayDouble += price * (receivePeriod - 1);
}
}
DecimalFormat format = new DecimalFormat("0");
needpay = Integer.parseInt(format.format(needPayDouble)); //分做四舍五入
}else if(i < paycount - 1){//中间周期
Date receiveDate = DateUtils.getFirstDayOfNextMonth(wxPropertyContract.getRentalStartDate(),receivePeriod * i);
Date receiveDate = DateUtils.getFirstDayOfNextMonth(startdate ,receivePeriod * i);
wxBillProperty.setReceiveDate(receiveDate);
wxBillProperty.setStarttime(receiveDate);
wxBillProperty.setEndtime(DateUtils.getLastDayForMonth(receiveDate,receivePeriod * i));
@@ -549,25 +601,27 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
instance.add(Calendar.DAY_OF_MONTH, -1);
wxBillProperty.setEndtime(instance.getTime());
}else if(i == paycount - 1) {//最后周期
Date receiveDate = DateUtils.getFirstDayOfNextMonth(wxPropertyContract.getRentalStartDate() ,receivePeriod * i);
Date receiveDate = DateUtils.getFirstDayOfNextMonth(startdate ,receivePeriod * i);
wxBillProperty.setReceiveDate(receiveDate);
wxBillProperty.setStarttime(receiveDate);
Date firstDay = DateUtils.getFirstDayForCurrMonth(wxBillProperty.getStarttime());
instance.clear();
instance.setTime(receiveDate);
instance.add(dayType, extracount>0?extralease:receivePeriod);//最后一期不足,一个完整周期
instance.setTime(firstDay);
//最后一期有余,加上残月,(不整除时,最后一个月有余,否则为0)
if(receivePeriod > 1) {
instance.add(dayType, extralease);
}
instance.add(Calendar.DAY_OF_MONTH, rentStartDateInt-1);
instance.add(Calendar.DAY_OF_MONTH, -1);
int endDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxPropertyContract.getEndDate()));
String endDateStr = DateUtils.date2String(instance.getTime(),"yyyy-MM")+ "-" +endDateInt;
wxBillProperty.setEndtime(DateUtils.stringToDate(endDateStr,"yyyy-MM-dd"));
wxBillProperty.setEndtime(instance.getTime());
double needPayDouble;
double needPayDouble = 0;
double oneDayProce = (double) price/DateUtils.getMonthDayCount(wxBillProperty.getEndtime());
if(receivePeriod <= 1) {//周期为一个月
needPayDouble = oneDayProce * endDateInt;
}else{
needPayDouble = price * (extralease-1);
needPayDouble += oneDayProce * endDateInt;
if(receivePeriod > 1) {
needPayDouble += price * extralease;
}
needPayDouble += oneDayProce * endDateInt;
DecimalFormat format = new DecimalFormat("0");
needpay = Integer.parseInt(format.format(needPayDouble)); //分做四舍五入
}
@@ -657,7 +711,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
result = buildRentMonth(wxMerchant, userId, propertyContract, receivePeriod, lease, rentalStartDate, price,isPreview);
} else {
//按日计租
Map<String, Object> resultMap = buildRent(lease, receivePeriod, price, rentalStartDate, Calendar.DAY_OF_MONTH, propertyContract, userId, wxMerchant, 0, isPreview, null);
Map<String, Object> resultMap = buildRent(lease, receivePeriod, price, rentalStartDate, Calendar.DAY_OF_MONTH, propertyContract, userId, wxMerchant, 0, isPreview, null,false );
result = (List<WxBillProperty>)resultMap.get("billList");
}
}