From 134615a71eaf9baab9f14cb352a6f472399eba97 Mon Sep 17 00:00:00 2001 From: luozukai Date: Fri, 30 Aug 2019 20:44:00 +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=B4=A6=E5=8D=95=E7=BB=93=E7=AE=97]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migration/V201908301829__L_CONTRACT.sql | 2 + .../migration/V201908301845__L_CONTRACT.sql | 2 + .../com/iformall/domain/po/WxBillDaily.java | 3 +- .../com/iformall/domain/po/WxBillOther.java | 3 +- .../domain/po/WxBillOtherDeposit.java | 3 +- .../iformall/domain/po/WxBillProperty.java | 3 + .../domain/po/WxBillPropertyDeposit.java | 4 +- .../com/iformall/domain/po/WxBillRent.java | 8 +- .../iformall/enums/EnumBillRentStatus.java | 1 - .../com/iformall/enums/EnumFreezeType.java | 37 ++ .../iformall/service/WxBillSettleService.java | 4 + .../service/impl/WxBillRentServiceImpl.java | 13 +- .../service/impl/WxBillSettleServiceImpl.java | 6 +- .../service/impl/WxFlowServiceImpl.java | 8 +- .../impl/WxPropertyContractServiceImpl.java | 225 ++++---- .../impl/WxRentContractServiceImpl.java | 542 +++++++++--------- .../main/resources/mapper/WxBillAllMapper.xml | 14 + .../resources/mapper/WxBillDailyMapper.xml | 3 +- .../mapper/WxBillOtherDepositMapper.xml | 5 +- .../resources/mapper/WxBillOtherMapper.xml | 4 +- .../mapper/WxBillPropertyDepositMapper.xml | 4 +- .../resources/mapper/WxBillPropertyMapper.xml | 3 +- .../resources/mapper/WxBillRentMapper.xml | 9 +- 23 files changed, 478 insertions(+), 428 deletions(-) create mode 100644 mallinkAdmin/src/main/resources/db/migration/V201908301829__L_CONTRACT.sql create mode 100644 mallinkAdmin/src/main/resources/db/migration/V201908301845__L_CONTRACT.sql create mode 100644 mallinkService/src/main/java/com/iformall/enums/EnumFreezeType.java diff --git a/mallinkAdmin/src/main/resources/db/migration/V201908301829__L_CONTRACT.sql b/mallinkAdmin/src/main/resources/db/migration/V201908301829__L_CONTRACT.sql new file mode 100644 index 000000000..9bc58f5c2 --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V201908301829__L_CONTRACT.sql @@ -0,0 +1,2 @@ +alter table wx_bill_rent +add column `join_rent_price` SMALLINT (1) NULL DEFAULT 0 COMMENT '联营租金'; diff --git a/mallinkAdmin/src/main/resources/db/migration/V201908301845__L_CONTRACT.sql b/mallinkAdmin/src/main/resources/db/migration/V201908301845__L_CONTRACT.sql new file mode 100644 index 000000000..802ea0b85 --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V201908301845__L_CONTRACT.sql @@ -0,0 +1,2 @@ +alter table wx_bill_rent +modify column `join_rent_price` BIGINT(20) NULL DEFAULT NULL COMMENT '联营扣点率'; \ No newline at end of file diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillDaily.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillDaily.java index 7150d717d..e19c127cf 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillDaily.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillDaily.java @@ -106,5 +106,6 @@ public class WxBillDaily extends BaseEntity{ @io.swagger.annotations.ApiModelProperty(value = "结束时间", name = "endtime") private Date endtime; - + @io.swagger.annotations.ApiModelProperty(value = "冻结状态,0正常1冻结", name = "freeze") + private Integer freeze; } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillOther.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillOther.java index f6a584e60..1df316759 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillOther.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillOther.java @@ -130,5 +130,6 @@ public class WxBillOther extends BaseEntity { @Transient private List> shops; - + @io.swagger.annotations.ApiModelProperty(value = "冻结状态,0正常1冻结", name = "freeze") + private Integer freeze; } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillOtherDeposit.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillOtherDeposit.java index 920fd8f06..1a70376a0 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillOtherDeposit.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillOtherDeposit.java @@ -139,5 +139,6 @@ public class WxBillOtherDeposit extends BaseEntity { @io.swagger.annotations.ApiModelProperty(value = "结束时间", name = "endtime") private Date endtime; - + @io.swagger.annotations.ApiModelProperty(value = "冻结状态,0正常1冻结", name = "freeze") + private Integer freeze; } 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 dc1c949c1..1ab08ec51 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillProperty.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillProperty.java @@ -184,4 +184,7 @@ public class WxBillProperty extends BaseEntity { private String latePayMoneyBefore; @Transient private String latePayMoneyUpdate; + + @io.swagger.annotations.ApiModelProperty(value = "冻结状态,0正常1冻结", name = "freeze") + private Integer freeze; } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillPropertyDeposit.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillPropertyDeposit.java index 5fdbf2bbd..42e05dfd5 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillPropertyDeposit.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillPropertyDeposit.java @@ -76,5 +76,7 @@ public class WxBillPropertyDeposit extends BaseEntity { @io.swagger.annotations.ApiModelProperty(value = "支付方式:见枚举EnumBillPayWay", name = "payWay") private Integer payWay; - + + @io.swagger.annotations.ApiModelProperty(value = "冻结状态,0正常1冻结", name = "freeze") + private Integer freeze; } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java index 617fe4334..1c462fa4d 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java @@ -192,6 +192,12 @@ public class WxBillRent extends BaseEntity { private String latePayMoneyBefore; @Transient private String latePayMoneyUpdate; - + @Transient private String busDiscountRatio; + + @io.swagger.annotations.ApiModelProperty(value = "冻结状态,0正常1冻结", name = "freeze") + private Integer freeze; + + @io.swagger.annotations.ApiModelProperty(value = "联营租金", name = "joinRentPrice") + private Long joinRentPrice; } diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumBillRentStatus.java b/mallinkService/src/main/java/com/iformall/enums/EnumBillRentStatus.java index f15abadf3..a9c36a0ff 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumBillRentStatus.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumBillRentStatus.java @@ -12,7 +12,6 @@ public enum EnumBillRentStatus { NOT_EXPIRED(4,"未到期"), RETURN(5, "已退还"), INVALID(6, "失效"), - FREEZE(7, "冻结(结算单审核过程中)"), ; public static EnumBillRentStatus getEnum(Integer code) { diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumFreezeType.java b/mallinkService/src/main/java/com/iformall/enums/EnumFreezeType.java new file mode 100644 index 000000000..6cb2a46db --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumFreezeType.java @@ -0,0 +1,37 @@ +package com.iformall.enums; + +/** + * Created by Stormeye on 2018/08/09. + */ +public enum EnumFreezeType { + + + DEF(0, "正常"), + YES(1, "冻结"), + ; + + public static EnumFreezeType getEnum(Integer code) { + for (EnumFreezeType value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumFreezeType(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/WxBillSettleService.java b/mallinkService/src/main/java/com/iformall/service/WxBillSettleService.java index 9aef23a10..a2eb19513 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxBillSettleService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxBillSettleService.java @@ -4,9 +4,11 @@ import com.github.pagehelper.PageInfo; import com.iformall.common.ResultData; import com.iformall.domain.po.MallUserInfo; import com.iformall.domain.po.WxBillSettle; +import com.iformall.domain.po.WxBillSettleBill; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.util.List; /** * @author luozukai @@ -37,4 +39,6 @@ public interface WxBillSettleService { ResultData saveOrUpdate(WxBillSettle record, MallUserInfo userInfo); void exportBill(HttpServletRequest request, HttpServletResponse response, WxBillSettle wxBillSettle); + + void updateFreeze(List billList, int status); } 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 9c3237b05..b883e5eb6 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java @@ -321,7 +321,11 @@ public class WxBillRentServiceImpl implements WxBillRentService { long newReceivePay; if(ratioVo != null){ newReceivePay = ratioVo.getPrice(); - //ratio = ratioVo.getRatio(); + //wxBillRent.setPayRatio(ratioVo.getRatio().longValue()); + //如果在跳点区间中,修改扣点率 + if(StringUtils.isNotBlank(wxRentContract.getBusDiscountRatio())){ + wxBillRent.setBusDiscountRatio(ratioVo.getUseRatio()); + } }else{ BigDecimal hundred = new BigDecimal(100); BigDecimal revenue = new BigDecimal(record.getRevenue() == null ? 0 : record.getRevenue()).divide(hundred); @@ -329,7 +333,7 @@ public class WxBillRentServiceImpl implements WxBillRentService { BigDecimal price = revenue.multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); newReceivePay = price.multiply(hundred).longValue(); } - + wxBillRent.setJoinRentPrice(newReceivePay); if(newReceivePay > wxBillRent.getReceivePay()){ wxBillRent.setReceivePay(newReceivePay); } @@ -338,11 +342,6 @@ public class WxBillRentServiceImpl implements WxBillRentService { Long newPrice = newReceivePay; wxBillRent.setUpdatetime(new Date()); - //如果在跳点区间中,修改扣点率 - if(StringUtils.isNotBlank(wxRentContract.getBusDiscountRatio())){ - wxBillRent.setBusDiscountRatio(ratioVo.getUseRatio()); - wxBillRent.setPayRatio(new Long(ratio)); - } wxBillRentMapper.updateByPrimaryKeySelective(wxBillRent); if (!oldPrice.equals(newPrice)) { diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillSettleServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillSettleServiceImpl.java index f193e2589..1c9f1096a 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillSettleServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillSettleServiceImpl.java @@ -7,6 +7,7 @@ import com.iformall.common.ResultData; import com.iformall.domain.po.*; import com.iformall.enums.EnumBillRentStatus; import com.iformall.enums.EnumBillType; +import com.iformall.enums.EnumFreezeType; import com.iformall.enums.EnumSettleBillType; import com.iformall.mapper.*; import com.iformall.service.WxBillSettleService; @@ -69,6 +70,7 @@ public class WxBillSettleServiceImpl implements WxBillSettleService { return billSettle; } + @Override public void updateFreeze(List billList,int status){ for (WxBillSettleBill bill:billList) { if(EnumBillType.RENT.getCode().equals(bill.getBillType())) { @@ -132,8 +134,8 @@ public class WxBillSettleServiceImpl implements WxBillSettleService { //改为冻结状态 if (record.getFlowParams() != null && record.getFlowParams().size() > 0) { - updateFreeze(record.getReceiveBillIds(),EnumBillRentStatus.FREEZE.getCode()); - updateFreeze(record.getPayBillIds(),EnumBillRentStatus.FREEZE.getCode()); + updateFreeze(record.getReceiveBillIds(), EnumFreezeType.YES.getCode()); + updateFreeze(record.getPayBillIds(),EnumFreezeType.YES.getCode()); } //启动审批流 diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java index 1dca2761d..bf0b130f4 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java @@ -88,6 +88,8 @@ public class WxFlowServiceImpl implements WxFlowService { private WxRentContractMapper wxRentContractMapper; @Autowired private WxBillSettleMapper wxBillSettleMapper; + @Autowired + private WxBillSettleService wxBillSettleService; /** * 获取流程key @@ -278,9 +280,11 @@ public class WxFlowServiceImpl implements WxFlowService { wxBillSettle.setApplyStatus(applyStatus); wxBillSettleMapper.update(wxBillSettle); - // 审批完成,账单解冻 + //审批完成,账单解冻 if(EnumRentContractAppStatus.FINISH.getCode().intValue() == applyStatus.intValue()) { - + WxBillSettle settle = wxBillSettleService.getById(businessId); + wxBillSettleService.updateFreeze(settle.getReceiveBillIds(), EnumFreezeType.DEF.getCode()); + wxBillSettleService.updateFreeze(settle.getPayBillIds(),EnumFreezeType.DEF.getCode()); } } } 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 338d6c461..3e6bd2e5b 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java @@ -97,26 +97,26 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService } //init dateDiff - if (wxPropertyContract.getRentalStartDate() != null && wxPropertyContract.getRentalEndDate() != null) { + if(wxPropertyContract.getRentalStartDate() != null && wxPropertyContract.getRentalEndDate() != null){ //加1天 - Date newEndDate = DateUtils.getDaySet(wxPropertyContract.getRentalEndDate(), Calendar.DATE, 1); - int[] array = DateUtils.getDiff(wxPropertyContract.getRentalStartDate(), newEndDate); - result.put("totalPeriodMonth", array[0]); - result.put("totalPeriodDay", array[1]); + Date newEndDate = DateUtils.getDaySet(wxPropertyContract.getRentalEndDate(),Calendar.DATE,1); + int[] array = DateUtils.getDiff(wxPropertyContract.getRentalStartDate(),newEndDate); + result.put("totalPeriodMonth",array[0]); + result.put("totalPeriodDay",array[1]); } //init 租赁单价 String rentInfo = wxPropertyContract.getRentInfo(); - if (StringUtils.isNotBlank(rentInfo)) { + if(StringUtils.isNotBlank(rentInfo)){ JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); int size = rentInfoArray.size(); //查询rent_info 包括shopId for (int i = 0; i < size; i++) { JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); Double rentPrice = rentInfoObject.getDouble("rentPrice"); - Long price = wxPropertyContract.getPrice() / 100; - if (rentPrice == null) { - if (StringUtils.isNotBlank(wxPropertyContract.getRentArea()) && !"0".equals(wxPropertyContract.getRentArea()) && !"0.00".equals(wxPropertyContract.getRentArea()) && !"0.0".equals(wxPropertyContract.getRentArea())) { + Long price = wxPropertyContract.getPrice()/100; + if(rentPrice == null){ + if(StringUtils.isNotBlank(wxPropertyContract.getRentArea()) && !"0".equals(wxPropertyContract.getRentArea()) && !"0.00".equals(wxPropertyContract.getRentArea())&& !"0.0".equals(wxPropertyContract.getRentArea()) ) { Double rentArea = Double.parseDouble(wxPropertyContract.getRentArea()); rentPrice = new BigDecimal((double) price / rentArea).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); rentInfoObject.put("rentPrice", rentPrice); @@ -124,9 +124,9 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService } } wxPropertyContract.setRentInfo(rentInfoArray.toJSONString()); - } else { - if (StringUtils.isNotBlank(wxPropertyContract.getRentArea()) && !"0".equals(wxPropertyContract.getRentArea()) && !"0.00".equals(wxPropertyContract.getRentArea()) && !"0.0".equals(wxPropertyContract.getRentArea())) { - if (StringUtils.isNotBlank(wxPropertyContract.getRentArea()) && !"0".equals(wxPropertyContract.getRentArea()) && !"0.00".equals(wxPropertyContract.getRentArea())) { + }else{ + if(StringUtils.isNotBlank(wxPropertyContract.getRentArea()) && !"0".equals(wxPropertyContract.getRentArea()) && !"0.00".equals(wxPropertyContract.getRentArea())&& !"0.0".equals(wxPropertyContract.getRentArea()) ) { + if(StringUtils.isNotBlank(wxPropertyContract.getRentArea()) && !"0".equals(wxPropertyContract.getRentArea()) && !"0.00".equals(wxPropertyContract.getRentArea())) { Long price = wxPropertyContract.getPrice(); Double rentArea = Double.parseDouble(wxPropertyContract.getRentArea()) * 100; Double rentPrice = new BigDecimal((double) price / rentArea).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); @@ -139,10 +139,10 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService } } } - if (wxPropertyContract.getPriceUnit() == null) { + if(wxPropertyContract.getPriceUnit() == null){ wxPropertyContract.setPriceUnit(EnumPriceUnit.M.getCode()); } - if (wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode())) { + if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode())){ wxPropertyContract.setAdjustPeriod(EnumRentContractAdjustPeriod.ADJUST_PERIOD_MONTH.getCode()); wxPropertyContract.setPriceUnit(EnumPriceUnit.D.getCode()); } @@ -171,13 +171,13 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService //租赁费用欠缴 WxRentContract wxRentContract = new WxRentContract(); wxRentContract.setId(wxPropertyContract.getRentContractId()); - result.put("rentOweCount", wxRentContractMapper.queryOweCount(wxRentContract)); + result.put("rentOweCount",wxRentContractMapper.queryOweCount(wxRentContract)); //物业费用欠缴 WxPropertyContract propertyContract = new WxPropertyContract(); propertyContract.setId(id); - result.put("propertyOweCount", wxPropertyContractMapper.queryOweCount(propertyContract)); + result.put("propertyOweCount",wxPropertyContractMapper.queryOweCount(propertyContract)); //押金欠缴 - result.put("depositOweCount", wxBillPropertyDepositMapper.queryOweCount(propertyContract)); + result.put("depositOweCount",wxBillPropertyDepositMapper.queryOweCount(propertyContract)); //押金状态 WxBillPropertyDeposit wxBillPropertyDeposit = new WxBillPropertyDeposit(); wxBillPropertyDeposit.setPropertyContractId(id); @@ -190,8 +190,8 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService wxFlowRecord.setBusinessId(id); wxFlowRecord.setStatus(EnumFlowRecordStatus.NEW.getCode()); List flowRecordList = wxFlowRecordService.findList(wxFlowRecord); - if (!CollectionUtils.isEmpty(flowRecordList)) { - result.put("remark", flowRecordList.get(0).getRemark()); + if(!CollectionUtils.isEmpty(flowRecordList)){ + result.put("remark",flowRecordList.get(0).getRemark()); } //查询预账单用于展示 @@ -212,14 +212,14 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService /** * 重新生成账单(预账单调整) */ - public void savePreviewBill(WxPropertyContract record) { - if (CollectionUtils.isEmpty(record.getPreviewBillRentList())) { + public void savePreviewBill(WxPropertyContract record){ + if(CollectionUtils.isEmpty(record.getPreviewBillRentList())){ return; } wxBillPropertyMapper.deletePreviewBill(record); final IdWorker idWorker = IdWorker.get(); int count = 1; - for (WxBillProperty bill : record.getPreviewBillRentList()) { + for (WxBillProperty bill:record.getPreviewBillRentList()) { bill.setId(idWorker.nextId()); Date date = new Date(); bill.setPropertyContractId(record.getId()); @@ -238,7 +238,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService bill.setIsDel(EnumDelStatus.NOT_DEL.getCode()); bill.setShopId(record.getShopId()); bill.setExpiredDay(0L); - setExpiredDay(bill, Calendar.MONTH, record.getReceivePeriod()); + setExpiredDay(bill,Calendar.MONTH,record.getReceivePeriod()); if (bill.getReceivePay().equals(0L)) { bill.setStatus(EnumBillRentStatus.PAID.getCode()); bill.setPayDate(date); @@ -253,7 +253,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService public ResultData saveOrUpdate(WxPropertyContract record, Long userId, String userName) { // 保存调整金额(预账单调整) boolean haspreview = false; - if (!CollectionUtils.isEmpty(record.getPreviewBillRentList())) { + if(!CollectionUtils.isEmpty(record.getPreviewBillRentList())){ savePreviewBill(record); haspreview = true; } @@ -345,7 +345,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService //生成预览账单 wxBillPropertyMapper.deletePreviewBill(record); //重新生成 - List billList = buildProperty(new WxMerchant(), userId, record, EnumIsPreview.YES.getCode(), true); + List billList = buildProperty(new WxMerchant(),userId,record,EnumIsPreview.YES.getCode(),true); record.setPreviewBillRentList(billList); message = "保存物业合同信息成功"; @@ -358,13 +358,13 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService List billList = wxBillPropertyMapper.findList(wxBillRent); record.setPreviewBillRentList(billList); - if (!haspreview) { + if(!haspreview){ if (record.getReceivePeriod() != null && record.getLease() != null && record.getPrice() != null && !record.getReceivePeriod().equals(0) && !record.getLease().equals(0) && !record.getPrice().equals(0l)) { //删除预账单,重新生成 wxBillPropertyMapper.deletePreviewBill(record); //重新生成 - billList = buildProperty(new WxMerchant(), userId, record, EnumIsPreview.YES.getCode(), true); + billList = buildProperty(new WxMerchant(),userId,record,EnumIsPreview.YES.getCode(),true); record.setPreviewBillRentList(billList); } } @@ -466,7 +466,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService billProperty.setIsPreview(EnumIsPreview.NO.getCode()); billProperty.setMerchantId(record.getMerchantId()); wxBillPropertyMapper.updatePreviewStatus(billProperty); - if (record.getDeposit() > 0) { + if(record.getDeposit() > 0) { buildDeposit(record); } } @@ -523,7 +523,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService } } - public String getShopInfoStr(WxPropertyContract wxPropertyContract) { + public String getShopInfoStr(WxPropertyContract wxPropertyContract){ String rentInfo = wxPropertyContract.getRentInfo(); Map shopInfo = new HashMap<>(); if (rentInfo != null) { @@ -536,7 +536,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService return JSONObject.toJSONString(shopInfo); } - public List buildRentMonth(WxMerchant wxMerchant, Long userId, WxPropertyContract wxPropertyContract, int receivePeriod, Integer lease, Date rentalStartDate, Long price, Integer isPreview, boolean saveDb) { + public List buildRentMonth(WxMerchant wxMerchant, Long userId, WxPropertyContract wxPropertyContract, int receivePeriod, Integer lease, Date rentalStartDate, Long price, Integer isPreview,boolean saveDb) { String adjustRatio = wxPropertyContract.getAdjustRatio(); String rentInfo = wxPropertyContract.getRentInfo(); Map shopInfo = new HashMap<>(); @@ -560,19 +560,14 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService priceD = priceD + priceD * integers.get(i) / 10000.0; priceArr[i] = new BigDecimal(priceD).setScale(0, RoundingMode.HALF_EVEN).longValue(); } - } else if (wxPropertyContract.getAdjustRatioWay().equals(EnumRentContractAdjustRatioWay.MONEY.getCode())) { + } else { long priceD = price; for (int i = 1; i < size; i++) { priceD = priceD + integers.get(i); priceArr[i] = new BigDecimal(priceD).setScale(0, RoundingMode.HALF_EVEN).longValue(); } - } else { - for (int i = 1; i < size; i++) { - priceArr[i] = new BigDecimal(integers.get(i)).setScale(0, RoundingMode.HALF_EVEN).longValue(); - } } - int month = 12; int divide = lease / month; int mod = lease % month; @@ -592,90 +587,89 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService Calendar instance = Calendar.getInstance(); Date startDate; //自然月 - if (wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) { - if (i == 0) { //第一期 + if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ + if(i == 0){ //第一期 startDate = rentalStartDate; - } else { + }else{ instance.setTime(rentalStartDate); instance.add(Calendar.MONTH, month * i); startDate = DateUtils.getFirstDayForCurrMonth(instance.getTime()); } - } else { + }else{ instance.setTime(rentalStartDate); instance.add(Calendar.MONTH, month * i); startDate = instance.getTime(); } yearList.add(startDate); } - - Map resultMap = buildRent(receivePeriod, priceArr, yearList, Calendar.MONTH, wxPropertyContract, userId, wxMerchant, billcount, isPreview, shopInfo, saveDb); - List billRentList = (List) resultMap.get("billList"); + Map resultMap = buildRent(receivePeriod, priceArr, yearList, Calendar.MONTH, wxPropertyContract, userId, wxMerchant, billcount, isPreview, shopInfo,saveDb); + List billRentList = (List)resultMap.get("billList"); resultList.addAll(billRentList); return resultList; } - public Map buildRent(int receivePeriod, long[] priceArrs, List yearList, int dayType, WxPropertyContract wxPropertyContract, Long userId, WxMerchant wxMerchant, int billcount, Integer isPreview, Map shopInfo, boolean saveDb) { + public Map buildRent(int receivePeriod,long[] priceArrs, List yearList,int dayType, WxPropertyContract wxPropertyContract, Long userId, WxMerchant wxMerchant, int billcount, Integer isPreview,Map shopInfo,boolean saveDb) { SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); - Map resultMap = new HashedMap(); + Map resultMap = new HashedMap(); List resultList = new ArrayList<>(); final IdWorker idWorker = IdWorker.get(); Date endDate = null; - if (yearList.size() > 1) { + if(yearList.size() > 1){ endDate = yearList.get(1); } List billTimeVoList = new ArrayList<>(); - if (saveDb) { - billTimeVoList = WxRentContractServiceImpl.initBillTimeList(wxPropertyContract.getRentalStartDate(), wxPropertyContract.getRentalEndDate(), wxPropertyContract.getAdjustPeriod(), dayType, receivePeriod); - } else { + if(saveDb){ + billTimeVoList = WxRentContractServiceImpl.initBillTimeList(wxPropertyContract.getRentalStartDate(),wxPropertyContract.getRentalEndDate(),wxPropertyContract.getAdjustPeriod(),dayType,receivePeriod); + }else{ //预账单编辑账期,生成金额 - for (WxBillProperty rent : wxPropertyContract.getPreviewBillRentList()) { + for (WxBillProperty rent:wxPropertyContract.getPreviewBillRentList()) { BillTimeVo billTimeVo = new BillTimeVo(); billTimeVo.setStartDate(rent.getStarttime()); billTimeVo.setEndDate(rent.getEndtime()); - billTimeVo.setReceiveDate(DateUtils.getDaySet(rent.getStarttime(), Calendar.DATE, -1)); + billTimeVo.setReceiveDate(DateUtils.getDaySet(rent.getStarttime(),Calendar.DATE,-1)); billTimeVoList.add(billTimeVo); } } int index = 0; for (int i = 0; i < billTimeVoList.size(); i++) { - BillTimeVo billTimeVo = billTimeVoList.get(i); + BillTimeVo billTimeVo = billTimeVoList.get(i); //计算金额 long needpay = 0; boolean flag = false; - 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))) { + 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)) { + if(!saveDb && billTimeVo.getEndDate().after(endDate)) { long needpayFront = 0; long 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); - } else { - if (billTimeVo.getStartDate().before(endDate)) { - needpayFront = getNeedPayMoney(wxPropertyContract, priceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb); - needpayAfter = getNeedPayMoney(wxPropertyContract, priceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb); - } else { - needpayFront = getNeedPayMoney(wxPropertyContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb); + 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; + needpay = needpayFront+needpayAfter; flag = true; } - if (index >= yearList.size() - 1) { + if(index >= yearList.size()-1){ endDate = null; - } else { - endDate = yearList.get(index + 1);//price index 0开始,year.end 从第二年开始 + }else{ + endDate = yearList.get(index+1);//price index 0开始,year.end 从第二年开始 //logger.info("==========cross:"+sd.format(endDate)); } } @@ -684,8 +678,8 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService } //计算金额 - if (!flag) { - needpay = getNeedPayMoney(wxPropertyContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb); + if(!flag){ + needpay = getNeedPayMoney(wxPropertyContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod); } WxBillProperty wxBillProperty = new WxBillProperty(); @@ -703,7 +697,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService //截止收租日在当前时间之前 Date date = new Date(); - setExpiredDay(wxBillProperty, dayType, receivePeriod); + setExpiredDay(wxBillProperty,dayType,receivePeriod); wxBillProperty.setTenantId(wxPropertyContract.getTenantId()); wxBillProperty.setIsDel(0); wxBillProperty.setMerchantId(wxPropertyContract.getMerchantId()); @@ -721,31 +715,31 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService resultList.add(wxBillProperty); } //批量生成预账单 - if (saveDb) { + if(saveDb) { wxBillPropertyMapper.insertBills(resultList); } - resultMap.put("billcount", billcount); - resultMap.put("billList", resultList); + resultMap.put("billcount",billcount); + resultMap.put("billList",resultList); return resultMap; } - public long getNeedPayMoney(WxPropertyContract wxRentContract, long price, Date startDate, Date endDate, int i, int billTimeVoListSize, boolean saveDb) { + public long getNeedPayMoney(WxPropertyContract wxRentContract,long price,Date startDate,Date endDate,int i,int billTimeVoListSize,boolean saveDb,int dayType,int receivePeriod){ long needpay; //按日 - if (wxRentContract.getPriceUnit().equals(EnumPriceUnit.D.getCode())) { + if (wxRentContract.getPriceUnit().equals(EnumPriceUnit.D.getCode())){ Double priceD = new Double(price); - double needpayD = WxRentContractServiceImpl.getNeedPay(0, priceD, startDate, endDate); + double needpayD = WxRentContractServiceImpl.getNeedPay(0,priceD,startDate,endDate); needpay = new Double(needpayD).longValue(); - } else { + }else{ //年 需要除12 Double priceD = new Double(price); - if (EnumPriceUnit.Y.getCode().equals(wxRentContract.getPriceUnit())) { - priceD = new Double(price) / 12; + if(EnumPriceUnit.Y.getCode().equals(wxRentContract.getPriceUnit())){ + priceD = new Double(price)/12; } //生成金额直接计算 - if (!saveDb) { - needpay = new Double(WxRentContractServiceImpl.getMonthNeedPay(priceD, startDate, endDate)).longValue(); + if(!saveDb){ + needpay = new Double(WxRentContractServiceImpl.getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod)).longValue(); return needpay; } @@ -754,37 +748,37 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdMR = new SimpleDateFormat("MM-dd"); - if (i == billTimeVoListSize - 1) {//最后 - if (sdMR.format(startDate).equals(sdMR.format(wxRentContract.getStartDate())) && sdMR.format(endDate).equals(sdMR.format(wxRentContract.getEndDate()))) { - int months = WxRentContractServiceImpl.getMonths(sdM.format(startDate) + "-01", sdM.format(endDate) + "-01"); + if(i == billTimeVoListSize - 1){//最后 + if(sdMR.format(startDate).equals(sdMR.format(wxRentContract.getStartDate())) && sdMR.format(endDate).equals(sdMR.format(wxRentContract.getEndDate())) ){ + int months = WxRentContractServiceImpl.getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); months++; needpay = new Double(months * priceD).longValue(); - } else { - needpay = new Double(WxRentContractServiceImpl.getMonthNeedPay(priceD, startDate, endDate)).longValue(); + }else { + needpay = new Double(WxRentContractServiceImpl.getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod)).longValue(); } - } else if (i == 0) {//第一期 - if (wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) { - if (isFirstDay(startDate)) { - int months = WxRentContractServiceImpl.getMonths(sdM.format(startDate) + "-01", sdM.format(endDate) + "-01"); + }else if(i == 0){//第一期 + if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ + if(isFirstDay(startDate)){ + int months = WxRentContractServiceImpl.getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); months++; needpay = new Double(months * priceD).longValue(); - } else { - needpay = new Double(WxRentContractServiceImpl.getMonthNeedPay(priceD, startDate, endDate)).longValue(); + }else{ + needpay = new Double(WxRentContractServiceImpl.getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod)).longValue(); } - } else { - if (isFirstDay(startDate)) { - int months = WxRentContractServiceImpl.getMonths(sdM.format(startDate) + "-01", sdM.format(endDate) + "-01"); - if (isFirstDay(startDate)) { + }else{ + if(isFirstDay(startDate)){ + int months = WxRentContractServiceImpl.getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); + if(isFirstDay(startDate)){ months++; } needpay = new Double(months * priceD).longValue(); - } else { - needpay = new Double(WxRentContractServiceImpl.getMonthNeedPay(priceD, startDate, endDate)).longValue(); + }else{ + needpay = new Double(WxRentContractServiceImpl.getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod)).longValue(); } } - } else {//中间 - int months = WxRentContractServiceImpl.getMonths(sdM.format(startDate) + "-01", sdM.format(endDate) + "-01"); - if (isFirstDay(startDate)) { + }else{//中间 + int months = WxRentContractServiceImpl.getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); + if(isFirstDay(startDate)){ months++; } needpay = new Double(months * priceD).longValue(); @@ -793,7 +787,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService return needpay; } - public void setExpiredDay(WxBillProperty wxBillProperty, int dayType, int receivePeriod) { + public void setExpiredDay(WxBillProperty wxBillProperty,int dayType, int receivePeriod){ Date date = new Date(); wxBillProperty.setExpiredDay(0L); if (wxBillProperty.getReceiveDate().before(date)) { @@ -815,9 +809,9 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService } } - public boolean isFirstDay(Date date) { + public boolean isFirstDay(Date date){ int dateInt = Integer.parseInt(new SimpleDateFormat("d").format(date)); - if (dateInt == 1) { + if(dateInt == 1){ return true; } return false; @@ -825,18 +819,17 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService /** * 根据商户/指定物业合同生成物业账单 - * * @param wxMerchant * @param propertyContract * @return */ @Override @Transactional(rollbackFor = {Exception.class}) - public List buildProperty(WxMerchant wxMerchant, Long userId, WxPropertyContract propertyContract, Integer isPreview, boolean saveDb) { + public List buildProperty(WxMerchant wxMerchant,Long userId,WxPropertyContract propertyContract,Integer isPreview,boolean saveDb) { List result = new ArrayList<>(); WxPropertyContract wxPropertyContract; - if (propertyContract == null) { + if(propertyContract == null){ //根据商户ID找出合同 wxPropertyContract = new WxPropertyContract(); wxPropertyContract.setMerchantId(wxMerchant.getId()); @@ -844,7 +837,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService if (list.size() > 0) { wxPropertyContract = list.get(0); } - } else { + }else{ wxPropertyContract = propertyContract; } @@ -859,10 +852,10 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService Long price = propertyContract.getPrice(); //按月计租 - result = buildRentMonth(wxMerchant, userId, propertyContract, receivePeriod, lease, rentalStartDate, price, isPreview, saveDb); + result = buildRentMonth(wxMerchant, userId, propertyContract, receivePeriod, lease, rentalStartDate, price,isPreview,saveDb); } for (int i = 0; i < result.size(); i++) { - result.get(i).setPeriod(i + 1); + result.get(i).setPeriod(i+1); } return result; } @@ -890,7 +883,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService try { String exportFileName = wxPropertyContract.getFilename(); downLoadFromUrl(wxPropertyContract.getFilepath(), filename, filepath); - downFile(destPath, wxPropertyContract.getFilename(), exportFileName, response, request); + downFile(destPath, wxPropertyContract.getFilename(), exportFileName,response, request); org.apache.commons.io.FileUtils.forceDelete(dest); } catch (IOException e) { logger.info("创建本地文件失败" + e.getMessage()); @@ -914,9 +907,9 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService HashMap shopMap = new HashMap<>(3); int rentedCount = rentedList.size(); int unrentedCount = unrentedList.size(); - shopMap.put("rentedCount", rentedCount); - shopMap.put("unrentedCount", unrentedCount); - shopMap.put("allCount", rentedCount + unrentedCount); + shopMap.put("rentedCount",rentedCount); + shopMap.put("unrentedCount",unrentedCount); + shopMap.put("allCount",rentedCount+unrentedCount); resultData.put("shopCountInfo", shopMap); //需要更新的状态 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 08ad49648..14f37a907 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -130,31 +130,31 @@ public class WxRentContractServiceImpl implements WxRentContractService { } //init dateDiff - if (wxRentContract.getRentalStartDate() != null && wxRentContract.getRentalEndDate() != null) { + if(wxRentContract.getRentalStartDate() != null && wxRentContract.getRentalEndDate() != null){ //加1天 - Date newEndDate = DateUtils.getDaySet(wxRentContract.getRentalEndDate(), Calendar.DATE, 1); - int[] array = DateUtils.getDiff(wxRentContract.getRentalStartDate(), newEndDate); - result.put("totalPeriodMonth", array[0]); - result.put("totalPeriodDay", array[1]); + Date newEndDate = DateUtils.getDaySet(wxRentContract.getRentalEndDate(),Calendar.DATE,1); + int[] array = DateUtils.getDiff(wxRentContract.getRentalStartDate(),newEndDate); + result.put("totalPeriodMonth",array[0]); + result.put("totalPeriodDay",array[1]); } //init rentPrice - if (StringUtils.isNotBlank(wxRentContract.getRentPrice())) { - wxRentContract.setRentPrice(Double.parseDouble(wxRentContract.getRentPrice()) / 100 + ""); + if(StringUtils.isNotBlank(wxRentContract.getRentPrice())){ + wxRentContract.setRentPrice(Double.parseDouble(wxRentContract.getRentPrice())/100 + ""); } //init 租赁单价 String rentInfo = wxRentContract.getRentInfo(); - if (StringUtils.isNotBlank(rentInfo)) { + if(StringUtils.isNotBlank(rentInfo)){ JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); int size = rentInfoArray.size(); //查询rent_info 包括shopId for (int i = 0; i < size; i++) { JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); Double rentPrice = rentInfoObject.getDouble("rentPrice"); - Long price = wxRentContract.getPrice() / 100; - if (rentPrice == null) { - if (StringUtils.isNotBlank(wxRentContract.getRentArea()) && !"0".equals(wxRentContract.getRentArea()) && !"0.00".equals(wxRentContract.getRentArea()) && !"0.0".equals(wxRentContract.getRentArea())) { + Long price = wxRentContract.getPrice()/100; + if(rentPrice == null){ + if(StringUtils.isNotBlank(wxRentContract.getRentArea()) && !"0".equals(wxRentContract.getRentArea()) && !"0.00".equals(wxRentContract.getRentArea()) && !"0.0".equals(wxRentContract.getRentArea()) ) { Double rentArea = Double.parseDouble(wxRentContract.getRentArea()); rentPrice = new BigDecimal((float) price / rentArea).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); rentInfoObject.put("rentPrice", rentPrice); @@ -162,25 +162,25 @@ public class WxRentContractServiceImpl implements WxRentContractService { } } wxRentContract.setRentInfo(rentInfoArray.toJSONString()); - } else { - if (wxRentContract.getRentPrice() == null || "0".equals(wxRentContract.getRentPrice())) { - if (StringUtils.isNotBlank(wxRentContract.getRentArea()) && !"0".equals(wxRentContract.getRentArea()) && !"0.00".equals(wxRentContract.getRentArea()) && !"0.0".equals(wxRentContract.getRentArea())) { - Long price = wxRentContract.getPrice() / 100; + }else{ + if(wxRentContract.getRentPrice() == null || "0".equals(wxRentContract.getRentPrice())){ + if(StringUtils.isNotBlank(wxRentContract.getRentArea()) && !"0".equals(wxRentContract.getRentArea()) && !"0.00".equals(wxRentContract.getRentArea()) && !"0.0".equals(wxRentContract.getRentArea()) ) { + Long price = wxRentContract.getPrice()/100; Double rentArea = Double.parseDouble(wxRentContract.getRentArea()); - Double rentPrice = new BigDecimal((float) price / rentArea).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - if (rentPrice > 0) { + Double rentPrice = new BigDecimal((float)price/rentArea).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + if(rentPrice > 0){ wxRentContract.setRentPrice(rentPrice.toString()); - } else { + }else{ wxRentContract.setRentPrice("0"); } } } } - if (wxRentContract.getPriceUnit() == null) { + if(wxRentContract.getPriceUnit() == null){ wxRentContract.setPriceUnit(EnumPriceUnit.M.getCode()); } - if (wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode())) { + if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode())){ wxRentContract.setAdjustPeriod(EnumRentContractAdjustPeriod.ADJUST_PERIOD_MONTH.getCode()); wxRentContract.setPriceUnit(EnumPriceUnit.D.getCode()); } @@ -216,13 +216,13 @@ public class WxRentContractServiceImpl implements WxRentContractService { result.put("applyStatus", wxRentContract.getApplyStatus()); //租赁费用欠缴 - result.put("rentOweCount", wxRentContractMapper.queryOweCount(wxRentContract)); + result.put("rentOweCount",wxRentContractMapper.queryOweCount(wxRentContract)); //物业费用欠缴 WxPropertyContract propertyContract = new WxPropertyContract(); propertyContract.setRentContractId(id); - result.put("propertyOweCount", wxPropertyContractMapper.queryOweCount(propertyContract)); + result.put("propertyOweCount",wxPropertyContractMapper.queryOweCount(propertyContract)); //押金欠缴 - result.put("depositOweCount", wxBillDepositMapper.queryOweCount(wxRentContract)); + result.put("depositOweCount",wxBillDepositMapper.queryOweCount(wxRentContract)); //押金状态 WxBillDeposit wxBillDeposit = new WxBillDeposit(); wxBillDeposit.setRentContractId(id); @@ -235,8 +235,8 @@ public class WxRentContractServiceImpl implements WxRentContractService { wxFlowRecord.setBusinessId(id); wxFlowRecord.setStatus(EnumFlowRecordStatus.NEW.getCode()); List flowRecordList = wxFlowRecordService.findList(wxFlowRecord); - if (!CollectionUtils.isEmpty(flowRecordList)) { - result.put("remark", flowRecordList.get(0).getRemark()); + if(!CollectionUtils.isEmpty(flowRecordList)){ + result.put("remark",flowRecordList.get(0).getRemark()); } //查询预账单用于展示 @@ -244,31 +244,26 @@ public class WxRentContractServiceImpl implements WxRentContractService { wxBillRent.setRentContractId(id); wxBillRent.setSortColumns(BaseEntity.SortField.Period_ASC); List resultList = wxBillRentMapper.findList(wxBillRent); - result.put("previewBillRentList", resultList); + result.put("previewBillRentList",resultList); return result; } - /** * 计算金额 - * * @param ratio * @param revenueLong * @return */ - public static Long countPrice(Integer ratio, Long revenueLong, int timeType, int period, int from) { + public static Long countPrice(Integer ratio,Long revenueLong,int timeType,int period,int from){ BigDecimal hundred = new BigDecimal(100); BigDecimal revenue = new BigDecimal(revenueLong == null ? 0 : revenueLong).divide(hundred); BigDecimal payRatio = new BigDecimal(ratio == null ? 0 : ratio).divide(new BigDecimal(10000)); BigDecimal price; - if (EnumMissTimeType.YEAR.getCode().equals(timeType) && EnumGetRatioFrom.RENT.getCode().equals(from)) { - price = revenue.multiply(new BigDecimal(12)).multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); - ; - ; - } else if (EnumMissTimeType.PERIOD.getCode().equals(timeType) && EnumGetRatioFrom.RENT.getCode().equals(from)) { - price = revenue.multiply(new BigDecimal(period)).multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); - ; - } else { + if(EnumMissTimeType.YEAR.getCode().equals(timeType) && EnumGetRatioFrom.RENT.getCode().equals(from)){ + price = revenue.multiply(new BigDecimal(12)).multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN);;; + }else if(EnumMissTimeType.PERIOD.getCode().equals(timeType) && EnumGetRatioFrom.RENT.getCode().equals(from)){ + price = revenue.multiply(new BigDecimal(period)).multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN);; + }else{ price = revenue.multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); } return price.multiply(hundred).longValue(); @@ -278,9 +273,9 @@ public class WxRentContractServiceImpl implements WxRentContractService { * 获取设置的跳点率 * ["1000-1200:10",">3000:20"] */ - public static RatioVo getPayRatio(int from, Long revenueLong, String busDiscountRatio, int timeType, long dayCount, int period) { + public static RatioVo getPayRatio(int from,Long revenueLong,String busDiscountRatio,int timeType,long dayCount,int period){ RatioVo ratioVo = new RatioVo(); - if (StringUtils.isBlank(busDiscountRatio)) { + if(StringUtils.isBlank(busDiscountRatio)){ return ratioVo; } List ratioList = JSONArray.parseArray(busDiscountRatio, String.class); @@ -293,80 +288,80 @@ public class WxRentContractServiceImpl implements WxRentContractService { String[] array = e.split(":"); Integer ratio = Integer.parseInt(array[1]); - if (e.indexOf("-") >= 0) { + if(e.indexOf("-") >= 0){ 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)) { - if (EnumGetRatioFrom.BILL.getCode().equals(from)) { + if(EnumMissTimeType.YEAR.getCode().equals(timeType)){ + if(EnumGetRatioFrom.BILL.getCode().equals(from)) { start = new BigDecimal(revenueArray[0]).divide(new BigDecimal(365), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); } - if (EnumGetRatioFrom.RENT.getCode().equals(from)) { + if(EnumGetRatioFrom.RENT.getCode().equals(from)) { revenue = revenue.multiply(new BigDecimal(12)); } - } else if (EnumMissTimeType.MONTH.getCode().equals(timeType)) { - if (EnumGetRatioFrom.BILL.getCode().equals(from)) { + }else if(EnumMissTimeType.MONTH.getCode().equals(timeType)){ + if(EnumGetRatioFrom.BILL.getCode().equals(from)) { start = new BigDecimal(revenueArray[0]).divide(new BigDecimal(30), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); } - } else if (EnumMissTimeType.PERIOD.getCode().equals(timeType)) { - if (EnumGetRatioFrom.RENT.getCode().equals(from)) { + }else if(EnumMissTimeType.PERIOD.getCode().equals(timeType)){ + if(EnumGetRatioFrom.RENT.getCode().equals(from)) { revenue = revenue.multiply(new BigDecimal(period)); } } - if (revenue.compareTo(start) >= 0 && revenue.compareTo(end) <= 0) { + if (revenue.compareTo(start) >= 0 && revenue.compareTo(end)<= 0){ ratioVo.setRatio(ratio); - ratioVo.setPrice(countPrice(ratioVo.getRatio(), revenueLong, timeType, period, from)); - ratioVo.setUseRatio(ratioVo.getUseRatio() + e + ","); + ratioVo.setPrice(countPrice(ratioVo.getRatio(),revenueLong,timeType,period,from)); + ratioVo.setUseRatio(ratioVo.getUseRatio()+e+","); break; } - } else if (e.indexOf(">") >= 0) { + }else if(e.indexOf(">") >= 0){ String[] revenueArray = array[0].split(">"); BigDecimal end = new BigDecimal(revenueArray[1]); //残年 (小金额 / 365 * 账单周期天数 )--(大金额 / 365 * 账单周期天数) - if (EnumMissTimeType.YEAR.getCode().equals(timeType)) { - if (EnumGetRatioFrom.BILL.getCode().equals(from)) { + if(EnumMissTimeType.YEAR.getCode().equals(timeType)){ + if(EnumGetRatioFrom.BILL.getCode().equals(from)) { end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); } - if (EnumGetRatioFrom.RENT.getCode().equals(from)) { + if(EnumGetRatioFrom.RENT.getCode().equals(from)) { revenue = revenue.multiply(new BigDecimal(12)); } - } else if (EnumMissTimeType.MONTH.getCode().equals(timeType)) { - if (EnumGetRatioFrom.BILL.getCode().equals(from)) { + }else if(EnumMissTimeType.MONTH.getCode().equals(timeType)){ + if(EnumGetRatioFrom.BILL.getCode().equals(from)) { end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); } - } else if (EnumMissTimeType.PERIOD.getCode().equals(timeType)) { - if (EnumGetRatioFrom.RENT.getCode().equals(from)) { + }else if(EnumMissTimeType.PERIOD.getCode().equals(timeType)){ + if(EnumGetRatioFrom.RENT.getCode().equals(from)) { revenue = revenue.multiply(new BigDecimal(period)); } } - if (revenue.compareTo(end) >= 0) { + if (revenue.compareTo(end) >= 0){ ratioVo.setRatio(ratio); - ratioVo.setUseRatio(ratioVo.getUseRatio() + e + ","); + ratioVo.setUseRatio(ratioVo.getUseRatio()+e+","); //计算超出部分 BigDecimal payRatio = new BigDecimal(ratio).divide(new BigDecimal(10000)); BigDecimal balance = revenue.subtract(end).multiply(new BigDecimal(1000000)); BigDecimal price = balance.multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); - array = ratioList.get(i - 1).split(":"); + array = ratioList.get(i-1).split(":"); Integer frontatio = Integer.parseInt(array[1]); revenueArray = array[0].split("-"); BigDecimal frontEnd = new BigDecimal(0); - if (EnumGetRatioFrom.BILL.getCode().equals(from)) { - if (EnumMissTimeType.YEAR.getCode().equals(timeType)) { + if(EnumGetRatioFrom.BILL.getCode().equals(from)){ + if(EnumMissTimeType.YEAR.getCode().equals(timeType)){ frontEnd = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); - } else if (EnumMissTimeType.MONTH.getCode().equals(timeType)) { + }else if(EnumMissTimeType.MONTH.getCode().equals(timeType)){ frontEnd = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); } - } else { + }else{ frontEnd = new BigDecimal(revenueArray[1]); } @@ -378,13 +373,13 @@ public class WxRentContractServiceImpl implements WxRentContractService { } } } - ratioVo.setUseRatio(ratioVo.getUseRatio().substring(0, ratioVo.getUseRatio().lastIndexOf(",")) + "]"); + ratioVo.setUseRatio(ratioVo.getUseRatio().substring(0,ratioVo.getUseRatio().lastIndexOf(","))+"]"); return ratioVo; } @Transactional(rollbackFor = {Exception.class}) @Override - public ResultData save(WxRentContract record, Long userId, String userName, Date oldRentStartDate) { + public ResultData save(WxRentContract record,Long userId,String userName,Date oldRentStartDate) { //保存租赁合同信息 final IdWorker idWorker = IdWorker.get(); record.setId(idWorker.nextId()); @@ -405,14 +400,14 @@ public class WxRentContractServiceImpl implements WxRentContractService { } if (record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { - if (record.getRevenue() == null || record.getRevenue().longValue() <= 0) { + if(record.getRevenue() == null || record.getRevenue().longValue() <= 0){ record.setPrice(0l); - } else { - if (record.getPayRatio() != null && record.getPayRatio().intValue() > 0) { - record.setPrice(countPrice(record.getPayRatio(), record.getRevenue(), EnumMissTimeType.OTHER.getCode(), record.getAdjustPeriod(), EnumGetRatioFrom.RENT.getCode())); - } else { + }else{ + if(record.getPayRatio()!=null && record.getPayRatio().intValue() > 0){ + record.setPrice(countPrice(record.getPayRatio(),record.getRevenue(),EnumMissTimeType.OTHER.getCode(),record.getAdjustPeriod(),EnumGetRatioFrom.RENT.getCode())); + }else{ int dayCount = record.getReceivePeriod() * 30; - RatioVo ratioVo = getPayRatio(EnumGetRatioFrom.RENT.getCode(), record.getRevenue(), record.getBusDiscountRatio(), record.getBusDiscountTime(), dayCount, record.getReceivePeriod()); + RatioVo ratioVo = getPayRatio(EnumGetRatioFrom.RENT.getCode(),record.getRevenue(),record.getBusDiscountRatio(),record.getBusDiscountTime(),dayCount,record.getReceivePeriod()); //record.setPayRatio(ratioVo.getRatio()); record.setPrice(ratioVo.getPrice()); } @@ -499,11 +494,11 @@ public class WxRentContractServiceImpl implements WxRentContractService { } //有模板,启动审批流,没有,直接生产账单 - if (!CollectionUtils.isEmpty(record.getFlowParams())) { + if (!CollectionUtils.isEmpty(record.getFlowParams())){ if (wxFlowService.getModelByType((Integer) record.getFlowParams().get("businessType"), record.getTenantId()) == null && record.getMerchantId() != null) { updateRentContractStatus(record.getId()); - } else { + }else{ record.getFlowParams().put("businessId", record.getId().toString()); if (record.getMerchantId() != null) { record.getFlowParams().put("supplement", true); //设置补录 @@ -524,7 +519,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { && !record.getReceivePeriod().equals(0) && !record.getLease().equals(0) && !record.getPrice().equals(0l)) { wxBillRentMapper.deletePreviewBill(record); //重新生成 - List resultList = buildRent(new WxMerchant(), null, record, EnumIsPreview.YES.getCode(), true); + List resultList = buildRent(new WxMerchant(), null, record, EnumIsPreview.YES.getCode(),true); record.setPreviewBillRentList(resultList); } return new ResultData(Result.SUCCESS, "保存租赁合同信息成功", record); @@ -532,7 +527,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { @Transactional(rollbackFor = {Exception.class}) @Override - public ResultData update(WxRentContract record, Long userId, String userName, int from, Date oldRentStartDate) { + public ResultData update(WxRentContract record, Long userId,String userName,int from,Date oldRentStartDate) { //查询预账单用于展示 WxBillRent wxBillRent = new WxBillRent(); wxBillRent.setRentContractId(record.getId()); @@ -541,17 +536,17 @@ public class WxRentContractServiceImpl implements WxRentContractService { List resultList = wxBillRentMapper.findList(wxBillRent); //更新 - ResultData resultData = getResultDataForUpdate(record, userId, from, oldRentStartDate); + ResultData resultData = getResultDataForUpdate(record, userId,from,oldRentStartDate); if (resultData.code != Result.SUCCESS) { return resultData; } - if (CollectionUtils.isEmpty(record.getPreviewBillRentList())) { + if(CollectionUtils.isEmpty(record.getPreviewBillRentList())) { if (record.getReceivePeriod() != null && record.getLease() != null && !record.getReceivePeriod().equals(0) && !record.getLease().equals(0)) { //删除预账单,重新生成 wxBillRentMapper.deletePreviewBill(record); - resultList = buildRent(new WxMerchant(), null, record, EnumIsPreview.YES.getCode(), true); + resultList = buildRent(new WxMerchant(), null, record, EnumIsPreview.YES.getCode(),true); } } @@ -560,7 +555,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { if (wxFlowService.getModelByType((Integer) record.getFlowParams().get("businessType"), record.getTenantId()) == null && record.getMerchantId() != null) { updateRentContractStatus(record.getId()); - } else { + }else{ record.getFlowParams().put("businessId", record.getId().toString()); if (record.getMerchantId() != null) { record.getFlowParams().put("supplement", true); //设置补录 @@ -579,7 +574,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { //保存调整金额(预账单调整) savePreviewBill(record); - WxRentContract wxRentContract = (WxRentContract) resultData.data; + WxRentContract wxRentContract = (WxRentContract)resultData.data; wxRentContract.setPreviewBillRentList(resultList); return new ResultData(wxRentContract); } @@ -587,14 +582,14 @@ public class WxRentContractServiceImpl implements WxRentContractService { /** * 重新生成账单(预账单调整) */ - public void savePreviewBill(WxRentContract record) { - if (CollectionUtils.isEmpty(record.getPreviewBillRentList())) { + public void savePreviewBill(WxRentContract record){ + if(CollectionUtils.isEmpty(record.getPreviewBillRentList())){ return; } wxBillRentMapper.deletePreviewBill(record); final IdWorker idWorker = IdWorker.get(); int count = 1; - for (WxBillRent bill : record.getPreviewBillRentList()) { + for (WxBillRent bill:record.getPreviewBillRentList()) { bill.setId(idWorker.nextId()); Date date = new Date(); bill.setRentContractId(record.getId()); @@ -612,7 +607,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { bill.setPay(0L); bill.setIsDel(EnumDelStatus.NOT_DEL.getCode()); bill.setShopId(record.getShopId()); - setExpiredDay(bill, Calendar.MONTH, record.getReceivePeriod()); + setExpiredDay(bill,Calendar.MONTH,record.getReceivePeriod()); if (bill.getReceivePay().equals(0L)) { bill.setStatus(EnumBillRentStatus.PAID.getCode()); bill.setPayDate(date); @@ -622,7 +617,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { wxBillRentMapper.insertBills(record.getPreviewBillRentList()); } - public ResultData getResultDataForUpdate(WxRentContract record, Long userId, int from, Date oldRentStartDate) { + public ResultData getResultDataForUpdate(WxRentContract record, Long userId,int from,Date oldRentStartDate) { //更新租赁合同信息 WxRentContract wxRentContract = wxRentContractMapper.selectByPrimaryKey(record.getId()); if (wxRentContract == null) { @@ -639,13 +634,13 @@ public class WxRentContractServiceImpl implements WxRentContractService { instance.add(dayType, record.getLease()); instance.add(Calendar.DAY_OF_MONTH, -1); - if (!EnumFromType.SWITCH.getCode().equals(from)) { + if(!EnumFromType.SWITCH.getCode().equals(from)){ if (record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { - if (record.getPayRatio() != null && record.getPayRatio().intValue() > 0) { - record.setPrice(countPrice(record.getPayRatio(), record.getRevenue(), EnumMissTimeType.OTHER.getCode(), record.getAdjustPeriod(), from)); - } else { + if(record.getPayRatio()!=null && record.getPayRatio().intValue() > 0){ + record.setPrice(countPrice(record.getPayRatio(),record.getRevenue(),EnumMissTimeType.OTHER.getCode(),record.getAdjustPeriod(),from)); + }else{ int dayCount = record.getReceivePeriod() * 30; - RatioVo ratioVo = getPayRatio(EnumGetRatioFrom.RENT.getCode(), record.getRevenue(), record.getBusDiscountRatio(), record.getBusDiscountTime(), dayCount, record.getReceivePeriod()); + RatioVo ratioVo = getPayRatio(EnumGetRatioFrom.RENT.getCode(),record.getRevenue(),record.getBusDiscountRatio(),record.getBusDiscountTime(),dayCount,record.getReceivePeriod()); //record.setPayRatio(ratioVo.getRatio()); record.setPrice(ratioVo.getPrice()); } @@ -737,7 +732,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { @Transactional(rollbackFor = {Exception.class}) @Override - public void buildDeposit(WxMerchant wxMerchant, Long userId, Long rentContractId) { + public void buildDeposit(WxMerchant wxMerchant, Long userId,Long rentContractId) { WxRentContract wxRentContract = wxRentContractMapper.selectByPrimaryKey(rentContractId); if (wxRentContract != null && wxRentContract.getDeposit() > 0) { final IdWorker idWorker = IdWorker.get(); @@ -892,38 +887,38 @@ public class WxRentContractServiceImpl implements WxRentContractService { logger.info("合同id:{},开始停止...", id); //结束审批流 by luozukai - WxFlowModel flowModel = wxFlowService.getModelByType(EnumFlowKey.NEW_RENT_CONTRACT.getCode().intValue(), record.getTenantId()); - WxFlowModel flowModelPoint = wxFlowService.getModelByType(EnumFlowKey.NEW_SHOP_CONTRACT.getCode().intValue(), record.getTenantId()); + WxFlowModel flowModel = wxFlowService.getModelByType(EnumFlowKey.NEW_RENT_CONTRACT.getCode().intValue(),record.getTenantId()); + WxFlowModel flowModelPoint = wxFlowService.getModelByType(EnumFlowKey.NEW_SHOP_CONTRACT.getCode().intValue(),record.getTenantId()); - WxFlowModel flowModel_pro = wxFlowService.getModelByType(EnumFlowKey.NEW_PRO_CONTRACT.getCode().intValue(), record.getTenantId()); - WxFlowModel flowModelPoint_pro = wxFlowService.getModelByType(EnumFlowKey.NEW_PRO_POINT_CONTRACT.getCode().intValue(), record.getTenantId()); + WxFlowModel flowModel_pro = wxFlowService.getModelByType(EnumFlowKey.NEW_PRO_CONTRACT.getCode().intValue(),record.getTenantId()); + WxFlowModel flowModelPoint_pro = wxFlowService.getModelByType(EnumFlowKey.NEW_PRO_POINT_CONTRACT.getCode().intValue(),record.getTenantId()); - WxFlowModel flowModel_rent = wxFlowService.getModelByType(EnumFlowKey.NNEW_RENT_CONTRACT.getCode().intValue(), record.getTenantId()); - WxFlowModel flowModelPoint_rent = wxFlowService.getModelByType(EnumFlowKey.NEW_RENT_POINT_CONTRACT.getCode().intValue(), record.getTenantId()); + WxFlowModel flowModel_rent = wxFlowService.getModelByType(EnumFlowKey.NNEW_RENT_CONTRACT.getCode().intValue(),record.getTenantId()); + WxFlowModel flowModelPoint_rent = wxFlowService.getModelByType(EnumFlowKey.NEW_RENT_POINT_CONTRACT.getCode().intValue(),record.getTenantId()); List keyList = new ArrayList<>(); - if (flowModel != null) { + if(flowModel != null){ keyList.add(flowModel.getFlowId()); } - if (flowModelPoint != null) { + if(flowModelPoint != null){ keyList.add(flowModelPoint.getFlowId()); } - if (flowModel_pro != null) { + if(flowModel_pro != null){ keyList.add(flowModel_pro.getFlowId()); } - if (flowModelPoint_pro != null) { + if(flowModelPoint_pro != null){ keyList.add(flowModelPoint_pro.getFlowId()); } - if (flowModel_rent != null) { + if(flowModel_rent != null){ keyList.add(flowModel_rent.getFlowId()); } - if (flowModelPoint_rent != null) { + if(flowModelPoint_rent != null){ keyList.add(flowModelPoint_rent.getFlowId()); } keyList.add(EnumFlowKey.CONTRACT.getMessage()); List tasks = taskService.createTaskQuery() .processDefinitionKeyIn(keyList) - .processVariableValueEquals("businessId", id + "").list(); + .processVariableValueEquals("businessId", id+"").list(); if (!CollectionUtils.isEmpty(tasks)) { for (Task task : tasks) { logger.info("合同id:{},taskid:{}", id, task.getId()); @@ -948,18 +943,18 @@ public class WxRentContractServiceImpl implements WxRentContractService { @Override @Transactional(rollbackFor = {Exception.class}) - public List buildRent(WxMerchant wxMerchant, Long userId, WxRentContract rentContract, Integer isPreview, boolean saveDb) { + public List buildRent(WxMerchant wxMerchant, Long userId,WxRentContract rentContract,Integer isPreview,boolean saveDb) { List rentList = new ArrayList<>(); //根据商户ID找出合同 WxRentContract wxRentContract; - if (rentContract == null) { + if(rentContract == null){ wxRentContract = new WxRentContract(); wxRentContract.setMerchantId(wxMerchant.getId()); List list = wxRentContractMapper.findList(wxRentContract); if (list.size() > 0) { wxRentContract = list.get(0); } - } else { + }else{ wxRentContract = rentContract; } if (wxRentContract != null) { @@ -972,7 +967,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { //按月计租 // if (wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_MONTH.getCode()) // ||wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) { - rentList = buildRentMonth(userId, wxRentContract, receivePeriod, lease, rentalStartDate, price, isPreview, saveDb); + rentList = buildRentMonth(userId, wxRentContract, receivePeriod, lease, rentalStartDate, price, isPreview,saveDb); // } else { // //如果按日 // List yearList = new ArrayList<>(); @@ -982,7 +977,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { // } } for (int i = 0; i < rentList.size(); i++) { - rentList.get(i).setPeriod(i + 1); + rentList.get(i).setPeriod(i+1); } return rentList; } @@ -998,7 +993,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { for (int i = 0; i < arraySize; i++) { JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); String priceStr = rentInfoObject.getString("price"); - if (priceStr.equalsIgnoreCase("NaN")) { + if(priceStr.equalsIgnoreCase("NaN")) { priceStr = "0"; } priceArr[i] = new BigDecimal(priceStr).multiply(new BigDecimal(100)).longValue(); @@ -1021,9 +1016,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { } priceList.add(priceArrs); } - return priceList; - } - if (wxRentContract.getAdjustRatioWay().equals(EnumRentContractAdjustRatioWay.MONEY.getCode())) { + } else { for (int i = 0; i < adjustRatioSize; i++) { long[] priceArrs = new long[arraySize]; for (int j = 0; j < arraySize; j++) { @@ -1034,24 +1027,12 @@ public class WxRentContractServiceImpl implements WxRentContractService { } priceList.add(priceArrs); } - return priceList; - } - if (wxRentContract.getAdjustRatioWay().equals(EnumRentContractAdjustRatioWay.CUSTOM.getCode())) { - for (int i = 0; i < adjustRatioSize; i++) { - long[] priceArrs = new long[arraySize]; - for (int j = 0; j < arraySize; j++) { - rentInfoObject = rentInfoArray.getJSONObject(j); - adjustRatio = rentInfoObject.getJSONArray("adjustRatio"); - BigDecimal price = new BigDecimal(adjustRatio.getString(i)).multiply(new BigDecimal(100)); - priceArrs[j] = price.setScale(0, RoundingMode.HALF_EVEN).longValue(); - } - priceList.add(priceArrs); - } } + return priceList; } - public List buildRentMonth(Long userId, WxRentContract wxRentContract, int receivePeriod, Integer lease, Date rentalStartDate, Long price, Integer isPreview, boolean saveDb) { + public List buildRentMonth(Long userId, WxRentContract wxRentContract, int receivePeriod, Integer lease, Date rentalStartDate, Long price, Integer isPreview,boolean saveDb) { int size = 0; long[] priceArrs = null; List> shopInfos = new ArrayList<>(); @@ -1096,15 +1077,11 @@ public class WxRentContractServiceImpl implements WxRentContractService { priceD = priceD.add(divide); priceArrs[i] = priceD.setScale(0, RoundingMode.HALF_EVEN).longValue(); } - } else if (wxRentContract.getAdjustRatioWay().equals(EnumRentContractAdjustRatioWay.MONEY.getCode())) { + } else { for (int i = 1; i < size; i++) { priceD = priceD.add(new BigDecimal(integers.get(i))); priceArrs[i] = priceD.setScale(0, RoundingMode.HALF_EVEN).longValue(); } - } else { - for (int i = 1; i < size; i++) { - priceArrs[i] = new BigDecimal(integers.get(i)).setScale(0, RoundingMode.HALF_EVEN).longValue(); - } } } @@ -1127,15 +1104,15 @@ public class WxRentContractServiceImpl implements WxRentContractService { Calendar instance = Calendar.getInstance(); Date startDate; //自然月 - if (wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) { - if (i == 0) { //第一期 + if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ + if(i == 0){ //第一期 startDate = rentalStartDate; - } else { + }else{ instance.setTime(rentalStartDate); instance.add(Calendar.MONTH, month * i); startDate = DateUtils.getFirstDayForCurrMonth(instance.getTime()); } - } else { + }else{ instance.setTime(rentalStartDate); instance.add(Calendar.MONTH, month * i); startDate = instance.getTime(); @@ -1144,13 +1121,13 @@ public class WxRentContractServiceImpl implements WxRentContractService { } String shopInfoStr = getShopInfoStr(wxRentContract); - Map resultMap = buildRent(receivePeriod, priceArrs, yearList, Calendar.MONTH, wxRentContract, userId, billcount, isPreview, shopInfoStr, saveDb); - List billRentList = (List) resultMap.get("billList"); + Map resultMap = buildRent(receivePeriod, priceArrs, yearList, Calendar.MONTH, wxRentContract, userId, billcount, isPreview, shopInfoStr,saveDb); + List billRentList = (List)resultMap.get("billList"); resultList.addAll(billRentList); return resultList; } - public String getShopInfoStr(WxRentContract wxRentContract) { + public String getShopInfoStr(WxRentContract wxRentContract){ String shopInfoStr = null; if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { String rentInfo = wxRentContract.getRentInfo(); @@ -1167,70 +1144,68 @@ public class WxRentContractServiceImpl implements WxRentContractService { } - public Map buildRent(int receivePeriod, long[] priceArrs, List yearList, - int dayType, WxRentContract wxRentContract, Long userId, int billcount, Integer isPreview, String shopInfoStr, - boolean saveDb) { + public Map buildRent(int receivePeriod, long[] priceArrs, List yearList, int dayType, WxRentContract wxRentContract, Long userId, int billcount, Integer isPreview, String shopInfoStr,boolean saveDb) { SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); - Map resultMap = new HashedMap(); + Map resultMap = new HashedMap(); List resultList = new ArrayList<>(); final IdWorker idWorker = IdWorker.get(); Date endDate = null;//每年的截止日期 - if (yearList.size() > 1) { + if(yearList.size() > 1){ endDate = yearList.get(1); } List billTimeVoList = new ArrayList<>(); - if (saveDb) { - billTimeVoList = initBillTimeList(wxRentContract.getRentalStartDate(), wxRentContract.getRentalEndDate(), wxRentContract.getAdjustPeriod(), dayType, receivePeriod); - } else { + if(saveDb){ + billTimeVoList = initBillTimeList(wxRentContract.getRentalStartDate(),wxRentContract.getRentalEndDate(),wxRentContract.getAdjustPeriod(),dayType,receivePeriod); + }else{ //预账单编辑账期,生成金额 - for (WxBillRent rent : wxRentContract.getPreviewBillRentList()) { + for (WxBillRent rent:wxRentContract.getPreviewBillRentList()) { BillTimeVo billTimeVo = new BillTimeVo(); billTimeVo.setStartDate(rent.getStarttime()); billTimeVo.setEndDate(rent.getEndtime()); - billTimeVo.setReceiveDate(DateUtils.getDaySet(rent.getStarttime(), Calendar.DATE, -1)); + billTimeVo.setReceiveDate(DateUtils.getDaySet(rent.getStarttime(),Calendar.DATE,-1)); billTimeVoList.add(billTimeVo); } } int index = 0; for (int i = 0; i < billTimeVoList.size(); i++) { - BillTimeVo billTimeVo = billTimeVoList.get(i); + BillTimeVo billTimeVo = billTimeVoList.get(i); //计算金额 long needpay = 0; boolean flag = false; - 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))) { + 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)) { + if(!saveDb && billTimeVo.getEndDate().after(endDate)) { long needpayFront = 0; long needpayAfter = 0; //同一天,算一天 - if (sd.format(billTimeVo.getStartDate()).equals(sd.format(billTimeVo.getEndDate()))) { - needpayFront = getNeedPayMoney(wxRentContract, priceArrs[index - 1], billTimeVo.getStartDate(), endDate, i, billTimeVoList.size(), saveDb); - } else { - if (billTimeVo.getStartDate().before(endDate)) { - needpayFront = getNeedPayMoney(wxRentContract, priceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb); - needpayAfter = getNeedPayMoney(wxRentContract, priceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb); - } else { - needpayFront = getNeedPayMoney(wxRentContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb); + if(sd.format(billTimeVo.getStartDate()).equals(sd.format(billTimeVo.getEndDate()))){ + needpayFront = getNeedPayMoney(wxRentContract,priceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod); + }else{ + if(billTimeVo.getStartDate().before(endDate)){ + needpayFront = getNeedPayMoney(wxRentContract, priceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate,Calendar.DATE,-1), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); + needpayAfter = getNeedPayMoney(wxRentContract, priceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); + }else{ + needpayFront = getNeedPayMoney(wxRentContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); } } - needpay = needpayFront + needpayAfter; + needpay = needpayFront+needpayAfter; flag = true; } - if (index >= yearList.size() - 1) { + if(index >= yearList.size()-1){ endDate = null; - } else { - endDate = yearList.get(index + 1);//price index 0开始,year.end 从第二年开始 + }else{ + endDate = yearList.get(index+1);//price index 0开始,year.end 从第二年开始 //logger.info("==========cross:"+sd.format(endDate)); } } @@ -1239,8 +1214,8 @@ public class WxRentContractServiceImpl implements WxRentContractService { } //计算金额 - if (!flag) { - needpay = getNeedPayMoney(wxRentContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb); + if(!flag){ + needpay = getNeedPayMoney(wxRentContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod); } WxBillRent wxBillRent = new WxBillRent(); @@ -1258,7 +1233,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { //截止收租日在当前时间之前 Date date = new Date(); - setExpiredDay(wxBillRent, dayType, receivePeriod); + setExpiredDay(wxBillRent,dayType,receivePeriod); wxBillRent.setRevenue(0L); wxBillRent.setTenantId(wxRentContract.getTenantId()); wxBillRent.setIsDel(0); @@ -1276,83 +1251,84 @@ public class WxRentContractServiceImpl implements WxRentContractService { } //批量插入账单 - if (saveDb) { + if(saveDb) { wxBillRentMapper.insertBills(resultList); } - resultMap.put("billcount", billcount); - resultMap.put("billList", resultList); + resultMap.put("billcount",billcount); + resultMap.put("billList",resultList); return resultMap; } - public long getNeedPayMoney(WxRentContract wxRentContract, long price, Date startDate, Date endDate, int i, - int billTimeVoListSize, boolean saveDb) { + public long getNeedPayMoney(WxRentContract wxRentContract,long price,Date startDate,Date endDate,int i,int billTimeVoListSize,boolean saveDb,int dayType,int receivePeriod){ long needpay; //按日 - if (wxRentContract.getPriceUnit().equals(EnumPriceUnit.D.getCode())) { + if (wxRentContract.getPriceUnit().equals(EnumPriceUnit.D.getCode())){ Double priceD = new Double(price); - double needpayD = WxRentContractServiceImpl.getNeedPay(0, priceD, startDate, endDate); + double needpayD = WxRentContractServiceImpl.getNeedPay(0,priceD,startDate,endDate); needpay = new Double(needpayD).longValue(); - } else { + }else{ Double priceD = new Double(price); if (EnumRentContractType.RENT_BY_JOINT.getCode().equals(wxRentContract.getType())) { //设置跳点率为年周期 price不变 - if (EnumMissTimeType.PERIOD.getCode().equals(wxRentContract.getBusDiscountTime())) { + if(EnumMissTimeType.PERIOD.getCode().equals(wxRentContract.getBusDiscountTime())){ return priceD.longValue(); } //年或者设置跳点率为年周期 除12 - if (EnumMissTimeType.YEAR.getCode().equals(wxRentContract.getBusDiscountTime())) { - priceD = new Double(price) / 12; + if(EnumMissTimeType.YEAR.getCode().equals(wxRentContract.getBusDiscountTime())){ + priceD = new Double(price)/12; } - } else { + }else{ //年 除12 - if (EnumPriceUnit.Y.getCode().equals(wxRentContract.getPriceUnit())) { - priceD = new Double(price) / 12; + if(EnumPriceUnit.Y.getCode().equals(wxRentContract.getPriceUnit())){ + priceD = new Double(price)/12; } } //生成金额直接计算 - if (!saveDb) { - needpay = new Double(getMonthNeedPay(priceD, startDate, endDate)).longValue(); + if(!saveDb){ + needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod)).longValue(); return needpay; } SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM"); - SimpleDateFormat sdD = new SimpleDateFormat("d"); + SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); - if (i == billTimeVoListSize - 1) {//最后 + if(i == billTimeVoListSize - 1){//最后 //判断是否满足整月 - int startInt = Integer.parseInt(sdD.format(startDate)); - int endInt = Integer.parseInt(sdD.format(DateUtils.getDaySet(endDate, Calendar.DATE, 1))); - if (startInt == endInt) { - int months = getMonths(sdM.format(startDate) + "-01", sdM.format(DateUtils.getDaySet(endDate, Calendar.DATE, 1)) + "-01"); + Calendar instance = Calendar.getInstance(); + instance.setTime(startDate); + instance.add(dayType, receivePeriod); + instance.add(Calendar.DATE, -1); + if(sd.format(instance.getTime()).equals(sd.format(endDate))){ + int months = getMonths(sdM.format(startDate)+"-01",sdM.format(DateUtils.getDaySet(endDate,Calendar.DATE,1))+"-01"); needpay = new Double(months * priceD).longValue(); - } else { - needpay = new Double(getMonthNeedPay(priceD, startDate, endDate)).longValue(); + }else{ + needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod)).longValue(); } - } else if (i == 0) {//第一期 - if (wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) { - if (isFirstDay(startDate)) { - int months = getMonths(sdM.format(startDate) + "-01", sdM.format(endDate) + "-01"); + }else if(i == 0){//第一期 + if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ + if(isFirstDay(startDate)){ + int months = getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); months++; needpay = new Double(months * priceD).longValue(); - } else { - needpay = new Double(getMonthNeedPay(priceD, startDate, endDate)).longValue(); + }else{ + needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod)).longValue(); } - } else { - if (isFirstDay(startDate)) { - int months = getMonths(sdM.format(startDate) + "-01", sdM.format(endDate) + "-01"); - if (isFirstDay(startDate)) { + }else{ + if(isFirstDay(startDate)){ + int months = getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); + if(isFirstDay(startDate)){ months++; } needpay = new Double(months * priceD).longValue(); - } else { - needpay = new Double(getMonthNeedPay(priceD, startDate, endDate)).longValue(); + }else{ + needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod)).longValue(); } } - } else {//中间 - int months = getMonths(sdM.format(startDate) + "-01", sdM.format(endDate) + "-01"); - if (isFirstDay(startDate)) { + }else{//中间 + int months = getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01"); + if(isFirstDay(startDate)){ months++; } needpay = new Double(months * priceD).longValue(); @@ -1361,7 +1337,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { return needpay; } - public void setExpiredDay(WxBillRent wxBillRent, int dayType, int receivePeriod) { + public void setExpiredDay(WxBillRent wxBillRent,int dayType, int receivePeriod){ //截止收租日在当前时间之前 Date date = new Date(); wxBillRent.setExpiredDay(0L); @@ -1384,15 +1360,15 @@ public class WxRentContractServiceImpl implements WxRentContractService { } } - public boolean isFirstDay(Date date) { + public boolean isFirstDay(Date date){ int dateInt = Integer.parseInt(new SimpleDateFormat("d").format(date)); - if (dateInt == 1) { + if(dateInt == 1){ return true; } return false; } - public static int getMonths(String startStr, String endStr) { + 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); @@ -1514,8 +1490,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { } @Override - public PageInfo getRentContractList(WxRentContract rentContract, Integer pageIndex, Integer - pageSize) { + public PageInfo getRentContractList(WxRentContract rentContract, Integer pageIndex, Integer pageSize) { PageInfo pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxRentContractMapper.getRentContractList(rentContract)); return pageInfo; } @@ -1607,12 +1582,12 @@ public class WxRentContractServiceImpl implements WxRentContractService { @Override @Transactional(rollbackFor = {Exception.class}) - public ResultData updateFile(WxRentContract record, Long userId, String userName, Date oldRentStartDate) { + public ResultData updateFile(WxRentContract record, Long userId,String userName,Date oldRentStartDate) { // 保存调整金额(预账单调整) - if (!CollectionUtils.isEmpty(record.getPreviewBillRentList())) { + if(!CollectionUtils.isEmpty(record.getPreviewBillRentList())){ savePreviewBill(record); } - ResultData resultData = getResultDataForUpdate(record, userId, 0, oldRentStartDate); + ResultData resultData = getResultDataForUpdate(record, userId,0,oldRentStartDate); if (resultData.code != Result.SUCCESS) { return resultData; } @@ -1622,7 +1597,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { if (wxFlowService.getModelByType((Integer) record.getFlowParams().get("businessType"), record.getTenantId()) == null && record.getMerchantId() != null) { updateRentContractStatus(record.getId()); - } else { + }else{ record.getFlowParams().put("businessId", record.getId().toString()); if (record.getMerchantId() != null) { record.getFlowParams().put("supplement", true); //设置补录 @@ -1663,7 +1638,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { if (record != null && record.getMerchantId() != null && record.getReceivePeriod() != null && - record.getPrice() > 0) { + record.getPrice() > 0 ) { //预览账单改为正式,并写入商户id WxBillRent billRent = new WxBillRent(); billRent.setRentContractId(id); @@ -1673,7 +1648,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { WxMerchant wxMerchant = new WxMerchant(); wxMerchant.setId(record.getMerchantId()); wxMerchant.setTenantId(record.getTenantId()); - if (record.getDeposit() > 0) { + if(record.getDeposit() > 0) { //押金 buildDeposit(wxMerchant, null, id); } @@ -1801,7 +1776,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { result.put("lease", lease); result.put("receivePeriod", receivePeriod); String payAccountStr = " "; - if (wxRentContract.getPayAccount() != null && !wxRentContract.getPayAccount().equals("")) { + if(wxRentContract.getPayAccount() != null && !wxRentContract.getPayAccount().equals("")) { payAccountStr = wxRentContract.getPayAccount(); } result.put("payAccount", payAccountStr); @@ -1970,8 +1945,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { return result; } - public void ratioWay(WxRentContract wxRentContract, Map result, Integer lease, - int extralease, int extracount, int paycount, int index, int count, BigDecimal rentPrice) { + public void ratioWay(WxRentContract wxRentContract, Map result, Integer lease, int extralease, int extracount, int paycount, int index, int count, BigDecimal rentPrice) { String adjustRatio = wxRentContract.getAdjustRatio(); List integers = JSONArray.parseArray(adjustRatio, Integer.class); integers.add(0, 0); @@ -2050,8 +2024,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { } } - public void areaWay(WxRentContract wxRentContract, Map result, Integer lease, int extralease, - int extracount, int paycount, int index, int count, BigDecimal rentPrice) { + public void areaWay(WxRentContract wxRentContract, Map result, Integer lease, int extralease, int extracount, int paycount, int index, int count, BigDecimal rentPrice) { long[] priceArrs = new long[]{}; List adjustRatioList = new ArrayList<>(); @@ -2198,7 +2171,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { return wxRentContractMapper.getShopType(wxRentContract); } - public static double getMonthNeedPay(Double price, Date start, Date end) { + public static double getMonthNeedPay(Double price,Date start,Date end,int dayType,int receivePeriod){ SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM"); SimpleDateFormat sdD = new SimpleDateFormat("d"); @@ -2206,56 +2179,56 @@ public class WxRentContractServiceImpl implements WxRentContractService { int[] diff; //同一天 - if (sd.format(start).equals(sd.format(end))) { + if(sd.format(start).equals(sd.format(end))){ int dayCount = DateUtils.getMonthDayCount(start); - return 1 * (price / dayCount); + return 1 * (price/dayCount); } //同月 - if (sdM.format(start).equals(sdM.format(end))) { + if(sdM.format(start).equals(sdM.format(end))){ - diff = DateUtils.getDiff(start, end); + diff = DateUtils.getDiff(start,end); int dayCount = DateUtils.getMonthDayCount(start); - total += (diff[1] + 1) * (price / dayCount); + total += (diff[1]+1) * (price/dayCount); return total; } //判断是否满足整月 - int startInt = Integer.parseInt(sdD.format(start)); - int endInt = Integer.parseInt(sdD.format(DateUtils.getDaySet(end, Calendar.DATE, 1))); - - if (startInt == endInt) { - int months = getMonths(sdM.format(start) + "-01", sdM.format(DateUtils.getDaySet(end, Calendar.DATE, 1)) + "-01"); + Calendar instance = Calendar.getInstance(); + instance.setTime(start); + instance.add(dayType, receivePeriod); + instance.add(Calendar.DATE, -1); + 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"); return (months) * price; } //第一个月 Date lastMonthDay = DateUtils.getLastDayForMonth(start); - diff = DateUtils.getDiff(start, lastMonthDay); + diff = DateUtils.getDiff(start,lastMonthDay); int dayCount = DateUtils.getMonthDayCount(start); - total += (diff[1] + 1) * (price / dayCount); + 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"); + 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); + diff = DateUtils.getDiff(DateUtils.getFirstDayForCurrMonth(end),end); dayCount = DateUtils.getMonthDayCount(end); - total += (diff[1] + 1) * (price / dayCount); + total += (diff[1]+1) * (price/dayCount); return total; } /** * 按日计租 根据每月的日期总数计算needpay - * * @param monthPrice * @param start * @param end * @return */ - public static double getNeedPay(long monthPrice, Double dayPrice, Date start, Date end) { + public static double getNeedPay(long monthPrice,Double dayPrice,Date start,Date end){ SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM"); Double total; @@ -2263,64 +2236,63 @@ public class WxRentContractServiceImpl implements WxRentContractService { int dayCount = DateUtils.getMonthDayCount(start); double price; - if (monthPrice > 0) { - price = (double) monthPrice / dayCount; - } else { + if(monthPrice > 0){ + price = (double) monthPrice/dayCount; + }else{ price = dayPrice; } //同一天 - if (sd.format(start).equals(sd.format(end))) { + if(sd.format(start).equals(sd.format(end))){ return 1 * price; //算1天 } //同月 - if (sdM.format(start).equals(sdM.format(end))) { - diff = DateUtils.getDiff(start, end); - return (diff[1] + 1) * price; + if(sdM.format(start).equals(sdM.format(end))){ + diff = DateUtils.getDiff(start,end); + return (diff[1]+1) * price; } Date currEnd = DateUtils.getLastDayForMonth(start); - diff = DateUtils.getDiff(start, currEnd); - total = (diff[1] + 1) * price; + diff = DateUtils.getDiff(start,currEnd); + total = (diff[1]+1) * price; int warnCount = 0; - while (true) { - Date monthStartDate = DateUtils.getDaySet(currEnd, Calendar.DATE, 1); + while (true){ + Date monthStartDate = DateUtils.getDaySet(currEnd,Calendar.DATE,1); dayCount = DateUtils.getMonthDayCount(monthStartDate); - if (monthPrice > 0) { - price = (double) monthPrice / dayCount; - } else { + if(monthPrice > 0){ + price = (double) monthPrice/dayCount; + }else{ price = dayPrice; } //最后一个月 - if (sdM.format(monthStartDate).equals(sdM.format(end))) { - diff = DateUtils.getDiff(monthStartDate, end); - total += price * (diff[1] + 1); + if(sdM.format(monthStartDate).equals(sdM.format(end))){ + diff = DateUtils.getDiff(monthStartDate,end); + total += price * (diff[1]+1); break; - } else { + }else{ currEnd = DateUtils.getLastDayForMonth(monthStartDate); - diff = DateUtils.getDiff(monthStartDate, currEnd); - total += price * (diff[1] + 1); + diff = DateUtils.getDiff(monthStartDate,currEnd); + total += price * (diff[1]+1); } //预警 - if (warnCount >= 1000) { + if(warnCount >= 1000){ Logger logger = LoggerFactory.getLogger(WxRentContractServiceImpl.class); - logger.error("getNeedPay() warnCount max error !!! monthPrice:{},dayPrice:{},start:{},end:{}", monthPrice, dayPrice, sd.format(start), sd.format(end)); + logger.error("getNeedPay() warnCount max error !!! monthPrice:{},dayPrice:{},start:{},end:{}",monthPrice,dayPrice,sd.format(start),sd.format(end)); break; } - warnCount++; + warnCount ++; } return total; } - public static List initBillTimeList(Date start, Date end, Integer adjustPeriod, Integer dayType, - int receivePeriod) { + public static List initBillTimeList(Date start,Date end,Integer adjustPeriod,Integer dayType,int receivePeriod){ List list = new ArrayList<>(); int count = 0; - while (true) { + while (true){ BillTimeVo timeVo = new BillTimeVo(); //开始时间 @@ -2329,7 +2301,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { //账单日 Calendar instance = Calendar.getInstance(); instance.setTime(start); - if (!adjustPeriod.equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) { + if(!adjustPeriod.equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ instance.add(Calendar.DATE, -1); } timeVo.setReceiveDate(instance.getTime()); @@ -2342,11 +2314,11 @@ public class WxRentContractServiceImpl implements WxRentContractService { timeVo.setEndDate(instance.getTime()); //自然月 - if (adjustPeriod.equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) { - if (count == 0) { - if (receivePeriod == 1) { //周期1个月 头一个月到当月底 + if(adjustPeriod.equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ + if(count == 0){ + if(receivePeriod == 1) { //周期1个月 头一个月到当月底 timeVo.setEndDate(DateUtils.getLastDayForMonth(timeVo.getStartDate())); - } else { + }else{ Date firstDay = DateUtils.getFirstDayForCurrMonth(start); instance.clear(); instance.setTime(firstDay); @@ -2358,22 +2330,22 @@ public class WxRentContractServiceImpl implements WxRentContractService { } } - if (timeVo.getEndDate().after(end)) { + if(timeVo.getEndDate().after(end)){ timeVo.setEndDate(end); } list.add(timeVo); //next - start = DateUtils.getDaySet(timeVo.getEndDate(), Calendar.DATE, 1); + start = DateUtils.getDaySet(timeVo.getEndDate(),Calendar.DATE,1); - if (start.after(end)) { + if(start.after(end)) { break; } - count++; + count ++; //预警 - if (count >= 1000) { + if(count >= 1000){ Logger logger = LoggerFactory.getLogger(WxRentContractServiceImpl.class); logger.error("initBillTimeList() warnCount max error !!!"); break; @@ -2388,7 +2360,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { wxRentContractMapper.updateStatus(wxRentContract); //终止租赁合同,同时终止物业合同 - if (EnumEndProperty.END_RENT_AND_PROPERTY.getCode().equals(wxRentContract.getEndProperty())) { + if(EnumEndProperty.END_RENT_AND_PROPERTY.getCode().equals(wxRentContract.getEndProperty())){ WxPropertyContract wxPropertyContract = new WxPropertyContract(); wxPropertyContract.setRentContractId(wxRentContract.getId()); wxPropertyContract.setStatus(EnumRentContractStatus.CONTRACT_TERMINATE.getCode()); @@ -2404,7 +2376,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { //解绑商户和商铺关系 WxRentContract rentContract = wxRentContractMapper.selectByPrimaryKey(wxRentContract.getId()); - if (rentContract != null && rentContract.getMerchantId() != null) { + if(rentContract != null && rentContract.getMerchantId() != null){ wxMerchantService.disable(rentContract.getMerchantId()); } } diff --git a/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml b/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml index 7a940d70c..0ff3842b0 100644 --- a/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml @@ -643,6 +643,8 @@