From 245e62f87e29b22b1824d5361d073acaa06ceed9 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期四, 10 七月 2025 11:11:04 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/DataStatisticsController.java |  134 ++++++++++++++++++++++++++++++++++++++------
 1 files changed, 115 insertions(+), 19 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/DataStatisticsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/DataStatisticsController.java
index c19569c..2585930 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/DataStatisticsController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/DataStatisticsController.java
@@ -77,12 +77,21 @@
             if (deptType == 1) {
                 // 查询片区
                 TProjectDept projectDept = projectDeptService.getById(deptId);
-                // 查询项目部
-                TProjectDept parent = projectDeptService.getById(projectDept.getParentId());
-                List<TProjectDept> children = new ArrayList<>();
-                children.add(projectDept);
-                parent.setChildren(children);
-                projectDeptList.add(parent);
+                if("0".equals(projectDept.getParentId())){
+                    // 查询项目部
+                    List<TProjectDept> childProjectDept = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                            .eq(TProjectDept::getStatus,1)
+                            .eq(TProjectDept::getParentId,projectDept.getId()));
+                    projectDept.setChildren(childProjectDept);
+                    projectDeptList.add(projectDept);
+                }else {
+                    // 查询项目部
+                    TProjectDept parent = projectDeptService.getById(projectDept.getParentId());
+                    List<TProjectDept> children = new ArrayList<>();
+                    children.add(projectDept);
+                    parent.setChildren(children);
+                    projectDeptList.add(parent);
+                }
             }else {
                 projectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
                         .eq(TProjectDept::getStatus,1)
@@ -153,8 +162,17 @@
             if (deptType == 1) {
                 // 项目部人员
                 if(CollectionUtils.isEmpty(query.getProjectId())){
+                    TProjectDept projectDept = projectDeptService.getById(deptId);
                     List<String> projectIds = new ArrayList<>();
-                    projectIds.add(deptId);
+                    if("0".equals(projectDept.getParentId())){
+                        List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                                .eq(TProjectDept::getStatus, 1)
+                                .eq(TProjectDept::getParentId, projectDept.getId()));
+                        List<String> ids = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                        projectIds.addAll(ids);
+                    }else {
+                        projectIds.add(deptId);
+                    }
                     query.setProjectId(projectIds);
                 }
             }else {
@@ -177,6 +195,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -188,11 +207,12 @@
             if(!CollectionUtils.isEmpty(taskList)){
                 list.addAll(taskList);
             }
+            list = list.stream().distinct().collect(Collectors.toList());
 
             map.put("taskCount", list.size());
-            map.put("taskUnExecutedCount", list.stream().filter(task -> task.getStatus() == 1).count());
+            map.put("taskUnExecutedCount", list.stream().filter(task -> task.getStatus() == 1  || task.getStatus() == 2).count());
             map.put("taskPendingCount", list.stream().filter(task -> task.getStatus() == 3).count());
-            map.put("taskFinishCount", list.stream().filter(task -> task.getStatus() == 6).count());
+            map.put("taskFinishCount", list.stream().filter(task -> task.getStatus() == 5 || task.getStatus() == 6).count());
         }else {
             // 超级管理员
             // 查询点位类型
@@ -221,6 +241,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -232,11 +253,12 @@
             if(!CollectionUtils.isEmpty(taskList)){
                 list.addAll(taskList);
             }
+            list = list.stream().distinct().collect(Collectors.toList());
 
             map.put("taskCount", list.size());
-            map.put("taskUnExecutedCount", list.stream().filter(task -> task.getStatus() == 1).count());
+            map.put("taskUnExecutedCount", list.stream().filter(task -> task.getStatus() == 1 || task.getStatus() == 2).count());
             map.put("taskPendingCount", list.stream().filter(task -> task.getStatus() == 3).count());
-            map.put("taskFinishCount", list.stream().filter(task -> task.getStatus() == 6).count());
+            map.put("taskFinishCount", list.stream().filter(task -> task.getStatus() == 5 || task.getStatus() == 6).count());
         }
 
         return R.ok(map);
@@ -264,8 +286,17 @@
             if (deptType == 1) {
                 // 项目部人员
                 if(CollectionUtils.isEmpty(query.getProjectId())){
+                    TProjectDept projectDept = projectDeptService.getById(deptId);
                     List<String> projectIds = new ArrayList<>();
-                    projectIds.add(deptId);
+                    if("0".equals(projectDept.getParentId())){
+                        List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                                .eq(TProjectDept::getStatus, 1)
+                                .eq(TProjectDept::getParentId, projectDept.getId()));
+                        List<String> ids = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                        projectIds.addAll(ids);
+                    }else {
+                        projectIds.add(deptId);
+                    }
                     query.setProjectId(projectIds);
                 }
             }else {
@@ -292,6 +323,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 List<TLocation> locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class)
                         .in(TLocation::getProjectId, query.getProjectId()));
                 List<String> locationTypeList = locationList.stream().map(TLocation::getLocationType).distinct().collect(Collectors.toList());
@@ -379,8 +411,17 @@
             if (deptType == 1) {
                 // 项目部人员
                 if(CollectionUtils.isEmpty(query.getProjectId())){
+                    TProjectDept projectDept = projectDeptService.getById(deptId);
                     List<String> projectIds = new ArrayList<>();
-                    projectIds.add(deptId);
+                    if("0".equals(projectDept.getParentId())){
+                        List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                                .eq(TProjectDept::getStatus, 1)
+                                .eq(TProjectDept::getParentId, projectDept.getId()));
+                        List<String> ids = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                        projectIds.addAll(ids);
+                    }else {
+                        projectIds.add(deptId);
+                    }
                     query.setProjectId(projectIds);
                 }
             }else {
@@ -402,6 +443,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -413,6 +455,7 @@
             if(!CollectionUtils.isEmpty(taskList)){
                 list.addAll(taskList);
             }
+            list = list.stream().distinct().collect(Collectors.toList());
             map.put("timeoutWarn", list.stream().filter(task -> task.getStatus() == 2).count());
             List<TTask> tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2).collect(Collectors.toList());
             if(CollectionUtils.isEmpty(tasks)){
@@ -460,6 +503,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -471,6 +515,7 @@
             if(!CollectionUtils.isEmpty(taskList)){
                 list.addAll(taskList);
             }
+            list = list.stream().distinct().collect(Collectors.toList());
             map.put("timeoutWarn", list.stream().filter(task -> task.getStatus() == 2).count());
             List<TTask> tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2).collect(Collectors.toList());
             if(CollectionUtils.isEmpty(tasks)){
@@ -518,8 +563,17 @@
             if (deptType == 1) {
                 // 项目部人员
                 if(CollectionUtils.isEmpty(query.getProjectId())){
+                    TProjectDept projectDept = projectDeptService.getById(deptId);
                     List<String> projectIds = new ArrayList<>();
-                    projectIds.add(deptId);
+                    if("0".equals(projectDept.getParentId())){
+                        List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                                .eq(TProjectDept::getStatus, 1)
+                                .eq(TProjectDept::getParentId, projectDept.getId()));
+                        List<String> ids = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                        projectIds.addAll(ids);
+                    }else {
+                        projectIds.add(deptId);
+                    }
                     query.setProjectId(projectIds);
                 }
             }else {
@@ -541,6 +595,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -552,6 +607,7 @@
             if(!CollectionUtils.isEmpty(taskList)){
                 list.addAll(taskList);
             }
+            list = list.stream().distinct().collect(Collectors.toList());
 
             List<TTask> tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2).collect(Collectors.toList());
             if(CollectionUtils.isEmpty(tasks)){
@@ -561,6 +617,7 @@
             List<TTaskDetail> taskDetails = tTaskDetailService.list(Wrappers.lambdaQuery(TTaskDetail.class)
                     .in(TTaskDetail::getTaskId, taskIds)
                     .eq(TTaskDetail::getClearStatus, 2)
+                    .eq(TTaskDetail::getHandleType,1)
                     .orderByDesc(TTaskDetail::getCreateTime));
             List<TTaskDetail> taskDetailList = new ArrayList<>();
             for (TTask task : list) {
@@ -576,7 +633,7 @@
                     .eq(TDictData::getDataType, 2));
             List<AnalysisUnqualifiedCleaningDetailVO> analysisUnqualifiedCleaningDetailVOS = new ArrayList<>();
             for (TDictData tDictData : dictDataList) {
-                List<TTaskDetail> tTaskDetails = taskDetailList.stream().filter(taskDetail -> taskDetail.getUnqualified().equals(tDictData.getId())).collect(Collectors.toList());
+                List<TTaskDetail> tTaskDetails = taskDetailList.stream().filter(taskDetail -> StringUtils.isNotEmpty(taskDetail.getUnqualified())&&taskDetail.getUnqualified().equals(tDictData.getId())).collect(Collectors.toList());
                 AnalysisUnqualifiedCleaningDetailVO analysisUnqualifiedCleaningDetailVO = new AnalysisUnqualifiedCleaningDetailVO();
                 analysisUnqualifiedCleaningDetailVO.setUnqualifiedName(tDictData.getDataContent());
                 analysisUnqualifiedCleaningDetailVO.setCount(tTaskDetails.size());
@@ -610,6 +667,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -621,6 +679,7 @@
             if(!CollectionUtils.isEmpty(taskList)){
                 list.addAll(taskList);
             }
+            list = list.stream().distinct().collect(Collectors.toList());
 
             List<TTask> tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2).collect(Collectors.toList());
             if(CollectionUtils.isEmpty(tasks)){
@@ -629,6 +688,7 @@
             List<String> taskIds = tasks.stream().map(TTask::getId).collect(Collectors.toList());
             List<TTaskDetail> taskDetails = tTaskDetailService.list(Wrappers.lambdaQuery(TTaskDetail.class)
                     .in(TTaskDetail::getTaskId, taskIds)
+                    .eq(TTaskDetail::getHandleType,1)
                     .eq(TTaskDetail::getClearStatus, 2)
                     .orderByDesc(TTaskDetail::getCreateTime));
             List<TTaskDetail> taskDetailList = new ArrayList<>();
@@ -645,7 +705,7 @@
                     .eq(TDictData::getDataType, 2));
             List<AnalysisUnqualifiedCleaningDetailVO> analysisUnqualifiedCleaningDetailVOS = new ArrayList<>();
             for (TDictData tDictData : dictDataList) {
-                List<TTaskDetail> tTaskDetails = taskDetailList.stream().filter(taskDetail -> org.springframework.util.StringUtils.hasLength(taskDetail.getUnqualified())&& taskDetail.getUnqualified().equals(tDictData.getId())).collect(Collectors.toList());
+                List<TTaskDetail> tTaskDetails = taskDetailList.stream().filter(taskDetail -> StringUtils.isNotEmpty(taskDetail.getUnqualified())&& taskDetail.getUnqualified().equals(tDictData.getId())).collect(Collectors.toList());
                 AnalysisUnqualifiedCleaningDetailVO analysisUnqualifiedCleaningDetailVO = new AnalysisUnqualifiedCleaningDetailVO();
                 analysisUnqualifiedCleaningDetailVO.setUnqualifiedName(tDictData.getDataContent());
                 analysisUnqualifiedCleaningDetailVO.setCount(tTaskDetails.size());
@@ -707,8 +767,17 @@
             if (deptType == 1) {
                 // 项目部人员
                 if(CollectionUtils.isEmpty(query.getProjectId())){
+                    TProjectDept projectDept = projectDeptService.getById(deptId);
                     List<String> projectIds = new ArrayList<>();
-                    projectIds.add(deptId);
+                    if("0".equals(projectDept.getParentId())){
+                        List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                                .eq(TProjectDept::getStatus, 1)
+                                .eq(TProjectDept::getParentId, projectDept.getId()));
+                        List<String> ids = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                        projectIds.addAll(ids);
+                    }else {
+                        projectIds.add(deptId);
+                    }
                     query.setProjectId(projectIds);
                 }
             }else {
@@ -750,6 +819,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -761,6 +831,7 @@
             if(!CollectionUtils.isEmpty(taskList)){
                 list.addAll(taskList);
             }
+            list = list.stream().distinct().collect(Collectors.toList());
 
             List<TTask> tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2).collect(Collectors.toList());
             if(CollectionUtils.isEmpty(tasks)){
@@ -882,6 +953,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -893,6 +965,7 @@
             if(!CollectionUtils.isEmpty(taskList)){
                 list.addAll(taskList);
             }
+            list = list.stream().distinct().collect(Collectors.toList());
 
             List<TTask> tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2).collect(Collectors.toList());
             if(CollectionUtils.isEmpty(tasks)){
@@ -994,8 +1067,17 @@
             if (deptType == 1) {
                 // 项目部人员
                 if(CollectionUtils.isEmpty(query.getProjectId())){
+                    TProjectDept projectDept = projectDeptService.getById(deptId);
                     List<String> projectIds = new ArrayList<>();
-                    projectIds.add(deptId);
+                    if("0".equals(projectDept.getParentId())){
+                        List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                                .eq(TProjectDept::getStatus, 1)
+                                .eq(TProjectDept::getParentId, projectDept.getId()));
+                        List<String> ids = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                        projectIds.addAll(ids);
+                    }else {
+                        projectIds.add(deptId);
+                    }
                     query.setProjectId(projectIds);
                 }
             }else {
@@ -1017,6 +1099,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
                 // 查询点位数
                 List<TLocation> locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class)
@@ -1032,6 +1115,7 @@
             if(!CollectionUtils.isEmpty(taskList)){
                 list.addAll(taskList);
             }
+            list = list.stream().distinct().collect(Collectors.toList());
         }else {
             // 超级管理员
             // 查询点位类型
@@ -1060,6 +1144,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
                 List<TLocation> locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class)
                         .in(TLocation::getProjectId, query.getProjectId()));
@@ -1074,6 +1159,7 @@
             if(!CollectionUtils.isEmpty(taskList)){
                 list.addAll(taskList);
             }
+            list = list.stream().distinct().collect(Collectors.toList());
         }
 
         // 查询任务相关数据
@@ -1141,8 +1227,17 @@
             if (deptType == 1) {
                 // 项目部人员
                 if(CollectionUtils.isEmpty(query.getProjectId())){
+                    TProjectDept projectDept = projectDeptService.getById(deptId);
                     List<String> projectIds = new ArrayList<>();
-                    projectIds.add(deptId);
+                    if("0".equals(projectDept.getParentId())){
+                        List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                                .eq(TProjectDept::getStatus, 1)
+                                .eq(TProjectDept::getParentId, projectDept.getId()));
+                        List<String> ids = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                        projectIds.addAll(ids);
+                    }else {
+                        projectIds.add(deptId);
+                    }
                     query.setProjectId(projectIds);
                 }
             }else {
@@ -1174,6 +1269,7 @@
 
         // 查询片区
         if(!CollectionUtils.isEmpty(query.getProjectId())){
+            query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
             wrapper.in(TLocation::getProjectId, query.getProjectId());
         }
 

--
Gitblit v1.7.1