From 96663fa18252980057b0d00492b002cbcf89999a Mon Sep 17 00:00:00 2001 From: winter Date: Tue, 9 Jul 2024 00:06:23 +0800 Subject: [PATCH] fix --- .../contract/WxRentContractController.java | 2 +- .../service/WxRentContractService.java | 4 +- .../service/impl/WxBillDailyServiceImpl.java | 11 + .../impl/WxBillOtherDepositServiceImpl.java | 16 + .../service/impl/WxBillOtherServiceImpl.java | 14 + .../WxBillPropertyDepositServiceImpl.java | 12 + .../impl/WxBillPropertyServiceImpl.java | 12 + .../impl/WxBillRentManageServiceImpl.java | 12 + .../service/impl/WxBillRentServiceImpl.java | 14 + .../impl/WxPropertyContractServiceImpl.java | 10 +- .../impl/WxRentContractServiceImpl.java | 6933 +++++++++-------- 11 files changed, 3575 insertions(+), 3465 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/contract/WxRentContractController.java b/mallinkAdmin/src/main/java/com/iformall/controller/contract/WxRentContractController.java index 4f6d5f274..520d68148 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/contract/WxRentContractController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/contract/WxRentContractController.java @@ -250,7 +250,7 @@ public class WxRentContractController extends WxContractBaseController { } //wxRentContract.setRentShopType(null); //wxRentContract.setOperationType(null); - return wxRentContractService.updateFile(wxRentContract, user.getId(),user.getName(),oldDate,true); + return wxRentContractService.updateFile(wxRentContract, user,user.getName(),oldDate,true); } @GetMapping("/findById") diff --git a/mallinkService/src/main/java/com/iformall/service/WxRentContractService.java b/mallinkService/src/main/java/com/iformall/service/WxRentContractService.java index 0d4d89389..3a9c23d60 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxRentContractService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxRentContractService.java @@ -71,7 +71,7 @@ public interface WxRentContractService { //void exportContract(HttpServletRequest request, HttpServletResponse response, Long rentId,Long propertyId); - ResultData updateFile(WxRentContract wxRentContract, Long userId,String userName,Date oldRentStartDate,boolean writeComplate); + ResultData updateFile(WxRentContract wxRentContract, MallUserInfo user,String userName,Date oldRentStartDate,boolean writeComplate); ResultData updateRentContractStatus(Long id,boolean buildPropertyBill); @@ -81,7 +81,7 @@ public interface WxRentContractService { List buildRent(MallUserInfo user,WxRentContract rentContract,Integer isPreview,boolean saveDb); - void buildDeposit(Long userId,Long rentContractId); + void buildDeposit(MallUserInfo user,Long rentContractId); Object getMerchants(WxRentContract wxRentContract); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillDailyServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillDailyServiceImpl.java index f9836a01e..33d9a2a38 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillDailyServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillDailyServiceImpl.java @@ -268,7 +268,11 @@ public class WxBillDailyServiceImpl extends WxBillBaseService implements WxBillD //record.setStatus(record.getReceiveDate().after(date)?EnumBillStatus.WAIT_PAY.getCode():EnumBillStatus.NOT_PAID.getCode()); record.setStatus(EnumBillStatus.WAIT_PAY.getCode()); record.setCreatetime(date); + record.setCreateBy(user.getId()); + record.setCreateByName(user.getName()); record.setUpdatetime(date); + record.setUpdateBy(user.getId()); + record.setUpdateByName(user.getName()); record.setExpiredDay(0L); record.updateTenantInfo(user); //record.setOwe(new BigDecimal(record.getRealReceivePay()).subtract(new BigDecimal(record.getPay())).toPlainString()); @@ -302,6 +306,7 @@ public class WxBillDailyServiceImpl extends WxBillBaseService implements WxBillD return new ResultData(ErrorCode.BILL_IS_FOUND.getCode(),"商户已存在其他包含该时间端的费用账单"); } wxBillDaily.setUpdatetime(date); + wxBillDaily.setUpdateBy(user.getId()); wxBillDaily.setRemark(record.getRemark()); wxBillDailyMapper.updateById(wxBillDaily); return new ResultData(Result.SUCCESS, "更新日常账单成功"); @@ -467,6 +472,8 @@ public class WxBillDailyServiceImpl extends WxBillBaseService implements WxBillD wxBillDaily.setId(dto.getId()); wxBillDaily.updateTenantInfo(dto); wxBillDaily.setUpdatetime(new Date()); + wxBillDaily.setUpdateBy(user.getId()); + wxBillDaily.setUpdateByName(user.getName()); if (forcePaid) { wxBillDaily.setReceivePay(dbBill.getPay()); wxBillDaily.setStatus(EnumBillStatus.PAID.getCode()); @@ -611,6 +618,8 @@ public class WxBillDailyServiceImpl extends WxBillBaseService implements WxBillD wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); wxBillRent.setStatus(EnumBillStatus.BAD.getCode()); wxBillDailyMapper.updateById(wxBillRent); String badMoney = dbBill.getOwe(); @@ -671,6 +680,8 @@ public class WxBillDailyServiceImpl extends WxBillBaseService implements WxBillD bu.updateTenantInfo(b); bu.setStatus(EnumBillStatus.INVALID.getCode()); bu.setUpdatetime(new Date()); + bu.setUpdateBy(user.getId()); + bu.setUpdateByName(user.getName()); wxBillDailyMapper.updateById(bu); WxBillAction wxBillAction = new WxBillAction(); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillOtherDepositServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillOtherDepositServiceImpl.java index 999572cc1..028854ec5 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillOtherDepositServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillOtherDepositServiceImpl.java @@ -272,7 +272,11 @@ public class WxBillOtherDepositServiceImpl extends WxBillBaseService implements record.setId(idWorker.nextId()); record.setStatus(EnumBillStatus.WAIT_PAY.getCode()); record.setCreatetime(date); + record.setCreateBy(user.getId()); + record.setCreateByName(user.getName()); record.setUpdatetime(date); + record.setUpdateBy(user.getId()); + record.setUpdateByName(user.getName()); record.setExpiredDay(0L); //record.setOwe(new BigDecimal(record.getRealReceivePay()).subtract(new BigDecimal(record.getPay())).toPlainString()); //record.setOwe(new BigDecimal(record.getReceivePay()).subtract(new BigDecimal(record.getPay())).toPlainString()); @@ -306,6 +310,7 @@ public class WxBillOtherDepositServiceImpl extends WxBillBaseService implements return new ResultData(ErrorCode.BILL_IS_FOUND.getCode(),"商户已存在包含该时间端的费用账单"); } record.setUpdatetime(date); + record.setUpdateBy(user.getId()); wxBillOtherDepositMapper.updateById(record); return new ResultData(Result.SUCCESS, "更新其他账单成功"); } @@ -433,6 +438,8 @@ public class WxBillOtherDepositServiceImpl extends WxBillBaseService implements wxBillOtherDeposit.setId(dto.getId()); wxBillOtherDeposit.updateTenantInfo(dto); wxBillOtherDeposit.setUpdatetime(new Date()); + wxBillOtherDeposit.setUpdateBy(user.getId()); + wxBillOtherDeposit.setUpdateByName(user.getName()); if (forcePaid) { wxBillOtherDeposit.setReceivePay(dbBill.getPay()); wxBillOtherDeposit.setStatus(EnumBillStatus.PAID.getCode()); @@ -470,6 +477,8 @@ public class WxBillOtherDepositServiceImpl extends WxBillBaseService implements wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); wxBillRent.setLastOweCallTime(new Date()); wxBillRent.setLastOweCallUser(user.getName()+"(账号:"+user.getUsername()+")"); wxBillOtherDepositMapper.updateById(wxBillRent); @@ -490,6 +499,7 @@ public class WxBillOtherDepositServiceImpl extends WxBillBaseService implements wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + BigDecimal opay = new BigDecimal(0); if (StringUtils.isNotBlank(dbBill.getPay())) { opay = new BigDecimal(dbBill.getPay()); @@ -556,6 +566,8 @@ public class WxBillOtherDepositServiceImpl extends WxBillBaseService implements wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); wxBillRent.setReturnPrice(oldpay.add(new BigDecimal(dto.getAddpay())).toPlainString()); wxBillOtherDepositMapper.updateById(wxBillRent); this.addBillAction(EnumBillAction.RETURN, dto.getBillTypeValue(),dto.getId(), @@ -569,6 +581,8 @@ public class WxBillOtherDepositServiceImpl extends WxBillBaseService implements wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); wxBillRent.setStatus(EnumBillStatus.BAD.getCode()); wxBillOtherDepositMapper.updateById(wxBillRent); String badMoney = dbBill.getOwe(); @@ -629,6 +643,8 @@ public class WxBillOtherDepositServiceImpl extends WxBillBaseService implements bu.updateTenantInfo(b); bu.setStatus(EnumBillStatus.INVALID.getCode()); bu.setUpdatetime(new Date()); + bu.setUpdateBy(user.getId()); + bu.setUpdateByName(user.getName()); wxBillOtherDepositMapper.updateById(bu); WxBillAction wxBillAction = new WxBillAction(); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillOtherServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillOtherServiceImpl.java index 67547d43e..1393e6ab2 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillOtherServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillOtherServiceImpl.java @@ -271,7 +271,11 @@ public class WxBillOtherServiceImpl extends WxBillBaseService implements WxBillO //record.setStatus(record.getReceiveDate().after(date)?EnumBillStatus.WAIT_PAY.getCode():EnumBillStatus.NOT_PAID.getCode()); record.setStatus(EnumBillStatus.WAIT_PAY.getCode()); record.setCreatetime(date); + record.setCreateBy(user.getId()); + record.setCreateByName(user.getName()); record.setUpdatetime(date); + record.setUpdateBy(user.getId()); + record.setUpdateByName(user.getName()); record.setExpiredDay(0L); record.updateTenantInfo(user); //record.setOwe(new BigDecimal(record.getRealReceivePay()).subtract(new BigDecimal(record.getPay())).toPlainString()); @@ -306,6 +310,8 @@ public class WxBillOtherServiceImpl extends WxBillBaseService implements WxBillO return new ResultData(ErrorCode.BILL_IS_FOUND.getCode(),"商户已存在其他包含该时间端的费用账单"); } record.setUpdatetime(date); + record.setUpdateBy(user.getId()); + record.setUpdateByName(user.getName()); wxBillOtherMapper.updateById(record); return new ResultData(Result.SUCCESS, "更新其他押金账单成功"); } @@ -375,6 +381,8 @@ public class WxBillOtherServiceImpl extends WxBillBaseService implements WxBillO wxBillOther.setId(dto.getId()); wxBillOther.updateTenantInfo(dto); wxBillOther.setUpdatetime(new Date()); + wxBillOther.setUpdateBy(user.getId()); + wxBillOther.setUpdateByName(user.getName()); if (forcePaid) { wxBillOther.setReceivePay(dbBill.getPay()); wxBillOther.setStatus(EnumBillStatus.PAID.getCode()); @@ -414,6 +422,8 @@ public class WxBillOtherServiceImpl extends WxBillBaseService implements WxBillO wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); wxBillRent.setLastOweCallTime(new Date()); wxBillRent.setLastOweCallUser(user.getName()+"(账号:"+user.getUsername()+")"); wxBillOtherMapper.updateById(wxBillRent); @@ -495,6 +505,8 @@ public class WxBillOtherServiceImpl extends WxBillBaseService implements WxBillO wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); wxBillRent.setStatus(EnumBillStatus.BAD.getCode()); wxBillOtherMapper.updateById(wxBillRent); String badMoney = dbBill.getOwe(); @@ -555,6 +567,8 @@ public class WxBillOtherServiceImpl extends WxBillBaseService implements WxBillO bu.updateTenantInfo(b); bu.setStatus(EnumBillStatus.INVALID.getCode()); bu.setUpdatetime(new Date()); + bu.setUpdateBy(user.getId()); + bu.setUpdateByName(user.getName()); wxBillOtherMapper.updateById(bu); WxBillAction wxBillAction = new WxBillAction(); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillPropertyDepositServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillPropertyDepositServiceImpl.java index 393b43192..e99982362 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillPropertyDepositServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillPropertyDepositServiceImpl.java @@ -271,7 +271,11 @@ public class WxBillPropertyDepositServiceImpl extends WxBillBaseService implemen final IdWorker idWorker = IdWorker.get(); record.setId(idWorker.nextId()); record.setCreatetime(date); + record.setUpdateBy(user.getId()); + record.setUpdateByName(user.getName()); record.setUpdatetime(date); + record.setCreateBy(user.getId()); + record.setCreateByName(user.getName()); record.updateTenantInfo(user); //record.setOwe(new BigDecimal(receivepay).subtract(new BigDecimal(pay)).toPlainString()); record.setIsDel(EnumDelStatus.NOT_DEL.getCode()); @@ -407,6 +411,8 @@ public class WxBillPropertyDepositServiceImpl extends WxBillBaseService implemen wxBillPropertyDeposit.setId(dto.getId()); wxBillPropertyDeposit.updateTenantInfo(dto); wxBillPropertyDeposit.setUpdatetime(new Date()); + wxBillPropertyDeposit.setUpdateBy(user.getId()); + wxBillPropertyDeposit.setUpdateByName(user.getName()); String billPropertyDepositOldPrce = dto.getOldPrice(); String billPropertyDepositNewPrce = dto.getNewPrice(); if (forcePaid) { @@ -534,6 +540,8 @@ public class WxBillPropertyDepositServiceImpl extends WxBillBaseService implemen wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); wxBillRent.setReturnPrice(oldpay.add(new BigDecimal(dto.getAddpay())).toPlainString()); wxBillPropertyDepositMapper.updateById(wxBillRent); this.addBillAction(EnumBillAction.RETURN, dto.getBillTypeValue(),dto.getId(), @@ -547,6 +555,8 @@ public class WxBillPropertyDepositServiceImpl extends WxBillBaseService implemen wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); wxBillRent.setStatus(EnumBillStatus.BAD.getCode()); wxBillPropertyDepositMapper.updateById(wxBillRent); String badMoney = dbBill.getOwe(); @@ -606,6 +616,8 @@ public class WxBillPropertyDepositServiceImpl extends WxBillBaseService implemen bu.updateTenantInfo(b); bu.setStatus(EnumBillStatus.INVALID.getCode()); bu.setUpdatetime(new Date()); + bu.setUpdateBy(user.getId()); + bu.setUpdateByName(user.getName()); wxBillPropertyDepositMapper.updateById(bu); WxBillAction wxBillAction = new WxBillAction(); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillPropertyServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillPropertyServiceImpl.java index fc1352be4..1ad3bcaae 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillPropertyServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillPropertyServiceImpl.java @@ -315,6 +315,10 @@ public class WxBillPropertyServiceImpl extends WxBillBaseService implements WxBi record.setId(idWorker.nextId()); record.setCreatetime(date); record.setUpdatetime(date); + record.setUpdateBy(user.getId()); + record.setUpdateByName(user.getName()); + record.setCreateBy(user.getId()); + record.setCreateByName(user.getName()); record.updateTenantInfo(user); //record.setOwe(new BigDecimal(record.getRealReceivePay()).subtract(new BigDecimal(record.getPay())).toPlainString()); //record.setOwe(new BigDecimal(record.getReceivePay()).subtract(new BigDecimal(record.getPay())).toPlainString()); @@ -493,6 +497,8 @@ public class WxBillPropertyServiceImpl extends WxBillBaseService implements WxBi wxBillProperty.setId(dto.getId()); wxBillProperty.updateTenantInfo(dto); wxBillProperty.setUpdatetime(new Date()); + wxBillProperty.setUpdateBy(user.getId()); + wxBillProperty.setUpdateByName(user.getName()); if (forcePaid) { wxBillProperty.setReceivePay(dbBill.getPay()); wxBillProperty.setStatus(EnumBillStatus.PAID.getCode()); @@ -536,6 +542,8 @@ public class WxBillPropertyServiceImpl extends WxBillBaseService implements WxBi wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); wxBillRent.setLastOweCallTime(new Date()); wxBillRent.setLastOweCallUser(user.getName()+"(账号:"+user.getUsername()+")"); wxBillPropertyMapper.updateById(wxBillRent); @@ -636,6 +644,8 @@ public class WxBillPropertyServiceImpl extends WxBillBaseService implements WxBi wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); wxBillRent.setStatus(EnumBillStatus.BAD.getCode()); wxBillPropertyMapper.updateById(wxBillRent); String badMoney = dbBill.getOwe(); @@ -702,6 +712,8 @@ public class WxBillPropertyServiceImpl extends WxBillBaseService implements WxBi bu.updateTenantInfo(b); bu.setStatus(EnumBillStatus.INVALID.getCode()); bu.setUpdatetime(new Date()); + bu.setUpdateBy(user.getId()); + bu.setUpdateByName(user.getName()); wxBillPropertyMapper.updateById(bu); WxBillAction wxBillAction = new WxBillAction(); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentManageServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentManageServiceImpl.java index 6ae20eb0b..a0831d353 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentManageServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentManageServiceImpl.java @@ -191,6 +191,10 @@ public class WxBillRentManageServiceImpl extends WxBillBaseService implements W record.setId(idWorker.nextId()); record.setCreatetime(date); record.setUpdatetime(date); + record.setUpdateBy(user.getId()); + record.setUpdateByName(user.getName()); + record.setCreateBy(user.getId()); + record.setCreateByName(user.getName()); record.updateTenantInfo(user); //record.setOwe(new BigDecimal(receivepay).subtract(new BigDecimal(pay)).toPlainString()); record.setIsDel(EnumDelStatus.NOT_DEL.getCode()); @@ -422,6 +426,8 @@ public class WxBillRentManageServiceImpl extends WxBillBaseService implements W wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); if (forcePaid) { wxBillRent.setReceivePay(dbBill.getPay()); wxBillRent.setStatus(EnumBillStatus.PAID.getCode()); @@ -465,6 +471,8 @@ public class WxBillRentManageServiceImpl extends WxBillBaseService implements W wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); wxBillRent.setLastOweCallTime(new Date()); wxBillRent.setLastOweCallUser(user.getName()+"(账号:"+user.getUsername()+")"); wxBillRentManageMapper.updateById(wxBillRent); @@ -566,6 +574,8 @@ public class WxBillRentManageServiceImpl extends WxBillBaseService implements W wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); wxBillRent.setStatus(EnumBillStatus.BAD.getCode()); wxBillRentManageMapper.updateById(wxBillRent); String badMoney = dbBill.getOwe(); @@ -633,6 +643,8 @@ public class WxBillRentManageServiceImpl extends WxBillBaseService implements W bu.updateTenantInfo(b); bu.setStatus(EnumBillStatus.INVALID.getCode()); bu.setUpdatetime(new Date()); + bu.setUpdateBy(user.getId()); + bu.setUpdateByName(user.getName()); wxBillRentManageMapper.updateById(bu); WxBillAction wxBillAction = new WxBillAction(); 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 3e0e3a83f..f0d20891a 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java @@ -185,6 +185,10 @@ public class WxBillRentServiceImpl extends WxBillBaseService implements WxBillRe record.setId(idWorker.nextId()); record.setCreatetime(date); record.setUpdatetime(date); + record.setUpdateBy(user.getId()); + record.setUpdateByName(user.getName()); + record.setCreateBy(user.getId()); + record.setCreateByName(user.getName()); record.updateTenantInfo(user); //record.setOwe(new BigDecimal(receivepay).subtract(new BigDecimal(pay)).toPlainString()); record.setIsDel(EnumDelStatus.NOT_DEL.getCode()); @@ -350,6 +354,8 @@ public class WxBillRentServiceImpl extends WxBillBaseService implements WxBillRe String oldPrice = wxBillRent.getReceivePay(); String newPrice = newReceivePay; wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); String latePayPrice = StringUtils.isBlank(wxBillRent.getLatePayPrice()) ? "0" : wxBillRent.getLatePayPrice(); //wxBillRent.setOwe(new BigDecimal(newPrice).add(new BigDecimal(wxBillRent.getServiceChargePay())).add(new BigDecimal(latePayPrice)).subtract(new BigDecimal(wxBillRent.getPay())).toPlainString()); //wxBillRent.setOwe(new BigDecimal(newPrice).subtract(new BigDecimal(wxBillRent.getPay())).toPlainString()); @@ -592,6 +598,8 @@ public class WxBillRentServiceImpl extends WxBillBaseService implements WxBillRe wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); if (forcePaid) { wxBillRent.setReceivePay(dbBill.getPay()); wxBillRent.setStatus(EnumBillStatus.PAID.getCode()); @@ -635,6 +643,8 @@ public class WxBillRentServiceImpl extends WxBillBaseService implements WxBillRe wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); wxBillRent.setLastOweCallTime(new Date()); wxBillRent.setLastOweCallUser(user.getName()+"(账号:"+user.getUsername()+")"); wxBillRentMapper.updateById(wxBillRent); @@ -735,6 +745,8 @@ public class WxBillRentServiceImpl extends WxBillBaseService implements WxBillRe wxBillRent.setId(dto.getId()); wxBillRent.updateTenantInfo(dto); wxBillRent.setUpdatetime(new Date()); + wxBillRent.setUpdateBy(user.getId()); + wxBillRent.setUpdateByName(user.getName()); wxBillRent.setStatus(EnumBillStatus.BAD.getCode()); wxBillRentMapper.updateById(wxBillRent); String badMoney = dbBill.getOwe(); @@ -802,6 +814,8 @@ public class WxBillRentServiceImpl extends WxBillBaseService implements WxBillRe bu.updateTenantInfo(b); bu.setStatus(EnumBillStatus.INVALID.getCode()); bu.setUpdatetime(new Date()); + bu.setUpdateBy(user.getId()); + bu.setUpdateByName(user.getName()); wxBillRentMapper.updateById(bu); WxBillAction wxBillAction = new WxBillAction(); 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 b9dcb7866..82d1f84ca 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java @@ -267,7 +267,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService /** * 重新生成账单(预账单调整) */ - public void savePreviewBill(WxPropertyContract record){ + public void savePreviewBill(WxPropertyContract record,MallUserInfo user){ if(CollectionUtils.isEmpty(record.getPreviewBillRentList())){ return; } @@ -280,10 +280,14 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService Date date = new Date(); bill.setPropertyContractId(record.getId()); bill.setCreatetime(date); + bill.setCreateBy(user.getId()); + bill.setCreateByName(user.getName()); bill.updateTenantInfo(wxPayAccountBill); //bill.setOwe(bill.getReceivePay()); bill.setNeedPay(bill.getNeedPay()); bill.setUpdatetime(date); + bill.setUpdateBy(user.getId()); + bill.setUpdateByName(user.getName()); bill.setRentShopType(record.getRentShopType()); bill.setPeriod(count); bill.setIsPreview(EnumIsPreview.YES.getCode()); @@ -525,7 +529,11 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService wxBillDeposit.setMerchantId(record.getMerchantId()); //wxBillDeposit.setShopId(wxPropertyContract.getShopId()); wxBillDeposit.setCreatetime(date); + //wxBillDeposit.setCreateBy(user.getId()); + //wxBillDeposit.setCreateByName(user.getName()); wxBillDeposit.setUpdatetime(date); + //wxBillDeposit.setUpdateBy(user.getId()); + //wxBillDeposit.setUpdateByName(user.getName()); wxBillDeposit.setIsDel(EnumDelStatus.NOT_DEL.getCode()); wxBillDeposit.setRentShopType(wxPropertyContract.getRentShopType()); wxBillDeposit.setShopInfo(getShopInfoStr(wxPropertyContract)); 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 1da73826b..07c1daf4d 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -1,3464 +1,3475 @@ -package com.iformall.service.impl; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; -import com.iformall.common.ErrorCode; -import com.iformall.common.IdWorker; -import com.iformall.common.Result; -import com.iformall.common.ResultData; -import com.iformall.domain.po.*; -import com.iformall.domain.po.base.BaseEntity; -import com.iformall.domain.po.base.TenantEntity; -import com.iformall.domain.vo.BillTimeVo; -import com.iformall.domain.vo.RatioVo; -import com.iformall.enums.*; -import com.iformall.exception.MallinkException; -import com.iformall.mapper.*; -import com.iformall.service.*; -import com.iformall.service.helper.WxBillAllHelper; -import com.iformall.service.helper.WxRentContractHelper; -import com.iformall.utils.*; -import org.apache.commons.collections.map.HashedMap; -import org.apache.commons.compress.utils.Lists; -import org.apache.commons.lang3.StringUtils; -import org.apache.shiro.SecurityUtils; -import org.flowable.engine.RuntimeService; -import org.flowable.engine.TaskService; -import org.flowable.task.api.Task; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.CollectionUtils; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.IOException; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.text.SimpleDateFormat; -import java.util.*; - -/** - * @author gongbiao - */ -@Service -public class WxRentContractServiceImpl implements WxRentContractService { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - @Autowired - private String fmUploadDir; - - @Autowired - WxRentContractMapper wxRentContractMapper; - - @Autowired - WxShopMapper wxShopMapper; - - @Lazy - @Autowired - WxMerchantService wxMerchantService; - - @Autowired - WxBillRentMapper wxBillRentMapper; - - @Autowired - WxBillDepositMapper wxBillDepositMapper; - - @Autowired - WxPropertyContractMapper wxPropertyContractMapper; - - @Autowired - WxMerchantMapper wxMerchantMapper; - - @Autowired - WxBusinessMapper wxBusinessMapper; - - @Autowired - WxMallService wxMallService; - - @Autowired - WxBrandMapper WxBrandMapper; - - @Lazy - @Autowired - WxFlowRecordService wxFlowRecordService; - - @Lazy - @Autowired - RuntimeService runtimeService; - - @Lazy - @Autowired - private TaskService taskService; - - @Lazy - @Autowired - private WxFlowService wxFlowService; - - @Autowired - WxMerchantShopMapper wxMerchantShopMapper; - - @Autowired - WxFlowRecordMapper wxFlowRecordMapper; - - @Autowired - WxBillPropertyMapper wxBillPropertyMapper; - - @Lazy - @Autowired - WxPropertyContractService wxPropertyContractService; - - @Lazy - @Autowired - WxPayAccountBillService wxPayAccountBillService; - - @Lazy - @Autowired - WxShopService wxShopService; - - @Autowired - WxBillRentManageMapper wxBillRentManageMapper; - - @Autowired - WxMerchantTradeDailyMapper wxMerchantTradeDailyMapper; - - @Autowired - WxRentContractDepositTypeMapper wxRentContractDepositTypeMapper; - - @Lazy - @Autowired - WxBillAllHelper wxBillAllHelper; - -// @Override -// public Map listAsPage(WxRentContract record, Integer pageIndex, Integer pageSize) { -// //Object rentContractStatusInfo = getRentContractStatusInfo(record); -// PageHelper.startPage(pageIndex, pageSize); -// //List> rentContractData = wxRentContractMapper.queryRentContractData(record); -// //PageInfo> pageInfo = new PageInfo<>(rentContractData); -// //Map result = new HashMap<>(); -// //result.put("rentContractStatusInfo", rentContractStatusInfo); -// result.put("pageInfo", pageInfo); -// this. -// return result; -// } - - @Override - public List findList(WxRentContract record){ - return wxRentContractMapper.findList(record); - } - - @Override - public Map getById(Long id) { - Map result = new HashMap<>(); - WxRentContract wxRentContract = wxRentContractMapper.selectById(id); - if (wxRentContract == null) { - throw new MallinkException(ErrorCode.RENT_CONTRACT_IS_NOT_FOUND); - } - - //init dateDiff - 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]); - } - - //init rentPrice - //if(StringUtils.isNotBlank(wxRentContract.getRentPrice())){ - //wxRentContract.setRentPrice(Double.parseDouble(wxRentContract.getRentPrice())/100 + ""); - //} - - //init 租赁单价 - String rentInfo = wxRentContract.getRentInfo(); - 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); - BigDecimal rentPrice = rentInfoObject.getBigDecimal("rentPrice"); - //wxRentContract.setShopId(rentInfoObject.getLong("shopId")); - String price = wxRentContract.getPrice(); - 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(price).divide(new BigDecimal(rentArea),wxRentContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP); - rentInfoObject.put("rentPrice", rentPrice); - } - } - } - 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()) ) { - String price = wxRentContract.getPrice(); - Double rentArea = Double.parseDouble(wxRentContract.getRentArea()); - BigDecimal rentPrice = new BigDecimal(price).divide(new BigDecimal(rentArea),wxRentContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP); - if(rentPrice.compareTo(new BigDecimal(0)) > 0){ - wxRentContract.setRentPrice(rentPrice.toString()); - }else{ - wxRentContract.setRentPrice("0"); - } - } - - } - } - if(wxRentContract.getPriceUnit() == null){ - wxRentContract.setPriceUnit(EnumPriceUnit.M.getCode()); - } - if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode())){ - wxRentContract.setAdjustPeriod(EnumRentContractAdjustPeriod.ADJUST_PERIOD_MONTH.getCode()); - wxRentContract.setPriceUnit(EnumPriceUnit.D.getCode()); - } - - //商场信息 - WxMall wxMall = new WxMall(); - wxMall.setTenantInfo(wxRentContract); - List mallList = wxMallService.findList(wxMall); - if (!mallList.isEmpty()) { - result.put("mall", mallList.get(0)); - } - wxRentContract.setPrice(StringUtils.isNotBlank(wxRentContract.getPrice()) ? wxRentContract.getPrice() : "0"); - wxRentContract.setDeposit(StringUtils.isNotBlank(wxRentContract.getDeposit()) ? wxRentContract.getDeposit() : "0"); - - result.put("wxRentContract", wxRentContract); - //关联的商户 - if (wxRentContract.getMerchantId() != null) { - WxMerchant wxMerchant = wxMerchantService.getById(wxRentContract.getMerchantId()); - result.put("wxMerchant", wxMerchant); - } else { - result.put("wxMerchant", null); - } - //关联的店铺 - if (wxRentContract.shopIdsByRentInfo().size()> 0) { - WxShop record = new WxShop(); - //record.setId(wxRentContract.getShopId()); - record.setIds(wxRentContract.shopIdsByRentInfo()); - record.updateTenantInfo(wxRentContract); - PageInfo> shopPageInfo = wxShopService.findListMap(record,1,10000); - List> list = shopPageInfo.getList(); - result.put("wxShops", list); - } else { - result.put("wxShops", Collections.EMPTY_LIST); - } - //设置审批流程状态 - result.put("applyStatus", wxRentContract.getApplyStatus()); - - //租赁费用欠缴 - result.put("rentOweCount",wxRentContractMapper.queryOweCount(wxRentContract)); - //物业费用欠缴 -// WxPropertyContract propertyContract = new WxPropertyContract(); -// propertyContract.setRentContractId(id); -// result.put("propertyOweCount",wxPropertyContractMapper.queryOweCount(propertyContract)); -// result.put("protertyContract", wxPropertyContractMapper.findOneByRentId(wxRentContract)); -// //押金欠缴 -// result.put("depositOweCount",wxBillDepositMapper.queryOweCount(wxRentContract)); -// //押金状态 -// WxBillDeposit wxBillDeposit = new WxBillDeposit(); -// wxBillDeposit.setRentContractId(id); -// wxBillDeposit.updateTenantInfo(wxRentContract); -// List select = wxBillDepositMapper.findList(wxBillDeposit); -// if (!select.isEmpty()) { -// result.put("depositStatus", select.get(0).getStatus()); -// } - //发起人备注 - WxFlowRecord wxFlowRecord = new WxFlowRecord(); - wxFlowRecord.setBusinessId(String.valueOf(id)); - wxFlowRecord.setStatus(EnumFlowRecordStatus.NEW.getCode()); - List flowRecordList = wxFlowRecordService.findList(wxFlowRecord); - if(!CollectionUtils.isEmpty(flowRecordList)){ - result.put("remark",flowRecordList.get(0).getRemark()); - } - - //查询预账单用于展示 - WxBillRent wxBillRent = new WxBillRent(); - wxBillRent.setRentContractId(id); - wxBillRent.setSortColumns(BaseEntity.SortField.Period_ASC); - wxBillRent.updateTenantInfo(wxRentContract); - List resultList = wxBillRentMapper.findList(wxBillRent); - result.put("previewBillRentList",resultList); - - return result; - } - /** - * 计算金额 - * @param ratio - * @param revenueLong - * @return - */ - public static BigDecimal countPrice(Integer decimalSize,String ratio,String revenueLong,int timeType,int period,int from){ - if (StringUtils.isBlank(revenueLong)) { - revenueLong = "0"; - } - BigDecimal revenue = new BigDecimal(revenueLong); - BigDecimal payRatio = null; - if (StringUtils.isBlank(ratio)) { - payRatio = new BigDecimal(0); - }else { - payRatio = new BigDecimal(ratio); - } - BigDecimal price; - if(EnumMissTimeType.YEAR.getCode().equals(timeType) && EnumGetRatioFrom.RENT.getCode().equals(from)){ - price = revenue.multiply(new BigDecimal(12)).multiply(payRatio).setScale(decimalSize, RoundingMode.HALF_EVEN); - }else if(EnumMissTimeType.PERIOD.getCode().equals(timeType) && EnumGetRatioFrom.RENT.getCode().equals(from)){ - price = revenue.multiply(new BigDecimal(period)).multiply(payRatio).setScale(decimalSize, RoundingMode.HALF_EVEN);; - }else{ - price = revenue.multiply(payRatio).setScale(decimalSize, RoundingMode.HALF_EVEN); - } - return price; - } - - /** - * 获取设置的跳点率 - * ["1000-1200:10",">3000:20"] - */ - public static RatioVo getPayRatio(Integer decimalSize,int from,String revenueLong,String busDiscountRatio,int timeType,long dayCount,int period,Integer periodUnit){ - RatioVo ratioVo = new RatioVo(); - if(StringUtils.isBlank(busDiscountRatio)){ - return ratioVo; - } - List ratioList = JSONArray.parseArray(busDiscountRatio, String.class); - ratioVo.setUseRatio(busDiscountRatio); - - for (int i = 0; i < ratioList.size(); i++) { - //BigDecimal revenue = new BigDecimal(revenueLong).divide(new BigDecimal(1000000)).setScale(8, RoundingMode.HALF_EVEN); - BigDecimal revenue = new BigDecimal(revenueLong); - String e = ratioList.get(i); - String[] array = e.split(":"); - //Integer ratio = Integer.parseInt(array[1]); - String ratio = array[1]; - - 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)) { - 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)) { - revenue = revenue.multiply(new BigDecimal(12)); - } - }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)) { - revenue = revenue.multiply(new BigDecimal(period)); - } - } - - if (revenue.compareTo(start) >= 0 && revenue.compareTo(end)<= 0){ - ratioVo.setRatio(ratio); - ratioVo.setPrice(countPrice(decimalSize,ratioVo.getRatio(),revenueLong,timeType,period,from).toPlainString()); - break; - } - }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)) { - end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); - } - 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)) { - 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)) { - revenue = revenue.multiply(new BigDecimal(period)); - } - } - - if (revenue.compareTo(end) >= 0){ - ratioVo.setRatio(ratio); - - //计算超出部分 - BigDecimal payRatio = new BigDecimal(ratio).divide(new BigDecimal(10000)); - BigDecimal balance = revenue.subtract(end).multiply(new BigDecimal(1000000)); - BigDecimal price = balance.multiply(payRatio).setScale(decimalSize, RoundingMode.HALF_EVEN); - - array = ratioList.get(i-1).split(":"); - Integer frontatio = Integer.parseInt(array[1]); - revenueArray = array[0].split("-"); - - BigDecimal frontEnd; - 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)){ - frontEnd = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); - }else{ - frontEnd = new BigDecimal(revenueArray[1]); - } - }else{ - frontEnd = new BigDecimal(revenueArray[1]); - } - - BigDecimal frontRatio = new BigDecimal(frontatio).divide(new BigDecimal(10000)); - BigDecimal frontPrice = frontEnd.multiply(new BigDecimal(1000000).multiply(frontRatio).setScale(decimalSize, RoundingMode.HALF_EVEN)); - - ratioVo.setPrice(price.add(frontPrice).toPlainString()); - break; - } - } - } - return ratioVo; - } - - @Transactional(rollbackFor = {Exception.class}) - @Override - public ResultData save(WxRentContract record,MallUserInfo user,String userName,Date oldRentStartDate) { - //保存租赁合同信息 - final IdWorker idWorker = IdWorker.get(); - record.setId(idWorker.nextId()); - int dayType = record.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode()) ? Calendar.DAY_OF_MONTH : Calendar.MONTH; - //计租开始时间 - Calendar instance = Calendar.getInstance(); - instance.setTime(record.getRentalStartDate()); - instance.add(dayType, record.getLease()); - instance.add(Calendar.DAY_OF_MONTH, -1); - //计租结束时间 - if (!record.getStartDate().equals(record.getRentalStartDate())) { - instance.clear(); - instance.setTime(record.getRentalStartDate()); - instance.add(Calendar.DAY_OF_MONTH, -1); - record.setEndDate(instance.getTime()); - } else { - record.setEndDate(record.getStartDate()); - } - - if (null != record.getType() && record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { - if(StringUtils.isBlank(record.getRevenue())){ - record.setPrice("0"); - }else{ - if(StringUtils.isNotBlank(record.getPayRatio())){ - record.setPrice(countPrice(Constant.default_long_decimal_size,record.getPayRatio(),record.getRevenue(),EnumMissTimeType.OTHER.getCode(),record.getAdjustPeriod(),EnumGetRatioFrom.RENT.getCode()).toPlainString()); - }else{ - int dayCount = record.getReceivePeriod() * 30; - RatioVo ratioVo = getPayRatio(Constant.default_long_decimal_size,EnumGetRatioFrom.RENT.getCode(),record.getRevenue(),record.getBusDiscountRatio(), +package com.iformall.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.iformall.common.ErrorCode; +import com.iformall.common.IdWorker; +import com.iformall.common.Result; +import com.iformall.common.ResultData; +import com.iformall.domain.po.*; +import com.iformall.domain.po.base.BaseEntity; +import com.iformall.domain.po.base.TenantEntity; +import com.iformall.domain.vo.BillTimeVo; +import com.iformall.domain.vo.RatioVo; +import com.iformall.enums.*; +import com.iformall.exception.MallinkException; +import com.iformall.mapper.*; +import com.iformall.service.*; +import com.iformall.service.helper.WxBillAllHelper; +import com.iformall.service.helper.WxRentContractHelper; +import com.iformall.utils.*; +import org.apache.commons.collections.map.HashedMap; +import org.apache.commons.compress.utils.Lists; +import org.apache.commons.lang3.StringUtils; +import org.apache.shiro.SecurityUtils; +import org.flowable.engine.RuntimeService; +import org.flowable.engine.TaskService; +import org.flowable.task.api.Task; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.SimpleDateFormat; +import java.util.*; + +/** + * @author gongbiao + */ +@Service +public class WxRentContractServiceImpl implements WxRentContractService { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private String fmUploadDir; + + @Autowired + WxRentContractMapper wxRentContractMapper; + + @Autowired + WxShopMapper wxShopMapper; + + @Lazy + @Autowired + WxMerchantService wxMerchantService; + + @Autowired + WxBillRentMapper wxBillRentMapper; + + @Autowired + WxBillDepositMapper wxBillDepositMapper; + + @Autowired + WxPropertyContractMapper wxPropertyContractMapper; + + @Autowired + WxMerchantMapper wxMerchantMapper; + + @Autowired + WxBusinessMapper wxBusinessMapper; + + @Autowired + WxMallService wxMallService; + + @Autowired + WxBrandMapper WxBrandMapper; + + @Lazy + @Autowired + WxFlowRecordService wxFlowRecordService; + + @Lazy + @Autowired + RuntimeService runtimeService; + + @Lazy + @Autowired + private TaskService taskService; + + @Lazy + @Autowired + private WxFlowService wxFlowService; + + @Autowired + WxMerchantShopMapper wxMerchantShopMapper; + + @Autowired + WxFlowRecordMapper wxFlowRecordMapper; + + @Autowired + WxBillPropertyMapper wxBillPropertyMapper; + + @Lazy + @Autowired + WxPropertyContractService wxPropertyContractService; + + @Lazy + @Autowired + WxPayAccountBillService wxPayAccountBillService; + + @Lazy + @Autowired + WxShopService wxShopService; + + @Autowired + WxBillRentManageMapper wxBillRentManageMapper; + + @Autowired + WxMerchantTradeDailyMapper wxMerchantTradeDailyMapper; + + @Autowired + WxRentContractDepositTypeMapper wxRentContractDepositTypeMapper; + + @Lazy + @Autowired + WxBillAllHelper wxBillAllHelper; + +// @Override +// public Map listAsPage(WxRentContract record, Integer pageIndex, Integer pageSize) { +// //Object rentContractStatusInfo = getRentContractStatusInfo(record); +// PageHelper.startPage(pageIndex, pageSize); +// //List> rentContractData = wxRentContractMapper.queryRentContractData(record); +// //PageInfo> pageInfo = new PageInfo<>(rentContractData); +// //Map result = new HashMap<>(); +// //result.put("rentContractStatusInfo", rentContractStatusInfo); +// result.put("pageInfo", pageInfo); +// this. +// return result; +// } + + @Override + public List findList(WxRentContract record){ + return wxRentContractMapper.findList(record); + } + + @Override + public Map getById(Long id) { + Map result = new HashMap<>(); + WxRentContract wxRentContract = wxRentContractMapper.selectById(id); + if (wxRentContract == null) { + throw new MallinkException(ErrorCode.RENT_CONTRACT_IS_NOT_FOUND); + } + + //init dateDiff + 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]); + } + + //init rentPrice + //if(StringUtils.isNotBlank(wxRentContract.getRentPrice())){ + //wxRentContract.setRentPrice(Double.parseDouble(wxRentContract.getRentPrice())/100 + ""); + //} + + //init 租赁单价 + String rentInfo = wxRentContract.getRentInfo(); + 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); + BigDecimal rentPrice = rentInfoObject.getBigDecimal("rentPrice"); + //wxRentContract.setShopId(rentInfoObject.getLong("shopId")); + String price = wxRentContract.getPrice(); + 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(price).divide(new BigDecimal(rentArea),wxRentContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP); + rentInfoObject.put("rentPrice", rentPrice); + } + } + } + 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()) ) { + String price = wxRentContract.getPrice(); + Double rentArea = Double.parseDouble(wxRentContract.getRentArea()); + BigDecimal rentPrice = new BigDecimal(price).divide(new BigDecimal(rentArea),wxRentContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP); + if(rentPrice.compareTo(new BigDecimal(0)) > 0){ + wxRentContract.setRentPrice(rentPrice.toString()); + }else{ + wxRentContract.setRentPrice("0"); + } + } + + } + } + if(wxRentContract.getPriceUnit() == null){ + wxRentContract.setPriceUnit(EnumPriceUnit.M.getCode()); + } + if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode())){ + wxRentContract.setAdjustPeriod(EnumRentContractAdjustPeriod.ADJUST_PERIOD_MONTH.getCode()); + wxRentContract.setPriceUnit(EnumPriceUnit.D.getCode()); + } + + //商场信息 + WxMall wxMall = new WxMall(); + wxMall.setTenantInfo(wxRentContract); + List mallList = wxMallService.findList(wxMall); + if (!mallList.isEmpty()) { + result.put("mall", mallList.get(0)); + } + wxRentContract.setPrice(StringUtils.isNotBlank(wxRentContract.getPrice()) ? wxRentContract.getPrice() : "0"); + wxRentContract.setDeposit(StringUtils.isNotBlank(wxRentContract.getDeposit()) ? wxRentContract.getDeposit() : "0"); + + result.put("wxRentContract", wxRentContract); + //关联的商户 + if (wxRentContract.getMerchantId() != null) { + WxMerchant wxMerchant = wxMerchantService.getById(wxRentContract.getMerchantId()); + result.put("wxMerchant", wxMerchant); + } else { + result.put("wxMerchant", null); + } + //关联的店铺 + if (wxRentContract.shopIdsByRentInfo().size()> 0) { + WxShop record = new WxShop(); + //record.setId(wxRentContract.getShopId()); + record.setIds(wxRentContract.shopIdsByRentInfo()); + record.updateTenantInfo(wxRentContract); + PageInfo> shopPageInfo = wxShopService.findListMap(record,1,10000); + List> list = shopPageInfo.getList(); + result.put("wxShops", list); + } else { + result.put("wxShops", Collections.EMPTY_LIST); + } + //设置审批流程状态 + result.put("applyStatus", wxRentContract.getApplyStatus()); + + //租赁费用欠缴 + result.put("rentOweCount",wxRentContractMapper.queryOweCount(wxRentContract)); + //物业费用欠缴 +// WxPropertyContract propertyContract = new WxPropertyContract(); +// propertyContract.setRentContractId(id); +// result.put("propertyOweCount",wxPropertyContractMapper.queryOweCount(propertyContract)); +// result.put("protertyContract", wxPropertyContractMapper.findOneByRentId(wxRentContract)); +// //押金欠缴 +// result.put("depositOweCount",wxBillDepositMapper.queryOweCount(wxRentContract)); +// //押金状态 +// WxBillDeposit wxBillDeposit = new WxBillDeposit(); +// wxBillDeposit.setRentContractId(id); +// wxBillDeposit.updateTenantInfo(wxRentContract); +// List select = wxBillDepositMapper.findList(wxBillDeposit); +// if (!select.isEmpty()) { +// result.put("depositStatus", select.get(0).getStatus()); +// } + //发起人备注 + WxFlowRecord wxFlowRecord = new WxFlowRecord(); + wxFlowRecord.setBusinessId(String.valueOf(id)); + wxFlowRecord.setStatus(EnumFlowRecordStatus.NEW.getCode()); + List flowRecordList = wxFlowRecordService.findList(wxFlowRecord); + if(!CollectionUtils.isEmpty(flowRecordList)){ + result.put("remark",flowRecordList.get(0).getRemark()); + } + + //查询预账单用于展示 + WxBillRent wxBillRent = new WxBillRent(); + wxBillRent.setRentContractId(id); + wxBillRent.setSortColumns(BaseEntity.SortField.Period_ASC); + wxBillRent.updateTenantInfo(wxRentContract); + List resultList = wxBillRentMapper.findList(wxBillRent); + result.put("previewBillRentList",resultList); + + return result; + } + /** + * 计算金额 + * @param ratio + * @param revenueLong + * @return + */ + public static BigDecimal countPrice(Integer decimalSize,String ratio,String revenueLong,int timeType,int period,int from){ + if (StringUtils.isBlank(revenueLong)) { + revenueLong = "0"; + } + BigDecimal revenue = new BigDecimal(revenueLong); + BigDecimal payRatio = null; + if (StringUtils.isBlank(ratio)) { + payRatio = new BigDecimal(0); + }else { + payRatio = new BigDecimal(ratio); + } + BigDecimal price; + if(EnumMissTimeType.YEAR.getCode().equals(timeType) && EnumGetRatioFrom.RENT.getCode().equals(from)){ + price = revenue.multiply(new BigDecimal(12)).multiply(payRatio).setScale(decimalSize, RoundingMode.HALF_EVEN); + }else if(EnumMissTimeType.PERIOD.getCode().equals(timeType) && EnumGetRatioFrom.RENT.getCode().equals(from)){ + price = revenue.multiply(new BigDecimal(period)).multiply(payRatio).setScale(decimalSize, RoundingMode.HALF_EVEN);; + }else{ + price = revenue.multiply(payRatio).setScale(decimalSize, RoundingMode.HALF_EVEN); + } + return price; + } + + /** + * 获取设置的跳点率 + * ["1000-1200:10",">3000:20"] + */ + public static RatioVo getPayRatio(Integer decimalSize,int from,String revenueLong,String busDiscountRatio,int timeType,long dayCount,int period,Integer periodUnit){ + RatioVo ratioVo = new RatioVo(); + if(StringUtils.isBlank(busDiscountRatio)){ + return ratioVo; + } + List ratioList = JSONArray.parseArray(busDiscountRatio, String.class); + ratioVo.setUseRatio(busDiscountRatio); + + for (int i = 0; i < ratioList.size(); i++) { + //BigDecimal revenue = new BigDecimal(revenueLong).divide(new BigDecimal(1000000)).setScale(8, RoundingMode.HALF_EVEN); + BigDecimal revenue = new BigDecimal(revenueLong); + String e = ratioList.get(i); + String[] array = e.split(":"); + //Integer ratio = Integer.parseInt(array[1]); + String ratio = array[1]; + + 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)) { + 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)) { + revenue = revenue.multiply(new BigDecimal(12)); + } + }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)) { + revenue = revenue.multiply(new BigDecimal(period)); + } + } + + if (revenue.compareTo(start) >= 0 && revenue.compareTo(end)<= 0){ + ratioVo.setRatio(ratio); + ratioVo.setPrice(countPrice(decimalSize,ratioVo.getRatio(),revenueLong,timeType,period,from).toPlainString()); + break; + } + }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)) { + end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); + } + 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)) { + 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)) { + revenue = revenue.multiply(new BigDecimal(period)); + } + } + + if (revenue.compareTo(end) >= 0){ + ratioVo.setRatio(ratio); + + //计算超出部分 + BigDecimal payRatio = new BigDecimal(ratio).divide(new BigDecimal(10000)); + BigDecimal balance = revenue.subtract(end).multiply(new BigDecimal(1000000)); + BigDecimal price = balance.multiply(payRatio).setScale(decimalSize, RoundingMode.HALF_EVEN); + + array = ratioList.get(i-1).split(":"); + Integer frontatio = Integer.parseInt(array[1]); + revenueArray = array[0].split("-"); + + BigDecimal frontEnd; + 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)){ + frontEnd = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); + }else{ + frontEnd = new BigDecimal(revenueArray[1]); + } + }else{ + frontEnd = new BigDecimal(revenueArray[1]); + } + + BigDecimal frontRatio = new BigDecimal(frontatio).divide(new BigDecimal(10000)); + BigDecimal frontPrice = frontEnd.multiply(new BigDecimal(1000000).multiply(frontRatio).setScale(decimalSize, RoundingMode.HALF_EVEN)); + + ratioVo.setPrice(price.add(frontPrice).toPlainString()); + break; + } + } + } + return ratioVo; + } + + @Transactional(rollbackFor = {Exception.class}) + @Override + public ResultData save(WxRentContract record,MallUserInfo user,String userName,Date oldRentStartDate) { + //保存租赁合同信息 + final IdWorker idWorker = IdWorker.get(); + record.setId(idWorker.nextId()); + int dayType = record.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode()) ? Calendar.DAY_OF_MONTH : Calendar.MONTH; + //计租开始时间 + Calendar instance = Calendar.getInstance(); + instance.setTime(record.getRentalStartDate()); + instance.add(dayType, record.getLease()); + instance.add(Calendar.DAY_OF_MONTH, -1); + //计租结束时间 + if (!record.getStartDate().equals(record.getRentalStartDate())) { + instance.clear(); + instance.setTime(record.getRentalStartDate()); + instance.add(Calendar.DAY_OF_MONTH, -1); + record.setEndDate(instance.getTime()); + } else { + record.setEndDate(record.getStartDate()); + } + + if (null != record.getType() && record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { + if(StringUtils.isBlank(record.getRevenue())){ + record.setPrice("0"); + }else{ + if(StringUtils.isNotBlank(record.getPayRatio())){ + record.setPrice(countPrice(Constant.default_long_decimal_size,record.getPayRatio(),record.getRevenue(),EnumMissTimeType.OTHER.getCode(),record.getAdjustPeriod(),EnumGetRatioFrom.RENT.getCode()).toPlainString()); + }else{ + int dayCount = record.getReceivePeriod() * 30; + RatioVo ratioVo = getPayRatio(Constant.default_long_decimal_size,EnumGetRatioFrom.RENT.getCode(),record.getRevenue(),record.getBusDiscountRatio(), record.getBusDiscountTime(),dayCount,record.getReceivePeriod(),record.getReceivePeriodUnit()); - //record.setPayRatio(ratioVo.getRatio()); - record.setPrice(ratioVo.getPrice()); - } - } - } else { - if (StringUtils.isNotEmpty(record.getPrice())) { - //record.setPrice(new BigDecimal(record.getPriceStr()).multiply(new BigDecimal(100)).longValue()); - } else { - record.setPrice("0"); - } - } - if (StringUtils.isNotEmpty(record.getDeposit())) { - //record.setDeposit(new BigDecimal(record.getDepositStr()).multiply(new BigDecimal(100)).longValue()); - } else { - record.setDeposit("0"); - } - - Date date = new Date(); - record.setCreatetime(date); - record.setCreateBy(user.getId()); - record.setUpdatetime(date); - record.setUpdateBy(user.getId()); - - List shopList = Lists.newArrayList(); - String rentInfo = record.getRentInfo(); - JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); - int size = rentInfoArray.size(); - if (size == 0) { - return new ResultData(ErrorCode.SHOP_NOT_SELECTED); - } - //查询rent_info 包括 shopId - String shopName = ""; - for (int i = 0; i < size; i++) { - JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); - WxRentContract wxRentContract = new WxRentContract(); - wxRentContract.updateTenantInfo(record); - Long shopId = rentInfoObject.getLong("id"); - //wxRentContract.setShopId(shopId); - String shopNumber = rentInfoObject.getString("shopNumber"); -// int count = wxRentContractMapper.selectRentContractCountByShopId(wxRentContract.getTenantId(),wxRentContract.getParentTenantId(),shopId,wxRentContract.getId()); -// if (count > 0) { -// return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + shopNumber + " 已出租"); -// } -// if (record.getMerchantId() != null) { -// WxMerchantShop wxMerchantShop = new WxMerchantShop(); -// wxMerchantShop.setShopId(shopId); -// wxMerchantShop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); -// List wxMerchantShopList = wxMerchantShopMapper.findList(wxMerchantShop); -// long total = wxMerchantShopList.parallelStream(). -// filter(ms -> !ms.getMerchantId().equals(record.getMerchantId())).count(); -// if (total > 0) { -// return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + shopNumber + " 已出租"); -// } -// } else { -// WxShop wxShop = wxShopMapper.selectById(shopId); -// if (wxShop == null) { -// return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND.getCode(), "店铺 " + shopNumber + " 不存在"); -// } -// //if (wxShop.getStatus().equals(EnumShopStatus.RENT.getCode())) { -// // return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + wxShop.getShopNumber() + " 已出租"); -// //} -// } - if (!shopList.contains(shopId)) { - shopList.add(shopId); - shopName = shopName +","+ shopNumber; - } - } - - try { - record.setApplyStatus(EnumRentContractAppStatus.DEFAULT.getCode()); - record.setStatus(EnumRentContractStatus.UNWRITE.getCode()); - Date tempDate = record.getRentalStartDate(); - record.setRentalStartDate(oldRentStartDate); - record.setShopName(shopName); - wxRentContractMapper.insert(record); - record.setRentalStartDate(tempDate); - } catch (Exception e) { - logger.error("保存租赁合同信息失败,e:" + e.getMessage()); - throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); - } - - //生成预览账单(补录第二步,第三步走编辑) -// if (record.getReceivePeriod() != null && record.getLease() != null && record.getPrice() != null -// && !record.getReceivePeriod().equals(0) && !record.getLease().equals(0)) { -// wxBillRentMapper.deletePreviewBill(record); -// //重新生成 -// List resultList = buildRent(null, record, EnumIsPreview.YES.getCode(),true); -// record.setPreviewBillRentList(resultList); -// } - - //创建预览账单 -// List resultList = buildRent(null, record, EnumIsPreview.YES.getCode(),true); -// record.setPreviewBillRentList(resultList); - //EventUtil.publistRentEvent(this, record); - - return new ResultData(Result.SUCCESS, "保存租赁合同信息成功", record); - } - - @Override - public List getShopIds(WxRentContract record) { - return record.shopIdsByRentInfo(); -// List shopList = Lists.newArrayList(); -// if (record.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { -// String rentInfo = record.getRentInfo(); -// JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); -// int size = rentInfoArray.size(); -// //查询rent_info 包括 shopId -// for (int i = 0; i < size; i++) { -// JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); -// WxRentContract wxRentContract = new WxRentContract(); -// wxRentContract.updateTenantInfo(record); -// Long shopId = rentInfoObject.getLong("shopId"); -// shopList.add(shopId); -// } -// } else { -// WxRentContract wxRentContract = new WxRentContract(); -// wxRentContract.updateTenantInfo(record); -// wxRentContract.setShopId(record.getShopId()); -// shopList.add(record.getShopId()); -// } -// return shopList; - } - - //@Transactional(rollbackFor = {Exception.class}) - @Override - public ResultData update(WxRentContract record, MallUserInfo user,String userName,int from,Date oldRentStartDate,boolean writeComplate) { - //查询预账单用于展示 - WxBillRent wxBillRent = new WxBillRent(); - wxBillRent.setRentContractId(record.getId()); - wxBillRent.setSortColumns(BaseEntity.SortField.Period_ASC); - wxBillRent.setIsPreview(EnumIsPreview.YES.getCode()); - wxBillRent.updateTenantInfo(record); - List resultList = wxBillRentMapper.findList(wxBillRent); - - //更新 - ResultData resultData = getResultDataForUpdate(record, user,from,oldRentStartDate,writeComplate); - if (resultData.code != Result.SUCCESS) { - return resultData; - } - - boolean saveBill = true; - if(CollectionUtils.isEmpty(record.getPreviewBillRentList())) { - if (record.getReceivePeriod() != null && record.getLease() != null - && !record.getReceivePeriod().equals(0) && !record.getLease().equals(0)) { - //删除预账单,重新生成 - wxBillRentMapper.deleteBillByContract(record); - //删除商业管理费账单 - WxBillRentManage wxBillRentManage = new WxBillRentManage(); - wxBillRentManage.setRentContractId(record.getId()); - wxBillRentManage.setManageFeeType(EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE.getCode()); - wxBillRentManage.updateTenantInfo(record); - wxBillRentManageMapper.deletePreviewBill(wxBillRentManage); - //删除营业管理费账单 - wxBillRentManage.setManageFeeType(EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE.getCode()); - wxBillRentManageMapper.deletePreviewBill(wxBillRentManage); - - - - //联营扣点,不设置保底营业额,不生成账单 - //if (EnumRentContractType.RENT_BY_JOINT.getCode().equals(record.getType()) && record.getRevenueRatio().equals(0)) { - //do nothing - // saveBill = false; - //}else { - resultList = buildRent(user, record, EnumIsPreview.YES.getCode(),true); - //} - } - } - - //保存调整金额(预账单调整) - //if (saveBill) { - savePreviewBill(record); - //保存商业管理费账单 - savePreviewManageFeeBill(record,EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE); - //保存营业管理费账单 - savePreviewManageFeeBill(record,EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE); - //} - - WxRentContract wxRentContract = (WxRentContract)resultData.data; - wxRentContract.setPreviewBillRentList(resultList); - return new ResultData(wxRentContract); - } - - @Transactional(rollbackFor = {Exception.class}) - @Override - public ResultData updateOneStep(WxRentContract record, MallUserInfo user,String userName,int from,Date oldRentStartDate,boolean writeComplate) { - //查询预账单用于展示 - WxBillRent wxBillRent = new WxBillRent(); - wxBillRent.setRentContractId(record.getId()); - wxBillRent.setSortColumns(BaseEntity.SortField.Period_ASC); - wxBillRent.setIsPreview(EnumIsPreview.YES.getCode()); - wxBillRent.updateTenantInfo(record); - List resultList = wxBillRentMapper.findList(wxBillRent); - - //更新 - ResultData resultData = getResultDataForUpdate(record, user,from,oldRentStartDate,writeComplate); - if (resultData.code != Result.SUCCESS) { - return resultData; - } - WxRentContract wxRentContract = (WxRentContract)resultData.data; - wxRentContract.setPreviewBillRentList(resultList); - return new ResultData(wxRentContract); - } - - /** - * 重新生成账单(预账单调整) - */ - public void savePreviewBill(WxRentContract record){ - - if(CollectionUtils.isEmpty(record.getPreviewBillRentList())){ - return; - } - if (null == record.getDecimalSize()) { - record.setDecimalSize(Constant.default_short_decimal_size); - } - wxBillRentMapper.deleteBillByContract(record); - WxPayAccountBill wxPayAccountBill = wxPayAccountBillService.getByTenantInfo(record); - final IdWorker idWorker = IdWorker.get(); - int count = 1; - List shopIds = record.shopIdsByRentInfo(); - for (WxBillRent bill:record.getPreviewBillRentList()) { - bill.setId(idWorker.nextId()); - Date date = new Date(); - bill.setRentContractId(record.getId()); - bill.setCreatetime(date); - bill.updateTenantInfo(record); - bill.setNeedPay(bill.getNeedPay()); - bill.setReceivePay(bill.getNeedPay()); - bill.setBussinessManageFeeNeedPay(bill.getBussinessManageFeeNeedPay()); - bill.setOperatingManageFeeNeedPay(bill.getOperatingManageFeeNeedPay()); - bill.setUpdatetime(date); - bill.setRentShopType(record.getRentShopType()); - bill.setPeriod(count); - bill.setIsPreview(EnumIsPreview.YES.getCode()); - bill.setShopInfo(getShopInfoStr(record)); - bill.setRevenue("0"); - bill.setLatePayRatio(0); - bill.setPay("0"); - bill.setIsDel(EnumDelStatus.NOT_DEL.getCode()); - bill.setStatus(EnumBillStatus.WAIT_PAY.getCode()); - bill.setMerchantId(record.getMerchantId()); - if (null != shopIds && shopIds.size() == 1) { - bill.setShopId(shopIds.get(0)); - } - //setExpiredDay(bill,Calendar.MONTH,record.getReceivePeriod()); - if (bill.getReceivePay().equals("0")) { - bill.setStatus(EnumBillStatus.PAID.getCode()); - bill.setPayDate(date); - } - //计算手续费 - BigDecimal servicePay = new BigDecimal(bill.getReceivePay()).multiply(new BigDecimal(wxPayAccountBill.getServiceChargeRate())).divide(new BigDecimal(10000), record.getDecimalSize(), BigDecimal.ROUND_HALF_UP); - bill.setServiceChargePay(servicePay.toPlainString()); - //bill.setOwe(bill.getReceivePay() + bill.getServiceChargePay()); - //bill.setOwe(bill.getReceivePay()); - count++; - } - wxBillRentMapper.insertBills(record.getTenantId(),record.getPreviewBillRentList()); - } - - /** - * 重新生成其他管理费用账单(预账单调整) - */ - private void savePreviewManageFeeBill(WxRentContract record,EnumRentContractManageFeeType feeType){ - if(CollectionUtils.isEmpty(record.getPreviewBillRentList())){ - return; - } - if (null == record.getDecimalSize()) { - record.setDecimalSize(Constant.default_short_decimal_size); - } - WxBillRentManage wxBillRentManage = new WxBillRentManage(); - wxBillRentManage.setRentContractId(record.getId()); - wxBillRentManage.setManageFeeType(feeType.getCode()); - wxBillRentManage.updateTenantInfo(record); - wxBillRentManageMapper.deletePreviewBill(wxBillRentManage); - WxPayAccountBill wxPayAccountBill = wxPayAccountBillService.getByTenantInfo(record); - final IdWorker idWorker = IdWorker.get(); - int count = 1; - List shopIds = record.shopIdsByRentInfo(); - List billList = new ArrayList(); - for (WxBillRent _bi:record.getPreviewBillRentList()) { - BigDecimal needPay = new BigDecimal("0"); - if (feeType.getCode() == EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE.getCode()) { - if (null != _bi.getBussinessManageFeeNeedPay()) { - needPay = new BigDecimal(_bi.getBussinessManageFeeNeedPay()); - } - }else if (feeType.getCode() == EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE.getCode()) { - if (null != _bi.getOperatingManageFeeNeedPay()) { - needPay = new BigDecimal(_bi.getOperatingManageFeeNeedPay()); - } - } - if (needPay.compareTo(new BigDecimal(0)) <= 0) { - continue; - } - WxBillRentManage bill = new WxBillRentManage(); - bill.initByBillRent(_bi); - bill.setId(idWorker.nextId()); - Date date = new Date(); - bill.setRentContractId(record.getId()); - bill.setCreatetime(date); - bill.updateTenantInfo(record); - bill.setManageFeeType(feeType.getCode()); - bill.setNeedPay(needPay.toPlainString()); - bill.setReceivePay(needPay.toPlainString()); - bill.setUpdatetime(date); - bill.setRentShopType(record.getRentShopType()); - bill.setPeriod(count); - bill.setShopInfo(getShopInfoStr(record)); - bill.setLatePayRatio(0); - bill.setPay("0"); - bill.setIsDel(EnumDelStatus.NOT_DEL.getCode()); - bill.setStatus(EnumBillStatus.WAIT_PAY.getCode()); - bill.setMerchantId(record.getMerchantId()); - if (null != shopIds && shopIds.size() == 1) { - bill.setShopId(shopIds.get(0)); - } - //setManageExpiredDay(bill,Calendar.MONTH,record.getReceivePeriod()); - if (bill.getReceivePay().equals("0")) { - bill.setStatus(EnumBillStatus.PAID.getCode()); - bill.setPayDate(date); - } - //计算手续费 - BigDecimal servicePay = new BigDecimal(bill.getReceivePay()).multiply(new BigDecimal(wxPayAccountBill.getServiceChargeRate())).divide(new BigDecimal(10000), record.getDecimalSize(), BigDecimal.ROUND_HALF_UP); - bill.setServiceChargePay(servicePay.toPlainString()); - //bill.setOwe(bill.getReceivePay() + bill.getServiceChargePay()); - //bill.setOwe(bill.getReceivePay()); - count++; - billList.add(bill); - } - if (billList.size() > 0 ) { - wxBillRentManageMapper.insertBills(record.getTenantId(),billList); - } - } - - public ResultData getResultDataForUpdate(WxRentContract record, MallUserInfo user,int from,Date oldRentStartDate,boolean writeFinal) { - //更新租赁合同信息 - WxRentContract wxRentContract = wxRentContractMapper.selectById(record.getId()); - if (wxRentContract == null) { - return new ResultData(ErrorCode.RENT_CONTRACT_IS_NOT_FOUND); - } - wxRentContract.setBusDiscountTime(record.getBusDiscountTime()); - wxRentContract.setBusDiscountRatio(record.getBusDiscountRatio()); - wxRentContract.setPayRatio(record.getPayRatio()); - - int dayType = wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode()) ? Calendar.DAY_OF_MONTH : Calendar.MONTH; - - Calendar instance = Calendar.getInstance(); - instance.setTime(record.getRentalStartDate()); - instance.add(dayType, record.getLease()); - instance.add(Calendar.DAY_OF_MONTH, -1); - - if(!EnumFromType.SWITCH.getCode().equals(from)){ - if (record.getType() != null && record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { - if(StringUtils.isNotBlank(record.getPayRatio())){ - record.setPrice(countPrice(Constant.default_long_decimal_size,record.getPayRatio(),record.getRevenue(),EnumMissTimeType.OTHER.getCode(),record.getAdjustPeriod(),from).toPlainString()); - }else{ - int dayCount = record.getReceivePeriod() * 30; - RatioVo ratioVo = getPayRatio(Constant.default_long_decimal_size,EnumGetRatioFrom.RENT.getCode(),record.getRevenue(), - record.getBusDiscountRatio(),record.getBusDiscountTime(),dayCount,record.getReceivePeriod(),record.getReceivePeriodUnit()); - //record.setPayRatio(ratioVo.getRatio()); - record.setPrice(ratioVo.getPrice()); - } - } else { - if (StringUtils.isNotEmpty(record.getPrice())) { - //record.setPrice(new BigDecimal(record.getPriceStr()).multiply(new BigDecimal(100)).longValue()); - } else { - record.setPrice("0"); - } - } - } - - if (StringUtils.isNotEmpty(record.getDeposit())) { - //record.setDeposit(new BigDecimal(record.getDepositStr()).multiply(new BigDecimal(100)).longValue()); - } else { - record.setDeposit("0"); - } - List shopList = Lists.newArrayList(); - record.setUpdatetime(new Date()); + //record.setPayRatio(ratioVo.getRatio()); + record.setPrice(ratioVo.getPrice()); + } + } + } else { + if (StringUtils.isNotEmpty(record.getPrice())) { + //record.setPrice(new BigDecimal(record.getPriceStr()).multiply(new BigDecimal(100)).longValue()); + } else { + record.setPrice("0"); + } + } + if (StringUtils.isNotEmpty(record.getDeposit())) { + //record.setDeposit(new BigDecimal(record.getDepositStr()).multiply(new BigDecimal(100)).longValue()); + } else { + record.setDeposit("0"); + } + + Date date = new Date(); + record.setCreatetime(date); + record.setCreateBy(user.getId()); + record.setUpdatetime(date); + record.setUpdateBy(user.getId()); + + List shopList = Lists.newArrayList(); + String rentInfo = record.getRentInfo(); + JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); + int size = rentInfoArray.size(); + if (size == 0) { + return new ResultData(ErrorCode.SHOP_NOT_SELECTED); + } + //查询rent_info 包括 shopId + String shopName = ""; + for (int i = 0; i < size; i++) { + JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); + WxRentContract wxRentContract = new WxRentContract(); + wxRentContract.updateTenantInfo(record); + Long shopId = rentInfoObject.getLong("id"); + //wxRentContract.setShopId(shopId); + String shopNumber = rentInfoObject.getString("shopNumber"); +// int count = wxRentContractMapper.selectRentContractCountByShopId(wxRentContract.getTenantId(),wxRentContract.getParentTenantId(),shopId,wxRentContract.getId()); +// if (count > 0) { +// return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + shopNumber + " 已出租"); +// } +// if (record.getMerchantId() != null) { +// WxMerchantShop wxMerchantShop = new WxMerchantShop(); +// wxMerchantShop.setShopId(shopId); +// wxMerchantShop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); +// List wxMerchantShopList = wxMerchantShopMapper.findList(wxMerchantShop); +// long total = wxMerchantShopList.parallelStream(). +// filter(ms -> !ms.getMerchantId().equals(record.getMerchantId())).count(); +// if (total > 0) { +// return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + shopNumber + " 已出租"); +// } +// } else { +// WxShop wxShop = wxShopMapper.selectById(shopId); +// if (wxShop == null) { +// return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND.getCode(), "店铺 " + shopNumber + " 不存在"); +// } +// //if (wxShop.getStatus().equals(EnumShopStatus.RENT.getCode())) { +// // return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + wxShop.getShopNumber() + " 已出租"); +// //} +// } + if (!shopList.contains(shopId)) { + shopList.add(shopId); + shopName = shopName +","+ shopNumber; + } + } + + try { + record.setApplyStatus(EnumRentContractAppStatus.DEFAULT.getCode()); + record.setStatus(EnumRentContractStatus.UNWRITE.getCode()); + Date tempDate = record.getRentalStartDate(); + record.setRentalStartDate(oldRentStartDate); + record.setShopName(shopName); + wxRentContractMapper.insert(record); + record.setRentalStartDate(tempDate); + } catch (Exception e) { + logger.error("保存租赁合同信息失败,e:" + e.getMessage()); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); + } + + //生成预览账单(补录第二步,第三步走编辑) +// if (record.getReceivePeriod() != null && record.getLease() != null && record.getPrice() != null +// && !record.getReceivePeriod().equals(0) && !record.getLease().equals(0)) { +// wxBillRentMapper.deletePreviewBill(record); +// //重新生成 +// List resultList = buildRent(null, record, EnumIsPreview.YES.getCode(),true); +// record.setPreviewBillRentList(resultList); +// } + + //创建预览账单 +// List resultList = buildRent(null, record, EnumIsPreview.YES.getCode(),true); +// record.setPreviewBillRentList(resultList); + //EventUtil.publistRentEvent(this, record); + + return new ResultData(Result.SUCCESS, "保存租赁合同信息成功", record); + } + + @Override + public List getShopIds(WxRentContract record) { + return record.shopIdsByRentInfo(); +// List shopList = Lists.newArrayList(); +// if (record.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { +// String rentInfo = record.getRentInfo(); +// JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); +// int size = rentInfoArray.size(); +// //查询rent_info 包括 shopId +// for (int i = 0; i < size; i++) { +// JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); +// WxRentContract wxRentContract = new WxRentContract(); +// wxRentContract.updateTenantInfo(record); +// Long shopId = rentInfoObject.getLong("shopId"); +// shopList.add(shopId); +// } +// } else { +// WxRentContract wxRentContract = new WxRentContract(); +// wxRentContract.updateTenantInfo(record); +// wxRentContract.setShopId(record.getShopId()); +// shopList.add(record.getShopId()); +// } +// return shopList; + } + + //@Transactional(rollbackFor = {Exception.class}) + @Override + public ResultData update(WxRentContract record, MallUserInfo user,String userName,int from,Date oldRentStartDate,boolean writeComplate) { + //查询预账单用于展示 + WxBillRent wxBillRent = new WxBillRent(); + wxBillRent.setRentContractId(record.getId()); + wxBillRent.setSortColumns(BaseEntity.SortField.Period_ASC); + wxBillRent.setIsPreview(EnumIsPreview.YES.getCode()); + wxBillRent.updateTenantInfo(record); + List resultList = wxBillRentMapper.findList(wxBillRent); + + //更新 + ResultData resultData = getResultDataForUpdate(record, user,from,oldRentStartDate,writeComplate); + if (resultData.code != Result.SUCCESS) { + return resultData; + } + + boolean saveBill = true; + if(CollectionUtils.isEmpty(record.getPreviewBillRentList())) { + if (record.getReceivePeriod() != null && record.getLease() != null + && !record.getReceivePeriod().equals(0) && !record.getLease().equals(0)) { + //删除预账单,重新生成 + wxBillRentMapper.deleteBillByContract(record); + //删除商业管理费账单 + WxBillRentManage wxBillRentManage = new WxBillRentManage(); + wxBillRentManage.setRentContractId(record.getId()); + wxBillRentManage.setManageFeeType(EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE.getCode()); + wxBillRentManage.updateTenantInfo(record); + wxBillRentManageMapper.deletePreviewBill(wxBillRentManage); + //删除营业管理费账单 + wxBillRentManage.setManageFeeType(EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE.getCode()); + wxBillRentManageMapper.deletePreviewBill(wxBillRentManage); + + + + //联营扣点,不设置保底营业额,不生成账单 + //if (EnumRentContractType.RENT_BY_JOINT.getCode().equals(record.getType()) && record.getRevenueRatio().equals(0)) { + //do nothing + // saveBill = false; + //}else { + resultList = buildRent(user, record, EnumIsPreview.YES.getCode(),true); + //} + } + } + + //保存调整金额(预账单调整) + //if (saveBill) { + savePreviewBill(record,user); + //保存商业管理费账单 + savePreviewManageFeeBill(record,user,EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE); + //保存营业管理费账单 + savePreviewManageFeeBill(record,user,EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE); + //} + + WxRentContract wxRentContract = (WxRentContract)resultData.data; + wxRentContract.setPreviewBillRentList(resultList); + return new ResultData(wxRentContract); + } + + @Transactional(rollbackFor = {Exception.class}) + @Override + public ResultData updateOneStep(WxRentContract record, MallUserInfo user,String userName,int from,Date oldRentStartDate,boolean writeComplate) { + //查询预账单用于展示 + WxBillRent wxBillRent = new WxBillRent(); + wxBillRent.setRentContractId(record.getId()); + wxBillRent.setSortColumns(BaseEntity.SortField.Period_ASC); + wxBillRent.setIsPreview(EnumIsPreview.YES.getCode()); + wxBillRent.updateTenantInfo(record); + List resultList = wxBillRentMapper.findList(wxBillRent); + + //更新 + ResultData resultData = getResultDataForUpdate(record, user,from,oldRentStartDate,writeComplate); + if (resultData.code != Result.SUCCESS) { + return resultData; + } + WxRentContract wxRentContract = (WxRentContract)resultData.data; + wxRentContract.setPreviewBillRentList(resultList); + return new ResultData(wxRentContract); + } + + /** + * 重新生成账单(预账单调整) + */ + public void savePreviewBill(WxRentContract record,MallUserInfo user){ + + if(CollectionUtils.isEmpty(record.getPreviewBillRentList())){ + return; + } + if (null == record.getDecimalSize()) { + record.setDecimalSize(Constant.default_short_decimal_size); + } + wxBillRentMapper.deleteBillByContract(record); + WxPayAccountBill wxPayAccountBill = wxPayAccountBillService.getByTenantInfo(record); + final IdWorker idWorker = IdWorker.get(); + int count = 1; + List shopIds = record.shopIdsByRentInfo(); + for (WxBillRent bill:record.getPreviewBillRentList()) { + bill.setId(idWorker.nextId()); + Date date = new Date(); + bill.setRentContractId(record.getId()); + bill.setCreatetime(date); + bill.setCreateBy(user.getId()); + bill.setCreateByName(user.getName()); + bill.updateTenantInfo(record); + bill.setNeedPay(bill.getNeedPay()); + bill.setReceivePay(bill.getNeedPay()); + bill.setBussinessManageFeeNeedPay(bill.getBussinessManageFeeNeedPay()); + bill.setOperatingManageFeeNeedPay(bill.getOperatingManageFeeNeedPay()); + bill.setUpdatetime(date); bill.setUpdateBy(user.getId()); + bill.setUpdateByName(user.getName()); + bill.setRentShopType(record.getRentShopType()); + bill.setPeriod(count); + bill.setIsPreview(EnumIsPreview.YES.getCode()); + bill.setShopInfo(getShopInfoStr(record)); + bill.setRevenue("0"); + bill.setLatePayRatio(0); + bill.setPay("0"); + bill.setIsDel(EnumDelStatus.NOT_DEL.getCode()); + bill.setStatus(EnumBillStatus.WAIT_PAY.getCode()); + bill.setMerchantId(record.getMerchantId()); + if (null != shopIds && shopIds.size() == 1) { + bill.setShopId(shopIds.get(0)); + } + //setExpiredDay(bill,Calendar.MONTH,record.getReceivePeriod()); + if (bill.getReceivePay().equals("0")) { + bill.setStatus(EnumBillStatus.PAID.getCode()); + bill.setPayDate(date); + } + //计算手续费 + BigDecimal servicePay = new BigDecimal(bill.getReceivePay()).multiply(new BigDecimal(wxPayAccountBill.getServiceChargeRate())).divide(new BigDecimal(10000), record.getDecimalSize(), BigDecimal.ROUND_HALF_UP); + bill.setServiceChargePay(servicePay.toPlainString()); + //bill.setOwe(bill.getReceivePay() + bill.getServiceChargePay()); + //bill.setOwe(bill.getReceivePay()); + count++; + } + wxBillRentMapper.insertBills(record.getTenantId(),record.getPreviewBillRentList()); + } + + /** + * 重新生成其他管理费用账单(预账单调整) + */ + private void savePreviewManageFeeBill(WxRentContract record,MallUserInfo user,EnumRentContractManageFeeType feeType){ + if(CollectionUtils.isEmpty(record.getPreviewBillRentList())){ + return; + } + if (null == record.getDecimalSize()) { + record.setDecimalSize(Constant.default_short_decimal_size); + } + WxBillRentManage wxBillRentManage = new WxBillRentManage(); + wxBillRentManage.setRentContractId(record.getId()); + wxBillRentManage.setManageFeeType(feeType.getCode()); + wxBillRentManage.updateTenantInfo(record); + wxBillRentManageMapper.deletePreviewBill(wxBillRentManage); + WxPayAccountBill wxPayAccountBill = wxPayAccountBillService.getByTenantInfo(record); + final IdWorker idWorker = IdWorker.get(); + int count = 1; + List shopIds = record.shopIdsByRentInfo(); + List billList = new ArrayList(); + for (WxBillRent _bi:record.getPreviewBillRentList()) { + BigDecimal needPay = new BigDecimal("0"); + if (feeType.getCode() == EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE.getCode()) { + if (null != _bi.getBussinessManageFeeNeedPay()) { + needPay = new BigDecimal(_bi.getBussinessManageFeeNeedPay()); + } + }else if (feeType.getCode() == EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE.getCode()) { + if (null != _bi.getOperatingManageFeeNeedPay()) { + needPay = new BigDecimal(_bi.getOperatingManageFeeNeedPay()); + } + } + if (needPay.compareTo(new BigDecimal(0)) <= 0) { + continue; + } + WxBillRentManage bill = new WxBillRentManage(); + bill.initByBillRent(_bi); + bill.setId(idWorker.nextId()); + Date date = new Date(); + bill.setRentContractId(record.getId()); + bill.setCreatetime(date); + bill.setCreateBy(user.getId()); + bill.setCreateByName(user.getName());; + bill.updateTenantInfo(record); + bill.setManageFeeType(feeType.getCode()); + bill.setNeedPay(needPay.toPlainString()); + bill.setReceivePay(needPay.toPlainString()); + bill.setUpdatetime(date); + bill.setUpdateBy(user.getId()); + bill.setUpdateByName(user.getName()); + bill.setRentShopType(record.getRentShopType()); + bill.setPeriod(count); + bill.setShopInfo(getShopInfoStr(record)); + bill.setLatePayRatio(0); + bill.setPay("0"); + bill.setIsDel(EnumDelStatus.NOT_DEL.getCode()); + bill.setStatus(EnumBillStatus.WAIT_PAY.getCode()); + bill.setMerchantId(record.getMerchantId()); + if (null != shopIds && shopIds.size() == 1) { + bill.setShopId(shopIds.get(0)); + } + //setManageExpiredDay(bill,Calendar.MONTH,record.getReceivePeriod()); + if (bill.getReceivePay().equals("0")) { + bill.setStatus(EnumBillStatus.PAID.getCode()); + bill.setPayDate(date); + } + //计算手续费 + BigDecimal servicePay = new BigDecimal(bill.getReceivePay()).multiply(new BigDecimal(wxPayAccountBill.getServiceChargeRate())).divide(new BigDecimal(10000), record.getDecimalSize(), BigDecimal.ROUND_HALF_UP); + bill.setServiceChargePay(servicePay.toPlainString()); + //bill.setOwe(bill.getReceivePay() + bill.getServiceChargePay()); + //bill.setOwe(bill.getReceivePay()); + count++; + billList.add(bill); + } + if (billList.size() > 0 ) { + wxBillRentManageMapper.insertBills(record.getTenantId(),billList); + } + } + + public ResultData getResultDataForUpdate(WxRentContract record, MallUserInfo user,int from,Date oldRentStartDate,boolean writeFinal) { + //更新租赁合同信息 + WxRentContract wxRentContract = wxRentContractMapper.selectById(record.getId()); + if (wxRentContract == null) { + return new ResultData(ErrorCode.RENT_CONTRACT_IS_NOT_FOUND); + } + wxRentContract.setBusDiscountTime(record.getBusDiscountTime()); + wxRentContract.setBusDiscountRatio(record.getBusDiscountRatio()); + wxRentContract.setPayRatio(record.getPayRatio()); + + int dayType = wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode()) ? Calendar.DAY_OF_MONTH : Calendar.MONTH; + + Calendar instance = Calendar.getInstance(); + instance.setTime(record.getRentalStartDate()); + instance.add(dayType, record.getLease()); + instance.add(Calendar.DAY_OF_MONTH, -1); + + if(!EnumFromType.SWITCH.getCode().equals(from)){ + if (record.getType() != null && record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { + if(StringUtils.isNotBlank(record.getPayRatio())){ + record.setPrice(countPrice(Constant.default_long_decimal_size,record.getPayRatio(),record.getRevenue(),EnumMissTimeType.OTHER.getCode(),record.getAdjustPeriod(),from).toPlainString()); + }else{ + int dayCount = record.getReceivePeriod() * 30; + RatioVo ratioVo = getPayRatio(Constant.default_long_decimal_size,EnumGetRatioFrom.RENT.getCode(),record.getRevenue(), + record.getBusDiscountRatio(),record.getBusDiscountTime(),dayCount,record.getReceivePeriod(),record.getReceivePeriodUnit()); + //record.setPayRatio(ratioVo.getRatio()); + record.setPrice(ratioVo.getPrice()); + } + } else { + if (StringUtils.isNotEmpty(record.getPrice())) { + //record.setPrice(new BigDecimal(record.getPriceStr()).multiply(new BigDecimal(100)).longValue()); + } else { + record.setPrice("0"); + } + } + } + + if (StringUtils.isNotEmpty(record.getDeposit())) { + //record.setDeposit(new BigDecimal(record.getDepositStr()).multiply(new BigDecimal(100)).longValue()); + } else { + record.setDeposit("0"); + } + List shopList = Lists.newArrayList(); + record.setUpdatetime(new Date()); record.setUpdateBy(user.getId());; -// if (record.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { - String rentInfo = record.getRentInfo(); - JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); - int size = rentInfoArray.size(); - if (size == 0) { - return new ResultData(ErrorCode.SHOP_NOT_SELECTED); - } - //查询rent_info 包括 shopId - String shopName = ""; - for (int i = 0; i < size; i++) { - JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); - WxRentContract wxRentContractQuery = new WxRentContract(); - wxRentContractQuery.updateTenantInfo(record); - Long shopId = rentInfoObject.getLong("id"); - String shopNumber = rentInfoObject.getString("shopNumber"); - if (shopId == null) { - return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND.getCode(), "店铺 " + shopNumber + " 已删除"); - } - wxRentContractQuery.setId(record.getId()); - //int count = wxRentContractMapper.selectRentContractCountByShopId(wxRentContractQuery.getTenantId(),wxRentContractQuery.getParentTenantId(),shopId,wxRentContractQuery.getId()); - //if (count > 0) { - // return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + shopNumber + " 已出租"); - //} -// if (record.getMerchantId() != null) { -// WxMerchantShop wxMerchantShop = new WxMerchantShop(); -// wxMerchantShop.setShopId(shopId); -// wxMerchantShop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); -// List wxMerchantShopList = wxMerchantShopMapper.findList(wxMerchantShop); -// long total = wxMerchantShopList.parallelStream(). -// filter(ms -> !ms.getMerchantId().equals(record.getMerchantId())).count(); -// if (total > 0) { -// return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + shopNumber + " 已出租"); -// } -// } else { -// WxShop wxShop = wxShopMapper.selectById(shopId); -// if (wxShop == null) { -// return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND.getCode(), "店铺 " + shopNumber + " 已删除"); -// } -//// if (wxShop.getStatus().equals(EnumShopStatus.RENT.getCode())) { -//// return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + wxShop.getShopNumber() + " 已出租"); -//// } -// } - if (!shopList.contains(shopId)) { - shopList.add(shopId); - shopName = shopName +","+shopNumber; - } - } -// } else { -// WxRentContract wxRentContractQuery = new WxRentContract(); -// wxRentContractQuery.updateTenantInfo(record); -// wxRentContractQuery.setShopId(record.getShopId()); -//// long count = wxRentContractMapper.queryRentContractData(wxRentContract).stream(). -//// filter(rc -> rc.get("status").equals(EnumRentContractStatus.READY_FOR_PAING.getCode()) -//// || rc.get("status").equals(EnumRentContractStatus.PAING.getCode()) -//// || rc.get("status").equals(EnumRentContractStatus.CONTRACT_END_SOON.getCode())).count(); -// long count = wxRentContractMapper.queryRentContractData(wxRentContract).stream(). -// filter(rc -> rc.get("status").equals(EnumRentContractStatus.READY_FOR_PAING.getCode()) -// || rc.get("status").equals(EnumRentContractStatus.PAING.getCode())).count(); -// if (count > 0) { -// return new ResultData(ErrorCode.RENT_CONTRACT_WITH_SHOP_IS_FOUND); -// } -// } - - try { - Date tempDate = record.getRentalStartDate(); - record.setRentalStartDate(oldRentStartDate); - record.setShopName(shopName); - if (writeFinal) { - record.setStatus(EnumRentContractStatus.DRAFT.getCode()); - }else { - record.setStatus(wxRentContract.getStatus()); - } - record.setApplyStatus(wxRentContract.getApplyStatus()); - if (StringUtils.isBlank(record.getOperatingManagementFee())){ - record.setOperatingManagementFee(null); - } - if (StringUtils.isBlank(record.getBussinessManagementFee())){ - record.setBussinessManagementFee(null); - } - wxRentContractMapper.updateById(record); - record.setRentalStartDate(tempDate); - } catch (Exception e) { - logger.error("更新租赁合同信息失败,e:" + e.getMessage()); - throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); - } - //重新查一次 - wxRentContract = wxRentContractMapper.selectById(record.getId()); - return new ResultData(Result.SUCCESS, "保存租赁合同信息成功", wxRentContract); - } - - - @Transactional(rollbackFor = {Exception.class}) - @Override - public void buildDeposit( Long userId,Long rentContractId) { - WxRentContract wxRentContract = wxRentContractMapper.selectById(rentContractId); - if (wxRentContract != null && StringUtils.isNotBlank(wxRentContract.getDeposit()) - && new BigDecimal(wxRentContract.getDeposit()).compareTo(new BigDecimal(0)) > 0 ) { - - WxRentContractDepositType dt = new WxRentContractDepositType(); - dt.updateTenantInfo(wxRentContract); - Map typeMap = findDepositTypesMap(dt); - - final IdWorker idWorker = IdWorker.get(); - WxBillDeposit wxBillDeposit = new WxBillDeposit(); - wxBillDeposit.setId(idWorker.nextId()); - wxBillDeposit.setRentContractId(wxRentContract.getId()); - wxBillDeposit.setContractDepoistDetail(wxRentContract.getDepositDetail(typeMap)); - wxBillDeposit.setPay("0"); - String needpay = wxRentContract.getDeposit(); - wxBillDeposit.setReceivePay(needpay); - wxBillDeposit.setNeedPay(needpay); - //wxBillDeposit.setOwe(needpay); - //找到计租方式 - int dayType = wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode()) ? Calendar.DAY_OF_MONTH : Calendar.MONTH; - - Date date = new Date(); - Calendar instance = Calendar.getInstance(); - instance.setTime(wxRentContract.getRentalStartDate()); - instance.add(Calendar.DAY_OF_MONTH, -1); - Date time = instance.getTime(); - wxBillDeposit.setReceiveDate(time); - - //账单开始时间 - instance.clear(); - instance.setTime(wxBillDeposit.getReceiveDate()); - instance.add(Calendar.DAY_OF_MONTH, 1); - wxBillDeposit.setStarttime(instance.getTime()); - //账单结束时间 - instance.clear(); - instance.setTime(wxBillDeposit.getReceiveDate()); - instance.add(dayType, wxRentContract.getLease()); - wxBillDeposit.setEndtime(instance.getTime()); - wxBillDeposit.setStatus(EnumBillStatus.WAIT_PAY.getCode()); - wxBillDeposit.setExpiredDay(0L); - wxBillDeposit.setReceiveDate(time); - wxBillDeposit.updateTenantInfo(wxRentContract); - wxBillDeposit.setIsDel(0); - wxBillDeposit.setMerchantId(wxRentContract.getMerchantId()); - wxBillDeposit.setUserId(userId); - if (wxRentContract.shopIdsByRentInfo().size()==1) { - wxBillDeposit.setShopId(wxRentContract.shopIdsByRentInfo().get(0)); - } - wxBillDeposit.setCreatetime(date); - wxBillDeposit.setUpdatetime(date); - wxBillDeposit.setIsDel(EnumDelStatus.NOT_DEL.getCode()); - wxBillDeposit.setRentShopType(wxRentContract.getRentShopType()); - if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { - String rentInfo = wxRentContract.getRentInfo(); - if (rentInfo != null) { - JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); - Map shopInfo = new HashMap<>(); - for (int i = 0, size = rentInfoArray.size(); i < size; i++) { - JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); - shopInfo.put(rentInfoObject.getString("shopNumber"), rentInfoObject.get("deposit")); - } - wxBillDeposit.setShopInfo(JSONObject.toJSONString(shopInfo)); - } - } - try { - wxBillDepositMapper.insert(wxBillDeposit); - } catch (Exception e) { - logger.error("添加押金账单失败,e:" + e.getMessage()); - throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); - } - } - } - - @Override - public Object getMerchants(WxRentContract wxRentContract) { - List rentContractList = wxRentContractMapper.getMerchants(wxRentContract); - return rentContractList; - } - -// @Override -// public void updateInvalidContract(Long rentContractId) { -// WxRentContract wxRentContract = wxRentContractMapper.selectById(rentContractId); -// if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { -// String rentInfo = wxRentContract.getRentInfo(); -// JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); -// WxRentContract record = new WxRentContract(); -// for (int i = 0, size = rentInfoArray.size(); i < size; i++) { -// JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); -// Long shopId = rentInfoObject.getLong("shopId"); -// record.setShopId(shopId); -// record.updateTenantInfo(wxRentContract); -// record.setStatus(EnumRentContractStatus.INVALID.getCode()); -// wxRentContractMapper.updateInvalidContract(record); -// List rentContractList = wxRentContractMapper.selectRentContractByShopId(record); -// for (WxRentContract updateContract : rentContractList) { -// updateInvalidStatus(updateContract); -// } -// } -// } else { -// WxRentContract record = new WxRentContract(); -// record.updateTenantInfo(wxRentContract); -// record.setRentShopType(wxRentContract.getRentShopType()); -// record.setStatus(EnumRentContractStatus.INVALID.getCode()); -// wxRentContractMapper.updateRentInvalidStatus(record); -// List rentContractList = wxRentContractMapper.selectList(new QueryWrapper(record)); -// for (WxRentContract updateContract : rentContractList) { -// updateInvalidStatus(updateContract); -// } -// } -// -// } - - @Override - public ResultData hasRentStatus(WxRentContract record) { - String rentInfo = record.getRentInfo(); - if (StringUtils.isEmpty(rentInfo)) { - return new ResultData(ErrorCode.SHOP_NOT_SELECTED); - } - String[] split = rentInfo.split(","); - int size = split.length; - //查询rent_info 包括 shopId - for (int i = 0; i < size; i++) { - String shopId = split[i]; - WxShop wxShop = wxShopMapper.selectById(shopId); - WxRentContract wxRentContractQuery = new WxRentContract(); - wxRentContractQuery.updateTenantInfo(record); - String shopNumber = wxShop.getShopNumber(); - if (shopId == null) { - return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND.getCode(), "店铺 " + shopNumber + " 已删除"); - } - //wxRentContractQuery.setShopId(Long.valueOf(shopId)); - int count = wxRentContractMapper.selectRentContractCountByShopId(wxRentContractQuery.getTenantId(),wxRentContractQuery.getParentTenantId(),Long.valueOf(shopId),wxRentContractQuery.getId()); - if (count > 0) { - return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + shopNumber + " 已出租"); - } - } - return new ResultData(Result.SUCCESS, "操作成功"); - } - - @Override - public ResultData hasContractNumber(WxRentContract wxRentContract) { - int count = wxRentContractMapper.hasContractNumber(wxRentContract); - return new ResultData(Result.SUCCESS, "操作成功", count > 0 ? true : false); - } - - public void updateInvalidStatus(WxRentContract record) { - Long id = record.getId(); - //审核流程中止 - try { - // 修改合同审核状态 - WxRentContract rentContract = record; - rentContract.setId(id); - rentContract.setApplyStatus(EnumRentContractAppStatus.CANCLE.getCode()); - updateApplyStatus(rentContract); - - //修改flowRecord - WxFlowRecord fr = new WxFlowRecord(); - fr.setBusinessId(String.valueOf(id)); - fr.setCurrStatus(EnumRentContractAppStatus.CANCLE.getCode()); - wxFlowRecordMapper.updateCurrStatus(fr); - - logger.info("合同id:{},开始停止...", id); - //结束审批流 by luozukai - WxFlowModel flowModel = wxFlowService.getModelByType(EnumFlowKey.NEW_RENT_CONTRACT.getCode().intValue(),record); - WxFlowModel flowModelPoint = wxFlowService.getModelByType(EnumFlowKey.NEW_SHOP_CONTRACT.getCode().intValue(),record); - - WxFlowModel flowModel_pro = wxFlowService.getModelByType(EnumFlowKey.NEW_PRO_CONTRACT.getCode().intValue(),record); - WxFlowModel flowModelPoint_pro = wxFlowService.getModelByType(EnumFlowKey.NEW_PRO_POINT_CONTRACT.getCode().intValue(),record); - - WxFlowModel flowModel_rent = wxFlowService.getModelByType(EnumFlowKey.NNEW_RENT_CONTRACT.getCode().intValue(),record); - WxFlowModel flowModelPoint_rent = wxFlowService.getModelByType(EnumFlowKey.NEW_RENT_POINT_CONTRACT.getCode().intValue(),record); - - List keyList = new ArrayList<>(); - if(flowModel != null){ - keyList.add(flowModel.getFlowId()); - } - if(flowModelPoint != null){ - keyList.add(flowModelPoint.getFlowId()); - } - if(flowModel_pro != null){ - keyList.add(flowModel_pro.getFlowId()); - } - if(flowModelPoint_pro != null){ - keyList.add(flowModelPoint_pro.getFlowId()); - } - if(flowModel_rent != null){ - keyList.add(flowModel_rent.getFlowId()); - } - if(flowModelPoint_rent != null){ - keyList.add(flowModelPoint_rent.getFlowId()); - } - keyList.add(EnumFlowKey.CONTRACT.getMessage()); - List tasks = taskService.createTaskQuery() - .processDefinitionKeyIn(keyList) - .processVariableValueEquals("businessId", id+"").list(); - if (!CollectionUtils.isEmpty(tasks)) { - for (Task task : tasks) { - logger.info("合同id:{},taskid:{}", id, task.getId()); - runtimeService.deleteProcessInstance(task.getProcessInstanceId(), "合同作废"); - - // 保存审批历史入 - MallUserInfo mallUserInfo = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute("userSession"); - WxFlowRecord updateRecord = new WxFlowRecord(); - updateRecord.setBusinessId(String.valueOf(id)); - updateRecord.setStatus(EnumFlowRecordStatus.CANCLE.getCode()); - updateRecord.setBusinessType(1); - updateRecord.setUserId(mallUserInfo.getId()); - updateRecord.setProcessInstanceId(task.getProcessInstanceId()); - wxFlowRecordService.saveOrUpdate(updateRecord); - } - } - - } catch (Exception e) { - logger.error("deleteProcessInstance error", e); - } - } - - @Override - @Transactional(rollbackFor = {Exception.class}) - public List buildRent(MallUserInfo user,WxRentContract wxRentContract,Integer isPreview,boolean saveDb) { - List rentList = new ArrayList<>(); - if (wxRentContract != null) { - int receivePeriod = wxRentContract.getReceivePeriod().intValue(); - Integer lease = wxRentContract.getLease(); - Date rentalStartDate = wxRentContract.getRentalStartDate(); - String price = wxRentContract.getPrice(); - if(EnumContractOperationType.JINMAO.getCode().equals(wxRentContract.getOperationType())){ - Date startDate = wxRentContract.getStartDate(); - rentList = buildRentJinmao(user, wxRentContract, receivePeriod, lease, startDate, price, isPreview,saveDb); - }else{ - rentList = buildRentMonth(user, wxRentContract, receivePeriod, lease, rentalStartDate, price, isPreview,saveDb); - } - } - for (int i = 0; i < rentList.size(); i++) { - rentList.get(i).setPeriod(i+1); - } - return rentList; - } - - - - public List buildRentMonth(MallUserInfo user, WxRentContract wxRentContract, int receivePeriod, Integer lease, Date rentalStartDate, String price, Integer isPreview, boolean saveDb) { - int years = 0; - //计算租金每年的计费基数 - String[] priceArrs = WxRentContractHelper.calcuteRentPrice(wxRentContract); - //计算商业管理费 - String[] bussinessManagerPriceArrs = WxRentContractHelper.calcuteBussinessManagementFee(wxRentContract); - //计算运营管理费 - String[] operationManagerPriceArrs = WxRentContractHelper.calcuteOperatingManagementFee(wxRentContract); - int month = 12; - int billcount = 0; - List resultList = new ArrayList<>(); - years = priceArrs.length; - List yearList = new ArrayList<>(); - for (int i = 0; i < years; i++) { - Calendar instance = Calendar.getInstance(); - Date startDate; - //自然月 - if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ - if(i == 0){ //第一期 - startDate = rentalStartDate; - }else{ - instance.setTime(rentalStartDate); - instance.add(Calendar.MONTH, month * i); - startDate = DateUtils.getFirstDayForCurrMonth(instance.getTime()); - } - }else{ - instance.setTime(rentalStartDate); - instance.add(Calendar.MONTH, month * i); - startDate = instance.getTime(); - } - yearList.add(startDate); - } - - String shopInfoStr = getShopInfoStr(wxRentContract); - Map resultMap = buildRent(receivePeriod, priceArrs,bussinessManagerPriceArrs,operationManagerPriceArrs, yearList, wxRentContract.getReceivePeriodUnit(), wxRentContract, user, billcount, isPreview, shopInfoStr,saveDb); - List billRentList = (List)resultMap.get("billList"); - resultList.addAll(billRentList); - return resultList; - } - - public List buildRentJinmao(MallUserInfo user, WxRentContract wxRentContract, int receivePeriod, Integer lease, Date rentalStartDate, String price, Integer isPreview, boolean saveDb) { - int size = 0; - String[] priceArrs = null; - if (wxRentContract.getType().equals(EnumRentContractType.RENT_BY_AREA.getCode())){ - - String adjustRatio = wxRentContract.getAdjustRatio(); - JSONArray array = JSONArray.parseArray(adjustRatio); - List integers = new ArrayList<>(); - if(array != null && array.size() > 0){ - for (int i=0;i 0){ - priceArrs = new String[array.size()]; - size = array.size(); - for (int i=0;i(); - } - - int month = 12; -// int divide = lease / month; -// int mod = lease % month; -// int[] leaseArr = new int[size]; -// for (int i = 0; i < divide; i++) { -// leaseArr[i] = month; -// } -// if (mod > 0) { -// leaseArr[divide] = mod; -// } - - int billcount = 0; - List resultList = new ArrayList<>(); - - List yearList = new ArrayList<>(); - for (int i = 0; i < size; i++) { - Calendar instance = Calendar.getInstance(); - Date startDate; - //自然月 - if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ - if(i == 0){ //第一期 - startDate = rentalStartDate; - }else{ - instance.setTime(rentalStartDate); - instance.add(Calendar.MONTH, month * i); - startDate = DateUtils.getFirstDayForCurrMonth(instance.getTime()); - } - }else{ - instance.setTime(rentalStartDate); - instance.add(Calendar.MONTH, month * i); - startDate = instance.getTime(); - } - yearList.add(startDate); - } - - String shopInfoStr = getShopInfoStr(wxRentContract); - Map resultMap = buildRent(receivePeriod, priceArrs,null,null, yearList, Calendar.MONTH, wxRentContract, user, billcount, isPreview, shopInfoStr,saveDb); - List billRentList = (List)resultMap.get("billList"); - resultList.addAll(billRentList); - return resultList; - } - - public String getShopInfoStr(WxRentContract wxRentContract){ - String shopInfoStr = null; -// if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { - String rentInfo = wxRentContract.getRentInfo(); - JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); - int rentSize = rentInfoArray.size(); - Map shopInfoMap = new HashMap<>(rentSize); - for (int j = 0; j < rentSize; j++) { - JSONObject rentInfoObject = rentInfoArray.getJSONObject(j); - shopInfoMap.put(rentInfoObject.getString("shopNumber"), rentInfoObject.getString("buildArea")); - } - shopInfoStr = JSONObject.toJSONString(shopInfoMap); -// } - return shopInfoStr; - } - - private String getRentPriceInfo(WxRentContract wxRentContract, BigDecimal contractNeedPay){ - if(contractNeedPay.compareTo(new BigDecimal(0)) == 0){ - return null; - } - BigDecimal rentPrice = new BigDecimal(0), siteMoney = new BigDecimal(0), facilityMoney = new BigDecimal(0), administratorMoney = new BigDecimal(0),managementMoney = new BigDecimal(0); - if(!wxRentContract.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode()) && - !wxRentContract.getType().equals(EnumRentContractType.RENT_BY_COUNT.getCode()) - && !wxRentContract.getType().equals(EnumRentContractType.RENT_BY_CUSTOMIZE.getCode())){ - if(wxRentContract.getRentInputWay().equals(EnumRentContractRentInputWay.PART.getCode())){ - String rentInfo = wxRentContract.getRentInfo(); - JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); - String[] priceList = WxRentContractHelper.computeRentPriceByShop(wxRentContract).get(0); - BigDecimal sum = new BigDecimal(0); - for (int i = 0 ; i < priceList.length ; i++) { - sum = sum.add(new BigDecimal(priceList[i])); - } - int size = rentInfoArray.size(); - for (int i = 0;i < size;i++) { - BigDecimal a=new BigDecimal(0),b=new BigDecimal(0),c=new BigDecimal(0),d=new BigDecimal(0),e=new BigDecimal(0); - JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); - - String rentPrice1 = rentInfoObject.getString("rentPrice"); - if(StringUtils.isNotBlank(rentPrice1)){ - a = new BigDecimal(rentPrice1); - } - JSONObject otherRentPriceInfo = rentInfoObject.getJSONObject("otherRentPriceInfo"); - if(otherRentPriceInfo != null ){ - - //场地费 - String siteMoney1 = otherRentPriceInfo.getString("siteMoney"); - if(StringUtils.isNotBlank(siteMoney1)){ - b = new BigDecimal(siteMoney1); - } - //设备费 - String facilityMoney1 = otherRentPriceInfo.getString("facilityMoney"); - if(StringUtils.isNotBlank(facilityMoney1)){ - c = new BigDecimal(facilityMoney1); - } - //商业管理费 - String administratorMoney1 = otherRentPriceInfo.getString("administratorMoney"); - if(StringUtils.isNotBlank(administratorMoney1)){ - d = new BigDecimal(administratorMoney1); - } - - //营业管理费 - String managementMoney1 = otherRentPriceInfo.getString("managementMoney"); - if(StringUtils.isNotBlank(managementMoney1)){ - e = new BigDecimal(managementMoney1); - } - } - - rentPrice =rentPrice.add(contractNeedPay.multiply(new BigDecimal(priceList[i])).divide(sum,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP) - .multiply(a).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP)); - siteMoney =siteMoney.add(contractNeedPay.multiply(new BigDecimal(priceList[i])).divide(sum,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP) - .multiply(b).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP)); - facilityMoney =facilityMoney.add(contractNeedPay.multiply(new BigDecimal(priceList[i])).divide(sum,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP) - .multiply(c).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP)); - administratorMoney =administratorMoney.add(contractNeedPay.multiply(new BigDecimal(priceList[i])).divide(sum,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP) - .multiply(d).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP)); - managementMoney =managementMoney.add(contractNeedPay.multiply(new BigDecimal(priceList[i])).divide(sum,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP) - .multiply(e).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP)); - } - - }else{ - BigDecimal a=new BigDecimal(0),b=new BigDecimal(0),c=new BigDecimal(0),d=new BigDecimal(0),e=new BigDecimal(0); - String rentPrice1 = wxRentContract.getRentPrice(); - if(StringUtils.isNotBlank(rentPrice1)){ - //a = new BigDecimal(rentPrice1).divide(new BigDecimal(100)); - a = new BigDecimal(rentPrice1); - } - String otherRentPriceInfo1 = wxRentContract.getOtherRentPriceInfo(); - if(StringUtils.isNotBlank(otherRentPriceInfo1)){ - - JSONObject jsonObject = JSONObject.parseObject(otherRentPriceInfo1); - - String siteMoney1 = jsonObject.getString("siteMoney"); - if(StringUtils.isNotBlank(siteMoney1)){ - b = new BigDecimal(siteMoney1); - } - String facilityMoney1 = jsonObject.getString("facilityMoney"); - if(StringUtils.isNotBlank(facilityMoney1)){ - c = new BigDecimal(facilityMoney1); - } - String administratorMoney1 = jsonObject.getString("administratorMoney"); - if(StringUtils.isNotBlank(administratorMoney1)){ - d = new BigDecimal(administratorMoney1); - } - - String managementMoney1 = jsonObject.getString("managementMoney"); - if(StringUtils.isNotBlank(managementMoney1)){ - e = new BigDecimal(managementMoney1); - } - } - rentPrice = contractNeedPay.multiply(a).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); - siteMoney = contractNeedPay.multiply(b).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); - facilityMoney = contractNeedPay.multiply(c).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); - administratorMoney = contractNeedPay.multiply(d).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); - managementMoney = contractNeedPay.multiply(e).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); - } - }else{ - rentPrice = contractNeedPay; - } - - - Map resultMap = new HashedMap(); - resultMap.put("rentPrice",rentPrice.toString()); - resultMap.put("siteMoney",siteMoney.toString()); - resultMap.put("facilityMoney",facilityMoney.toString()); - resultMap.put("administratorMoney",administratorMoney.toString()); - resultMap.put("managementMoney",managementMoney.toString()); - return JSON.toJSONString(resultMap); - } - - - private static Date getCurrentYearRentDate(Date yearEndDate,Date rentDate){ - Calendar calendar = Calendar.getInstance(); - calendar.setTime(yearEndDate); - - Calendar rentCalendar = Calendar.getInstance(); - rentCalendar.setTime(rentDate); - - calendar.set(Calendar.DAY_OF_MONTH,rentCalendar.get(Calendar.DAY_OF_MONTH)); - calendar.set(Calendar.MONTH, rentCalendar.get(Calendar.MONTH)); - return calendar.getTime(); - } - - public Map buildRent(int receivePeriod, String[] priceArrs,String[] bussinessManagerPriceArrs,String[] operationManagerPriceArrs, List yearList, int dayType, WxRentContract wxRentContract, MallUserInfo user, int billcount, Integer isPreview, String shopInfoStr,boolean saveDb) { - WxPayAccountBill wxPayAccountBill = wxPayAccountBillService.getByTenantInfo(wxRentContract); - SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); - Map resultMap = new HashedMap(); - List resultList = new ArrayList<>(); - List manageList = new ArrayList(); - final IdWorker idWorker = IdWorker.get(); - - Date endDate = null;//每年的截止日期 - 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{ - //预账单编辑账期,生成金额 - 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)); - billTimeVoList.add(billTimeVo); - } - } - - int index = 0; - for (int i = 0; i < billTimeVoList.size(); i++) { - BillTimeVo billTimeVo = billTimeVoList.get(i); - //计算金额 - String needpay = "0"; - //商业管理费 - String bussinessManageFeeNeedpay = "0"; - //营业管理费 - String operatingManageFeeNeedpay = "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) )) { - //logger.info("=====billTimeVo.getStartDate():"+sd.format(billTimeVo.getStartDate())+" endDate:"+sd.format(endDate)); - - index++; - //如果是计算账单金额&cross 拆分日期进行计算 - if(billTimeVo.getEndDate().after(endDate)) { - String needpayFront = "0"; - String needpayAfter = "0"; - - //商业管理费 - String bussinessManageFeeNeedpayFront = "0"; - String bussinessManageFeeNeedpayAfter = "0"; - - //营业管理费 - String operatingManageFeeNeedpayFront = "0"; - String operatingManageFeeNeedpayAfter = "0"; - - //同一天,算一天 - if(sd.format(billTimeVo.getStartDate()).equals(sd.format(billTimeVo.getEndDate()))){ - needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract,priceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); - if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) { - bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract,bussinessManagerPriceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); - } - if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { - operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract,operationManagerPriceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); - } - }else{ - if(billTimeVo.getStartDate().before(endDate)){ - if (EnumRentContractType.RENT_BY_JOINT.getCode().equals(wxRentContract.getType()) && EnumMissTimeType.PERIOD.getCode().equals(wxRentContract.getBusDiscountTime())) { - //设置跳点率为年周期 price不变 - needpayFront = priceArrs[index - 1]; - if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) { - bussinessManageFeeNeedpayFront = bussinessManagerPriceArrs[index - 1]; - } - if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { - operatingManageFeeNeedpayFront = operationManagerPriceArrs[index - 1]; - } - }else { - needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); - needpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); - if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) { - bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); - bussinessManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); - } - if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { - operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); - operatingManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); - } - } - }else{ - //如果是按自然月,则这一年和下一年交叉部分需要重新计算 - if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) { - Date currentYearRentDate = getCurrentYearRentDate(endDate,wxRentContract.getRentalStartDate()); - needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index - 1],endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); - needpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index],currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); - if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) { - bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index - 1],endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); - bussinessManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index],currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); - } - if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { - operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index - 1],endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); - operatingManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index],currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); - } - }else { - //按账单日 - needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod,false,false); - if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) { - bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod,false,false); - } - if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { - operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod,false,false); - } - } - } - } - needpay = new BigDecimal(needpayFront).add(new BigDecimal(needpayAfter)).toPlainString(); - bussinessManageFeeNeedpay = new BigDecimal(bussinessManageFeeNeedpayFront).add(new BigDecimal(bussinessManageFeeNeedpayAfter)).toPlainString(); - operatingManageFeeNeedpay = new BigDecimal(operatingManageFeeNeedpayFront).add(new BigDecimal(operatingManageFeeNeedpayAfter)).toPlainString(); - flag = true; - } - if(index >= yearList.size()-1){ - endDate = null; - }else{ - endDate = yearList.get(index+1);//price index 0开始,year.end 从第二年开始 - //logger.info("==========cross:"+sd.format(endDate)); - } - } - } - } - } - - //计算金额 - if(!flag){ - needpay = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index],billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); - if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0 ) { - bussinessManageFeeNeedpay = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index],billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); - } - if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { - operatingManageFeeNeedpay = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index],billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); - } - } - - WxBillRent wxBillRent = new WxBillRent(); - wxBillRent.setIsPreview(isPreview); - wxBillRent.setId(idWorker.nextId()); - wxBillRent.setRentContractId(wxRentContract.getId()); - wxBillRent.setPay("0"); - wxBillRent.setStarttime(billTimeVo.getStartDate()); - wxBillRent.setEndtime(billTimeVo.getEndDate()); - wxBillRent.setReceiveDate(billTimeVo.getReceiveDate()); - - wxBillRent.setContractNeedPay(needpay); - wxBillRent.setRentPriceInfo(getRentPriceInfo(wxRentContract,new BigDecimal(needpay))); - wxBillRent.setNeedPay(needpay); - //wxBillRent.setOwe(needpay); - wxBillRent.setReceivePay(needpay); - //商业管理费 - wxBillRent.setBussinessManageFeeNeedPay(bussinessManageFeeNeedpay); - //运营管理费 - wxBillRent.setOperatingManageFeeNeedPay(operatingManageFeeNeedpay); - //截止收租日在当前时间之前 - Date date = new Date(); - //setExpiredDay(wxBillRent,dayType,receivePeriod); - wxBillRent.setRevenue("0"); - wxBillRent.updateTenantInfo(wxRentContract); - wxBillRent.setMerchantId(wxRentContract.getMerchantId()); - wxBillRent.setUserId(user.getId()); - if (null != wxRentContract.shopIdsByRentInfo() && wxRentContract.shopIdsByRentInfo().size() == 1) { - wxBillRent.setShopId(wxRentContract.shopIdsByRentInfo().get(0)); - } - wxBillRent.setCreatetime(date); - wxBillRent.setCreateBy(user.getId()); - wxBillRent.setCreateByName(user.getName()); - wxBillRent.setUpdatetime(date); - wxBillRent.setUpdateBy(user.getId()); +// if (record.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { + String rentInfo = record.getRentInfo(); + JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); + int size = rentInfoArray.size(); + if (size == 0) { + return new ResultData(ErrorCode.SHOP_NOT_SELECTED); + } + //查询rent_info 包括 shopId + String shopName = ""; + for (int i = 0; i < size; i++) { + JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); + WxRentContract wxRentContractQuery = new WxRentContract(); + wxRentContractQuery.updateTenantInfo(record); + Long shopId = rentInfoObject.getLong("id"); + String shopNumber = rentInfoObject.getString("shopNumber"); + if (shopId == null) { + return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND.getCode(), "店铺 " + shopNumber + " 已删除"); + } + wxRentContractQuery.setId(record.getId()); + //int count = wxRentContractMapper.selectRentContractCountByShopId(wxRentContractQuery.getTenantId(),wxRentContractQuery.getParentTenantId(),shopId,wxRentContractQuery.getId()); + //if (count > 0) { + // return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + shopNumber + " 已出租"); + //} +// if (record.getMerchantId() != null) { +// WxMerchantShop wxMerchantShop = new WxMerchantShop(); +// wxMerchantShop.setShopId(shopId); +// wxMerchantShop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); +// List wxMerchantShopList = wxMerchantShopMapper.findList(wxMerchantShop); +// long total = wxMerchantShopList.parallelStream(). +// filter(ms -> !ms.getMerchantId().equals(record.getMerchantId())).count(); +// if (total > 0) { +// return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + shopNumber + " 已出租"); +// } +// } else { +// WxShop wxShop = wxShopMapper.selectById(shopId); +// if (wxShop == null) { +// return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND.getCode(), "店铺 " + shopNumber + " 已删除"); +// } +//// if (wxShop.getStatus().equals(EnumShopStatus.RENT.getCode())) { +//// return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + wxShop.getShopNumber() + " 已出租"); +//// } +// } + if (!shopList.contains(shopId)) { + shopList.add(shopId); + shopName = shopName +","+shopNumber; + } + } +// } else { +// WxRentContract wxRentContractQuery = new WxRentContract(); +// wxRentContractQuery.updateTenantInfo(record); +// wxRentContractQuery.setShopId(record.getShopId()); +//// long count = wxRentContractMapper.queryRentContractData(wxRentContract).stream(). +//// filter(rc -> rc.get("status").equals(EnumRentContractStatus.READY_FOR_PAING.getCode()) +//// || rc.get("status").equals(EnumRentContractStatus.PAING.getCode()) +//// || rc.get("status").equals(EnumRentContractStatus.CONTRACT_END_SOON.getCode())).count(); +// long count = wxRentContractMapper.queryRentContractData(wxRentContract).stream(). +// filter(rc -> rc.get("status").equals(EnumRentContractStatus.READY_FOR_PAING.getCode()) +// || rc.get("status").equals(EnumRentContractStatus.PAING.getCode())).count(); +// if (count > 0) { +// return new ResultData(ErrorCode.RENT_CONTRACT_WITH_SHOP_IS_FOUND); +// } +// } + + try { + Date tempDate = record.getRentalStartDate(); + record.setRentalStartDate(oldRentStartDate); + record.setShopName(shopName); + if (writeFinal) { + record.setStatus(EnumRentContractStatus.DRAFT.getCode()); + }else { + record.setStatus(wxRentContract.getStatus()); + } + record.setApplyStatus(wxRentContract.getApplyStatus()); + if (StringUtils.isBlank(record.getOperatingManagementFee())){ + record.setOperatingManagementFee(null); + } + if (StringUtils.isBlank(record.getBussinessManagementFee())){ + record.setBussinessManagementFee(null); + } + wxRentContractMapper.updateById(record); + record.setRentalStartDate(tempDate); + } catch (Exception e) { + logger.error("更新租赁合同信息失败,e:" + e.getMessage()); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); + } + //重新查一次 + wxRentContract = wxRentContractMapper.selectById(record.getId()); + return new ResultData(Result.SUCCESS, "保存租赁合同信息成功", wxRentContract); + } + + + @Transactional(rollbackFor = {Exception.class}) + @Override + public void buildDeposit( MallUserInfo user,Long rentContractId) { + WxRentContract wxRentContract = wxRentContractMapper.selectById(rentContractId); + if (wxRentContract != null && StringUtils.isNotBlank(wxRentContract.getDeposit()) + && new BigDecimal(wxRentContract.getDeposit()).compareTo(new BigDecimal(0)) > 0 ) { + + WxRentContractDepositType dt = new WxRentContractDepositType(); + dt.updateTenantInfo(wxRentContract); + Map typeMap = findDepositTypesMap(dt); + + final IdWorker idWorker = IdWorker.get(); + WxBillDeposit wxBillDeposit = new WxBillDeposit(); + wxBillDeposit.setId(idWorker.nextId()); + wxBillDeposit.setRentContractId(wxRentContract.getId()); + wxBillDeposit.setContractDepoistDetail(wxRentContract.getDepositDetail(typeMap)); + wxBillDeposit.setPay("0"); + String needpay = wxRentContract.getDeposit(); + wxBillDeposit.setReceivePay(needpay); + wxBillDeposit.setNeedPay(needpay); + //wxBillDeposit.setOwe(needpay); + //找到计租方式 + int dayType = wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode()) ? Calendar.DAY_OF_MONTH : Calendar.MONTH; + + Date date = new Date(); + Calendar instance = Calendar.getInstance(); + instance.setTime(wxRentContract.getRentalStartDate()); + instance.add(Calendar.DAY_OF_MONTH, -1); + Date time = instance.getTime(); + wxBillDeposit.setReceiveDate(time); + + //账单开始时间 + instance.clear(); + instance.setTime(wxBillDeposit.getReceiveDate()); + instance.add(Calendar.DAY_OF_MONTH, 1); + wxBillDeposit.setStarttime(instance.getTime()); + //账单结束时间 + instance.clear(); + instance.setTime(wxBillDeposit.getReceiveDate()); + instance.add(dayType, wxRentContract.getLease()); + wxBillDeposit.setEndtime(instance.getTime()); + wxBillDeposit.setStatus(EnumBillStatus.WAIT_PAY.getCode()); + wxBillDeposit.setExpiredDay(0L); + wxBillDeposit.setReceiveDate(time); + wxBillDeposit.updateTenantInfo(wxRentContract); + wxBillDeposit.setIsDel(0); + wxBillDeposit.setMerchantId(wxRentContract.getMerchantId()); + wxBillDeposit.setUserId(user.getId()); + if (wxRentContract.shopIdsByRentInfo().size()==1) { + wxBillDeposit.setShopId(wxRentContract.shopIdsByRentInfo().get(0)); + } + wxBillDeposit.setCreatetime(date); + wxBillDeposit.setCreateBy(user.getId()); + wxBillDeposit.setCreateByName(user.getName()); + wxBillDeposit.setUpdatetime(date); + wxBillDeposit.setUpdateBy(user.getId()); + wxBillDeposit.setUpdateByName(user.getName()); + wxBillDeposit.setIsDel(EnumDelStatus.NOT_DEL.getCode()); + wxBillDeposit.setRentShopType(wxRentContract.getRentShopType()); + if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { + String rentInfo = wxRentContract.getRentInfo(); + if (rentInfo != null) { + JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); + Map shopInfo = new HashMap<>(); + for (int i = 0, size = rentInfoArray.size(); i < size; i++) { + JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); + shopInfo.put(rentInfoObject.getString("shopNumber"), rentInfoObject.get("deposit")); + } + wxBillDeposit.setShopInfo(JSONObject.toJSONString(shopInfo)); + } + } + try { + wxBillDepositMapper.insert(wxBillDeposit); + } catch (Exception e) { + logger.error("添加押金账单失败,e:" + e.getMessage()); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); + } + } + } + + @Override + public Object getMerchants(WxRentContract wxRentContract) { + List rentContractList = wxRentContractMapper.getMerchants(wxRentContract); + return rentContractList; + } + +// @Override +// public void updateInvalidContract(Long rentContractId) { +// WxRentContract wxRentContract = wxRentContractMapper.selectById(rentContractId); +// if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { +// String rentInfo = wxRentContract.getRentInfo(); +// JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); +// WxRentContract record = new WxRentContract(); +// for (int i = 0, size = rentInfoArray.size(); i < size; i++) { +// JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); +// Long shopId = rentInfoObject.getLong("shopId"); +// record.setShopId(shopId); +// record.updateTenantInfo(wxRentContract); +// record.setStatus(EnumRentContractStatus.INVALID.getCode()); +// wxRentContractMapper.updateInvalidContract(record); +// List rentContractList = wxRentContractMapper.selectRentContractByShopId(record); +// for (WxRentContract updateContract : rentContractList) { +// updateInvalidStatus(updateContract); +// } +// } +// } else { +// WxRentContract record = new WxRentContract(); +// record.updateTenantInfo(wxRentContract); +// record.setRentShopType(wxRentContract.getRentShopType()); +// record.setStatus(EnumRentContractStatus.INVALID.getCode()); +// wxRentContractMapper.updateRentInvalidStatus(record); +// List rentContractList = wxRentContractMapper.selectList(new QueryWrapper(record)); +// for (WxRentContract updateContract : rentContractList) { +// updateInvalidStatus(updateContract); +// } +// } +// +// } + + @Override + public ResultData hasRentStatus(WxRentContract record) { + String rentInfo = record.getRentInfo(); + if (StringUtils.isEmpty(rentInfo)) { + return new ResultData(ErrorCode.SHOP_NOT_SELECTED); + } + String[] split = rentInfo.split(","); + int size = split.length; + //查询rent_info 包括 shopId + for (int i = 0; i < size; i++) { + String shopId = split[i]; + WxShop wxShop = wxShopMapper.selectById(shopId); + WxRentContract wxRentContractQuery = new WxRentContract(); + wxRentContractQuery.updateTenantInfo(record); + String shopNumber = wxShop.getShopNumber(); + if (shopId == null) { + return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND.getCode(), "店铺 " + shopNumber + " 已删除"); + } + //wxRentContractQuery.setShopId(Long.valueOf(shopId)); + int count = wxRentContractMapper.selectRentContractCountByShopId(wxRentContractQuery.getTenantId(),wxRentContractQuery.getParentTenantId(),Long.valueOf(shopId),wxRentContractQuery.getId()); + if (count > 0) { + return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + shopNumber + " 已出租"); + } + } + return new ResultData(Result.SUCCESS, "操作成功"); + } + + @Override + public ResultData hasContractNumber(WxRentContract wxRentContract) { + int count = wxRentContractMapper.hasContractNumber(wxRentContract); + return new ResultData(Result.SUCCESS, "操作成功", count > 0 ? true : false); + } + + public void updateInvalidStatus(WxRentContract record) { + Long id = record.getId(); + //审核流程中止 + try { + // 修改合同审核状态 + WxRentContract rentContract = record; + rentContract.setId(id); + rentContract.setApplyStatus(EnumRentContractAppStatus.CANCLE.getCode()); + updateApplyStatus(rentContract); + + //修改flowRecord + WxFlowRecord fr = new WxFlowRecord(); + fr.setBusinessId(String.valueOf(id)); + fr.setCurrStatus(EnumRentContractAppStatus.CANCLE.getCode()); + wxFlowRecordMapper.updateCurrStatus(fr); + + logger.info("合同id:{},开始停止...", id); + //结束审批流 by luozukai + WxFlowModel flowModel = wxFlowService.getModelByType(EnumFlowKey.NEW_RENT_CONTRACT.getCode().intValue(),record); + WxFlowModel flowModelPoint = wxFlowService.getModelByType(EnumFlowKey.NEW_SHOP_CONTRACT.getCode().intValue(),record); + + WxFlowModel flowModel_pro = wxFlowService.getModelByType(EnumFlowKey.NEW_PRO_CONTRACT.getCode().intValue(),record); + WxFlowModel flowModelPoint_pro = wxFlowService.getModelByType(EnumFlowKey.NEW_PRO_POINT_CONTRACT.getCode().intValue(),record); + + WxFlowModel flowModel_rent = wxFlowService.getModelByType(EnumFlowKey.NNEW_RENT_CONTRACT.getCode().intValue(),record); + WxFlowModel flowModelPoint_rent = wxFlowService.getModelByType(EnumFlowKey.NEW_RENT_POINT_CONTRACT.getCode().intValue(),record); + + List keyList = new ArrayList<>(); + if(flowModel != null){ + keyList.add(flowModel.getFlowId()); + } + if(flowModelPoint != null){ + keyList.add(flowModelPoint.getFlowId()); + } + if(flowModel_pro != null){ + keyList.add(flowModel_pro.getFlowId()); + } + if(flowModelPoint_pro != null){ + keyList.add(flowModelPoint_pro.getFlowId()); + } + if(flowModel_rent != null){ + keyList.add(flowModel_rent.getFlowId()); + } + if(flowModelPoint_rent != null){ + keyList.add(flowModelPoint_rent.getFlowId()); + } + keyList.add(EnumFlowKey.CONTRACT.getMessage()); + List tasks = taskService.createTaskQuery() + .processDefinitionKeyIn(keyList) + .processVariableValueEquals("businessId", id+"").list(); + if (!CollectionUtils.isEmpty(tasks)) { + for (Task task : tasks) { + logger.info("合同id:{},taskid:{}", id, task.getId()); + runtimeService.deleteProcessInstance(task.getProcessInstanceId(), "合同作废"); + + // 保存审批历史入 + MallUserInfo mallUserInfo = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute("userSession"); + WxFlowRecord updateRecord = new WxFlowRecord(); + updateRecord.setBusinessId(String.valueOf(id)); + updateRecord.setStatus(EnumFlowRecordStatus.CANCLE.getCode()); + updateRecord.setBusinessType(1); + updateRecord.setUserId(mallUserInfo.getId()); + updateRecord.setProcessInstanceId(task.getProcessInstanceId()); + wxFlowRecordService.saveOrUpdate(updateRecord); + } + } + + } catch (Exception e) { + logger.error("deleteProcessInstance error", e); + } + } + + @Override + @Transactional(rollbackFor = {Exception.class}) + public List buildRent(MallUserInfo user,WxRentContract wxRentContract,Integer isPreview,boolean saveDb) { + List rentList = new ArrayList<>(); + if (wxRentContract != null) { + int receivePeriod = wxRentContract.getReceivePeriod().intValue(); + Integer lease = wxRentContract.getLease(); + Date rentalStartDate = wxRentContract.getRentalStartDate(); + String price = wxRentContract.getPrice(); + if(EnumContractOperationType.JINMAO.getCode().equals(wxRentContract.getOperationType())){ + Date startDate = wxRentContract.getStartDate(); + rentList = buildRentJinmao(user, wxRentContract, receivePeriod, lease, startDate, price, isPreview,saveDb); + }else{ + rentList = buildRentMonth(user, wxRentContract, receivePeriod, lease, rentalStartDate, price, isPreview,saveDb); + } + } + for (int i = 0; i < rentList.size(); i++) { + rentList.get(i).setPeriod(i+1); + } + return rentList; + } + + + + public List buildRentMonth(MallUserInfo user, WxRentContract wxRentContract, int receivePeriod, Integer lease, Date rentalStartDate, String price, Integer isPreview, boolean saveDb) { + int years = 0; + //计算租金每年的计费基数 + String[] priceArrs = WxRentContractHelper.calcuteRentPrice(wxRentContract); + //计算商业管理费 + String[] bussinessManagerPriceArrs = WxRentContractHelper.calcuteBussinessManagementFee(wxRentContract); + //计算运营管理费 + String[] operationManagerPriceArrs = WxRentContractHelper.calcuteOperatingManagementFee(wxRentContract); + int month = 12; + int billcount = 0; + List resultList = new ArrayList<>(); + years = priceArrs.length; + List yearList = new ArrayList<>(); + for (int i = 0; i < years; i++) { + Calendar instance = Calendar.getInstance(); + Date startDate; + //自然月 + if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ + if(i == 0){ //第一期 + startDate = rentalStartDate; + }else{ + instance.setTime(rentalStartDate); + instance.add(Calendar.MONTH, month * i); + startDate = DateUtils.getFirstDayForCurrMonth(instance.getTime()); + } + }else{ + instance.setTime(rentalStartDate); + instance.add(Calendar.MONTH, month * i); + startDate = instance.getTime(); + } + yearList.add(startDate); + } + + String shopInfoStr = getShopInfoStr(wxRentContract); + Map resultMap = buildRent(receivePeriod, priceArrs,bussinessManagerPriceArrs,operationManagerPriceArrs, yearList, wxRentContract.getReceivePeriodUnit(), wxRentContract, user, billcount, isPreview, shopInfoStr,saveDb); + List billRentList = (List)resultMap.get("billList"); + resultList.addAll(billRentList); + return resultList; + } + + public List buildRentJinmao(MallUserInfo user, WxRentContract wxRentContract, int receivePeriod, Integer lease, Date rentalStartDate, String price, Integer isPreview, boolean saveDb) { + int size = 0; + String[] priceArrs = null; + if (wxRentContract.getType().equals(EnumRentContractType.RENT_BY_AREA.getCode())){ + + String adjustRatio = wxRentContract.getAdjustRatio(); + JSONArray array = JSONArray.parseArray(adjustRatio); + List integers = new ArrayList<>(); + if(array != null && array.size() > 0){ + for (int i=0;i 0){ + priceArrs = new String[array.size()]; + size = array.size(); + for (int i=0;i(); + } + + int month = 12; +// int divide = lease / month; +// int mod = lease % month; +// int[] leaseArr = new int[size]; +// for (int i = 0; i < divide; i++) { +// leaseArr[i] = month; +// } +// if (mod > 0) { +// leaseArr[divide] = mod; +// } + + int billcount = 0; + List resultList = new ArrayList<>(); + + List yearList = new ArrayList<>(); + for (int i = 0; i < size; i++) { + Calendar instance = Calendar.getInstance(); + Date startDate; + //自然月 + if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ + if(i == 0){ //第一期 + startDate = rentalStartDate; + }else{ + instance.setTime(rentalStartDate); + instance.add(Calendar.MONTH, month * i); + startDate = DateUtils.getFirstDayForCurrMonth(instance.getTime()); + } + }else{ + instance.setTime(rentalStartDate); + instance.add(Calendar.MONTH, month * i); + startDate = instance.getTime(); + } + yearList.add(startDate); + } + + String shopInfoStr = getShopInfoStr(wxRentContract); + Map resultMap = buildRent(receivePeriod, priceArrs,null,null, yearList, Calendar.MONTH, wxRentContract, user, billcount, isPreview, shopInfoStr,saveDb); + List billRentList = (List)resultMap.get("billList"); + resultList.addAll(billRentList); + return resultList; + } + + public String getShopInfoStr(WxRentContract wxRentContract){ + String shopInfoStr = null; +// if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { + String rentInfo = wxRentContract.getRentInfo(); + JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); + int rentSize = rentInfoArray.size(); + Map shopInfoMap = new HashMap<>(rentSize); + for (int j = 0; j < rentSize; j++) { + JSONObject rentInfoObject = rentInfoArray.getJSONObject(j); + shopInfoMap.put(rentInfoObject.getString("shopNumber"), rentInfoObject.getString("buildArea")); + } + shopInfoStr = JSONObject.toJSONString(shopInfoMap); +// } + return shopInfoStr; + } + + private String getRentPriceInfo(WxRentContract wxRentContract, BigDecimal contractNeedPay){ + if(contractNeedPay.compareTo(new BigDecimal(0)) == 0){ + return null; + } + BigDecimal rentPrice = new BigDecimal(0), siteMoney = new BigDecimal(0), facilityMoney = new BigDecimal(0), administratorMoney = new BigDecimal(0),managementMoney = new BigDecimal(0); + if(!wxRentContract.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode()) && + !wxRentContract.getType().equals(EnumRentContractType.RENT_BY_COUNT.getCode()) + && !wxRentContract.getType().equals(EnumRentContractType.RENT_BY_CUSTOMIZE.getCode())){ + if(wxRentContract.getRentInputWay().equals(EnumRentContractRentInputWay.PART.getCode())){ + String rentInfo = wxRentContract.getRentInfo(); + JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); + String[] priceList = WxRentContractHelper.computeRentPriceByShop(wxRentContract).get(0); + BigDecimal sum = new BigDecimal(0); + for (int i = 0 ; i < priceList.length ; i++) { + sum = sum.add(new BigDecimal(priceList[i])); + } + int size = rentInfoArray.size(); + for (int i = 0;i < size;i++) { + BigDecimal a=new BigDecimal(0),b=new BigDecimal(0),c=new BigDecimal(0),d=new BigDecimal(0),e=new BigDecimal(0); + JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); + + String rentPrice1 = rentInfoObject.getString("rentPrice"); + if(StringUtils.isNotBlank(rentPrice1)){ + a = new BigDecimal(rentPrice1); + } + JSONObject otherRentPriceInfo = rentInfoObject.getJSONObject("otherRentPriceInfo"); + if(otherRentPriceInfo != null ){ + + //场地费 + String siteMoney1 = otherRentPriceInfo.getString("siteMoney"); + if(StringUtils.isNotBlank(siteMoney1)){ + b = new BigDecimal(siteMoney1); + } + //设备费 + String facilityMoney1 = otherRentPriceInfo.getString("facilityMoney"); + if(StringUtils.isNotBlank(facilityMoney1)){ + c = new BigDecimal(facilityMoney1); + } + //商业管理费 + String administratorMoney1 = otherRentPriceInfo.getString("administratorMoney"); + if(StringUtils.isNotBlank(administratorMoney1)){ + d = new BigDecimal(administratorMoney1); + } + + //营业管理费 + String managementMoney1 = otherRentPriceInfo.getString("managementMoney"); + if(StringUtils.isNotBlank(managementMoney1)){ + e = new BigDecimal(managementMoney1); + } + } + + rentPrice =rentPrice.add(contractNeedPay.multiply(new BigDecimal(priceList[i])).divide(sum,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP) + .multiply(a).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP)); + siteMoney =siteMoney.add(contractNeedPay.multiply(new BigDecimal(priceList[i])).divide(sum,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP) + .multiply(b).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP)); + facilityMoney =facilityMoney.add(contractNeedPay.multiply(new BigDecimal(priceList[i])).divide(sum,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP) + .multiply(c).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP)); + administratorMoney =administratorMoney.add(contractNeedPay.multiply(new BigDecimal(priceList[i])).divide(sum,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP) + .multiply(d).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP)); + managementMoney =managementMoney.add(contractNeedPay.multiply(new BigDecimal(priceList[i])).divide(sum,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP) + .multiply(e).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP)); + } + + }else{ + BigDecimal a=new BigDecimal(0),b=new BigDecimal(0),c=new BigDecimal(0),d=new BigDecimal(0),e=new BigDecimal(0); + String rentPrice1 = wxRentContract.getRentPrice(); + if(StringUtils.isNotBlank(rentPrice1)){ + //a = new BigDecimal(rentPrice1).divide(new BigDecimal(100)); + a = new BigDecimal(rentPrice1); + } + String otherRentPriceInfo1 = wxRentContract.getOtherRentPriceInfo(); + if(StringUtils.isNotBlank(otherRentPriceInfo1)){ + + JSONObject jsonObject = JSONObject.parseObject(otherRentPriceInfo1); + + String siteMoney1 = jsonObject.getString("siteMoney"); + if(StringUtils.isNotBlank(siteMoney1)){ + b = new BigDecimal(siteMoney1); + } + String facilityMoney1 = jsonObject.getString("facilityMoney"); + if(StringUtils.isNotBlank(facilityMoney1)){ + c = new BigDecimal(facilityMoney1); + } + String administratorMoney1 = jsonObject.getString("administratorMoney"); + if(StringUtils.isNotBlank(administratorMoney1)){ + d = new BigDecimal(administratorMoney1); + } + + String managementMoney1 = jsonObject.getString("managementMoney"); + if(StringUtils.isNotBlank(managementMoney1)){ + e = new BigDecimal(managementMoney1); + } + } + rentPrice = contractNeedPay.multiply(a).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); + siteMoney = contractNeedPay.multiply(b).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); + facilityMoney = contractNeedPay.multiply(c).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); + administratorMoney = contractNeedPay.multiply(d).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); + managementMoney = contractNeedPay.multiply(e).divide(a.add(b).add(c).add(d).add(e),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).setScale(wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); + } + }else{ + rentPrice = contractNeedPay; + } + + + Map resultMap = new HashedMap(); + resultMap.put("rentPrice",rentPrice.toString()); + resultMap.put("siteMoney",siteMoney.toString()); + resultMap.put("facilityMoney",facilityMoney.toString()); + resultMap.put("administratorMoney",administratorMoney.toString()); + resultMap.put("managementMoney",managementMoney.toString()); + return JSON.toJSONString(resultMap); + } + + + private static Date getCurrentYearRentDate(Date yearEndDate,Date rentDate){ + Calendar calendar = Calendar.getInstance(); + calendar.setTime(yearEndDate); + + Calendar rentCalendar = Calendar.getInstance(); + rentCalendar.setTime(rentDate); + + calendar.set(Calendar.DAY_OF_MONTH,rentCalendar.get(Calendar.DAY_OF_MONTH)); + calendar.set(Calendar.MONTH, rentCalendar.get(Calendar.MONTH)); + return calendar.getTime(); + } + + public Map buildRent(int receivePeriod, String[] priceArrs,String[] bussinessManagerPriceArrs,String[] operationManagerPriceArrs, List yearList, int dayType, WxRentContract wxRentContract, MallUserInfo user, int billcount, Integer isPreview, String shopInfoStr,boolean saveDb) { + WxPayAccountBill wxPayAccountBill = wxPayAccountBillService.getByTenantInfo(wxRentContract); + SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); + Map resultMap = new HashedMap(); + List resultList = new ArrayList<>(); + List manageList = new ArrayList(); + final IdWorker idWorker = IdWorker.get(); + + Date endDate = null;//每年的截止日期 + 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{ + //预账单编辑账期,生成金额 + 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)); + billTimeVoList.add(billTimeVo); + } + } + + int index = 0; + for (int i = 0; i < billTimeVoList.size(); i++) { + BillTimeVo billTimeVo = billTimeVoList.get(i); + //计算金额 + String needpay = "0"; + //商业管理费 + String bussinessManageFeeNeedpay = "0"; + //营业管理费 + String operatingManageFeeNeedpay = "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) )) { + //logger.info("=====billTimeVo.getStartDate():"+sd.format(billTimeVo.getStartDate())+" endDate:"+sd.format(endDate)); + + index++; + //如果是计算账单金额&cross 拆分日期进行计算 + if(billTimeVo.getEndDate().after(endDate)) { + String needpayFront = "0"; + String needpayAfter = "0"; + + //商业管理费 + String bussinessManageFeeNeedpayFront = "0"; + String bussinessManageFeeNeedpayAfter = "0"; + + //营业管理费 + String operatingManageFeeNeedpayFront = "0"; + String operatingManageFeeNeedpayAfter = "0"; + + //同一天,算一天 + if(sd.format(billTimeVo.getStartDate()).equals(sd.format(billTimeVo.getEndDate()))){ + needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract,priceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); + if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) { + bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract,bussinessManagerPriceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); + } + if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { + operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract,operationManagerPriceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); + } + }else{ + if(billTimeVo.getStartDate().before(endDate)){ + if (EnumRentContractType.RENT_BY_JOINT.getCode().equals(wxRentContract.getType()) && EnumMissTimeType.PERIOD.getCode().equals(wxRentContract.getBusDiscountTime())) { + //设置跳点率为年周期 price不变 + needpayFront = priceArrs[index - 1]; + if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) { + bussinessManageFeeNeedpayFront = bussinessManagerPriceArrs[index - 1]; + } + if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { + operatingManageFeeNeedpayFront = operationManagerPriceArrs[index - 1]; + } + }else { + needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); + needpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); + if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) { + bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); + bussinessManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); + } + if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { + operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); + operatingManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false); + } + } + }else{ + //如果是按自然月,则这一年和下一年交叉部分需要重新计算 + if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) { + Date currentYearRentDate = getCurrentYearRentDate(endDate,wxRentContract.getRentalStartDate()); + needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index - 1],endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); + needpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index],currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); + if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) { + bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index - 1],endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); + bussinessManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index],currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); + } + if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { + operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index - 1],endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); + operatingManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index],currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true); + } + }else { + //按账单日 + needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod,false,false); + if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) { + bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod,false,false); + } + if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { + operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod,false,false); + } + } + } + } + needpay = new BigDecimal(needpayFront).add(new BigDecimal(needpayAfter)).toPlainString(); + bussinessManageFeeNeedpay = new BigDecimal(bussinessManageFeeNeedpayFront).add(new BigDecimal(bussinessManageFeeNeedpayAfter)).toPlainString(); + operatingManageFeeNeedpay = new BigDecimal(operatingManageFeeNeedpayFront).add(new BigDecimal(operatingManageFeeNeedpayAfter)).toPlainString(); + flag = true; + } + if(index >= yearList.size()-1){ + endDate = null; + }else{ + endDate = yearList.get(index+1);//price index 0开始,year.end 从第二年开始 + //logger.info("==========cross:"+sd.format(endDate)); + } + } + } + } + } + + //计算金额 + if(!flag){ + needpay = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index],billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); + if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0 ) { + bussinessManageFeeNeedpay = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index],billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); + } + if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) { + operatingManageFeeNeedpay = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index],billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false); + } + } + + WxBillRent wxBillRent = new WxBillRent(); + wxBillRent.setIsPreview(isPreview); + wxBillRent.setId(idWorker.nextId()); + wxBillRent.setRentContractId(wxRentContract.getId()); + wxBillRent.setPay("0"); + wxBillRent.setStarttime(billTimeVo.getStartDate()); + wxBillRent.setEndtime(billTimeVo.getEndDate()); + wxBillRent.setReceiveDate(billTimeVo.getReceiveDate()); + + wxBillRent.setContractNeedPay(needpay); + wxBillRent.setRentPriceInfo(getRentPriceInfo(wxRentContract,new BigDecimal(needpay))); + wxBillRent.setNeedPay(needpay); + //wxBillRent.setOwe(needpay); + wxBillRent.setReceivePay(needpay); + //商业管理费 + wxBillRent.setBussinessManageFeeNeedPay(bussinessManageFeeNeedpay); + //运营管理费 + wxBillRent.setOperatingManageFeeNeedPay(operatingManageFeeNeedpay); + //截止收租日在当前时间之前 + Date date = new Date(); + //setExpiredDay(wxBillRent,dayType,receivePeriod); + wxBillRent.setRevenue("0"); + wxBillRent.updateTenantInfo(wxRentContract); + wxBillRent.setMerchantId(wxRentContract.getMerchantId()); + wxBillRent.setUserId(user.getId()); + if (null != wxRentContract.shopIdsByRentInfo() && wxRentContract.shopIdsByRentInfo().size() == 1) { + wxBillRent.setShopId(wxRentContract.shopIdsByRentInfo().get(0)); + } + wxBillRent.setCreatetime(date); + wxBillRent.setCreateBy(user.getId()); + wxBillRent.setCreateByName(user.getName()); + wxBillRent.setUpdatetime(date); + wxBillRent.setUpdateBy(user.getId()); wxBillRent.setUpdateByName(user.getName());; - wxBillRent.setIsDel(EnumDelStatus.NOT_DEL.getCode()); - wxBillRent.setRentShopType(wxRentContract.getRentShopType()); - wxBillRent.setPeriod(++billcount); - wxBillRent.setShopInfo(shopInfoStr); - wxBillRent.setLatePayRatio(0); - wxBillRent.calcuteTotalFee(wxRentContract.getDecimalSize()); - - //计算手续费 - BigDecimal servicePay = new BigDecimal(wxBillRent.getReceivePay()).multiply(new BigDecimal(wxPayAccountBill.getServiceChargeRate())) - .divide(new BigDecimal(10000), wxRentContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP); - wxBillRent.setServiceChargePay(servicePay.toPlainString()); - //wxBillRent.setOwe(new BigDecimal(wxBillRent.getReceivePay()).add(new BigDecimal(wxBillRent.getServiceChargePay())).toPlainString()); - //wxBillRent.setOwe(new BigDecimal(wxBillRent.getReceivePay()).toPlainString()); - resultList.add(wxBillRent); - - - //商业管理费账单 - if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0 && new BigDecimal(bussinessManageFeeNeedpay).compareTo(new BigDecimal(0)) > 0) { - manageList.add(setManageRent(wxRentContract.getDecimalSize(),wxBillRent,EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE,bussinessManageFeeNeedpay,wxPayAccountBill.getServiceChargeRate(),dayType,receivePeriod)); - } - //营业管理费账单 - if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0 && new BigDecimal(operatingManageFeeNeedpay).compareTo(new BigDecimal(0)) > 0 ) { - manageList.add(setManageRent(wxRentContract.getDecimalSize(),wxBillRent,EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE,operatingManageFeeNeedpay,wxPayAccountBill.getServiceChargeRate(),dayType,receivePeriod)); - } - } - - //批量插入账单 - if(saveDb) { - wxBillRentMapper.insertBills(wxRentContract.getTenantId(),resultList); - if (manageList.size() > 0 ) { - wxBillRentManageMapper.insertBills(wxRentContract.getTenantId(),manageList); - } - } - resultMap.put("billcount",billcount); - resultMap.put("billList",resultList); - return resultMap; - } - - - private WxBillRentManage setManageRent(Integer decimalSize,WxBillRent wxBillRent,EnumRentContractManageFeeType feeType,String needPay,Integer serviceChargeRate,int dayType,int receivePeriod) { - WxBillRentManage manage = new WxBillRentManage(); - manage.initByBillRent(wxBillRent); - final IdWorker idWorker = IdWorker.get(); - wxBillRent.setId(idWorker.nextId()); - manage.setManageFeeType(feeType.getCode()); - manage.setNeedPay(needPay); - manage.setReceivePay(needPay); - //manage.setOwe(needPay); - //setManageExpiredDay(manage,dayType,receivePeriod); - //计算手续费 - BigDecimal servicePay = new BigDecimal(needPay).multiply(new BigDecimal(serviceChargeRate)).divide(new BigDecimal(10000), decimalSize, BigDecimal.ROUND_HALF_UP); - manage.setServiceChargePay(servicePay.toPlainString()); - //manage.setOwe(new BigDecimal(needPay).add(new BigDecimal(manage.getServiceChargePay())).toPlainString()); - //manage.setOwe(new BigDecimal(needPay).toPlainString()); - return manage; - } - -// public void setExpiredDay(WxBillRent wxBillRent,int dayType, int receivePeriod){ -// //截止收租日在当前时间之前 -// Date date = new Date(); -// wxBillRent.setExpiredDay(0L); -// if (wxBillRent.getReceiveDate().before(date)) { -// long day = (date.getTime() - wxBillRent.getReceiveDate().getTime()) / (24 * 60 * 60 * 1000); -// wxBillRent.setStatus(EnumBillStatus.NOT_PAID.getCode()); -// if (day > 0) { -// wxBillRent.setExpiredDay(day); -// } -// } else {//截止收租日在当前时间之后 -// Calendar now = Calendar.getInstance(); -// now.add(dayType, receivePeriod); -// Date currenttime = now.getTime(); -// //当前日期加上周期后小于截止收租日就是没有到期,否则当前待缴 -// if (currenttime.before(wxBillRent.getReceiveDate())) { -// wxBillRent.setStatus(EnumBillStatus.NOT_EXPIRED.getCode()); -// } else { -// wxBillRent.setStatus(EnumBillStatus.WAIT_PAY.getCode()); -// } -// } -// } - -// public void setManageExpiredDay(WxBillRentManage wxBillRentManage,int dayType, int receivePeriod){ -// //截止收租日在当前时间之前 -// Date date = new Date(); -// wxBillRentManage.setExpiredDay(0L); -// if (wxBillRentManage.getReceiveDate().before(date)) { -// long day = (date.getTime() - wxBillRentManage.getReceiveDate().getTime()) / (24 * 60 * 60 * 1000); -// wxBillRentManage.setStatus(EnumBillStatus.NOT_PAID.getCode()); -// if (day > 0) { -// wxBillRentManage.setExpiredDay(day); -// } -// } else {//截止收租日在当前时间之后 -// Calendar now = Calendar.getInstance(); -// now.add(dayType, receivePeriod); -// Date currenttime = now.getTime(); -// //当前日期加上周期后小于截止收租日就是没有到期,否则当前待缴 -// if (currenttime.before(wxBillRentManage.getReceiveDate())) { -// wxBillRentManage.setStatus(EnumBillStatus.NOT_EXPIRED.getCode()); -// } else { -// wxBillRentManage.setStatus(EnumBillStatus.WAIT_PAY.getCode()); -// } -// } -// } - - @Transactional(rollbackFor = {Exception.class}) - @Override - public ResultData deleteById(String id) { - wxRentContractMapper.deleteById(id); - return new ResultData(Result.SUCCESS, "删除租赁合同信息成功"); - } - - @Override - public void download(HttpServletRequest request, HttpServletResponse response) { - String id = request.getParameter("id"); - WxRentContract wxRentContract = wxRentContractMapper.selectById(id); - String filesuffix = wxRentContract.getFilepath().substring(wxRentContract.getFilepath().lastIndexOf(".")); - String filename = UUID.randomUUID() + filesuffix; - String filepath = fmUploadDir; - String destPath = filepath + filename; - File dest = new File(destPath); - File pDest = dest.getParentFile(); - if (!pDest.exists()) { - pDest.mkdirs(); - } - try { - String exportFileName = wxRentContract.getFilename(); - DownFileUtil.downLoadFromUrl(wxRentContract.getFilepath(), filename, filepath); - DownFileUtil.downFile(destPath, exportFileName, response, request); - org.apache.commons.io.FileUtils.forceDelete(dest); - } catch (IOException e) { - logger.info("创建本地文件失败" + e.getMessage()); - } - } - -// @Transactional(rollbackFor = {Exception.class}) -// @Override -// public Object getRentContractStatusInfo(WxRentContract rentContract) { -// -// Map resultData = new HashMap(); -// //商铺信息 -// WxShop wxShop = new WxShop(); -// wxShop.updateTenantInfo(rentContract); -// wxShop.setType(rentContract.getRentShopType()); -// wxShop.setStatus(EnumShopStatus.RENT.getCode()); -// List rentedList = wxShopMapper.findList(wxShop); -// wxShop.setStatus(EnumShopStatus.NOT_RENT.getCode()); -// List unrentedList = wxShopMapper.findList(wxShop); -// -// 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); -// resultData.put("shopCountInfo", shopMap); -// -// //需要更新的状态 -// resultData.putAll(updateStatus(rentContract)); -// return resultData; -// } - - @Transactional(rollbackFor = {Exception.class}) - @Override - public ResultData endContract(WxRentContract wxRentContract,MallUserInfo userInfo) { - - WxRentContract contract = wxRentContractMapper.selectById(wxRentContract.getId()); - if (contract == null) { - return new ResultData(ErrorCode.RENT_CONTRACT_IS_NOT_FOUND); - } - contract.setStatus(EnumRentContractStatus.TERMINATE.getCode()); - contract.setUpdatetime(new Date()); - contract.setUpdateBy(userInfo.getId()); - contract.setEndContractTime(wxRentContract.getEndContractTime()); - wxRentContractMapper.updateById(contract); - - //终止租赁合同,同时终止物业合同 - if(EnumEndProperty.END_RENT_AND_PROPERTY.getCode().equals(wxRentContract.getEndProperty())){ -// WxPropertyContract wxPropertyContract = new WxPropertyContract(); -// wxPropertyContract.setRentContractId(wxRentContract.getId()); -// wxPropertyContract.setStatus(EnumRentContractStatus.TERMINATE.getCode()); -// wxPropertyContractMapper.updateStatusByRentContractId(wxPropertyContract); - WxPropertyContract wxPropertyContract = new WxPropertyContract(); - wxRentContract.updateTenantInfo(wxRentContract); - wxPropertyContract.setRentContractId(wxRentContract.getId()); - //终止有效的合同 - wxPropertyContract.setStatuss(EnumRentContractStatus.getValidStatus()); - wxPropertyContract.setUpdatetime(new Date()); - wxPropertyContract.setUpdateBy(userInfo.getId()); - wxPropertyContract.setStatus(EnumRentContractStatus.TERMINATE.getCode()); - wxPropertyContractMapper.endContract(wxPropertyContract); - //作废未生效的合同 - List unvalidstatuss = new ArrayList(); - unvalidstatuss.add(EnumRentContractStatus.DRAFT.getCode()); - unvalidstatuss.add(EnumRentContractStatus.PERFORMANCE.getCode()); - wxPropertyContract.setStatuss(unvalidstatuss); - wxPropertyContract.setStatus(EnumRentContractStatus.INVALID.getCode()); - wxPropertyContractMapper.endContract(wxPropertyContract); - - //物业账单失效 - wxBillPropertyMapper.updateInvalidStatusByRent(wxRentContract); - } - //租赁账单失效 - wxBillAllHelper.rentContractStop(wxRentContract,userInfo); -// WxBillRent wxBillRent = new WxBillRent(); -// wxBillRent.setRentContractId(wxRentContract.getId()); -// wxBillRent.updateTenantInfo(wxRentContract); -// wxBillRentMapper.updateInvalidStatus(wxBillRent); - return new ResultData(Result.SUCCESS,"终止成功"); - //解绑商户和商铺关系 -// WxRentContract rentContract = wxRentContractMapper.selectById(wxRentContract.getId()); -// if(rentContract != null && rentContract.getMerchantId() != null){ -// wxMerchantService.disable(rentContract.getMerchantId()); -// } - } - - @Transactional(rollbackFor = {Exception.class}) - @Override - public ResultData updateRentContract(WxRentContract wxRentContract) { -// WxRentContract record = wxRentContractMapper.selectById(wxRentContract); -// if (wxRentContract == null) { -// return new ResultData(ErrorCode.RENT_CONTRACT_IS_NOT_FOUND); -// } -// record.setMerchantId(wxRentContract.getMerchantId()); - try { - wxRentContractMapper.updateById(wxRentContract); - } catch (MallinkException e) { - logger.info("关联合同商户失败:" + e.getMessage()); - throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); - } - return new ResultData(Result.SUCCESS, "操作成功"); - } - - @Override - public PageInfo getRentContractList(WxRentContract rentContract, Integer pageIndex, Integer pageSize) { - if (StringUtils.isNoneBlank(rentContract.getFloorForRule())) { - List mids = wxMerchantService.getFloorBuildMerchantIds(rentContract, rentContract.getFloorForRule() , null, null, 0, 0); - if (null == mids || mids.size() <= 0 ) { - rentContract.setId(-1L); - } else { - rentContract.setMerchantIds(mids); - } - } - //PageInfo pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxRentContractMapper.getRentContractList(rentContract)); - PageInfo pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxRentContractMapper.findList(rentContract)); - return pageInfo; - } - -// @Override -// public Map updateStatus(WxRentContract record) { -// Map resultData = new HashMap(); -// WxRentContract wxRentContract = new WxRentContract(); -// wxRentContract.updateTenantInfo(record); -// wxRentContract.setRentShopType(record.getRentShopType()); -// -// int allCount = wxRentContractMapper.selectCount(new QueryWrapper(wxRentContract)); -// resultData.put("allCount", allCount); -// -// //待签约 -// //wxRentContract.setStatus(EnumRentContractStatus.WAIT_SIGN.getCode()); -// //int waitSignCount = wxRentContractMapper.queryRentContractWaitSignStatus(wxRentContract); -// //resultData.put("waitSignCount", waitSignCount); -// resultData.put("waitSignCount", 0); -// -// //计租中 -// wxRentContract.setStatus(EnumRentContractStatus.PAING.getCode()); -// wxRentContractMapper.updateRentContractPaidStatus(wxRentContract); -// int rendPaidCount = wxRentContractMapper.queryRentContractPaidStatus(wxRentContract); -// resultData.put("rendPaidCount", rendPaidCount); -// -// //将到期 -// //wxRentContract.setStatus(EnumRentContractStatus.CONTRACT_END_SOON.getCode()); -// //wxRentContractMapper.updateRentContractEndSoonStatus(wxRentContract); -// //int endSoonCount = wxRentContractMapper.queryRentContractEndSoonStatus(wxRentContract); -// //resultData.put("endSoonCount", endSoonCount); -// resultData.put("endSoonCount", 0); -// -// //到期 -// wxRentContract.setStatus(EnumRentContractStatus.OUT_DATE.getCode()); -// wxRentContractMapper.updateRentContractEndStatus(wxRentContract); -// int endCount = wxRentContractMapper.queryRentContractEndStatus(wxRentContract); -// resultData.put("endCount", endCount); -// -// //合同到期 -// contractEnd(record.getTenantId()); -// -// return resultData; -// } - -// @Override -// public void exportContract(HttpServletRequest request, HttpServletResponse response, Long rentId,Long propertyId) { -// String contracType = "0"; -// String templatePath = null; -// Map result = null; -// if (EnumContractType.ALL.getCode().toString().equals(contracType)) { -// logger.info("获取租赁及物业合同数据"); -// result = getRentAndPropertyInfo(rentId,propertyId); -// result.put("contractType", EnumContractType.ALL.getMessage()); -// if(EnumContractOperationType.JINMAO.getCode().equals(result.get("operationType"))){ -// templatePath = "contract-word-template/jinmao_contract_rent_property.docx"; -// }else{ -// if (EnumRentContractType.RENT_BY_AREA.getCode().equals(result.get("type"))) { -// templatePath = "contract-word-template/contract_rent_property.docx"; -// } else { -// templatePath = "contract-word-template/contract_rent_property_by_ratio.docx"; -// } -// } -// -// logger.info("租赁及物业合同数据结果:" + result); -// } -// -// if (templatePath == null) { -// logger.info("没有租赁及物业合同模板"); -// return; -// } -// String filepath = fmUploadDir; -// String filename = UUID.randomUUID() + ".docx"; -// String exportFileName = result.get("merchantName").toString() + "合同.docx"; -// WordUtil.exportWord(templatePath, filepath, filename, exportFileName, result, request, response,null); -// } - - @Override - @Transactional(rollbackFor = {Exception.class}) - public ResultData updateFile(WxRentContract record, Long userId,String userName,Date oldRentStartDate,boolean writeComplate) { - - WxRentContract wxRentContract = wxRentContractMapper.selectById(record.getId()); - if (null == wxRentContract) { - return new ResultData(Result.ERROR,"id查询不到合同"); - } - // 保存调整金额(预账单调整) - if(!CollectionUtils.isEmpty(record.getPreviewBillRentList())){ - wxRentContract.setPreviewBillRentList(record.getPreviewBillRentList()); - savePreviewBill(wxRentContract); - //保存商业管理费账单 - savePreviewManageFeeBill(wxRentContract,EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE); - //保存营业管理费账单 - savePreviewManageFeeBill(wxRentContract,EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE); - } - WxRentContract rc = new WxRentContract(); - rc.setId(record.getId()); - rc.setRentalStartDate(oldRentStartDate); - rc.setDecimalSize(wxRentContract.getDecimalSize()); - if (writeComplate) { - rc.setStatus(EnumRentContractStatus.DRAFT.getCode()); - }else { - rc.setStatus(wxRentContract.getStatus()); - } - rc.setFileNames(record.getFileNames()); - wxRentContractMapper.updateById(rc); - if (null != wxRentContract.getOperationType() && EnumContractOperationType.WHOLE.getCode().equals(wxRentContract.getOperationType())) { - WxPropertyContract pc = wxPropertyContractMapper.findOneByRentId(wxRentContract); - if (null != pc) { - wxRentContract.setPropertyContractId(pc.getId()); - } - } - return new ResultData(wxRentContract); - } - - @Override - public ResultData updateRentContractStatus(Long id,boolean buildProperyBill) { - if (id == null) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); - } - WxRentContract record = wxRentContractMapper.selectById(id); - if (record == null) { - return new ResultData(ErrorCode.RENT_CONTRACT_IS_NOT_FOUND); - } - //如果合同状态为非正常状态,则不更新合同状态,并删除账单 - if(record.getStatus().intValue() == EnumRentContractStatus.INVALID.getCode().intValue() - || record.getStatus().intValue() == EnumRentContractStatus.TERMINATE.getCode().intValue()) { - return new ResultData(ErrorCode.RENT_CONTRACT_IS_TERMINATED.getCode(),"合同状态已作废或者已终止."); - } - - - //更新合同状态为签约 - WxRentContract wxRentContract = new WxRentContract(); - wxRentContract.setId(id); - if (record.getRentalStartDate().before(new Date())) { - wxRentContract.setStatus(EnumRentContractStatus.PAING.getCode()); - } else { - wxRentContract.setStatus(EnumRentContractStatus.READY_FOR_PAING.getCode()); - } - wxRentContractMapper.updateById(wxRentContract); - //EventUtil.publistRentEvent(this, wxRentContract); - //建立账单 - //自定义账单无单价,为能生成账单,设置该值 - if (EnumRentContractType.RENT_BY_CUSTOMIZE.getCode() == record.getType()) { - record.setPrice("0.01"); - } - if (record != null && - record.getMerchantId() != null && - record.getReceivePeriod() != null ) { - //预览账单改为正式,并写入商户id - WxBillRent billRent = new WxBillRent(); - billRent.setRentContractId(id); - billRent.setIsPreview(EnumIsPreview.NO.getCode()); - billRent.setMerchantId(record.getMerchantId()); - billRent.updateTenantInfo(record); - wxBillRentMapper.updatePreviewStatus(billRent); -// WxMerchant wxMerchant = new WxMerchant(); -// wxMerchant.setId(record.getMerchantId()); -// wxMerchant.updateTenantInfo(record); - - //商业管理费,营业管理费 - WxBillRentManage billRentManage = new WxBillRentManage(); - billRentManage.setRentContractId(id); - billRentManage.setIsPreview(EnumIsPreview.NO.getCode()); - billRentManage.updateTenantInfo(record); - wxBillRentManageMapper.updatePreviewStatus(billRentManage); - - if(new BigDecimal(record.getDeposit()).compareTo(new BigDecimal(0)) > 0) { - //押金 - buildDeposit( null, id); - } - //一起建立物业账单 - if (buildProperyBill) { - updatePropertyPreviewBill(record); - } - - //作废合同 - //updateInvalidContract(id); - } - - return new ResultData(Result.SUCCESS, "操作成功"); - } - - @Override - public void updatePropertyPreviewBill(WxRentContract record) { - //合并合同-更新物业账单 - if (record.getOperationType().equals(EnumContractOperationType.WHOLE.getCode())) { - //查签约 - WxPropertyContract wxPropertyContract = new WxPropertyContract(); - wxPropertyContract.setRentContractId(record.getId()); - WxPropertyContract propertyContract = wxPropertyContractMapper.selectOne(new QueryWrapper(wxPropertyContract)); - logger.info("物业合同状态及账单状态修改:{}",propertyContract); - if (propertyContract != null) { - propertyContract.setMerchantId(record.getMerchantId()); - wxPropertyContractMapper.updateById(propertyContract); - wxPropertyContractService.updatePropertyContractStatus(propertyContract.getId()); - } - } - } - -// public Map getRentAndPropertyInfo(Long rentId,Long propertyId) { -// logger.info("获取租赁物业合同数据>>>>>>rentId:" + rentId +" >>>>propertyId:"+propertyId); -// Map result = new HashMap<>(); -// WxRentContract wxRentContract = wxRentContractMapper.selectById(rentId); -// -// result.put("operationType", wxRentContract.getOperationType()); -// if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { -// JSONArray jsonArray = JSONArray.parseArray(wxRentContract.getRentInfo()); -// StringBuffer shopNumberStr = new StringBuffer(); -// StringBuffer floorNameStr = new StringBuffer(); -// StringBuffer buildingNameStr = new StringBuffer(); -// StringBuffer buildAreaStr = new StringBuffer(); -// StringBuffer operationAreaStr = new StringBuffer(); -// for (int i = 0, size = jsonArray.size(); i < size; i++) { -// JSONObject jsonObject = jsonArray.getJSONObject(i); -// shopNumberStr.append("[").append(jsonObject.getString("shopNumber")).append("]"); -// floorNameStr.append("[").append(jsonObject.getString("floorName")).append("]"); -// buildingNameStr.append("[").append(jsonObject.getString("buildingName")).append("]"); -// buildAreaStr.append("[").append(jsonObject.getString("buildArea")).append("]"); -// operationAreaStr.append("[").append(jsonObject.getString("operationArea")).append("]"); -// } -// result.put("shopNumber", shopNumberStr); -// result.put("floorName", floorNameStr); -// result.put("buildingName", buildingNameStr); -// result.put("buildArea", buildAreaStr); -// result.put("operationArea", operationAreaStr); -// } else { -// //record.setId(wxRentContract.getShopId()); -// if (wxRentContract.shopIdsByRentInfo().size() == 0) { -// result.put("shopNumber", " "); -// result.put("floorName", " "); -// result.put("buildingName", " "); -// result.put("buildArea", " "); -// result.put("operationArea", " "); -// }else { -// WxShop record = new WxShop(); -// record.setIds(wxRentContract.shopIdsByRentInfo()); -// record.updateTenantInfo(wxRentContract); -// PageInfo> shopPageInfo = wxShopService.findListMap(record,1,10000); -// List> wxShops = shopPageInfo.getList(); -// if (!wxShops.isEmpty()) { -// //店铺信息 -// Map wxShop = wxShops.get(0); -// result.put("shopNumber", wxShop.get("shopNumber")); -// result.put("floorName", wxShop.get("floor")); -// result.put("buildingName", wxShop.get("building")); -// result.put("buildArea", wxShop.get("buildArea")); -// result.put("operationArea", wxShop.get("operationArea")); -// } -// } -// } -// //MALL信息 -// WxMall wxMall = new WxMall(); -// wxMall.setTenantInfo(wxRentContract); -// wxMall = wxMallService.findList(wxMall).get(0); -// result.put("mallName", wxMall.getName()); -// result.put("province", wxMall.getProvince()); -// result.put("city", wxMall.getCity()); -// result.put("mallAddr", wxMall.getAddr()); -// result.put("mallServicePhone", wxMall.getServicePhone()); -// -// //商户信息 -// WxMerchant merchant = wxMerchantService.getById(wxRentContract.getMerchantId()); -// //经营业态 -// wxRentContract.getMerchantId(); -// WxBusiness wxBusiness = wxBusinessMapper.selectById(merchant.getFinalTenantId(),merchant.getBusinessId()); -// result.put("business", wxBusiness.getTitle()); -// -// if (merchant != null) { -// result.put("merchantName", merchant.getName()); -// //法人信息 -// WxMerchantCorp wxMerchantCorp = merchant.getWxMerchantCorp(); -// result.put("corpPapersNumber", StringUtils.isNotEmpty(wxMerchantCorp.getCorpPapersNumber()) ? wxMerchantCorp.getCorpPapersNumber() : " "); -// result.put("corpPapersType", wxMerchantCorp.getCorpPapersType() != null ? EnumPapersType.getEnum(wxMerchantCorp.getCorpPapersType()).getMessage() : " "); -// result.put("corpPapersPerson", StringUtils.isNotEmpty(wxMerchantCorp.getCorpPapersPerson()) ? wxMerchantCorp.getCorpPapersPerson() : " "); -// //税务信息 -// WxMerchantTax wxMerchantTax = merchant.getWxMerchantTax(); -// result.put("taxPapersType", wxMerchantTax.getTaxPapersType() != null ? EnumTaxpayerType.getEnum(wxMerchantTax.getTaxPapersType()).getMessage() : " "); -// result.put("bankName", StringUtils.isNotEmpty(wxMerchantTax.getBankName()) ? wxMerchantTax.getBankName() : " "); -// result.put("bankAccount", StringUtils.isNotEmpty(wxMerchantTax.getBankAccount()) ? wxMerchantTax.getBankAccount() : " "); -// result.put("invoiceAddressPhone", StringUtils.isNotEmpty(wxMerchantTax.getInvoiceAddressPhone()) ? wxMerchantTax.getInvoiceAddressPhone() : " "); -// } else { -// result.put("merchantName", ""); -// //法人信息 -// result.put("corpPapersNumber", " "); -// result.put("corpPapersType", " "); -// result.put("corpPapersPerson", " "); -// //税务信息 -// result.put("taxPapersType", " "); -// result.put("bankName", " "); -// result.put("bankAccount", " "); -// result.put("invoiceAddressPhone", " "); -// } -// -// //租赁合同信息 -// if(StringUtils.isNotBlank(wxRentContract.getContractualRules())){ -// //{total:,partyA:,partyB:} -// JSONObject jsonObject = JSONObject.parseObject(wxRentContract.getContractualRules()); -// result.put("rentTotal",jsonObject.getString("total")); -// result.put("rentPartyA",jsonObject.getString("partyA")); -// result.put("rentPartyB",jsonObject.getString("partyB")); -// } -// if(StringUtils.isNotBlank(wxRentContract.getBusinessHours())){ -// //{"beginEnd": "00", "finishEnd": "00", "beginStart": "00", "finishStart": "18"} -// JSONObject jsonObject = JSONObject.parseObject(wxRentContract.getBusinessHours()); -// if(!("-1").equals(jsonObject.getString("beginStart")) && !("-1").equals(jsonObject.getString("beginEnd")) -// && !("-1").equals(jsonObject.getString("finishStart")) && !("-1").equals(jsonObject.getString("finishEnd"))){ -// result.put("businessStart",jsonObject.getString("beginStart")+":"+jsonObject.getString("beginEnd")); -// result.put("businessEnd",jsonObject.getString("finishStart")+":"+jsonObject.getString("finishEnd")); -// } -// } -// //甲方信息 -// if(StringUtils.isNotBlank(wxRentContract.getFirstPartyBankInfo())){ -// //{"bankNameA": "", "accountNumA": "", "accountNameA": "", "socialCreditCodeA": ""} -// JSONObject jsonObject = JSONObject.parseObject(wxRentContract.getFirstPartyBankInfo()); -// result.put("bankNameA",jsonObject.getString("bankNameA")); -// result.put("accountNumA",jsonObject.getString("accountNumA")); -// result.put("accountNameA",jsonObject.getString("accountNameA")); -// result.put("socialCreditCodeA",jsonObject.getString("socialCreditCodeA")); -// }else{ -// result.put("bankNameA",""); -// result.put("accountNumA",""); -// result.put("accountNameA",""); -// result.put("socialCreditCodeA",""); -// } -// //乙方信息 -// result.put("scopeMetre",wxRentContract.getScopeMetre()); -// result.put("shopTypeSub",wxRentContract.getShopTypeSub()); -// result.put("leasePurpose",wxRentContract.getLeasePurpose()); -// result.put("linkPhoneB",wxRentContract.getLinkPhone()); -// result.put("linkAddressB",wxRentContract.getLinkAddress()); -// if(StringUtils.isNotBlank(wxRentContract.getSecondPartyBankInfo())){ -// //{"bankName": "", "payAccount": "", "accountName": "", "socialCreditCode": ""} -// JSONObject jsonObject = JSONObject.parseObject(wxRentContract.getSecondPartyBankInfo()); -// result.put("bankNameB",jsonObject.getString("bankName")); -// result.put("accountNumB",jsonObject.getString("payAccount")); -// result.put("accountNameB",jsonObject.getString("accountName")); -// result.put("socialCreditCodeB",jsonObject.getString("socialCreditCode")); -// }else{ -// result.put("bankNameB",""); -// result.put("accountNumB",""); -// result.put("accountNameB",""); -// result.put("socialCreditCodeB",""); -// } -// //乙方税务信息 -// if(StringUtils.isNotBlank(wxRentContract.getSecondPartyTaxInfo())){ -// //{"bankName": "", "linkPhone": "", "payAccount": "", "accountName": "", "taxpayerAdress": "", "taxpayerNumber": ""} -// JSONObject jsonObject = JSONObject.parseObject(wxRentContract.getSecondPartyTaxInfo()); -// result.put("bankNameBTax",jsonObject.getString("bankName")); -// result.put("accountNumBTax",jsonObject.getString("payAccount")); -// result.put("accountNameBTax",jsonObject.getString("accountName")); -// result.put("linkPhoneBTax",jsonObject.getString("linkPhone")); -// result.put("taxpayerAdressB",jsonObject.getString("taxpayerAdress")); -// result.put("taxpayerNumberB",jsonObject.getString("taxpayerNumber")); -// }else{ -// result.put("bankNameBTax",""); -// result.put("accountNumBTax",""); -// result.put("accountNameBTax",""); -// result.put("linkPhoneBTax",""); -// result.put("taxpayerAdressB",""); -// result.put("taxpayerNumberB",""); -// } -// -// //物业 -// result.put("propertyName",wxRentContract.getPropertyName()); -// if(wxRentContract.getPropertyFee() != null){ -// double propertyFee = new BigDecimal(wxRentContract.getPropertyFee()) -// .divide(new BigDecimal(100)) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("propertyFee",propertyFee); -// } -// if(wxRentContract.getFeeCycle() != null){ -// if(wxRentContract.getFeeCycle().intValue() == 1){ -// result.put("feeCycle","月"); -// }else if(wxRentContract.getFeeCycle().intValue() == 2){ -// result.put("feeCycle","季"); -// }else if(wxRentContract.getFeeCycle().intValue() == 3){ -// result.put("feeCycle","年"); -// } -// } -// if(wxRentContract.getWaterFee() != null){ -// double waterFee = new BigDecimal(wxRentContract.getWaterFee()) -// .divide(new BigDecimal(100)) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("waterFee",waterFee); -// } -// if(wxRentContract.getElectricityFees() != null){ -// double electricityFees = new BigDecimal(wxRentContract.getElectricityFees()) -// .divide(new BigDecimal(100)) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("electricityFees",electricityFees); -// } -// -// -// -// //交付 -// if(wxRentContract.getDeliveryDate() != null){ -// String deliveryDate = DateUtils.date2String(wxRentContract.getDeliveryDate(), "yyyy-MM-dd"); -// result.put("deliveryDateYear", deliveryDate.substring(0, 4)); -// result.put("deliveryDateMonth", deliveryDate.substring(5, 7)); -// result.put("deliveryDateDay", deliveryDate.substring(8)); -// result.put("deliveryGracePeriod", wxRentContract.getDeliveryGracePeriod()); -// } -// -// -// //装修 -// if(wxRentContract.getFixStartDate() != null && wxRentContract.getFixEndDate() != null){ -// String fixStartDate = DateUtils.date2String(wxRentContract.getFixStartDate(), "yyyy-MM-dd"); -// result.put("fixStartDateYear", fixStartDate.substring(0, 4)); -// result.put("fixStartDateMonth", fixStartDate.substring(5, 7)); -// result.put("fixStartDateDay", fixStartDate.substring(8)); -// String fixEndDate = DateUtils.date2String(wxRentContract.getFixEndDate(), "yyyy-MM-dd"); -// result.put("fixEndDateYear", fixEndDate.substring(0, 4)); -// result.put("fixEndDateMonth", fixEndDate.substring(5, 7)); -// result.put("fixEndDateDay", fixEndDate.substring(8)); -// } -// -// //开业 -// if(wxRentContract.getOpeningDate() != null){ -// String openingDate = DateUtils.date2String(wxRentContract.getOpeningDate(), "yyyy-MM-dd"); -// result.put("openingDateYear", openingDate.substring(0, 4)); -// result.put("openingDateMonth", openingDate.substring(5, 7)); -// result.put("openingDateDay", openingDate.substring(8)); -// } -// -// //计租 -// if(wxRentContract.getStartDate() != null && wxRentContract.getRentalEndDate() != null){ -// String rentalStartDate = DateUtils.date2String(wxRentContract.getStartDate(), "yyyy-MM-dd"); -// result.put("rentalStartDate", rentalStartDate); -// result.put("rentalStartDateYear", rentalStartDate.substring(0, 4)); -// result.put("rentalStartDateMonth", rentalStartDate.substring(5, 7)); -// result.put("rentalStartDateDay", rentalStartDate.substring(8)); -// String rentalEndDate = DateUtils.date2String(wxRentContract.getRentalEndDate(), "yyyy-MM-dd"); -// result.put("rentalEndDate", rentalEndDate); -// result.put("rentalEndDateYear", rentalEndDate.substring(0, 4)); -// result.put("rentalEndDateMonth", rentalEndDate.substring(5, 7)); -// result.put("rentalEndDateDay", rentalEndDate.substring(8)); -// } -// //免租 -// if(wxRentContract.getStartDate() != null && wxRentContract.getRentalStartDate()!=null -// && !DateUtils.isSameDate(wxRentContract.getStartDate(),wxRentContract.getRentalStartDate())){ -// String reductionStartDate = DateUtils.date2String(wxRentContract.getRentalStartDate(), "yyyy-MM-dd"); -// result.put("reductionStartDateYear", reductionStartDate.substring(0, 4)); -// result.put("reductionStartDateMonth", reductionStartDate.substring(5, 7)); -// result.put("reductionStartDateDay", reductionStartDate.substring(8)); -//// String reductionEndDate = DateUtils.date2String(wxRentContract.getRentalStartDate(), "yyyy-MM-dd"); -// String reductionEndDate = DateUtils.getTimeBefore(1,wxRentContract.getStartDate()); -// result.put("reductionEndDateYear", reductionEndDate.substring(0, 4)); -// result.put("reductionEndDateMonth", reductionEndDate.substring(5, 7)); -// result.put("reductionEndDateDay", reductionEndDate.substring(8)); -// }else{ -// result.put("reductionStartDateYear", "/"); -// result.put("reductionStartDateMonth", "/"); -// result.put("reductionStartDateDay", "/"); -// result.put("reductionEndDateYear", "/"); -// result.put("reductionEndDateMonth", "/"); -// result.put("reductionEndDateDay", "/"); -// } -// -// String shopType4Str = ""; -// if(wxRentContract.getShopType() != null && wxRentContract.getShopType().intValue() == 1){ -// shopType4Str = "直营"; -// }else if(wxRentContract.getShopType() != null && wxRentContract.getShopType().intValue() == 6){ -// shopType4Str = "代理"; -// }else if(wxRentContract.getShopType() != null && wxRentContract.getShopType().intValue() == 2){ -// shopType4Str = "加盟"; -// }else{ -// shopType4Str = "其他("+wxRentContract.getShopTypeStr()+")"; -// } -// result.put("shopType4Str",shopType4Str); -// -// -// -// -// result.put("price", wxRentContract.getPrice()); -// result.put("contractNumber", wxRentContract.getContractNumber()); -// Integer lease = wxRentContract.getLease(); -// Integer receivePeriod = wxRentContract.getReceivePeriod(); -// result.put("lease", lease); -// result.put("receivePeriod", receivePeriod); -// String payAccountStr = " "; -// if(wxRentContract.getPayAccount() != null && !wxRentContract.getPayAccount().equals("")) { -// payAccountStr = wxRentContract.getPayAccount(); -// } -// result.put("payAccount", payAccountStr); -// result.put("signDate", DateUtils.date2String(wxRentContract.getSignDate(), "yyyy-MM-dd")); -// //主体名称-乙方 -// if (StringUtils.isNotEmpty(wxRentContract.getSubjectName())) { -// result.put("subjectName", wxRentContract.getSubjectName()); -// } else { -// result.put("subjectName", " "); -// } -// -// //品牌 -// Long brandId = wxRentContract.getBrand(); -// String brand = " "; -// if (brandId != null) { -// WxBrand wxBrand = WxBrandMapper.selectById(brandId); -// if (wxBrand != null) { -// brand = wxBrand.getName(); -// } -// } -// result.put("brand", brand); -// Integer type = wxRentContract.getType(); -// result.put("type", type); -// -// if(EnumContractOperationType.JINMAO.getCode().equals(wxRentContract.getOperationType())){ -// if(StringUtils.isNotBlank(wxRentContract.getCashtypeContentLsit())){ -// //{"honourPledge": "", "fitmentPledge": "", "qualityPledge": "", "honourDuration": "", "qualityDuration": ""} -// //fitmentPledge:"",//装修押金 -// //honourPledge:"",//履约保证金 -// //honourDuration:"",//履约保证金时限 -// //qualityPledge:"",//品质保证金 -// //qualityDuration:"",//品质保证金时限 -// JSONObject jsonObject = JSONObject.parseObject(wxRentContract.getCashtypeContentLsit()); -// result.put("fitmentPledge",jsonObject.getString("fitmentPledge")); -// result.put("honourPledge",jsonObject.getString("honourPledge")); -// if(StringUtils.isNotBlank(jsonObject.getString("honourPledge"))){ -// result.put("honourPledgeUpper",PriceUtil.digitUppercase(Double.valueOf(jsonObject.getString("honourPledge")))); -// } -// result.put("honourDuration",jsonObject.getString("honourDuration")); -// result.put("qualityPledge",jsonObject.getString("qualityPledge")); -// if(StringUtils.isNotBlank(jsonObject.getString("qualityPledge"))){ -// result.put("honourPledgeUpper",PriceUtil.digitUppercase(Double.valueOf(jsonObject.getString("qualityPledge")))); -// } -// result.put("qualityDuration",jsonObject.getString("qualityDuration")); -// -// } -// //[{"progressivePay": "", "tempAdjustRatio": "2021-11-30 00:00:00", "incrementStartDate": "2021-11-29T16:00:00.000Z", "increasingProportion": "1.78"}] -// //increasingProportion//租金递增比例 -// //progressivePay//递增租赁单价 -// List> ratioList = new ArrayList<>(); -// if(StringUtils.isNotBlank(wxRentContract.getAdjustRatio())){ -// JSONArray array = JSONArray.parseArray(wxRentContract.getAdjustRatio()); -// if(array != null && array.size() > 0){ -// for(int i=0;i ratioMap = new HashMap<>(); -// String afterYear = DateUtils.getAfterYear(wxRentContract.getStartDate(), i + 1); -// String beforeAfterYear = DateUtils.getTimeBefore(1, afterYear); -// ratioMap.put("incrementStartDate",afterYear); -// ratioMap.put("beforeOneIncrementStartDate",beforeAfterYear); -// ratioMap.put("increasingProportion",jsonObject.getString("increasingProportion")); -// ratioMap.put("progressivePay",jsonObject.getString("progressivePay")); -// ratioList.add(ratioMap); -// } -// } -// } -// } -// result.put("countRatioList",ratioList.size()); -// -// if(EnumRentContractType.RENT_BY_AREA.getCode().equals(type)){ -// -// double priceRent = new BigDecimal(wxRentContract.getPrice()) -// .divide(new BigDecimal(100)) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("oneRentalPrice1", priceRent); -// result.put("oneRentalPriceUpper1", PriceUtil.digitUppercase(priceRent)); -// -// double oneRentPrice = new BigDecimal(wxRentContract.getRentPrice()) -// .divide(new BigDecimal(100)) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("oneRentPrice",oneRentPrice); -// -// WxBillRent wxBillRent = new WxBillRent(); -// wxBillRent.setRentContractId(wxRentContract.getId()); -// wxBillRent.setSortColumns(BaseEntity.SortField.Period_ASC); -// List resultList = wxBillRentMapper.findList(wxBillRent); -// //稍后详细计算(查询首期账单用于显示) -// if(resultList != null && resultList.size() > 0){ -// double oneRentalQuarterPrice1 = new BigDecimal(resultList.get(0).getReceivePay()) -// .divide(new BigDecimal(100)) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("oneRentalQuarterPrice1", oneRentalQuarterPrice1); -// result.put("oneRentalQuarterPriceUpper1", PriceUtil.digitUppercase(oneRentalQuarterPrice1)); -// } -// -// if(ratioList.size() > 0){ -// String beforeOneIncrementStartDate = ratioList.get(0).get("beforeOneIncrementStartDate"); -// result.put("oneRentalEndDateYear1",beforeOneIncrementStartDate.substring(0,4)); -// result.put("oneRentalEndDateMonth1",beforeOneIncrementStartDate.substring(5,7)); -// result.put("oneRentalEndDateDay1",beforeOneIncrementStartDate.substring(8,10)); -// -// String incrementStartDate = ratioList.get(0).get("incrementStartDate"); -// result.put("oneRentalStartDateYear2",incrementStartDate.substring(0,4)); -// result.put("oneRentalStartDateMonth2",incrementStartDate.substring(5,7)); -// result.put("oneRentalStartDateDay2",incrementStartDate.substring(8,10)); -// String increasingProportion = ratioList.get(0).get("increasingProportion"); -// result.put("oneRentIncreasing2",increasingProportion); -// double priceRent2 = new BigDecimal(priceRent) -// .multiply(new BigDecimal(1).add(new BigDecimal(increasingProportion).divide(new BigDecimal(100)))) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("oneRentalPrice2", priceRent2); -// result.put("oneRentalPriceUpper2", PriceUtil.digitUppercase(priceRent2)); -// -// if(ratioList.size() > 1){ -// for (int i = 1;i < ratioList.size();i++){ -// int n = i+2; -// String incrementStartDaten = ratioList.get(i).get("incrementStartDate"); -// result.put("oneRentalStartDateYear"+n,incrementStartDaten.substring(0,4)); -// result.put("oneRentalStartDateMonth"+n,incrementStartDaten.substring(5,7)); -// result.put("oneRentalStartDateDay"+n,incrementStartDaten.substring(8,10)); -// String increasingProportionn = ratioList.get(i).get("increasingProportion"); -// result.put("oneRentIncreasing"+n,increasingProportionn); -// priceRent2 = new BigDecimal(priceRent2) -// .multiply(new BigDecimal(1).add(new BigDecimal(increasingProportionn).divide(new BigDecimal(100)))) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("oneRentalPrice"+n, priceRent2); -// result.put("oneRentalPriceUpper"+n, PriceUtil.digitUppercase(priceRent2)); -// } -// } -// -// }else{ -// String rentalEndDate = DateUtils.date2String(wxRentContract.getRentalEndDate(), "yyyy-MM-dd"); -// result.put("oneRentalStartDateYear1", rentalEndDate.substring(0, 4)); -// result.put("oneRentalStartDateMonth1", rentalEndDate.substring(5, 7)); -// result.put("oneRentalStartDateDay1", rentalEndDate.substring(8)); -// } -// -// -// }else if(EnumRentContractType.RENT_BY_JOINT.getCode().equals(type)){ -// Double twoPayRatio1 = new BigDecimal(wxRentContract.getPayRatio()) -// .divide(new BigDecimal(100)) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("twoPayRatio1",twoPayRatio1); -// result.put("twoPayDate",wxRentContract.getPayDate()); -// if(ratioList.size() > 0){ -// String beforeOneIncrementStartDate = ratioList.get(0).get("beforeOneIncrementStartDate"); -// result.put("twoRentalEndDateYear1",beforeOneIncrementStartDate.substring(0,4)); -// result.put("twoRentalEndDateMonth1",beforeOneIncrementStartDate.substring(5,7)); -// result.put("twoRentalEndDateDay1",beforeOneIncrementStartDate.substring(8,10)); -// String incrementStartDate = ratioList.get(0).get("incrementStartDate"); -// result.put("twoRentalStartDateYear2",incrementStartDate.substring(0,4)); -// result.put("twoRentalStartDateMonth2",incrementStartDate.substring(5,7)); -// result.put("twoRentalStartDateDay2",incrementStartDate.substring(8,10)); -// String increasingProportion = ratioList.get(0).get("increasingProportion"); -// result.put("twoRentIncreasing2",increasingProportion); -//// Double twoPayRatio2 = new BigDecimal(twoPayRatio1) -//// .add(new BigDecimal(increasingProportion)) -//// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("twoPayRatio2",twoPayRatio1); -// -// if(ratioList.size() > 1){ -// for (int i = 1;i < ratioList.size();i++){ -// int n = i+2; -// String incrementStartDaten = ratioList.get(i).get("incrementStartDate"); -// result.put("twoRentalStartDateYear"+n,incrementStartDaten.substring(0,4)); -// result.put("twoRentalStartDateMonth"+n,incrementStartDaten.substring(5,7)); -// result.put("twoRentalStartDateDay"+n,incrementStartDaten.substring(8,10)); -// String increasingProportionn = ratioList.get(i).get("increasingProportion"); -// result.put("twoRentIncreasing"+n,increasingProportionn); -//// Double twoPayRatio2 = new BigDecimal(twoPayRatio1) -//// .add(new BigDecimal(increasingProportion)) -//// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("twoPayRatio"+n,twoPayRatio1); -// } -// } -// -// }else{ -// String rentalEndDate = DateUtils.date2String(wxRentContract.getRentalEndDate(), "yyyy-MM-dd"); -// result.put("twoRentalStartDateYear1", rentalEndDate.substring(0, 4)); -// result.put("twoRentalStartDateMonth1", rentalEndDate.substring(5, 7)); -// result.put("twoRentalStartDateDay1", rentalEndDate.substring(8)); -// } -// -// }else if(EnumRentContractType.RENT_BY_AREA_AND_JOINT.getCode().equals(type)){ -// double priceRent = new BigDecimal(wxRentContract.getPrice()) -// .divide(new BigDecimal(100)) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("threeRentalPrice1", priceRent); -// result.put("threeRentalPriceUpper1", PriceUtil.digitUppercase(priceRent)); -// -// double threeRentPrice = new BigDecimal(wxRentContract.getRentPrice()) -// .divide(new BigDecimal(100)) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("threeRentPrice",threeRentPrice); -// double threePayRatio1 = new BigDecimal(wxRentContract.getPayRatio()) -// .divide(new BigDecimal(100)) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("threePayRatio1",threePayRatio1); -// -// result.put("threePayDate",wxRentContract.getPayDate()); -// if(ratioList.size() > 0){ -// String beforeOneIncrementStartDate = ratioList.get(0).get("beforeOneIncrementStartDate"); -// result.put("threeRentalEndDateYear1",beforeOneIncrementStartDate.substring(0,4)); -// result.put("threeRentalEndDateMonth1",beforeOneIncrementStartDate.substring(5,7)); -// result.put("threeRentalEndDateDay1",beforeOneIncrementStartDate.substring(8,10)); -// String incrementStartDate = ratioList.get(0).get("incrementStartDate"); -// result.put("threeRentalStartDateYear2",incrementStartDate.substring(0,4)); -// result.put("threeRentalStartDateMonth2",incrementStartDate.substring(5,7)); -// result.put("threeRentalStartDateDay2",incrementStartDate.substring(8,10)); -// String progressivePay = ratioList.get(0).get("progressivePay"); -// double threeProgressivePay2 = new BigDecimal(progressivePay) -// .multiply(new BigDecimal(wxRentContract.getRentArea())) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("threeProgressivePay2",threeProgressivePay2); -// result.put("threeProgressivePayUpper2",PriceUtil.digitUppercase(threeProgressivePay2)); -// result.put("threeRentPrice2",progressivePay); -// String increasingProportion = ratioList.get(0).get("increasingProportion"); -// result.put("threeRentIncreasing2",increasingProportion); -// if(ratioList.size() > 1){ -// for (int i = 1;i < ratioList.size();i++){ -// int n = i+2; -// String incrementStartDaten = ratioList.get(i).get("incrementStartDate"); -// result.put("threeRentalStartDateYear"+n,incrementStartDaten.substring(0,4)); -// result.put("threeRentalStartDateMonth"+n,incrementStartDaten.substring(5,7)); -// result.put("threeRentalStartDateDay"+n,incrementStartDaten.substring(8,10)); -// String progressivePayn = ratioList.get(i).get("progressivePay"); -// double threeProgressivePayn = new BigDecimal(progressivePayn) -// .multiply(new BigDecimal(wxRentContract.getRentArea())) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("threeProgressivePay"+n,threeProgressivePayn); -// result.put("threeProgressivePayUpper"+n,PriceUtil.digitUppercase(threeProgressivePayn)); -// result.put("threeRentPrice"+n,progressivePayn); -// String increasingProportionn = ratioList.get(i).get("increasingProportion"); -// result.put("threeRentIncreasing"+n,increasingProportionn); -// } -// } -// }else{ -// String rentalEndDate = DateUtils.date2String(wxRentContract.getRentalEndDate(), "yyyy-MM-dd"); -// result.put("threeRentalStartDateYear1", rentalEndDate.substring(0, 4)); -// result.put("threeRentalStartDateMonth1", rentalEndDate.substring(5, 7)); -// result.put("threeRentalStartDateDay1", rentalEndDate.substring(8)); -// } -// -// } -// }else{ -// //double adjustRatio = wxRentContract.getAdjustRatio() != null ? wxRentContract.getAdjustRatio() / 100.0 : 0; -// result.put("adjustRatio", 0); -// double priceRent = new BigDecimal(wxRentContract.getPrice()) -// .divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("priceRent", priceRent); -// if (!wxRentContract.getRentArea().equals("0")) { -// double unitPrice = new BigDecimal(wxRentContract.getPrice()) -// .divide(new BigDecimal(wxRentContract.getRentArea()), 2, RoundingMode.HALF_EVEN) -// .divide(new BigDecimal(100)) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("unitPriceRent", unitPrice); -// result.put("priceRentUpper", PriceUtil.digitUppercase(priceRent)); -// result.put("unitPriceRentUpper", PriceUtil.digitUppercase(unitPrice)); -// } else { -// result.put("unitPriceRent", "0"); -// result.put("priceRentUpper", PriceUtil.digitUppercase(0)); -// result.put("unitPriceRentUpper", PriceUtil.digitUppercase(0)); -// } -// -// //租赁保证金 -// int cashDepositMonthRent = 3; -// BigDecimal cashDepositRent = new BigDecimal(wxRentContract.getPrice()).multiply(new BigDecimal(cashDepositMonthRent)) -// .setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_EVEN); -// result.put("cashDepositMonthRent", cashDepositMonthRent); -// result.put("cashDepositRent", cashDepositRent.toPlainString()); -// result.put("cashDepositRentUpper", PriceUtil.digitUppercase(cashDepositRent.setScale(2,RoundingMode.HALF_EVEN).longValue())); -// -// int extralease = lease % 12; -// int extracount = extralease > 0 ? 1 : 0; -// int paycount = lease / 12 + extracount; -// int index = 10 - paycount; -// int count = paycount - 1; -// BigDecimal rentPrice = new BigDecimal(priceRent); -// //保底 -// if (wxRentContract.getRevenue() != null) { -//// double revenue = new BigDecimal(wxRentContract.getRevenue()) -//// .divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("revenue", wxRentContract.getRevenue()); -// result.put("revenueUpper", PriceUtil.digitUppercase(new BigDecimal(wxRentContract.getRevenue()) -// .setScale(2,RoundingMode.HALF_EVEN).longValue())); -// } else { -// result.put("revenue", "0"); -// result.put("revenueUpper", PriceUtil.digitUppercase(0)); -// } -// if (!wxRentContract.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { -// areaWay(wxRentContract, result, lease, extralease, extracount, paycount, index, count, rentPrice); -// } else { -// ratioWay(wxRentContract, result, lease, extralease, extracount, paycount, index, count, rentPrice); -// } -// } -// -// -// -// -// //物业合同信息 -// //WxPropertyContract propertyContract = new WxPropertyContract(); -// //propertyContract.updateTenantInfo(wxRentContract); -// //propertyContract.setRentContractId(wxRentContract.getId()); -//// Optional> first = wxPropertyContractMapper.queryPropertyContractData(propertyContract) -//// .stream().filter(rc -> !rc.get("status").equals(EnumRentContractStatus.CONTRACT_TERMINATE.getCode()) -//// && !rc.get("status").equals(EnumRentContractStatus.WAIT_SIGN.getCode()) -//// && !rc.get("status").equals(EnumRentContractStatus.INVALID.getCode()) -//// && !rc.get("status").equals(EnumRentContractStatus.CONTRACT_END.getCode()) -//// && !rc.get("status").equals(EnumRentContractStatus.INTENTION.getCode())).findFirst(); -// //Optional> first = wxPropertyContractMapper.queryPropertyContractData(propertyContract) -// //.stream().filter(rc -> !rc.get("status").equals(EnumRentContractStatus.TERMINATE.getCode()) -// // && !rc.get("status").equals(EnumRentContractStatus.INVALID.getCode()) -// // && !rc.get("status").equals(EnumRentContractStatus.OUT_DATE.getCode())).findFirst(); -// // Map wxPropertyContract = null; -// // if (first.isPresent()) { -// // wxPropertyContract = first.get(); -// // } -// WxPropertyContract propertyContract = null; -// if (null != propertyId) { -// propertyContract = wxPropertyContractMapper.selectById(propertyId); -// } -// if (propertyContract != null) { -// Integer receivePeriodProperty = propertyContract.getReceivePeriod(); -// result.put("receivePeriodProperty", receivePeriodProperty); -// double priceProperty = new BigDecimal(propertyContract.getPrice().toString()) -// .divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("priceProperty", priceProperty); -// if (!wxRentContract.getRentArea().equals("0")) { -// double unitPriceProperty = new BigDecimal(propertyContract.getPrice().toString()) -// .divide(new BigDecimal(wxRentContract.getRentArea()), 2, RoundingMode.HALF_EVEN) -// .divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("unitPriceProperty", unitPriceProperty); -// result.put("pricePropertyUpper", PriceUtil.digitUppercase(priceProperty)); -// result.put("unitPricePropertyUpper", PriceUtil.digitUppercase(unitPriceProperty)); -// } else { -// result.put("unitPriceProperty", 0); -// result.put("pricePropertyUpper", PriceUtil.digitUppercase(0)); -// result.put("unitPricePropertyUpper", PriceUtil.digitUppercase(0)); -// } -// -// //首期物业费 -// Calendar instance = Calendar.getInstance(); -// instance.setTime(wxRentContract.getRentalStartDate()); -// instance.add(Calendar.MONTH, 0); -// Date starttime = instance.getTime(); -// String startdate = DateUtils.date2String(starttime, "yyyy-MM-dd"); -// result.put("rentalStartDateProperty", startdate); -// result.put("rentalStartDateYearProperty", startdate.substring(0, 4)); -// result.put("rentalStartDateMonthProperty", startdate.substring(5, 7)); -// result.put("rentalStartDateDayProperty", startdate.substring(8)); -// //结束时间 -// instance.clear(); -// instance.setTime(starttime); -// instance.add(Calendar.MONTH, receivePeriodProperty); -// instance.add(Calendar.DAY_OF_MONTH, -1); -// Date endtime = instance.getTime(); -// String enddate = DateUtils.date2String(endtime, "yyyy-MM-dd"); -// result.put("rentalEndDateProperty", enddate); -// result.put("rentalEndDateYearProperty", enddate.substring(0, 4)); -// result.put("rentalEndDateMonthProperty", enddate.substring(5, 7)); -// result.put("rentalEndDateDayProperty", enddate.substring(8)); -// double pricePropertyFirst = new BigDecimal(priceProperty) -// .multiply(new BigDecimal(receivePeriodProperty)) -// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("pricePropertyFirst", pricePropertyFirst); -// result.put("pricePropertyFirstUpper", PriceUtil.digitUppercase(pricePropertyFirst)); -// -// -// //物业保证金 -// int cashDepositMonthProperty = 3; -// double cashDepositProperty = new BigDecimal(propertyContract.getPrice().toString()).multiply(new BigDecimal(cashDepositMonthProperty)) -// .divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); -// result.put("cashDepositMonthProperty", cashDepositMonthProperty); -// result.put("cashDepositProperty", cashDepositProperty); -// result.put("cashDepositPropertyUpper", PriceUtil.digitUppercase(cashDepositProperty)); -// -// -// } else { -// result.put("receivePeriodProperty", " "); -// result.put("priceProperty", " "); -// result.put("unitPriceProperty", " "); -// result.put("pricePropertyUpper", " "); -// result.put("unitPricePropertyUpper", " "); -// //首期物业费 -// result.put("rentalStartDateProperty", " "); -// result.put("rentalStartDateYearProperty", " "); -// result.put("rentalStartDateMonthProperty", " "); -// result.put("rentalStartDateDayProperty", " "); -// //结束时间 -// result.put("rentalEndDateProperty", " "); -// result.put("rentalEndDateYearProperty", " "); -// result.put("rentalEndDateMonthProperty", " "); -// result.put("rentalEndDateDayProperty", " "); -// result.put("pricePropertyFirst", " "); -// result.put("pricePropertyFirstUpper", " "); -// //物业保证金 -// result.put("cashDepositMonthProperty", " "); -// result.put("cashDepositProperty", " "); -// result.put("cashDepositPropertyUpper", " "); -// } -// -// -// return result; -// } - -// 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); -// //常规租期 -// for (int i = 0; i <= count; i++) { -// //开始时间 -// Calendar instance = Calendar.getInstance(); -// instance.setTime(wxRentContract.getRentalStartDate()); -// instance.add(Calendar.MONTH, lease * i); -// Date starttime = instance.getTime(); -// String startdate = DateUtils.date2String(starttime, "yyyy-MM-dd"); -// result.put("rentalStartDate" + i, startdate); -// result.put("rentalStartDateYear" + i, startdate.substring(0, 4)); -// result.put("rentalStartDateMonth" + i, startdate.substring(5, 7)); -// result.put("rentalStartDateDay" + i, startdate.substring(8)); -// //结束时间 -// instance.clear(); -// instance.setTime(starttime); -// instance.add(Calendar.MONTH, lease); -// instance.add(Calendar.DAY_OF_MONTH, -1); -// Date endtime = instance.getTime(); -// String enddate = DateUtils.date2String(endtime, "yyyy-MM-dd"); -// result.put("rentalEndDate" + i, enddate); -// result.put("rentalEndDateYear" + i, enddate.substring(0, 4)); -// result.put("rentalEndDateMonth" + i, enddate.substring(5, 7)); -// result.put("rentalEndDateDay" + i, enddate.substring(8)); -// String ratio = new BigDecimal(integers.get(i)).divide(new BigDecimal(100)).toPlainString(); -// result.put("adjustRatio" + i, ratio); -// result.put("adjustPeriod" + i, wxRentContract.getAdjustPeriod()); -// Integer tempPayRatio = Optional.ofNullable(wxRentContract.getPayRatio()).orElse(0); -// String payRatio = new BigDecimal(tempPayRatio).divide(new BigDecimal(100)).toPlainString(); -// result.put("payRatio" + i, payRatio); -// -// } -// if (extracount > 0) { -// //额外租期 -// //开始时间 -// Calendar instance = Calendar.getInstance(); -// instance.setTime(wxRentContract.getRentalStartDate()); -// instance.add(Calendar.MONTH, lease * count); -// Date starttime = instance.getTime(); -// String startdate = DateUtils.date2String(starttime, "yyyy-MM-dd"); -// result.put("rentalStartDate" + count, startdate); -// result.put("rentalStartDateYear" + count, startdate.substring(0, 4)); -// result.put("rentalStartDateMonth" + count, startdate.substring(5, 7)); -// result.put("rentalStartDateDay" + count, startdate.substring(8)); -// //结束时间 -// instance.clear(); -// instance.setTime(starttime); -// instance.add(Calendar.MONTH, extralease); -// instance.add(Calendar.DAY_OF_MONTH, -1); -// Date endtime = instance.getTime(); -// String enddate = DateUtils.date2String(endtime, "yyyy-MM-dd"); -// result.put("rentalEndDate" + count, enddate); -// result.put("rentalEndDateYear" + count, enddate.substring(0, 4)); -// result.put("rentalEndDateMonth" + count, enddate.substring(5, 7)); -// result.put("rentalEndDateDay" + count, enddate.substring(8)); -// result.put("adjustRatio" + count, wxRentContract.getAdjustRatio()); -// result.put("adjustPeriod" + count, wxRentContract.getAdjustPeriod()); -// Integer tempPayRatio = Optional.ofNullable(wxRentContract.getPayRatio()).orElse(0); -// String payRatio = new BigDecimal(tempPayRatio).divide(new BigDecimal(100)).toPlainString(); -// result.put("payRatio" + count, payRatio); -// -// } -// //无数据租期 -// for (int i = paycount; i <= 10; i++) { -// result.put("rentalStartDate" + i, "/"); -// result.put("rentalStartDateYear" + i, "/"); -// result.put("rentalStartDateMonth" + i, "/"); -// result.put("rentalStartDateDay" + i, "/"); -// result.put("rentalEndDate" + i, "/"); -// result.put("rentalEndDateYear" + i, "/"); -// result.put("rentalEndDateMonth" + i, "/"); -// result.put("rentalEndDateDay" + i, "/"); -// result.put("adjustRatio" + i, "/"); -// result.put("adjustPeriod" + i, "/"); -// result.put("payRatio" + i, "/"); -// } -// } - - public void areaWay(WxRentContract wxRentContract, Map result, Integer lease, int extralease, int extracount, int paycount, int index, int count, BigDecimal rentPrice) { - - String[] priceArrs = new String[]{}; - List adjustRatioList = new ArrayList<>(); - adjustRatioList.add(0, "0"); - if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { - String rentInfo = wxRentContract.getRentInfo(); - JSONArray objects = JSONArray.parseArray(rentInfo); - JSONObject jsonObject = objects.getJSONObject(0); - JSONArray adjustRatio = jsonObject.getJSONArray("adjustRatio"); - for (int i = 0, size = adjustRatio.size(); i < size; i++) { - StringBuffer adjustRatioStr = new StringBuffer(); - for (int j = 0, shopSize = objects.size(); j < shopSize; j++) { - JSONObject shopObject = objects.getJSONObject(j); - JSONArray adjustRatioArr = shopObject.getJSONArray("adjustRatio"); - String shopNumber = shopObject.getString("shopNumber"); - adjustRatioStr.append(shopNumber).append("[").append(adjustRatioArr.getString(i)).append("]"); - } - adjustRatioList.add(adjustRatioStr.toString()); - } - List priceList = WxRentContractHelper.computeRentPriceByShop(wxRentContract); - int size = priceList.size(); - priceArrs = new String[size]; - for (int i = 0; i < size; i++) { - String[] priceInt = priceList.get(i); - BigDecimal sum = new BigDecimal(0); - for (String p : priceInt) { - sum = sum.add(new BigDecimal(p)); - } - priceArrs[i] = sum.toPlainString(); - } - } else { - String adjustRatio = wxRentContract.getAdjustRatio(); - List integers = JSONArray.parseArray(adjustRatio, Integer.class); - for (int i = 0, size = integers.size(); i < size; i++) { - double ratioStr = new BigDecimal(integers.get(i)).divide(new BigDecimal(100)).doubleValue(); - adjustRatioList.add(String.valueOf(ratioStr)); - } - } - String payRatioStr = "0"; - if (wxRentContract.getPayRatio() != null) { - payRatioStr = new BigDecimal(wxRentContract.getPayRatio()).divide(new BigDecimal(100)).toPlainString(); - } - //常规租期 - for (int i = 0; i <= count; i++) { - //开始时间 - Calendar instance = Calendar.getInstance(); - instance.setTime(wxRentContract.getRentalStartDate()); - instance.add(Calendar.MONTH, lease * i); - Date starttime = instance.getTime(); - String startdate = DateUtils.date2String(starttime, "yyyy-MM-dd"); - result.put("rentalStartDate" + i, startdate); - result.put("rentalStartDateYear" + i, startdate.substring(0, 4)); - result.put("rentalStartDateMonth" + i, startdate.substring(5, 7)); - result.put("rentalStartDateDay" + i, startdate.substring(8)); - //结束时间 - instance.clear(); - instance.setTime(starttime); - instance.add(Calendar.MONTH, lease); - instance.add(Calendar.DAY_OF_MONTH, -1); - Date endtime = instance.getTime(); - String enddate = DateUtils.date2String(endtime, "yyyy-MM-dd"); - result.put("rentalEndDate" + i, enddate); - result.put("rentalEndDateYear" + i, enddate.substring(0, 4)); - result.put("rentalEndDateMonth" + i, enddate.substring(5, 7)); - result.put("rentalEndDateDay" + i, enddate.substring(8)); - - if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { - rentPrice = new BigDecimal(priceArrs[i]).divide(new BigDecimal(100)).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_EVEN); - result.put("priceRentUpper" + i, PriceUtil.digitUppercase(rentPrice.doubleValue())); - result.put("priceRent" + i, rentPrice.toPlainString()); - result.put("adjustRatio" + i, adjustRatioList.get(i)); - } else { - rentPrice = rentPrice.multiply(new BigDecimal(adjustRatioList.get(i))) - .add(rentPrice).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_EVEN); - result.put("priceRentUpper" + i, PriceUtil.digitUppercase(rentPrice.doubleValue())); - result.put("priceRent" + i, rentPrice.toPlainString()); - result.put("adjustRatio" + i, adjustRatioList.get(i)); - } - result.put("payRatio" + i, payRatioStr); - result.put("adjustPeriod" + i, wxRentContract.getAdjustPeriod()); - } - if (extracount > 0) { - //额外租期 - //开始时间 - Calendar instance = Calendar.getInstance(); - instance.setTime(wxRentContract.getRentalStartDate()); - instance.add(Calendar.MONTH, lease * count); - Date starttime = instance.getTime(); - String startdate = DateUtils.date2String(starttime, "yyyy-MM-dd"); - result.put("rentalStartDate" + count, startdate); - result.put("rentalStartDateYear" + count, startdate.substring(0, 4)); - result.put("rentalStartDateMonth" + count, startdate.substring(5, 7)); - result.put("rentalStartDateDay" + count, startdate.substring(8)); - //结束时间 - instance.clear(); - instance.setTime(starttime); - instance.add(Calendar.MONTH, extralease); - instance.add(Calendar.DAY_OF_MONTH, -1); - Date endtime = instance.getTime(); - String enddate = DateUtils.date2String(endtime, "yyyy-MM-dd"); - result.put("rentalEndDate" + count, enddate); - result.put("rentalEndDateYear" + count, enddate.substring(0, 4)); - result.put("rentalEndDateMonth" + count, enddate.substring(5, 7)); - result.put("rentalEndDateDay" + count, enddate.substring(8)); - - if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { - rentPrice = new BigDecimal(priceArrs[count]).divide(new BigDecimal(100)).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_EVEN); - result.put("priceRentUpper" + count, PriceUtil.digitUppercase(rentPrice.doubleValue())); - result.put("priceRent" + count, rentPrice.toPlainString()); - } else { - rentPrice = rentPrice.multiply(new BigDecimal(adjustRatioList.get(count))) - .add(rentPrice).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_EVEN); - result.put("priceRentUpper" + count, PriceUtil.digitUppercase(rentPrice.doubleValue())); - result.put("priceRent" + count, rentPrice.toPlainString()); - } - - } - //无数据租期 - for (int i = paycount; i <= 10; i++) { - result.put("rentalStartDate" + i, "/"); - result.put("rentalStartDateYear" + i, "/"); - result.put("rentalStartDateMonth" + i, "/"); - result.put("rentalStartDateDay" + i, "/"); - result.put("rentalEndDate" + i, "/"); - result.put("rentalEndDateYear" + i, "/"); - result.put("rentalEndDateMonth" + i, "/"); - result.put("rentalEndDateDay" + i, "/"); - result.put("priceRentUpper" + i, "/"); - result.put("priceRent" + i, "/"); - result.put("adjustRatio" + i, "/"); - result.put("payRatio" + i, "/"); - result.put("adjustPeriod" + i, "/"); - } - } - - - @Override - public void updateApplyStatus(WxRentContract wxRentContract) { - wxRentContractMapper.updateApplyStatus(wxRentContract); - } - -// @Override -// public Integer getShopType(WxRentContract wxRentContract) { -// return wxRentContractMapper.getShopType(wxRentContract); -// } - - - - public static List initBillTimeList(Date start,Date end,Integer adjustPeriod,Integer dayType,int receivePeriod){ - List list = new ArrayList<>(); - - int count = 0; - while (true){ - BillTimeVo timeVo = new BillTimeVo(); - - //开始时间 - timeVo.setStartDate(start); - - //账单日 - Calendar instance = Calendar.getInstance(); - instance.setTime(start); - if(!adjustPeriod.equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ - instance.add(Calendar.DATE, -1); - } - timeVo.setReceiveDate(instance.getTime()); - - //结束时间 - instance.clear(); - instance.setTime(start); - instance = EnumContractReceivePeriodUnit.getAfterCalendarDay(instance, receivePeriod, dayType); - //instance.add(dayType, receivePeriod); - //instance.add(Calendar.DATE, -1); - timeVo.setEndDate(instance.getTime()); - - //自然月 - if(adjustPeriod.equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ - if(count == 0){ - timeVo.setEndDate(EnumContractReceivePeriodUnit.getAfterCalendarNarDay(timeVo.getStartDate(), receivePeriod, dayType)); - /** - if(receivePeriod == 1) { //周期1个月 头一个月到当月底 头一个月或者头一个季度 - timeVo.setEndDate(DateUtils.getLastDayForMonth(timeVo.getStartDate())); - }else{ - Date firstDay = DateUtils.getFirstDayForCurrMonth(start); - instance.clear(); - instance.setTime(firstDay); - //最后一个期有余,加上残月,不整除时,最后一个月有余,否则为0 - instance.add(dayType, receivePeriod); - instance.add(Calendar.DAY_OF_MONTH, -1); - timeVo.setEndDate(instance.getTime()); - }*/ - } - } - - 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.SECOND,1); - - if(start.after(end)) { - break; - } - count ++; - - //预警 - if(count >= 1000){ - Logger logger = LoggerFactory.getLogger(WxRentContractServiceImpl.class); - logger.error("initBillTimeList() warnCount max error !!!"); - break; - } - } - return list; - } - - - @Override - public WxRentContract getByBill(WxBillRent billRent) { - return wxRentContractMapper.getByBill(billRent); - } - -// @Override -// public Map selectRentContractByShopIds(Collection shopIds, String shopIdsRegexp, TenantEntity tenantEntity) { -// List list = wxRentContractMapper.selectRentContractByShopIds(shopIds, shopIdsRegexp, tenantEntity.getTenantId(), tenantEntity.getParentTenantId()); -// List shopIdArr = Arrays.asList(StringUtils.split(shopIdsRegexp,"|")) ; -// Map allShopContract = new HashMap<>(); -// for (WxRentContract wxRentContract : list) { -// if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { -// String rentInfo = wxRentContract.getRentInfo(); -// JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); -// int size = rentInfoArray.size(); -// //查询rent_info 包括 shopId -// for (int i = 0; i < size; i++) { -// JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); -// Long shopId = rentInfoObject.getLong("shopId"); -// if (!shopIdArr.contains(String.valueOf(shopId))) { -// continue; -// } -// WxRentContract rentContract = new WxRentContract(); -// BeanUtils.copyProperties(wxRentContract,rentContract); -// rentContract.setRentalStartDate(wxRentContract.getRentalStartDate()); -// rentContract.setRentalEndDate(wxRentContract.getRentalEndDate()); -// rentContract.setShopId(shopId); -// allShopContract.put(shopId, rentContract); -// } -// } -// if (shopIds.contains(wxRentContract.getShopId())) { -// allShopContract.put(wxRentContract.getShopId(), wxRentContract); -// } -// } -// return allShopContract; -// } - -// @Override -// public int selectContractCountByShopId(WxRentContract wxRentContract) { -// return wxRentContractMapper.selectContractCountByShopId(wxRentContract) ; -// } - - @Override - public ResultData getContractByContractNumber(WxRentContract rentContract) { - WxRentContract wxRentContract = wxRentContractMapper.selectOne(new QueryWrapper<>(rentContract)); - return new ResultData(wxRentContract); - } - - @Override - public ResultData apply(WxRentContract rentContract,MallUserInfo user) { - //如果存在审批中的合同,不允许提交审批 - WxRentContract wrq = new WxRentContract(); - wrq.updateTenantInfo(user); - wrq.setMerchantId(rentContract.getMerchantId()); - wrq.setStatus(EnumRentContractStatus.PERFORMANCE.getCode()); - List clist = wxRentContractMapper.findList(wrq); - if (null != clist && clist.size() > 0 ) { - return new ResultData(Result.ERROR, "当前商户存在其他审批中的租金合同。请先作完成。"); - } - //如果该合同是租金+物业合同,则还要判断物业合同 - if(rentContract.getOperationType().intValue() == EnumContractOperationType.WHOLE.getCode().intValue()) { - WxPropertyContract wpc = new WxPropertyContract(); - wpc.updateTenantInfo(user); - wpc.setMerchantId(rentContract.getMerchantId()); - wpc.setStatus(EnumRentContractStatus.PERFORMANCE.getCode()); - List plist = wxPropertyContractMapper.findList(wpc); - if (null != plist && plist.size() > 0 ) { - return new ResultData(Result.ERROR, "当前商户存在其他审批中的物业合同。请先作完成。"); - } - } -// Integer count = wxRentContractMapper.getCanApplyCount(rentContract.getId()); -// if (null != count && count.intValue()>0) { -// return new ResultData(Result.ERROR, "当前存在其他草稿状态或者履约驳回的合同。请先作废其他草稿或者审批拒绝或者撤回的合同。"); -// } - - if (CollectionUtils.isEmpty(rentContract.getFlowParams())) { - return new ResultData(Result.ERROR, "编号["+rentContract.getId()+"]租金合同没有审批流程."); - } - - if (rentContract.getMerchantId() == null) { - return new ResultData(Result.ERROR, "编号["+rentContract.getId()+"]租金合同没有绑定商户."); - } - - if ((EnumRentContractStatus.DRAFT.getCode().intValue() == rentContract.getStatus().intValue()) - || (EnumRentContractStatus.PERFORMANCE.getCode().intValue() == rentContract.getStatus().intValue() - && (EnumRentContractAppStatus.REJECT.getCode().intValue() == rentContract.getApplyStatus().intValue() || - EnumRentContractAppStatus.SETBACK.getCode().intValue() == rentContract.getApplyStatus().intValue())) - ) { - Integer bussinessType = (Integer) rentContract.getFlowParams().get("businessType"); - if (null == bussinessType) { - return new ResultData(Result.ERROR, "编号["+rentContract.getId()+"]租金合同FlowParams错误,未找到businessType."); - } - WxFlowModel flowModle = wxFlowService.getModelByType(bussinessType, rentContract); - if (null == flowModle) { - return new ResultData(Result.ERROR, "编号["+rentContract.getId()+"]租金合同配置的流程["+String.valueOf(bussinessType)+"]未找到流程模板."); - } - //rentContract.getFlowParams().put("businessId", rentContract.getId().toString()); - wxFlowService.start(rentContract.getFlowParams(), user.getId(), user.getName(), rentContract); - return new ResultData(Result.SUCCESS,"提交审批成功",rentContract); - }else { - return new ResultData(Result.ERROR, "编号["+rentContract.getId()+"]租金合同状态不能提交审批.允许提交的状态为 [草稿],[履约中+审批驳回]"); - } - } - - @Override - @Transactional(rollbackFor = {Exception.class}) - public void outDateContract(WxMall wxMall) { - //查询有计租合同的商户 - WxRentContract wr = new WxRentContract(); - wr.setStatuss(EnumRentContractStatus.getValidStatus()); - wr.updateTenantInfo(wxMall); - List merchantIds = wxRentContractMapper.getMerchantIdsByStatuss(wr); - for (Long mid: merchantIds) { - if (null == mid) { - continue; - } - try { - //查询商户下计租到期的合同,更新合同状态 - WxRentContract wrc = new WxRentContract(); - wrc.setMerchantId(mid); - wrc.setStatus(EnumRentContractStatus.PAING.getCode()); - List contractList = wxRentContractMapper.findList(wrc); - List shopIdList = new ArrayList(); - for (WxRentContract contract:contractList) { - if (contract.getRentalEndDate().before(new Date())) { - contract.setStatus(EnumRentContractStatus.OUT_DATE.getCode()); - wxRentContractMapper.updateById(contract); - List shopIds = contract.shopIdsByRentInfo(); - for (Long sid: shopIds) { - if (!shopIdList.contains(sid)) { - shopIdList.add(sid); - } - } - } - } - - //到期合同中的店铺,如果存在有效合同,则不释放 - if (shopIdList.size() > 0 ) { - WxRentContract wrcq = new WxRentContract(); - wrcq.setMerchantId(mid); - wrcq.setStatuss(EnumRentContractStatus.getValidStatus()); - List contractList0 = wxRentContractMapper.findList(wrcq); - for (WxRentContract w : contractList0) { - List shopids0 = w.shopIdsByRentInfo(); - if (null != shopids0) { - shopIdList.removeAll(shopids0); - } - } - } - - //释放店铺 -// if (null != shopIdList && shopIdList.size() > 0) { -// wxMerchantShopMapper.delShops(mid, shopIdList); -// //更新商铺的状态为未出租 -// wxShopMapper.updateUnRentByIds(shopIdList); -// } - }catch(Exception e) { - logger.error("merchantId["+mid+"] outDateContract error.",e); - } - - } - } - - @Override - public void readyToNomal(WxMall wxMall) { - WxRentContract wr = new WxRentContract(); - wr.setStatus(EnumRentContractStatus.READY_FOR_PAING.getCode()); - wr.updateTenantInfo(wxMall); - List rentList = wxRentContractMapper.findList(wr); - if (null != rentList && rentList.size() > 0 ) { - for (WxRentContract wrc : rentList) { - if (wrc.getRentalStartDate().before(new Date())) { - wrc.setStatus(EnumRentContractStatus.PAING.getCode()); - wxRentContractMapper.updateStatus(wrc); - } - } - } - } - - @Override - public WxRentContract getSimpleDeatil(Long id) { - return wxRentContractMapper.selectById(id); - } - - @Override - public boolean hasOtherValidContractShop(WxRentContract wxRentContract) { - WxRentContract wrc = new WxRentContract(); - wrc.setMerchantId(wxRentContract.getMerchantId()); - wrc.setStatuss(EnumRentContractStatus.getValidStatus()); - List contractList = wxRentContractMapper.findList(wrc); - boolean exists =false; - for (WxRentContract wc : contractList) { - if (null != wxRentContract.shopIdsByRentInfo()) { - for (Long sid : wxRentContract.shopIdsByRentInfo()) { - if(wc.getRentInfo().indexOf(String.valueOf(sid)) != -1 ) { - exists = true; - break; - } - } - } - } - return exists; - } - - @Override - public Map findRentByShop(Long shopId) { - List> rentByShop = wxRentContractMapper.findRentByShop(shopId); - if(rentByShop != null && rentByShop.size() > 0){ - return rentByShop.get(0); - } - return null; - } - - @Override - public Map currentValidByMerchantId(TenantEntity tenantInfo, Long merchantId,String shopNumber) { - WxRentContract rentContract = new WxRentContract(); - rentContract.updateTenantInfo(tenantInfo); - rentContract.setMerchantId(merchantId); - rentContract.setShopNumber(shopNumber); - List statuss = new ArrayList<>(); - statuss.add(EnumRentContractStatus.READY_FOR_PAING.getCode()); - statuss.add(EnumRentContractStatus.PAING.getCode()); - rentContract.setStatuss(statuss); - List> rentContracts = wxRentContractMapper.currentValidByMerchantId(rentContract); - if(rentContracts != null && rentContracts.size() > 0){ - return rentContracts.get(0); - } - return null; - } - - @Override - public long findCount(WxRentContract wxRentContract) { - TenantEntity tenantEntity = new TenantEntity(); - tenantEntity.setTenantId(wxRentContract.getTenantId()); - tenantEntity.setParentTenantId(wxRentContract.getParentTenantId()); - List tenantEntitys = wxMallService.getTenantEntitys(tenantEntity); - long count = 0l; - for (TenantEntity te:tenantEntitys) { - wxRentContract.updateTenantInfo(te); - count += wxRentContractMapper.findCount(wxRentContract); - } - wxRentContract.updateTenantInfo(tenantEntity); - return count; - } - - @Override - public void setEndContractTime(WxRentContract wxRentContract) { - wxRentContractMapper.setEndContractTime(wxRentContract); - } - - @Override - public List findToEndContractList(WxRentContract record) { - return wxRentContractMapper.findToEndContractList(record); - } - - @Override - public List findToOutDateContracts(TenantEntity tenantEntity) { - WxRentContract wrc = new WxRentContract(); - wrc.setStatus(EnumRentContractStatus.PAING.getCode()); - wrc.setOutDateNofity(1); - return wxRentContractMapper.findList(wrc); - } - - public static void main(String[] args) { - System.out.println(DateUtils.getDayBegin(DateUtils.getFirstDayOfNextMonth(new Date(),-1))); - } - - @Override - public void calcuteByTradeDaily(WxRentContract wxRentContract) { - WxPayAccountBill wxPayAccountBill = wxPayAccountBillService.getByTenantInfo(wxRentContract); - //查询合同下截止时间为昨天的账单 - WxBillRent bq = new WxBillRent(); - bq.updateTenantInfo(wxRentContract); - bq.setRentContractId(wxRentContract.getId()); - bq.setIsPreview(EnumIsPreview.NO.getCode()); - Date current = new Date(); - //从上个月1号开始的都更新 - bq.setEndtimeBegin(DateUtils.getDayBegin(DateUtils.getFirstDayOfNextMonth(current,-1))); - bq.setEndtimeEnd(current); - bq.setIsDel(EnumDelStatus.NOT_DEL.getCode()); - List billList = wxBillRentMapper.findList(bq); - if (null != billList && billList.size() > 0 ) { - for (int j = 0 ; j < billList.size(); j++) { - WxBillRent br = billList.get(j); - try { - //判断账单是否跨月,如果跨月,需要按照每月来查询解单金额 - BigDecimal needPay = new BigDecimal(0) ; - int months = DateUtils.monthsBetween(br.getStarttime(), br.getEndtime()); - if ( months > 0 ) { - for (int i = 0 ; i <= months ; i++ ) { - BigDecimal _money = new BigDecimal(0); - if (i == 0 ) { - _money = sumTradeDailyBySameMonthDay(Constant.default_long_decimal_size,bq, wxRentContract.getMerchantId(), br.getStarttime(), - DateUtils.getLastDayForMonth(br.getStarttime())); - }else if (i == months){ - _money = sumTradeDailyBySameMonthDay(Constant.default_long_decimal_size,bq, wxRentContract.getMerchantId(), - DateUtils.getFirstDayForCurrMonth(DateUtils.getTimeAfterMonths(i,br.getStarttime())), - DateUtils.getDayEnd(DateUtils.getTimeAfterDays(-1, br.getEndtime()))); - }else { - Date _date = DateUtils.getTimeAfterMonths(i,br.getStarttime()); - _money = sumTradeDailyBySameMonthDay(Constant.default_long_decimal_size,bq, wxRentContract.getMerchantId(), - DateUtils.getFirstDayForCurrMonth(_date), - DateUtils.getLastDayForMonth(_date)); - } - needPay = needPay.add(_money); - } - }else { - //同一个月 - //合同账单结束的时间是00:00:00,取日期要取前一天 - needPay = sumTradeDailyBySameMonthDay(Constant.default_long_decimal_size,bq, wxRentContract.getMerchantId(), - br.getStarttime(), DateUtils.getDayEnd(br.getEndtime())); - } - needPay = needPay.multiply(new BigDecimal(wxRentContract.getPayRatio())) - .divide(new BigDecimal(10000), wxRentContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP); - String oldNeedPay = br.getNeedPay(); - if (needPay.compareTo(new BigDecimal(br.getNeedPay())) > 0) { - br.setNeedPay(needPay.toPlainString()); - //br.setOwe(needPay.toPlainString()); - br.setReceivePay(needPay.toPlainString()); - br.setUpdatetime(new Date()); - BigDecimal servicePay = new BigDecimal(br.getReceivePay()).multiply(new BigDecimal(wxPayAccountBill.getServiceChargeRate())).divide(new BigDecimal(10000), wxRentContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP); - br.setServiceChargePay(servicePay.toPlainString()); - //br.setOwe(new BigDecimal(br.getReceivePay()).add(new BigDecimal(br.getServiceChargePay())).toPlainString()); - //br.setOwe(new BigDecimal(br.getReceivePay()).toPlainString()); - br.setComments("原金额["+oldNeedPay+"(分)]小于解单金额["+needPay+"(分)],系统自动更新"); - wxBillRentMapper.updateById(br); - } - }catch(Exception e) { - logger.error("calcuteByTradeDaily error:"+br.getId(),e); - } - } - } - } - - private BigDecimal sumTradeDailyBySameMonthDay(Integer decimalSize,TenantEntity tenantEntity,Long merchantId,Date begin ,Date end) { - //如果有按月的,则取按月来算 - WxMerchantTradeDaily tdq = new WxMerchantTradeDaily(); - tdq.updateTenantInfo(tenantEntity); - tdq.setMerchantId(merchantId); - tdq.setDateType(EnumTradeDailyDateType.MONTH.getCode()); - tdq.setReportDate(DateUtils.date2String(begin, DateUtils.DATE_PATTERN_MONTH)); - List monthList = wxMerchantTradeDailyMapper.findList(tdq); - if (null != monthList && monthList.size() > 0 ){ - int monthSums = monthList.get(0).getTradeAmtInteger(); - Date _fistDay = DateUtils.getDayBegin(DateUtils.getFirstDayForCurrMonth(begin)); - Date _lastDay = DateUtils.getLastDayForMonth(begin); - if (begin.equals(_fistDay) && end.equals(_lastDay)) { - //满月 - return new BigDecimal(monthSums); - }else { - //根据天数计算 - int monthDays = DateUtils.daysBetween(_fistDay, _lastDay)+1; - int _days = DateUtils.daysBetween(begin, end)+1; - if (_days == 0) { - _days = 1;//当天 - } - BigDecimal servicePay = new BigDecimal(monthSums).multiply(new BigDecimal(_days)).divide(new BigDecimal(monthDays), decimalSize, BigDecimal.ROUND_HALF_UP); - return servicePay; - } - }else { - WxMerchantTradeDaily tdq1 = new WxMerchantTradeDaily(); - tdq1.updateTenantInfo(tenantEntity); - tdq1.setMerchantId(merchantId); - tdq1.setDateType(EnumTradeDailyDateType.DAY.getCode()); - tdq1.setStartTime(DateUtils.format(begin)); - tdq1.setEndTime(DateUtils.format(end)); - String sumMoney = wxMerchantTradeDailyMapper.findSumMoney(tdq1); - return new BigDecimal(sumMoney); - } - } - - @Override - public List findDepositTypes(WxRentContractDepositType rentContract) { - return wxRentContractDepositTypeMapper.findList(rentContract); - } - - private Map findDepositTypesMap(WxRentContractDepositType rentContract) { - List types = findDepositTypes(rentContract); - if (null != types && types.size() > 0 ) { - Map tmap = new HashMap(); - for (int i = 0 ; i < types.size(); i++ ) { - WxRentContractDepositType dt = types.get(i); - tmap.put(dt.getId(), dt); - } - return tmap; - } - return null; - } - - @Override - public void saveOrUpdateDepositType(WxRentContractDepositType rentContract) { - if (null == rentContract.getId()) { - final IdWorker idWorker = IdWorker.get(); - rentContract.setId(idWorker.nextId()); - rentContract.setCreateTime(new Date()); - rentContract.setUpdateTime(new Date()); - wxRentContractDepositTypeMapper.insert(rentContract); - }else { - rentContract.setUpdateTime(new Date()); - wxRentContractDepositTypeMapper.updateById(rentContract); - } - } -} + wxBillRent.setIsDel(EnumDelStatus.NOT_DEL.getCode()); + wxBillRent.setRentShopType(wxRentContract.getRentShopType()); + wxBillRent.setPeriod(++billcount); + wxBillRent.setShopInfo(shopInfoStr); + wxBillRent.setLatePayRatio(0); + wxBillRent.calcuteTotalFee(wxRentContract.getDecimalSize()); + + //计算手续费 + BigDecimal servicePay = new BigDecimal(wxBillRent.getReceivePay()).multiply(new BigDecimal(wxPayAccountBill.getServiceChargeRate())) + .divide(new BigDecimal(10000), wxRentContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP); + wxBillRent.setServiceChargePay(servicePay.toPlainString()); + //wxBillRent.setOwe(new BigDecimal(wxBillRent.getReceivePay()).add(new BigDecimal(wxBillRent.getServiceChargePay())).toPlainString()); + //wxBillRent.setOwe(new BigDecimal(wxBillRent.getReceivePay()).toPlainString()); + resultList.add(wxBillRent); + + + //商业管理费账单 + if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0 && new BigDecimal(bussinessManageFeeNeedpay).compareTo(new BigDecimal(0)) > 0) { + manageList.add(setManageRent(wxRentContract.getDecimalSize(),wxBillRent,EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE,bussinessManageFeeNeedpay,wxPayAccountBill.getServiceChargeRate(),dayType,receivePeriod)); + } + //营业管理费账单 + if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0 && new BigDecimal(operatingManageFeeNeedpay).compareTo(new BigDecimal(0)) > 0 ) { + manageList.add(setManageRent(wxRentContract.getDecimalSize(),wxBillRent,EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE,operatingManageFeeNeedpay,wxPayAccountBill.getServiceChargeRate(),dayType,receivePeriod)); + } + } + + //批量插入账单 + if(saveDb) { + wxBillRentMapper.insertBills(wxRentContract.getTenantId(),resultList); + if (manageList.size() > 0 ) { + wxBillRentManageMapper.insertBills(wxRentContract.getTenantId(),manageList); + } + } + resultMap.put("billcount",billcount); + resultMap.put("billList",resultList); + return resultMap; + } + + + private WxBillRentManage setManageRent(Integer decimalSize,WxBillRent wxBillRent,EnumRentContractManageFeeType feeType,String needPay,Integer serviceChargeRate,int dayType,int receivePeriod) { + WxBillRentManage manage = new WxBillRentManage(); + manage.initByBillRent(wxBillRent); + final IdWorker idWorker = IdWorker.get(); + wxBillRent.setId(idWorker.nextId()); + manage.setManageFeeType(feeType.getCode()); + manage.setNeedPay(needPay); + manage.setReceivePay(needPay); + //manage.setOwe(needPay); + //setManageExpiredDay(manage,dayType,receivePeriod); + //计算手续费 + BigDecimal servicePay = new BigDecimal(needPay).multiply(new BigDecimal(serviceChargeRate)).divide(new BigDecimal(10000), decimalSize, BigDecimal.ROUND_HALF_UP); + manage.setServiceChargePay(servicePay.toPlainString()); + //manage.setOwe(new BigDecimal(needPay).add(new BigDecimal(manage.getServiceChargePay())).toPlainString()); + //manage.setOwe(new BigDecimal(needPay).toPlainString()); + return manage; + } + +// public void setExpiredDay(WxBillRent wxBillRent,int dayType, int receivePeriod){ +// //截止收租日在当前时间之前 +// Date date = new Date(); +// wxBillRent.setExpiredDay(0L); +// if (wxBillRent.getReceiveDate().before(date)) { +// long day = (date.getTime() - wxBillRent.getReceiveDate().getTime()) / (24 * 60 * 60 * 1000); +// wxBillRent.setStatus(EnumBillStatus.NOT_PAID.getCode()); +// if (day > 0) { +// wxBillRent.setExpiredDay(day); +// } +// } else {//截止收租日在当前时间之后 +// Calendar now = Calendar.getInstance(); +// now.add(dayType, receivePeriod); +// Date currenttime = now.getTime(); +// //当前日期加上周期后小于截止收租日就是没有到期,否则当前待缴 +// if (currenttime.before(wxBillRent.getReceiveDate())) { +// wxBillRent.setStatus(EnumBillStatus.NOT_EXPIRED.getCode()); +// } else { +// wxBillRent.setStatus(EnumBillStatus.WAIT_PAY.getCode()); +// } +// } +// } + +// public void setManageExpiredDay(WxBillRentManage wxBillRentManage,int dayType, int receivePeriod){ +// //截止收租日在当前时间之前 +// Date date = new Date(); +// wxBillRentManage.setExpiredDay(0L); +// if (wxBillRentManage.getReceiveDate().before(date)) { +// long day = (date.getTime() - wxBillRentManage.getReceiveDate().getTime()) / (24 * 60 * 60 * 1000); +// wxBillRentManage.setStatus(EnumBillStatus.NOT_PAID.getCode()); +// if (day > 0) { +// wxBillRentManage.setExpiredDay(day); +// } +// } else {//截止收租日在当前时间之后 +// Calendar now = Calendar.getInstance(); +// now.add(dayType, receivePeriod); +// Date currenttime = now.getTime(); +// //当前日期加上周期后小于截止收租日就是没有到期,否则当前待缴 +// if (currenttime.before(wxBillRentManage.getReceiveDate())) { +// wxBillRentManage.setStatus(EnumBillStatus.NOT_EXPIRED.getCode()); +// } else { +// wxBillRentManage.setStatus(EnumBillStatus.WAIT_PAY.getCode()); +// } +// } +// } + + @Transactional(rollbackFor = {Exception.class}) + @Override + public ResultData deleteById(String id) { + wxRentContractMapper.deleteById(id); + return new ResultData(Result.SUCCESS, "删除租赁合同信息成功"); + } + + @Override + public void download(HttpServletRequest request, HttpServletResponse response) { + String id = request.getParameter("id"); + WxRentContract wxRentContract = wxRentContractMapper.selectById(id); + String filesuffix = wxRentContract.getFilepath().substring(wxRentContract.getFilepath().lastIndexOf(".")); + String filename = UUID.randomUUID() + filesuffix; + String filepath = fmUploadDir; + String destPath = filepath + filename; + File dest = new File(destPath); + File pDest = dest.getParentFile(); + if (!pDest.exists()) { + pDest.mkdirs(); + } + try { + String exportFileName = wxRentContract.getFilename(); + DownFileUtil.downLoadFromUrl(wxRentContract.getFilepath(), filename, filepath); + DownFileUtil.downFile(destPath, exportFileName, response, request); + org.apache.commons.io.FileUtils.forceDelete(dest); + } catch (IOException e) { + logger.info("创建本地文件失败" + e.getMessage()); + } + } + +// @Transactional(rollbackFor = {Exception.class}) +// @Override +// public Object getRentContractStatusInfo(WxRentContract rentContract) { +// +// Map resultData = new HashMap(); +// //商铺信息 +// WxShop wxShop = new WxShop(); +// wxShop.updateTenantInfo(rentContract); +// wxShop.setType(rentContract.getRentShopType()); +// wxShop.setStatus(EnumShopStatus.RENT.getCode()); +// List rentedList = wxShopMapper.findList(wxShop); +// wxShop.setStatus(EnumShopStatus.NOT_RENT.getCode()); +// List unrentedList = wxShopMapper.findList(wxShop); +// +// 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); +// resultData.put("shopCountInfo", shopMap); +// +// //需要更新的状态 +// resultData.putAll(updateStatus(rentContract)); +// return resultData; +// } + + @Transactional(rollbackFor = {Exception.class}) + @Override + public ResultData endContract(WxRentContract wxRentContract,MallUserInfo userInfo) { + + WxRentContract contract = wxRentContractMapper.selectById(wxRentContract.getId()); + if (contract == null) { + return new ResultData(ErrorCode.RENT_CONTRACT_IS_NOT_FOUND); + } + contract.setStatus(EnumRentContractStatus.TERMINATE.getCode()); + contract.setUpdatetime(new Date()); + contract.setUpdateBy(userInfo.getId()); + contract.setEndContractTime(wxRentContract.getEndContractTime()); + wxRentContractMapper.updateById(contract); + + //终止租赁合同,同时终止物业合同 + if(EnumEndProperty.END_RENT_AND_PROPERTY.getCode().equals(wxRentContract.getEndProperty())){ +// WxPropertyContract wxPropertyContract = new WxPropertyContract(); +// wxPropertyContract.setRentContractId(wxRentContract.getId()); +// wxPropertyContract.setStatus(EnumRentContractStatus.TERMINATE.getCode()); +// wxPropertyContractMapper.updateStatusByRentContractId(wxPropertyContract); + WxPropertyContract wxPropertyContract = new WxPropertyContract(); + wxRentContract.updateTenantInfo(wxRentContract); + wxPropertyContract.setRentContractId(wxRentContract.getId()); + //终止有效的合同 + wxPropertyContract.setStatuss(EnumRentContractStatus.getValidStatus()); + wxPropertyContract.setUpdatetime(new Date()); + wxPropertyContract.setUpdateBy(userInfo.getId()); + wxPropertyContract.setStatus(EnumRentContractStatus.TERMINATE.getCode()); + wxPropertyContractMapper.endContract(wxPropertyContract); + //作废未生效的合同 + List unvalidstatuss = new ArrayList(); + unvalidstatuss.add(EnumRentContractStatus.DRAFT.getCode()); + unvalidstatuss.add(EnumRentContractStatus.PERFORMANCE.getCode()); + wxPropertyContract.setStatuss(unvalidstatuss); + wxPropertyContract.setStatus(EnumRentContractStatus.INVALID.getCode()); + wxPropertyContractMapper.endContract(wxPropertyContract); + + //物业账单失效 + wxBillPropertyMapper.updateInvalidStatusByRent(wxRentContract); + } + //租赁账单失效 + wxBillAllHelper.rentContractStop(wxRentContract,userInfo); +// WxBillRent wxBillRent = new WxBillRent(); +// wxBillRent.setRentContractId(wxRentContract.getId()); +// wxBillRent.updateTenantInfo(wxRentContract); +// wxBillRentMapper.updateInvalidStatus(wxBillRent); + return new ResultData(Result.SUCCESS,"终止成功"); + //解绑商户和商铺关系 +// WxRentContract rentContract = wxRentContractMapper.selectById(wxRentContract.getId()); +// if(rentContract != null && rentContract.getMerchantId() != null){ +// wxMerchantService.disable(rentContract.getMerchantId()); +// } + } + + @Transactional(rollbackFor = {Exception.class}) + @Override + public ResultData updateRentContract(WxRentContract wxRentContract) { +// WxRentContract record = wxRentContractMapper.selectById(wxRentContract); +// if (wxRentContract == null) { +// return new ResultData(ErrorCode.RENT_CONTRACT_IS_NOT_FOUND); +// } +// record.setMerchantId(wxRentContract.getMerchantId()); + try { + wxRentContractMapper.updateById(wxRentContract); + } catch (MallinkException e) { + logger.info("关联合同商户失败:" + e.getMessage()); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); + } + return new ResultData(Result.SUCCESS, "操作成功"); + } + + @Override + public PageInfo getRentContractList(WxRentContract rentContract, Integer pageIndex, Integer pageSize) { + if (StringUtils.isNoneBlank(rentContract.getFloorForRule())) { + List mids = wxMerchantService.getFloorBuildMerchantIds(rentContract, rentContract.getFloorForRule() , null, null, 0, 0); + if (null == mids || mids.size() <= 0 ) { + rentContract.setId(-1L); + } else { + rentContract.setMerchantIds(mids); + } + } + //PageInfo pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxRentContractMapper.getRentContractList(rentContract)); + PageInfo pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxRentContractMapper.findList(rentContract)); + return pageInfo; + } + +// @Override +// public Map updateStatus(WxRentContract record) { +// Map resultData = new HashMap(); +// WxRentContract wxRentContract = new WxRentContract(); +// wxRentContract.updateTenantInfo(record); +// wxRentContract.setRentShopType(record.getRentShopType()); +// +// int allCount = wxRentContractMapper.selectCount(new QueryWrapper(wxRentContract)); +// resultData.put("allCount", allCount); +// +// //待签约 +// //wxRentContract.setStatus(EnumRentContractStatus.WAIT_SIGN.getCode()); +// //int waitSignCount = wxRentContractMapper.queryRentContractWaitSignStatus(wxRentContract); +// //resultData.put("waitSignCount", waitSignCount); +// resultData.put("waitSignCount", 0); +// +// //计租中 +// wxRentContract.setStatus(EnumRentContractStatus.PAING.getCode()); +// wxRentContractMapper.updateRentContractPaidStatus(wxRentContract); +// int rendPaidCount = wxRentContractMapper.queryRentContractPaidStatus(wxRentContract); +// resultData.put("rendPaidCount", rendPaidCount); +// +// //将到期 +// //wxRentContract.setStatus(EnumRentContractStatus.CONTRACT_END_SOON.getCode()); +// //wxRentContractMapper.updateRentContractEndSoonStatus(wxRentContract); +// //int endSoonCount = wxRentContractMapper.queryRentContractEndSoonStatus(wxRentContract); +// //resultData.put("endSoonCount", endSoonCount); +// resultData.put("endSoonCount", 0); +// +// //到期 +// wxRentContract.setStatus(EnumRentContractStatus.OUT_DATE.getCode()); +// wxRentContractMapper.updateRentContractEndStatus(wxRentContract); +// int endCount = wxRentContractMapper.queryRentContractEndStatus(wxRentContract); +// resultData.put("endCount", endCount); +// +// //合同到期 +// contractEnd(record.getTenantId()); +// +// return resultData; +// } + +// @Override +// public void exportContract(HttpServletRequest request, HttpServletResponse response, Long rentId,Long propertyId) { +// String contracType = "0"; +// String templatePath = null; +// Map result = null; +// if (EnumContractType.ALL.getCode().toString().equals(contracType)) { +// logger.info("获取租赁及物业合同数据"); +// result = getRentAndPropertyInfo(rentId,propertyId); +// result.put("contractType", EnumContractType.ALL.getMessage()); +// if(EnumContractOperationType.JINMAO.getCode().equals(result.get("operationType"))){ +// templatePath = "contract-word-template/jinmao_contract_rent_property.docx"; +// }else{ +// if (EnumRentContractType.RENT_BY_AREA.getCode().equals(result.get("type"))) { +// templatePath = "contract-word-template/contract_rent_property.docx"; +// } else { +// templatePath = "contract-word-template/contract_rent_property_by_ratio.docx"; +// } +// } +// +// logger.info("租赁及物业合同数据结果:" + result); +// } +// +// if (templatePath == null) { +// logger.info("没有租赁及物业合同模板"); +// return; +// } +// String filepath = fmUploadDir; +// String filename = UUID.randomUUID() + ".docx"; +// String exportFileName = result.get("merchantName").toString() + "合同.docx"; +// WordUtil.exportWord(templatePath, filepath, filename, exportFileName, result, request, response,null); +// } + + @Override + @Transactional(rollbackFor = {Exception.class}) + public ResultData updateFile(WxRentContract record, MallUserInfo user,String userName,Date oldRentStartDate,boolean writeComplate) { + + WxRentContract wxRentContract = wxRentContractMapper.selectById(record.getId()); + if (null == wxRentContract) { + return new ResultData(Result.ERROR,"id查询不到合同"); + } + // 保存调整金额(预账单调整) + if(!CollectionUtils.isEmpty(record.getPreviewBillRentList())){ + wxRentContract.setPreviewBillRentList(record.getPreviewBillRentList()); + savePreviewBill(wxRentContract,user); + //保存商业管理费账单 + savePreviewManageFeeBill(wxRentContract,user,EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE); + //保存营业管理费账单 + savePreviewManageFeeBill(wxRentContract,user,EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE); + } + WxRentContract rc = new WxRentContract(); + rc.setId(record.getId()); + rc.setRentalStartDate(oldRentStartDate); + rc.setDecimalSize(wxRentContract.getDecimalSize()); + if (writeComplate) { + rc.setStatus(EnumRentContractStatus.DRAFT.getCode()); + }else { + rc.setStatus(wxRentContract.getStatus()); + } + rc.setFileNames(record.getFileNames()); + wxRentContractMapper.updateById(rc); + if (null != wxRentContract.getOperationType() && EnumContractOperationType.WHOLE.getCode().equals(wxRentContract.getOperationType())) { + WxPropertyContract pc = wxPropertyContractMapper.findOneByRentId(wxRentContract); + if (null != pc) { + wxRentContract.setPropertyContractId(pc.getId()); + } + } + return new ResultData(wxRentContract); + } + + @Override + public ResultData updateRentContractStatus(Long id,boolean buildProperyBill) { + if (id == null) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); + } + WxRentContract record = wxRentContractMapper.selectById(id); + if (record == null) { + return new ResultData(ErrorCode.RENT_CONTRACT_IS_NOT_FOUND); + } + //如果合同状态为非正常状态,则不更新合同状态,并删除账单 + if(record.getStatus().intValue() == EnumRentContractStatus.INVALID.getCode().intValue() + || record.getStatus().intValue() == EnumRentContractStatus.TERMINATE.getCode().intValue()) { + return new ResultData(ErrorCode.RENT_CONTRACT_IS_TERMINATED.getCode(),"合同状态已作废或者已终止."); + } + + + //更新合同状态为签约 + WxRentContract wxRentContract = new WxRentContract(); + wxRentContract.setId(id); + if (record.getRentalStartDate().before(new Date())) { + wxRentContract.setStatus(EnumRentContractStatus.PAING.getCode()); + } else { + wxRentContract.setStatus(EnumRentContractStatus.READY_FOR_PAING.getCode()); + } + wxRentContractMapper.updateById(wxRentContract); + //EventUtil.publistRentEvent(this, wxRentContract); + //建立账单 + //自定义账单无单价,为能生成账单,设置该值 + if (EnumRentContractType.RENT_BY_CUSTOMIZE.getCode() == record.getType()) { + record.setPrice("0.01"); + } + if (record != null && + record.getMerchantId() != null && + record.getReceivePeriod() != null ) { + //预览账单改为正式,并写入商户id + WxBillRent billRent = new WxBillRent(); + billRent.setRentContractId(id); + billRent.setIsPreview(EnumIsPreview.NO.getCode()); + billRent.setMerchantId(record.getMerchantId()); + billRent.updateTenantInfo(record); + wxBillRentMapper.updatePreviewStatus(billRent); +// WxMerchant wxMerchant = new WxMerchant(); +// wxMerchant.setId(record.getMerchantId()); +// wxMerchant.updateTenantInfo(record); + + //商业管理费,营业管理费 + WxBillRentManage billRentManage = new WxBillRentManage(); + billRentManage.setRentContractId(id); + billRentManage.setIsPreview(EnumIsPreview.NO.getCode()); + billRentManage.updateTenantInfo(record); + wxBillRentManageMapper.updatePreviewStatus(billRentManage); + + if(new BigDecimal(record.getDeposit()).compareTo(new BigDecimal(0)) > 0) { + //押金 + buildDeposit( null, id); + } + //一起建立物业账单 + if (buildProperyBill) { + updatePropertyPreviewBill(record); + } + + //作废合同 + //updateInvalidContract(id); + } + + return new ResultData(Result.SUCCESS, "操作成功"); + } + + @Override + public void updatePropertyPreviewBill(WxRentContract record) { + //合并合同-更新物业账单 + if (record.getOperationType().equals(EnumContractOperationType.WHOLE.getCode())) { + //查签约 + WxPropertyContract wxPropertyContract = new WxPropertyContract(); + wxPropertyContract.setRentContractId(record.getId()); + WxPropertyContract propertyContract = wxPropertyContractMapper.selectOne(new QueryWrapper(wxPropertyContract)); + logger.info("物业合同状态及账单状态修改:{}",propertyContract); + if (propertyContract != null) { + propertyContract.setMerchantId(record.getMerchantId()); + wxPropertyContractMapper.updateById(propertyContract); + wxPropertyContractService.updatePropertyContractStatus(propertyContract.getId()); + } + } + } + +// public Map getRentAndPropertyInfo(Long rentId,Long propertyId) { +// logger.info("获取租赁物业合同数据>>>>>>rentId:" + rentId +" >>>>propertyId:"+propertyId); +// Map result = new HashMap<>(); +// WxRentContract wxRentContract = wxRentContractMapper.selectById(rentId); +// +// result.put("operationType", wxRentContract.getOperationType()); +// if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { +// JSONArray jsonArray = JSONArray.parseArray(wxRentContract.getRentInfo()); +// StringBuffer shopNumberStr = new StringBuffer(); +// StringBuffer floorNameStr = new StringBuffer(); +// StringBuffer buildingNameStr = new StringBuffer(); +// StringBuffer buildAreaStr = new StringBuffer(); +// StringBuffer operationAreaStr = new StringBuffer(); +// for (int i = 0, size = jsonArray.size(); i < size; i++) { +// JSONObject jsonObject = jsonArray.getJSONObject(i); +// shopNumberStr.append("[").append(jsonObject.getString("shopNumber")).append("]"); +// floorNameStr.append("[").append(jsonObject.getString("floorName")).append("]"); +// buildingNameStr.append("[").append(jsonObject.getString("buildingName")).append("]"); +// buildAreaStr.append("[").append(jsonObject.getString("buildArea")).append("]"); +// operationAreaStr.append("[").append(jsonObject.getString("operationArea")).append("]"); +// } +// result.put("shopNumber", shopNumberStr); +// result.put("floorName", floorNameStr); +// result.put("buildingName", buildingNameStr); +// result.put("buildArea", buildAreaStr); +// result.put("operationArea", operationAreaStr); +// } else { +// //record.setId(wxRentContract.getShopId()); +// if (wxRentContract.shopIdsByRentInfo().size() == 0) { +// result.put("shopNumber", " "); +// result.put("floorName", " "); +// result.put("buildingName", " "); +// result.put("buildArea", " "); +// result.put("operationArea", " "); +// }else { +// WxShop record = new WxShop(); +// record.setIds(wxRentContract.shopIdsByRentInfo()); +// record.updateTenantInfo(wxRentContract); +// PageInfo> shopPageInfo = wxShopService.findListMap(record,1,10000); +// List> wxShops = shopPageInfo.getList(); +// if (!wxShops.isEmpty()) { +// //店铺信息 +// Map wxShop = wxShops.get(0); +// result.put("shopNumber", wxShop.get("shopNumber")); +// result.put("floorName", wxShop.get("floor")); +// result.put("buildingName", wxShop.get("building")); +// result.put("buildArea", wxShop.get("buildArea")); +// result.put("operationArea", wxShop.get("operationArea")); +// } +// } +// } +// //MALL信息 +// WxMall wxMall = new WxMall(); +// wxMall.setTenantInfo(wxRentContract); +// wxMall = wxMallService.findList(wxMall).get(0); +// result.put("mallName", wxMall.getName()); +// result.put("province", wxMall.getProvince()); +// result.put("city", wxMall.getCity()); +// result.put("mallAddr", wxMall.getAddr()); +// result.put("mallServicePhone", wxMall.getServicePhone()); +// +// //商户信息 +// WxMerchant merchant = wxMerchantService.getById(wxRentContract.getMerchantId()); +// //经营业态 +// wxRentContract.getMerchantId(); +// WxBusiness wxBusiness = wxBusinessMapper.selectById(merchant.getFinalTenantId(),merchant.getBusinessId()); +// result.put("business", wxBusiness.getTitle()); +// +// if (merchant != null) { +// result.put("merchantName", merchant.getName()); +// //法人信息 +// WxMerchantCorp wxMerchantCorp = merchant.getWxMerchantCorp(); +// result.put("corpPapersNumber", StringUtils.isNotEmpty(wxMerchantCorp.getCorpPapersNumber()) ? wxMerchantCorp.getCorpPapersNumber() : " "); +// result.put("corpPapersType", wxMerchantCorp.getCorpPapersType() != null ? EnumPapersType.getEnum(wxMerchantCorp.getCorpPapersType()).getMessage() : " "); +// result.put("corpPapersPerson", StringUtils.isNotEmpty(wxMerchantCorp.getCorpPapersPerson()) ? wxMerchantCorp.getCorpPapersPerson() : " "); +// //税务信息 +// WxMerchantTax wxMerchantTax = merchant.getWxMerchantTax(); +// result.put("taxPapersType", wxMerchantTax.getTaxPapersType() != null ? EnumTaxpayerType.getEnum(wxMerchantTax.getTaxPapersType()).getMessage() : " "); +// result.put("bankName", StringUtils.isNotEmpty(wxMerchantTax.getBankName()) ? wxMerchantTax.getBankName() : " "); +// result.put("bankAccount", StringUtils.isNotEmpty(wxMerchantTax.getBankAccount()) ? wxMerchantTax.getBankAccount() : " "); +// result.put("invoiceAddressPhone", StringUtils.isNotEmpty(wxMerchantTax.getInvoiceAddressPhone()) ? wxMerchantTax.getInvoiceAddressPhone() : " "); +// } else { +// result.put("merchantName", ""); +// //法人信息 +// result.put("corpPapersNumber", " "); +// result.put("corpPapersType", " "); +// result.put("corpPapersPerson", " "); +// //税务信息 +// result.put("taxPapersType", " "); +// result.put("bankName", " "); +// result.put("bankAccount", " "); +// result.put("invoiceAddressPhone", " "); +// } +// +// //租赁合同信息 +// if(StringUtils.isNotBlank(wxRentContract.getContractualRules())){ +// //{total:,partyA:,partyB:} +// JSONObject jsonObject = JSONObject.parseObject(wxRentContract.getContractualRules()); +// result.put("rentTotal",jsonObject.getString("total")); +// result.put("rentPartyA",jsonObject.getString("partyA")); +// result.put("rentPartyB",jsonObject.getString("partyB")); +// } +// if(StringUtils.isNotBlank(wxRentContract.getBusinessHours())){ +// //{"beginEnd": "00", "finishEnd": "00", "beginStart": "00", "finishStart": "18"} +// JSONObject jsonObject = JSONObject.parseObject(wxRentContract.getBusinessHours()); +// if(!("-1").equals(jsonObject.getString("beginStart")) && !("-1").equals(jsonObject.getString("beginEnd")) +// && !("-1").equals(jsonObject.getString("finishStart")) && !("-1").equals(jsonObject.getString("finishEnd"))){ +// result.put("businessStart",jsonObject.getString("beginStart")+":"+jsonObject.getString("beginEnd")); +// result.put("businessEnd",jsonObject.getString("finishStart")+":"+jsonObject.getString("finishEnd")); +// } +// } +// //甲方信息 +// if(StringUtils.isNotBlank(wxRentContract.getFirstPartyBankInfo())){ +// //{"bankNameA": "", "accountNumA": "", "accountNameA": "", "socialCreditCodeA": ""} +// JSONObject jsonObject = JSONObject.parseObject(wxRentContract.getFirstPartyBankInfo()); +// result.put("bankNameA",jsonObject.getString("bankNameA")); +// result.put("accountNumA",jsonObject.getString("accountNumA")); +// result.put("accountNameA",jsonObject.getString("accountNameA")); +// result.put("socialCreditCodeA",jsonObject.getString("socialCreditCodeA")); +// }else{ +// result.put("bankNameA",""); +// result.put("accountNumA",""); +// result.put("accountNameA",""); +// result.put("socialCreditCodeA",""); +// } +// //乙方信息 +// result.put("scopeMetre",wxRentContract.getScopeMetre()); +// result.put("shopTypeSub",wxRentContract.getShopTypeSub()); +// result.put("leasePurpose",wxRentContract.getLeasePurpose()); +// result.put("linkPhoneB",wxRentContract.getLinkPhone()); +// result.put("linkAddressB",wxRentContract.getLinkAddress()); +// if(StringUtils.isNotBlank(wxRentContract.getSecondPartyBankInfo())){ +// //{"bankName": "", "payAccount": "", "accountName": "", "socialCreditCode": ""} +// JSONObject jsonObject = JSONObject.parseObject(wxRentContract.getSecondPartyBankInfo()); +// result.put("bankNameB",jsonObject.getString("bankName")); +// result.put("accountNumB",jsonObject.getString("payAccount")); +// result.put("accountNameB",jsonObject.getString("accountName")); +// result.put("socialCreditCodeB",jsonObject.getString("socialCreditCode")); +// }else{ +// result.put("bankNameB",""); +// result.put("accountNumB",""); +// result.put("accountNameB",""); +// result.put("socialCreditCodeB",""); +// } +// //乙方税务信息 +// if(StringUtils.isNotBlank(wxRentContract.getSecondPartyTaxInfo())){ +// //{"bankName": "", "linkPhone": "", "payAccount": "", "accountName": "", "taxpayerAdress": "", "taxpayerNumber": ""} +// JSONObject jsonObject = JSONObject.parseObject(wxRentContract.getSecondPartyTaxInfo()); +// result.put("bankNameBTax",jsonObject.getString("bankName")); +// result.put("accountNumBTax",jsonObject.getString("payAccount")); +// result.put("accountNameBTax",jsonObject.getString("accountName")); +// result.put("linkPhoneBTax",jsonObject.getString("linkPhone")); +// result.put("taxpayerAdressB",jsonObject.getString("taxpayerAdress")); +// result.put("taxpayerNumberB",jsonObject.getString("taxpayerNumber")); +// }else{ +// result.put("bankNameBTax",""); +// result.put("accountNumBTax",""); +// result.put("accountNameBTax",""); +// result.put("linkPhoneBTax",""); +// result.put("taxpayerAdressB",""); +// result.put("taxpayerNumberB",""); +// } +// +// //物业 +// result.put("propertyName",wxRentContract.getPropertyName()); +// if(wxRentContract.getPropertyFee() != null){ +// double propertyFee = new BigDecimal(wxRentContract.getPropertyFee()) +// .divide(new BigDecimal(100)) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("propertyFee",propertyFee); +// } +// if(wxRentContract.getFeeCycle() != null){ +// if(wxRentContract.getFeeCycle().intValue() == 1){ +// result.put("feeCycle","月"); +// }else if(wxRentContract.getFeeCycle().intValue() == 2){ +// result.put("feeCycle","季"); +// }else if(wxRentContract.getFeeCycle().intValue() == 3){ +// result.put("feeCycle","年"); +// } +// } +// if(wxRentContract.getWaterFee() != null){ +// double waterFee = new BigDecimal(wxRentContract.getWaterFee()) +// .divide(new BigDecimal(100)) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("waterFee",waterFee); +// } +// if(wxRentContract.getElectricityFees() != null){ +// double electricityFees = new BigDecimal(wxRentContract.getElectricityFees()) +// .divide(new BigDecimal(100)) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("electricityFees",electricityFees); +// } +// +// +// +// //交付 +// if(wxRentContract.getDeliveryDate() != null){ +// String deliveryDate = DateUtils.date2String(wxRentContract.getDeliveryDate(), "yyyy-MM-dd"); +// result.put("deliveryDateYear", deliveryDate.substring(0, 4)); +// result.put("deliveryDateMonth", deliveryDate.substring(5, 7)); +// result.put("deliveryDateDay", deliveryDate.substring(8)); +// result.put("deliveryGracePeriod", wxRentContract.getDeliveryGracePeriod()); +// } +// +// +// //装修 +// if(wxRentContract.getFixStartDate() != null && wxRentContract.getFixEndDate() != null){ +// String fixStartDate = DateUtils.date2String(wxRentContract.getFixStartDate(), "yyyy-MM-dd"); +// result.put("fixStartDateYear", fixStartDate.substring(0, 4)); +// result.put("fixStartDateMonth", fixStartDate.substring(5, 7)); +// result.put("fixStartDateDay", fixStartDate.substring(8)); +// String fixEndDate = DateUtils.date2String(wxRentContract.getFixEndDate(), "yyyy-MM-dd"); +// result.put("fixEndDateYear", fixEndDate.substring(0, 4)); +// result.put("fixEndDateMonth", fixEndDate.substring(5, 7)); +// result.put("fixEndDateDay", fixEndDate.substring(8)); +// } +// +// //开业 +// if(wxRentContract.getOpeningDate() != null){ +// String openingDate = DateUtils.date2String(wxRentContract.getOpeningDate(), "yyyy-MM-dd"); +// result.put("openingDateYear", openingDate.substring(0, 4)); +// result.put("openingDateMonth", openingDate.substring(5, 7)); +// result.put("openingDateDay", openingDate.substring(8)); +// } +// +// //计租 +// if(wxRentContract.getStartDate() != null && wxRentContract.getRentalEndDate() != null){ +// String rentalStartDate = DateUtils.date2String(wxRentContract.getStartDate(), "yyyy-MM-dd"); +// result.put("rentalStartDate", rentalStartDate); +// result.put("rentalStartDateYear", rentalStartDate.substring(0, 4)); +// result.put("rentalStartDateMonth", rentalStartDate.substring(5, 7)); +// result.put("rentalStartDateDay", rentalStartDate.substring(8)); +// String rentalEndDate = DateUtils.date2String(wxRentContract.getRentalEndDate(), "yyyy-MM-dd"); +// result.put("rentalEndDate", rentalEndDate); +// result.put("rentalEndDateYear", rentalEndDate.substring(0, 4)); +// result.put("rentalEndDateMonth", rentalEndDate.substring(5, 7)); +// result.put("rentalEndDateDay", rentalEndDate.substring(8)); +// } +// //免租 +// if(wxRentContract.getStartDate() != null && wxRentContract.getRentalStartDate()!=null +// && !DateUtils.isSameDate(wxRentContract.getStartDate(),wxRentContract.getRentalStartDate())){ +// String reductionStartDate = DateUtils.date2String(wxRentContract.getRentalStartDate(), "yyyy-MM-dd"); +// result.put("reductionStartDateYear", reductionStartDate.substring(0, 4)); +// result.put("reductionStartDateMonth", reductionStartDate.substring(5, 7)); +// result.put("reductionStartDateDay", reductionStartDate.substring(8)); +//// String reductionEndDate = DateUtils.date2String(wxRentContract.getRentalStartDate(), "yyyy-MM-dd"); +// String reductionEndDate = DateUtils.getTimeBefore(1,wxRentContract.getStartDate()); +// result.put("reductionEndDateYear", reductionEndDate.substring(0, 4)); +// result.put("reductionEndDateMonth", reductionEndDate.substring(5, 7)); +// result.put("reductionEndDateDay", reductionEndDate.substring(8)); +// }else{ +// result.put("reductionStartDateYear", "/"); +// result.put("reductionStartDateMonth", "/"); +// result.put("reductionStartDateDay", "/"); +// result.put("reductionEndDateYear", "/"); +// result.put("reductionEndDateMonth", "/"); +// result.put("reductionEndDateDay", "/"); +// } +// +// String shopType4Str = ""; +// if(wxRentContract.getShopType() != null && wxRentContract.getShopType().intValue() == 1){ +// shopType4Str = "直营"; +// }else if(wxRentContract.getShopType() != null && wxRentContract.getShopType().intValue() == 6){ +// shopType4Str = "代理"; +// }else if(wxRentContract.getShopType() != null && wxRentContract.getShopType().intValue() == 2){ +// shopType4Str = "加盟"; +// }else{ +// shopType4Str = "其他("+wxRentContract.getShopTypeStr()+")"; +// } +// result.put("shopType4Str",shopType4Str); +// +// +// +// +// result.put("price", wxRentContract.getPrice()); +// result.put("contractNumber", wxRentContract.getContractNumber()); +// Integer lease = wxRentContract.getLease(); +// Integer receivePeriod = wxRentContract.getReceivePeriod(); +// result.put("lease", lease); +// result.put("receivePeriod", receivePeriod); +// String payAccountStr = " "; +// if(wxRentContract.getPayAccount() != null && !wxRentContract.getPayAccount().equals("")) { +// payAccountStr = wxRentContract.getPayAccount(); +// } +// result.put("payAccount", payAccountStr); +// result.put("signDate", DateUtils.date2String(wxRentContract.getSignDate(), "yyyy-MM-dd")); +// //主体名称-乙方 +// if (StringUtils.isNotEmpty(wxRentContract.getSubjectName())) { +// result.put("subjectName", wxRentContract.getSubjectName()); +// } else { +// result.put("subjectName", " "); +// } +// +// //品牌 +// Long brandId = wxRentContract.getBrand(); +// String brand = " "; +// if (brandId != null) { +// WxBrand wxBrand = WxBrandMapper.selectById(brandId); +// if (wxBrand != null) { +// brand = wxBrand.getName(); +// } +// } +// result.put("brand", brand); +// Integer type = wxRentContract.getType(); +// result.put("type", type); +// +// if(EnumContractOperationType.JINMAO.getCode().equals(wxRentContract.getOperationType())){ +// if(StringUtils.isNotBlank(wxRentContract.getCashtypeContentLsit())){ +// //{"honourPledge": "", "fitmentPledge": "", "qualityPledge": "", "honourDuration": "", "qualityDuration": ""} +// //fitmentPledge:"",//装修押金 +// //honourPledge:"",//履约保证金 +// //honourDuration:"",//履约保证金时限 +// //qualityPledge:"",//品质保证金 +// //qualityDuration:"",//品质保证金时限 +// JSONObject jsonObject = JSONObject.parseObject(wxRentContract.getCashtypeContentLsit()); +// result.put("fitmentPledge",jsonObject.getString("fitmentPledge")); +// result.put("honourPledge",jsonObject.getString("honourPledge")); +// if(StringUtils.isNotBlank(jsonObject.getString("honourPledge"))){ +// result.put("honourPledgeUpper",PriceUtil.digitUppercase(Double.valueOf(jsonObject.getString("honourPledge")))); +// } +// result.put("honourDuration",jsonObject.getString("honourDuration")); +// result.put("qualityPledge",jsonObject.getString("qualityPledge")); +// if(StringUtils.isNotBlank(jsonObject.getString("qualityPledge"))){ +// result.put("honourPledgeUpper",PriceUtil.digitUppercase(Double.valueOf(jsonObject.getString("qualityPledge")))); +// } +// result.put("qualityDuration",jsonObject.getString("qualityDuration")); +// +// } +// //[{"progressivePay": "", "tempAdjustRatio": "2021-11-30 00:00:00", "incrementStartDate": "2021-11-29T16:00:00.000Z", "increasingProportion": "1.78"}] +// //increasingProportion//租金递增比例 +// //progressivePay//递增租赁单价 +// List> ratioList = new ArrayList<>(); +// if(StringUtils.isNotBlank(wxRentContract.getAdjustRatio())){ +// JSONArray array = JSONArray.parseArray(wxRentContract.getAdjustRatio()); +// if(array != null && array.size() > 0){ +// for(int i=0;i ratioMap = new HashMap<>(); +// String afterYear = DateUtils.getAfterYear(wxRentContract.getStartDate(), i + 1); +// String beforeAfterYear = DateUtils.getTimeBefore(1, afterYear); +// ratioMap.put("incrementStartDate",afterYear); +// ratioMap.put("beforeOneIncrementStartDate",beforeAfterYear); +// ratioMap.put("increasingProportion",jsonObject.getString("increasingProportion")); +// ratioMap.put("progressivePay",jsonObject.getString("progressivePay")); +// ratioList.add(ratioMap); +// } +// } +// } +// } +// result.put("countRatioList",ratioList.size()); +// +// if(EnumRentContractType.RENT_BY_AREA.getCode().equals(type)){ +// +// double priceRent = new BigDecimal(wxRentContract.getPrice()) +// .divide(new BigDecimal(100)) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("oneRentalPrice1", priceRent); +// result.put("oneRentalPriceUpper1", PriceUtil.digitUppercase(priceRent)); +// +// double oneRentPrice = new BigDecimal(wxRentContract.getRentPrice()) +// .divide(new BigDecimal(100)) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("oneRentPrice",oneRentPrice); +// +// WxBillRent wxBillRent = new WxBillRent(); +// wxBillRent.setRentContractId(wxRentContract.getId()); +// wxBillRent.setSortColumns(BaseEntity.SortField.Period_ASC); +// List resultList = wxBillRentMapper.findList(wxBillRent); +// //稍后详细计算(查询首期账单用于显示) +// if(resultList != null && resultList.size() > 0){ +// double oneRentalQuarterPrice1 = new BigDecimal(resultList.get(0).getReceivePay()) +// .divide(new BigDecimal(100)) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("oneRentalQuarterPrice1", oneRentalQuarterPrice1); +// result.put("oneRentalQuarterPriceUpper1", PriceUtil.digitUppercase(oneRentalQuarterPrice1)); +// } +// +// if(ratioList.size() > 0){ +// String beforeOneIncrementStartDate = ratioList.get(0).get("beforeOneIncrementStartDate"); +// result.put("oneRentalEndDateYear1",beforeOneIncrementStartDate.substring(0,4)); +// result.put("oneRentalEndDateMonth1",beforeOneIncrementStartDate.substring(5,7)); +// result.put("oneRentalEndDateDay1",beforeOneIncrementStartDate.substring(8,10)); +// +// String incrementStartDate = ratioList.get(0).get("incrementStartDate"); +// result.put("oneRentalStartDateYear2",incrementStartDate.substring(0,4)); +// result.put("oneRentalStartDateMonth2",incrementStartDate.substring(5,7)); +// result.put("oneRentalStartDateDay2",incrementStartDate.substring(8,10)); +// String increasingProportion = ratioList.get(0).get("increasingProportion"); +// result.put("oneRentIncreasing2",increasingProportion); +// double priceRent2 = new BigDecimal(priceRent) +// .multiply(new BigDecimal(1).add(new BigDecimal(increasingProportion).divide(new BigDecimal(100)))) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("oneRentalPrice2", priceRent2); +// result.put("oneRentalPriceUpper2", PriceUtil.digitUppercase(priceRent2)); +// +// if(ratioList.size() > 1){ +// for (int i = 1;i < ratioList.size();i++){ +// int n = i+2; +// String incrementStartDaten = ratioList.get(i).get("incrementStartDate"); +// result.put("oneRentalStartDateYear"+n,incrementStartDaten.substring(0,4)); +// result.put("oneRentalStartDateMonth"+n,incrementStartDaten.substring(5,7)); +// result.put("oneRentalStartDateDay"+n,incrementStartDaten.substring(8,10)); +// String increasingProportionn = ratioList.get(i).get("increasingProportion"); +// result.put("oneRentIncreasing"+n,increasingProportionn); +// priceRent2 = new BigDecimal(priceRent2) +// .multiply(new BigDecimal(1).add(new BigDecimal(increasingProportionn).divide(new BigDecimal(100)))) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("oneRentalPrice"+n, priceRent2); +// result.put("oneRentalPriceUpper"+n, PriceUtil.digitUppercase(priceRent2)); +// } +// } +// +// }else{ +// String rentalEndDate = DateUtils.date2String(wxRentContract.getRentalEndDate(), "yyyy-MM-dd"); +// result.put("oneRentalStartDateYear1", rentalEndDate.substring(0, 4)); +// result.put("oneRentalStartDateMonth1", rentalEndDate.substring(5, 7)); +// result.put("oneRentalStartDateDay1", rentalEndDate.substring(8)); +// } +// +// +// }else if(EnumRentContractType.RENT_BY_JOINT.getCode().equals(type)){ +// Double twoPayRatio1 = new BigDecimal(wxRentContract.getPayRatio()) +// .divide(new BigDecimal(100)) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("twoPayRatio1",twoPayRatio1); +// result.put("twoPayDate",wxRentContract.getPayDate()); +// if(ratioList.size() > 0){ +// String beforeOneIncrementStartDate = ratioList.get(0).get("beforeOneIncrementStartDate"); +// result.put("twoRentalEndDateYear1",beforeOneIncrementStartDate.substring(0,4)); +// result.put("twoRentalEndDateMonth1",beforeOneIncrementStartDate.substring(5,7)); +// result.put("twoRentalEndDateDay1",beforeOneIncrementStartDate.substring(8,10)); +// String incrementStartDate = ratioList.get(0).get("incrementStartDate"); +// result.put("twoRentalStartDateYear2",incrementStartDate.substring(0,4)); +// result.put("twoRentalStartDateMonth2",incrementStartDate.substring(5,7)); +// result.put("twoRentalStartDateDay2",incrementStartDate.substring(8,10)); +// String increasingProportion = ratioList.get(0).get("increasingProportion"); +// result.put("twoRentIncreasing2",increasingProportion); +//// Double twoPayRatio2 = new BigDecimal(twoPayRatio1) +//// .add(new BigDecimal(increasingProportion)) +//// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("twoPayRatio2",twoPayRatio1); +// +// if(ratioList.size() > 1){ +// for (int i = 1;i < ratioList.size();i++){ +// int n = i+2; +// String incrementStartDaten = ratioList.get(i).get("incrementStartDate"); +// result.put("twoRentalStartDateYear"+n,incrementStartDaten.substring(0,4)); +// result.put("twoRentalStartDateMonth"+n,incrementStartDaten.substring(5,7)); +// result.put("twoRentalStartDateDay"+n,incrementStartDaten.substring(8,10)); +// String increasingProportionn = ratioList.get(i).get("increasingProportion"); +// result.put("twoRentIncreasing"+n,increasingProportionn); +//// Double twoPayRatio2 = new BigDecimal(twoPayRatio1) +//// .add(new BigDecimal(increasingProportion)) +//// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("twoPayRatio"+n,twoPayRatio1); +// } +// } +// +// }else{ +// String rentalEndDate = DateUtils.date2String(wxRentContract.getRentalEndDate(), "yyyy-MM-dd"); +// result.put("twoRentalStartDateYear1", rentalEndDate.substring(0, 4)); +// result.put("twoRentalStartDateMonth1", rentalEndDate.substring(5, 7)); +// result.put("twoRentalStartDateDay1", rentalEndDate.substring(8)); +// } +// +// }else if(EnumRentContractType.RENT_BY_AREA_AND_JOINT.getCode().equals(type)){ +// double priceRent = new BigDecimal(wxRentContract.getPrice()) +// .divide(new BigDecimal(100)) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("threeRentalPrice1", priceRent); +// result.put("threeRentalPriceUpper1", PriceUtil.digitUppercase(priceRent)); +// +// double threeRentPrice = new BigDecimal(wxRentContract.getRentPrice()) +// .divide(new BigDecimal(100)) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("threeRentPrice",threeRentPrice); +// double threePayRatio1 = new BigDecimal(wxRentContract.getPayRatio()) +// .divide(new BigDecimal(100)) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("threePayRatio1",threePayRatio1); +// +// result.put("threePayDate",wxRentContract.getPayDate()); +// if(ratioList.size() > 0){ +// String beforeOneIncrementStartDate = ratioList.get(0).get("beforeOneIncrementStartDate"); +// result.put("threeRentalEndDateYear1",beforeOneIncrementStartDate.substring(0,4)); +// result.put("threeRentalEndDateMonth1",beforeOneIncrementStartDate.substring(5,7)); +// result.put("threeRentalEndDateDay1",beforeOneIncrementStartDate.substring(8,10)); +// String incrementStartDate = ratioList.get(0).get("incrementStartDate"); +// result.put("threeRentalStartDateYear2",incrementStartDate.substring(0,4)); +// result.put("threeRentalStartDateMonth2",incrementStartDate.substring(5,7)); +// result.put("threeRentalStartDateDay2",incrementStartDate.substring(8,10)); +// String progressivePay = ratioList.get(0).get("progressivePay"); +// double threeProgressivePay2 = new BigDecimal(progressivePay) +// .multiply(new BigDecimal(wxRentContract.getRentArea())) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("threeProgressivePay2",threeProgressivePay2); +// result.put("threeProgressivePayUpper2",PriceUtil.digitUppercase(threeProgressivePay2)); +// result.put("threeRentPrice2",progressivePay); +// String increasingProportion = ratioList.get(0).get("increasingProportion"); +// result.put("threeRentIncreasing2",increasingProportion); +// if(ratioList.size() > 1){ +// for (int i = 1;i < ratioList.size();i++){ +// int n = i+2; +// String incrementStartDaten = ratioList.get(i).get("incrementStartDate"); +// result.put("threeRentalStartDateYear"+n,incrementStartDaten.substring(0,4)); +// result.put("threeRentalStartDateMonth"+n,incrementStartDaten.substring(5,7)); +// result.put("threeRentalStartDateDay"+n,incrementStartDaten.substring(8,10)); +// String progressivePayn = ratioList.get(i).get("progressivePay"); +// double threeProgressivePayn = new BigDecimal(progressivePayn) +// .multiply(new BigDecimal(wxRentContract.getRentArea())) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("threeProgressivePay"+n,threeProgressivePayn); +// result.put("threeProgressivePayUpper"+n,PriceUtil.digitUppercase(threeProgressivePayn)); +// result.put("threeRentPrice"+n,progressivePayn); +// String increasingProportionn = ratioList.get(i).get("increasingProportion"); +// result.put("threeRentIncreasing"+n,increasingProportionn); +// } +// } +// }else{ +// String rentalEndDate = DateUtils.date2String(wxRentContract.getRentalEndDate(), "yyyy-MM-dd"); +// result.put("threeRentalStartDateYear1", rentalEndDate.substring(0, 4)); +// result.put("threeRentalStartDateMonth1", rentalEndDate.substring(5, 7)); +// result.put("threeRentalStartDateDay1", rentalEndDate.substring(8)); +// } +// +// } +// }else{ +// //double adjustRatio = wxRentContract.getAdjustRatio() != null ? wxRentContract.getAdjustRatio() / 100.0 : 0; +// result.put("adjustRatio", 0); +// double priceRent = new BigDecimal(wxRentContract.getPrice()) +// .divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("priceRent", priceRent); +// if (!wxRentContract.getRentArea().equals("0")) { +// double unitPrice = new BigDecimal(wxRentContract.getPrice()) +// .divide(new BigDecimal(wxRentContract.getRentArea()), 2, RoundingMode.HALF_EVEN) +// .divide(new BigDecimal(100)) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("unitPriceRent", unitPrice); +// result.put("priceRentUpper", PriceUtil.digitUppercase(priceRent)); +// result.put("unitPriceRentUpper", PriceUtil.digitUppercase(unitPrice)); +// } else { +// result.put("unitPriceRent", "0"); +// result.put("priceRentUpper", PriceUtil.digitUppercase(0)); +// result.put("unitPriceRentUpper", PriceUtil.digitUppercase(0)); +// } +// +// //租赁保证金 +// int cashDepositMonthRent = 3; +// BigDecimal cashDepositRent = new BigDecimal(wxRentContract.getPrice()).multiply(new BigDecimal(cashDepositMonthRent)) +// .setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_EVEN); +// result.put("cashDepositMonthRent", cashDepositMonthRent); +// result.put("cashDepositRent", cashDepositRent.toPlainString()); +// result.put("cashDepositRentUpper", PriceUtil.digitUppercase(cashDepositRent.setScale(2,RoundingMode.HALF_EVEN).longValue())); +// +// int extralease = lease % 12; +// int extracount = extralease > 0 ? 1 : 0; +// int paycount = lease / 12 + extracount; +// int index = 10 - paycount; +// int count = paycount - 1; +// BigDecimal rentPrice = new BigDecimal(priceRent); +// //保底 +// if (wxRentContract.getRevenue() != null) { +//// double revenue = new BigDecimal(wxRentContract.getRevenue()) +//// .divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("revenue", wxRentContract.getRevenue()); +// result.put("revenueUpper", PriceUtil.digitUppercase(new BigDecimal(wxRentContract.getRevenue()) +// .setScale(2,RoundingMode.HALF_EVEN).longValue())); +// } else { +// result.put("revenue", "0"); +// result.put("revenueUpper", PriceUtil.digitUppercase(0)); +// } +// if (!wxRentContract.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { +// areaWay(wxRentContract, result, lease, extralease, extracount, paycount, index, count, rentPrice); +// } else { +// ratioWay(wxRentContract, result, lease, extralease, extracount, paycount, index, count, rentPrice); +// } +// } +// +// +// +// +// //物业合同信息 +// //WxPropertyContract propertyContract = new WxPropertyContract(); +// //propertyContract.updateTenantInfo(wxRentContract); +// //propertyContract.setRentContractId(wxRentContract.getId()); +//// Optional> first = wxPropertyContractMapper.queryPropertyContractData(propertyContract) +//// .stream().filter(rc -> !rc.get("status").equals(EnumRentContractStatus.CONTRACT_TERMINATE.getCode()) +//// && !rc.get("status").equals(EnumRentContractStatus.WAIT_SIGN.getCode()) +//// && !rc.get("status").equals(EnumRentContractStatus.INVALID.getCode()) +//// && !rc.get("status").equals(EnumRentContractStatus.CONTRACT_END.getCode()) +//// && !rc.get("status").equals(EnumRentContractStatus.INTENTION.getCode())).findFirst(); +// //Optional> first = wxPropertyContractMapper.queryPropertyContractData(propertyContract) +// //.stream().filter(rc -> !rc.get("status").equals(EnumRentContractStatus.TERMINATE.getCode()) +// // && !rc.get("status").equals(EnumRentContractStatus.INVALID.getCode()) +// // && !rc.get("status").equals(EnumRentContractStatus.OUT_DATE.getCode())).findFirst(); +// // Map wxPropertyContract = null; +// // if (first.isPresent()) { +// // wxPropertyContract = first.get(); +// // } +// WxPropertyContract propertyContract = null; +// if (null != propertyId) { +// propertyContract = wxPropertyContractMapper.selectById(propertyId); +// } +// if (propertyContract != null) { +// Integer receivePeriodProperty = propertyContract.getReceivePeriod(); +// result.put("receivePeriodProperty", receivePeriodProperty); +// double priceProperty = new BigDecimal(propertyContract.getPrice().toString()) +// .divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("priceProperty", priceProperty); +// if (!wxRentContract.getRentArea().equals("0")) { +// double unitPriceProperty = new BigDecimal(propertyContract.getPrice().toString()) +// .divide(new BigDecimal(wxRentContract.getRentArea()), 2, RoundingMode.HALF_EVEN) +// .divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("unitPriceProperty", unitPriceProperty); +// result.put("pricePropertyUpper", PriceUtil.digitUppercase(priceProperty)); +// result.put("unitPricePropertyUpper", PriceUtil.digitUppercase(unitPriceProperty)); +// } else { +// result.put("unitPriceProperty", 0); +// result.put("pricePropertyUpper", PriceUtil.digitUppercase(0)); +// result.put("unitPricePropertyUpper", PriceUtil.digitUppercase(0)); +// } +// +// //首期物业费 +// Calendar instance = Calendar.getInstance(); +// instance.setTime(wxRentContract.getRentalStartDate()); +// instance.add(Calendar.MONTH, 0); +// Date starttime = instance.getTime(); +// String startdate = DateUtils.date2String(starttime, "yyyy-MM-dd"); +// result.put("rentalStartDateProperty", startdate); +// result.put("rentalStartDateYearProperty", startdate.substring(0, 4)); +// result.put("rentalStartDateMonthProperty", startdate.substring(5, 7)); +// result.put("rentalStartDateDayProperty", startdate.substring(8)); +// //结束时间 +// instance.clear(); +// instance.setTime(starttime); +// instance.add(Calendar.MONTH, receivePeriodProperty); +// instance.add(Calendar.DAY_OF_MONTH, -1); +// Date endtime = instance.getTime(); +// String enddate = DateUtils.date2String(endtime, "yyyy-MM-dd"); +// result.put("rentalEndDateProperty", enddate); +// result.put("rentalEndDateYearProperty", enddate.substring(0, 4)); +// result.put("rentalEndDateMonthProperty", enddate.substring(5, 7)); +// result.put("rentalEndDateDayProperty", enddate.substring(8)); +// double pricePropertyFirst = new BigDecimal(priceProperty) +// .multiply(new BigDecimal(receivePeriodProperty)) +// .setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("pricePropertyFirst", pricePropertyFirst); +// result.put("pricePropertyFirstUpper", PriceUtil.digitUppercase(pricePropertyFirst)); +// +// +// //物业保证金 +// int cashDepositMonthProperty = 3; +// double cashDepositProperty = new BigDecimal(propertyContract.getPrice().toString()).multiply(new BigDecimal(cashDepositMonthProperty)) +// .divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); +// result.put("cashDepositMonthProperty", cashDepositMonthProperty); +// result.put("cashDepositProperty", cashDepositProperty); +// result.put("cashDepositPropertyUpper", PriceUtil.digitUppercase(cashDepositProperty)); +// +// +// } else { +// result.put("receivePeriodProperty", " "); +// result.put("priceProperty", " "); +// result.put("unitPriceProperty", " "); +// result.put("pricePropertyUpper", " "); +// result.put("unitPricePropertyUpper", " "); +// //首期物业费 +// result.put("rentalStartDateProperty", " "); +// result.put("rentalStartDateYearProperty", " "); +// result.put("rentalStartDateMonthProperty", " "); +// result.put("rentalStartDateDayProperty", " "); +// //结束时间 +// result.put("rentalEndDateProperty", " "); +// result.put("rentalEndDateYearProperty", " "); +// result.put("rentalEndDateMonthProperty", " "); +// result.put("rentalEndDateDayProperty", " "); +// result.put("pricePropertyFirst", " "); +// result.put("pricePropertyFirstUpper", " "); +// //物业保证金 +// result.put("cashDepositMonthProperty", " "); +// result.put("cashDepositProperty", " "); +// result.put("cashDepositPropertyUpper", " "); +// } +// +// +// return result; +// } + +// 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); +// //常规租期 +// for (int i = 0; i <= count; i++) { +// //开始时间 +// Calendar instance = Calendar.getInstance(); +// instance.setTime(wxRentContract.getRentalStartDate()); +// instance.add(Calendar.MONTH, lease * i); +// Date starttime = instance.getTime(); +// String startdate = DateUtils.date2String(starttime, "yyyy-MM-dd"); +// result.put("rentalStartDate" + i, startdate); +// result.put("rentalStartDateYear" + i, startdate.substring(0, 4)); +// result.put("rentalStartDateMonth" + i, startdate.substring(5, 7)); +// result.put("rentalStartDateDay" + i, startdate.substring(8)); +// //结束时间 +// instance.clear(); +// instance.setTime(starttime); +// instance.add(Calendar.MONTH, lease); +// instance.add(Calendar.DAY_OF_MONTH, -1); +// Date endtime = instance.getTime(); +// String enddate = DateUtils.date2String(endtime, "yyyy-MM-dd"); +// result.put("rentalEndDate" + i, enddate); +// result.put("rentalEndDateYear" + i, enddate.substring(0, 4)); +// result.put("rentalEndDateMonth" + i, enddate.substring(5, 7)); +// result.put("rentalEndDateDay" + i, enddate.substring(8)); +// String ratio = new BigDecimal(integers.get(i)).divide(new BigDecimal(100)).toPlainString(); +// result.put("adjustRatio" + i, ratio); +// result.put("adjustPeriod" + i, wxRentContract.getAdjustPeriod()); +// Integer tempPayRatio = Optional.ofNullable(wxRentContract.getPayRatio()).orElse(0); +// String payRatio = new BigDecimal(tempPayRatio).divide(new BigDecimal(100)).toPlainString(); +// result.put("payRatio" + i, payRatio); +// +// } +// if (extracount > 0) { +// //额外租期 +// //开始时间 +// Calendar instance = Calendar.getInstance(); +// instance.setTime(wxRentContract.getRentalStartDate()); +// instance.add(Calendar.MONTH, lease * count); +// Date starttime = instance.getTime(); +// String startdate = DateUtils.date2String(starttime, "yyyy-MM-dd"); +// result.put("rentalStartDate" + count, startdate); +// result.put("rentalStartDateYear" + count, startdate.substring(0, 4)); +// result.put("rentalStartDateMonth" + count, startdate.substring(5, 7)); +// result.put("rentalStartDateDay" + count, startdate.substring(8)); +// //结束时间 +// instance.clear(); +// instance.setTime(starttime); +// instance.add(Calendar.MONTH, extralease); +// instance.add(Calendar.DAY_OF_MONTH, -1); +// Date endtime = instance.getTime(); +// String enddate = DateUtils.date2String(endtime, "yyyy-MM-dd"); +// result.put("rentalEndDate" + count, enddate); +// result.put("rentalEndDateYear" + count, enddate.substring(0, 4)); +// result.put("rentalEndDateMonth" + count, enddate.substring(5, 7)); +// result.put("rentalEndDateDay" + count, enddate.substring(8)); +// result.put("adjustRatio" + count, wxRentContract.getAdjustRatio()); +// result.put("adjustPeriod" + count, wxRentContract.getAdjustPeriod()); +// Integer tempPayRatio = Optional.ofNullable(wxRentContract.getPayRatio()).orElse(0); +// String payRatio = new BigDecimal(tempPayRatio).divide(new BigDecimal(100)).toPlainString(); +// result.put("payRatio" + count, payRatio); +// +// } +// //无数据租期 +// for (int i = paycount; i <= 10; i++) { +// result.put("rentalStartDate" + i, "/"); +// result.put("rentalStartDateYear" + i, "/"); +// result.put("rentalStartDateMonth" + i, "/"); +// result.put("rentalStartDateDay" + i, "/"); +// result.put("rentalEndDate" + i, "/"); +// result.put("rentalEndDateYear" + i, "/"); +// result.put("rentalEndDateMonth" + i, "/"); +// result.put("rentalEndDateDay" + i, "/"); +// result.put("adjustRatio" + i, "/"); +// result.put("adjustPeriod" + i, "/"); +// result.put("payRatio" + i, "/"); +// } +// } + + public void areaWay(WxRentContract wxRentContract, Map result, Integer lease, int extralease, int extracount, int paycount, int index, int count, BigDecimal rentPrice) { + + String[] priceArrs = new String[]{}; + List adjustRatioList = new ArrayList<>(); + adjustRatioList.add(0, "0"); + if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { + String rentInfo = wxRentContract.getRentInfo(); + JSONArray objects = JSONArray.parseArray(rentInfo); + JSONObject jsonObject = objects.getJSONObject(0); + JSONArray adjustRatio = jsonObject.getJSONArray("adjustRatio"); + for (int i = 0, size = adjustRatio.size(); i < size; i++) { + StringBuffer adjustRatioStr = new StringBuffer(); + for (int j = 0, shopSize = objects.size(); j < shopSize; j++) { + JSONObject shopObject = objects.getJSONObject(j); + JSONArray adjustRatioArr = shopObject.getJSONArray("adjustRatio"); + String shopNumber = shopObject.getString("shopNumber"); + adjustRatioStr.append(shopNumber).append("[").append(adjustRatioArr.getString(i)).append("]"); + } + adjustRatioList.add(adjustRatioStr.toString()); + } + List priceList = WxRentContractHelper.computeRentPriceByShop(wxRentContract); + int size = priceList.size(); + priceArrs = new String[size]; + for (int i = 0; i < size; i++) { + String[] priceInt = priceList.get(i); + BigDecimal sum = new BigDecimal(0); + for (String p : priceInt) { + sum = sum.add(new BigDecimal(p)); + } + priceArrs[i] = sum.toPlainString(); + } + } else { + String adjustRatio = wxRentContract.getAdjustRatio(); + List integers = JSONArray.parseArray(adjustRatio, Integer.class); + for (int i = 0, size = integers.size(); i < size; i++) { + double ratioStr = new BigDecimal(integers.get(i)).divide(new BigDecimal(100)).doubleValue(); + adjustRatioList.add(String.valueOf(ratioStr)); + } + } + String payRatioStr = "0"; + if (wxRentContract.getPayRatio() != null) { + payRatioStr = new BigDecimal(wxRentContract.getPayRatio()).divide(new BigDecimal(100)).toPlainString(); + } + //常规租期 + for (int i = 0; i <= count; i++) { + //开始时间 + Calendar instance = Calendar.getInstance(); + instance.setTime(wxRentContract.getRentalStartDate()); + instance.add(Calendar.MONTH, lease * i); + Date starttime = instance.getTime(); + String startdate = DateUtils.date2String(starttime, "yyyy-MM-dd"); + result.put("rentalStartDate" + i, startdate); + result.put("rentalStartDateYear" + i, startdate.substring(0, 4)); + result.put("rentalStartDateMonth" + i, startdate.substring(5, 7)); + result.put("rentalStartDateDay" + i, startdate.substring(8)); + //结束时间 + instance.clear(); + instance.setTime(starttime); + instance.add(Calendar.MONTH, lease); + instance.add(Calendar.DAY_OF_MONTH, -1); + Date endtime = instance.getTime(); + String enddate = DateUtils.date2String(endtime, "yyyy-MM-dd"); + result.put("rentalEndDate" + i, enddate); + result.put("rentalEndDateYear" + i, enddate.substring(0, 4)); + result.put("rentalEndDateMonth" + i, enddate.substring(5, 7)); + result.put("rentalEndDateDay" + i, enddate.substring(8)); + + if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { + rentPrice = new BigDecimal(priceArrs[i]).divide(new BigDecimal(100)).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_EVEN); + result.put("priceRentUpper" + i, PriceUtil.digitUppercase(rentPrice.doubleValue())); + result.put("priceRent" + i, rentPrice.toPlainString()); + result.put("adjustRatio" + i, adjustRatioList.get(i)); + } else { + rentPrice = rentPrice.multiply(new BigDecimal(adjustRatioList.get(i))) + .add(rentPrice).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_EVEN); + result.put("priceRentUpper" + i, PriceUtil.digitUppercase(rentPrice.doubleValue())); + result.put("priceRent" + i, rentPrice.toPlainString()); + result.put("adjustRatio" + i, adjustRatioList.get(i)); + } + result.put("payRatio" + i, payRatioStr); + result.put("adjustPeriod" + i, wxRentContract.getAdjustPeriod()); + } + if (extracount > 0) { + //额外租期 + //开始时间 + Calendar instance = Calendar.getInstance(); + instance.setTime(wxRentContract.getRentalStartDate()); + instance.add(Calendar.MONTH, lease * count); + Date starttime = instance.getTime(); + String startdate = DateUtils.date2String(starttime, "yyyy-MM-dd"); + result.put("rentalStartDate" + count, startdate); + result.put("rentalStartDateYear" + count, startdate.substring(0, 4)); + result.put("rentalStartDateMonth" + count, startdate.substring(5, 7)); + result.put("rentalStartDateDay" + count, startdate.substring(8)); + //结束时间 + instance.clear(); + instance.setTime(starttime); + instance.add(Calendar.MONTH, extralease); + instance.add(Calendar.DAY_OF_MONTH, -1); + Date endtime = instance.getTime(); + String enddate = DateUtils.date2String(endtime, "yyyy-MM-dd"); + result.put("rentalEndDate" + count, enddate); + result.put("rentalEndDateYear" + count, enddate.substring(0, 4)); + result.put("rentalEndDateMonth" + count, enddate.substring(5, 7)); + result.put("rentalEndDateDay" + count, enddate.substring(8)); + + if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { + rentPrice = new BigDecimal(priceArrs[count]).divide(new BigDecimal(100)).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_EVEN); + result.put("priceRentUpper" + count, PriceUtil.digitUppercase(rentPrice.doubleValue())); + result.put("priceRent" + count, rentPrice.toPlainString()); + } else { + rentPrice = rentPrice.multiply(new BigDecimal(adjustRatioList.get(count))) + .add(rentPrice).setScale(wxRentContract.getDecimalSize(), RoundingMode.HALF_EVEN); + result.put("priceRentUpper" + count, PriceUtil.digitUppercase(rentPrice.doubleValue())); + result.put("priceRent" + count, rentPrice.toPlainString()); + } + + } + //无数据租期 + for (int i = paycount; i <= 10; i++) { + result.put("rentalStartDate" + i, "/"); + result.put("rentalStartDateYear" + i, "/"); + result.put("rentalStartDateMonth" + i, "/"); + result.put("rentalStartDateDay" + i, "/"); + result.put("rentalEndDate" + i, "/"); + result.put("rentalEndDateYear" + i, "/"); + result.put("rentalEndDateMonth" + i, "/"); + result.put("rentalEndDateDay" + i, "/"); + result.put("priceRentUpper" + i, "/"); + result.put("priceRent" + i, "/"); + result.put("adjustRatio" + i, "/"); + result.put("payRatio" + i, "/"); + result.put("adjustPeriod" + i, "/"); + } + } + + + @Override + public void updateApplyStatus(WxRentContract wxRentContract) { + wxRentContractMapper.updateApplyStatus(wxRentContract); + } + +// @Override +// public Integer getShopType(WxRentContract wxRentContract) { +// return wxRentContractMapper.getShopType(wxRentContract); +// } + + + + public static List initBillTimeList(Date start,Date end,Integer adjustPeriod,Integer dayType,int receivePeriod){ + List list = new ArrayList<>(); + + int count = 0; + while (true){ + BillTimeVo timeVo = new BillTimeVo(); + + //开始时间 + timeVo.setStartDate(start); + + //账单日 + Calendar instance = Calendar.getInstance(); + instance.setTime(start); + if(!adjustPeriod.equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ + instance.add(Calendar.DATE, -1); + } + timeVo.setReceiveDate(instance.getTime()); + + //结束时间 + instance.clear(); + instance.setTime(start); + instance = EnumContractReceivePeriodUnit.getAfterCalendarDay(instance, receivePeriod, dayType); + //instance.add(dayType, receivePeriod); + //instance.add(Calendar.DATE, -1); + timeVo.setEndDate(instance.getTime()); + + //自然月 + if(adjustPeriod.equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ + if(count == 0){ + timeVo.setEndDate(EnumContractReceivePeriodUnit.getAfterCalendarNarDay(timeVo.getStartDate(), receivePeriod, dayType)); + /** + if(receivePeriod == 1) { //周期1个月 头一个月到当月底 头一个月或者头一个季度 + timeVo.setEndDate(DateUtils.getLastDayForMonth(timeVo.getStartDate())); + }else{ + Date firstDay = DateUtils.getFirstDayForCurrMonth(start); + instance.clear(); + instance.setTime(firstDay); + //最后一个期有余,加上残月,不整除时,最后一个月有余,否则为0 + instance.add(dayType, receivePeriod); + instance.add(Calendar.DAY_OF_MONTH, -1); + timeVo.setEndDate(instance.getTime()); + }*/ + } + } + + 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.SECOND,1); + + if(start.after(end)) { + break; + } + count ++; + + //预警 + if(count >= 1000){ + Logger logger = LoggerFactory.getLogger(WxRentContractServiceImpl.class); + logger.error("initBillTimeList() warnCount max error !!!"); + break; + } + } + return list; + } + + + @Override + public WxRentContract getByBill(WxBillRent billRent) { + return wxRentContractMapper.getByBill(billRent); + } + +// @Override +// public Map selectRentContractByShopIds(Collection shopIds, String shopIdsRegexp, TenantEntity tenantEntity) { +// List list = wxRentContractMapper.selectRentContractByShopIds(shopIds, shopIdsRegexp, tenantEntity.getTenantId(), tenantEntity.getParentTenantId()); +// List shopIdArr = Arrays.asList(StringUtils.split(shopIdsRegexp,"|")) ; +// Map allShopContract = new HashMap<>(); +// for (WxRentContract wxRentContract : list) { +// if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { +// String rentInfo = wxRentContract.getRentInfo(); +// JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); +// int size = rentInfoArray.size(); +// //查询rent_info 包括 shopId +// for (int i = 0; i < size; i++) { +// JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); +// Long shopId = rentInfoObject.getLong("shopId"); +// if (!shopIdArr.contains(String.valueOf(shopId))) { +// continue; +// } +// WxRentContract rentContract = new WxRentContract(); +// BeanUtils.copyProperties(wxRentContract,rentContract); +// rentContract.setRentalStartDate(wxRentContract.getRentalStartDate()); +// rentContract.setRentalEndDate(wxRentContract.getRentalEndDate()); +// rentContract.setShopId(shopId); +// allShopContract.put(shopId, rentContract); +// } +// } +// if (shopIds.contains(wxRentContract.getShopId())) { +// allShopContract.put(wxRentContract.getShopId(), wxRentContract); +// } +// } +// return allShopContract; +// } + +// @Override +// public int selectContractCountByShopId(WxRentContract wxRentContract) { +// return wxRentContractMapper.selectContractCountByShopId(wxRentContract) ; +// } + + @Override + public ResultData getContractByContractNumber(WxRentContract rentContract) { + WxRentContract wxRentContract = wxRentContractMapper.selectOne(new QueryWrapper<>(rentContract)); + return new ResultData(wxRentContract); + } + + @Override + public ResultData apply(WxRentContract rentContract,MallUserInfo user) { + //如果存在审批中的合同,不允许提交审批 + WxRentContract wrq = new WxRentContract(); + wrq.updateTenantInfo(user); + wrq.setMerchantId(rentContract.getMerchantId()); + wrq.setStatus(EnumRentContractStatus.PERFORMANCE.getCode()); + List clist = wxRentContractMapper.findList(wrq); + if (null != clist && clist.size() > 0 ) { + return new ResultData(Result.ERROR, "当前商户存在其他审批中的租金合同。请先作完成。"); + } + //如果该合同是租金+物业合同,则还要判断物业合同 + if(rentContract.getOperationType().intValue() == EnumContractOperationType.WHOLE.getCode().intValue()) { + WxPropertyContract wpc = new WxPropertyContract(); + wpc.updateTenantInfo(user); + wpc.setMerchantId(rentContract.getMerchantId()); + wpc.setStatus(EnumRentContractStatus.PERFORMANCE.getCode()); + List plist = wxPropertyContractMapper.findList(wpc); + if (null != plist && plist.size() > 0 ) { + return new ResultData(Result.ERROR, "当前商户存在其他审批中的物业合同。请先作完成。"); + } + } +// Integer count = wxRentContractMapper.getCanApplyCount(rentContract.getId()); +// if (null != count && count.intValue()>0) { +// return new ResultData(Result.ERROR, "当前存在其他草稿状态或者履约驳回的合同。请先作废其他草稿或者审批拒绝或者撤回的合同。"); +// } + + if (CollectionUtils.isEmpty(rentContract.getFlowParams())) { + return new ResultData(Result.ERROR, "编号["+rentContract.getId()+"]租金合同没有审批流程."); + } + + if (rentContract.getMerchantId() == null) { + return new ResultData(Result.ERROR, "编号["+rentContract.getId()+"]租金合同没有绑定商户."); + } + + if ((EnumRentContractStatus.DRAFT.getCode().intValue() == rentContract.getStatus().intValue()) + || (EnumRentContractStatus.PERFORMANCE.getCode().intValue() == rentContract.getStatus().intValue() + && (EnumRentContractAppStatus.REJECT.getCode().intValue() == rentContract.getApplyStatus().intValue() || + EnumRentContractAppStatus.SETBACK.getCode().intValue() == rentContract.getApplyStatus().intValue())) + ) { + Integer bussinessType = (Integer) rentContract.getFlowParams().get("businessType"); + if (null == bussinessType) { + return new ResultData(Result.ERROR, "编号["+rentContract.getId()+"]租金合同FlowParams错误,未找到businessType."); + } + WxFlowModel flowModle = wxFlowService.getModelByType(bussinessType, rentContract); + if (null == flowModle) { + return new ResultData(Result.ERROR, "编号["+rentContract.getId()+"]租金合同配置的流程["+String.valueOf(bussinessType)+"]未找到流程模板."); + } + //rentContract.getFlowParams().put("businessId", rentContract.getId().toString()); + wxFlowService.start(rentContract.getFlowParams(), user.getId(), user.getName(), rentContract); + return new ResultData(Result.SUCCESS,"提交审批成功",rentContract); + }else { + return new ResultData(Result.ERROR, "编号["+rentContract.getId()+"]租金合同状态不能提交审批.允许提交的状态为 [草稿],[履约中+审批驳回]"); + } + } + + @Override + @Transactional(rollbackFor = {Exception.class}) + public void outDateContract(WxMall wxMall) { + //查询有计租合同的商户 + WxRentContract wr = new WxRentContract(); + wr.setStatuss(EnumRentContractStatus.getValidStatus()); + wr.updateTenantInfo(wxMall); + List merchantIds = wxRentContractMapper.getMerchantIdsByStatuss(wr); + for (Long mid: merchantIds) { + if (null == mid) { + continue; + } + try { + //查询商户下计租到期的合同,更新合同状态 + WxRentContract wrc = new WxRentContract(); + wrc.setMerchantId(mid); + wrc.setStatus(EnumRentContractStatus.PAING.getCode()); + List contractList = wxRentContractMapper.findList(wrc); + List shopIdList = new ArrayList(); + for (WxRentContract contract:contractList) { + if (contract.getRentalEndDate().before(new Date())) { + contract.setStatus(EnumRentContractStatus.OUT_DATE.getCode()); + wxRentContractMapper.updateById(contract); + List shopIds = contract.shopIdsByRentInfo(); + for (Long sid: shopIds) { + if (!shopIdList.contains(sid)) { + shopIdList.add(sid); + } + } + } + } + + //到期合同中的店铺,如果存在有效合同,则不释放 + if (shopIdList.size() > 0 ) { + WxRentContract wrcq = new WxRentContract(); + wrcq.setMerchantId(mid); + wrcq.setStatuss(EnumRentContractStatus.getValidStatus()); + List contractList0 = wxRentContractMapper.findList(wrcq); + for (WxRentContract w : contractList0) { + List shopids0 = w.shopIdsByRentInfo(); + if (null != shopids0) { + shopIdList.removeAll(shopids0); + } + } + } + + //释放店铺 +// if (null != shopIdList && shopIdList.size() > 0) { +// wxMerchantShopMapper.delShops(mid, shopIdList); +// //更新商铺的状态为未出租 +// wxShopMapper.updateUnRentByIds(shopIdList); +// } + }catch(Exception e) { + logger.error("merchantId["+mid+"] outDateContract error.",e); + } + + } + } + + @Override + public void readyToNomal(WxMall wxMall) { + WxRentContract wr = new WxRentContract(); + wr.setStatus(EnumRentContractStatus.READY_FOR_PAING.getCode()); + wr.updateTenantInfo(wxMall); + List rentList = wxRentContractMapper.findList(wr); + if (null != rentList && rentList.size() > 0 ) { + for (WxRentContract wrc : rentList) { + if (wrc.getRentalStartDate().before(new Date())) { + wrc.setStatus(EnumRentContractStatus.PAING.getCode()); + wxRentContractMapper.updateStatus(wrc); + } + } + } + } + + @Override + public WxRentContract getSimpleDeatil(Long id) { + return wxRentContractMapper.selectById(id); + } + + @Override + public boolean hasOtherValidContractShop(WxRentContract wxRentContract) { + WxRentContract wrc = new WxRentContract(); + wrc.setMerchantId(wxRentContract.getMerchantId()); + wrc.setStatuss(EnumRentContractStatus.getValidStatus()); + List contractList = wxRentContractMapper.findList(wrc); + boolean exists =false; + for (WxRentContract wc : contractList) { + if (null != wxRentContract.shopIdsByRentInfo()) { + for (Long sid : wxRentContract.shopIdsByRentInfo()) { + if(wc.getRentInfo().indexOf(String.valueOf(sid)) != -1 ) { + exists = true; + break; + } + } + } + } + return exists; + } + + @Override + public Map findRentByShop(Long shopId) { + List> rentByShop = wxRentContractMapper.findRentByShop(shopId); + if(rentByShop != null && rentByShop.size() > 0){ + return rentByShop.get(0); + } + return null; + } + + @Override + public Map currentValidByMerchantId(TenantEntity tenantInfo, Long merchantId,String shopNumber) { + WxRentContract rentContract = new WxRentContract(); + rentContract.updateTenantInfo(tenantInfo); + rentContract.setMerchantId(merchantId); + rentContract.setShopNumber(shopNumber); + List statuss = new ArrayList<>(); + statuss.add(EnumRentContractStatus.READY_FOR_PAING.getCode()); + statuss.add(EnumRentContractStatus.PAING.getCode()); + rentContract.setStatuss(statuss); + List> rentContracts = wxRentContractMapper.currentValidByMerchantId(rentContract); + if(rentContracts != null && rentContracts.size() > 0){ + return rentContracts.get(0); + } + return null; + } + + @Override + public long findCount(WxRentContract wxRentContract) { + TenantEntity tenantEntity = new TenantEntity(); + tenantEntity.setTenantId(wxRentContract.getTenantId()); + tenantEntity.setParentTenantId(wxRentContract.getParentTenantId()); + List tenantEntitys = wxMallService.getTenantEntitys(tenantEntity); + long count = 0l; + for (TenantEntity te:tenantEntitys) { + wxRentContract.updateTenantInfo(te); + count += wxRentContractMapper.findCount(wxRentContract); + } + wxRentContract.updateTenantInfo(tenantEntity); + return count; + } + + @Override + public void setEndContractTime(WxRentContract wxRentContract) { + wxRentContractMapper.setEndContractTime(wxRentContract); + } + + @Override + public List findToEndContractList(WxRentContract record) { + return wxRentContractMapper.findToEndContractList(record); + } + + @Override + public List findToOutDateContracts(TenantEntity tenantEntity) { + WxRentContract wrc = new WxRentContract(); + wrc.setStatus(EnumRentContractStatus.PAING.getCode()); + wrc.setOutDateNofity(1); + return wxRentContractMapper.findList(wrc); + } + + public static void main(String[] args) { + System.out.println(DateUtils.getDayBegin(DateUtils.getFirstDayOfNextMonth(new Date(),-1))); + } + + @Override + public void calcuteByTradeDaily(WxRentContract wxRentContract) { + WxPayAccountBill wxPayAccountBill = wxPayAccountBillService.getByTenantInfo(wxRentContract); + //查询合同下截止时间为昨天的账单 + WxBillRent bq = new WxBillRent(); + bq.updateTenantInfo(wxRentContract); + bq.setRentContractId(wxRentContract.getId()); + bq.setIsPreview(EnumIsPreview.NO.getCode()); + Date current = new Date(); + //从上个月1号开始的都更新 + bq.setEndtimeBegin(DateUtils.getDayBegin(DateUtils.getFirstDayOfNextMonth(current,-1))); + bq.setEndtimeEnd(current); + bq.setIsDel(EnumDelStatus.NOT_DEL.getCode()); + List billList = wxBillRentMapper.findList(bq); + if (null != billList && billList.size() > 0 ) { + for (int j = 0 ; j < billList.size(); j++) { + WxBillRent br = billList.get(j); + try { + //判断账单是否跨月,如果跨月,需要按照每月来查询解单金额 + BigDecimal needPay = new BigDecimal(0) ; + int months = DateUtils.monthsBetween(br.getStarttime(), br.getEndtime()); + if ( months > 0 ) { + for (int i = 0 ; i <= months ; i++ ) { + BigDecimal _money = new BigDecimal(0); + if (i == 0 ) { + _money = sumTradeDailyBySameMonthDay(Constant.default_long_decimal_size,bq, wxRentContract.getMerchantId(), br.getStarttime(), + DateUtils.getLastDayForMonth(br.getStarttime())); + }else if (i == months){ + _money = sumTradeDailyBySameMonthDay(Constant.default_long_decimal_size,bq, wxRentContract.getMerchantId(), + DateUtils.getFirstDayForCurrMonth(DateUtils.getTimeAfterMonths(i,br.getStarttime())), + DateUtils.getDayEnd(DateUtils.getTimeAfterDays(-1, br.getEndtime()))); + }else { + Date _date = DateUtils.getTimeAfterMonths(i,br.getStarttime()); + _money = sumTradeDailyBySameMonthDay(Constant.default_long_decimal_size,bq, wxRentContract.getMerchantId(), + DateUtils.getFirstDayForCurrMonth(_date), + DateUtils.getLastDayForMonth(_date)); + } + needPay = needPay.add(_money); + } + }else { + //同一个月 + //合同账单结束的时间是00:00:00,取日期要取前一天 + needPay = sumTradeDailyBySameMonthDay(Constant.default_long_decimal_size,bq, wxRentContract.getMerchantId(), + br.getStarttime(), DateUtils.getDayEnd(br.getEndtime())); + } + needPay = needPay.multiply(new BigDecimal(wxRentContract.getPayRatio())) + .divide(new BigDecimal(10000), wxRentContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP); + String oldNeedPay = br.getNeedPay(); + if (needPay.compareTo(new BigDecimal(br.getNeedPay())) > 0) { + br.setNeedPay(needPay.toPlainString()); + //br.setOwe(needPay.toPlainString()); + br.setReceivePay(needPay.toPlainString()); + br.setUpdatetime(new Date()); + BigDecimal servicePay = new BigDecimal(br.getReceivePay()).multiply(new BigDecimal(wxPayAccountBill.getServiceChargeRate())).divide(new BigDecimal(10000), wxRentContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP); + br.setServiceChargePay(servicePay.toPlainString()); + //br.setOwe(new BigDecimal(br.getReceivePay()).add(new BigDecimal(br.getServiceChargePay())).toPlainString()); + //br.setOwe(new BigDecimal(br.getReceivePay()).toPlainString()); + br.setComments("原金额["+oldNeedPay+"(分)]小于解单金额["+needPay+"(分)],系统自动更新"); + wxBillRentMapper.updateById(br); + } + }catch(Exception e) { + logger.error("calcuteByTradeDaily error:"+br.getId(),e); + } + } + } + } + + private BigDecimal sumTradeDailyBySameMonthDay(Integer decimalSize,TenantEntity tenantEntity,Long merchantId,Date begin ,Date end) { + //如果有按月的,则取按月来算 + WxMerchantTradeDaily tdq = new WxMerchantTradeDaily(); + tdq.updateTenantInfo(tenantEntity); + tdq.setMerchantId(merchantId); + tdq.setDateType(EnumTradeDailyDateType.MONTH.getCode()); + tdq.setReportDate(DateUtils.date2String(begin, DateUtils.DATE_PATTERN_MONTH)); + List monthList = wxMerchantTradeDailyMapper.findList(tdq); + if (null != monthList && monthList.size() > 0 ){ + int monthSums = monthList.get(0).getTradeAmtInteger(); + Date _fistDay = DateUtils.getDayBegin(DateUtils.getFirstDayForCurrMonth(begin)); + Date _lastDay = DateUtils.getLastDayForMonth(begin); + if (begin.equals(_fistDay) && end.equals(_lastDay)) { + //满月 + return new BigDecimal(monthSums); + }else { + //根据天数计算 + int monthDays = DateUtils.daysBetween(_fistDay, _lastDay)+1; + int _days = DateUtils.daysBetween(begin, end)+1; + if (_days == 0) { + _days = 1;//当天 + } + BigDecimal servicePay = new BigDecimal(monthSums).multiply(new BigDecimal(_days)).divide(new BigDecimal(monthDays), decimalSize, BigDecimal.ROUND_HALF_UP); + return servicePay; + } + }else { + WxMerchantTradeDaily tdq1 = new WxMerchantTradeDaily(); + tdq1.updateTenantInfo(tenantEntity); + tdq1.setMerchantId(merchantId); + tdq1.setDateType(EnumTradeDailyDateType.DAY.getCode()); + tdq1.setStartTime(DateUtils.format(begin)); + tdq1.setEndTime(DateUtils.format(end)); + String sumMoney = wxMerchantTradeDailyMapper.findSumMoney(tdq1); + return new BigDecimal(sumMoney); + } + } + + @Override + public List findDepositTypes(WxRentContractDepositType rentContract) { + return wxRentContractDepositTypeMapper.findList(rentContract); + } + + private Map findDepositTypesMap(WxRentContractDepositType rentContract) { + List types = findDepositTypes(rentContract); + if (null != types && types.size() > 0 ) { + Map tmap = new HashMap(); + for (int i = 0 ; i < types.size(); i++ ) { + WxRentContractDepositType dt = types.get(i); + tmap.put(dt.getId(), dt); + } + return tmap; + } + return null; + } + + @Override + public void saveOrUpdateDepositType(WxRentContractDepositType rentContract) { + if (null == rentContract.getId()) { + final IdWorker idWorker = IdWorker.get(); + rentContract.setId(idWorker.nextId()); + rentContract.setCreateTime(new Date()); + rentContract.setUpdateTime(new Date()); + wxRentContractDepositTypeMapper.insert(rentContract); + }else { + rentContract.setUpdateTime(new Date()); + wxRentContractDepositTypeMapper.updateById(rentContract); + } + } +}