From b2e3d6532dbbb3929e01a598dcef7eb07f39b826 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期五, 11 七月 2025 09:30:27 +0800
Subject: [PATCH] 保洁巡检本周代码

---
 ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TIndexController.java |   34 ++++++++++++++++++++++++----------
 1 files changed, 24 insertions(+), 10 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 a41fc1b..fdb22cd 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
@@ -151,8 +151,7 @@
                         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();
+                        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);
@@ -336,7 +335,7 @@
 
                 TProjectDept projectDept = projectDeptService.getById(sysUser.getDeptId());
                 if (projectDept != null) {
-                    if (!"0".equals(projectDept.getParentId())) {
+                    if ("0".equals(projectDept.getParentId())) {
                         // 查询片区下的所有人员
                         users = sysUsers.stream().filter(e -> e.getDeptId()
                                 .equals(projectDept.getId())
@@ -363,11 +362,11 @@
             } else {
                 TDept dept = deptService.getById(sysUser.getDeptId());
                 if (dept != null) {
-                    if (!dept.getDeptName().equals("公司")) {
-                        users = sysUsers.stream().filter(e -> e.getDeptId()
+                    if (!dept.getDeptName().contains("公司")) {
+                        users = sysUsers.stream().filter(e -> (e.getDeptId()
                                 .equals(sysUser.getDeptId())
-                                && e.getStatus().equals("0")
-                                && e.getDeptType() == 1).collect(Collectors.toList());
+                                && e.getStatus().equals("0"))
+                                || e.getDeptType() == 1).collect(Collectors.toList());
                     }
                 }
 
@@ -397,8 +396,8 @@
                 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.isEmpty()) {
-                    BigDecimal divide = new BigDecimal(status3.size() + status4.size())
-                            .divide(new BigDecimal(status3.size()), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100));
+                    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));
@@ -447,7 +446,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) {
@@ -474,6 +472,8 @@
             }
             pendingTask.add(taskTodayVO);
         }
+        // 将pendingTask按照距离 从小到大排序
+        pendingTask.sort(Comparator.comparing(TaskPendingVO::getDistance));
         res.setPendingTask(pendingTask);
         res.setLeaveList(leaveList);
         List<TaskTodayVO> todayTask = new ArrayList<>();
@@ -521,6 +521,8 @@
             }
             todayTask.add(taskTodayVO);
         }
+        // 将todayTask进行排序 优先根据status状态排序,优先展示未执行、超时、待整改、待确认、整改完成、已完成,然后状态一样再根据距离排序
+        sortTodayTasks(todayTask);
         res.setTodayTask(todayTask);
         List<TaskTomorrowVO> tomorrowTask = new ArrayList<>();
 
@@ -548,5 +550,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