From ca7e5eec896bb022ccb7e177ca3641e79f5f8554 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期四, 03 七月 2025 23:55:17 +0800
Subject: [PATCH] bug修改

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/DataStatisticsController.java |  450 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 428 insertions(+), 22 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 81a2230..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
@@ -3,6 +3,7 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.ruoyi.common.basic.PageInfo;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.utils.DateUtils;
@@ -12,17 +13,19 @@
 import com.ruoyi.system.query.DataStatisticsQuery;
 import com.ruoyi.system.query.DataStatisticsRankQuery;
 import com.ruoyi.system.query.InsepectorListQuery;
+import com.ruoyi.system.query.PointDetailQuery;
 import com.ruoyi.system.service.*;
-import com.ruoyi.system.vo.system.AnalysisUnqualifiedCleaningDetailVO;
-import com.ruoyi.system.vo.system.AnalysisUnqualifiedCleaningVO;
-import com.ruoyi.system.vo.system.DataStatisticsRankVO;
+import com.ruoyi.system.vo.system.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.BeanUtils;
 import org.springframework.util.CollectionUtils;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.util.*;
@@ -74,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)
@@ -150,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 {
@@ -174,6 +195,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -185,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 {
             // 超级管理员
             // 查询点位类型
@@ -218,6 +241,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -229,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);
@@ -261,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 {
@@ -289,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());
@@ -334,6 +369,9 @@
                 // 查询片区
                 List<TLocation> locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class)
                         .in(TLocation::getProjectId, query.getProjectId()));
+                if (locationList.isEmpty()){
+                    return R.ok(map);
+                }
                 List<String> locationTypeList = locationList.stream().map(TLocation::getLocationType).distinct().collect(Collectors.toList());
                 List<TLocationType> locationTypes = locationTypeService.list(Wrappers.lambdaQuery(TLocationType.class)
                         .in(TLocationType::getId, locationTypeList));
@@ -373,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 {
@@ -396,6 +443,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -407,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)){
@@ -454,6 +503,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -465,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)){
@@ -512,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 {
@@ -535,6 +595,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -546,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)){
@@ -555,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) {
@@ -570,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());
@@ -604,6 +667,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -615,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)){
@@ -623,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<>();
@@ -639,7 +705,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());
@@ -701,15 +767,25 @@
             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 {
                 // 公司人员
                 // 查询自己的任务列表
                 taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class)
-                        .eq(TTask::getPatrolInspector, userId));
+                        .eq(TTask::getPatrolInspector, userId)
+                        .between(TTask::getCreateTime, startTime, endTime));
                 if(CollectionUtils.isEmpty(query.getProjectId())){
                     // 查询所有项目部的任务列表
                     List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
@@ -743,6 +819,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -754,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)){
@@ -841,7 +919,8 @@
                 sysUsers = sysUserService.selectListByDeptId(deptId);
             }
             // 超级管理员 查询所有的任务列表
-            List<TTask> taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class));
+            List<TTask> taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class)
+                    .between(TTask::getImplementTime, startTime, endTime));
             if(CollectionUtils.isEmpty(query.getProjectId())){
                 // 查询所有项目部的任务列表
                 List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
@@ -874,6 +953,7 @@
 
             // 查询片区
             if(!CollectionUtils.isEmpty(query.getProjectId())){
+                query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
                 wrapper.in(TTask::getProjectId, query.getProjectId());
             }
 
@@ -885,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)){
@@ -953,5 +1034,330 @@
         return R.ok(result);
     }
 
+
+    @ApiOperation(value = "点位巡检热力图-数量统计")
+    @PostMapping(value = "/pointInspectionHeatStatistics")
+    public R<Map<String, Object>> pointInspectionHeatStatistics(@RequestBody DataStatisticsQuery query) {
+        Map<String, Object> map = new HashMap<>();
+        Integer deptType = tokenService.getLoginUser().getUser().getDeptType();
+        String deptId = tokenService.getLoginUser().getUser().getDeptId();
+        Long userId = tokenService.getLoginUser().getUserId();
+
+        LambdaQueryWrapper<TTask> wrapper = new LambdaQueryWrapper<>();
+
+        Map<String, Date> yearDate = DateUtils.getYearDate(new Date());
+        String startTime = new SimpleDateFormat("yyyy-MM-dd").format(yearDate.get("first"));
+        String endTime = new SimpleDateFormat("yyyy-MM-dd").format(yearDate.get("last"));
+        wrapper.between(TTask::getImplementTime, startTime, endTime);
+
+        List<TTask> list;
+        if (userId != 1L) {
+            // 查询点位类型
+            if(StringUtils.isNotEmpty(query.getLocationTypeId())){
+                // 查询点位
+                List<TLocation> locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class)
+                        .in(TLocation::getLocationType, query.getLocationTypeId()));
+                if(!CollectionUtils.isEmpty(locationList)){
+                    List<String> locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList());
+                    wrapper.in(TTask::getLocationId, locationIds);
+                }
+                map.put("totalLocationNum", locationList.size());
+            }
+            List<TTask> taskList = new ArrayList<>();
+            if (deptType == 1) {
+                // 项目部人员
+                if(CollectionUtils.isEmpty(query.getProjectId())){
+                    TProjectDept projectDept = projectDeptService.getById(deptId);
+                    List<String> projectIds = new ArrayList<>();
+                    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 {
+                // 公司人员
+                // 查询自己的任务列表
+                taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class)
+                        .eq(TTask::getPatrolInspector, userId));
+                if(CollectionUtils.isEmpty(query.getProjectId())){
+                    // 查询所有项目部的任务列表
+                    List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                            .eq(TProjectDept::getStatus, 1)
+                            .ne(TProjectDept::getParentId, 0));
+                    if(!CollectionUtils.isEmpty(tProjectDeptList)){
+                        List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                        query.setProjectId(projectIds);
+                    }
+                }
+            }
+
+            // 查询片区
+            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()));
+                map.put("totalLocationNum", locationList.size());
+            }
+
+            list = taskCleanService.list(wrapper);
+            if(CollectionUtils.isEmpty(list)){
+                return R.ok();
+            }
+
+            if(!CollectionUtils.isEmpty(taskList)){
+                list.addAll(taskList);
+            }
+            list = list.stream().distinct().collect(Collectors.toList());
+        }else {
+            // 超级管理员
+            // 查询点位类型
+            if(StringUtils.isNotEmpty(query.getLocationTypeId())){
+                // 查询点位
+                List<TLocation> locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class)
+                        .in(TLocation::getLocationType, query.getLocationTypeId()));
+                if(!CollectionUtils.isEmpty(locationList)){
+                    List<String> locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList());
+                    wrapper.in(TTask::getLocationId, locationIds);
+                }
+                map.put("totalLocationNum", locationList.size());
+            }
+            // 超级管理员 查询所有的任务列表
+            List<TTask> taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class));
+            if(CollectionUtils.isEmpty(query.getProjectId())){
+                // 查询所有项目部的任务列表
+                List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                        .eq(TProjectDept::getStatus, 1)
+                        .ne(TProjectDept::getParentId, 0));
+                if(!CollectionUtils.isEmpty(tProjectDeptList)){
+                    List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                    query.setProjectId(projectIds);
+                }
+            }
+
+            // 查询片区
+            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()));
+                map.put("totalLocationNum", locationList.size());
+            }
+
+            list = taskCleanService.list(wrapper);
+            if(CollectionUtils.isEmpty(list)){
+                return R.ok();
+            }
+
+            if(!CollectionUtils.isEmpty(taskList)){
+                list.addAll(taskList);
+            }
+            list = list.stream().distinct().collect(Collectors.toList());
+        }
+
+        // 查询任务相关数据
+        // 总计任务数
+        map.put("totalTaskNum", list.size());
+        // 片区数量
+        map.put("totalProjectNum", query.getProjectId().size());
+
+        // 巡检员数
+        Integer totalEmployeeNum = sysUserService.selectUserCount(query.getProjectId(),deptType);
+        if (deptType != 1) {
+            totalEmployeeNum = totalEmployeeNum + 1;
+        }
+        map.put("totalEmployeeNum", totalEmployeeNum);
+
+        // 合格率
+        // 匹配任务详情查看合格数量
+        List<TTask> tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2).collect(Collectors.toList());
+        if(CollectionUtils.isEmpty(tasks)){
+            map.put("qualifiedRate",BigDecimal.ZERO);
+            return R.ok(map);
+        }
+        List<String> taskIds = tasks.stream().map(TTask::getId).collect(Collectors.toList());
+        List<TTaskDetail> taskDetails = tTaskDetailService.list(Wrappers.lambdaQuery(TTaskDetail.class)
+                .in(TTaskDetail::getTaskId, taskIds)
+                .orderByDesc(TTaskDetail::getCreateTime));
+        int qualifiedWarn = 0;
+        for (TTask task : list) {
+            TTaskDetail tTaskDetail = taskDetails.stream().filter(taskDetail -> taskDetail.getTaskId().equals(task.getId())).findFirst().orElse(null);
+            if(Objects.nonNull(tTaskDetail)){
+                if(Objects.nonNull(tTaskDetail.getClearStatus()) && tTaskDetail.getClearStatus() == 1){
+                    qualifiedWarn++;
+                }
+            }
+        }
+        map.put("qualifiedRate", new BigDecimal(qualifiedWarn).divide(new BigDecimal(tasks.size()), 2, RoundingMode.HALF_UP));
+
+        return R.ok(map);
+    }
+
+    @ApiOperation(value = "点位巡检热力图-点位地图")
+    @PostMapping(value = "/pointInspectionHeatMap")
+    public R<List<TLocation>> pointInspectionHeatMap(@RequestBody DataStatisticsQuery query) {
+        Integer deptType = tokenService.getLoginUser().getUser().getDeptType();
+        String deptId = tokenService.getLoginUser().getUser().getDeptId();
+        Long userId = tokenService.getLoginUser().getUserId();
+
+        LambdaQueryWrapper<TLocation> wrapper = new LambdaQueryWrapper<>();
+
+        Map<String, Date> yearDate = DateUtils.getYearDate(new Date());
+        String startTime = new SimpleDateFormat("yyyy-MM-dd").format(yearDate.get("first"));
+        String endTime = new SimpleDateFormat("yyyy-MM-dd").format(yearDate.get("last"));
+        wrapper.between(TLocation::getCreateTime, startTime, endTime);
+
+        // 查询点位类型
+        if(StringUtils.isNotEmpty(query.getLocationTypeId())){
+            // 查询点位
+            wrapper.in(TLocation::getLocationType, query.getLocationTypeId());
+        }
+        if(StringUtils.isNotEmpty(query.getLocationNameOrCode())){
+            wrapper.and(e->e.like(TLocation::getLocationName, query.getLocationNameOrCode()).or()
+                    .like(TLocation::getLocationCode, query.getLocationNameOrCode()));
+        }
+        if (userId != 1L) {
+            if (deptType == 1) {
+                // 项目部人员
+                if(CollectionUtils.isEmpty(query.getProjectId())){
+                    TProjectDept projectDept = projectDeptService.getById(deptId);
+                    List<String> projectIds = new ArrayList<>();
+                    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 {
+                // 公司人员
+                if(CollectionUtils.isEmpty(query.getProjectId())){
+                    // 查询所有项目部的任务列表
+                    List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                            .eq(TProjectDept::getStatus, 1)
+                            .ne(TProjectDept::getParentId, 0));
+                    if(!CollectionUtils.isEmpty(tProjectDeptList)){
+                        List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                        query.setProjectId(projectIds);
+                    }
+                }
+            }
+        }else {
+            // 超级管理员
+            if(CollectionUtils.isEmpty(query.getProjectId())){
+                // 查询所有项目部的任务列表
+                List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                        .eq(TProjectDept::getStatus, 1)
+                        .ne(TProjectDept::getParentId, 0));
+                if(!CollectionUtils.isEmpty(tProjectDeptList)){
+                    List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                    query.setProjectId(projectIds);
+                }
+            }
+        }
+
+        // 查询片区
+        if(!CollectionUtils.isEmpty(query.getProjectId())){
+            query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList()));
+            wrapper.in(TLocation::getProjectId, query.getProjectId());
+        }
+
+        // 查询点位
+        List<TLocation> locationList = locationService.list(wrapper);
+
+        if(CollectionUtils.isEmpty(locationList)){
+            return R.ok(locationList);
+        }
+
+        List<String> locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList());
+
+        // 查询任务
+        List<TTask> tasks = taskCleanService.list(Wrappers.lambdaQuery(TTask.class)
+                .in(TTask::getLocationId, locationIds));
+
+        for (TLocation tLocation : locationList) {
+            long count = tasks.stream().filter(task -> task.getLocationId().equals(tLocation.getId())).count();
+            tLocation.setTaskNum(count);
+        }
+        return R.ok(locationList);
+    }
+
+
+    @ApiOperation(value = "点位巡检热力图-点位详情和统计")
+    @PostMapping(value = "/pointInspectionHeatDetailStatistics")
+    public R<TLocationStatisticsVO> pointInspectionHeatDetailStatistics(@Validated @RequestBody PointDetailQuery query) {
+
+        TLocation location = locationService.getById(query.getLocationId());
+        TLocationStatisticsVO locationStatisticsVO = new TLocationStatisticsVO();
+        BeanUtils.copyProperties(location, locationStatisticsVO);
+
+        List<TTask> list = taskCleanService.list(Wrappers.lambdaQuery(TTask.class)
+                .eq(TTask::getLocationId, query.getLocationId()));
+        // 总数
+        locationStatisticsVO.setTotalInspection(list.size());
+
+        // 完成数
+        long completeInspection = list.stream().filter(task -> task.getStatus() == 6).count();
+        locationStatisticsVO.setCompleteInspection(completeInspection);
+
+        // 合格率
+        List<TTask> tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2).collect(Collectors.toList());
+        if(CollectionUtils.isEmpty(tasks)){
+            locationStatisticsVO.setPassRate(new BigDecimal(0));
+            return R.ok(locationStatisticsVO);
+        }
+        List<String> taskIds = tasks.stream().map(TTask::getId).collect(Collectors.toList());
+        List<TTaskDetail> taskDetails = tTaskDetailService.list(Wrappers.lambdaQuery(TTaskDetail.class)
+                .in(TTaskDetail::getTaskId, taskIds)
+                .orderByDesc(TTaskDetail::getCreateTime));
+        int qualifiedWarn = 0;
+        for (TTask task : list) {
+            TTaskDetail tTaskDetail = taskDetails.stream().filter(taskDetail -> taskDetail.getTaskId().equals(task.getId())).findFirst().orElse(null);
+            if(Objects.nonNull(tTaskDetail)){
+                if(Objects.nonNull(tTaskDetail.getClearStatus()) && tTaskDetail.getClearStatus() == 1){
+                    qualifiedWarn++;
+                }
+            }
+        }
+        locationStatisticsVO.setPassRate(new BigDecimal(qualifiedWarn).divide(new BigDecimal(tasks.size()), 2, RoundingMode.HALF_UP));
+        return R.ok(locationStatisticsVO);
+    }
+
+    @ApiOperation(value = "点位巡检热力图-点位详情任务列表")
+    @PostMapping(value = "/pointInspectionHeatDetailTaskList")
+    public R<PageInfo<TLocationTaskListVO>> pointInspectionHeatDetailTaskList(@Validated @RequestBody PointDetailQuery query) {
+
+        if(StringUtils.isNotBlank(query.getDeptName())){
+
+            List<TProjectDept> projectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                    .like(TProjectDept::getProjectName, query.getDeptName()));
+            List<String> projectIds = projectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
+
+            List<TDept> deptList = deptService.list(Wrappers.lambdaQuery(TDept.class)
+                    .like(TDept::getDeptName, query.getDeptName()));
+            List<String> deptIds = deptList.stream().map(TDept::getId).collect(Collectors.toList());
+
+            projectIds.addAll(deptIds);
+            if (projectIds.isEmpty()){
+                projectIds.add("-1");
+            }
+            query.setProjectIds(projectIds);
+        }
+
+        PageInfo<TLocationTaskListVO> pageInfo = taskCleanService.pointInspectionHeatDetailTaskList(query);
+        return R.ok(pageInfo);
+    }
+
 }
 

--
Gitblit v1.7.1