From e5a88380d552cff1dba4b97a9a5db57b2af21f61 Mon Sep 17 00:00:00 2001 From: luozukai Date: Thu, 15 Aug 2019 11:57:22 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=90=88=E5=90=8C][=E4=BF=AE=E6=94=B9][?= =?UTF-8?q?=E5=BC=80=E5=8F=91=E8=81=94=E8=90=A5=E8=B7=B3=E7=82=B9=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/iformall/enums/EnumMissTimeType.java | 36 ++++++++++ .../service/impl/WxBillRentServiceImpl.java | 65 +++++++++++++------ 2 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 mallinkService/src/main/java/com/iformall/enums/EnumMissTimeType.java diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumMissTimeType.java b/mallinkService/src/main/java/com/iformall/enums/EnumMissTimeType.java new file mode 100644 index 000000000..4ff171f33 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumMissTimeType.java @@ -0,0 +1,36 @@ +package com.iformall.enums; + +/** + * Created by Stormeye on 2018/08/09. + */ +public enum EnumMissTimeType { + + YEAR(1, "残年"), + MONTH(2, "残月"), + ; + + public static EnumMissTimeType getEnum(Integer code) { + for (EnumMissTimeType value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumMissTimeType(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java index 29b38b34c..c1742df11 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java @@ -267,9 +267,13 @@ public class WxBillRentServiceImpl implements WxBillRentService { * ["1000-1200:10",">3000:20"] * @param record */ - public Integer getPayRatio(WxBillRent record,WxRentContract wxRentContract){ + public Integer getPayRatio(WxBillRent record,WxRentContract wxRentContract,EnumMissTimeType timeType){ + if(wxRentContract.getPayRatio() != null){ + return wxRentContract.getPayRatio(); + } BigDecimal revenue = new BigDecimal(record.getRevenue()).divide(new BigDecimal(1000000)).setScale(4, RoundingMode.HALF_EVEN); List ratioList = JSONArray.parseArray(wxRentContract.getBusDiscountRatio(), String.class); + long dayCount = DateUtils.startToEnd(record.getStarttime(),record.getEndtime()); for (String e:ratioList) { String[] array = e.split(":"); @@ -279,12 +283,28 @@ public class WxBillRentServiceImpl implements WxBillRentService { String[] revenueArray = array[0].split("-"); BigDecimal start = new BigDecimal(revenueArray[0]); BigDecimal end = new BigDecimal(revenueArray[1]); + + //残年 (小金额 / 365 * 账单周期天数 )--(大金额 / 365 * 账单周期天数) + if(EnumMissTimeType.YEAR.getCode().equals(timeType.getCode())){ + start = new BigDecimal(revenueArray[0]).divide(new BigDecimal(365)).multiply(new BigDecimal(dayCount)); + end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365)).multiply(new BigDecimal(dayCount)); + }else if(EnumMissTimeType.MONTH.getCode().equals(timeType.getCode())){ + start = new BigDecimal(revenueArray[0]).divide(new BigDecimal(30)).multiply(new BigDecimal(dayCount)); + end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30)).multiply(new BigDecimal(dayCount)); + } if (revenue.compareTo(start) >= 0 && revenue.compareTo(end)<= 0){ return ratio; } }if(e.indexOf(">") >= 0){ String[] revenueArray = array[0].split(">"); BigDecimal end = new BigDecimal(revenueArray[1]); + + //残年 (小金额 / 365 * 账单周期天数 )--(大金额 / 365 * 账单周期天数) + if(EnumMissTimeType.YEAR.getCode().equals(timeType.getCode())){ + end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365)).multiply(new BigDecimal(dayCount)); + }else if(EnumMissTimeType.MONTH.getCode().equals(timeType.getCode())){ + end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30)).multiply(new BigDecimal(dayCount)); + } if (revenue.compareTo(end) >= 0){ return ratio; } @@ -300,39 +320,42 @@ public class WxBillRentServiceImpl implements WxBillRentService { WxRentContract wxRentContract = wxRentContractMapper.selectByPrimaryKey(record.getRentContractId()); SimpleDateFormat sdD = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM"); - Integer ratio = getPayRatio(record,wxRentContract); int startInt = Integer.parseInt(sdD.format(wxBillRent.getStarttime())); int endInt = Integer.parseInt(sdD.format(DateUtils.getDaySet(wxBillRent.getEndtime(),Calendar.DATE,1))); int months = getMonths(sdM.format(wxBillRent.getStarttime())+"-01",sdM.format(DateUtils.getDaySet(wxBillRent.getEndtime(),Calendar.DATE,1))+"-01"); - if(EnumBusRatioTime.YEAR.getCode().equals(wxRentContract.getBusDiscountTime())){ - if(startInt == endInt && months == 12){ - //刚好1年 - BigDecimal hundred = new BigDecimal(100); - BigDecimal revenue = new BigDecimal(record.getRevenue() == null ? 0 : record.getRevenue()).divide(hundred); - BigDecimal payRatio = new BigDecimal(ratio).divide(new BigDecimal(10000)); - BigDecimal price = revenue.multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); - long newReceivePay = price.multiply(hundred).longValue(); - - }else{ + Integer ratio = getPayRatio(record,wxRentContract,null); + if(StringUtils.isNotBlank(wxRentContract.getBusDiscountRatio())){ + if(EnumBusRatioTime.YEAR.getCode().equals(wxRentContract.getBusDiscountTime())){ + if(startInt == endInt && months == 12){ + //刚好1年 + }else{ + ratio = getPayRatio(record,wxRentContract,EnumMissTimeType.YEAR); + } + }else if(EnumBusRatioTime.MONTH.getCode().equals(wxRentContract.getBusDiscountTime())){ + if(startInt == endInt && months == 1){ + //刚好1个月 + }else{ + ratio = getPayRatio(record,wxRentContract,EnumMissTimeType.MONTH); + } } + } - }else if(EnumBusRatioTime.MONTH.getCode().equals(wxRentContract.getBusDiscountTime())){ - if(startInt == endInt && months == 1){ - //刚好1个月 - - - }else{ - - } + BigDecimal hundred = new BigDecimal(100); + BigDecimal revenue = new BigDecimal(record.getRevenue() == null ? 0 : record.getRevenue()).divide(hundred); + BigDecimal payRatio = new BigDecimal(ratio).divide(new BigDecimal(10000)); + BigDecimal price = revenue.multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); + long newReceivePay = price.multiply(hundred).longValue(); + if(newReceivePay > wxBillRent.getReceivePay()){ + wxBillRent.setReceivePay(newReceivePay); } Long oldPrice = wxBillRent.getReceivePay(); Long newPrice = record.getReceivePay(); wxBillRent.setRevenue(record.getRevenue()); - wxBillRent.setReceivePay(oldPrice.equals(newPrice) ? oldPrice : newPrice); + //wxBillRent.setReceivePay(oldPrice.equals(newPrice) ? oldPrice : newPrice); wxBillRent.setUpdatetime(new Date()); try { wxBillRentMapper.updateByPrimaryKeySelective(wxBillRent);