| | |
| | | BigDecimal fee = Constants.formatBigdecimal(model.getBtFee()); |
| | | String str = "退租摘要:剩余未结清账单{param1}份,关闭账单{param2}份【退租日{param3},退租费用合计需{param4}{param5}元。】"; |
| | | str = str.replace("{param1}",model.getBtWaitBill()+"") |
| | | .replace("{param2}",DateUtil.getDateLongSlash(model.getBtDate())) |
| | | .replace("{param3}",fee.compareTo(new BigDecimal(0)) >=0?"收":"付") |
| | | .replace("{param4}",(fee.compareTo(new BigDecimal(0)) >=0? |
| | | .replace("{param2}",model.getBtCLoseBill()+"") |
| | | .replace("{param3}",DateUtil.getDateLongSlash(model.getBtDate())) |
| | | .replace("{param4}",fee.compareTo(new BigDecimal(0)) >=0?"收":"付") |
| | | .replace("{param5}",(fee.compareTo(new BigDecimal(0)) >=0? |
| | | Constants.formatBigdecimal(model.getBtFee()).intValue() |
| | | :(Constants.formatBigdecimal(model.getBtFee()).intValue() * -1))+"" ); |
| | | return str; |
| | |
| | | } |
| | | @Override |
| | | public YwContract findById(Integer id) { |
| | | |
| | | YwContract model =queryDetailInfoById(id); |
| | | //查询操作日志记录 |
| | | YwWorkorderLog log = new YwWorkorderLog(); |
| | | log.setJobId(model.getId()); |
| | | log.setIsdeleted(Constants.ZERO); |
| | | model.setLogList(ywWorkorderLogMapper.selectList(new QueryWrapper<YwWorkorderLog>(log) |
| | | .lambda() |
| | | .in(YwWorkorderLog::getObjType,Constants.YwLogType.CONTRACT_BACK.getKey() |
| | | ,Constants.YwLogType.CONTRACT_CREATE.getKey() |
| | | ,Constants.YwLogType.CONTRACT_UPDATE.getKey()) |
| | | .orderByAsc(YwWorkorderLog::getCreateDate))); |
| | | |
| | | //查询账单集合 |
| | | queryBillListByModel(model,new Date()); |
| | | return model; |
| | | } |
| | | private YwContract queryDetailInfoById(Integer id) { |
| | | MPJLambdaWrapper<YwContract> queryWrapper = new MPJLambdaWrapper<>(); |
| | | queryWrapper.selectAll(YwContract.class ) |
| | | .selectAs(Company::getName,YwContract::getCompanyName ) |
| | | .selectAs(SystemUser::getRealname,YwContract::getUserName ) |
| | | .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) |
| | | .leftJoin(YwProject.class,YwProject::getId,YwContract::getProjectId) |
| | | .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId) |
| | | .eq( YwContract::getId,id); |
| | | YwContract model = ywContractMapper.selectJoinOne(YwContract.class,queryWrapper); |
| | | if(model != null){ |
| | | queryWrapper.selectAll(YwContract.class) |
| | | .selectAs(Company::getName, YwContract::getCompanyName) |
| | | .selectAs(SystemUser::getRealname, YwContract::getUserName) |
| | | .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) |
| | | .leftJoin(YwProject.class, YwProject::getId, YwContract::getProjectId) |
| | | .leftJoin(YwCustomer.class, YwCustomer::getId, YwContract::getRenterId) |
| | | .eq(YwContract::getId, id); |
| | | YwContract model = ywContractMapper.selectJoinOne(YwContract.class, queryWrapper); |
| | | if (model == null) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | //合同附件 |
| | | initFiles(model); |
| | | //查询房源信息数据 |
| | | MPJLambdaWrapper<YwRoom> rw = new MPJLambdaWrapper<>(); |
| | | rw.selectAll(YwRoom.class ) |
| | | .selectAs(YwProject::getName,YwRoom::getProjectName) |
| | | .selectAs(YwFloor::getName,YwRoom::getFloorName) |
| | | .selectAs(YwBuilding::getName,YwRoom::getBuildingName) |
| | | .leftJoin(YwProject.class,YwProject::getId,YwRoom::getProjectId) |
| | | .leftJoin(YwBuilding.class,YwBuilding::getId,YwRoom::getBuildingId) |
| | | .leftJoin(YwFloor.class,YwFloor::getId,YwRoom::getFloor) |
| | | .eq(YwRoom::getIsdeleted,Constants.ZERO) |
| | | .exists("(select a.id from yw_contract_room a where a.isdeleted=0 and a.type=0 and a.room_id=t.id and a.contract_id="+model.getId()+")"); |
| | | model.setRoomList(roomMapper.selectJoinList(YwRoom.class,rw)); |
| | | rw.selectAll(YwRoom.class) |
| | | .selectAs(YwProject::getName, YwRoom::getProjectName) |
| | | .selectAs(YwFloor::getName, YwRoom::getFloorName) |
| | | .selectAs(YwBuilding::getName, YwRoom::getBuildingName) |
| | | .leftJoin(YwProject.class, YwProject::getId, YwRoom::getProjectId) |
| | | .leftJoin(YwBuilding.class, YwBuilding::getId, YwRoom::getBuildingId) |
| | | .leftJoin(YwFloor.class, YwFloor::getId, YwRoom::getFloor) |
| | | .eq(YwRoom::getIsdeleted, Constants.ZERO) |
| | | .exists("(select a.id from yw_contract_room a where a.isdeleted=0 and a.type=0 and a.room_id=t.id and a.contract_id=" + model.getId() + ")"); |
| | | model.setRoomList(roomMapper.selectJoinList(YwRoom.class, rw)); |
| | | model.setWyFirstCircleStr(Constants.getUnitTypeByNum(model.getWyFirstCircle())); |
| | | model.setZlFirstCircleStr(Constants.getUnitTypeByNum(model.getZlFirstCircle())); |
| | | //查询租賃条款信息 |
| | | MPJLambdaWrapper<YwContractDetail> dw = new MPJLambdaWrapper<>(); |
| | | dw.selectAll(YwContractDetail.class ) |
| | | .eq(YwContractDetail::getIsdeleted,Constants.ZERO) |
| | | .eq(YwContractDetail::getContractId,model.getId()) |
| | | .in(YwContractDetail::getType,Constants.ZERO,Constants.TWO) |
| | | dw.selectAll(YwContractDetail.class) |
| | | .eq(YwContractDetail::getIsdeleted, Constants.ZERO) |
| | | .eq(YwContractDetail::getContractId, model.getId()) |
| | | .in(YwContractDetail::getType, Constants.ZERO, Constants.TWO) |
| | | .orderByAsc(YwContractDetail::getSortnum); |
| | | model.setZlDetailList(ywContractDetailMapper.selectJoinList(YwContractDetail.class,dw)); |
| | | model.setZlDetailList(ywContractDetailMapper.selectJoinList(YwContractDetail.class, dw)); |
| | | //查询物業条款信息 |
| | | dw = new MPJLambdaWrapper<>(); |
| | | dw.selectAll(YwContractDetail.class ) |
| | | .eq(YwContractDetail::getIsdeleted,Constants.ZERO) |
| | | .eq(YwContractDetail::getContractId,model.getId()) |
| | | .in(YwContractDetail::getType,Constants.ONE,Constants.THREE) |
| | | dw.selectAll(YwContractDetail.class) |
| | | .eq(YwContractDetail::getIsdeleted, Constants.ZERO) |
| | | .eq(YwContractDetail::getContractId, model.getId()) |
| | | .in(YwContractDetail::getType, Constants.ONE, Constants.THREE) |
| | | .orderByAsc(YwContractDetail::getSortnum); |
| | | model.setWyDetailList(ywContractDetailMapper.selectJoinList(YwContractDetail.class,dw)); |
| | | model.setWyDetailList(ywContractDetailMapper.selectJoinList(YwContractDetail.class, dw)); |
| | | |
| | | //查询操作日志记录 |
| | | YwWorkorderLog log = new YwWorkorderLog(); |
| | | log.setJobId(model.getId()); |
| | | log.setIsdeleted(Constants.ZERO); |
| | | model.setLogList(ywWorkorderLogMapper.selectList(new QueryWrapper<YwWorkorderLog>(log) |
| | | .lambda() |
| | | .in(YwWorkorderLog::getObjType,Constants.YwLogType.CONTRACT_BACK.getKey() |
| | | ,Constants.YwLogType.CONTRACT_CREATE.getKey() |
| | | ,Constants.YwLogType.CONTRACT_UPDATE.getKey()) |
| | | .orderByAsc(YwWorkorderLog::getCreateDate))); |
| | | |
| | | //查询账单集合 |
| | | |
| | | queryBillListByModel(model,new Date()); |
| | | } |
| | | return model; |
| | | } |
| | | @Override |
| | | public YwContract findForBills(YwContract model) { |
| | | queryBillListByModel(model,model.getBtDate()); |
| | | |
| | | @Override |
| | | public YwContract findForBills(YwContract param) { |
| | | YwContract model = queryDetailInfoById(param.getId()); |
| | | queryBillListByModel(model,param.getBtDate()); |
| | | return model; |
| | | |
| | | } |
| | | private void queryBillListByModel(YwContract model,Date date) { |
| | | if(date ==null){ |
| | | date = new Date(); |
| | | } |
| | | //查询账单集合 |
| | | model.setBillList(ywContractBillMapper.selectJoinList(YwContractBill.class,new MPJLambdaWrapper<YwContractBill>() |
| | | .selectAll(YwContractBill.class ) |
| | |
| | | .eq( YwContractBill::getContractId,model.getId()) |
| | | .eq(YwContractBill::getIsdeleted,Constants.ZERO) |
| | | .orderByAsc(YwContractBill::getSortnum,YwContractBill::getCreateDate))); |
| | | |
| | | for (YwContractBill ywContractBill:model.getBillList()) { |
| | | ywContractBill.setNeedReceivableFee(ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee())); |
| | | ywContractBill.setNeedReceivableFee(ywContractBill.getReceivableFee()); |
| | | // ywContractBill.setNeedReceivableFee(ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee())); |
| | | } |
| | | model.setCanBackRentBills(new ArrayList<>()); |
| | | long nowStart = Utils.Date.getStart(date).getTime(); |
| | |
| | | continue; |
| | | } |
| | | model.getCanBackRentBills().add(bill); |
| | | |
| | | }else if(Constants.equalsInteger(bill.getPayStatus(),Constants.ONE) ){ |
| | | if(bill.getEndDate().getTime()<nowStart){ |
| | | //如果已结清,账单直接关闭 |
| | |
| | | model.getCanBackRentBills().add(bill); |
| | | } |
| | | } |
| | | for(YwContractBill bill : model.getCanBackRentBills()){ |
| | | YwContractDetail detail = null; |
| | | if(Constants.equalsInteger(bill.getCostType(),Constants.ZERO)){ |
| | | detail = getDetailByIdFromList(bill.getDetailId(),model.getZlDetailList()); |
| | | if(detail!=null&& bill.getStartDate()!=null && bill.getEndDate()!=null |
| | | &&(date.getTime() <= bill.getStartDate().getTime() || (date.getTime() >= bill.getStartDate().getTime() && date.getTime()<= bill.getEndDate().getTime()))){ |
| | | Date odate = bill.getEndDate(); |
| | | bill.setEndDate(date); |
| | | BigDecimal actFee = getTotalFeeByStartEnd(model,detail,bill,model.getZlFreeStartDate(),model.getZlFreeEndDate()); |
| | | bill.setEndDate(odate); |
| | | bill.setNeedReceivableFee(actFee); |
| | | } |
| | | }else if(Constants.equalsInteger(bill.getCostType(),Constants.ONE)){ |
| | | detail = getDetailByIdFromList(bill.getDetailId(),model.getWyDetailList()); |
| | | if(detail!=null&& bill.getStartDate()!=null && bill.getEndDate()!=null |
| | | &&(date.getTime() <= bill.getStartDate().getTime() || (date.getTime() >= bill.getStartDate().getTime() && date.getTime()<= bill.getEndDate().getTime()))){ |
| | | Date odate = bill.getEndDate(); |
| | | bill.setEndDate(date); |
| | | BigDecimal actFee = getTotalFeeByStartEnd(model,detail,bill,model.getWyFreeStartDate(),model.getWyFreeEndDate()); |
| | | bill.setEndDate(odate); |
| | | bill.setNeedReceivableFee(actFee); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private YwContractDetail getDetailByIdFromList(Integer detailId, List<YwContractDetail> list) { |
| | | if(list!=null){ |
| | | for(YwContractDetail d : list){ |
| | | if(Constants.equalsInteger(detailId,d.getId())){ |
| | | return d; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public YwContract findOne(YwContract ywContract) { |
| | | QueryWrapper<YwContract> wrapper = new QueryWrapper<>(ywContract); |