diff --git a/mallinkService/src/main/java/com/iformall/domain/dto/NeedPayDTO.java b/mallinkService/src/main/java/com/iformall/domain/dto/NeedPayDTO.java new file mode 100644 index 000000000..0352be81f --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/dto/NeedPayDTO.java @@ -0,0 +1,13 @@ +package com.iformall.domain.dto; + +import java.math.BigDecimal; + +import lombok.Data; + +/** + */ +@Data +public class NeedPayDTO { + private boolean isFullMonth; + private BigDecimal money; +} diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxEnergyFees.java b/mallinkService/src/main/java/com/iformall/domain/po/WxEnergyFees.java index 4fe9c73f9..386e051bf 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxEnergyFees.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxEnergyFees.java @@ -133,7 +133,7 @@ public class WxEnergyFees extends TenantEntity { if (this.timeUnit.intValue() == EnumFeesStandardsTimeUnit.DAY.getCode().intValue()) { BigDecimal priceD = new BigDecimal(this.price); priceD = priceD.multiply(new BigDecimal(count)); - return WxRentContractHelper.getNeedPay(decimalSize,new BigDecimal(0),priceD,start,end,priceCalcute,monthDays); + return WxRentContractHelper.getNeedPay(null,decimalSize,new BigDecimal(0),priceD,start,end,priceCalcute,monthDays); }else { //按月计算 BigDecimal priceMonth = new BigDecimal(this.price); diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxRentContractFreePeriod.java b/mallinkService/src/main/java/com/iformall/domain/po/WxRentContractFreePeriod.java index 6b6b6f380..5ca0fbd66 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxRentContractFreePeriod.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxRentContractFreePeriod.java @@ -1,5 +1,6 @@ package com.iformall.domain.po; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.iformall.domain.po.base.TenantEntity; import lombok.Data; diff --git a/mallinkService/src/main/java/com/iformall/service/helper/WxRentContractHelper.java b/mallinkService/src/main/java/com/iformall/service/helper/WxRentContractHelper.java index 138c4ce15..5e8470000 100644 --- a/mallinkService/src/main/java/com/iformall/service/helper/WxRentContractHelper.java +++ b/mallinkService/src/main/java/com/iformall/service/helper/WxRentContractHelper.java @@ -1,14 +1,13 @@ package com.iformall.service.helper; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.iformall.domain.po.WxEnergyFees; -import com.iformall.domain.po.WxRentContract; -import com.iformall.domain.vo.WxBillFeesStandardsListVo; -import com.iformall.enums.*; -import com.iformall.service.impl.WxRentContractServiceImpl; -import com.iformall.utils.Constant; -import com.iformall.utils.DateUtils; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; import org.joda.time.Months; @@ -17,13 +16,24 @@ import org.joda.time.format.DateTimeFormatter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.iformall.domain.dto.NeedPayDTO; +import com.iformall.domain.po.WxEnergyFees; +import com.iformall.domain.po.WxRentContract; +import com.iformall.domain.vo.WxBillFeesStandardsListVo; +import com.iformall.enums.EnumContractReceivePeriodUnit; +import com.iformall.enums.EnumFeesStandardsCalcuteUnit; +import com.iformall.enums.EnumPriceUnit; +import com.iformall.enums.EnumRentContractAdjustPeriod; +import com.iformall.enums.EnumRentContractAdjustRatioWay; +import com.iformall.enums.EnumRentContractRentInputWay; +import com.iformall.enums.EnumRentContractType; +import com.iformall.enums.EnumRentDayPriceCalcute; +import com.iformall.enums.EnumYesOrNo; +import com.iformall.service.impl.WxRentContractServiceImpl; +import com.iformall.utils.Constant; +import com.iformall.utils.DateUtils; public class WxRentContractHelper { @@ -340,17 +350,18 @@ public class WxRentContractHelper { } //查询月账单需要支付的金额 - public static String getNeedPayMoney(WxRentContract wxRentContract,String price,Date startDate,Date endDate,int i,int billTimeVoListSize,boolean saveDb,int dayType,int receivePeriod,boolean part,boolean monthCalDay){ + public static String getNeedPayMoney(List freeDays,WxRentContract wxRentContract,String price,Date startDate,Date endDate,int i,int billTimeVoListSize,boolean saveDb,int dayType,int receivePeriod){ String needpay; if (null == wxRentContract.getDecimalSize()) { wxRentContract.setDecimalSize(Constant.default_short_decimal_size); } EnumRentDayPriceCalcute priceCalcute = EnumRentDayPriceCalcute.getEnum(wxRentContract.getDayPriceCalcute()); + //按日 if (wxRentContract.getPriceUnit().equals(EnumPriceUnit.D.getCode())){ BigDecimal priceD = new BigDecimal(price); - String needpayD = WxRentContractHelper.getNeedPay(Constant.default_long_decimal_size,new BigDecimal(0),priceD,startDate,endDate,priceCalcute,wxRentContract.getMonthAverageDays()); + String needpayD = WxRentContractHelper.getNeedPay(freeDays,Constant.default_long_decimal_size,new BigDecimal(0),priceD,startDate,endDate,priceCalcute,wxRentContract.getMonthAverageDays()); //取整 //needpay = new Double(needpayD).longValue(); //四舍五入 @@ -365,66 +376,13 @@ public class WxRentContractHelper { //生成金额直接计算 if(!saveDb){ //needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,part)).longValue(); - needpay = new BigDecimal(getMonthNeedPay(Constant.default_long_decimal_size,priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays(),part)).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); + needpay = new BigDecimal(getMonthNeedPay(freeDays,Constant.default_long_decimal_size,priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays())).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); return needpay; } - SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM"); - SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); - - if(i == billTimeVoListSize - 1){//最后 - //判断是否满足整月 - Calendar instance = Calendar.getInstance(); - instance.setTime(startDate); -// instance.add(dayType, receivePeriod); -// instance.add(Calendar.DATE, -1); - instance = EnumContractReceivePeriodUnit.getAfterCalendarDay(instance, receivePeriod, dayType); - if(sd.format(instance.getTime()).equals(sd.format(endDate))){ - int months = WxRentContractHelper.getMonths(sdM.format(startDate)+"-01",sdM.format(DateUtils.getDaySet(endDate,Calendar.DATE,1))+"-01"); - needpay = new BigDecimal(months).multiply(priceD).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); - }else{ - //needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue(); - needpay = new BigDecimal(getMonthNeedPay(Constant.default_long_decimal_size,priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays(),false)) - .setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); - } - }else if(i == 0){//第一期 - if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ - if(isFirstDay(startDate)){ - int months = WxRentContractHelper.getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); - months++; - needpay = new BigDecimal(months).multiply(priceD).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); - }else{ - //needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue(); - needpay = new BigDecimal(getMonthNeedPay(Constant.default_long_decimal_size,priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays(),false)) - .setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); - } - }else{ - if(isFirstDay(startDate)){ - int months = WxRentContractHelper.getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); - if(isFirstDay(startDate)){ - months++; - } - needpay = new BigDecimal(months).multiply(priceD).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); - }else{ - //needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue(); - needpay = new BigDecimal(getMonthNeedPay(Constant.default_long_decimal_size,priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays(),false)) - .setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); - } - } - }else{//中间 - 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(Constant.default_long_decimal_size,priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays(),false)) - .setScale(wxRentContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP).toPlainString(); - }else { - needpay = new BigDecimal(months).multiply(priceD).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); - } - } + //判断是否满足整月 + needpay = new BigDecimal(getMonthNeedPay(freeDays,Constant.default_long_decimal_size,priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays())) + .setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_UP).toPlainString(); } return needpay; } @@ -479,71 +437,113 @@ public class WxRentContractHelper { * @param end * @return */ - public static String getMonthNeedPay(Integer decimalSize,BigDecimal price,Date start,Date end,int dayType,int receivePeriod,Integer dayPriceCalcute,Integer monthAvageDays,boolean part){ + public static String getMonthNeedPay(List freeDays,Integer decimalSize,BigDecimal price,Date start,Date end,int dayType,int receivePeriod,Integer dayPriceCalcute,Integer monthAvageDays){ SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM"); SimpleDateFormat sdD = new SimpleDateFormat("d"); BigDecimal total = new BigDecimal(0); int[] diff; + List allDaysFrees = DateUtils.getAllDays(start, end); + if (null == allDaysFrees) { + return "0"; + } + List validDays = new ArrayList(); + validDays.addAll(allDaysFrees); + if (null != freeDays && freeDays.size() > 0 ) { + allDaysFrees.retainAll(freeDays); + } + if (null != freeDays && freeDays.size() > 0 && null != allDaysFrees && allDaysFrees.size() > 0 ) { + validDays.removeAll(allDaysFrees); + } + if (validDays.size() <= 0 ) { + return "0"; + } + + //同一天 if(sd.format(start).equals(sd.format(end))){ - int dayCount = getRealDays(dayPriceCalcute, monthAvageDays, start); - return price.divide(new BigDecimal(dayCount),decimalSize,BigDecimal.ROUND_HALF_UP).toPlainString(); - + if (validDays.contains(start)) { + int dayCount = getRealDays(dayPriceCalcute, monthAvageDays, start); + return price.divide(new BigDecimal(dayCount),decimalSize,BigDecimal.ROUND_HALF_UP).toPlainString(); + }else { + return "0"; + } } - + //同月 if(sdM.format(start).equals(sdM.format(end))){ - - diff = DateUtils.getDiff(start,end); - int dayCount = getRealDays(dayPriceCalcute, monthAvageDays, start); - total = total.add(new BigDecimal((diff[1]+1)).multiply(price).divide(new BigDecimal(dayCount),decimalSize,BigDecimal.ROUND_HALF_UP)); - return total.toPlainString(); + NeedPayDTO np = getMonthPay(start, end, price, decimalSize, validDays, dayPriceCalcute, monthAvageDays); + return np.getMoney().toPlainString(); } - //判断是否满足整月 - 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); - instance = EnumContractReceivePeriodUnit.getAfterCalendarDay(instance, receivePeriod, dayType); - if(sd.format(instance.getTime()).equals(sd.format(end))){ - isFullMonth = true; - } + Calendar instance = Calendar.getInstance(); + instance.setTime(start); + instance = EnumContractReceivePeriodUnit.getAfterCalendarDay(instance, receivePeriod, dayType); + if(sd.format(instance.getTime()).equals(sd.format(end))){ + //不是一个月的。但是按整月算的 + int months = getMonths(sdM.format(start)+"-01",sdM.format(DateUtils.getDaySet(end,Calendar.DATE,1))+"-01"); + for (int i = 0 ; i < months; i++) { + Date currentMonthEnd = DateUtils.getLastDayForMonth(start); + NeedPayDTO np = getMonthPay(start, currentMonthEnd, price, decimalSize, validDays, dayPriceCalcute, monthAvageDays); + start = DateUtils.getDaySet(currentMonthEnd,Calendar.DATE,1); + total = total.add(np.getMoney()); + } + return total.toPlainString(); } - - if(isFullMonth){ - int months = getMonths(sdM.format(start)+"-01",sdM.format(DateUtils.getDaySet(end,Calendar.DATE,1))+"-01"); - return new BigDecimal(months).multiply(price).setScale(decimalSize, RoundingMode.HALF_UP).toPlainString(); - } - - //第一个月 + + //开始到这个月底 Date lastMonthDay = DateUtils.getLastDayForMonth(start); - diff = DateUtils.getDiff(start,lastMonthDay); - int dayCount = getRealDays(dayPriceCalcute, monthAvageDays, start); - total = total.add(new BigDecimal((diff[1]+1)).multiply(price).divide(new BigDecimal(dayCount),decimalSize,BigDecimal.ROUND_HALF_UP)); - + NeedPayDTO np = getMonthPay(start, lastMonthDay, price, decimalSize, validDays, dayPriceCalcute, monthAvageDays); + total = total.add(np.getMoney()); + //中间月份 Date newStartDate = DateUtils.getDaySet(lastMonthDay,Calendar.DATE,1); - int months = getMonths(sdM.format(newStartDate)+"-01",sdM.format(end)+"-01"); - total = total.add(new BigDecimal(months).multiply(price)); - + int months = getMonths(sdM.format(newStartDate)+"-01",sdM.format(end)+"-01"); + for (int i = 0 ; i < months; i++) { + Date currentMonthEnd = DateUtils.getLastDayForMonth(newStartDate); + NeedPayDTO _np = getMonthPay(newStartDate, currentMonthEnd, price, decimalSize, validDays, dayPriceCalcute, monthAvageDays); + newStartDate = DateUtils.getDaySet(currentMonthEnd,Calendar.DATE,1); + total = total.add(_np.getMoney()); + } + //最后一个月 - diff = DateUtils.getDiff(DateUtils.getFirstDayForCurrMonth(end),end); - dayCount = getRealDays(dayPriceCalcute, monthAvageDays, end); - total = total.add(new BigDecimal((diff[1]+1)).multiply(price).divide(new BigDecimal(dayCount),decimalSize,BigDecimal.ROUND_HALF_UP)); + if (newStartDate.before(end)) { + NeedPayDTO enp = getMonthPay(DateUtils.getFirstDayForCurrMonth(end), end, price, decimalSize, validDays, dayPriceCalcute, monthAvageDays); + total = total.add(enp.getMoney()); + } return total.toPlainString(); } + + private static NeedPayDTO getMonthPay(Date start,Date end, BigDecimal priceMonth,Integer decimalSize,List validDays,Integer dayPriceCalcute,Integer monthAvageDays) { + NeedPayDTO np = new NeedPayDTO(); + //当月实际天数 + int md = DateUtils.getMonthDayCount(start);; + //在有效的时间里面有多少天 + int ms = getDays(end,validDays); + + //计算天数 + int dayCount = getRealDays(dayPriceCalcute, monthAvageDays, start); + int sed = DateUtils.daysBetween(start,end)+1; + + //满月 + if (md == sed) { + //如果有免租的,则按天算 + if (ms == md) { + np.setFullMonth(true); + np.setMoney(priceMonth); + }else { + np.setFullMonth(false); + np.setMoney(new BigDecimal(ms).multiply(priceMonth).divide(new BigDecimal(dayCount),decimalSize,BigDecimal.ROUND_HALF_UP)); + } + }else { + np.setFullMonth(false); + np.setMoney(new BigDecimal(ms).multiply(priceMonth).divide(new BigDecimal(dayCount),decimalSize,BigDecimal.ROUND_HALF_UP)); + } + return np; + } + private static int getRealDays(Integer dayPriceCalcute,Integer monthAvageDays,Date start) { //是不是按实际天数来计算 boolean isRealDays = true; @@ -582,12 +582,30 @@ public class WxRentContractHelper { * @param end * @return */ - public static String getNeedPay(Integer decimalSize,BigDecimal monthPrice,BigDecimal dayPrice,Date start,Date end,EnumRentDayPriceCalcute priceCalcute,Integer monthDays){ + public static String getNeedPay(List freeDays,Integer decimalSize,BigDecimal monthPrice,BigDecimal dayPrice,Date start,Date end,EnumRentDayPriceCalcute priceCalcute,Integer monthDays){ SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM"); BigDecimal total; int[] diff; + List allDaysFrees = DateUtils.getAllDays(start, end); + if (null == allDaysFrees) { + return "0"; + } + List validDays = new ArrayList(); + validDays.addAll(allDaysFrees); + //取交集 + if (null != freeDays && freeDays.size() > 0 ) { + allDaysFrees.retainAll(freeDays); + } + //剩下的都是计费的 + if (null != freeDays && freeDays.size() > 0 && null != allDaysFrees && allDaysFrees.size() > 0 ) { + validDays.removeAll(allDaysFrees); + } + if (validDays.size() <= 0 ) { + return "0"; + } + int dayCount = getRealMonthDays(priceCalcute,monthDays,start); BigDecimal price; if(monthPrice.compareTo(new BigDecimal(0)) > 0){ @@ -598,17 +616,25 @@ public class WxRentContractHelper { //同一天 if(sd.format(start).equals(sd.format(end))){ - return price.toPlainString(); //算1天 + if (validDays.contains(start)) { + return price.toPlainString(); //算1天 + }else { + return "0"; + } } //同月 if(sdM.format(start).equals(sdM.format(end))){ - diff = DateUtils.getDiff(start,end); - return new BigDecimal((diff[1]+1)).multiply(price).setScale(decimalSize, BigDecimal.ROUND_HALF_UP).toPlainString(); + //diff = DateUtils.getDiff(start,end); + //return new BigDecimal((diff[1]+1)).multiply(price).setScale(decimalSize, BigDecimal.ROUND_HALF_UP).toPlainString(); + return new BigDecimal(validDays.size()).multiply(price).setScale(decimalSize, BigDecimal.ROUND_HALF_UP).toPlainString(); } + //当月截止 Date currEnd = DateUtils.getLastDayForMonth(start); - diff = DateUtils.getDiff(start,currEnd); - total = new BigDecimal((diff[1]+1)).multiply(price).setScale(decimalSize, BigDecimal.ROUND_HALF_UP); + //diff = DateUtils.getDiff(start,currEnd); + //total = new BigDecimal((diff[1]+1)).multiply(price).setScale(decimalSize, BigDecimal.ROUND_HALF_UP); + int ds = getDays(currEnd,validDays); + total = new BigDecimal(ds).multiply(price).setScale(decimalSize, BigDecimal.ROUND_HALF_UP); int warnCount = 0; while (true){ @@ -623,13 +649,17 @@ public class WxRentContractHelper { //最后一个月 if(sdM.format(monthStartDate).equals(sdM.format(end))){ - diff = DateUtils.getDiff(monthStartDate,end); - total = total.add(price.multiply(new BigDecimal((diff[1]+1))).setScale(decimalSize, BigDecimal.ROUND_HALF_UP)); + int ms = getDays(end,validDays); + //diff = DateUtils.getDiff(monthStartDate,end); + //total = total.add(price.multiply(new BigDecimal((diff[1]+1))).setScale(decimalSize, BigDecimal.ROUND_HALF_UP)); + total = total.add(price.multiply(new BigDecimal(ms)).setScale(decimalSize, BigDecimal.ROUND_HALF_UP)); break; }else{ currEnd = DateUtils.getLastDayForMonth(monthStartDate); - diff = DateUtils.getDiff(monthStartDate,currEnd); - total = total.add(price.multiply(new BigDecimal((diff[1]+1))).setScale(decimalSize, BigDecimal.ROUND_HALF_UP)); + //diff = DateUtils.getDiff(monthStartDate,currEnd); + //total = total.add(price.multiply(new BigDecimal((diff[1]+1))).setScale(decimalSize, BigDecimal.ROUND_HALF_UP)); + int ms = getDays(currEnd,validDays); + total = total.add(price.multiply(new BigDecimal(ms)).setScale(decimalSize, BigDecimal.ROUND_HALF_UP)); } //预警 @@ -642,5 +672,25 @@ public class WxRentContractHelper { } return total.setScale(decimalSize, BigDecimal.ROUND_HALF_UP).toPlainString(); } - + + private static int getDays(Date end,List allDays) { + if (null == allDays || allDays.size() <= 0 ) { + return 0; + } + List _tempList = new ArrayList(); + _tempList.addAll(allDays); + Date _end = DateUtils.getDayBegin(end); + for (int i = 0 ; i < _tempList.size(); i ++) { + Date a = _tempList.get(i); + if (a.equals(_end)) { + allDays.remove(a); + return i+1; + }else if (a.after(_end)) { + return i; + }else { + allDays.remove(a); + } + } + return 0; + } } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java index 746d3ccb3..03b5692f2 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java @@ -906,7 +906,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService //按日 if (wxRentContract.getPriceUnit().equals(EnumPriceUnit.D.getCode())){ BigDecimal priceD = new BigDecimal(price); - String needpayD = WxRentContractHelper.getNeedPay(wxRentContract.getDecimalSize(),new BigDecimal(0),priceD,startDate,endDate,dayPrice,wxRentContract.getMonthAverageDays()); + String needpayD = WxRentContractHelper.getNeedPay(null,wxRentContract.getDecimalSize(),new BigDecimal(0),priceD,startDate,endDate,dayPrice,wxRentContract.getMonthAverageDays()); needpay = needpayD; //按月计算 }else{ @@ -918,7 +918,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService //生成金额直接计算 if(!saveDb){ - needpay = WxRentContractHelper.getMonthNeedPay(wxRentContract.getDecimalSize(),priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays(),false); + needpay = WxRentContractHelper.getMonthNeedPay(null,wxRentContract.getDecimalSize(),priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays()); return needpay; } @@ -933,7 +933,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService months++; needpay = new BigDecimal(months).multiply(priceD).toPlainString(); }else { - needpay = WxRentContractHelper.getMonthNeedPay(wxRentContract.getDecimalSize(),priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays(),false); + needpay = WxRentContractHelper.getMonthNeedPay(null,wxRentContract.getDecimalSize(),priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays()); } }else if(i == 0){//第一期 if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ @@ -942,7 +942,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService months++; needpay = new BigDecimal(months).multiply(priceD).toPlainString(); }else{ - needpay = WxRentContractHelper.getMonthNeedPay(wxRentContract.getDecimalSize(),priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays(),false); + needpay = WxRentContractHelper.getMonthNeedPay(null,wxRentContract.getDecimalSize(),priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays()); } }else{ if(isFirstDay(startDate)){ @@ -952,7 +952,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService } needpay = new BigDecimal(months).multiply(priceD).toPlainString(); }else{ - needpay = WxRentContractHelper.getMonthNeedPay(wxRentContract.getDecimalSize(),priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays(),false); + needpay = WxRentContractHelper.getMonthNeedPay(null,wxRentContract.getDecimalSize(),priceD, startDate, endDate,dayType,receivePeriod,wxRentContract.getDayPriceCalcute(),wxRentContract.getMonthAverageDays()); } } }else{//中间 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 4e246a5b9..a1c7a5add 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -1335,6 +1335,31 @@ public class WxRentContractServiceImpl implements WxRentContractService { return calendar.getTime(); } + private List getFreeDays(WxRentContract wxRentContract) { + //免租期 + WxRentContractFreePeriod fpq = new WxRentContractFreePeriod(); + fpq.updateTenantInfo(wxRentContract); + fpq.setRentContractId(wxRentContract.getId()); + fpq.setSortColumn("start_date asc"); + List freePeriods = wxRentContractFreePeriodMapper.findList(fpq); + if (null == freePeriods || freePeriods.size() <= 0 ) { + return null; + } + List allDate = new ArrayList(); + for (int i = 0 ; i < freePeriods.size() ; i ++) { + WxRentContractFreePeriod fp = freePeriods.get(i); + List dates = DateUtils.getAllDays(fp.getStartDate(), fp.getEndDate()); + if (null != dates && dates.size() > 0 ) { + allDate.retainAll(dates); + allDate.addAll(dates); + } + } + if (allDate.size() <= 0 ) { + return null; + } + return allDate; + } + public Map buildRent(int receivePeriod, String[] priceArrs,String[] bussinessManagerPriceArrs,String[] operationManagerPriceArrs, List yearList, int dayType, WxRentContract wxRentContract, MallUserInfo user, int billcount, Integer isPreview, String shopInfoStr,boolean saveDb) { WxPayAccountBill wxPayAccountBill = wxPayAccountBillService.getByTenantInfo(wxRentContract); SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); @@ -1363,11 +1388,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { } //免租期 - WxRentContractFreePeriod fpq = new WxRentContractFreePeriod(); - fpq.updateTenantInfo(wxRentContract); - fpq.setRentContractId(wxRentContract.getId()); - fpq.setSortColumn("start_date asc"); - List freePeroids = wxRentContractFreePeriodMapper.findList(fpq); + List freePeriods = getFreeDays(wxRentContract); int index = 0; for (int i = 0; i < billTimeVoList.size(); i++) { @@ -1403,12 +1424,12 @@ public class WxRentContractServiceImpl implements WxRentContractService { //同一天,算一天 if(sd.format(billTimeVo.getStartDate()).equals(sd.format(billTimeVo.getEndDate()))){ - needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract,priceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); + needpayFront = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract,priceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod); if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) { - bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract,bussinessManagerPriceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); + bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract,bussinessManagerPriceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod); } if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { - operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract,operationManagerPriceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); + operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract,operationManagerPriceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod); } }else{ if(billTimeVo.getStartDate().before(endDate)){ @@ -1422,39 +1443,39 @@ public class WxRentContractServiceImpl implements WxRentContractService { operatingManageFeeNeedpayFront = operationManagerPriceArrs[index - 1]; } }else { - needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); - needpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); + needpayFront = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, priceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod); + needpayAfter = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, priceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod); if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) { - bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); - bussinessManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); + bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, bussinessManagerPriceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod); + bussinessManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, bussinessManagerPriceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod); } if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { - operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); - operatingManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); + operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, operationManagerPriceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod); + operatingManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, operationManagerPriceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod); } } }else{ //如果是按自然月,则这一年和下一年交叉部分需要重新计算 if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) { Date currentYearRentDate = getCurrentYearRentDate(endDate,wxRentContract.getRentalStartDate()); - needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index - 1],endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); - needpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index],currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); + needpayFront = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, priceArrs[index - 1],endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod); + needpayAfter = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, priceArrs[index],currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod); if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) { - bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index - 1],endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); - bussinessManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index],currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); + bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, bussinessManagerPriceArrs[index - 1],endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod); + bussinessManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, bussinessManagerPriceArrs[index],currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod); } if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { - operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index - 1],endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); - operatingManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index],currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); + operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, operationManagerPriceArrs[index - 1],endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod); + operatingManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, operationManagerPriceArrs[index],currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod); } }else { //按账单日 - needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod,false,false); + needpayFront = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) { - bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod,false,false); + bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, bussinessManagerPriceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); } if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { - operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod,false,false); + operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, operationManagerPriceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); } } } @@ -1477,12 +1498,12 @@ public class WxRentContractServiceImpl implements WxRentContractService { //计算金额 if(!flag){ - needpay = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index],billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); + needpay = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, priceArrs[index],billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod); if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0 ) { - bussinessManageFeeNeedpay = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index],billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); + bussinessManageFeeNeedpay = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, bussinessManagerPriceArrs[index],billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod); } if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { - operatingManageFeeNeedpay = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index],billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); + operatingManageFeeNeedpay = WxRentContractHelper.getNeedPayMoney(freePeriods,wxRentContract, operationManagerPriceArrs[index],billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod); } } diff --git a/mallinkService/src/main/java/com/iformall/utils/DateUtils.java b/mallinkService/src/main/java/com/iformall/utils/DateUtils.java index 8dfb1b31c..06931db27 100755 --- a/mallinkService/src/main/java/com/iformall/utils/DateUtils.java +++ b/mallinkService/src/main/java/com/iformall/utils/DateUtils.java @@ -1639,4 +1639,18 @@ public class DateUtils { end.add(Calendar.DATE, -1); return end; } + + public static List getAllDays(Date start,Date end) { + Calendar cal = Calendar.getInstance(); + cal.setTime(start); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + List allDays = new ArrayList(); + while (cal.getTime().before(end) || cal.getTime().equals(end)) { + allDays.add(cal.getTime()); + cal.add(Calendar.DATE, 1); + } + return allDays; + } }