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 5368b6536..91236edd9 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -33,7 +33,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; - +import org.joda.time.DateTime; +import org.joda.time.Months; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; @@ -882,9 +885,11 @@ public class WxRentContractServiceImpl implements WxRentContractService { // } int index = 0; - for (BillTimeVo billTimeVo : billTimeVoList){ + for (int i = 0; i < billTimeVoList.size(); i++) { + BillTimeVo billTimeVo = billTimeVoList.get(i); + if(yearList.size() > 1) { - if (endDate!=null && (sd.format(billTimeVo.getStartDate()).equals(sd.format(endDate)) || billTimeVo.getStartDate().after(endDate))) { + if (endDate!=null && (sd.format(billTimeVo.getStartDate()).equals(sd.format(endDate)) || billTimeVo.getStartDate().after(endDate) || billTimeVo.getEndDate().after(endDate) )) { logger.info("=====billTimeVo.getStartDate():"+sd.format(billTimeVo.getStartDate())+" endDate:"+sd.format(endDate)); index++; @@ -916,8 +921,8 @@ public class WxRentContractServiceImpl implements WxRentContractService { JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); int rentSize = rentInfoArray.size(); Map shopInfoMap = new HashMap<>(); - for (int i = 0; i < rentSize; i++) { - JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); + for (int j = 0; j < rentSize; j++) { + JSONObject rentInfoObject = rentInfoArray.getJSONObject(j); shopInfoMap.put(rentInfoObject.getString("shopNumber"), 0); } shopInfoStr = JSONObject.toJSONString(shopInfoMap); @@ -933,7 +938,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { wxBillRent.setEndtime(billTimeVo.getEndDate()); wxBillRent.setReceiveDate(billTimeVo.getReceiveDate()); - long needpay; + long needpay = 0; //按日 if (wxRentContract.getPriceUnit().equals(EnumPriceUnit.D.getCode())){ @@ -947,14 +952,17 @@ public class WxRentContractServiceImpl implements WxRentContractService { priceD = new Double(price)/12; } - //当天也算,加1天 - Date newEndDate = DateUtils.getDaySet(wxBillRent.getEndtime(),Calendar.DATE,1); - //按月 - int[] diff = DateUtils.getDiff(wxBillRent.getStarttime(),newEndDate); - needpay =new Double( diff[0]*priceD).longValue(); - - double oneDayProce = priceD/DateUtils.getMonthDayCount(wxRentContract.getRentalEndDate()); - needpay += diff[1] * oneDayProce; + if(i == 0){//第一期 + if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ + needpay = new Double(getMonthNeedPay(priceD,billTimeVo.getStartDate(),billTimeVo.getEndDate())).longValue(); + }else{ + needpay = new Double(receivePeriod * priceD).longValue(); + } + }else if(i == billTimeVoList.size()-1){//最后 + needpay = new Double(getMonthNeedPay(priceD,billTimeVo.getStartDate(),billTimeVo.getEndDate())).longValue(); + }else{//中间 + needpay = new Double(receivePeriod * priceD).longValue(); + } } wxBillRent.setNeedPay(needpay); @@ -1001,6 +1009,23 @@ public class WxRentContractServiceImpl implements WxRentContractService { return resultMap; } + public boolean isFirstDay(Date date){ + int dateInt = Integer.parseInt(new SimpleDateFormat("d").format(date)); + if(dateInt == 1){ + return true; + } + 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 public ResultData deleteById(String id) { @@ -1769,6 +1794,30 @@ public class WxRentContractServiceImpl implements WxRentContractService { return wxRentContractMapper.getShopType(wxRentContract); } + public static double getMonthNeedPay(Double price,Date start,Date end){ + SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); + SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM"); + Double total = new Double(0); + int[] diff; + + //第一个月 + 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