From e02b3baaee130d1d9a6ec188deea452763f76c9f Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期五, 11 七月 2025 21:06:06 +0800 Subject: [PATCH] bug修改 --- ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/DataStatisticsController.java | 362 +++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 260 insertions(+), 102 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 5525bf0..aa13f5f 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 @@ -65,6 +65,8 @@ private TAppealService appealService; @Resource private TDictDataService dictDataService; + @Resource + private TEarlyWarningService earlyWarningService; @ApiOperation(value = "查询片区") @GetMapping(value = "/queryProject") @@ -77,12 +79,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 +164,18 @@ 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.add(projectDept.getId()); + projectIds.addAll(ids); + }else { + projectIds.add(deptId); + } query.setProjectId(projectIds); } }else { @@ -166,8 +187,7 @@ if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询所有项目部的任务列表 List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) - .eq(TProjectDept::getStatus, 1) - .ne(TProjectDept::getParentId, 0)); + .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); query.setProjectId(projectIds); @@ -177,6 +197,7 @@ // 查询片区 if(!CollectionUtils.isEmpty(query.getProjectId())){ + query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList())); wrapper.in(TTask::getProjectId, query.getProjectId()); } @@ -188,11 +209,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 { // 超级管理员 // 查询点位类型 @@ -211,8 +233,7 @@ if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询所有项目部的任务列表 List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) - .eq(TProjectDept::getStatus, 1) - .ne(TProjectDept::getParentId, 0)); + .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); query.setProjectId(projectIds); @@ -221,7 +242,11 @@ // 查询片区 if(!CollectionUtils.isEmpty(query.getProjectId())){ + query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList())); wrapper.in(TTask::getProjectId, query.getProjectId()); + taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) + .in(TTask::getProjectId, query.getProjectId()) + .between(TTask::getImplementTime, startTime, endTime)); } List<TTask> list = taskCleanService.list(wrapper); @@ -232,11 +257,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,16 +290,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.add(projectDept.getId()); + 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)); + .eq(TProjectDept::getStatus, 1)); if (!CollectionUtils.isEmpty(tProjectDeptList)) { List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); List<TLocation> locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) @@ -292,6 +327,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()); @@ -318,8 +354,7 @@ if(CollectionUtils.isEmpty(query.getProjectId())) { // 查询所有项目部的任务列表 List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) - .eq(TProjectDept::getStatus, 1) - .ne(TProjectDept::getParentId, 0)); + .eq(TProjectDept::getStatus, 1)); if (!CollectionUtils.isEmpty(tProjectDeptList)) { List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); List<TLocation> locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) @@ -379,8 +414,18 @@ 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.add(projectDept.getId()); + projectIds.addAll(ids); + }else { + projectIds.add(deptId); + } query.setProjectId(projectIds); } }else { @@ -391,8 +436,7 @@ if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询所有项目部的任务列表 List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) - .eq(TProjectDept::getStatus, 1) - .ne(TProjectDept::getParentId, 0)); + .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); query.setProjectId(projectIds); @@ -402,6 +446,7 @@ // 查询片区 if(!CollectionUtils.isEmpty(query.getProjectId())){ + query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList())); wrapper.in(TTask::getProjectId, query.getProjectId()); } @@ -413,26 +458,22 @@ 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)){ - map.put("unqualifiedWarn", 0); - 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 unqualifiedWarn = 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() == 2){ + List<TEarlyWarning> earlyWarnings = earlyWarningService.list(Wrappers.lambdaQuery(TEarlyWarning.class)); + if(CollectionUtils.isEmpty(earlyWarnings)){ + map.put("unqualifiedWarn", unqualifiedWarn); + }else { + // 将earlyWarnings列表的taskId用逗号拼接 + String taskIds = earlyWarnings.stream().map(TEarlyWarning::getTaskId).collect(Collectors.joining(",")); + for (TTask task : list) { + if(taskIds.contains(task.getId())){ unqualifiedWarn++; } } + map.put("unqualifiedWarn", unqualifiedWarn); } - map.put("unqualifiedWarn", unqualifiedWarn); }else { // 超级管理员 // 查询点位类型 @@ -446,12 +487,12 @@ } } // 超级管理员 查询所有的任务列表 - List<TTask> taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class)); + List<TTask> taskList = new ArrayList<>(); if(CollectionUtils.isEmpty(query.getProjectId())){ + taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class)); // 查询所有项目部的任务列表 List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) - .eq(TProjectDept::getStatus, 1) - .ne(TProjectDept::getParentId, 0)); + .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); query.setProjectId(projectIds); @@ -460,6 +501,7 @@ // 查询片区 if(!CollectionUtils.isEmpty(query.getProjectId())){ + query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList())); wrapper.in(TTask::getProjectId, query.getProjectId()); } @@ -471,26 +513,22 @@ 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)){ - map.put("unqualifiedWarn", 0); - 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 unqualifiedWarn = 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() == 2){ + List<TEarlyWarning> earlyWarnings = earlyWarningService.list(Wrappers.lambdaQuery(TEarlyWarning.class)); + if(CollectionUtils.isEmpty(earlyWarnings)){ + map.put("unqualifiedWarn", unqualifiedWarn); + }else { + // 将earlyWarnings列表的taskId用逗号拼接 + String taskIds = earlyWarnings.stream().map(TEarlyWarning::getTaskId).collect(Collectors.joining(",")); + for (TTask task : list) { + if(taskIds.contains(task.getId())){ unqualifiedWarn++; } } + map.put("unqualifiedWarn", unqualifiedWarn); } - map.put("unqualifiedWarn", unqualifiedWarn); } return R.ok(map); } @@ -518,8 +556,18 @@ 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.add(projectDept.getId()); + projectIds.addAll(ids); + }else { + projectIds.add(deptId); + } query.setProjectId(projectIds); } }else { @@ -530,8 +578,7 @@ if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询所有项目部的任务列表 List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) - .eq(TProjectDept::getStatus, 1) - .ne(TProjectDept::getParentId, 0)); + .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); query.setProjectId(projectIds); @@ -541,6 +588,7 @@ // 查询片区 if(!CollectionUtils.isEmpty(query.getProjectId())){ + query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList())); wrapper.in(TTask::getProjectId, query.getProjectId()); } @@ -552,8 +600,10 @@ 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()); + List<TTask> tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2 + && task.getStatus() != 3 && task.getStatus() != 4).collect(Collectors.toList()); if(CollectionUtils.isEmpty(tasks)){ return R.ok(); } @@ -561,6 +611,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 +627,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()); @@ -596,12 +647,12 @@ } } // 超级管理员 查询所有的任务列表 - List<TTask> taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class)); + List<TTask> taskList = new ArrayList<>(); if(CollectionUtils.isEmpty(query.getProjectId())){ + taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class)); // 查询所有项目部的任务列表 List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) - .eq(TProjectDept::getStatus, 1) - .ne(TProjectDept::getParentId, 0)); + .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); query.setProjectId(projectIds); @@ -610,6 +661,7 @@ // 查询片区 if(!CollectionUtils.isEmpty(query.getProjectId())){ + query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList())); wrapper.in(TTask::getProjectId, query.getProjectId()); } @@ -621,14 +673,17 @@ 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()); + List<TTask> tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2 + && task.getStatus() != 3 && task.getStatus() != 4).collect(Collectors.toList()); if(CollectionUtils.isEmpty(tasks)){ return R.ok(); } 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 +700,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()); @@ -707,8 +762,18 @@ 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.add(projectDept.getId()); + projectIds.addAll(ids); + }else { + projectIds.add(deptId); + } query.setProjectId(projectIds); } }else { @@ -720,8 +785,7 @@ if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询所有项目部的任务列表 List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) - .eq(TProjectDept::getStatus, 1) - .ne(TProjectDept::getParentId, 0)); + .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); query.setProjectId(projectIds); @@ -750,6 +814,7 @@ // 查询片区 if(!CollectionUtils.isEmpty(query.getProjectId())){ + query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList())); wrapper.in(TTask::getProjectId, query.getProjectId()); } @@ -761,16 +826,29 @@ 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()); + List<TTask> tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2 + && task.getStatus() != 3 && task.getStatus() != 4).collect(Collectors.toList()); if(CollectionUtils.isEmpty(tasks)){ return R.ok(); } 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::getClearStatus, 1) + .eq(TTaskDetail::getHandleType,1) .orderByDesc(TTaskDetail::getCreateTime)); + + // 使用 stream 去重,保留每个 taskId 最新的一条 + taskDetails = new ArrayList<>(taskDetails.stream() + .collect(Collectors.groupingBy( + TTaskDetail::getTaskId, + Collectors.collectingAndThen( + Collectors.toList(), + list1 -> list1.get(0) + ) + )) + .values()); if(query.getRankType() == 1){ // 用户排名 @@ -779,8 +857,10 @@ dataStatisticsRankVO.setName(sysUser.getNickName()); List<String> taskIdList = tasks.stream().filter(task -> task.getPatrolInspector().equals(String.valueOf(sysUser.getUserId()))).map(TTask::getId).collect(Collectors.toList()); dataStatisticsRankVO.setTaskCount(taskIdList.size()); - long count = taskDetails.stream().filter(taskDetail -> taskIdList.contains(taskDetail.getTaskId())).count(); + long count = taskDetails.stream().filter(taskDetail -> taskIdList.contains(taskDetail.getTaskId()) + && taskDetail.getClearStatus() == 1).count(); dataStatisticsRankVO.setQualifiedCount(count); + result.add(dataStatisticsRankVO); } }else { // 查询项目部 @@ -789,6 +869,9 @@ projectDepts = new ArrayList<>(); // 当前项目部 TProjectDept projectDept = projectDeptService.getById(deptId); + if(Objects.nonNull(projectDept) && !"0".equals(projectDept.getParentId())){ + projectDept = projectDeptService.getById(projectDept.getParentId()); + } projectDepts.add(projectDept); }else { if (CollectionUtils.isEmpty(query.getProjectId())){ @@ -817,7 +900,7 @@ dataStatisticsRankVO.setName(projectDept.getProjectName()); List<String> taskIdList; if(!CollectionUtils.isEmpty(tProjectDeptList)){ - List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); + List<String> projectIds = tProjectDeptList.stream().filter(e -> e.getParentId().equals(projectDept.getId())).map(TProjectDept::getId).collect(Collectors.toList()); taskIdList = tasks.stream().filter(task -> projectIds.contains(task.getProjectId())).map(TTask::getId).collect(Collectors.toList()); } else { taskIdList = new ArrayList<>(); @@ -827,8 +910,10 @@ dataStatisticsRankVO.setQualifiedCount(0L); continue; } - long count = taskDetails.stream().filter(taskDetail -> taskIdList.contains(taskDetail.getTaskId())).count(); + long count = taskDetails.stream().filter(taskDetail -> taskIdList.contains(taskDetail.getTaskId()) + && taskDetail.getClearStatus() == 1).count(); dataStatisticsRankVO.setQualifiedCount(count); + result.add(dataStatisticsRankVO); } } }else { @@ -882,6 +967,7 @@ // 查询片区 if(!CollectionUtils.isEmpty(query.getProjectId())){ + query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList())); wrapper.in(TTask::getProjectId, query.getProjectId()); } @@ -893,16 +979,29 @@ 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()); + List<TTask> tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2 + && task.getStatus() != 3 && task.getStatus() != 4).collect(Collectors.toList()); if(CollectionUtils.isEmpty(tasks)){ return R.ok(); } 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::getClearStatus, 1) + .eq(TTaskDetail::getHandleType,1) .orderByDesc(TTaskDetail::getCreateTime)); + + // 使用 stream 去重,保留每个 taskId 最新的一条 + taskDetails = new ArrayList<>(taskDetails.stream() + .collect(Collectors.groupingBy( + TTaskDetail::getTaskId, + Collectors.collectingAndThen( + Collectors.toList(), + list1 -> list1.get(0) + ) + )) + .values()); if(query.getRankType() == 1){ // 用户排名 @@ -911,8 +1010,10 @@ dataStatisticsRankVO.setName(sysUser.getNickName()); List<String> taskIdList = tasks.stream().filter(task -> task.getPatrolInspector().equals(String.valueOf(sysUser.getUserId()))).map(TTask::getId).collect(Collectors.toList()); dataStatisticsRankVO.setTaskCount(taskIdList.size()); - long count = taskDetails.stream().filter(taskDetail -> taskIdList.contains(taskDetail.getTaskId())).count(); + long count = taskDetails.stream().filter(taskDetail -> taskIdList.contains(taskDetail.getTaskId()) + && taskDetail.getClearStatus() == 1).count(); dataStatisticsRankVO.setQualifiedCount(count); + result.add(dataStatisticsRankVO); } }else { // 超级管理员 查询所有项目部 @@ -942,7 +1043,7 @@ dataStatisticsRankVO.setName(projectDept.getProjectName()); List<String> taskIdList; if(!CollectionUtils.isEmpty(tProjectDeptList)){ - List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); + List<String> projectIds = tProjectDeptList.stream().filter(e -> e.getParentId().equals(projectDept.getId())).map(TProjectDept::getId).collect(Collectors.toList()); taskIdList = tasks.stream().filter(task -> projectIds.contains(task.getProjectId())).map(TTask::getId).collect(Collectors.toList()); } else { taskIdList = new ArrayList<>(); @@ -952,12 +1053,21 @@ dataStatisticsRankVO.setQualifiedCount(0L); continue; } - long count = taskDetails.stream().filter(taskDetail -> taskIdList.contains(taskDetail.getTaskId())).count(); + long count = taskDetails.stream().filter(taskDetail -> taskIdList.contains(taskDetail.getTaskId()) + && taskDetail.getClearStatus() == 1).count(); dataStatisticsRankVO.setQualifiedCount(count); + result.add(dataStatisticsRankVO); } } } - + // 先根据任务总数排序,再根据合格数进行排序 + result.sort((o1, o2) -> { + if (o1.getTaskCount().equals(o2.getTaskCount())) { + return o2.getQualifiedCount().compareTo(o1.getQualifiedCount()); + }else{ + return o2.getTaskCount().compareTo(o1.getTaskCount()); + } + }); return R.ok(result); } @@ -994,29 +1104,48 @@ 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.add(projectDept.getId()); + projectIds.addAll(ids); + }else { + projectIds.add(deptId); + } query.setProjectId(projectIds); } + // 巡检员数 + Integer totalEmployeeNum = sysUserService.selectUserCount(query.getProjectId(),deptType); + map.put("totalEmployeeNum", totalEmployeeNum); }else { // 公司人员 // 查询自己的任务列表 taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) - .eq(TTask::getPatrolInspector, userId)); + .eq(TTask::getPatrolInspector, userId) + .between(TTask::getImplementTime, startTime, endTime)); if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询所有项目部的任务列表 List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) - .eq(TProjectDept::getStatus, 1) - .ne(TProjectDept::getParentId, 0)); + .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); query.setProjectId(projectIds); } + }else { + } + // 巡检员数 + Integer totalEmployeeNum = sysUserService.selectUserCount(query.getProjectId(),1); + map.put("totalEmployeeNum", totalEmployeeNum+1); } // 查询片区 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 +1161,8 @@ if(!CollectionUtils.isEmpty(taskList)){ list.addAll(taskList); } + list = list.stream().distinct().collect(Collectors.toList()); + }else { // 超级管理员 // 查询点位类型 @@ -1046,12 +1177,13 @@ map.put("totalLocationNum", locationList.size()); } // 超级管理员 查询所有的任务列表 - List<TTask> taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class)); + List<TTask> taskList = new ArrayList<>(); if(CollectionUtils.isEmpty(query.getProjectId())){ + taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) + .between(TTask::getImplementTime, startTime, endTime)); // 查询所有项目部的任务列表 List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) - .eq(TProjectDept::getStatus, 1) - .ne(TProjectDept::getParentId, 0)); + .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); query.setProjectId(projectIds); @@ -1060,10 +1192,14 @@ // 查询片区 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()); + taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) + .in(TTask::getProjectId, query.getProjectId()) + .between(TTask::getImplementTime, startTime, endTime)); } list = taskCleanService.list(wrapper); @@ -1074,6 +1210,18 @@ if(!CollectionUtils.isEmpty(taskList)){ list.addAll(taskList); } + list = list.stream().distinct().collect(Collectors.toList()); + + // 巡检员数 + if(CollectionUtils.isEmpty(query.getProjectId())){ + Integer totalEmployeeNum = sysUserService.selectUserCount(query.getProjectId(),deptType); + Integer totalEmployeeNum1 = sysUserService.selectUserCount(query.getProjectId(),1); + map.put("totalEmployeeNum", totalEmployeeNum+totalEmployeeNum1); + }else { + Integer totalEmployeeNum = sysUserService.selectUserCount(query.getProjectId(),1); + map.put("totalEmployeeNum", totalEmployeeNum); + } + } // 查询任务相关数据 @@ -1082,16 +1230,10 @@ // 片区数量 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()); + List<TTask> tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2 + && task.getStatus() != 3 && task.getStatus() != 4).collect(Collectors.toList()); if(CollectionUtils.isEmpty(tasks)){ map.put("qualifiedRate",BigDecimal.ZERO); return R.ok(map); @@ -1109,7 +1251,7 @@ } } } - map.put("qualifiedRate", new BigDecimal(qualifiedWarn).divide(new BigDecimal(tasks.size()), 2, RoundingMode.HALF_UP)); + map.put("qualifiedRate", new BigDecimal(qualifiedWarn).divide(new BigDecimal(tasks.size()), 2, RoundingMode.HALF_DOWN)); return R.ok(map); } @@ -1141,8 +1283,18 @@ 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.add(projectDept.getId()); + projectIds.addAll(ids); + }else { + projectIds.add(deptId); + } query.setProjectId(projectIds); } }else { @@ -1150,8 +1302,7 @@ if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询所有项目部的任务列表 List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) - .eq(TProjectDept::getStatus, 1) - .ne(TProjectDept::getParentId, 0)); + .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); query.setProjectId(projectIds); @@ -1163,8 +1314,7 @@ if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询所有项目部的任务列表 List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) - .eq(TProjectDept::getStatus, 1) - .ne(TProjectDept::getParentId, 0)); + .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List<String> projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); query.setProjectId(projectIds); @@ -1174,6 +1324,7 @@ // 查询片区 if(!CollectionUtils.isEmpty(query.getProjectId())){ + query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList())); wrapper.in(TLocation::getProjectId, query.getProjectId()); } @@ -1206,17 +1357,24 @@ TLocationStatisticsVO locationStatisticsVO = new TLocationStatisticsVO(); BeanUtils.copyProperties(location, locationStatisticsVO); + // 查询点位类型 + TLocationType locationType = locationTypeService.getById(location.getLocationType()); + if(Objects.nonNull(locationType)){ + locationStatisticsVO.setLocationIcon(locationType.getLocationIcon()); + } + 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(); + long completeInspection = list.stream().filter(task -> task.getStatus() == 6 || task.getStatus() == 5).count(); locationStatisticsVO.setCompleteInspection(completeInspection); // 合格率 - List<TTask> tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2).collect(Collectors.toList()); + List<TTask> tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2 + && task.getStatus() != 3 && task.getStatus() != 4).collect(Collectors.toList()); if(CollectionUtils.isEmpty(tasks)){ locationStatisticsVO.setPassRate(new BigDecimal(0)); return R.ok(locationStatisticsVO); @@ -1234,7 +1392,7 @@ } } } - locationStatisticsVO.setPassRate(new BigDecimal(qualifiedWarn).divide(new BigDecimal(tasks.size()), 2, RoundingMode.HALF_UP)); + locationStatisticsVO.setPassRate(new BigDecimal(qualifiedWarn).divide(new BigDecimal(tasks.size()), 2, RoundingMode.HALF_DOWN)); return R.ok(locationStatisticsVO); } -- Gitblit v1.7.1