| | |
| | | //处理 |
| | | 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); |
| | |
| | | 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()); |
| | |
| | | list.add(DateUtil.addMonthToDate(startDate,i*6)); |
| | | } |
| | | if(restMonth>0 || monthDays>0){ |
| | | list.add(DateUtil.addDaysToDate(startDate,monthSix)); |
| | | list.add(DateUtil.addMonthToDate(startDate,monthSix*6)); |
| | | } |
| | | return list; |
| | | } |
| | |
| | | list.add(DateUtil.addMonthToDate(startDate,i*3)); |
| | | } |
| | | if(restMonth>0 || monthDays>0){ |
| | | list.add(DateUtil.addDaysToDate(startDate,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(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=元每月 |
| | |
| | | bill.setStartDate(d.getStartDate());//账单开始 |
| | | bill.setEndDate(d.getEndDate());//账单结束 |
| | | bill.setPlanPayDate(DateUtil.addDaysToDate(bill.getStartDate(),Constants.formatIntegerNum(d.getAdvanceDays()) * -1)); |
| | | bill.setTotleFee(getTotalFeeByStartEnd(model,d,freeStart,freeEnd)); |
| | | bill.setTotleFee(getTotalFeeByStartEnd(model,d,bill,freeStart,freeEnd)); |
| | | bill.setReceivableFee(bill.getTotleFee()); |
| | | bill.setBillType(Constants.ZERO); |
| | | list.add(bill); |
| | |
| | | .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) |