From da47dbf6fba7fa5b3b92f072e5c3520416336fe3 Mon Sep 17 00:00:00 2001 From: winter Date: Sat, 6 Jul 2024 23:06:39 +0800 Subject: [PATCH] fix contract --- .../WxPropertyContractController.java | 10 + .../iformall/domain/po/WxBillProperty.java | 9 +- .../iformall/domain/po/WxFeesStandards.java | 79 +++++++ .../domain/po/WxPropertyContract.java | 3 +- .../domain/vo/WxBillFeesStandardsListVo.java | 19 ++ .../domain/vo/WxBillFeesStandardsVo.java | 13 ++ .../enums/EnumFeesStandardsCalcuteUnit.java | 1 + .../enums/EnumFeesStandardsTimeUnit.java | 4 + .../service/helper/WxRentContractHelper.java | 31 +++ .../impl/WxPropertyContractServiceImpl.java | 218 ++++++++++++------ 10 files changed, 314 insertions(+), 73 deletions(-) create mode 100644 mallinkService/src/main/java/com/iformall/domain/vo/WxBillFeesStandardsListVo.java create mode 100644 mallinkService/src/main/java/com/iformall/domain/vo/WxBillFeesStandardsVo.java diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/contract/WxPropertyContractController.java b/mallinkAdmin/src/main/java/com/iformall/controller/contract/WxPropertyContractController.java index 27ec32122..7d668b181 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/contract/WxPropertyContractController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/contract/WxPropertyContractController.java @@ -1,5 +1,6 @@ package com.iformall.controller.contract; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.github.pagehelper.PageInfo; import com.iformall.annotation.SystemControllerLog; @@ -183,6 +184,9 @@ public class WxPropertyContractController extends WxContractBaseController { if(wxPropertyContract.getRentStartType()!=null && wxPropertyContract.getRentStartType().equals(EnumRentStartType.STARTTIME.getCode())){ wxPropertyContract.setRentalStartDate(wxPropertyContract.getStartDate()); } + if (null != wxPropertyContract.getFeeStandards() && wxPropertyContract.getFeeStandards().size() > 0 ) { + wxPropertyContract.setFeesStandardsInfo(JSON.toJSONString(wxPropertyContract.getFeeStandards())); + } return wxPropertyContractService.saveOrUpdate(wxPropertyContract, user.getId(), user.getName(),false); } @@ -201,6 +205,9 @@ public class WxPropertyContractController extends WxContractBaseController { wxPropertyContract.calcutePrice(rentContract.getRentArea()); } propertyContract.setRentStartType(wxPropertyContract.getRentStartType()); + if (null != wxPropertyContract.getFeeStandards() && wxPropertyContract.getFeeStandards().size() > 0 ) { + wxPropertyContract.setFeesStandardsInfo(JSON.toJSONString(wxPropertyContract.getFeeStandards())); + } return wxPropertyContractService.saveOrUpdate(propertyContract, user.getId(), user.getName(),false); } @@ -212,6 +219,9 @@ public class WxPropertyContractController extends WxContractBaseController { wxPropertyContract.setAdjustPeriodHandle(); //第三步提交 SWITCH wxPropertyContract.setFixedPrice(null); + if (null != wxPropertyContract.getFeeStandards() && wxPropertyContract.getFeeStandards().size() > 0 ) { + wxPropertyContract.setFeesStandardsInfo(JSON.toJSONString(wxPropertyContract.getFeeStandards())); + } return wxPropertyContractService.saveOrUpdate(wxPropertyContract, user.getId(), user.getName(),true); } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillProperty.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillProperty.java index 2dbf6a0d8..1cd36231b 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillProperty.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillProperty.java @@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableName; import com.iformall.common.SortColumn; import com.iformall.domain.po.base.TenantEntity; import com.iformall.domain.po.base.WxBillBaseEntity; +import com.iformall.domain.vo.WxBillFeesStandardsListVo; +import com.iformall.domain.vo.WxBillFeesStandardsVo; import com.iformall.enums.EnumBillAllType; import lombok.Data; @@ -177,8 +179,9 @@ public class WxBillProperty extends WxBillBaseEntity { @TableField(exist = false) private String totalFee; - public void calcuteTotalFee(Integer decimalSize) { - this.totalFee = new BigDecimal(this.receivePay).setScale(decimalSize, RoundingMode.HALF_UP).toPlainString(); - } + + + @TableField(exist = false) + List unFixedbillFeesStandardsList; } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxFeesStandards.java b/mallinkService/src/main/java/com/iformall/domain/po/WxFeesStandards.java index 490ecb4de..4dcdcf9e9 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxFeesStandards.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxFeesStandards.java @@ -1,15 +1,26 @@ package com.iformall.domain.po; +import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.iformall.domain.po.base.TenantEntity; +import com.iformall.enums.EnumContractReceivePeriodUnit; import com.iformall.enums.EnumFeesStandardsCalcuteUnit; import com.iformall.enums.EnumFeesStandardsTimeUnit; +import com.iformall.enums.EnumFeesStandardsType; +import com.iformall.enums.EnumRentContractAdjustPeriod; import com.iformall.enums.EnumYesOrNo; +import com.iformall.service.helper.WxRentContractHelper; +import com.iformall.utils.Constant; +import com.iformall.utils.DateUtils; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; + +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; /** * @author gongbiao @@ -34,8 +45,17 @@ public class WxFeesStandards extends TenantEntity { private String name; @io.swagger.annotations.ApiModelProperty(value = "单价", name = "price") private String price; + @io.swagger.annotations.ApiModelProperty(value = "类型EnumFeesStandardsType", name = "type") private Integer type; + @TableField(exist = false) + private String typeName; + public String getTypeName() { + if (null != type) { + return EnumFeesStandardsType.getEnum(type).getMessage(); + } + return ""; + } @io.swagger.annotations.ApiModelProperty(value = "是否一次性费用EnumYesOrNo", name = "fixedPrice") private Integer fixedPrice; @@ -74,5 +94,64 @@ public class WxFeesStandards extends TenantEntity { return ""; } + public String calcuteTotalMoney(Integer decimalSize,Date start,Date end,String count) { + if (StringUtils.isBlank(count)) { + count = "1"; + } + 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); + }else { + //按月计算 + BigDecimal priceMonth = new BigDecimal(this.price); + if (this.timeUnit.intValue() == EnumFeesStandardsTimeUnit.YEAR.getCode().intValue()) { + priceMonth = new BigDecimal(price).divide(new BigDecimal(12),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP); + } + priceMonth = priceMonth.multiply(new BigDecimal(count)); + + //如果开始时间是1号,结束时间是当月最后一天,则是整月,*月数。 + //如果不是整月,跨月了的,则计算: 开始时间到当月底+ 中间整月 + 结束时间月1号到结束时间 + SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); + Date startMonthFirstDay = DateUtils.getFirstDayForCurrMonth(start); + Date endMonthLastDay = DateUtils.getLastDayForMonth(end); + if(sd.format(start).equals(sd.format(startMonthFirstDay)) && sd.format(end).equals(sd.format(endMonthLastDay)) ){ + int months = WxRentContractHelper.getMonths(sd.format(start),sd.format(end)); + months++; + if (months > 0 ) { + return priceMonth.multiply(new BigDecimal(months)).toPlainString(); + }else { + return priceMonth.toPlainString(); + } + }else { + Date startMonthEndDay = DateUtils.getLastDayForMonth(start); + int startDays = DateUtils.daysBetween(start, startMonthEndDay); + int startMonthDays = DateUtils.daysBetween(startMonthFirstDay, startMonthEndDay); + + Date endMontFirstDay = DateUtils.getFirstDayForCurrMonth(end); + int endDays = DateUtils.daysBetween(endMontFirstDay, end); + int endMonthDays = DateUtils.daysBetween(endMontFirstDay, endMonthLastDay); + + int months = WxRentContractHelper.getMonths(sd.format(DateUtils.getDaySet(startMonthEndDay, Calendar.DATE, 1)),sd.format(DateUtils.getDaySet(endMontFirstDay, Calendar.DATE, -1))); + months++; + + if (startDays > 0 ) { + priceMonth = priceMonth.multiply(new BigDecimal(startDays)).divide(new BigDecimal(startMonthDays),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP); + } + + if (endDays > 0 ) { + priceMonth = priceMonth.multiply(new BigDecimal(endDays)).divide(new BigDecimal(endMonthDays),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP); + } + + if (months > 0 ) { + priceMonth = priceMonth.multiply(new BigDecimal(months)); + } + + return priceMonth.toPlainString(); + + } + } + } + } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxPropertyContract.java b/mallinkService/src/main/java/com/iformall/domain/po/WxPropertyContract.java index 8dae42c96..668ea3b53 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxPropertyContract.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxPropertyContract.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.iformall.common.SortColumn; import com.iformall.domain.po.base.TenantEntity; +import com.iformall.domain.vo.WxBillFeesStandardsVo; import com.iformall.enums.EnumPriceUnit; import com.iformall.enums.EnumPropertyCreateType; import com.iformall.enums.EnumRentContractAdjustPeriod; @@ -318,5 +319,5 @@ public class WxPropertyContract extends TenantEntity { @TableField(exist = false) List feeStandards; - + } diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/WxBillFeesStandardsListVo.java b/mallinkService/src/main/java/com/iformall/domain/vo/WxBillFeesStandardsListVo.java new file mode 100644 index 000000000..dd39e724f --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/vo/WxBillFeesStandardsListVo.java @@ -0,0 +1,19 @@ +package com.iformall.domain.vo; + +import lombok.Data; +import java.io.Serializable; +import java.util.Date; + +import com.iformall.domain.po.WxFeesStandards; +@Data +public class WxBillFeesStandardsListVo implements Serializable { + + private static final long serialVersionUID = 1L; + private String billName;//名称 + private String total;//总金额 + private Date start; + private Date end; + private Date receiveDate; + private WxFeesStandards feeStandards; + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/WxBillFeesStandardsVo.java b/mallinkService/src/main/java/com/iformall/domain/vo/WxBillFeesStandardsVo.java new file mode 100644 index 000000000..9e17cd4fd --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/vo/WxBillFeesStandardsVo.java @@ -0,0 +1,13 @@ +package com.iformall.domain.vo; + +import lombok.Data; +import java.io.Serializable; +import java.util.List; +@Data +public class WxBillFeesStandardsVo implements Serializable { + + private static final long serialVersionUID = 1L; + private List fixedFeeStandards; + private List unFixedFeeStandards; + +} diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumFeesStandardsCalcuteUnit.java b/mallinkService/src/main/java/com/iformall/enums/EnumFeesStandardsCalcuteUnit.java index 4a567d54e..73b370d67 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumFeesStandardsCalcuteUnit.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumFeesStandardsCalcuteUnit.java @@ -1,5 +1,6 @@ package com.iformall.enums; +import java.math.BigDecimal; /** * @author gongbiao diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumFeesStandardsTimeUnit.java b/mallinkService/src/main/java/com/iformall/enums/EnumFeesStandardsTimeUnit.java index 9ad6abcd6..aec1a7588 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumFeesStandardsTimeUnit.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumFeesStandardsTimeUnit.java @@ -1,5 +1,9 @@ package com.iformall.enums; +import java.math.BigDecimal; +import java.util.Date; + +import com.iformall.utils.Constant; /** * @author gongbiao 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 755709504..cc754dbe7 100644 --- a/mallinkService/src/main/java/com/iformall/service/helper/WxRentContractHelper.java +++ b/mallinkService/src/main/java/com/iformall/service/helper/WxRentContractHelper.java @@ -2,7 +2,10 @@ package com.iformall.service.helper; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.iformall.domain.po.WxFeesStandards; import com.iformall.domain.po.WxRentContract; +import com.iformall.domain.vo.WxBillFeesStandardsListVo; +import com.iformall.domain.vo.WxBillFeesStandardsVo; import com.iformall.enums.*; import com.iformall.service.impl.WxRentContractServiceImpl; import com.iformall.utils.Constant; @@ -474,6 +477,34 @@ public class WxRentContractHelper { return needpay; } + //其他标准计费项 + public static WxBillFeesStandardsVo getStandardsBillList(List feesStandarsList,Date billStartDate,Date billEndDate) { + if (null == feesStandarsList || feesStandarsList.size() <= 0 ) { + return null; + } + WxBillFeesStandardsVo wvo = new WxBillFeesStandardsVo(); + List fixedList = new ArrayList(); + List unFixedList = new ArrayList(); + for (int i = 0 ; i < feesStandarsList.size() ; i ++) { + WxBillFeesStandardsListVo vo = new WxBillFeesStandardsListVo(); + WxFeesStandards fees = feesStandarsList.get(i); + vo.setBillName(fees.getName()); + if (fees.getFixedPrice().intValue() == EnumYesOrNo.YES.getCode().intValue() && null != billStartDate && null != billEndDate) { + vo.setStart(billStartDate); + vo.setEnd(billEndDate); + vo.setReceiveDate(DateUtils.getDaySet(billStartDate,Calendar.DATE,-1)); + fixedList.add(vo); + }else { + unFixedList.add(vo); + } + vo.setFeeStandards(fees); + + } + wvo.setFixedFeeStandards(fixedList); + wvo.setUnFixedFeeStandards(unFixedList); + return wvo; + } + private static boolean isFirstDay(Date date){ int dateInt = Integer.parseInt(new SimpleDateFormat("d").format(date)); if(dateInt == 1){ 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 14a93fc99..ed4c0ab70 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java @@ -13,12 +13,15 @@ import com.iformall.domain.po.*; import com.iformall.domain.po.base.BaseEntity; import com.iformall.domain.po.base.TenantEntity; import com.iformall.domain.vo.BillTimeVo; +import com.iformall.domain.vo.WxBillFeesStandardsListVo; +import com.iformall.domain.vo.WxBillFeesStandardsVo; import com.iformall.enums.*; import com.iformall.exception.MallinkException; import com.iformall.mapper.*; import com.iformall.service.*; import com.iformall.service.helper.WxBillAllHelper; import com.iformall.service.helper.WxRentContractHelper; +import com.iformall.utils.Constant; import com.iformall.utils.DateUtils; import org.apache.commons.collections.map.HashedMap; import org.apache.commons.lang3.StringUtils; @@ -643,7 +646,6 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); Map resultMap = new HashedMap(); List resultList = new ArrayList<>(); - final IdWorker idWorker = IdWorker.get(); Date endDate = null; if(yearList.size() > 1){ @@ -663,97 +665,99 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService billTimeVoList.add(billTimeVo); } } + + //结算其他金额 + Date billStartDate = null; + Date billEndDate = null; + if (billTimeVoList.size() > 0 ) { + billStartDate = billTimeVoList.get(0).getStartDate(); + billEndDate = billTimeVoList.get(billTimeVoList.size()-1).getEndDate(); + } + WxBillFeesStandardsVo standardsVo = WxRentContractHelper.getStandardsBillList(wxPropertyContract.getFeesStardarsList(),billStartDate,billEndDate); + List fixedList = null; + List unFixedList = null; + if (null != standardsVo) { + fixedList = standardsVo.getFixedFeeStandards(); + unFixedList = standardsVo.getUnFixedFeeStandards(); + } + int index = 0; for (int i = 0; i < billTimeVoList.size(); i++) { BillTimeVo billTimeVo = billTimeVoList.get(i); //计算金额 String needpay = "0"; - //结算其他金额 + String standarsTotal = "0"; boolean flag = false; + //超过1年 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) { - 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++; - - //如果是计算账单金额&cross 拆分日期进行计算 - if(!saveDb && billTimeVo.getEndDate().after(endDate)) { - String needpayFront = "0"; - String needpayAfter = "0"; - //同一天,算一天 - if(sd.format(billTimeVo.getStartDate()).equals(sd.format(billTimeVo.getEndDate()))){ - needpayFront = getNeedPayMoney(wxPropertyContract,priceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod); - }else{ - if(billTimeVo.getStartDate().before(endDate)){ - needpayFront = getNeedPayMoney(wxPropertyContract, priceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate,Calendar.DATE,-1), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); - needpayAfter = getNeedPayMoney(wxPropertyContract, priceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); - }else{ - needpayFront = getNeedPayMoney(wxPropertyContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); - } - } - needpay = needpayFront+needpayAfter; - flag = true; - } - if(index >= yearList.size()-1){ - endDate = null; + //logger.info("=====billTimeVo.getStartDate():"+sd.format(billTimeVo.getStartDate())+" endDate:"+sd.format(endDate)); + + index++; + + //如果是计算账单金额&cross 拆分日期进行计算 + if(!saveDb && billTimeVo.getEndDate().after(endDate)) { + String needpayFront = "0"; + String needpayAfter = "0"; + //同一天,算一天 + if(sd.format(billTimeVo.getStartDate()).equals(sd.format(billTimeVo.getEndDate()))){ + needpayFront = getNeedPayMoney(wxPropertyContract,priceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod); + standarsTotal = calcuteStandardsFee(unFixedList, billTimeVo.getStartDate(), endDate, wxPropertyContract); + }else{ + if(billTimeVo.getStartDate().before(endDate)){ + needpayFront = getNeedPayMoney(wxPropertyContract, priceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate,Calendar.DATE,-1), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); + needpayAfter = getNeedPayMoney(wxPropertyContract, priceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); }else{ - endDate = yearList.get(index+1);//price index 0开始,year.end 从第二年开始 - //logger.info("==========cross:"+sd.format(endDate)); + needpayFront = getNeedPayMoney(wxPropertyContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); } + standarsTotal = calcuteStandardsFee(unFixedList, billTimeVo.getStartDate(), billTimeVo.getEndDate(), wxPropertyContract); } + needpay = needpayFront+needpayAfter; + flag = true; + } + if(index >= yearList.size()-1){ + endDate = null; + }else{ + endDate = yearList.get(index+1);//price index 0开始,year.end 从第二年开始 + //logger.info("==========cross:"+sd.format(endDate)); } } } - //计算金额 + //第一年的,计算金额 if(!flag){ needpay = getNeedPayMoney(wxPropertyContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod); + standarsTotal = calcuteStandardsFee(unFixedList, billTimeVo.getStartDate(), billTimeVo.getEndDate(), wxPropertyContract); } - WxBillProperty wxBillProperty = new WxBillProperty(); - wxBillProperty.setIsPreview(isPreview); - wxBillProperty.setId(idWorker.nextId()); - wxBillProperty.setPropertyContractId(wxPropertyContract.getId()); - wxBillProperty.setPay("0"); - wxBillProperty.setStarttime(billTimeVo.getStartDate()); - wxBillProperty.setEndtime(billTimeVo.getEndDate()); - wxBillProperty.setReceiveDate(billTimeVo.getReceiveDate()); - - wxBillProperty.setNeedPay(needpay); - //wxBillProperty.setOwe(needpay); - wxBillProperty.setReceivePay(needpay); - - //截止收租日在当前时间之前 - Date date = new Date(); - //setExpiredDay(wxBillProperty,dayType,receivePeriod); - wxBillProperty.updateTenantInfo(wxPropertyContract); - wxBillProperty.setIsDel(0); - wxBillProperty.setMerchantId(wxPropertyContract.getMerchantId()); - wxBillProperty.setUserId(userId); - //wxBillProperty.setShopId(wxPropertyContract.getShopId()); - wxBillProperty.setCreatetime(date); - wxBillProperty.setUpdatetime(date); - wxBillProperty.setIsDel(EnumDelStatus.NOT_DEL.getCode()); - wxBillProperty.setRentShopType(wxPropertyContract.getRentShopType()); - wxBillProperty.setPeriod(++billcount); - if (shopInfo != null) { - wxBillProperty.setShopInfo(JSONObject.toJSONString(shopInfo)); - } - wxBillProperty.setLatePayRatio(0); - wxBillProperty.calcuteTotalFee(wxPropertyContract.getDecimalSize()); + ++billcount; + WxBillProperty wxBillProperty = generateBillProperty(wxPayAccountBill,wxPropertyContract,isPreview,billTimeVo.getStartDate(),billTimeVo.getEndDate(),billTimeVo.getReceiveDate(),needpay,userId,billcount,shopInfo,standarsTotal); + wxBillProperty.setUnFixedbillFeesStandardsList(unFixedList); - - //计算手续费 - BigDecimal servicePay = new BigDecimal(wxBillProperty.getReceivePay()).multiply(new BigDecimal(wxPayAccountBill.getServiceChargeRate())).divide(new BigDecimal(100), wxPropertyContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP); - wxBillProperty.setServiceChargePay(servicePay.toPlainString()); - //wxBillProperty.setOwe(new BigDecimal(wxBillProperty.getReceivePay()).add(new BigDecimal(wxBillProperty.getServiceChargePay())).toPlainString()); - //wxBillProperty.setOwe(new BigDecimal(wxBillProperty.getReceivePay()).toPlainString()); resultList.add(wxBillProperty); } + + if (null != fixedList) { + for (int i = 0 ; i < fixedList.size(); i ++ ) { + WxBillFeesStandardsListVo svo = fixedList.get(i); + ++billcount; + WxBillProperty property = generateBillPropertyByBillStandards(wxPayAccountBill,wxPropertyContract,isPreview,userId,svo,billcount,shopInfo); + resultList.add(property); + } + } + + if (null != unFixedList) { + for (int i = 0 ; i < unFixedList.size(); i ++ ) { + WxBillFeesStandardsListVo svo = unFixedList.get(i); + ++billcount; + WxBillProperty property = generateBillPropertyByBillStandards(wxPayAccountBill,wxPropertyContract,isPreview,userId,svo,billcount,shopInfo); + resultList.add(property); + } + } + //批量生成预账单 if(saveDb && resultList.size() > 0 ) { wxBillPropertyMapper.insertBills(resultList); @@ -765,6 +769,81 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService resultMap.put("billList",resultList); return resultMap; } + + + private WxBillProperty generateBillPropertyByBillStandards(WxPayAccountBill wxPayAccountBill,WxPropertyContract wxPropertyContract,Integer isPreview,Long userId,WxBillFeesStandardsListVo svo, + Integer billcount,Map shopInfo) { + return generateBillProperty(wxPayAccountBill,wxPropertyContract,isPreview,svo.getStart(),svo.getEnd(),svo.getReceiveDate(),svo.getTotal(),userId,billcount,shopInfo,"0"); + } + + private WxBillProperty generateBillProperty(WxPayAccountBill wxPayAccountBill,WxPropertyContract wxPropertyContract,Integer isPreview,Date start,Date end,Date receiveDate,String needpay, + Long userId,Integer billcount,Map shopInfo,String standarsTotal) { + final IdWorker idWorker = IdWorker.get(); + WxBillProperty wxBillProperty = new WxBillProperty(); + wxBillProperty.setIsPreview(isPreview); + wxBillProperty.setId(idWorker.nextId()); + wxBillProperty.setPropertyContractId(wxPropertyContract.getId()); + wxBillProperty.setPay("0"); + wxBillProperty.setStarttime(start); + wxBillProperty.setEndtime(end); + wxBillProperty.setReceiveDate(receiveDate); + + wxBillProperty.setNeedPay(needpay); + //wxBillProperty.setOwe(needpay); + wxBillProperty.setReceivePay(needpay); + + //截止收租日在当前时间之前 + Date date = new Date(); + //setExpiredDay(wxBillProperty,dayType,receivePeriod); + wxBillProperty.updateTenantInfo(wxPropertyContract); + wxBillProperty.setIsDel(0); + wxBillProperty.setMerchantId(wxPropertyContract.getMerchantId()); + wxBillProperty.setUserId(userId); + //wxBillProperty.setShopId(wxPropertyContract.getShopId()); + wxBillProperty.setCreatetime(date); + wxBillProperty.setUpdatetime(date); + wxBillProperty.setIsDel(EnumDelStatus.NOT_DEL.getCode()); + wxBillProperty.setRentShopType(wxPropertyContract.getRentShopType()); + wxBillProperty.setPeriod(billcount); + if (shopInfo != null) { + wxBillProperty.setShopInfo(JSONObject.toJSONString(shopInfo)); + } + wxBillProperty.setLatePayRatio(0); + wxBillProperty.setTotalFee(new BigDecimal(needpay).add(new BigDecimal(standarsTotal)).toPlainString()); + + + //计算手续费 + BigDecimal servicePay = new BigDecimal(wxBillProperty.getReceivePay()).multiply(new BigDecimal(wxPayAccountBill.getServiceChargeRate())).divide(new BigDecimal(100), wxPropertyContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP); + wxBillProperty.setServiceChargePay(servicePay.toPlainString()); + //wxBillProperty.setOwe(new BigDecimal(wxBillProperty.getReceivePay()).add(new BigDecimal(wxBillProperty.getServiceChargePay())).toPlainString()); + //wxBillProperty.setOwe(new BigDecimal(wxBillProperty.getReceivePay()).toPlainString()); + + return wxBillProperty; + } + + + private String calcuteStandardsFee(List unFixedList,Date start,Date end,WxPropertyContract wxPropertyContract) { + if (null != unFixedList) { + BigDecimal total = new BigDecimal(0); + for (int j = 0 ; j < unFixedList.size(); j ++) { + WxBillFeesStandardsListVo bfsvo = unFixedList.get(j); + WxFeesStandards feeStandars = bfsvo.getFeeStandards(); + if(EnumFeesStandardsCalcuteUnit.MM.getCode().intValue() == feeStandars.getCalcuteUnit().intValue()) { + bfsvo.setTotal(feeStandars.calcuteTotalMoney(wxPropertyContract.getDecimalSize(), start, end,wxPropertyContract.getRentArea())); + }else if (EnumFeesStandardsCalcuteUnit.HU.getCode().intValue() == feeStandars.getCalcuteUnit().intValue()) { + bfsvo.setTotal(feeStandars.calcuteTotalMoney(wxPropertyContract.getDecimalSize(), start, end,"1")); + }else { + bfsvo.setTotal(feeStandars.calcuteTotalMoney(wxPropertyContract.getDecimalSize(), start, end,"1")); + } + bfsvo.setStart(start); + bfsvo.setEnd(end); + bfsvo.setReceiveDate(DateUtils.getDaySet(start,Calendar.DATE,-1)); + total.add(new BigDecimal(bfsvo.getTotal()));; + } + return total.toPlainString(); + } + return "0"; + } public String getNeedPayMoney(WxPropertyContract wxRentContract,String price,Date startDate,Date endDate,int i,int billTimeVoListSize,boolean saveDb,int dayType,int receivePeriod){ String needpay; @@ -773,11 +852,12 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService BigDecimal priceD = new BigDecimal(price); String needpayD = WxRentContractHelper.getNeedPay(wxRentContract.getDecimalSize(),new BigDecimal(0),priceD,startDate,endDate); needpay = needpayD; + //按月计算 }else{ //年 需要除12 BigDecimal priceD = new BigDecimal(price); if(EnumPriceUnit.Y.getCode().equals(wxRentContract.getPriceUnit())){ - priceD = new BigDecimal(price).divide(new BigDecimal(12),wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); + priceD = new BigDecimal(price).divide(new BigDecimal(12),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP); } //生成金额直接计算