From a06e11838d8d833aee1597dec2c665477fe98b7a Mon Sep 17 00:00:00 2001 From: luozukai Date: Fri, 22 Feb 2019 16:59:13 +0800 Subject: [PATCH] =?UTF-8?q?[=E9=93=9C=E9=94=A3=E6=B9=BE][=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0][=E9=A2=84=E8=B4=A6=E5=8D=95]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WxPropertyContractController.java | 4 +- .../iformall/domain/po/WxBillProperty.java | 1 + .../com/iformall/domain/po/WxBillRent.java | 1 + .../impl/WxPropertyContractServiceImpl.java | 37 +++++--- .../impl/WxRentContractServiceImpl.java | 89 +++++++++++-------- .../resources/mapper/WxBillPropertyMapper.xml | 6 +- .../resources/mapper/WxBillRentMapper.xml | 6 +- 7 files changed, 90 insertions(+), 54 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxPropertyContractController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxPropertyContractController.java index 5470e6d1f..ccf377651 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxPropertyContractController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxPropertyContractController.java @@ -81,9 +81,9 @@ public class WxPropertyContractController extends BaseController { } /** - * 生成账单 + * 生成预览账单 */ - @ApiOperation("生成账单") + @ApiOperation("生成预览账单") @GetMapping(value = "/buildBill") public ResultData buildBill(@ModelAttribute WxRentContract wxRentContract) { logger.debug("[" + getIpAddr() + "] WxPropertyContractController::buildBill"); diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillProperty.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillProperty.java index 73bb32326..95bc482ba 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillProperty.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillProperty.java @@ -318,6 +318,7 @@ public class WxBillProperty implements Serializable { ,UserId_ASC("`userId` ASC"),UserId_DESC("`userId` DESC") ,ShopId_ASC("`shopId` ASC"),ShopId_DESC("`shopId` DESC") ,Updatetime_ASC("`updatetime` ASC"),Updatetime_DESC("`updatetime` DESC") + ,Period_ASC("`period` ASC") ; private String value; Field(String value){ diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java index 45b605c21..7a3501907 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java @@ -318,6 +318,7 @@ public class WxBillRent implements Serializable { ,MerchantId_ASC("`merchantId` ASC"),MerchantId_DESC("`merchantId` DESC") ,UserId_ASC("`userId` ASC"),UserId_DESC("`userId` DESC") ,ShopId_ASC("`shopId` ASC"),ShopId_DESC("`shopId` DESC") + ,Period_ASC("`period` ASC") ; private String value; Field(String value){ 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 919b433f6..e8857d90b 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java @@ -121,13 +121,20 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService result.put("remark",flowRecordList.get(0).getRemark()); } - //生成预览账单 - if(wxPropertyContract.getReceivePeriod() != null && wxPropertyContract.getLease()!=null) { - wxBillPropertyMapper.deletePreviewBill(wxPropertyContract); - //重新生成 - List billList = buildProperty(new WxMerchant(),wxPropertyContract,EnumIsPreview.YES.getCode()); - wxPropertyContract.setPreviewBillRentList(billList); - } +// //生成预览账单 +// if(wxPropertyContract.getReceivePeriod() != null && wxPropertyContract.getLease()!=null) { +// wxBillPropertyMapper.deletePreviewBill(wxPropertyContract); +// //重新生成 +// List billList = buildProperty(new WxMerchant(),wxPropertyContract,EnumIsPreview.YES.getCode()); +// wxPropertyContract.setPreviewBillRentList(billList); +// } + //查询预账单用于展示 + WxBillProperty wxBillRent = new WxBillProperty(); + wxBillRent.setPropertyContractId(id); + wxBillRent.setSortColumns(WxBillProperty.Field.Period_ASC); + wxBillRent.setIsPreview(EnumIsPreview.YES.getCode()); + List resultList = wxBillPropertyMapper.findList(wxBillRent); + wxPropertyContract.setPreviewBillRentList(resultList); return new ResultData(Result.SUCCESS, "查询成功", result); } @@ -482,6 +489,9 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService } } } + for (int i = 0; i < result.size(); i++) { + result.get(i).setPeriod(i+1); + } return result; } @@ -729,11 +739,14 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService //生成预览账单 //根据租赁合同找到对应的物业合同,生成物业账单 WxPropertyContract propertyContract = wxPropertyContractMapper.findOneByRentId(wxRentContract); - if(propertyContract!=null && propertyContract.getReceivePeriod() != null && propertyContract.getLease()!=null) { - wxBillPropertyMapper.deletePreviewBill(propertyContract); - //重新生成 - List billList = buildProperty(new WxMerchant(),propertyContract,EnumIsPreview.YES.getCode()); - return billList; + if(propertyContract != null) { + if(!wxRentContract.getLease().equals(propertyContract.getLease()) + ||!wxRentContract.getPrice().equals(propertyContract.getPrice())){ + wxBillPropertyMapper.deletePreviewBill(propertyContract); + //重新生成 + List billList = buildProperty(new WxMerchant(),propertyContract,EnumIsPreview.YES.getCode()); + return billList; + } } return new ArrayList<>(); } 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 70ebcd6cb..7737eb83b 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -15,6 +15,7 @@ import com.iformall.mapper.*; import com.iformall.service.*; import com.iformall.utils.Constant; import com.iformall.utils.DateUtils; +import org.apache.commons.collections.map.HashedMap; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.poi.xwpf.usermodel.XWPFDocument; @@ -146,13 +147,13 @@ public class WxRentContractServiceImpl implements WxRentContractService { result.put("remark",flowRecordList.get(0).getRemark()); } - //删除预账单 - if(wxRentContract.getReceivePeriod() != null && wxRentContract.getLease()!=null && wxRentContract.getRentalStartDate()!=null && wxRentContract.getPrice()!= null){ - wxBillRentMapper.deletePreviewBill(wxRentContract); - //重新生成 - List resultList = buildRent(new WxMerchant(),null,wxRentContract,EnumIsPreview.YES.getCode()); - wxRentContract.setPreviewBillRentList(resultList); - } + //查询预账单用于展示 + WxBillRent wxBillRent = new WxBillRent(); + wxBillRent.setRentContractId(id); + wxBillRent.setSortColumns(WxBillRent.Field.Period_ASC); + wxBillRent.setIsPreview(EnumIsPreview.YES.getCode()); + List resultList = wxBillRentMapper.findList(wxBillRent); + wxRentContract.setPreviewBillRentList(resultList); return new ResultData(Result.SUCCESS, "查询成功", result); } @@ -243,36 +244,43 @@ public class WxRentContractServiceImpl implements WxRentContractService { @Transactional(rollbackFor = {Exception.class}) @Override public ResultData update(WxRentContract record, Long userId,String userName) { + //删除预账单 + List resultList = new ArrayList<>(); + if(record.getReceivePeriod() != null && record.getLease()!=null && record.getPrice()!= null){ + //对比上一次,是否有更改,有,重新生成预账单 + WxRentContract dbRent = wxRentContractMapper.selectByPrimaryKey(record.getId()); + if(!record.getReceivePeriod().equals(dbRent.getReceivePeriod()) + ||!record.getLease().equals(dbRent.getLease()) + ||!record.getType().equals(dbRent.getType()) + ||!record.getPrice().equals(dbRent.getPrice()) + ||!record.getAdjustRatio().equals(dbRent.getAdjustRatio()) + ) { + wxBillRentMapper.deletePreviewBill(record); + //重新生成 + resultList = buildRent(new WxMerchant(), null, record, EnumIsPreview.YES.getCode()); + } + } + ResultData resultData = getResultDataForUpdate(record, userId); - try { - //启动审批流 - if(record.getFlowParams() != null){ - record.getFlowParams().put("businessId",record.getId().toString()); - if(record.getMerchantId() != null) { - record.getFlowParams().put("supplement", true); //设置补录 - } - wxFlowService.start(record.getFlowParams(),userId,userName,record.getTenantId()); - //合同状态改成待签约 - WxRentContract updateRentContract = new WxRentContract(); - updateRentContract.setId(record.getId()); - updateRentContract.setStatus(EnumRentContractStatus.WAIT_SIGN.getCode()); - wxRentContractMapper.updateStatus(updateRentContract); - logger.info("id:{},启动审批流成功 ,是否补录:{}",record.getId().toString(),record.getMerchantId() != null); + //启动审批流 + if(record.getFlowParams() != null){ + record.getFlowParams().put("businessId",record.getId().toString()); + if(record.getMerchantId() != null) { + record.getFlowParams().put("supplement", true); //设置补录 } - } catch (Exception e) { - logger.error("启动审批流失败,e:" + e.getMessage()); - throw new MallinkException(ErrorCode.FLOW_FAIL.getCode(), "FLOW FAILD " + e.getMessage()); + wxFlowService.start(record.getFlowParams(),userId,userName,record.getTenantId()); + + //合同状态改成待签约 + WxRentContract updateRentContract = new WxRentContract(); + updateRentContract.setId(record.getId()); + updateRentContract.setStatus(EnumRentContractStatus.WAIT_SIGN.getCode()); + wxRentContractMapper.updateStatus(updateRentContract); + logger.info("id:{},启动审批流成功 ,是否补录:{}",record.getId().toString(),record.getMerchantId() != null); } - WxRentContract wxRentContract = (WxRentContract)resultData.data; - //删除预账单 - if(record.getReceivePeriod() != null && record.getLease()!=null && record.getRentalStartDate()!=null && record.getPrice()!= null){ - wxBillRentMapper.deletePreviewBill(record); - //重新生成 - List resultList = buildRent(new WxMerchant(),null,record,EnumIsPreview.YES.getCode()); - wxRentContract.setPreviewBillRentList(resultList); - } + WxRentContract wxRentContract = (WxRentContract)resultData.data; + wxRentContract.setPreviewBillRentList(resultList); return new ResultData(wxRentContract); } @@ -428,9 +436,13 @@ public class WxRentContractServiceImpl implements WxRentContractService { rentList = buildRentMonth(wxMerchant, userId, wxRentContract, receivePeriod, lease, rentalStartDate, price,isPreview); } else { //按日计租 - rentList = buildRent(lease, receivePeriod, price, rentalStartDate, Calendar.DAY_OF_MONTH, wxRentContract, userId, wxMerchant, 0,isPreview); + Map resultMap = buildRent(lease, receivePeriod, price, rentalStartDate, Calendar.DAY_OF_MONTH, wxRentContract, userId, wxMerchant, 0,isPreview); + rentList = ( List)resultMap.get("billList"); } } + for (int i = 0; i < rentList.size(); i++) { + rentList.get(i).setPeriod(i+1); + } return rentList; } @@ -464,13 +476,16 @@ public class WxRentContractServiceImpl implements WxRentContractService { instance.setTime(rentalStartDate); //开始时间 instance.add(Calendar.MONTH, month * i); - List billRentList = buildRent(leaseArr[i], receivePeriod, priceArr[i], instance.getTime(), Calendar.MONTH, wxRentContract, userId, wxMerchant, billcount,isPreview); + Map resultMap = buildRent(leaseArr[i], receivePeriod, priceArr[i], instance.getTime(), Calendar.MONTH, wxRentContract, userId, wxMerchant, billcount,isPreview); + List billRentList = (List)resultMap.get("billList"); + billcount = (Integer)resultMap.get("billcount"); resultList.addAll(billRentList); } return resultList; } - public List buildRent(int lease, int receivePeriod, int price, Date startdate, int dayType, WxRentContract wxRentContract, Long userId, WxMerchant wxMerchant, int billcount,Integer isPreview) { + public Map buildRent(int lease, int receivePeriod, int price, Date startdate, int dayType, WxRentContract wxRentContract, Long userId, WxMerchant wxMerchant, int billcount,Integer isPreview) { + Map resultMap = new HashedMap(); List resultList = new ArrayList<>(); int extralease = lease % receivePeriod; int extracount = extralease > 0 ? 1 : 0; @@ -561,7 +576,9 @@ public class WxRentContractServiceImpl implements WxRentContractService { throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); } } - return resultList; + resultMap.put("billcount",billcount); + resultMap.put("billList",resultList); + return resultMap; } diff --git a/mallinkService/src/main/resources/mapper/WxBillPropertyMapper.xml b/mallinkService/src/main/resources/mapper/WxBillPropertyMapper.xml index 9abd020b3..fcbc87668 100644 --- a/mallinkService/src/main/resources/mapper/WxBillPropertyMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillPropertyMapper.xml @@ -38,7 +38,7 @@ - where is_preview = 0 + where 1=1 and `id` = #{id} and `property_contract_id` = #{propertyContractId} and `receive_pay` = #{receivePay} @@ -57,7 +57,9 @@ and `shop_id` = #{shopId} and `updatetime` = #{updatetime} and `rent_shop_type` = #{rentShopType} - + and is_preview = 0 + and is_preview = #{isPreview} + and id in diff --git a/mallinkService/src/main/resources/mapper/WxBillRentMapper.xml b/mallinkService/src/main/resources/mapper/WxBillRentMapper.xml index ad81224e8..db499bfc4 100644 --- a/mallinkService/src/main/resources/mapper/WxBillRentMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillRentMapper.xml @@ -37,7 +37,7 @@ - where is_preview = 0 + where 1=1 and `id` = #{id} and `rent_contract_id` = #{rentContractId} and `receive_pay` = #{receivePay} @@ -56,7 +56,9 @@ and `shop_id` = #{shopId} and `updatetime` = #{updatetime} and `rent_shop_type` = #{rentShopType} - + and is_preview = 0 + and is_preview = #{isPreview} + and id in