陈昶聿
4 天以前 04d04154d9041535342736bd1c924ade5d818614
ruoyi-task/src/main/java/com/ruoyi/task/service/impl/ServiceSubtaskServiceImpl.java
@@ -2459,7 +2459,10 @@
            if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
                groupKey = drcode;
            } else {
                groupKey = "deptcode";
                // 2026-11 字段重命名后:deptcode 是在院科室(历史数据为空),
                // 出院科室已改名为 leaveldeptcode,分组必须用后者,
                // 否则 getSfStatisticsGroupKey 会返回 NULL,拼成 IN (NULL) 导致整表查空。
                groupKey = "leaveldeptcode";
            }
        } else if (serviceSubtaskCountReq.getStatisticaltype() != null && serviceSubtaskCountReq.getStatisticaltype() == 3) {
            // 病种统计:按任务ID分组,每个任务即一个病种随访任务
@@ -2470,6 +2473,17 @@
        Map<String, List<ServiceSubtask>> collect = new HashMap<>();
        serviceSubtaskCountReq.setGroupKey(groupKey);
        List<String> groupKeyList = serviceSubtaskMapper.getSfStatisticsGroupKey(serviceSubtaskCountReq);
        /*
         * 分组键可能为 NULL(历史数据、或重命名后尚未回填的在院维度列),
         * 直接拼进 SQL 会变成 `AND IFNULL(列,'Unknown') IN (NULL)`,恒不成立,整张统计表为空。
         * 这里统一成 'Unknown',与聚合 SQL 的 IFNULL(列,'Unknown') 口径对齐。
         */
        if (groupKeyList != null) {
            groupKeyList = groupKeyList.stream()
                    .map(key -> key == null ? "Unknown" : key)
                    .distinct()
                    .collect(Collectors.toList());
        }
        serviceSubtaskCountReq.setGroupKeyList(groupKeyList);
        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
        switch (groupKey) {
@@ -2484,6 +2498,7 @@
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getManagementDoctorCode()).orElse("Unknown")));
                break;
            case "deptcode":
            case "leaveldeptcode":
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeaveldeptcode()).orElse("Unknown")));
                break;
            case "leavehospitaldistrictcode":