|
|
|
@@ -1450,7 +1450,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
//按日 |
|
|
|
if (wxRentContract.getPriceUnit().equals(EnumPriceUnit.D.getCode())){ |
|
|
|
Double priceD = new Double(price); |
|
|
|
double needpayD = WxRentContractServiceImpl.getNeedPay(0,priceD,startDate,endDate); |
|
|
|
double needpayD = WxRentContractHelper.getNeedPay(0,priceD,startDate,endDate); |
|
|
|
//取整 |
|
|
|
//needpay = new Double(needpayD).longValue(); |
|
|
|
//四舍五入 |
|
|
|
@@ -1477,7 +1477,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
//生成金额直接计算 |
|
|
|
if(!saveDb){ |
|
|
|
//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(); |
|
|
|
needpay = new BigDecimal(WxRentContractHelper.getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,part)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue(); |
|
|
|
return needpay; |
|
|
|
} |
|
|
|
|
|
|
|
@@ -1491,43 +1491,43 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
instance.add(dayType, receivePeriod); |
|
|
|
instance.add(Calendar.DATE, -1); |
|
|
|
if(sd.format(instance.getTime()).equals(sd.format(endDate))){ |
|
|
|
int months = getMonths(sdM.format(startDate)+"-01",sdM.format(DateUtils.getDaySet(endDate,Calendar.DATE,1))+"-01"); |
|
|
|
int months = WxRentContractHelper.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 BigDecimal(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue(); |
|
|
|
needpay = new BigDecimal(WxRentContractHelper.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())){ |
|
|
|
if(isFirstDay(startDate)){ |
|
|
|
int months = getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); |
|
|
|
int months = WxRentContractHelper.getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); |
|
|
|
months++; |
|
|
|
needpay = new Double(months * priceD).longValue(); |
|
|
|
}else{ |
|
|
|
//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(); |
|
|
|
needpay = new BigDecimal(WxRentContractHelper.getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue(); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
if(isFirstDay(startDate)){ |
|
|
|
int months = getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); |
|
|
|
int months = WxRentContractHelper.getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); |
|
|
|
if(isFirstDay(startDate)){ |
|
|
|
months++; |
|
|
|
} |
|
|
|
needpay = new Double(months * priceD).longValue(); |
|
|
|
}else{ |
|
|
|
//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(); |
|
|
|
needpay = new BigDecimal(WxRentContractHelper.getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue(); |
|
|
|
} |
|
|
|
} |
|
|
|
}else{//中间 |
|
|
|
int months = getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); |
|
|
|
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(priceD, startDate, endDate,dayType,receivePeriod,false)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue(); |
|
|
|
needpay = new BigDecimal(WxRentContractHelper.getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue(); |
|
|
|
}else { |
|
|
|
needpay = new Double(months * priceD).longValue(); |
|
|
|
} |
|
|
|
@@ -1567,14 +1567,6 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public static int getMonths(String startStr,String endStr){ |
|
|
|
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); |
|
|
|
DateTime start = formatter.parseDateTime(startStr); |
|
|
|
DateTime end = formatter.parseDateTime(endStr); |
|
|
|
int months = Months.monthsBetween(start, end).getMonths(); |
|
|
|
return months; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class}) |
|
|
|
@Override |
|
|
|
@@ -2786,135 +2778,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
// return wxRentContractMapper.getShopType(wxRentContract); |
|
|
|
// } |
|
|
|
|
|
|
|
public static double getMonthNeedPay(Double price,Date start,Date end,int dayType,int receivePeriod,boolean part){ |
|
|
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM"); |
|
|
|
SimpleDateFormat sdD = new SimpleDateFormat("d"); |
|
|
|
Double total = new Double(0); |
|
|
|
int[] diff; |
|
|
|
|
|
|
|
//同一天 |
|
|
|
if(sd.format(start).equals(sd.format(end))){ |
|
|
|
int dayCount = DateUtils.getMonthDayCount(start); |
|
|
|
return 1 * (price/dayCount); |
|
|
|
} |
|
|
|
|
|
|
|
//同月 |
|
|
|
if(sdM.format(start).equals(sdM.format(end))){ |
|
|
|
|
|
|
|
diff = DateUtils.getDiff(start,end); |
|
|
|
int dayCount = DateUtils.getMonthDayCount(start); |
|
|
|
total += (diff[1]+1) * (price/dayCount); |
|
|
|
return total; |
|
|
|
} |
|
|
|
|
|
|
|
//判断是否满足整月 |
|
|
|
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); |
|
|
|
if(sd.format(instance.getTime()).equals(sd.format(end))){ |
|
|
|
isFullMonth = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(isFullMonth){ |
|
|
|
int months = getMonths(sdM.format(start)+"-01",sdM.format(DateUtils.getDaySet(end,Calendar.DATE,1))+"-01"); |
|
|
|
return (months) * price; |
|
|
|
} |
|
|
|
|
|
|
|
//第一个月 |
|
|
|
Date lastMonthDay = DateUtils.getLastDayForMonth(start); |
|
|
|
diff = DateUtils.getDiff(start,lastMonthDay); |
|
|
|
int dayCount = DateUtils.getMonthDayCount(start); |
|
|
|
total += (diff[1]+1) * (price/dayCount); |
|
|
|
|
|
|
|
//中间月份 |
|
|
|
Date newStartDate = DateUtils.getDaySet(lastMonthDay,Calendar.DATE,1); |
|
|
|
int months = getMonths(sdM.format(newStartDate)+"-01",sdM.format(end)+"-01"); |
|
|
|
total += months * price; |
|
|
|
|
|
|
|
//最后一个月 |
|
|
|
diff = DateUtils.getDiff(DateUtils.getFirstDayForCurrMonth(end),end); |
|
|
|
dayCount = DateUtils.getMonthDayCount(end); |
|
|
|
total += (diff[1]+1) * (price/dayCount); |
|
|
|
return total; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 按日计租 根据每月的日期总数计算needpay |
|
|
|
* @param monthPrice |
|
|
|
* @param start |
|
|
|
* @param end |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public static double getNeedPay(long monthPrice,Double dayPrice,Date start,Date end){ |
|
|
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM"); |
|
|
|
Double total; |
|
|
|
int[] diff; |
|
|
|
|
|
|
|
int dayCount = DateUtils.getMonthDayCount(start); |
|
|
|
double price; |
|
|
|
if(monthPrice > 0){ |
|
|
|
price = (double) monthPrice/dayCount; |
|
|
|
}else{ |
|
|
|
price = dayPrice; |
|
|
|
} |
|
|
|
|
|
|
|
//同一天 |
|
|
|
if(sd.format(start).equals(sd.format(end))){ |
|
|
|
return 1 * price; //算1天 |
|
|
|
} |
|
|
|
//同月 |
|
|
|
if(sdM.format(start).equals(sdM.format(end))){ |
|
|
|
diff = DateUtils.getDiff(start,end); |
|
|
|
return (diff[1]+1) * price; |
|
|
|
} |
|
|
|
|
|
|
|
Date currEnd = DateUtils.getLastDayForMonth(start); |
|
|
|
diff = DateUtils.getDiff(start,currEnd); |
|
|
|
total = (diff[1]+1) * price; |
|
|
|
|
|
|
|
int warnCount = 0; |
|
|
|
while (true){ |
|
|
|
Date monthStartDate = DateUtils.getDaySet(currEnd,Calendar.DATE,1); |
|
|
|
dayCount = DateUtils.getMonthDayCount(monthStartDate); |
|
|
|
if(monthPrice > 0){ |
|
|
|
price = (double) monthPrice/dayCount; |
|
|
|
}else{ |
|
|
|
price = dayPrice; |
|
|
|
} |
|
|
|
|
|
|
|
//最后一个月 |
|
|
|
if(sdM.format(monthStartDate).equals(sdM.format(end))){ |
|
|
|
diff = DateUtils.getDiff(monthStartDate,end); |
|
|
|
total += price * (diff[1]+1); |
|
|
|
break; |
|
|
|
}else{ |
|
|
|
currEnd = DateUtils.getLastDayForMonth(monthStartDate); |
|
|
|
diff = DateUtils.getDiff(monthStartDate,currEnd); |
|
|
|
total += price * (diff[1]+1); |
|
|
|
} |
|
|
|
|
|
|
|
//预警 |
|
|
|
if(warnCount >= 1000){ |
|
|
|
Logger logger = LoggerFactory.getLogger(WxRentContractServiceImpl.class); |
|
|
|
logger.error("getNeedPay() warnCount max error !!! monthPrice:{},dayPrice:{},start:{},end:{}",monthPrice,dayPrice,sd.format(start),sd.format(end)); |
|
|
|
break; |
|
|
|
} |
|
|
|
warnCount ++; |
|
|
|
} |
|
|
|
return total; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static List<BillTimeVo> initBillTimeList(Date start,Date end,Integer adjustPeriod,Integer dayType,int receivePeriod){ |
|
|
|
List<BillTimeVo> list = new ArrayList<>(); |
|
|
|
|