From 3d2fe940f4424b9f4d85d65f259ba491c6a259e3 Mon Sep 17 00:00:00 2001 From: luozukai Date: Wed, 29 May 2019 18:04:10 +0800 Subject: [PATCH] =?UTF-8?q?[bug][=E4=BF=AE=E6=94=B9][1001640]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/WxRentContractServiceImpl.java | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java index fd5135bd0..fb4c0ce22 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -876,6 +876,10 @@ public class WxRentContractServiceImpl implements WxRentContractService { } List billTimeVoList = initBillTimeList(wxRentContract.getRentalStartDate(),wxRentContract.getRentalEndDate(),wxRentContract.getAdjustPeriod(),dayType,receivePeriod); + for (BillTimeVo vo:billTimeVoList) { + System.out.println("ooooooooo"); + System.out.println(sd.format(vo.getStartDate()) + " "+sd.format(vo.getEndDate()) ); + } int index = 0; for (BillTimeVo billTimeVo : billTimeVoList){ @@ -936,10 +940,8 @@ public class WxRentContractServiceImpl implements WxRentContractService { double needpayD = WxRentContractServiceImpl.getNeedPay(0,price,wxBillRent.getStarttime(),wxBillRent.getEndtime()); needpay = new Double(needpayD).longValue(); }else{ - //当天也算,加1天 - Date newEndDate = DateUtils.getDaySet(wxBillRent.getEndtime(),Calendar.DATE,1); //按月 - int[] diff = DateUtils.getDiff(wxBillRent.getStarttime(),newEndDate); + int[] diff = DateUtils.getDiff(wxBillRent.getStarttime(),wxBillRent.getEndtime()); needpay = diff[0]*price; double oneDayProce = (double) price/DateUtils.getMonthDayCount(wxRentContract.getRentalEndDate()); @@ -1746,7 +1748,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { */ public static double getNeedPay(long monthPrice,long dayPrice,Date start,Date end){ SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); - SimpleDateFormat sdM = new SimpleDateFormat("MM"); + SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM"); Double total; int[] diff; @@ -1757,20 +1759,20 @@ public class WxRentContractServiceImpl implements WxRentContractService { }else{ price = dayPrice; } - Date currEnd = DateUtils.getLastDayForMonth(start); - - System.out.println("-----------"); - System.out.println(sd.format(start)); - System.out.println(sd.format(currEnd)); + //同一天 if(sd.format(start).equals(sd.format(end))){ - total = 1 * price; //算1天 - return total; - }else{ - diff = DateUtils.getDiff(start,currEnd); - total = (diff[1]+1) * price; + return 1 * price; //算1天 } - System.out.println("-------total:"+total); + //同月 + 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; while (true){ Date monthStartDate = DateUtils.getDaySet(currEnd,Calendar.DATE,1); @@ -1782,6 +1784,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { } System.out.println("-------monthStartDate:"+sd.format(monthStartDate)); + System.out.println("-------monthStartDate:"+sd.format(end)); //最后一个月 if(sdM.format(monthStartDate).equals(sdM.format(end))){ @@ -1797,7 +1800,6 @@ public class WxRentContractServiceImpl implements WxRentContractService { diff = DateUtils.getDiff(monthStartDate,currEnd); total += price * (diff[1] +1); } - System.out.println("-------total:"+total); } return total; } @@ -1805,7 +1807,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { public static void main(String[] args) throws Exception{ long tprice = 100; SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); - Date start = sd.parse("2019-05-28"); + Date start = sd.parse("2019-05-13"); Date end = sd.parse("2019-07-05"); System.out.println("===="+new WxRentContractServiceImpl().getNeedPay(tprice,0,start,end));;