|  |  |  | 
|---|
|  |  |  | //处理 | 
|---|
|  |  |  | dealBackRentBillBiz(param); | 
|---|
|  |  |  | YwContract update = new YwContract(); | 
|---|
|  |  |  | update.setId(param.getId()); | 
|---|
|  |  |  | update.setEditDate(new Date()); | 
|---|
|  |  |  | update.setEditor(param.getLoginUserInfo().getId()); | 
|---|
|  |  |  | update.setBtActDate(update.getEditDate()); | 
|---|
|  |  |  | update.setBtActUserId(update.getEditor()); | 
|---|
|  |  |  | update.setStatus(Constants.THREE); | 
|---|
|  |  |  | if(Objects.nonNull(param.getBtWaitBill()) && param.getBtWaitBill() > Constants.ZERO){ | 
|---|
|  |  |  | update.setStatus(Constants.THREE); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | update.setStatus(Constants.FOUR); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | update.setBtInfo(param.getBtInfo()); | 
|---|
|  |  |  | update.setBtDate(param.getBtDate()); | 
|---|
|  |  |  | update.setBtType(param.getBtType()); | 
|---|
|  |  |  | 
|---|
|  |  |  | ywContractMapper.updateById(update); | 
|---|
|  |  |  | dealLogBiz(param,Constants.YwLogType.CONTRACT_BACK, param.getLoginUserInfo().getRealname(),getbackRentLogByParam(param)); | 
|---|
|  |  |  | return param.getId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public  void dealTimeOut(){ | 
|---|
|  |  |  | //定时处理合同执行中 | 
|---|
|  |  |  | ywContractMapper.update(new UpdateWrapper<YwContract>() | 
|---|
|  |  |  | .lambda() | 
|---|
|  |  |  | .set(YwContract::getStatus,Constants.ONE) | 
|---|
|  |  |  | .set(YwContract::getEditDate,DateUtil.getCurrDateTime()) | 
|---|
|  |  |  | .eq(YwContract::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .in(YwContract::getStatus,Constants.ZERO) | 
|---|
|  |  |  | .apply(" START_DATE < NOW()  AND END_DATE > NOW() ") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //定时处理合同已过期 | 
|---|
|  |  |  | ywContractMapper.update(new UpdateWrapper<YwContract>() | 
|---|
|  |  |  | .lambda() | 
|---|
|  |  |  | .set(YwContract::getStatus,Constants.TWO) | 
|---|
|  |  |  | .set(YwContract::getEditDate,DateUtil.getCurrDateTime()) | 
|---|
|  |  |  | .eq(YwContract::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .in(YwContract::getStatus,Constants.ONE,Constants.ZERO) | 
|---|
|  |  |  | .apply(" END_DATE < NOW() ") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void dealBackRentBillBiz(YwContract param) { | 
|---|
|  |  |  | 
|---|
|  |  |  | //付款状态:0=待收款;1=已结清;2=部分结清;3=待付款;4=待退款;5=已关闭 | 
|---|
|  |  |  | // 如果是押金或者保证金,不支持退款,保持原来的状态, 0=租赁费;1=物业费;2=租赁押金;3=物业押金;4=水电费;5=杂项费;6=其他;7=保证金 | 
|---|
|  |  |  | if(Constants.equalsInteger(Constants.THREE,bill.getCostType()) | 
|---|
|  |  |  | ||  Constants.equalsInteger(Constants.FOUR,bill.getCostType()) | 
|---|
|  |  |  | ||  Constants.equalsInteger(Constants.TWO,bill.getCostType()) | 
|---|
|  |  |  | ||Constants.equalsInteger(Constants.SEVEN,bill.getCostType())){ | 
|---|
|  |  |  | //押金和保证金 | 
|---|
|  |  |  | yjBills.add(bill); | 
|---|
|  |  |  | 
|---|
|  |  |  | ywContractBillMapper.updateById(b); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int yjNoBills =0; | 
|---|
|  |  |  | if(yjBills.size()>0){ | 
|---|
|  |  |  | // 如果是押金或者保证金,不支持退款,保持原来的状态, 0=租赁费;1=物业费;2=租赁押金;3=物业押金;4=水电费;5=杂项费;6=其他;7=保证金 | 
|---|
|  |  |  | for(YwContractBill bill : yjBills){ | 
|---|
|  |  |  | if(!Constants.equalsInteger(bill.getPayStatus(),Constants.ONE) ){ | 
|---|
|  |  |  | //如果是未结清押金 | 
|---|
|  |  |  | yjNoBills ++; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal totalBackFee = new BigDecimal(0); | 
|---|
|  |  |  | if(canBills.size()>0){ | 
|---|
|  |  |  | //直接关闭关闭账单 | 
|---|
|  |  |  | 
|---|
|  |  |  | fee = Constants.formatBigdecimal(b.getActReceivableFee()).subtract(editBill.getReceivableFee()); | 
|---|
|  |  |  | if(fee.compareTo(new BigDecimal(0))== 0){ | 
|---|
|  |  |  | //如果费用正好,则修改账单信息为已结清 | 
|---|
|  |  |  | b.setStatus(Constants.ONE); | 
|---|
|  |  |  | b.setPayStatus(Constants.ONE); | 
|---|
|  |  |  | }else if(fee.compareTo(new BigDecimal(0))> 0){ | 
|---|
|  |  |  | //如果需要进行退款,更新账单信息为待退款 | 
|---|
|  |  |  | b.setStatus(Constants.FOUR); | 
|---|
|  |  |  | b.setPayStatus(Constants.FOUR); | 
|---|
|  |  |  | }else if(fee.compareTo(new BigDecimal(0)) < 0){ | 
|---|
|  |  |  | //如果账单还有款待收,则保持状态不变 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | addBill.setContractId(param.getId()); | 
|---|
|  |  |  | addBill.setType(Constants.ONE); | 
|---|
|  |  |  | addBill.setStatus(Constants.ZERO); | 
|---|
|  |  |  | if(Constants.equalsInteger(addBill.getFeeType(),Constants.ONE)){ | 
|---|
|  |  |  | addBill.setStartDate(addBill.getPlanPayDate()); | 
|---|
|  |  |  | addBill.setEndDate(addBill.getPlanPayDate()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Constants.equalsInteger(addBill.getBillType(),Constants.ZERO)){ | 
|---|
|  |  |  | //如果是收款 | 
|---|
|  |  |  | totalBackFee = totalBackFee.add(Constants.formatBigdecimal(addBill.getActReceivableFee())); | 
|---|
|  |  |  | 
|---|
|  |  |  | newBills.add(addBill); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ywContractBillMapper.insert(param.getAddBillList());//批量插入数据 | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int yjNoBills =0; | 
|---|
|  |  |  | if(yjBills.size()>0){ | 
|---|
|  |  |  | // 如果是押金或者保证金,不支持退款,保持原来的状态, 0=租赁费;1=物业费;2=租赁押金;3=物业押金;4=水电费;5=杂项费;6=其他;7=保证金 | 
|---|
|  |  |  | for(YwContractBill bill : yjBills){ | 
|---|
|  |  |  | if(!Constants.equalsInteger(bill.getPayStatus(),Constants.ONE) ){ | 
|---|
|  |  |  | //                    YwContractBill b = new YwContractBill(); | 
|---|
|  |  |  | //                    //付款状态:0=待收款;1=已结清;2=部分结清;3=待付款;4=待退款;5=已关闭 | 
|---|
|  |  |  | //                    //如果账单信息做了编辑,金额计算 实收金额 和 修改后应收金额作对比,判断是否应该退款 | 
|---|
|  |  |  | //                    BigDecimal fee = Constants.formatBigdecimal(bill.getActReceivableFee()).subtract(bill.getReceivableFee()); | 
|---|
|  |  |  | //                    if(fee.compareTo(new BigDecimal(0))== 0){ | 
|---|
|  |  |  | //                        //如果费用正好,则修改账单信息为已结清 | 
|---|
|  |  |  | //                        b.setPayStatus(Constants.ONE); | 
|---|
|  |  |  | //                    }else if(fee.compareTo(new BigDecimal(0))> 0){ | 
|---|
|  |  |  | //                        //如果需要进行退款,更新账单信息为待退款 | 
|---|
|  |  |  | //                        b.setPayStatus(Constants.FOUR); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                    b.setId(bill.getId()); | 
|---|
|  |  |  | //                    b.setEditDate(param.getEditDate()); | 
|---|
|  |  |  | //                    b.setEditor(param.getEditor()); | 
|---|
|  |  |  | //                    b.setReceivableFee(BigDecimal.ZERO); | 
|---|
|  |  |  | //                    ywContractBillMapper.updateById(b); | 
|---|
|  |  |  | //如果是未结清押金 | 
|---|
|  |  |  | yjNoBills ++; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | param.setBtWaitBill(canBills.size() + newBills.size()+yjNoBills);//未清算的账单数量 | 
|---|
|  |  |  | param.setBtCLoseBill(closeBills.size()); | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,合同信息不存在,请返回列表刷新重试!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SystemUser user = systemUserMapper.selectById(param.getUserId()); | 
|---|
|  |  |  | SystemUser user = systemUserMapper.selectById(param.getBtUserId()); | 
|---|
|  |  |  | if(user ==null ||  (user.getDeleted()!=null&& user.getDeleted() )){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,经办人信息不存在!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void dealDetailListBiz(YwContract model) { | 
|---|
|  |  |  | List<YwContractDetail> details = new ArrayList<>(); | 
|---|
|  |  |  | List<YwContractDetail> details1 = new ArrayList<>(); | 
|---|
|  |  |  | List<YwContractDetail> details2 = new ArrayList<>(); | 
|---|
|  |  |  | int num = 0; | 
|---|
|  |  |  | if(Constants.equalsInteger(model.getType(),Constants.ZERO ) | 
|---|
|  |  |  | || Constants.equalsInteger(model.getType(),Constants.TWO)){ | 
|---|
|  |  |  | 
|---|
|  |  |  | d.setType(Constants.ZERO); | 
|---|
|  |  |  | d.setSortnum(num++); | 
|---|
|  |  |  | d.setStatus(Constants.ZERO); | 
|---|
|  |  |  | details.add(d); | 
|---|
|  |  |  | details1.add(d); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | num = 0; | 
|---|
|  |  |  | 
|---|
|  |  |  | d.setContractId(model.getId()); | 
|---|
|  |  |  | d.setSortnum(num++); | 
|---|
|  |  |  | d.setStatus(Constants.ZERO); | 
|---|
|  |  |  | details.add(d); | 
|---|
|  |  |  | details2.add(d); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(model.getId()!=null){ | 
|---|
|  |  |  | ywContractDetailMapper.insert(details);//批量插入条款信息信息 | 
|---|
|  |  |  | if(details1.size()>0){ | 
|---|
|  |  |  | ywContractDetailMapper.insert(details1);//批量插入条款信息信息 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(details2.size()>0){ | 
|---|
|  |  |  | ywContractDetailMapper.insert(details2);//批量插入条款信息信息 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //处理账单信息 | 
|---|
|  |  |  | dealBillListBiz(model,details); | 
|---|
|  |  |  | dealBillListBiz(model,details1,details2); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 支付方式 0=一次性付款;1=每三个月一付;2=六个月一付;3=一年一付 | 
|---|
|  |  |  | * @param model | 
|---|
|  |  |  | * @param details | 
|---|
|  |  |  | * @param details1 租赁条款 | 
|---|
|  |  |  | * @param details2 物业条款 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void dealBillListBiz(YwContract model, List<YwContractDetail> details) { | 
|---|
|  |  |  | private void dealBillListBiz(YwContract model, List<YwContractDetail> details1, List<YwContractDetail> details2) { | 
|---|
|  |  |  | List<YwContractBill> billList1 = new ArrayList<>(); | 
|---|
|  |  |  | List<YwContractBill> billList2 = new ArrayList<>(); | 
|---|
|  |  |  | if(Constants.equalsInteger(model.getType(),Constants.ZERO ) | 
|---|
|  |  |  | 
|---|
|  |  |  | //如果有租赁条款 | 
|---|
|  |  |  | if(Constants.formatBigdecimal(model.getZlDeposit()).compareTo(new BigDecimal(0))>0){ | 
|---|
|  |  |  | //如果有租赁押金 | 
|---|
|  |  |  | billList1.add(initDepoistBill(Constants.THREE,model,details)); | 
|---|
|  |  |  | billList1.add(initDepoistBill(Constants.TWO,model)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Constants.equalsInteger(model.getZlPayType(), Constants.ZERO)){ | 
|---|
|  |  |  | //如果是一次性付清 | 
|---|
|  |  |  | billList1.addAll(getBillsByParamOnce(model,details,model.getZlFreeStartDate(),model.getZlFreeEndDate())); | 
|---|
|  |  |  | billList1.addAll(getBillsByParamOnce(model,details1,model.getZlFreeStartDate(),model.getZlFreeEndDate())); | 
|---|
|  |  |  | }else if(Constants.equalsInteger(model.getZlPayType(), Constants.ONE)){ | 
|---|
|  |  |  | //如果每三个月一付 | 
|---|
|  |  |  | billList1.addAll(getBillsByParam3Months(model,details,model.getZlFreeStartDate(),model.getZlFreeEndDate())); | 
|---|
|  |  |  | billList1.addAll(getBillsByParam3Months(model,details1,model.getZlFreeStartDate(),model.getZlFreeEndDate())); | 
|---|
|  |  |  | }else if(Constants.equalsInteger(model.getZlPayType(), Constants.TWO)){ | 
|---|
|  |  |  | //如果六个月一付 | 
|---|
|  |  |  | billList1.addAll(getBillsByParam6Months(model,details,model.getZlFreeStartDate(),model.getZlFreeEndDate())); | 
|---|
|  |  |  | billList1.addAll(getBillsByParam6Months(model,details1,model.getZlFreeStartDate(),model.getZlFreeEndDate())); | 
|---|
|  |  |  | }else if(Constants.equalsInteger(model.getZlPayType(), Constants.THREE)){ | 
|---|
|  |  |  | //如果一年一付 | 
|---|
|  |  |  | billList1.addAll(getBillsByParam1Year(model,details,model.getZlFreeStartDate(),model.getZlFreeEndDate())); | 
|---|
|  |  |  | billList1.addAll(getBillsByParam1Year(model,details1,model.getZlFreeStartDate(),model.getZlFreeEndDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Constants.equalsInteger(model.getType(),Constants.ZERO ) | 
|---|
|  |  |  | 
|---|
|  |  |  | //如果物业条款 | 
|---|
|  |  |  | if(Constants.formatBigdecimal(model.getWyDeposit()).compareTo(new BigDecimal(0))>0){ | 
|---|
|  |  |  | //如果有租赁押金 | 
|---|
|  |  |  | billList2.add(initDepoistBill(Constants.FOUR,model,details)); | 
|---|
|  |  |  | billList2.add(initDepoistBill(Constants.THREE,model)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Constants.equalsInteger(model.getWyPayType(), Constants.ZERO)){ | 
|---|
|  |  |  | //如果是一次性付清 | 
|---|
|  |  |  | billList2.addAll(getBillsByParamOnce(model,details,model.getWyFreeStartDate(),model.getWyFreeEndDate())); | 
|---|
|  |  |  | billList2.addAll(getBillsByParamOnce(model,details2,model.getWyFreeStartDate(),model.getWyFreeEndDate())); | 
|---|
|  |  |  | }else if(Constants.equalsInteger(model.getWyPayType(), Constants.ONE)){ | 
|---|
|  |  |  | //如果每三个月一付 | 
|---|
|  |  |  | billList2.addAll(getBillsByParam3Months(model,details,model.getWyFreeStartDate(),model.getWyFreeEndDate())); | 
|---|
|  |  |  | billList2.addAll(getBillsByParam3Months(model,details2,model.getWyFreeStartDate(),model.getWyFreeEndDate())); | 
|---|
|  |  |  | }else if(Constants.equalsInteger(model.getWyPayType(), Constants.TWO)){ | 
|---|
|  |  |  | //如果六个月一付 | 
|---|
|  |  |  | billList2.addAll(getBillsByParam6Months(model,details,model.getWyFreeStartDate(),model.getWyFreeEndDate())); | 
|---|
|  |  |  | billList2.addAll(getBillsByParam6Months(model,details2,model.getWyFreeStartDate(),model.getWyFreeEndDate())); | 
|---|
|  |  |  | }else if(Constants.equalsInteger(model.getWyPayType(), Constants.THREE)){ | 
|---|
|  |  |  | //如果一年一付 | 
|---|
|  |  |  | billList2.addAll(getBillsByParam1Year(model,details,model.getWyFreeStartDate(),model.getWyFreeEndDate())); | 
|---|
|  |  |  | billList2.addAll(getBillsByParam1Year(model,details2,model.getWyFreeStartDate(),model.getWyFreeEndDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(model.getBillType() == 0){ | 
|---|
|  |  |  | model.setBillList(billList1); | 
|---|
|  |  |  | }else  if(model.getBillType() == 0){ | 
|---|
|  |  |  | }else  if(model.getBillType() == 1){ | 
|---|
|  |  |  | model.setBillList(billList2); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int num =1; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private YwContractBill initDepoistBill(int type,  YwContract model, List<YwContractDetail> details) { | 
|---|
|  |  |  | private YwContractBill initDepoistBill(int type,  YwContract model ) { | 
|---|
|  |  |  | YwContractBill bill  = new YwContractBill(); | 
|---|
|  |  |  | bill.setCreateDate(model.getEditDate()); | 
|---|
|  |  |  | bill.setCreator(model.getEditor()); | 
|---|
|  |  |  | 
|---|
|  |  |  | bill.setEndDate(model.getEndDate()); | 
|---|
|  |  |  | bill.setType(Constants.ZERO); | 
|---|
|  |  |  | bill.setCostType(type); | 
|---|
|  |  |  | YwContractDetail d = details.get(Constants.ZERO); | 
|---|
|  |  |  | if(Objects.isNull(d)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"条款数据异常"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Date planPayDate = DateUtil.addDaysToDate(d.getStartDate(),Constants.formatIntegerNum(d.getAdvanceDays()) * -1); | 
|---|
|  |  |  | bill.setPlanPayDate(planPayDate.getTime()>System.currentTimeMillis()?planPayDate:new Date()); | 
|---|
|  |  |  | bill.setTotleFee(type==Constants.THREE?model.getZlDeposit():model.getWyDeposit());//押金费用 | 
|---|
|  |  |  | bill.setPlanPayDate(bill.getStartDate()); | 
|---|
|  |  |  | bill.setTotleFee(type==Constants.TWO? | 
|---|
|  |  |  | Objects.isNull(model.getZlDeposit())?BigDecimal.ZERO:model.getZlDeposit() | 
|---|
|  |  |  | : | 
|---|
|  |  |  | Objects.isNull(model.getWyDeposit())?BigDecimal.ZERO:model.getWyDeposit());//押金费用 | 
|---|
|  |  |  | bill.setReceivableFee(bill.getTotleFee()); | 
|---|
|  |  |  | bill.setBillType(Constants.ZERO); | 
|---|
|  |  |  | bill.setPayStatus(Constants.ZERO); | 
|---|
|  |  |  | 
|---|
|  |  |  | int monthSix = months / 6;//6个月维度数量 | 
|---|
|  |  |  | int restMonth = months % 6;//剩余的整月 | 
|---|
|  |  |  | int monthDays =   dateCompare.getMonthDays();//不满一个月的天数 | 
|---|
|  |  |  | Date date = new Date(); | 
|---|
|  |  |  | List<Date> list = new ArrayList<>(); | 
|---|
|  |  |  | for (int i = 0; i < monthSix; i++) { | 
|---|
|  |  |  | list.add(DateUtil.addMonthToDate(date,i*6)); | 
|---|
|  |  |  | list.add(DateUtil.addMonthToDate(startDate,i*6)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(restMonth>0 || monthDays>0){ | 
|---|
|  |  |  | list.add(DateUtil.addDaysToDate(date,monthSix)); | 
|---|
|  |  |  | list.add(DateUtil.addMonthToDate(startDate,monthSix*6)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return list; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | int monthThree = months / 3;//3个月维度数量 | 
|---|
|  |  |  | int restMonth = months % 3;//剩余的整月 | 
|---|
|  |  |  | int monthDays =   dateCompare.getMonthDays();//不满一个月的天数 | 
|---|
|  |  |  | Date date = new Date(); | 
|---|
|  |  |  | List<Date> list = new ArrayList<>(); | 
|---|
|  |  |  | for (int i = 0; i < monthThree; i++) { | 
|---|
|  |  |  | list.add(DateUtil.addMonthToDate(date,i*3)); | 
|---|
|  |  |  | list.add(DateUtil.addMonthToDate(startDate,i*3)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(restMonth>0 || monthDays>0){ | 
|---|
|  |  |  | list.add(DateUtil.addDaysToDate(date,monthThree)); | 
|---|
|  |  |  | list.add(DateUtil.addMonthToDate(startDate,monthThree*3)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return list; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | if(temp+1 < dateList.size()){ | 
|---|
|  |  |  | end =DateUtil.addDaysToDate(dateList.get(temp+1),-1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | temp++; | 
|---|
|  |  |  | YwContractBill bill = initCreateBillModel(model,d ); | 
|---|
|  |  |  | bill.setStartDate(start);//账单开始 | 
|---|
|  |  |  | bill.setEndDate(end);//账单结束 | 
|---|
|  |  |  | Date planPayDate = DateUtil.addDaysToDate(d.getStartDate(),Constants.formatIntegerNum(d.getAdvanceDays()) * -1); | 
|---|
|  |  |  | Date planPayDate = DateUtil.addDaysToDate(bill.getStartDate(),Constants.formatIntegerNum(d.getAdvanceDays()) * -1); | 
|---|
|  |  |  | bill.setPlanPayDate(planPayDate.getTime()>System.currentTimeMillis()?planPayDate:new Date()); | 
|---|
|  |  |  | BigDecimal totalFee =getTotalFeeByStartEnd(model,d,freeStart,freeEnd); | 
|---|
|  |  |  | BigDecimal totalFee =getTotalFeeByStartEnd(model,d,bill,freeStart,freeEnd); | 
|---|
|  |  |  | bill.setTotleFee(totalFee); | 
|---|
|  |  |  | bill.setReceivableFee(totalFee); | 
|---|
|  |  |  | bill.setBillType(Constants.ZERO); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | temp++; | 
|---|
|  |  |  | bill.setCompanyId(model.getCompanyId()); | 
|---|
|  |  |  | list.add(bill); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private BigDecimal getTotalFeeByStartEnd(YwContract model, YwContractDetail d,Date freeStart,Date freeEnd) { | 
|---|
|  |  |  | private BigDecimal getTotalFeeByStartEnd(YwContract model, YwContractDetail d, YwContractBill bill,Date freeStart,Date freeEnd) { | 
|---|
|  |  |  | BigDecimal totalFee = new BigDecimal(0); | 
|---|
|  |  |  | DateCompare dateCompare =   DateCompare.dayCompare(d.getStartDate(),d.getEndDate(),freeStart,freeEnd); | 
|---|
|  |  |  | DateCompare dateCompare =   DateCompare.dayCompare(bill.getStartDate(),DateUtil.addDaysToDate(bill.getEndDate(),1),freeStart,DateUtil.addDaysToDate(freeEnd,1)); | 
|---|
|  |  |  | if(Constants.equalsInteger(d.getCircleType(),Constants.ZERO)){ | 
|---|
|  |  |  | //0=元每平米天 | 
|---|
|  |  |  | int days = dateCompare.getDay(); | 
|---|
|  |  |  | int days = dateCompare.getDay() ; | 
|---|
|  |  |  | BigDecimal areas = getAreasNumBYRooms(model.getRoomList()); | 
|---|
|  |  |  | totalFee = new BigDecimal(days).multiply(areas).multiply(Constants.formatBigdecimal(d.getPrice()));//总价格 | 
|---|
|  |  |  | }else  if(Constants.equalsInteger(d.getCircleType(),Constants.ONE)){ | 
|---|
|  |  |  | 
|---|
|  |  |  | totalFee = year.multiply(areas).multiply(Constants.formatBigdecimal(d.getPrice()));//总价格 | 
|---|
|  |  |  | }else  if(Constants.equalsInteger(d.getCircleType(),Constants.THREE)){ | 
|---|
|  |  |  | //3=元每天 | 
|---|
|  |  |  | int days = dateCompare.getDay(); | 
|---|
|  |  |  | int days = dateCompare.getDay() ; | 
|---|
|  |  |  | totalFee = new BigDecimal(days).multiply(Constants.formatBigdecimal(d.getPrice()));//总价格 | 
|---|
|  |  |  | }else  if(Constants.equalsInteger(d.getCircleType(),Constants.FOUR)){ | 
|---|
|  |  |  | //4=元每月 | 
|---|
|  |  |  | 
|---|
|  |  |  | DateCompare dateCompare =   DateCompare.monthYearCompare(startDate, endDate ); | 
|---|
|  |  |  | int years = dateCompare.getYear(); | 
|---|
|  |  |  | int yeardays = dateCompare.getYearDays(); | 
|---|
|  |  |  | Date date = new Date(); | 
|---|
|  |  |  | List<Date> list = new ArrayList<>(); | 
|---|
|  |  |  | for (int i = 0; i < years; i++) { | 
|---|
|  |  |  | list.add(DateUtil.addYearToDate(date,i)); | 
|---|
|  |  |  | list.add(DateUtil.addYearToDate(startDate,i)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(yeardays>0){ | 
|---|
|  |  |  | list.add(DateUtil.addYearToDate(date,years)); | 
|---|
|  |  |  | list.add(DateUtil.addYearToDate(startDate,years)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return list; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | YwContractBill bill = initCreateBillModel(model,d); | 
|---|
|  |  |  | bill.setStartDate(d.getStartDate());//账单开始 | 
|---|
|  |  |  | bill.setEndDate(d.getEndDate());//账单结束 | 
|---|
|  |  |  | bill.setPlanPayDate(DateUtil.addDaysToDate(d.getStartDate(),Constants.formatIntegerNum(d.getAdvanceDays()) * -1)); | 
|---|
|  |  |  | bill.setTotleFee(getTotalFeeByStartEnd(model,d,freeStart,freeEnd)); | 
|---|
|  |  |  | bill.setPlanPayDate(DateUtil.addDaysToDate(bill.getStartDate(),Constants.formatIntegerNum(d.getAdvanceDays()) * -1)); | 
|---|
|  |  |  | bill.setTotleFee(getTotalFeeByStartEnd(model,d,bill,freeStart,freeEnd)); | 
|---|
|  |  |  | bill.setReceivableFee(bill.getTotleFee()); | 
|---|
|  |  |  | bill.setBillType(Constants.ZERO); | 
|---|
|  |  |  | list.add(bill); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,合同有效期结束时间不得早于开始时间!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(Constants.equalsInteger(model.getType(),Constants.ZERO ) | 
|---|
|  |  |  | || Constants.equalsInteger(model.getType(),Constants.TWO)){ | 
|---|
|  |  |  | if(  model.getZlDeposit() == null | 
|---|
|  |  |  | 
|---|
|  |  |  | ||model.getZlDetailList().size() ==0){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请按页面要求填写租赁条款信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(!(model.getZlFreeEndDate()==null &&  model.getZlFreeStartDate()==null) && ( | 
|---|
|  |  |  | (model.getZlFreeEndDate()!=null &&  model.getZlFreeStartDate()==null) | 
|---|
|  |  |  | ||(model.getZlFreeEndDate()==null &&  model.getZlFreeStartDate()!=null) | 
|---|
|  |  |  | ||model.getZlFreeEndDate().getTime()<= model.getZlFreeStartDate().getTime()) | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请选择正确的租赁条款免租期信息!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if((model.getZlFreeStartDate()!=null && model.getZlFreeEndDate()!=null) | 
|---|
|  |  |  | && (model.getZlFreeEndDate().getTime()>model.getEndDate().getTime() | 
|---|
|  |  |  | || model.getZlFreeStartDate().getTime()<model.getStartDate().getTime())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,免租期开始日期和结束日期限制在合同时间范围内!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for(YwContractDetail d :model.getZlDetailList()){ | 
|---|
|  |  |  | if(  d.getStartDate() == null | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(d.getEndDate().getTime()<= d.getStartDate().getTime()){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,租赁条款有效期结束时间不得早于开始时间!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(d.getEndDate().getTime()>model.getEndDate().getTime() ||d.getStartDate().getTime()<model.getStartDate().getTime()){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,条款开始日期和结束日期限制在合同时间范围内!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!Constants.equalsInteger(model.getWyPayType(),Constants.ZERO) && | 
|---|
|  |  |  | Constants.equalsInteger(d.getCircleType(),Constants.SIX)){ | 
|---|
|  |  |  | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请按页面要求填写物业条款信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(!(model.getWyFreeEndDate()==null &&  model.getWyFreeStartDate()==null) && ( | 
|---|
|  |  |  | (model.getWyFreeEndDate()!=null &&  model.getWyFreeStartDate()==null) | 
|---|
|  |  |  | ||(model.getWyFreeEndDate()==null &&  model.getWyFreeStartDate()!=null) | 
|---|
|  |  |  | ||model.getWyFreeEndDate().getTime()<= model.getWyFreeStartDate().getTime())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请选择正确的物业条款免租期信息!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if((model.getWyFreeStartDate()!=null && model.getWyFreeEndDate()!=null) | 
|---|
|  |  |  | && (model.getWyFreeEndDate().getTime()>model.getEndDate().getTime() | 
|---|
|  |  |  | || model.getWyFreeStartDate().getTime()<model.getStartDate().getTime())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,免租期开始日期和结束日期限制在合同时间范围内!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for(YwContractDetail d :model.getWyDetailList()){ | 
|---|
|  |  |  | if(  d.getStartDate() == null | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(d.getEndDate().getTime()<= d.getStartDate().getTime()){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,物业条款有效期结束时间不得早于开始时间!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(d.getEndDate().getTime()>model.getEndDate().getTime() ||d.getStartDate().getTime()<model.getStartDate().getTime()){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,条款开始日期和结束日期限制在合同时间范围内!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!Constants.equalsInteger(model.getWyPayType(),Constants.ZERO) && | 
|---|
|  |  |  | Constants.equalsInteger(d.getCircleType(),Constants.SIX)){ | 
|---|
|  |  |  | 
|---|
|  |  |  | .selectAs(YwCustomer::getName,YwContract::getRenterName ) | 
|---|
|  |  |  | .selectAs(YwProject::getName,YwContract::getProjectName ) | 
|---|
|  |  |  | .select("t3.realname",YwContract::getCreatorName ) | 
|---|
|  |  |  | .select("(select sum(r.area) from yw_contract_room cr left join yw_room r on r.id = cr.room_id where r.isdeleted=0 and cr.contract_id =t.id)",YwContract::getTotalArea ) | 
|---|
|  |  |  | .leftJoin(Company.class,Company::getId,YwContract::getCompanyId) | 
|---|
|  |  |  | .leftJoin(SystemUser.class,SystemUser::getId,YwContract::getUserId) | 
|---|
|  |  |  | .leftJoin(SystemUser.class,SystemUser::getId,YwContract::getCreator) | 
|---|
|  |  |  | 
|---|
|  |  |  | }else  if(Constants.equalsInteger(bill.getPayStatus(),Constants.ONE) ){ | 
|---|
|  |  |  | if(bill.getEndDate().getTime()<nowStart){ | 
|---|
|  |  |  | //如果已结清,账单直接关闭 | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | model.getCanBackRentBills().add(bill); | 
|---|
|  |  |  | }else  if(Constants.equalsInteger(bill.getPayStatus(),Constants.TWO) ){ | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<YwContract> findList(YwContract ywContract) { | 
|---|
|  |  |  | QueryWrapper<YwContract> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | wrapper.lambda().eq(YwContract::getIsdeleted,Constants.ZERO); | 
|---|
|  |  |  | wrapper.lambda().in(YwContract::getStatus,Constants.ZERO,Constants.ONE,Constants.TWO); | 
|---|
|  |  |  | return ywContractMapper.selectList(wrapper); | 
|---|
|  |  |  | return ywContractMapper.selectJoinList(YwContract.class,new MPJLambdaWrapper<YwContract>().selectAll(YwContract.class ) | 
|---|
|  |  |  | .selectAs(Company::getName,YwContract::getCompanyName ) | 
|---|
|  |  |  | .selectAs(SystemUser::getRealname,YwContract::getUserName ) | 
|---|
|  |  |  | .selectAs(YwCustomer::getName,YwContract::getRenterName ) | 
|---|
|  |  |  | .selectAs(YwProject::getName,YwContract::getProjectName ) | 
|---|
|  |  |  | .leftJoin(Company.class,Company::getId,YwContract::getCompanyId) | 
|---|
|  |  |  | .leftJoin(SystemUser.class,SystemUser::getId,YwContract::getUserId) | 
|---|
|  |  |  | .leftJoin(SystemUser.class,SystemUser::getId,YwContract::getCreator) | 
|---|
|  |  |  | .leftJoin(YwProject.class,YwProject::getId,YwContract::getProjectId) | 
|---|
|  |  |  | .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId) | 
|---|
|  |  |  | .eq(YwContract::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .in(YwContract::getStatus,Constants.ZERO,Constants.ONE,Constants.TWO)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|