package com.ruoyi.web.controller.api; 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; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.model.*; 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.*; 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.*; import java.util.stream.Collectors; /** *

* 数据大屏 前端控制器 *

* * @author xiaochen * @since 2025-05-28 */ @Api(tags = "数据大屏") @RestController @RequestMapping("/statistics") public class DataStatisticsController { @Resource private TTaskCleanService taskCleanService; @Resource private TLocationTypeService locationTypeService; @Resource private TLocationService locationService; @Resource private TProjectDeptService projectDeptService; @Resource private TTaskDetailService tTaskDetailService; @Resource private TDeptService deptService; @Resource private ISysUserService sysUserService; @Resource private TokenService tokenService; @Resource private TAppealService appealService; @Resource private TDictDataService dictDataService; @Resource private TEarlyWarningService earlyWarningService; @ApiOperation(value = "查询片区") @GetMapping(value = "/queryProject") public R> queryProject() { Integer deptType = tokenService.getLoginUser().getUser().getDeptType(); String deptId = tokenService.getLoginUser().getUser().getDeptId(); Long userId = tokenService.getLoginUser().getUserId(); List projectDeptList = new ArrayList<>(); if(userId != 1L){ if (deptType == 1) { // 查询片区 TProjectDept projectDept = projectDeptService.getById(deptId); if("0".equals(projectDept.getParentId())){ // 查询项目部 List 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 children = new ArrayList<>(); children.add(projectDept); parent.setChildren(children); projectDeptList.add(parent); } }else { projectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus,1) .eq(TProjectDept::getParentId,0)); // 查询片区 projectDeptList.forEach(projectDept -> { List children = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getParentId, projectDept.getId())); projectDept.setChildren(children); }); } }else { projectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus,1) .eq(TProjectDept::getParentId,0)); // 查询片区 projectDeptList.forEach(projectDept -> { List children = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getParentId, projectDept.getId())); projectDept.setChildren(children); }); } return R.ok(projectDeptList); } @ApiOperation(value = "通过片区id查询点位类型") @GetMapping(value = "/queryLocationByProjectId") public R> queryLocationByProjectId() { // List locationTypes = new ArrayList<>(); // // 通过片区id查询点位 // List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) // .eq(TLocation::getProjectId, projectId)); // if(CollectionUtils.isEmpty(locationList)){ // return R.ok(locationTypes); // } // List typeIds = locationList.stream().map(TLocation::getLocationType).collect(Collectors.toList()); // locationTypes = locationTypeService.list(Wrappers.lambdaQuery(TLocationType.class) // .in(TLocationType::getId, typeIds)); List locationTypes = locationTypeService.list(); return R.ok(locationTypes); } @ApiOperation(value = "数据概览") @PostMapping(value = "/dataOverview") public R> dataOverview(@RequestBody DataStatisticsQuery query) { Map map = new HashMap<>(); Integer deptType = tokenService.getLoginUser().getUser().getDeptType(); String deptId = tokenService.getLoginUser().getUser().getDeptId(); Long userId = tokenService.getLoginUser().getUserId(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); String startTime = LocalDate.now() + " 00:00:00"; String endTime = LocalDate.now() + " 23:59:59"; wrapper.between(TTask::getImplementTime, startTime, endTime); if(userId != 1L){ // 查询点位类型 if(StringUtils.isNotEmpty(query.getLocationTypeId())){ // 查询点位 List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getLocationType, query.getLocationTypeId())); if(!CollectionUtils.isEmpty(locationList)){ List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); wrapper.in(TTask::getLocationId, locationIds); } } List taskList = new ArrayList<>(); if (deptType == 1) { // 项目部人员 if(CollectionUtils.isEmpty(query.getProjectId())){ TProjectDept projectDept = projectDeptService.getById(deptId); List projectIds = new ArrayList<>(); if("0".equals(projectDept.getParentId())){ List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .eq(TProjectDept::getParentId, projectDept.getId())); List ids = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); projectIds.add(projectDept.getId()); projectIds.addAll(ids); }else { projectIds.add(deptId); } query.setProjectId(projectIds); } }else { // 公司人员 // 查询自己的任务列表 taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) .eq(TTask::getPatrolInspector, userId) .between(TTask::getImplementTime, startTime, endTime)); if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询所有项目部的任务列表 List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List 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 list = taskCleanService.list(wrapper); if(CollectionUtils.isEmpty(list)){ return R.ok(map); } 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 || task.getStatus() == 2).count()); map.put("taskPendingCount", list.stream().filter(task -> task.getStatus() == 3).count()); map.put("taskFinishCount", list.stream().filter(task -> task.getStatus() == 5 || task.getStatus() == 6).count()); }else { // 超级管理员 // 查询点位类型 if(StringUtils.isNotEmpty(query.getLocationTypeId())){ // 查询点位 List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getLocationType, query.getLocationTypeId())); if(!CollectionUtils.isEmpty(locationList)){ List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); wrapper.in(TTask::getLocationId, locationIds); } } // 超级管理员 查询所有任务列表 List taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) .in(TTask::getPatrolInspector, userId)); if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询点位类型 // if(StringUtils.isNotEmpty(query.getLocationTypeId())){ // // 查询点位 // List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) // .in(TLocation::getLocationType, query.getLocationTypeId())); // if(!CollectionUtils.isEmpty(locationList)){ // List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); // taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) // .in(TTask::getLocationId, locationIds) // .between(TTask::getImplementTime, startTime, endTime)); // } // } // 查询所有项目部的任务列表 List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List 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()); taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) .in(TTask::getProjectId, query.getProjectId()) .between(TTask::getImplementTime, startTime, endTime)); } List list = taskCleanService.list(wrapper); if(CollectionUtils.isEmpty(list)){ return R.ok(map); } 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 || task.getStatus() == 2).count()); map.put("taskPendingCount", list.stream().filter(task -> task.getStatus() == 3).count()); map.put("taskFinishCount", list.stream().filter(task -> task.getStatus() == 5 || task.getStatus() == 6).count()); } return R.ok(map); } @ApiOperation(value = "点位类型") @PostMapping(value = "/locationType") public R> locationType(@RequestBody DataStatisticsQuery query) { Map map = new HashMap<>(); Integer deptType = tokenService.getLoginUser().getUser().getDeptType(); String deptId = tokenService.getLoginUser().getUser().getDeptId(); Long userId = tokenService.getLoginUser().getUserId(); if(userId != 1L){ // 查询点位类型 if(StringUtils.isNotEmpty(query.getLocationTypeId())){ // 查询点位 List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getLocationType, query.getLocationTypeId())); // 查询类型 TLocationType locationType = locationTypeService.getById(query.getLocationTypeId()); map.put(locationType.getLocationName(), locationList.size()); return R.ok(map); } if (deptType == 1) { // 项目部人员 if(CollectionUtils.isEmpty(query.getProjectId())){ TProjectDept projectDept = projectDeptService.getById(deptId); List projectIds = new ArrayList<>(); if("0".equals(projectDept.getParentId())){ List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .eq(TProjectDept::getParentId, projectDept.getId())); List 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 tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1)); if (!CollectionUtils.isEmpty(tProjectDeptList)) { List projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getProjectId, projectIds)); List locationTypeList = locationList.stream().map(TLocation::getLocationType).distinct().collect(Collectors.toList()); List locationTypes = locationTypeService.list(Wrappers.lambdaQuery(TLocationType.class) .in(TLocationType::getId, locationTypeList)); for (TLocationType locationType : locationTypes) { List locationList1 = locationList.stream().filter(location -> location.getLocationType().equals(locationType.getId())).collect(Collectors.toList()); map.put(locationType.getLocationName(), locationList1.size()); } return R.ok(map); } } } // 查询片区 if(!CollectionUtils.isEmpty(query.getProjectId())){ query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList())); List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getProjectId, query.getProjectId())); List locationTypeList = locationList.stream().map(TLocation::getLocationType).distinct().collect(Collectors.toList()); List locationTypes = locationTypeService.list(Wrappers.lambdaQuery(TLocationType.class) .in(TLocationType::getId, locationTypeList)); for (TLocationType locationType : locationTypes) { List locationList1 = locationList.stream().filter(location -> location.getLocationType().equals(locationType.getId())).collect(Collectors.toList()); map.put(locationType.getLocationName(), locationList1.size()); } return R.ok(map); } }else { // 超级管理员 // 查询点位类型 if(StringUtils.isNotEmpty(query.getLocationTypeId())){ // 查询点位 List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getLocationType, query.getLocationTypeId())); // 查询类型 TLocationType locationType = locationTypeService.getById(query.getLocationTypeId()); map.put(locationType.getLocationName(), locationList.size()); return R.ok(map); } if(CollectionUtils.isEmpty(query.getProjectId())) { // 查询所有项目部的任务列表 List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1)); if (!CollectionUtils.isEmpty(tProjectDeptList)) { List projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getProjectId, projectIds)); List locationTypeList = locationList.stream().map(TLocation::getLocationType).distinct().collect(Collectors.toList()); List locationTypes = locationTypeService.list(Wrappers.lambdaQuery(TLocationType.class) .in(TLocationType::getId, locationTypeList)); for (TLocationType locationType : locationTypes) { List locationList1 = locationList.stream().filter(location -> location.getLocationType().equals(locationType.getId())).collect(Collectors.toList()); map.put(locationType.getLocationName(), locationList1.size()); } return R.ok(map); } }else { // 查询片区 List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getProjectId, query.getProjectId())); if (locationList.isEmpty()){ return R.ok(map); } List locationTypeList = locationList.stream().map(TLocation::getLocationType).distinct().collect(Collectors.toList()); List locationTypes = locationTypeService.list(Wrappers.lambdaQuery(TLocationType.class) .in(TLocationType::getId, locationTypeList)); for (TLocationType locationType : locationTypes) { List locationList1 = locationList.stream().filter(location -> location.getLocationType().equals(locationType.getId())).collect(Collectors.toList()); map.put(locationType.getLocationName(), locationList1.size()); } return R.ok(map); } } return R.ok(map); } @ApiOperation(value = "预警汇总") @PostMapping(value = "/warningSummary") public R> warningSummary(@RequestBody DataStatisticsQuery query) { Map map = new HashMap<>(); map.put("timeoutWarn", 0); map.put("unqualifiedWarn", 0); Integer deptType = tokenService.getLoginUser().getUser().getDeptType(); String deptId = tokenService.getLoginUser().getUser().getDeptId(); Long userId = tokenService.getLoginUser().getUserId(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (userId != 1L) { // 查询点位类型 if(StringUtils.isNotEmpty(query.getLocationTypeId())){ // 查询点位 List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getLocationType, query.getLocationTypeId())); if(!CollectionUtils.isEmpty(locationList)){ List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); wrapper.in(TTask::getLocationId, locationIds); } } List taskList = new ArrayList<>(); if (deptType == 1) { // 项目部人员 if(CollectionUtils.isEmpty(query.getProjectId())){ TProjectDept projectDept = projectDeptService.getById(deptId); List projectIds = new ArrayList<>(); if("0".equals(projectDept.getParentId())){ List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .eq(TProjectDept::getParentId, projectDept.getId())); List ids = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); projectIds.add(projectDept.getId()); 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 tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List 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 list = taskCleanService.list(wrapper); if(CollectionUtils.isEmpty(list)){ return R.ok(map); } if(!CollectionUtils.isEmpty(taskList)){ list.addAll(taskList); } list = list.stream().distinct().collect(Collectors.toList()); int timeoutWarn = 0; int unqualifiedWarn = 0; List earlyWarnings = earlyWarningService.list(Wrappers.lambdaQuery(TEarlyWarning.class)); if(CollectionUtils.isEmpty(earlyWarnings)){ map.put("unqualifiedWarn", unqualifiedWarn); }else { // 将earlyWarnings列表的taskId用逗号拼接 List timeoutWarnList = earlyWarnings.stream().filter(e -> e.getWarningType() == 1).collect(Collectors.toList()); for (TEarlyWarning earlyWarning : timeoutWarnList) { List timeoutWarnTasks = list.stream().filter(task -> earlyWarning.getTaskId().contains(task.getId())).collect(Collectors.toList()); timeoutWarn = timeoutWarn + timeoutWarnTasks.size(); } map.put("timeoutWarn", timeoutWarn); List unqualifiedWarnList = earlyWarnings.stream().filter(e -> e.getWarningType() == 2).collect(Collectors.toList()); for (TEarlyWarning earlyWarning : unqualifiedWarnList) { List unqualifiedWarnTasks = list.stream().filter(task -> earlyWarning.getTaskId().contains(task.getId())).collect(Collectors.toList()); unqualifiedWarn = unqualifiedWarn + unqualifiedWarnTasks.size(); } map.put("unqualifiedWarn", unqualifiedWarn); } }else { // 超级管理员 // 查询点位类型 if(StringUtils.isNotEmpty(query.getLocationTypeId())){ // 查询点位 List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getLocationType, query.getLocationTypeId())); if(!CollectionUtils.isEmpty(locationList)){ List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); wrapper.in(TTask::getLocationId, locationIds); } } // 超级管理员 查询所有的任务列表 List taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) .in(TTask::getPatrolInspector, userId)); if(CollectionUtils.isEmpty(query.getProjectId())){ // // 查询点位类型 // if(StringUtils.isEmpty(query.getLocationTypeId())){ // // 查询点位 // List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) // .in(TLocation::getLocationType, query.getLocationTypeId())); // if(!CollectionUtils.isEmpty(locationList)){ // List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); // taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) // .in(TTask::getLocationId, locationIds)); // } // } // 查询所有项目部的任务列表 List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List 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 list = taskCleanService.list(wrapper); if(CollectionUtils.isEmpty(list)){ return R.ok(map); } if(!CollectionUtils.isEmpty(taskList)){ list.addAll(taskList); } list = list.stream().distinct().collect(Collectors.toList()); int timeoutWarn = 0; int unqualifiedWarn = 0; List earlyWarnings = earlyWarningService.list(Wrappers.lambdaQuery(TEarlyWarning.class)); if(CollectionUtils.isEmpty(earlyWarnings)){ map.put("unqualifiedWarn", unqualifiedWarn); }else { // 将earlyWarnings列表的taskId用逗号拼接 List timeoutWarnList = earlyWarnings.stream().filter(e -> e.getWarningType() == 1).collect(Collectors.toList()); for (TEarlyWarning earlyWarning : timeoutWarnList) { List timeoutWarnTasks = list.stream().filter(task -> earlyWarning.getTaskId().contains(task.getId())).collect(Collectors.toList()); timeoutWarn = timeoutWarn + timeoutWarnTasks.size(); } map.put("timeoutWarn", timeoutWarn); List unqualifiedWarnList = earlyWarnings.stream().filter(e -> e.getWarningType() == 2).collect(Collectors.toList()); for (TEarlyWarning earlyWarning : unqualifiedWarnList) { List unqualifiedWarnTasks = list.stream().filter(task -> earlyWarning.getTaskId().contains(task.getId())).collect(Collectors.toList()); unqualifiedWarn = unqualifiedWarn + unqualifiedWarnTasks.size(); } map.put("unqualifiedWarn", unqualifiedWarn); } } return R.ok(map); } @ApiOperation(value = "清洁不合格分析") @PostMapping(value = "/analysisUnqualifiedCleaning") public R analysisUnqualifiedCleaning(@RequestBody DataStatisticsQuery query) { Integer deptType = tokenService.getLoginUser().getUser().getDeptType(); String deptId = tokenService.getLoginUser().getUser().getDeptId(); Long userId = tokenService.getLoginUser().getUserId(); AnalysisUnqualifiedCleaningVO analysisUnqualifiedCleaningVO = new AnalysisUnqualifiedCleaningVO(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if(userId != 1L){ // 查询点位类型 if(StringUtils.isNotEmpty(query.getLocationTypeId())){ // 查询点位 List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getLocationType, query.getLocationTypeId())); if(!CollectionUtils.isEmpty(locationList)){ List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); wrapper.in(TTask::getLocationId, locationIds); } } List taskList = new ArrayList<>(); if (deptType == 1) { // 项目部人员 if(CollectionUtils.isEmpty(query.getProjectId())){ TProjectDept projectDept = projectDeptService.getById(deptId); List projectIds = new ArrayList<>(); if("0".equals(projectDept.getParentId())){ List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .eq(TProjectDept::getParentId, projectDept.getId())); List ids = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); projectIds.add(projectDept.getId()); 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 tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List 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 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()); List 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 taskIds = tasks.stream().map(TTask::getId).collect(Collectors.toList()); List taskDetails = tTaskDetailService.list(Wrappers.lambdaQuery(TTaskDetail.class) .in(TTaskDetail::getTaskId, taskIds) .eq(TTaskDetail::getClearStatus, 2) .eq(TTaskDetail::getHandleType,1) .orderByDesc(TTaskDetail::getCreateTime)); taskDetails = new ArrayList<>(taskDetails.stream() .collect(Collectors.groupingBy( TTaskDetail::getTaskId, Collectors.collectingAndThen( Collectors.toList(), listAll -> listAll.get(0) ) )) .values()); List taskDetailList = new ArrayList<>(); for (TTask task : list) { TTaskDetail tTaskDetail = taskDetails.stream().filter(taskDetail -> taskDetail.getTaskId().equals(task.getId())).findFirst().orElse(null); if(Objects.nonNull(tTaskDetail)){ taskDetailList.add(tTaskDetail); } } analysisUnqualifiedCleaningVO.setTotal(taskDetailList.size()); // 查询所有的不合格原因 List dictDataList = dictDataService.list(Wrappers.lambdaQuery(TDictData.class) .eq(TDictData::getDataType, 2)); List analysisUnqualifiedCleaningDetailVOS = new ArrayList<>(); for (TDictData tDictData : dictDataList) { List 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()); analysisUnqualifiedCleaningDetailVOS.add(analysisUnqualifiedCleaningDetailVO); } analysisUnqualifiedCleaningVO.setAnalysisUnqualifiedCleaningDetailVOS(analysisUnqualifiedCleaningDetailVOS); }else { // 超级管理员 // 查询点位类型 if(StringUtils.isNotEmpty(query.getLocationTypeId())){ // 查询点位 List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getLocationType, query.getLocationTypeId())); if(!CollectionUtils.isEmpty(locationList)){ List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); wrapper.in(TTask::getLocationId, locationIds); } } // 超级管理员 查询所有的任务列表 List taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) .in(TTask::getPatrolInspector, userId)); if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询点位类型 // if(StringUtils.isNotEmpty(query.getLocationTypeId())){ // // 查询点位 // List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) // .in(TLocation::getLocationType, query.getLocationTypeId())); // if(!CollectionUtils.isEmpty(locationList)){ // List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); // taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) // .in(TTask::getLocationId, locationIds)); // } // } // 查询所有项目部的任务列表 List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List 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 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()); List 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 taskIds = tasks.stream().map(TTask::getId).collect(Collectors.toList()); List taskDetails = tTaskDetailService.list(Wrappers.lambdaQuery(TTaskDetail.class) .in(TTaskDetail::getTaskId, taskIds) .eq(TTaskDetail::getHandleType,1) .eq(TTaskDetail::getClearStatus, 2) .orderByDesc(TTaskDetail::getCreateTime)); taskDetails = new ArrayList<>(taskDetails.stream() .collect(Collectors.groupingBy( TTaskDetail::getTaskId, Collectors.collectingAndThen( Collectors.toList(), listAll -> listAll.get(0) ) )) .values()); List taskDetailList = new ArrayList<>(); for (TTask task : list) { TTaskDetail tTaskDetail = taskDetails.stream().filter(taskDetail -> taskDetail.getTaskId().equals(task.getId())).findFirst().orElse(null); if(Objects.nonNull(tTaskDetail)){ taskDetailList.add(tTaskDetail); } } analysisUnqualifiedCleaningVO.setTotal(taskDetailList.size()); // 查询所有的不合格原因 List dictDataList = dictDataService.list(Wrappers.lambdaQuery(TDictData.class) .eq(TDictData::getDataType, 2)); List analysisUnqualifiedCleaningDetailVOS = new ArrayList<>(); for (TDictData tDictData : dictDataList) { List 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()); analysisUnqualifiedCleaningDetailVOS.add(analysisUnqualifiedCleaningDetailVO); } analysisUnqualifiedCleaningVO.setAnalysisUnqualifiedCleaningDetailVOS(analysisUnqualifiedCleaningDetailVOS); } return R.ok(analysisUnqualifiedCleaningVO); } @ApiOperation(value = "巡检排行榜") @PostMapping(value = "/inspectionRankingList") public R> inspectionRankingList(@Validated @RequestBody DataStatisticsRankQuery query) { Integer deptType = tokenService.getLoginUser().getUser().getDeptType(); String deptId = tokenService.getLoginUser().getUser().getDeptId(); Long userId = tokenService.getLoginUser().getUserId(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); // 判断时间 String startTime = ""; String endTime = ""; switch (query.getTimeType()){ case 1: Map monthDate = DateUtils.getMonthDate(new Date()); startTime = new SimpleDateFormat("yyyy-MM-dd").format((monthDate.get("first"))) + " 00:00:00"; endTime = new SimpleDateFormat("yyyy-MM-dd").format((monthDate.get("last"))) + " 23:59:59"; break; case 2: Map quarterDate = DateUtils.getQuarterDate(new Date()); startTime = new SimpleDateFormat("yyyy-MM-dd").format((quarterDate.get("first"))) + " 00:00:00"; endTime = new SimpleDateFormat("yyyy-MM-dd").format((quarterDate.get("last"))) + " 23:59:59"; break; case 3: Map yearDate = DateUtils.getYearDate(new Date()); startTime = new SimpleDateFormat("yyyy-MM-dd").format((yearDate.get("first"))) + " 00:00:00"; endTime = new SimpleDateFormat("yyyy-MM-dd").format((yearDate.get("last"))) + " 23:59:59"; break; } wrapper.between(TTask::getCreateTime, startTime, endTime); List result = new ArrayList<>(); if(userId != 1L){ // 查询点位类型 if(StringUtils.isNotEmpty(query.getLocationTypeId())){ // 查询点位 List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getLocationType, query.getLocationTypeId())); if(!CollectionUtils.isEmpty(locationList)){ List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); wrapper.in(TTask::getLocationId, locationIds); } } List taskList = new ArrayList<>(); List sysUsers = new ArrayList<>(); if(query.getRankType() == 1){ sysUsers = sysUserService.selectListByDeptId(deptId); } if (deptType == 1) { // 项目部人员 if(CollectionUtils.isEmpty(query.getProjectId())){ TProjectDept projectDept = projectDeptService.getById(deptId); List projectIds = new ArrayList<>(); if("0".equals(projectDept.getParentId())){ List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .eq(TProjectDept::getParentId, projectDept.getId())); List ids = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); projectIds.add(projectDept.getId()); projectIds.addAll(ids); }else { projectIds.add(deptId); } query.setProjectId(projectIds); } }else { // 公司人员 // 查询自己的任务列表 taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) .eq(TTask::getPatrolInspector, userId) .between(TTask::getCreateTime, startTime, endTime)); if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询所有项目部的任务列表 List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); query.setProjectId(projectIds); } if(query.getRankType() == 1){ // 查询所有项目部的人员 List sysUserList = sysUserService.selectListByDeptType(1); if(!CollectionUtils.isEmpty(sysUserList)){ sysUsers.addAll(sysUserList); } } }else { if(query.getRankType() == 1){ // 查询所有片区 List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .in(TProjectDept::getId, query.getProjectId())); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List projectIds = tProjectDeptList.stream().map(TProjectDept::getId).distinct().collect(Collectors.toList()); List sysUserList = sysUserService.selectListByDeptIds(projectIds); sysUsers.addAll(sysUserList); } } } } // 查询片区 if(!CollectionUtils.isEmpty(query.getProjectId())){ query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList())); wrapper.in(TTask::getProjectId, query.getProjectId()); } List 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()); List 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 taskIds = tasks.stream().map(TTask::getId).collect(Collectors.toList()); List taskDetails = tTaskDetailService.list(Wrappers.lambdaQuery(TTaskDetail.class) .in(TTaskDetail::getTaskId, taskIds) .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){ // 用户排名 for (SysUser sysUser : sysUsers) { DataStatisticsRankVO dataStatisticsRankVO = new DataStatisticsRankVO(); dataStatisticsRankVO.setName(sysUser.getNickName()); List 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()) && taskDetail.getClearStatus() == 1).count(); dataStatisticsRankVO.setQualifiedCount(count); result.add(dataStatisticsRankVO); } }else { // 查询项目部 List projectDepts; if(deptType == 1){ 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())){ projectDepts = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .eq(TProjectDept::getParentId, 0)); }else { List projectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .in(TProjectDept::getId, query.getProjectId())); List parentIds = projectDeptList.stream().map(TProjectDept::getParentId).collect(Collectors.toList()); projectDepts = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .in(TProjectDept::getId, parentIds)); } } if(CollectionUtils.isEmpty(projectDepts)){ return R.ok(); } // 查询所有片区 List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .ne(TProjectDept::getParentId, 0)); for (TProjectDept projectDept : projectDepts) { DataStatisticsRankVO dataStatisticsRankVO = new DataStatisticsRankVO(); dataStatisticsRankVO.setName(projectDept.getProjectName()); List taskIdList; if(!CollectionUtils.isEmpty(tProjectDeptList)){ List 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<>(); } dataStatisticsRankVO.setTaskCount(taskIdList.size()); if(CollectionUtils.isEmpty(taskIdList)){ dataStatisticsRankVO.setQualifiedCount(0L); continue; } long count = taskDetails.stream().filter(taskDetail -> taskIdList.contains(taskDetail.getTaskId()) && taskDetail.getClearStatus() == 1).count(); dataStatisticsRankVO.setQualifiedCount(count); result.add(dataStatisticsRankVO); } } }else { // 超级管理员 // 查询点位类型 if(StringUtils.isNotEmpty(query.getLocationTypeId())){ // 查询点位 List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getLocationType, query.getLocationTypeId())); if(!CollectionUtils.isEmpty(locationList)){ List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); wrapper.in(TTask::getLocationId, locationIds); } } List sysUsers = new ArrayList<>(); if(query.getRankType() == 1){ sysUsers = sysUserService.selectListByDeptId(deptId); } // 超级管理员 查询所有的任务列表 List taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) .in(TTask::getPatrolInspector, userId)); if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询点位类型 // if(StringUtils.isNotEmpty(query.getLocationTypeId())){ // // 查询点位 // List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) // .in(TLocation::getLocationType, query.getLocationTypeId())); // if(!CollectionUtils.isEmpty(locationList)){ // List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); // taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) // .in(TTask::getLocationId, locationIds) // .between(TTask::getImplementTime, startTime, endTime)); // } // } // 查询所有项目部的任务列表 List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .ne(TProjectDept::getParentId, 0)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); query.setProjectId(projectIds); } if(query.getRankType() == 1){ // 查询所有项目部的人员 List sysUserList = sysUserService.selectListByDeptType(1); if(!CollectionUtils.isEmpty(sysUserList)){ sysUsers.addAll(sysUserList); } } }else { if(query.getRankType() == 1){ // 查询所有片区 List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .in(TProjectDept::getId, query.getProjectId())); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List projectIds = tProjectDeptList.stream().map(TProjectDept::getId).distinct().collect(Collectors.toList()); List sysUserList = sysUserService.selectListByDeptIds(projectIds); sysUsers.addAll(sysUserList); } } } // 查询片区 if(!CollectionUtils.isEmpty(query.getProjectId())){ query.setProjectId(query.getProjectId().stream().distinct().collect(Collectors.toList())); wrapper.in(TTask::getProjectId, query.getProjectId()); } List 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()); List 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 taskIds = tasks.stream().map(TTask::getId).collect(Collectors.toList()); List taskDetails = tTaskDetailService.list(Wrappers.lambdaQuery(TTaskDetail.class) .in(TTaskDetail::getTaskId, taskIds) .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){ // 用户排名 for (SysUser sysUser : sysUsers) { DataStatisticsRankVO dataStatisticsRankVO = new DataStatisticsRankVO(); dataStatisticsRankVO.setName(sysUser.getNickName()); List 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()) && taskDetail.getClearStatus() == 1).count(); dataStatisticsRankVO.setQualifiedCount(count); result.add(dataStatisticsRankVO); } }else { // 超级管理员 查询所有项目部 List projectDepts; if (CollectionUtils.isEmpty(query.getProjectId())){ projectDepts = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .eq(TProjectDept::getParentId, 0)); }else { List projectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .in(TProjectDept::getId, query.getProjectId())); List parentIds = projectDeptList.stream().map(TProjectDept::getParentId).collect(Collectors.toList()); projectDepts = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .in(TProjectDept::getId, parentIds)); } if(CollectionUtils.isEmpty(projectDepts)){ return R.ok(); } // 查询所有片区 List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .ne(TProjectDept::getParentId, 0)); for (TProjectDept projectDept : projectDepts) { DataStatisticsRankVO dataStatisticsRankVO = new DataStatisticsRankVO(); dataStatisticsRankVO.setName(projectDept.getProjectName()); List taskIdList; if(!CollectionUtils.isEmpty(tProjectDeptList)){ List 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<>(); } dataStatisticsRankVO.setTaskCount(taskIdList.size()); if(CollectionUtils.isEmpty(taskIdList)){ dataStatisticsRankVO.setQualifiedCount(0L); continue; } 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); } @ApiOperation(value = "点位巡检热力图-数量统计") @PostMapping(value = "/pointInspectionHeatStatistics") public R> pointInspectionHeatStatistics(@RequestBody DataStatisticsQuery query) { Map map = new HashMap<>(); Integer deptType = tokenService.getLoginUser().getUser().getDeptType(); String deptId = tokenService.getLoginUser().getUser().getDeptId(); Long userId = tokenService.getLoginUser().getUserId(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); Map 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 list; if (userId != 1L) { // 查询点位类型 if(StringUtils.isNotEmpty(query.getLocationTypeId())){ // 查询点位 List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getLocationType, query.getLocationTypeId())); if(!CollectionUtils.isEmpty(locationList)){ List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); wrapper.in(TTask::getLocationId, locationIds); } map.put("totalLocationNum", locationList.size()); } List taskList = new ArrayList<>(); if (deptType == 1) { // 项目部人员 if(CollectionUtils.isEmpty(query.getProjectId())){ TProjectDept projectDept = projectDeptService.getById(deptId); List projectIds = new ArrayList<>(); if("0".equals(projectDept.getParentId())){ List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .eq(TProjectDept::getParentId, projectDept.getId())); List 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) .between(TTask::getImplementTime, startTime, endTime)); if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询所有项目部的任务列表 List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List 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 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 locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getLocationType, query.getLocationTypeId())); if(!CollectionUtils.isEmpty(locationList)){ List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); wrapper.in(TTask::getLocationId, locationIds); } map.put("totalLocationNum", locationList.size()); } // 超级管理员 查询所有的任务列表 List taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) .in(TTask::getPatrolInspector, userId)); if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询点位类型 // if(StringUtils.isNotEmpty(query.getLocationTypeId())){ // // 查询点位 // List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) // .in(TLocation::getLocationType, query.getLocationTypeId())); // if(!CollectionUtils.isEmpty(locationList)){ // List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); // taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) // .in(TTask::getLocationId, locationIds) // .between(TTask::getImplementTime, startTime, endTime)); // } // } // 查询所有项目部的任务列表 List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List 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 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); if(CollectionUtils.isEmpty(list)){ return R.ok(); } 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); } } // 查询任务相关数据 // 总计任务数 map.put("totalTaskNum", list.size()); // 片区数量 map.put("totalProjectNum", query.getProjectId().size()); // 合格率 // 匹配任务详情查看合格数量 List 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); } List taskIds = tasks.stream().map(TTask::getId).collect(Collectors.toList()); List taskDetails = tTaskDetailService.list(Wrappers.lambdaQuery(TTaskDetail.class) .in(TTaskDetail::getTaskId, taskIds) .eq(TTaskDetail::getHandleType,1) .orderByDesc(TTaskDetail::getCreateTime)); taskDetails = new ArrayList<>(taskDetails.stream() .collect(Collectors.groupingBy( TTaskDetail::getTaskId, Collectors.collectingAndThen( Collectors.toList(), listAll -> listAll.get(0) ) )) .values()); 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_DOWN)); return R.ok(map); } @ApiOperation(value = "点位巡检热力图-点位地图") @PostMapping(value = "/pointInspectionHeatMap") public R> pointInspectionHeatMap(@RequestBody DataStatisticsQuery query) { Integer deptType = tokenService.getLoginUser().getUser().getDeptType(); String deptId = tokenService.getLoginUser().getUser().getDeptId(); Long userId = tokenService.getLoginUser().getUserId(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); Map 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 projectIds = new ArrayList<>(); if("0".equals(projectDept.getParentId())){ List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1) .eq(TProjectDept::getParentId, projectDept.getId())); List 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 tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); query.setProjectId(projectIds); } } } }else { // 超级管理员 if(CollectionUtils.isEmpty(query.getProjectId())){ // 查询所有项目部的任务列表 List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getStatus, 1)); if(!CollectionUtils.isEmpty(tProjectDeptList)){ List 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 locationList = locationService.list(wrapper); if(CollectionUtils.isEmpty(locationList)){ return R.ok(locationList); } List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList()); // 查询任务 List tasks = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) .in(TTask::getLocationId, locationIds)); // 查询片区负责人 List users = sysUserService.selectUserByNickName("片区负责人"); for (TLocation tLocation : locationList) { if(!CollectionUtils.isEmpty(users)){ List userIds = users.stream().map(SysUser::getUserId).collect(Collectors.toList()); List taskList = taskCleanService.lambdaQuery().notIn(TTask::getPatrolInspector, userIds).list(); if(!CollectionUtils.isEmpty(taskList)){ List collect = taskList.stream().map(TTask::getId).collect(Collectors.toList()); long count = taskList.stream().filter(task -> task.getLocationId().equals(tLocation.getId()) && collect.contains(task.getId())).count(); tLocation.setTaskNum(count); }else { long count = tasks.stream().filter(task -> task.getLocationId().equals(tLocation.getId())).count(); tLocation.setTaskNum(count); } }else { 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 pointInspectionHeatDetailStatistics(@Validated @RequestBody PointDetailQuery query) { TLocation location = locationService.getById(query.getLocationId()); TLocationStatisticsVO locationStatisticsVO = new TLocationStatisticsVO(); BeanUtils.copyProperties(location, locationStatisticsVO); // 查询点位类型 TLocationType locationType = locationTypeService.getById(location.getLocationType()); if(Objects.nonNull(locationType)){ locationStatisticsVO.setLocationIcon(locationType.getLocationIcon()); } List 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 || task.getStatus() == 5).count(); locationStatisticsVO.setCompleteInspection(completeInspection); // 合格率 List 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); } List taskIds = tasks.stream().map(TTask::getId).collect(Collectors.toList()); List 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_DOWN)); return R.ok(locationStatisticsVO); } @ApiOperation(value = "点位巡检热力图-点位详情任务列表") @PostMapping(value = "/pointInspectionHeatDetailTaskList") public R> pointInspectionHeatDetailTaskList(@Validated @RequestBody PointDetailQuery query) { if(StringUtils.isNotBlank(query.getDeptName())){ List projectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .like(TProjectDept::getProjectName, query.getDeptName())); List projectIds = projectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList()); List deptList = deptService.list(Wrappers.lambdaQuery(TDept.class) .like(TDept::getDeptName, query.getDeptName())); List deptIds = deptList.stream().map(TDept::getId).collect(Collectors.toList()); projectIds.addAll(deptIds); if (projectIds.isEmpty()){ projectIds.add("-1"); } query.setProjectIds(projectIds); } PageInfo pageInfo = taskCleanService.pointInspectionHeatDetailTaskList(query); return R.ok(pageInfo); } }