| | |
| | | List<TContract> tContracts = contractService.list(new LambdaQueryWrapper<TContract>() |
| | | .eq(!"0".equals(businessDeptId), TContract::getBusinessDeptId, businessDeptId) |
| | | .eq(TContract::getPayType, 2)); |
| | | List<String> houseIds = tContracts.stream().map(TContract::getHouseId).collect(Collectors.toList()); |
| | | List<String> houseIds1 = tContracts.stream().map(TContract::getHouseId).collect(Collectors.toList()); |
| | | |
| | | |
| | | // 获取所有房屋信息 |
| | | List<THouse> houses = houseService.list(new LambdaQueryWrapper<THouse>() |
| | | .and(wrapper -> wrapper.in(!houseIds.isEmpty(),THouse::getId, houseIds) |
| | | .or(!houseIds.isEmpty()) |
| | | .and(wrapper -> wrapper.in(!houseIds1.isEmpty(),THouse::getId, houseIds1) |
| | | .or(!houseIds1.isEmpty()) |
| | | .eq(THouse::getLeaseStatus, "1") |
| | | ) |
| | | .eq(!"0".equals(businessDeptId),THouse::getBusinessDeptId, businessDeptId) |
| | | ); |
| | | |
| | | // 1. 提前获取所有房屋对应的最新有效合同(按房屋ID分组) |
| | | Set<String> houseIds = houses.stream().map(THouse::getId).collect(Collectors.toSet()); |
| | | Map<String, TContract> contractMap = contractService.list(new LambdaQueryWrapper<TContract>() |
| | | .eq(!"0".equals(businessDeptId), TContract::getBusinessDeptId, businessDeptId) |
| | | .eq(TContract::getPayType, 2) |
| | | .gt(TContract::getEndTime, LocalDate.now()) |
| | | .in(TContract::getHouseId, houseIds) // 批量查询 |
| | | .eq(TContract::getStatus, 4) |
| | | .orderByDesc(TContract::getEndTime)) |
| | | .stream() |
| | | .collect(Collectors.toMap( |
| | | TContract::getHouseId, |
| | | c -> c, |
| | | (existing, replacement) -> existing // 保留最新合同 |
| | | )); |
| | | |
| | | // 2. 提前批量查询所有合同对应的账单(按contractId分组) |
| | | Set<String> contractIds = contractMap.values().stream() |
| | | .map(TContract::getId) |
| | | .collect(Collectors.toSet()); |
| | | Map<String, List<TBill>> billsMap = billService.list(new LambdaQueryWrapper<TBill>() |
| | | .eq(!"0".equals(businessDeptId), TBill::getBusinessDeptId, businessDeptId) |
| | | .in(!contractIds.isEmpty(), TBill::getContractId, contractIds) |
| | | .eq(TBill::getBillType, 1)) |
| | | .stream() |
| | | .collect(Collectors.groupingBy(TBill::getContractId)); |
| | | |
| | | |
| | | // 3. 季度时间计算提到循环外(所有房屋共用) |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | LocalDate now = LocalDate.now(); |
| | | int month = now.getMonthValue(); |
| | | int quarterStartMonth = ((month - 1) / 3) * 3 + 1; |
| | | LocalDate quarterStart = YearMonth.of(now.getYear(), quarterStartMonth).atDay(1); |
| | | LocalDate quarterEnd = YearMonth.of(now.getYear(), quarterStartMonth + 2).atEndOfMonth(); |
| | | |
| | | List<HouseMapDistributionVO> result = new ArrayList<>(); |
| | | for (THouse house : houses) { |
| | | HouseMapDistributionVO houseMapDistributionVO = new HouseMapDistributionVO(); |
| | |
| | | |
| | | |
| | | |
| | | TContract contract = contractService.getOne(new LambdaQueryWrapper<TContract>() |
| | | .eq(!"0".equals(businessDeptId),TContract::getBusinessDeptId, businessDeptId) |
| | | .eq(TContract::getPayType, 2) |
| | | .gt(TContract::getEndTime, LocalDate.now()) |
| | | .eq(TContract::getHouseId, house.getId()) |
| | | .eq(TContract::getStatus, 4) |
| | | .last("limit 1")); |
| | | TContract contract = contractMap.get(house.getId()); |
| | | |
| | | |
| | | if (contract != null){ |
| | | List<TBill> tBills = billService.list(new LambdaQueryWrapper<TBill>() |
| | | .eq(!"0".equals(businessDeptId),TBill::getBusinessDeptId, businessDeptId) |
| | | .eq(TBill::getContractId, contract.getId()) |
| | | .eq(TBill::getBillType, 1)); |
| | | |
| | | |
| | | List<TBill> tBills = billsMap.getOrDefault(contract.getId(), Collections.emptyList()); |
| | | |
| | | |
| | | houseMapDistributionVO.setTenant(contract.getPartyTwoName()); |
| | | |
| | | BigDecimal payFeesMoney = tBills.stream() |
| | |
| | | String rentStatus = String.format("%.2f/%.2f", payFeesMoney, payableFeesMoney); |
| | | houseMapDistributionVO.setRentStatus(rentStatus); |
| | | |
| | | |
| | | // TBill one = billService.getOne(new LambdaQueryWrapper<TBill>() |
| | | // .le(TBill::getStartTime, LocalDate.now()) |
| | | // .ge(TBill::getEndTime, LocalDate.now()) |
| | | // .eq(TBill::getBillType, 1) |
| | | // .eq(TBill::getContractId, contract.getId())); |
| | | |
| | | |
| | | // 获取当前季度的开始和结束时间 |
| | | // 获取当前季度的开始和结束时间的实现示例: |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | LocalDate now = LocalDate.now(); |
| | | int month = now.getMonthValue(); |
| | | int year = now.getYear(); |
| | | |
| | | // 计算季度起始月份(1,4,7,10) |
| | | int quarterStartMonth = ((month - 1) / 3) * 3 + 1; |
| | | int quarterEndMonth = quarterStartMonth + 2; |
| | | // 构建季度起止日期 |
| | | LocalDate quarterStart = YearMonth.of(year, quarterStartMonth).atDay(1); |
| | | LocalDate quarterEnd = YearMonth.of(year, quarterEndMonth).atEndOfMonth(); |
| | | |
| | | System.out.println("季度开始:" + quarterStart.format(formatter)); |
| | | System.out.println("季度结束:" + quarterEnd.format(formatter)); |
| | | |
| | | List<TBill> ones = billService.list(new LambdaQueryWrapper<TBill>() |
| | | .eq(!"0".equals(businessDeptId),TBill::getBusinessDeptId, businessDeptId) |
| | | .between(TBill::getStartTime, quarterStart, quarterEnd) |
| | | .eq(TBill::getBillType, 1) |
| | | .eq(TBill::getContractId, contract.getId())); |
| | | // 季度账单筛选 |
| | | List<TBill> ones = tBills.stream() |
| | | .filter(b -> { |
| | | LocalDate billDate = b.getStartTime().toLocalDate(); |
| | | return !billDate.isBefore(quarterStart) && !billDate.isAfter(quarterEnd); |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | if (!ones.isEmpty()){ |
| | | |
| | | long count = ones.stream().filter(tBill -> "4".equals(tBill.getPayFeesStatus())).count(); |
| | |
| | | } |
| | | return R.ok(result); |
| | | } |
| | | |
| | | |
| | | } |