@@ -1389,6 +1389,18 @@ public class WxRentContractServiceImpl implements WxRentContractService {
}
private static Date getCurrentYearRentDate(Date yearEndDate,Date rentDate){
Calendar calendar = Calendar.getInstance();
calendar.setTime(yearEndDate);
Calendar rentCalendar = Calendar.getInstance();
rentCalendar.setTime(rentDate);
calendar.set(Calendar.DAY_OF_MONTH,rentCalendar.get(Calendar.DAY_OF_MONTH));
calendar.set(Calendar.MONTH, rentCalendar.get(Calendar.MONTH));
return calendar.getTime();
}
public Map<String, Object> buildRent(int receivePeriod, long[] priceArrs, List<Date> yearList, int dayType, WxRentContract wxRentContract, Long userId, int billcount, Integer isPreview, String shopInfoStr,boolean saveDb) {
WxPayAccountBill wxPayAccountBill = wxPayAccountBillService.getByTenantInfo(wxRentContract);
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
@@ -1422,6 +1434,7 @@ public class WxRentContractServiceImpl implements WxRentContractService {
long needpay = 0;
boolean flag = false;
//此处逻辑处理这一年和下一年交接那一期账单。
if(yearList.size() > 1) {
if (endDate!=null && (sd.format(billTimeVo.getStartDate()).equals(sd.format(endDate)) || billTimeVo.getStartDate().after(endDate) || billTimeVo.getEndDate().after(endDate) )) {
if(yearList.size() > 1) {
@@ -1436,18 +1449,26 @@ public class WxRentContractServiceImpl implements WxRentContractService {
long needpayAfter = 0;
//同一天,算一天
if(sd.format(billTimeVo.getStartDate()).equals(sd.format(billTimeVo.getEndDate()))){
needpayFront = getNeedPayMoney(wxRentContract,priceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod,false);
needpayFront = getNeedPayMoney(wxRentContract,priceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false );
}else{
if(billTimeVo.getStartDate().before(endDate)){
if (EnumRentContractType.RENT_BY_JOINT.getCode().equals(wxRentContract.getType()) && EnumMissTimeType.PERIOD.getCode().equals(wxRentContract.getBusDiscountTime())) {
//设置跳点率为年周期 price不变
needpayFront = priceArrs[index - 1];
}else {
needpayFront = getNeedPayMoney(wxRentContract, priceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true);
needpayAfter = getNeedPayMoney(wxRentContract, priceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true);
needpayFront = getNeedPayMoney(wxRentContract, priceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false );
needpayAfter = getNeedPayMoney(wxRentContract, priceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false );
}
}else{
needpayFront = getNeedPayMoney(wxRentContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod,false);
//如果是按自然月,则这一年和下一年交叉部分需要重新计算
if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) {
Date currentYearRentDate = getCurrentYearRentDate(endDate,wxRentContract.getRentalStartDate());
needpayFront = getNeedPayMoney(wxRentContract, priceArrs[index - 1], endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true);
needpayAfter = getNeedPayMoney(wxRentContract, priceArrs[index], currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true);
}else {
//按账单日
needpayFront = getNeedPayMoney(wxRentContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod,false,false);
}
}
}
needpay = needpayFront+needpayAfter;
@@ -1466,7 +1487,7 @@ public class WxRentContractServiceImpl implements WxRentContractService {
//计算金额
if(!flag){
needpay = getNeedPayMoney(wxRentContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod,false);
needpay = getNeedPayMoney(wxRentContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false );
}
WxBillRent wxBillRent = new WxBillRent();
@@ -1519,13 +1540,16 @@ public class WxRentContractServiceImpl implements WxRentContractService {
return resultMap;
}
public long getNeedPayMoney(WxRentContract wxRentContract,long price,Date startDate,Date endDate,int i,int billTimeVoListSize,boolean saveDb,int dayType,int receivePeriod,boolean part){
public long getNeedPayMoney(WxRentContract wxRentContract,long price,Date startDate,Date endDate,int i,int billTimeVoListSize,boolean saveDb,int dayType,int receivePeriod,boolean part,boolean monthCalDay ){
long needpay;
//按日
if (wxRentContract.getPriceUnit().equals(EnumPriceUnit.D.getCode())){
Double priceD = new Double(price);
double needpayD = WxRentContractServiceImpl.getNeedPay(0,priceD,startDate,endDate);
needpay = new Double(needpayD).longValue();
//取整
//needpay = new Double(needpayD).longValue();
//四舍五入
needpay = new BigDecimal(needpayD).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
}else{
Double priceD = new Double(price);
if (EnumRentContractType.RENT_BY_JOINT.getCode().equals(wxRentContract.getType())) {
@@ -1547,7 +1571,8 @@ public class WxRentContractServiceImpl implements WxRentContractService {
//生成金额直接计算
if(!saveDb){
needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,part)).longValue();
//needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,part)).longValue();
needpay = new BigDecimal(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,part)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
return needpay;
}
@@ -1564,7 +1589,8 @@ public class WxRentContractServiceImpl implements WxRentContractService {
int months = getMonths(sdM.format(startDate)+"-01",sdM.format(DateUtils.getDaySet(endDate,Calendar.DATE,1))+"-01");
needpay = new Double(months * priceD).longValue();
}else{
needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue();
//needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue();
needpay = new BigDecimal(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
}
}else if(i == 0){//第一期
if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){
@@ -1573,7 +1599,8 @@ public class WxRentContractServiceImpl implements WxRentContractService {
months++;
needpay = new Double(months * priceD).longValue();
}else{
needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue();
//needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue();
needpay = new BigDecimal(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
}
}else{
if(isFirstDay(startDate)){
@@ -1583,7 +1610,8 @@ public class WxRentContractServiceImpl implements WxRentContractService {
}
needpay = new Double(months * priceD).longValue();
}else{
needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue();
//needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue();
needpay = new BigDecimal(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
}
}
}else{//中间
@@ -1591,12 +1619,18 @@ public class WxRentContractServiceImpl implements WxRentContractService {
if(isFirstDay(startDate)){
months++;
}
needpay = new Double(months * priceD).longValue();
//如果当月费用需要按天计算
if (monthCalDay) {
//needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue();
needpay = new BigDecimal(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
}else {
needpay = new Double(months * priceD).longValue();
}
}
}
return needpay;
}
public void setExpiredDay(WxBillRent wxBillRent,int dayType, int receivePeriod){
//截止收租日在当前时间之前
Date date = new Date();
@@ -3288,12 +3322,4 @@ public class WxRentContractServiceImpl implements WxRentContractService {
return count;
}
public static void main(String[] args) {
String s = "{\"siteMoney\":\"2\",\"facilityMoney\":\"3\",\"administratorMoney\":\"4\"}";
JSONObject jsonObject = JSONObject.parseObject(s);
String siteMoney = jsonObject.getString("siteMoney");
System.out.println(siteMoney);
}
}