| @@ -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,7 +1540,7 @@ 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())){ | |||
| @@ -1591,7 +1612,12 @@ 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(); | |||
| }else { | |||
| needpay = new Double(months * priceD).longValue(); | |||
| } | |||
| } | |||
| } | |||
| return needpay; | |||
| @@ -3288,12 +3314,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); | |||
| } | |||
| } | |||