From d8ad5605a031477c252e029149a4735a1a20ffbd Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期五, 11 七月 2025 20:46:27 +0800 Subject: [PATCH] 保洁巡检本周代码 --- ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TIndexController.java | 155 +++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 111 insertions(+), 44 deletions(-) diff --git a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TIndexController.java b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TIndexController.java index 3506451..4d1bc33 100644 --- a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TIndexController.java +++ b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TIndexController.java @@ -99,6 +99,7 @@ @Resource private TSystemBulletinService systemBulletinService; + @ApiOperation(value = "首页-系统公告") @PostMapping(value = "/systemBulletin") public R<TSystemBulletin> systemBulletin() { @@ -110,17 +111,28 @@ @PostMapping(value = "/dataReport") public R<DataReportVO> dataReport(@RequestBody DataReportDTO dto) { DataReportQuery dataReportQuery = new DataReportQuery(); - dataReportQuery.setStartTime(dto.getStartTime()); - dataReportQuery.setEndTime(dto.getEndTime()); + dataReportQuery.setStartTime(dto.getStartTime()+" 00:00:00"); + dataReportQuery.setEndTime(dto.getEndTime()+" 23:59:59"); + dataReportQuery.setPageNum(dto.getPageNum()); + dataReportQuery.setPageSize(dto.getPageSize()); DataReportVO res = new DataReportVO(); List<TDictData> dataList = dictDataService.list(); List<TProjectDept> projectDepts = projectDeptService.list(); List<TTaskDetail> taskDetails = taskDetailService.lambdaQuery() .isNotNull(TTaskDetail::getClearStatus) + .eq(TTaskDetail::getHandleType,1) .eq(TTaskDetail::getAuditStatus,1) - .groupBy(TTaskDetail::getTaskId) .orderByDesc(BaseModel::getCreateTime) .list(); + taskDetails = new ArrayList<>(taskDetails.stream() + .collect(Collectors.groupingBy( + TTaskDetail::getTaskId, + Collectors.collectingAndThen( + Collectors.toList(), + listAll -> listAll.get(0) + ) + )) + .values()); List<String> userDeptIds = new ArrayList<>(); LambdaQueryWrapper<TTask> tTaskLambdaQueryWrapper = new LambdaQueryWrapper<>(); if (StringUtils.hasLength(dto.getProjectId())) { @@ -151,8 +163,8 @@ tTaskLambdaQueryWrapper.eq(TTask::getProjectId, projectDept.getId()); userDeptIds.add(projectDept.getId()); } else { - TProjectDept parent = projectDeptService.getById(projectDept.getParentId()); - List<TProjectDept> list = projectDeptService.lambdaQuery().eq(TProjectDept::getParentId, parent.getId()).list(); + userDeptIds.add(projectDept.getId()); + List<TProjectDept> list = projectDeptService.lambdaQuery().eq(TProjectDept::getParentId, projectDept.getId()).list(); List<String> deptIds = list.stream().map(TProjectDept::getId).collect(Collectors.toList()); if (!deptIds.isEmpty()) { tTaskLambdaQueryWrapper.in(TTask::getProjectId, deptIds); @@ -168,8 +180,8 @@ dataReportQuery.setProjectIds(userDeptIds); if (StringUtils.hasLength(dto.getStartTime())) { - tTaskLambdaQueryWrapper.ge(TTask::getImplementTime, dto.getStartTime()); - tTaskLambdaQueryWrapper.le(TTask::getImplementTime, dto.getEndTime()); + tTaskLambdaQueryWrapper.ge(TTask::getImplementTime, dto.getStartTime()+" 00:00:00"); + tTaskLambdaQueryWrapper.le(TTask::getImplementTime, dto.getEndTime()+" 23:59:59"); } else { // 获取今天凌晨00:00:00 和今天23:59:59 类型为LocalDateTime LocalDateTime startOfToday = LocalDateTime.of(LocalDate.now(), LocalTime.MIN); @@ -177,7 +189,7 @@ tTaskLambdaQueryWrapper.ge(TTask::getImplementTime, startOfToday); tTaskLambdaQueryWrapper.le(TTask::getImplementTime, endOfToday); } - tTaskLambdaQueryWrapper.ne(TTask::getStatus, 1); +// tTaskLambdaQueryWrapper.ne(TTask::getStatus, 1); List<TTask> tasks = taskCleanerService.list(tTaskLambdaQueryWrapper); HashMap<String, Integer> taskMap = new HashMap<>(); HashMap<String, Integer> statusMap = new HashMap<>(); @@ -214,13 +226,12 @@ break; case 5: temp.append("已完成"); - break; case 6: temp.append("已完成"); break; } - statusMap.put(temp.toString(), statusMap.getOrDefault(task.getStatus()+"", 0) + 1); + statusMap.put(temp.toString(), statusMap.getOrDefault(temp.toString(), 0) + 1); TTaskDetail tTaskDetail = taskDetails.stream().filter(e -> e.getTaskId().equals(task.getId())).findFirst().orElse(null); StringBuilder temp1 = new StringBuilder(); if (tTaskDetail!=null){ @@ -245,6 +256,10 @@ int pass=0; int unPass=0; List<TTask> userTaskList = tasks.stream().filter(e -> e.getPatrolInspector().equals(record.getUserId() + "")).collect(Collectors.toList()); + List<TTask> userTaskListPass = tasks.stream().filter(e -> + (e.getStatus()==5||e.getStatus()==6) + && + e.getPatrolInspector().equals(record.getUserId() + "")).collect(Collectors.toList()); for (TTask tTask : userTaskList) { TTaskDetail tTaskDetail = taskDetails.stream().filter(e -> e.getTaskId().equals(tTask.getId())).findFirst().orElse(null); if (tTaskDetail!=null){ @@ -261,9 +276,7 @@ } record.setTotal(userTaskList.size()); record.setRate(pass+unPass!=0?new BigDecimal(pass).divide(new BigDecimal(pass+unPass),2,RoundingMode.HALF_DOWN).multiply(new BigDecimal(100)):BigDecimal.ZERO); - List<TTask> status1 = userTaskList.stream().filter(e -> e.getStatus() == 5 || e.getStatus() == 6).collect(Collectors.toList()); - List<TTask> status2 = userTaskList.stream().filter(e -> e.getStatus() != 5 && e.getStatus() != 6).collect(Collectors.toList()); - record.setFinish(!status1.isEmpty()?new BigDecimal(status1.size()).divide(new BigDecimal(status1.size()+status2.size()),2,RoundingMode.HALF_DOWN).multiply(new BigDecimal(100)):BigDecimal.ZERO); + record.setFinish(!userTaskList.isEmpty()?new BigDecimal(userTaskListPass.size()).divide(new BigDecimal(userTaskList.size()),2,RoundingMode.HALF_DOWN).multiply(new BigDecimal(100)):BigDecimal.ZERO); } // PageInfo<TaskFinishListVO> taskFinishListVOPageInfo = new PageInfo<>(); @@ -306,9 +319,6 @@ @ApiOperation(value = "首页") @PostMapping(value = "/index") public R<IndexVO> index(@RequestBody IndexDTO dto) throws IOException { -// if (!StringUtils.hasLength(dto.getLon()) || !StringUtils.hasLength(dto.getLat())) { -// return R.fail("请上传经纬度"); -// } IndexVO res = new IndexVO(); res.setIsNotice(0); Long userId = tokenService.getLoginUserApplet().getUserId(); @@ -316,6 +326,8 @@ if (count>0){ res.setIsNotice(1); } + List<TProjectDept> projectListAll = projectDeptService.list(); + List<TLocation> locationList = locationService.list(); List<TLocationType> locationTypeList = locationTypeService.list(); List<TTask> taskAll = taskCleanerService.lambdaQuery().eq(TTask::getPatrolInspector, userId).list(); @@ -336,10 +348,11 @@ TProjectDept projectDept = projectDeptService.getById(sysUser.getDeptId()); if (projectDept != null) { - if (!"0".equals(projectDept.getParentId())) { + if ("0".equals(projectDept.getParentId())) { + List<String> collect = projectListAll.stream().filter(e -> e.getParentId().equals(projectDept.getId())).map(TProjectDept::getId).collect(Collectors.toList()); + collect.add(projectDept.getId()); // 查询片区下的所有人员 - users = sysUsers.stream().filter(e -> e.getDeptId() - .equals(projectDept.getId()) + users = sysUsers.stream().filter(e ->collect.contains(e.getDeptId()) && e.getStatus().equals("0") && e.getDeptType() == 1).collect(Collectors.toList()); } else { @@ -363,11 +376,8 @@ } else { TDept dept = deptService.getById(sysUser.getDeptId()); if (dept != null) { - if (!dept.getDeptName().equals("公司")) { - users = sysUsers.stream().filter(e -> e.getDeptId() - .equals(sysUser.getDeptId()) - && e.getStatus().equals("0") - && e.getDeptType() == 1).collect(Collectors.toList()); + if (!dept.getDeptName().contains("公司")) { + users = sysUsers.stream().filter(e -> e.getDeptType() == 1).collect(Collectors.toList()); } } @@ -388,17 +398,26 @@ .multiply(new BigDecimal(100)) : new BigDecimal(0)); List<TTaskDetail> taskDetails = taskDetailService.lambdaQuery() - .eq(TTaskDetail::getAuditStatus, 1).in(TTaskDetail::getTaskId, taskIds) + .eq(TTaskDetail::getAuditStatus, 1) + .in(TTaskDetail::getTaskId, taskIds) .isNotNull(TTaskDetail::getClearStatus) - .groupBy(TTaskDetail::getTaskId) + .eq(TTaskDetail::getHandleType,1) .orderByDesc(TTaskDetail::getCreateTime).list(); - + taskDetails = new ArrayList<>(taskDetails.stream() + .collect(Collectors.groupingBy( + TTaskDetail::getTaskId, + Collectors.collectingAndThen( + Collectors.toList(), + listAll -> listAll.get(0) + ) + )) + .values()); List<TTaskDetail> status3 = taskDetails.stream().filter(e -> e.getClearStatus() == 1).collect(Collectors.toList()); List<TTaskDetail> status4 = taskDetails.stream().filter(e -> e.getClearStatus() == 2).collect(Collectors.toList()); - if (status3.size() + status4.size() != 0) { - BigDecimal divide = new BigDecimal(status3.size() + status4.size()) - .divide(new BigDecimal(status3.size()), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)); + if (!status3.isEmpty()) { + BigDecimal divide = new BigDecimal(status3.size() ) + .divide(new BigDecimal(status3.size()+ status4.size()), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)); res.setRate(divide); } else { res.setRate(new BigDecimal(0)); @@ -433,6 +452,9 @@ } List<TTask> taskList = taskAll.stream().filter(e -> e.getPatrolInspector().equals(userId + "") && e.getStatus() == 4).collect(Collectors.toList()); List<String> taskIds = taskList.stream().map(TTask::getId).collect(Collectors.toList()); + // 驳回原因 + List<TTaskDetail> tTaskDetails = taskDetailService.list(new LambdaQueryWrapper<TTaskDetail>() + .eq(TTaskDetail::getHandleType,3).groupBy(TTaskDetail::getTaskId).orderByDesc(TTaskDetail::getCreateTime)); for (TTask tTask : taskList) { List<TTaskDetail> taskDetailsStatus1 = taskDetailService.lambdaQuery() .eq(TTaskDetail::getAuditStatus, 1).in(TTaskDetail::getTaskId, taskIds) @@ -447,7 +469,6 @@ taskTodayVO.setLocationLon(tLocation.getLocationLon()); taskTodayVO.setLocationLat(tLocation.getLocationLat()); taskTodayVO.setLocationName(tLocation.getLocationName()); - // todo if(StringUtils.hasLength(dto.getLon())){ Map<String, String> distance = amapApiClient.getDistance(dto.getLon() + "," + dto.getLat(), tLocation.getLocationLon() + "," + tLocation.getLocationLat(), 1); if (distance != null) { @@ -464,16 +485,51 @@ taskTodayVO.setLocationTypeIcon(tLocationType.getLocationIcon()); } } - TTaskDetail tTaskDetail = taskDetailsStatus1.stream().filter(e -> e.getTaskId().equals(tTask.getId())).findFirst().orElse(null); - if (tTaskDetail != null) { - String unqualified = tTaskDetail.getUnqualified(); - TDictData dictData = dictDataService.lambdaQuery().eq(TDictData::getId, unqualified).one(); - if (dictData != null) { - taskTodayVO.setRemark(dictData.getDataContent()); + TTaskDetail tTaskDetail = tTaskDetails.stream().filter(e -> e.getTaskId().equals(tTask.getId())).findFirst().orElse(null); + if (tTaskDetail!=null){ + taskTodayVO.setRemark(tTaskDetail.getAuditRemark()); + } + // 任务记录ids + List<String> collect = taskAll.stream().map(TTask::getId).collect(Collectors.toList()); + if (!collect.isEmpty()){ + List<TInspector> list1 = inspectorService.lambdaQuery() + + .in(TInspector::getTaskId, collect).eq(TInspector::getStatus, 2).list(); + for (TInspector tInspector : list1) { + TaskPendingVO taskTodayVOOne = new TaskPendingVO(); + BeanUtils.copyProperties(tTask, taskTodayVOOne); + taskTodayVOOne.setId(tInspector.getId()); + TLocation tLocationOne = locationList.stream().filter(e -> e.getId().equals(tTask.getLocationId())).findFirst().orElse(null); + if (tLocationOne != null) { + taskTodayVOOne.setLocationAddress(tLocationOne.getLocationAddress()); + taskTodayVOOne.setLocationLon(tLocationOne.getLocationLon()); + taskTodayVOOne.setLocationLat(tLocationOne.getLocationLat()); + taskTodayVOOne.setLocationName(tLocationOne.getLocationName()); + if(StringUtils.hasLength(dto.getLon())){ + Map<String, String> distance = amapApiClient.getDistance(dto.getLon() + "," + dto.getLat(), tLocationOne.getLocationLon() + "," + tLocationOne.getLocationLat(), 1); + if (distance != null) { + taskTodayVOOne.setDistance(new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_EVEN)); + } else { + taskTodayVOOne.setDistance(new BigDecimal("0")); + } + }else { + taskTodayVOOne.setDistance(new BigDecimal("0")); + } + TLocationType tLocationType = locationTypeList.stream().filter(e -> e.getId().equals(tLocationOne.getLocationType())).findFirst().orElse(null); + if (tLocationType != null) { + taskTodayVOOne.setLocationTypeName(tLocationType.getLocationName()); + taskTodayVOOne.setLocationTypeIcon(tLocationType.getLocationIcon()); + } + } + taskTodayVOOne.setStatus(4); + taskTodayVOOne.setRemark(tInspector.getAuditRemark()); + pendingTask.add(taskTodayVOOne); } } pendingTask.add(taskTodayVO); } + // 将pendingTask按照距离 从小到大排序 + pendingTask.sort(Comparator.comparing(TaskPendingVO::getDistance)); res.setPendingTask(pendingTask); res.setLeaveList(leaveList); List<TaskTodayVO> todayTask = new ArrayList<>(); @@ -511,16 +567,15 @@ taskTodayVO.setLocationTypeIcon(tLocationType.getLocationIcon()); } } - TTaskDetail tTaskDetail = taskDetailsStatus1.stream().filter(e -> e.getTaskId().equals(tTask.getId())).findFirst().orElse(null); - if (tTaskDetail != null) { - String unqualified = tTaskDetail.getUnqualified(); - TDictData dictData = dictDataService.lambdaQuery().eq(TDictData::getId, unqualified).one(); - if (dictData != null) { - taskTodayVO.setRemark(dictData.getDataContent()); - } + TTaskDetail tTaskDetail = tTaskDetails.stream().filter(e -> e.getTaskId().equals(tTask.getId())).findFirst().orElse(null); + if (tTaskDetail!=null){ + taskTodayVO.setRemark(tTaskDetail.getAuditRemark()); } todayTask.add(taskTodayVO); + } + // 将todayTask进行排序 优先根据status状态排序,优先展示未执行、超时、待整改、待确认、整改完成、已完成,然后状态一样再根据距离排序 + sortTodayTasks(todayTask); res.setTodayTask(todayTask); List<TaskTomorrowVO> tomorrowTask = new ArrayList<>(); @@ -548,5 +603,17 @@ } return R.ok(res); } + public static void sortTodayTasks(List<TaskTodayVO> taskList) { + Map<Integer, Integer> statusOrder = new HashMap<>(); + statusOrder.put(1, 0); + statusOrder.put(2, 1); + statusOrder.put(4, 2); + statusOrder.put(3, 3); + statusOrder.put(5, 4); + statusOrder.put(6, 5); + + taskList.sort(Comparator.comparingInt((TaskTodayVO o) -> statusOrder.getOrDefault(o.getStatus(), Integer.MAX_VALUE)).thenComparing(TaskTodayVO::getDistance)); + } + } -- Gitblit v1.7.1