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.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.dto.WorkBenchesDTO; import com.ruoyi.system.model.*; import com.ruoyi.system.query.DataStatisticsQuery; import com.ruoyi.system.query.TaskSituationQuery; import com.ruoyi.system.service.*; import com.ruoyi.system.vo.system.*; import com.ruoyi.web.util.OssUploadUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.*; import java.util.stream.Collectors; /** *

* 任务申诉 前端控制器 *

* * @author xiaochen * @since 2025-05-28 */ @Api(tags = "工作台") @RestController @RequestMapping("/workbenches") public class WorkbenchesController { @Resource private TTaskCleanService taskCleanService; @Resource private TLocationTypeService locationTypeService; @Resource private TLocationService locationService; @Resource private TProjectDeptService projectDeptService; @Resource private TTaskDetailService tTaskDetailService; @Resource private ISysUserService sysUserService; @Resource private TokenService tokenService; @Resource private TDictDataService dictDataService; @Resource private TCleanerService cleanerService; @Resource private TLeaveService leaveService; @Resource private TEarlyWarningService earlyWarningService; @ApiOperation(value = "查询部门 项目部列表 不分页") @GetMapping(value = "/listDepts") public R> listDepts() { Long userId = tokenService.getLoginUser().getUserId(); SysUser sysUser = sysUserService.selectUserById(userId); List parent = projectDeptService.lambdaQuery().eq(TProjectDept::getParentId, "0").list(); List child = projectDeptService.lambdaQuery().ne(TProjectDept::getParentId, "0").list(); List res = new ArrayList<>(); DeptNoLimitVO deptNoLimitVO2 = new DeptNoLimitVO(); deptNoLimitVO2.setDeptName("公司"); res.add(deptNoLimitVO2); if (sysUser.getDeptType()==1){ parent = parent.stream().filter(e -> e.getId().equals(sysUser.getDeptId())).collect(Collectors.toList()); } for (DeptNoLimitVO re : res) { if (re.getDeptName().equals("项目部")) { List deptNoLimitVOS = new ArrayList<>(); for (TProjectDept tProjectDept : parent) { DeptNoLimitParentVO deptNoLimitVO = new DeptNoLimitParentVO(); deptNoLimitVO.setDeptName(tProjectDept.getProjectName()); deptNoLimitVO.setDeptId(tProjectDept.getId()); List collect = child.stream().filter(e -> e.getParentId().equals(tProjectDept.getId())).collect(Collectors.toList()); List deptNoLimitChildVOS = new ArrayList<>(); for (TProjectDept projectDept : collect) { DeptNoLimitChildVO deptNoLimitChildVO = new DeptNoLimitChildVO(); deptNoLimitChildVO.setDeptName(projectDept.getProjectName()); deptNoLimitChildVO.setDeptId(projectDept.getId()); deptNoLimitChildVOS.add(deptNoLimitChildVO); } deptNoLimitVO.setDeptChild(deptNoLimitChildVOS); deptNoLimitVOS.add(deptNoLimitVO); } re.setDeptChild(deptNoLimitVOS); } } return R.ok(res); } @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 = locationTypeService.list(); return R.ok(locationTypes); } @ApiOperation(value = "顶部数量统计") @PostMapping(value = "/topQuantityStatistics") public R> topQuantityStatistics(@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<>(); 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)); 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); } } // 巡检员数 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)); // } // } // 查询所有项目部的任务列表 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()); } 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("todayTaskNum", list.stream().filter(tTask -> tTask.getImplementTime().toLocalDate().isEqual(LocalDate.now())).count()); // 待执行任务数 map.put("waitTaskNum", list.stream().filter(tTask -> tTask.getStatus() == 1).count()); // 总计员工数 // Integer totalEmployeeNum = sysUserService.selectUserCount(null,deptType); // if (deptType != 1) { // totalEmployeeNum = totalEmployeeNum + 1; // } // map.put("totalEmployeeNum", totalEmployeeNum); // 今日请假员工数量 List leaves = leaveService.list(Wrappers.lambdaQuery(TLeave.class) .le(TLeave::getStartTime, LocalDate.now()) .ge(TLeave::getEndTime, LocalDate.now()) .eq(TLeave::getAuditStatus, 2)); if(!CollectionUtils.isEmpty(leaves)){ map.put("todayLeaveNum", leaves.size()); }else { map.put("todayLeaveNum", 0); } // 总计保洁员数 long totalCleanerNum = cleanerService.count(Wrappers.lambdaQuery(TCleaner.class) .in(TCleaner::getProjectId, query.getProjectId())); map.put("totalCleanerNum", totalCleanerNum); return R.ok(map); } @ApiOperation(value = "任务情况") @PostMapping(value = "/taskSituation") public R taskSituation(@RequestBody TaskSituationQuery query) { Integer deptType = tokenService.getLoginUser().getUser().getDeptType(); String deptId = tokenService.getLoginUser().getUser().getDeptId(); Long userId = tokenService.getLoginUser().getUserId(); TaskSituationVO taskSituationVO = new TaskSituationVO(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if(StringUtils.isEmpty(query.getStartTime()) || StringUtils.isEmpty(query.getEndTime())){ LocalDate now = LocalDate.now(); String startTime = now.minusDays(6) + " 00:00:00"; String endTime = now + " 23:59:59"; query.setStartTime(startTime); query.setEndTime(endTime); }else { query.setStartTime(query.getStartTime() + " 00:00:00"); query.setEndTime(query.getEndTime() + " 23:59:59"); } wrapper.between(TTask::getImplementTime, query.getStartTime(), query.getEndTime()); // 过滤每天的任务 LocalDateTime start = DateUtils.stringToLocalDateTime(query.getStartTime()); LocalDateTime end = DateUtils.stringToLocalDateTime(query.getEndTime()); long daysBetween = ChronoUnit.DAYS.between(start, end); List taskSituationDayVOList = new ArrayList<>(); LocalDateTime localDateTime = DateUtils.stringToLocalDateTime(query.getStartTime()); String format = null; 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); } } 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, query.getStartTime(), query.getEndTime())); 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 = taskCleanService.list(wrapper); if(CollectionUtils.isEmpty(list)){ for (long i = 0; i <= daysBetween; i++) { TaskSituationDayVO taskSituationDayVO = new TaskSituationDayVO(); if(i == 0){ format = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); }else { format = DateUtils.stringToLocalDate(format).plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); } taskSituationDayVO.setTaskTime(format); // 任务数 taskSituationDayVO.setTaskNum(0); // 完成数 taskSituationDayVO.setCompletedNum(0); taskSituationDayVO.setCompleteRate(BigDecimal.ZERO); taskSituationDayVOList.add(taskSituationDayVO); } taskSituationVO.setTaskSituationDayVO(taskSituationDayVOList); return R.ok(taskSituationVO); } 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); } } // 超级管理员 查询所有的任务列表 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, query.getStartTime(), query.getEndTime())); // } // } // 查询所有项目部的任务列表 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 = taskCleanService.list(wrapper); if(CollectionUtils.isEmpty(list)){ for (long i = 0; i <= daysBetween; i++) { TaskSituationDayVO taskSituationDayVO = new TaskSituationDayVO(); if(i == 0){ format = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); }else { format = DateUtils.stringToLocalDate(format).plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); } taskSituationDayVO.setTaskTime(format); // 任务数 taskSituationDayVO.setTaskNum(0); // 完成数 taskSituationDayVO.setCompletedNum(0); taskSituationDayVO.setCompleteRate(BigDecimal.ZERO); taskSituationDayVOList.add(taskSituationDayVO); } taskSituationVO.setTaskSituationDayVO(taskSituationDayVOList); return R.ok(taskSituationVO); } if(!CollectionUtils.isEmpty(taskList)){ list.addAll(taskList); } list = list.stream().distinct().collect(Collectors.toList()); } // 任务总数 taskSituationVO.setTotalTaskNum(list.size()); List result = list.stream().filter(task -> task.getStatus() == 6 || task.getStatus() == 5).collect(Collectors.toList()); // 已完成任务数 taskSituationVO.setCompletedTaskNum(result.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)){ taskSituationVO.setPassRate(BigDecimal.ZERO); for (long i = 0; i <= daysBetween; i++) { TaskSituationDayVO taskSituationDayVO = new TaskSituationDayVO(); if(i == 0){ format = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); }else { format = DateUtils.stringToLocalDate(format).plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); } taskSituationDayVO.setTaskTime(format); // 任务数 taskSituationDayVO.setTaskNum(0); // 完成数 taskSituationDayVO.setCompletedNum(0); taskSituationDayVO.setCompleteRate(BigDecimal.ZERO); taskSituationDayVOList.add(taskSituationDayVO); } taskSituationVO.setTaskSituationDayVO(taskSituationDayVOList); return R.ok(taskSituationVO); } 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++; } } } taskSituationVO.setPassRate(new BigDecimal(qualifiedWarn).divide(new BigDecimal(tasks.size()), 2, RoundingMode.HALF_DOWN)); for (long i = 0; i <= daysBetween; i++) { TaskSituationDayVO taskSituationDayVO = new TaskSituationDayVO(); if(i == 0){ format = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); }else { format = DateUtils.stringToLocalDate(format).plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); } taskSituationDayVO.setTaskTime(format); String finalFormat = format; List tTasks = list.stream().filter(task -> DateUtils.localDateTimeToString(task.getImplementTime()).contains(finalFormat)).collect(Collectors.toList()); // 任务数 taskSituationDayVO.setTaskNum(tTasks.size()); // 完成数 taskSituationDayVO.setCompletedNum(tTasks.stream().filter(task -> task.getStatus() == 6 || task.getStatus() == 5).collect(Collectors.toList()).size()); int qualifiedWarnChild = 0; for (TTask task : tTasks) { 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){ qualifiedWarnChild++; } } } if(tTasks.isEmpty()){ taskSituationDayVO.setCompleteRate(BigDecimal.ZERO); }else { taskSituationDayVO.setCompleteRate(new BigDecimal(qualifiedWarnChild).divide(new BigDecimal(taskSituationDayVO.getCompletedNum()), 2, RoundingMode.HALF_DOWN)); } taskSituationDayVOList.add(taskSituationDayVO); } taskSituationVO.setTaskSituationDayVO(taskSituationDayVOList); return R.ok(taskSituationVO); } @ApiOperation(value = "今日预警") @PostMapping(value = "/todayWarning") public R> todayWarning(@RequestBody DataStatisticsQuery query) { Integer deptType = tokenService.getLoginUser().getUser().getDeptType(); String deptId = tokenService.getLoginUser().getUser().getDeptId(); Long userId = tokenService.getLoginUser().getUserId(); // 查询所有点位 List locations = locationService.list(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); String startTime = LocalDate.now() + " 00:00:00"; String endTime = LocalDate.now() + " 23:59:59"; // wrapper.between(TTask::getImplementTime, 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<>(); 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)); // 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(new ArrayList<>()); } if(!CollectionUtils.isEmpty(taskList)){ list.addAll(taskList); } list = list.stream().distinct().collect(Collectors.toList()); // 查询预警数据 List earlyWarnings = earlyWarningService.list(Wrappers.lambdaQuery(TEarlyWarning.class) .between(TEarlyWarning::getCreateTime, startTime, endTime)); if(CollectionUtils.isEmpty(earlyWarnings)){ return R.ok(new ArrayList<>()); } String taskIds = earlyWarnings.stream().map(TEarlyWarning::getTaskId).collect(Collectors.joining(",")); Iterator iterator = list.iterator(); while (iterator.hasNext()) { TTask task = iterator.next(); if(!taskIds.contains(task.getId())){ iterator.remove(); } } for (TTask task : list) { TLocation tLocation = locations.stream().filter(location -> location.getId().equals(task.getLocationId())).findFirst().orElse(null); if(Objects.nonNull(tLocation)) { task.setLocationName(tLocation.getLocationName()); } } for (TEarlyWarning earlyWarning : earlyWarnings) { List tTasks = list.stream().filter(task -> earlyWarning.getTaskId().contains(task.getId())).collect(Collectors.toList()); tTasks.forEach(task -> { task.setWarningType(earlyWarning.getWarningType()); }); result.addAll(tTasks); } // List result = list.stream().filter(task -> task.getStatus() == 2).collect(Collectors.toList()); // List tasks = list.stream().filter(task -> task.getStatus() == 1 || task.getStatus() == 2).collect(Collectors.toList()); // if(CollectionUtils.isEmpty(tasks)){ // for (TTask task : result) { // TLocation tLocation = locations.stream().filter(location -> location.getId().equals(task.getLocationId())).findFirst().orElse(null); // if(Objects.nonNull(tLocation)) { // task.setLocationName(tLocation.getLocationName()); // } // } // return R.ok(result); // } // 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)); // 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){ // result.add(task); // } // } // } return R.ok(result); }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()); } List list = taskCleanService.list(wrapper); if(CollectionUtils.isEmpty(list)){ return R.ok(new ArrayList<>()); } if(!CollectionUtils.isEmpty(taskList)){ list.addAll(taskList); } list = list.stream().distinct().collect(Collectors.toList()); // 查询预警数据 List earlyWarnings = earlyWarningService.list(Wrappers.lambdaQuery(TEarlyWarning.class) .between(TEarlyWarning::getCreateTime, startTime, endTime)); if(CollectionUtils.isEmpty(earlyWarnings)){ return R.ok(new ArrayList<>()); } String taskIds = earlyWarnings.stream().map(TEarlyWarning::getTaskId).collect(Collectors.joining(",")); Iterator iterator = list.iterator(); while (iterator.hasNext()) { TTask task = iterator.next(); if(!taskIds.contains(task.getId())){ iterator.remove(); } } for (TTask task : list) { TLocation tLocation = locations.stream().filter(location -> location.getId().equals(task.getLocationId())).findFirst().orElse(null); if(Objects.nonNull(tLocation)) { task.setLocationName(tLocation.getLocationName()); } } for (TEarlyWarning earlyWarning : earlyWarnings) { List tTasks = list.stream().filter(task -> earlyWarning.getTaskId().contains(task.getId())).collect(Collectors.toList()); tTasks.forEach(task -> { task.setWarningType(earlyWarning.getWarningType()); }); result.addAll(tTasks); } // List result = list.stream().filter(task -> task.getStatus() == 2).collect(Collectors.toList()); // List tasks = list.stream().filter(task -> task.getStatus() == 1 || task.getStatus() == 2).collect(Collectors.toList()); // if(CollectionUtils.isEmpty(tasks)){ // for (TTask task : result) { // TLocation tLocation = locations.stream().filter(location -> location.getId().equals(task.getLocationId())).findFirst().orElse(null); // if(Objects.nonNull(tLocation)) { // task.setLocationName(tLocation.getLocationName()); // } // } // return R.ok(result); // } // 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)); // 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){ // result.add(task); // } // } // } // for (TTask task : result) { // TLocation tLocation = locations.stream().filter(location -> location.getId().equals(task.getLocationId())).findFirst().orElse(null); // if(Objects.nonNull(tLocation)) { // task.setLocationName(tLocation.getLocationName()); // } // } return R.ok(result); } } @ApiOperation(value = "待审核任务") @PostMapping(value = "/pendingAuditTasks") public R> pendingAuditTasks(@RequestBody DataStatisticsQuery query) { Integer deptType = tokenService.getLoginUser().getUser().getDeptType(); String deptId = tokenService.getLoginUser().getUser().getDeptId(); Long userId = tokenService.getLoginUser().getUserId(); // 查询所有点位 List locations = locationService.list(); 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 result = list.stream().filter(task -> task.getStatus() == 3).collect(Collectors.toList()); for (TTask task : result) { TLocation tLocation = locations.stream().filter(location -> location.getId().equals(task.getLocationId())).findFirst().orElse(null); if(Objects.nonNull(tLocation)) { task.setLocationName(tLocation.getLocationName()); } } return R.ok(result); }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 result = list.stream().filter(task -> task.getStatus() == 3).collect(Collectors.toList()); for (TTask task : result) { TLocation tLocation = locations.stream().filter(location -> location.getId().equals(task.getLocationId())).findFirst().orElse(null); if(Objects.nonNull(tLocation)) { task.setLocationName(tLocation.getLocationName()); } } return R.ok(result); } } @ApiOperation(value = "保洁质量汇总") @PostMapping(value = "/cleaningQualitySummary") public R> cleaningQualitySummary(@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<>(); 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()); 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("unqualifiedWarn", 0); map.put("qualifiedWarn", 0); 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(), list1 -> list1.get(0) ) )) .values()); int unqualifiedWarn = 0; 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())){ if(tTaskDetail.getClearStatus() == 2){ unqualifiedWarn++; }else { qualifiedWarn++; } }else { unqualifiedWarn++; } } } map.put("qualifiedWarn", qualifiedWarn); 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.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(map); } 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)){ map.put("unqualifiedWarn", 0); map.put("qualifiedWarn", 0); 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) .orderByDesc(TTaskDetail::getCreateTime)); taskDetails = new ArrayList<>(taskDetails.stream() .collect(Collectors.groupingBy( TTaskDetail::getTaskId, Collectors.collectingAndThen( Collectors.toList(), list1 -> list1.get(0) ) )) .values()); int unqualifiedWarn = 0; 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())){ if(tTaskDetail.getClearStatus() == 2){ unqualifiedWarn++; }else { qualifiedWarn++; } }else { unqualifiedWarn++; } } } map.put("unqualifiedWarn", unqualifiedWarn); map.put("qualifiedWarn", qualifiedWarn); } 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(analysisUnqualifiedCleaningVO); } 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); } analysisUnqualifiedCleaningDetailVOS.sort(Comparator.comparingInt(AnalysisUnqualifiedCleaningDetailVO::getCount).reversed()); 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(analysisUnqualifiedCleaningVO); } 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(analysisUnqualifiedCleaningVO); } 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); } // 按照数量倒序排序 analysisUnqualifiedCleaningDetailVOS.sort(Comparator.comparingInt(AnalysisUnqualifiedCleaningDetailVO::getCount).reversed()); analysisUnqualifiedCleaningVO.setAnalysisUnqualifiedCleaningDetailVOS(analysisUnqualifiedCleaningDetailVOS); } return R.ok(analysisUnqualifiedCleaningVO); } }