|
|
|
@@ -267,9 +267,13 @@ public class WxBillRentServiceImpl implements WxBillRentService { |
|
|
|
* ["1000-1200:10",">3000:20"] |
|
|
|
* @param record |
|
|
|
*/ |
|
|
|
public Integer getPayRatio(WxBillRent record,WxRentContract wxRentContract){ |
|
|
|
public Integer getPayRatio(WxBillRent record,WxRentContract wxRentContract,EnumMissTimeType timeType){ |
|
|
|
if(wxRentContract.getPayRatio() != null){ |
|
|
|
return wxRentContract.getPayRatio(); |
|
|
|
} |
|
|
|
BigDecimal revenue = new BigDecimal(record.getRevenue()).divide(new BigDecimal(1000000)).setScale(4, RoundingMode.HALF_EVEN); |
|
|
|
List<String> ratioList = JSONArray.parseArray(wxRentContract.getBusDiscountRatio(), String.class); |
|
|
|
long dayCount = DateUtils.startToEnd(record.getStarttime(),record.getEndtime()); |
|
|
|
|
|
|
|
for (String e:ratioList) { |
|
|
|
String[] array = e.split(":"); |
|
|
|
@@ -279,12 +283,28 @@ public class WxBillRentServiceImpl implements WxBillRentService { |
|
|
|
String[] revenueArray = array[0].split("-"); |
|
|
|
BigDecimal start = new BigDecimal(revenueArray[0]); |
|
|
|
BigDecimal end = new BigDecimal(revenueArray[1]); |
|
|
|
|
|
|
|
//残年 (小金额 / 365 * 账单周期天数 )--(大金额 / 365 * 账单周期天数) |
|
|
|
if(EnumMissTimeType.YEAR.getCode().equals(timeType.getCode())){ |
|
|
|
start = new BigDecimal(revenueArray[0]).divide(new BigDecimal(365)).multiply(new BigDecimal(dayCount)); |
|
|
|
end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365)).multiply(new BigDecimal(dayCount)); |
|
|
|
}else if(EnumMissTimeType.MONTH.getCode().equals(timeType.getCode())){ |
|
|
|
start = new BigDecimal(revenueArray[0]).divide(new BigDecimal(30)).multiply(new BigDecimal(dayCount)); |
|
|
|
end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30)).multiply(new BigDecimal(dayCount)); |
|
|
|
} |
|
|
|
if (revenue.compareTo(start) >= 0 && revenue.compareTo(end)<= 0){ |
|
|
|
return ratio; |
|
|
|
} |
|
|
|
}if(e.indexOf(">") >= 0){ |
|
|
|
String[] revenueArray = array[0].split(">"); |
|
|
|
BigDecimal end = new BigDecimal(revenueArray[1]); |
|
|
|
|
|
|
|
//残年 (小金额 / 365 * 账单周期天数 )--(大金额 / 365 * 账单周期天数) |
|
|
|
if(EnumMissTimeType.YEAR.getCode().equals(timeType.getCode())){ |
|
|
|
end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365)).multiply(new BigDecimal(dayCount)); |
|
|
|
}else if(EnumMissTimeType.MONTH.getCode().equals(timeType.getCode())){ |
|
|
|
end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30)).multiply(new BigDecimal(dayCount)); |
|
|
|
} |
|
|
|
if (revenue.compareTo(end) >= 0){ |
|
|
|
return ratio; |
|
|
|
} |
|
|
|
@@ -300,39 +320,42 @@ public class WxBillRentServiceImpl implements WxBillRentService { |
|
|
|
WxRentContract wxRentContract = wxRentContractMapper.selectByPrimaryKey(record.getRentContractId()); |
|
|
|
SimpleDateFormat sdD = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM"); |
|
|
|
Integer ratio = getPayRatio(record,wxRentContract); |
|
|
|
|
|
|
|
int startInt = Integer.parseInt(sdD.format(wxBillRent.getStarttime())); |
|
|
|
int endInt = Integer.parseInt(sdD.format(DateUtils.getDaySet(wxBillRent.getEndtime(),Calendar.DATE,1))); |
|
|
|
int months = getMonths(sdM.format(wxBillRent.getStarttime())+"-01",sdM.format(DateUtils.getDaySet(wxBillRent.getEndtime(),Calendar.DATE,1))+"-01"); |
|
|
|
|
|
|
|
if(EnumBusRatioTime.YEAR.getCode().equals(wxRentContract.getBusDiscountTime())){ |
|
|
|
if(startInt == endInt && months == 12){ |
|
|
|
//刚好1年 |
|
|
|
BigDecimal hundred = new BigDecimal(100); |
|
|
|
BigDecimal revenue = new BigDecimal(record.getRevenue() == null ? 0 : record.getRevenue()).divide(hundred); |
|
|
|
BigDecimal payRatio = new BigDecimal(ratio).divide(new BigDecimal(10000)); |
|
|
|
BigDecimal price = revenue.multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); |
|
|
|
long newReceivePay = price.multiply(hundred).longValue(); |
|
|
|
|
|
|
|
}else{ |
|
|
|
Integer ratio = getPayRatio(record,wxRentContract,null); |
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(wxRentContract.getBusDiscountRatio())){ |
|
|
|
if(EnumBusRatioTime.YEAR.getCode().equals(wxRentContract.getBusDiscountTime())){ |
|
|
|
if(startInt == endInt && months == 12){ |
|
|
|
//刚好1年 |
|
|
|
}else{ |
|
|
|
ratio = getPayRatio(record,wxRentContract,EnumMissTimeType.YEAR); |
|
|
|
} |
|
|
|
}else if(EnumBusRatioTime.MONTH.getCode().equals(wxRentContract.getBusDiscountTime())){ |
|
|
|
if(startInt == endInt && months == 1){ |
|
|
|
//刚好1个月 |
|
|
|
}else{ |
|
|
|
ratio = getPayRatio(record,wxRentContract,EnumMissTimeType.MONTH); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}else if(EnumBusRatioTime.MONTH.getCode().equals(wxRentContract.getBusDiscountTime())){ |
|
|
|
if(startInt == endInt && months == 1){ |
|
|
|
//刚好1个月 |
|
|
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
} |
|
|
|
BigDecimal hundred = new BigDecimal(100); |
|
|
|
BigDecimal revenue = new BigDecimal(record.getRevenue() == null ? 0 : record.getRevenue()).divide(hundred); |
|
|
|
BigDecimal payRatio = new BigDecimal(ratio).divide(new BigDecimal(10000)); |
|
|
|
BigDecimal price = revenue.multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); |
|
|
|
long newReceivePay = price.multiply(hundred).longValue(); |
|
|
|
if(newReceivePay > wxBillRent.getReceivePay()){ |
|
|
|
wxBillRent.setReceivePay(newReceivePay); |
|
|
|
} |
|
|
|
|
|
|
|
Long oldPrice = wxBillRent.getReceivePay(); |
|
|
|
Long newPrice = record.getReceivePay(); |
|
|
|
wxBillRent.setRevenue(record.getRevenue()); |
|
|
|
wxBillRent.setReceivePay(oldPrice.equals(newPrice) ? oldPrice : newPrice); |
|
|
|
//wxBillRent.setReceivePay(oldPrice.equals(newPrice) ? oldPrice : newPrice); |
|
|
|
wxBillRent.setUpdatetime(new Date()); |
|
|
|
try { |
|
|
|
wxBillRentMapper.updateByPrimaryKeySelective(wxBillRent); |
|
|
|
|