| | |
| | | private final ProjectCategoryCalculator projectCategoryCalculator; |
| | | private final ClientParamMapper clientParamMapper; |
| | | private final DeviceMapper deviceMapper; |
| | | private final ErrorReviewMapper errorReviewMapper; |
| | | |
| | | @Override |
| | | public ClientDashboardVO getClientDashboard(ClientDashboardQuery query) { |
| | |
| | | .ne(Project::getType, 2) // 在建工程 |
| | | .and(wrapper -> wrapper |
| | | .eq(Project::getStatus, 1) // 在建项目 |
| | | .between(Project::getCreateTime, monthStart, monthEnd) |
| | | .or(w -> w |
| | | .eq(Project::getStatus, 2) // 已完成项目 |
| | | .between(Project::getSuccessTime, monthStart,monthEnd) // 完成时间 >= 开始日期// 完成时间 <= 结束日期 |
| | |
| | | List<Project> projects = projectMapper.selectList(projectWrapper); |
| | | |
| | | // 1. 统计项目总数及分类 |
| | | vo.setProjectTotal(projects.size()); |
| | | long housingCount = projects.stream().filter(p -> p.getType() != null && p.getType() == 0).count(); |
| | | long municipalCount = projects.stream().filter(p -> p.getType() != null && p.getType() == 1).count(); |
| | | vo.setHousingProjectCount((int) housingCount); |
| | | vo.setMunicipalProjectCount((int) municipalCount); |
| | | |
| | | ClientParam clientParam = null; |
| | | if (clientId != null) { |
| | | clientParam = clientParamMapper.selectOne( |
| | | new LambdaQueryWrapper<ClientParam>() |
| | | .eq(ClientParam::getClientId, clientId.intValue()) |
| | | ); |
| | | } |
| | | |
| | | int effectiveHousingCount = resolveDisplayProjectCount( |
| | | clientParam != null ? clientParam.getHousingProjectNum() : null, |
| | | housingCount |
| | | ); |
| | | int effectiveMunicipalCount = resolveDisplayProjectCount( |
| | | clientParam != null ? clientParam.getMunicipalProjectNum() : null, |
| | | municipalCount |
| | | ); |
| | | |
| | | vo.setProjectTotal(effectiveHousingCount + effectiveMunicipalCount); |
| | | vo.setHousingProjectCount(effectiveHousingCount); |
| | | vo.setMunicipalProjectCount(effectiveMunicipalCount); |
| | | |
| | | // 计算检查覆盖率(仅当查询时间范围为当月时才计算) |
| | | List<Integer> projectIds = projects.stream().map(Project::getId).collect(Collectors.toList()); |
| | |
| | | .distinct() |
| | | .toList(); |
| | | |
| | | // 查询配置的项目总数 |
| | | ClientParam clientParam = null; |
| | | if (clientId != null) { |
| | | clientParam = clientParamMapper.selectOne( |
| | | new LambdaQueryWrapper<ClientParam>() |
| | | .eq(ClientParam::getClientId, clientId.intValue()) |
| | | ); |
| | | } |
| | | |
| | | // 房建检查覆盖率 |
| | | List<Integer> housingProjectIds = projects.stream() |
| | | .filter(p -> p.getType() != null && p.getType() == 0) |
| | |
| | | .filter(housingProjectIds::contains) |
| | | .count(); |
| | | |
| | | // 使用配置的房建项目总数,如果没有配置则使用实际数量 |
| | | int configuredHousingNum = (clientParam != null && clientParam.getHousingProjectNum() != null) |
| | | ? clientParam.getHousingProjectNum() |
| | | : (int) housingCount; |
| | | vo.setHousingInspectionCoverage( |
| | | configuredHousingNum > 0 ? (int) Math.round(checkedHousingCount * 100.0 / configuredHousingNum) : 0 |
| | | effectiveHousingCount > 0 ? (int) Math.round(checkedHousingCount * 100.0 / effectiveHousingCount) : 0 |
| | | ); |
| | | |
| | | // 市政检查覆盖率 |
| | |
| | | .filter(municipalProjectIds::contains) |
| | | .count(); |
| | | |
| | | // 使用配置的市政项目总数,如果没有配置则使用实际数量 |
| | | int configuredMunicipalNum = (clientParam != null && clientParam.getMunicipalProjectNum() != null) |
| | | ? clientParam.getMunicipalProjectNum() |
| | | : (int) municipalCount; |
| | | vo.setMunicipalInspectionCoverage( |
| | | configuredMunicipalNum > 0 ? (int) Math.round(checkedMunicipalCount * 100.0 / configuredMunicipalNum) : 0 |
| | | effectiveMunicipalCount > 0 ? (int) Math.round(checkedMunicipalCount * 100.0 / effectiveMunicipalCount) : 0 |
| | | ); |
| | | } else { |
| | | vo.setHousingInspectionCoverage(0); |
| | |
| | | .eq(Project::getType, 2) // 在建工程 |
| | | .and(wrapper -> wrapper |
| | | .eq(Project::getStatus, 1) // 在建项目 |
| | | .between(Project::getCreateTime, monthStart, monthEnd) |
| | | .or(w -> w |
| | | .eq(Project::getStatus, 2) // 已完成项目 |
| | | .between(Project::getSuccessTime, monthStart,monthEnd) // 完成时间 >= 开始日期// 完成时间 <= 结束日期 |
| | |
| | | vo.setInspectedCount(0); |
| | | vo.setInspectedHousingCount(0); |
| | | vo.setInspectedMunicipalCount(0); |
| | | vo.setUninspectedCount(projects.size()); |
| | | vo.setUninspectedHousingCount(vo.getHousingProjectCount()); |
| | | vo.setUninspectedMunicipalCount(vo.getMunicipalProjectCount()); |
| | | fillUninspectedProjectCounts(vo); |
| | | return; |
| | | } |
| | | |
| | |
| | | vo.setInspectedCount(0); |
| | | vo.setInspectedHousingCount(0); |
| | | vo.setInspectedMunicipalCount(0); |
| | | vo.setUninspectedCount(projects.size()); |
| | | vo.setUninspectedHousingCount(vo.getHousingProjectCount()); |
| | | vo.setUninspectedMunicipalCount(vo.getMunicipalProjectCount()); |
| | | fillUninspectedProjectCounts(vo); |
| | | return; |
| | | } |
| | | |
| | |
| | | vo.setInspectedMunicipalCount((int) inspectedProjects.stream() |
| | | .filter(p -> p.getType() != null && p.getType() == 1).count()); |
| | | |
| | | // 未检查项目统计 |
| | | List<Project> uninspectedProjects = projects.stream() |
| | | .filter(p -> !inspectedProjectIds.contains(p.getId())) |
| | | .toList(); |
| | | |
| | | vo.setUninspectedCount(uninspectedProjects.size()); |
| | | vo.setUninspectedHousingCount((int) uninspectedProjects.stream() |
| | | .filter(p -> p.getType() != null && p.getType() == 0).count()); |
| | | vo.setUninspectedMunicipalCount((int) uninspectedProjects.stream() |
| | | .filter(p -> p.getType() != null && p.getType() == 1).count()); |
| | | fillUninspectedProjectCounts(vo); |
| | | } |
| | | |
| | | /** |
| | |
| | | vo.setMajorHazardTotal(majorHazards.size()); |
| | | |
| | | // 统计已整改和未整改数量 |
| | | long rectifiedCount = majorHazards.stream() |
| | | .filter(r -> r.getReformed() != null && r.getReformed()) |
| | | .count(); |
| | | long unrectifiedCount = majorHazards.stream() |
| | | .filter(r -> r.getReformed() == null || !r.getReformed()) |
| | | .count(); |
| | | // 1. 收集所有非空的 errorReviewId |
| | | List<Integer> errorReviewIds = majorHazards.stream() |
| | | .map(Record::getErrorReviewId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 2. 查询 ErrorReview 中 state=2 的记录 |
| | | long rectifiedCount = 0; |
| | | if (!errorReviewIds.isEmpty()) { |
| | | LambdaQueryWrapper<ErrorReview> reviewWrapper = new LambdaQueryWrapper<>(); |
| | | reviewWrapper.in(ErrorReview::getId, errorReviewIds) |
| | | .eq(ErrorReview::getState, 2) // state=2 表示已整改 |
| | | .eq(ErrorReview::getDeleted, false); |
| | | rectifiedCount = errorReviewMapper.selectCount(reviewWrapper); |
| | | } |
| | | |
| | | // 3. 未整改数量 = 总数 - 已整改数量 |
| | | long unrectifiedCount = majorHazards.size() - rectifiedCount; |
| | | |
| | | vo.setRectifiedHazardCount((int) rectifiedCount); |
| | | vo.setUnrectifiedHazardCount((int) unrectifiedCount); |
| | |
| | | vo.setMajorHazardTotal(majorHazards.size()); |
| | | |
| | | // 统计已整改和未整改数量 |
| | | long rectifiedCount = majorHazards.stream() |
| | | .filter(r -> r.getReformed() != null && r.getReformed()) |
| | | .count(); |
| | | long unrectifiedCount = majorHazards.stream() |
| | | .filter(r -> r.getReformed() == null || !r.getReformed()) |
| | | .count(); |
| | | // 1. 收集所有非空的 errorReviewId |
| | | List<Integer> errorReviewIds = majorHazards.stream() |
| | | .map(Record::getErrorReviewId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 2. 查询 ErrorReview 中 state=2 的记录 |
| | | long rectifiedCount = 0; |
| | | if (!errorReviewIds.isEmpty()) { |
| | | LambdaQueryWrapper<ErrorReview> reviewWrapper = new LambdaQueryWrapper<>(); |
| | | reviewWrapper.in(ErrorReview::getId, errorReviewIds) |
| | | .eq(ErrorReview::getState, 2) // state=2 表示已整改 |
| | | .eq(ErrorReview::getDeleted, false); |
| | | rectifiedCount = errorReviewMapper.selectCount(reviewWrapper); |
| | | } |
| | | |
| | | // 3. 未整改数量 = 总数 - 已整改数量 |
| | | long unrectifiedCount = majorHazards.size() - rectifiedCount; |
| | | |
| | | vo.setRectifiedHazardCount((int) rectifiedCount); |
| | | vo.setUnrectifiedHazardCount((int) unrectifiedCount); |
| | |
| | | // 解析 address_info JSON 字符串 |
| | | JSONObject addressJson = JSON.parseObject(p.getAddressInfo()); |
| | | JSONArray gps = addressJson.getJSONArray("gps"); |
| | | String lonLat = addressJson.getString("lonLat"); |
| | | |
| | | if (gps != null && gps.size() >= 2) { |
| | | ProjectMapPointVO vo = new ProjectMapPointVO(); |
| | |
| | | // gps 数组格式:[经度, 纬度] |
| | | vo.setLongitude(gps.getString(0)); |
| | | vo.setLatitude(gps.getString(1)); |
| | | //位置信息 |
| | | vo.setAddressInfo(addressJson); |
| | | // 设置项目类别 |
| | | vo.setCategory(categoryMap.get(p.getId())); |
| | | |
| | | result.add(vo); |
| | | }else if(org.apache.commons.lang3.StringUtils.isNotBlank(lonLat)){ |
| | | String[] split = lonLat.split(","); |
| | | ProjectMapPointVO vo = new ProjectMapPointVO(); |
| | | vo.setProjectId(p.getId()); |
| | | vo.setProjectName(p.getName()); |
| | | vo.setProjectType(p.getType()); |
| | | |
| | | // gps 数组格式:[经度, 纬度] |
| | | vo.setLongitude(split[0]); |
| | | vo.setLatitude(split[1]); |
| | | //位置信息 |
| | | vo.setAddressInfo(addressJson); |
| | | // 设置项目类别 |
| | | vo.setCategory(categoryMap.get(p.getId())); |
| | | |
| | |
| | | return DateUtil.endOfMonth(date); |
| | | } |
| | | |
| | | private int resolveDisplayProjectCount(Integer configuredCount, long actualCount) { |
| | | int actualProjectCount = (int) actualCount; |
| | | if (configuredCount == null) { |
| | | return actualProjectCount; |
| | | } |
| | | return Math.max(configuredCount, actualProjectCount); |
| | | } |
| | | |
| | | private void fillUninspectedProjectCounts(OngoingProjectDashboardVO vo) { |
| | | int uninspectedHousingCount = Math.max(vo.getHousingProjectCount() - vo.getInspectedHousingCount(), 0); |
| | | int uninspectedMunicipalCount = Math.max(vo.getMunicipalProjectCount() - vo.getInspectedMunicipalCount(), 0); |
| | | vo.setUninspectedHousingCount(uninspectedHousingCount); |
| | | vo.setUninspectedMunicipalCount(uninspectedMunicipalCount); |
| | | vo.setUninspectedCount(uninspectedHousingCount + uninspectedMunicipalCount); |
| | | } |
| | | |
| | | /** |
| | | * 判断给定的日期范围是否为当前月份 |
| | | * |