From 49e925cdc41cbfd964907efe011324915c23e5a5 Mon Sep 17 00:00:00 2001 From: luozukai Date: Wed, 27 Feb 2019 14:16:11 +0800 Subject: [PATCH] =?UTF-8?q?[=E9=93=9C=E9=94=A3=E6=B9=BE][=E4=BF=AE?= =?UTF-8?q?=E6=94=B9][=E9=A2=84=E8=B4=A6=E5=8D=95]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/po/WxPropertyContract.java | 13 + .../impl/WxPropertyContractServiceImpl.java | 238 +++++++++++------- .../mapper/WxPropertyContractMapper.xml | 5 +- 3 files changed, 167 insertions(+), 89 deletions(-) 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 5850fd7f0..02f953189 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxPropertyContract.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxPropertyContract.java @@ -166,11 +166,24 @@ public class WxPropertyContract implements Serializable { @io.swagger.annotations.ApiModelProperty(value = "审批流参数", name = "flowParams") private Map flowParams; + @io.swagger.annotations.ApiModelProperty(value = "调整比例", name = "adjustRatio") + private String adjustRatio; + + // 物业预账单列表 @Transient @io.swagger.annotations.ApiModelProperty(value = "物业预账单列表", name = "previewBillRentList") private List previewBillRentList; + + public String getAdjustRatio() { + return adjustRatio; + } + + public void setAdjustRatio(String adjustRatio) { + this.adjustRatio = adjustRatio; + } + public List getPreviewBillRentList() { return previewBillRentList; } 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 62f3f135b..daa711cac 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java @@ -1,5 +1,6 @@ package com.iformall.service.impl; +import com.alibaba.fastjson.JSONArray; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.iformall.common.ErrorCode; @@ -14,16 +15,18 @@ import com.iformall.service.WxFlowRecordService; import com.iformall.service.WxFlowService; import com.iformall.service.WxPropertyContractService; import com.iformall.utils.Constant; +import org.apache.commons.collections.map.HashedMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.net.HttpURLConnection; import java.net.URL; import java.util.*; @@ -226,7 +229,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService //生成预览账单 wxBillPropertyMapper.deletePreviewBill(record); //重新生成 - List billList = buildProperty(new WxMerchant(),record,EnumIsPreview.YES.getCode()); + List billList = buildProperty(new WxMerchant(),userId,record,EnumIsPreview.YES.getCode()); propertyContract.setPreviewBillRentList(billList); message = "保存物业合同信息成功"; @@ -270,7 +273,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService wxPropertyContract.setDeposit(record.getDeposit()); wxPropertyContract.setReceivePeriod(record.getReceivePeriod()); wxPropertyContract.setPayAccount(record.getPayAccount()); - List billList = buildProperty(new WxMerchant(),wxPropertyContract,EnumIsPreview.YES.getCode()); + List billList = buildProperty(new WxMerchant(),userId,wxPropertyContract,EnumIsPreview.YES.getCode()); record.setPreviewBillRentList(billList); }else{ //查询预账单用于展示 @@ -395,6 +398,141 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService } } + public List buildRentMonth(WxMerchant wxMerchant, Long userId, WxPropertyContract wxPropertyContract, int receivePeriod, Integer lease, Date rentalStartDate, Integer price,Integer isPreview) { + String adjustRatio = wxPropertyContract.getAdjustRatio(); + List integers = JSONArray.parseArray(adjustRatio, Integer.class); + integers.add(0, 0); + int size = integers.size(); + int[] priceArr = new int[size]; + priceArr[0] = price; + double priceD = price; + for (int i = 1; i < size; i++) { + priceD = priceD + priceD * integers.get(i) / 10000.0; + priceArr[i] = new BigDecimal(priceD).setScale(0, RoundingMode.HALF_EVEN).intValue(); + } + int month = 12; + int divide = lease / month; + int mod = lease % month; + int[] leaseArr = new int[size]; + for (int i = 0; i < divide; i++) { + leaseArr[i] = month; + } + if (mod > 0) { + leaseArr[divide] = mod; + } + + int billcount = 0; + List resultList = new ArrayList<>(); + for (int i = 0; i < size; i++) { + Calendar instance = Calendar.getInstance(); + instance.setTime(rentalStartDate); + //开始时间 + instance.add(Calendar.MONTH, month * i); + Map resultMap = buildRent(leaseArr[i], receivePeriod, priceArr[i], instance.getTime(), Calendar.MONTH, wxPropertyContract, userId, wxMerchant, billcount,isPreview); + List billRentList = (List)resultMap.get("billList"); + billcount = (Integer)resultMap.get("billcount"); + resultList.addAll(billRentList); + } + return resultList; + } + + public Map buildRent(int lease, int receivePeriod, int price, Date startdate, int dayType, WxPropertyContract wxPropertyContract, Long userId, WxMerchant wxMerchant, int billcount,Integer isPreview) { + Map resultMap = new HashedMap(); + List resultList = new ArrayList<>(); + int extralease = lease % receivePeriod; + int extracount = extralease > 0 ? 1 : 0; + int paycount = lease / receivePeriod + extracount; + int index = paycount - 1; + final IdWorker idWorker = IdWorker.get(); + for (int i = 0; i < paycount; i++) { + WxBillProperty wxBillRent = new WxBillProperty(); + wxBillRent.setIsPreview(isPreview); + + wxBillRent.setId(idWorker.nextId()); + wxBillRent.setPropertyContractId(wxPropertyContract.getId()); + wxBillRent.setPay(0); + int needpay = price * receivePeriod; + + Date date = new Date(); + Calendar instance = Calendar.getInstance(); + instance.setTime(startdate); + instance.add(dayType, receivePeriod * i); + instance.add(Calendar.DAY_OF_MONTH, -1); + Date time = instance.getTime(); + wxBillRent.setReceiveDate(time); + + //账单开始时间 + instance.clear(); + instance.setTime(wxBillRent.getReceiveDate()); + instance.add(Calendar.DAY_OF_MONTH, 1); + wxBillRent.setStarttime(instance.getTime()); + //账单结束时间 + instance.clear(); + instance.setTime(wxBillRent.getStarttime()); + instance.add(dayType, receivePeriod); + instance.add(Calendar.DAY_OF_MONTH, -1); + wxBillRent.setEndtime(instance.getTime()); + + if (extracount > 0 && i == index) { + //账单开始时间 + instance.clear(); + instance.setTime(wxBillRent.getReceiveDate()); + instance.add(Calendar.DAY_OF_MONTH, 1); + wxBillRent.setStarttime(instance.getTime()); + //账单结束时间 + instance.clear(); + instance.setTime(wxBillRent.getStarttime()); + instance.add(dayType, extralease); + instance.add(Calendar.DAY_OF_MONTH, -1); + wxBillRent.setEndtime(instance.getTime()); + needpay = price * extralease; + } + wxBillRent.setNeedPay(needpay); + wxBillRent.setOwe(needpay); + wxBillRent.setReceivePay(needpay); + + //截止收租日在当前时间之前 + if (wxBillRent.getReceiveDate().before(date)) { + long day = (time.getTime() - date.getTime()) / (24 * 60 * 60 * 1000); + wxBillRent.setStatus(EnumBillRentStatus.NOT_PAID.getCode()); + wxBillRent.setExpiredDay(day); + } else {//截止收租日在当前时间之后 + Calendar now = Calendar.getInstance(); + now.add(dayType, receivePeriod); + Date currenttime = now.getTime(); + //当前日期加上周期后小于截止收租日就是没有到期,否则当前待缴 + if (currenttime.before(wxBillRent.getReceiveDate())) { + wxBillRent.setStatus(EnumBillRentStatus.NOT_EXPIRED.getCode()); + wxBillRent.setExpiredDay(0L); + } else { + wxBillRent.setStatus(EnumBillRentStatus.WAIT_PAY.getCode()); + wxBillRent.setExpiredDay(0L); + } + } + + wxBillRent.setTenantId(wxMerchant.getTenantId()); + wxBillRent.setIsDel(0); + wxBillRent.setMerchantId(wxMerchant.getId()); + wxBillRent.setUserId(userId); + wxBillRent.setShopId(wxPropertyContract.getShopId()); + wxBillRent.setCreatetime(date); + wxBillRent.setUpdatetime(date); + wxBillRent.setIsDel(EnumDelStatus.NOT_DEL.getCode()); + wxBillRent.setRentShopType(wxPropertyContract.getRentShopType()); + wxBillRent.setPeriod(++billcount); + try { + wxBillPropertyMapper.insertSelective(wxBillRent); + resultList.add(wxBillRent); + } catch (Exception e) { + logger.error("添加租赁账单失败,e:" + e.getMessage()); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); + } + } + resultMap.put("billcount",billcount); + resultMap.put("billList",resultList); + return resultMap; + } + /** * 根据商户/指定物业合同生成物业账单 * @param wxMerchant @@ -402,7 +540,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService * @return */ @Transactional(rollbackFor = {Exception.class}) - public List buildProperty(WxMerchant wxMerchant,WxPropertyContract propertyContract,Integer isPreview) { + public List buildProperty(WxMerchant wxMerchant,Long userId,WxPropertyContract propertyContract,Integer isPreview) { List result = new ArrayList<>(); WxPropertyContract wxPropertyContract; @@ -419,92 +557,18 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService } if (wxPropertyContract != null) { - int dayType = wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode()) ? Calendar.DAY_OF_MONTH : Calendar.MONTH; int receivePeriod = wxPropertyContract.getReceivePeriod().intValue(); Integer lease = wxPropertyContract.getLease(); - int extralease = lease % receivePeriod; - int extracount = extralease > 0 ? 1 : 0; - int paycount = lease / receivePeriod + extracount; - int index = paycount - 1; - final IdWorker idWorker = IdWorker.get(); - for (int i = 0; i < paycount; i++) { - WxBillProperty wxBillProperty = new WxBillProperty(); - wxBillProperty.setIsPreview(isPreview); - wxBillProperty.setId(idWorker.nextId()); - wxBillProperty.setPropertyContractId(wxPropertyContract.getId()); - wxBillProperty.setPay(0); - - Date date = new Date(); - Calendar instance = Calendar.getInstance(); - instance.setTime(wxPropertyContract.getRentalStartDate()); - instance.add(dayType, receivePeriod * i); - instance.add(Calendar.DAY_OF_MONTH, -1); - Date time = instance.getTime(); - wxBillProperty.setReceiveDate(time); + Date rentalStartDate = propertyContract.getRentalStartDate(); + Integer price = propertyContract.getPrice(); - //账单开始时间 - instance.clear(); - instance.setTime(wxBillProperty.getReceiveDate()); - instance.add(Calendar.DAY_OF_MONTH, 1); - wxBillProperty.setStarttime(instance.getTime()); - //账单结束时间 - instance.clear(); - instance.setTime(wxBillProperty.getStarttime()); - instance.add(dayType, receivePeriod); - instance.add(Calendar.DAY_OF_MONTH, -1); - wxBillProperty.setEndtime(instance.getTime()); - int needpay = wxPropertyContract.getPrice() * receivePeriod; - if (extracount > 0 && i == index) { - //账单开始时间 - instance.clear(); - instance.setTime(wxBillProperty.getReceiveDate()); - instance.add(Calendar.DAY_OF_MONTH, 1); - wxBillProperty.setStarttime(instance.getTime()); - //账单结束时间 - instance.clear(); - instance.setTime(wxBillProperty.getStarttime()); - instance.add(dayType, extralease); - instance.add(Calendar.DAY_OF_MONTH, -1); - wxBillProperty.setEndtime(instance.getTime()); - needpay = wxPropertyContract.getPrice() * extralease; - } - wxBillProperty.setNeedPay(needpay); - wxBillProperty.setOwe(needpay); - wxBillProperty.setReceivePay(needpay); - - //截止收租日在当前时间之前 - if (wxBillProperty.getReceiveDate().before(date)) { - long day = (time.getTime() - date.getTime()) / (24 * 60 * 60 * 1000); - wxBillProperty.setStatus(EnumBillRentStatus.NOT_PAID.getCode()); - wxBillProperty.setExpiredDay(day); - } else {//截止收租日在当前时间之后 - Calendar now = Calendar.getInstance(); - now.add(dayType, receivePeriod); - Date currenttime = now.getTime(); - //当前日期加上周期后小于截止收租日就是没有到期,否则当前待缴 - if (currenttime.before(wxBillProperty.getReceiveDate())) { - wxBillProperty.setStatus(EnumBillRentStatus.NOT_EXPIRED.getCode()); - wxBillProperty.setExpiredDay(0L); - } else { - wxBillProperty.setStatus(EnumBillRentStatus.WAIT_PAY.getCode()); - wxBillProperty.setExpiredDay(0L); - } - } - wxBillProperty.setTenantId(wxMerchant.getTenantId()); - wxBillProperty.setIsDel(0); - wxBillProperty.setMerchantId(wxMerchant.getId()); - wxBillProperty.setShopId(wxPropertyContract.getShopId()); - wxBillProperty.setCreatetime(date); - wxBillProperty.setUpdatetime(date); - wxBillProperty.setIsDel(EnumDelStatus.NOT_DEL.getCode()); - wxBillProperty.setPeriod(i + 1); - try { - wxBillPropertyMapper.insertSelective(wxBillProperty); - result.add(wxBillProperty); - } catch (Exception e) { - logger.error("添加物业账单失败,e:" + e.getMessage()); - throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); - } + //按月计租 + if (propertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_MONTH.getCode())) { + result = buildRentMonth(wxMerchant, userId, propertyContract, receivePeriod, lease, rentalStartDate, price,isPreview); + } else { + //按日计租 + Map resultMap = buildRent(lease, receivePeriod, price, rentalStartDate, Calendar.DAY_OF_MONTH, propertyContract, userId, wxMerchant, 0,isPreview); + result = (List)resultMap.get("billList"); } } for (int i = 0; i < result.size(); i++) { diff --git a/mallinkService/src/main/resources/mapper/WxPropertyContractMapper.xml b/mallinkService/src/main/resources/mapper/WxPropertyContractMapper.xml index 2452b0f86..95765b823 100644 --- a/mallinkService/src/main/resources/mapper/WxPropertyContractMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxPropertyContractMapper.xml @@ -35,6 +35,7 @@ + @@ -44,7 +45,7 @@ `deposit`,`pay_date`,`is_del`,`merchant_name`,`brand`,`business_id`, `shop_type`,`shop_id`,`updatetime`,`createtime`,`rent_area`, `link_person`,`link_phone`,`pay_account`,`filename`,`lease`,`rent_contract_id`, - `start_date`,`end_date`,`apply_status`,`adjust_period`,`business_type` + `start_date`,`end_date`,`apply_status`,`adjust_period`,`business_type`,adjust_ratio @@ -103,7 +104,7 @@ f.floor_name floorName,b.building_name buildingName,receive_period receivePeriod, rc.lease,rc.filepath,rc.filename,rc.pay_account payAccount,rc.sign_date signDate, start_date startDate,end_date endDate,rc.rent_contract_id rentContractId,br.`name` brandName, - s.addr,rc.apply_status applyStatus,rc.adjust_period adjustPeriod,rc.business_type businessType + s.addr,rc.apply_status applyStatus,rc.adjust_period adjustPeriod,rc.business_type businessType,rc.adjust_ratio adjustRatio from wx_property_contract rc left join wx_shop s on rc.shop_id=s.id left join wx_mall_floor f on s.floor=f.id