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 144b66273..b6ce2913b 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java @@ -290,17 +290,16 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService //查询主账单列表,排除其他标砖费用,包括一次性费用,非一次性费用 WxAllBill wxBillRent = new WxAllBill(); wxBillRent.setPropertyContractId(id); - wxBillRent.setSortColumns("starttime asc"); wxBillRent.updateTenantInfo(tenantEntity); //物业主账单 wxBillRent.setEnergyFeesId(EnumBillAllType.PROPERTY.getEnergyFeesId()); - List retList = wxAllBillMapper.findList(wxBillRent); + List retList = wxAllBillMapper.findContractSamePeriodSum(wxBillRent); //获取非一次性的, wxBillRent.setEnergyFeesId(null); wxBillRent.setBillType(EnumBillAllType.PROPERTY.getCode()); wxBillRent.setHasParentBillId(EnumYesOrNo.YES.getCode()); - List unFixedList = wxAllBillMapper.findList(wxBillRent); + List unFixedList = wxAllBillMapper.findContractSamePeriodSum(wxBillRent); Map> childMap = null; if (null != unFixedList && unFixedList.size() > 0 ) { childMap = new HashMap>(); @@ -873,7 +872,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); Map resultMap = new HashedMap(); List propertyResultList = new ArrayList(); - List allResultList = new ArrayList(); + List fixedResultList = new ArrayList(); Date endDate = null; if(yearList.size() > 1){ @@ -997,72 +996,72 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService //设置科目 property.setEnergyFeesId(svo.getFeeStandards().getId()); property.setFeesStandarsId(property.getEnergyFeesId());//合同动态表格需要。 - allResultList.add(property); childList.add(property); } } wxBillProperty.setChildList(childList); //主账单列表 propertyResultList.add(wxBillProperty); - if (new BigDecimal(wxBillProperty.getReceivePay()).compareTo(new BigDecimal(0)) > 0 ) { - allResultList.add(wxBillProperty); - } + } if (null != fixedList && fixedList.size() > 0 ) { for (int i = 0 ; i < fixedList.size(); i ++ ) { WxBillFeesStandardsListVo svo = fixedList.get(i); WxAllBill property = generateBillPropertyByBillStandards(null,wxPayAccountBill,wxPropertyContract,isPreview,user,svo,billcount,shopInfo); - allResultList.add(property); + fixedResultList.add(property); } } //批量生成预账单 - if(saveDb && allResultList.size() > 0 ) { - + if(saveDb) { WxShopUsers suq = new WxShopUsers(); suq.updateTenantInfo(wxPropertyContract); suq.setShopIds(shopIdList); suq.setStatus(EnumShopUsersStatus.LIVE.getCode()); Map shopUserMap = wxShopService.getShopUserMap(suq); - - final IdWorker idWorker = IdWorker.get(); //根据店铺来拆分 List shopAllBillList = new ArrayList(); - for (int i = 0 ; i < allResultList.size(); i++ ) { - WxAllBill rb = allResultList.get(i); - for (int g = 0 ; g < shopIdList.size(); g ++ ){ - WxAllBill rs = new WxAllBill(); - Long sid = shopIdList.get(g); - BigDecimal shoprentArea = shopAreaRateMap.get(sid); - BigDecimal shoprate = shoprentArea.divide(new BigDecimal(wxPropertyContract.getRentArea()),wxPropertyContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); - - try { - BeanUtils.copyProperties(rs, rb); - rs.setId(idWorker.nextId()); - rs.setShopId(sid); - rs.setNeedPay(new BigDecimal(rb.getNeedPay()).multiply(shoprate).toPlainString()); - rs.setReceivePay(rs.getNeedPay()); - rs.setShopId(sid); - rs.setRentArea(shoprentArea.toPlainString()); - if (null != shopUserMap ) { - WxShopUsers wsu = shopUserMap.get(sid); - if (null != wsu) { - rs.setCusName(wsu.getName()); - } - }; - shopAllBillList.add(rs); - } catch (IllegalAccessException e) { - logger.error("saveBill error.",e); - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"创建账单失败"); - } catch (InvocationTargetException e) { - logger.error("saveBill error.",e); - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"创建账单失败"); - } - } + + if (propertyResultList.size() > 0 ) { + for (int i = 0 ; i < propertyResultList.size(); i++ ) { + WxAllBill rb = propertyResultList.get(i); + for (int g = 0 ; g < shopIdList.size(); g ++ ){ + //主物业账单根据店铺拆分 + Long sid = shopIdList.get(g); + WxAllBill rs = new WxAllBill(); + setNewsBills(wxPropertyContract, rs, rb, sid, shopAreaRateMap,shopUserMap); + shopAllBillList.add(rs); + + //其他周期的费用账单也需要拆分,并关联parentBillId + if (null != rb.getChildList() && rb.getChildList().size() > 0) { + for (int h = 0 ; h < rb.getChildList().size(); h++ ) { + WxAllBill ufb = rb.getChildList().get(h); + WxAllBill ufbn = new WxAllBill(); + setNewsBills(wxPropertyContract, ufbn, ufb, sid, shopAreaRateMap,shopUserMap); + ufbn.setParentBillId(rs.getId()); + shopAllBillList.add(rs); + } + } + } + } + } + //一次性费用 + if (fixedResultList.size() > 0 ) { + for (int i = 0 ; i < fixedResultList.size(); i++ ) { + WxAllBill rb = fixedResultList.get(i); + for (int g = 0 ; g < shopIdList.size(); g ++ ){ + Long sid = shopIdList.get(g); + WxAllBill rs = new WxAllBill(); + setNewsBills(wxPropertyContract, rs, rb, sid, shopAreaRateMap,shopUserMap); + shopAllBillList.add(rs); + } + } } - wxAllBillMapper.insertBills(wxPropertyContract.getTenantId() ,shopAllBillList); + if (shopAllBillList.size() > 0 ) { + wxAllBillMapper.insertBills(wxPropertyContract.getTenantId() ,shopAllBillList); + } //for (int i = 0 ; i < resultList.size() ; i++) { // wxBillPropertyMapper.insert(resultList.get(i)); //} @@ -1072,6 +1071,33 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService return resultMap; } + private void setNewsBills(WxPropertyContract wxPropertyContract,WxAllBill newBill,WxAllBill oldBill,Long shopId,Map shopAreaRateMap,Map shopUserMap) { + + BigDecimal shoprentArea = shopAreaRateMap.get(shopId); + BigDecimal shoprate = shoprentArea.divide(new BigDecimal(wxPropertyContract.getRentArea()),wxPropertyContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); + final IdWorker idWorker = IdWorker.get(); + try { + BeanUtils.copyProperties(newBill, oldBill); + newBill.setId(idWorker.nextId()); + newBill.setShopId(shopId); + newBill.setNeedPay(new BigDecimal(oldBill.getNeedPay()).multiply(shoprate).toPlainString()); + newBill.setReceivePay(newBill.getNeedPay()); + newBill.setRentArea(shoprentArea.toPlainString()); + if (null != shopUserMap ) { + WxShopUsers wsu = shopUserMap.get(shopId); + if (null != wsu) { + newBill.setCusName(wsu.getName()); + } + }; + } catch (IllegalAccessException e) { + logger.error("saveBill error.",e); + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"创建账单失败"); + } catch (InvocationTargetException e) { + logger.error("saveBill error.",e); + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"创建账单失败"); + } + } + private WxAllBill generateBillPropertyByBillStandards(WxAllBill wxBillProperty,WxPayAccountBill wxPayAccountBill,WxPropertyContract wxPropertyContract,Integer isPreview,MallUserInfo user,WxBillFeesStandardsListVo svo, Integer billcount,Map shopInfo) {