“mitao”
2026-04-02 0225ef3c66a2cc57dfc572b85848178bedd22fa3
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ClientServiceImpl.java
@@ -47,6 +47,7 @@
    private final ProjectCategoryCalculator projectCategoryCalculator;
    private final ClientParamMapper clientParamMapper;
    private final DeviceMapper deviceMapper;
    private final ErrorReviewMapper errorReviewMapper;
    @Override
    public ClientDashboardVO getClientDashboard(ClientDashboardQuery query) {
@@ -97,11 +98,29 @@
        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());
@@ -138,15 +157,6 @@
                        .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)
@@ -156,12 +166,8 @@
                        .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
                );
                // 市政检查覆盖率
@@ -173,12 +179,8 @@
                        .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);
@@ -268,9 +270,7 @@
            vo.setInspectedCount(0);
            vo.setInspectedHousingCount(0);
            vo.setInspectedMunicipalCount(0);
            vo.setUninspectedCount(projects.size());
            vo.setUninspectedHousingCount(vo.getHousingProjectCount());
            vo.setUninspectedMunicipalCount(vo.getMunicipalProjectCount());
            fillUninspectedProjectCounts(vo);
            return;
        }
@@ -286,9 +286,7 @@
            vo.setInspectedCount(0);
            vo.setInspectedHousingCount(0);
            vo.setInspectedMunicipalCount(0);
            vo.setUninspectedCount(projects.size());
            vo.setUninspectedHousingCount(vo.getHousingProjectCount());
            vo.setUninspectedMunicipalCount(vo.getMunicipalProjectCount());
            fillUninspectedProjectCounts(vo);
            return;
        }
@@ -326,16 +324,7 @@
        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);
    }
    /**
@@ -542,12 +531,25 @@
        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);
@@ -588,12 +590,25 @@
        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);
@@ -637,6 +652,7 @@
                // 解析 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();
@@ -647,7 +663,24 @@
                    // 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()));
@@ -687,6 +720,22 @@
        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);
    }
    /**
     * 判断给定的日期范围是否为当前月份
     *