From 083c414ff683ab12e65069c6c0ba6871ed1ed09f Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期六, 12 七月 2025 10:19:09 +0800
Subject: [PATCH] 保洁巡检本周代码

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TEarlyWarningController.java |  133 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 131 insertions(+), 2 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TEarlyWarningController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TEarlyWarningController.java
index 5419048..1e8dc3c 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TEarlyWarningController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TEarlyWarningController.java
@@ -1,9 +1,27 @@
 package com.ruoyi.web.controller.api;
 
 
+import com.ruoyi.common.annotation.Log;
+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.enums.BusinessType;
+import com.ruoyi.framework.web.service.TokenService;
+import com.ruoyi.system.model.*;
+import com.ruoyi.system.query.TaskListQuery;
+import com.ruoyi.system.query.TaskWarningQuery;
+import com.ruoyi.system.service.*;
+import com.ruoyi.system.vo.system.TaskListVO;
+import com.ruoyi.system.vo.system.TaskWarningVO;
 import io.swagger.annotations.Api;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -17,6 +35,117 @@
 @RestController
 @RequestMapping("/t-early-warning")
 public class TEarlyWarningController {
+    @Resource
+    private TTaskCleanService taskCleanerService;
 
+    @Resource
+    private TTaskDetailService taskDetailService;
+
+
+    @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 TDictDataService dictDataService;
+    @Resource
+    private TokenService tokenService;
+    @Resource
+    private TEarlyWarningService earlyWarningService;
+    @ApiOperation(value = "任务预警分页列表")
+    @PostMapping(value = "/pageList")
+    public R<PageInfo<TaskWarningVO>> pageList(@RequestBody TaskWarningQuery query) {
+        List<SysUser> sysUsers = sysUserService.selectAllList();
+        List<TLocation> locationList = locationService.list();
+        List<TTask> taskList = taskCleanerService.list();
+        if (StringUtils.hasLength(query.getDeptName())){
+            List<String> projectIds = projectDeptService.lambdaQuery().like(TProjectDept::getProjectName, query.getDeptName()).list()
+                    .stream().map(TProjectDept::getId).collect(Collectors.toList());
+            List<String> deptIds = deptService.lambdaQuery().like(TDept::getDeptName, query.getDeptName()).list()
+                    .stream().map(TDept::getId).collect(Collectors.toList());
+            projectIds.addAll(deptIds);
+            if (projectIds.isEmpty()){
+                return R.ok(new PageInfo<>());
+            }
+            if (StringUtils.hasLength(query.getPhonenumber())){
+                List<Long> patrolInspectorIds = sysUsers.stream().filter(sysUser ->
+                        sysUser.getPhonenumber().equals(query.getPhonenumber())
+                                && projectIds.contains(sysUser.getDeptId())
+                ).map(SysUser::getUserId).collect(Collectors.toList());
+                if (patrolInspectorIds.isEmpty()){
+                    return R.ok(new PageInfo<>());
+                }
+                query.setPatrolInspectorIds(patrolInspectorIds);
+            }
+        }
+        if (StringUtils.hasLength(query.getPhonenumber())){
+            List<Long> patrolInspectorIds = sysUsers.stream().filter(sysUser ->
+                    sysUser.getPhonenumber().equals(query.getPhonenumber())
+            ).map(SysUser::getUserId).collect(Collectors.toList());
+            if (!query.getPatrolInspectorIds().isEmpty()){
+                // 取交集
+                patrolInspectorIds = patrolInspectorIds.stream().filter(query.getPatrolInspectorIds()::contains).collect(Collectors.toList());
+            }
+            query.setPatrolInspectorIds(patrolInspectorIds);
+            if (patrolInspectorIds.isEmpty()){
+                return R.ok(new PageInfo<>());
+            }
+        }
+
+        if (StringUtils.hasLength(query.getLocationType())){
+            List<String> collect = locationList.stream().filter(
+                    e -> e.getLocationType().equals(query.getLocationType())
+                    ).map(TLocation::getId)
+                    .collect(Collectors.toList());
+            if (collect.isEmpty()){
+                return R.ok(new PageInfo<>());
+            }
+            query.setLocationIds(collect);
+        }
+        if (StringUtils.hasLength(query.getLocationName())){
+            List<String> collect = locationList.stream().filter(e -> e.getLocationName().contains(query.getLocationName())).map(TLocation::getId)
+                    .collect(Collectors.toList());
+            if (collect.isEmpty()){
+                query.setLocationIds(collect);
+                return R.ok(new PageInfo<>());
+            }else{
+                collect = collect.stream().filter(query.getLocationIds()::contains).collect(Collectors.toList());
+                if (collect.isEmpty()){
+                    return R.ok(new PageInfo<>());
+                }
+                query.setLocationIds(collect);
+            }
+        }
+        if (query.getPatrolInspectorIds()!=null && !query.getPatrolInspectorIds().isEmpty()){
+            taskList = taskList.stream().filter(task -> query.getPatrolInspectorIds().contains(Long.valueOf(task.getPatrolInspector()))).collect(Collectors.toList());
+            if (taskList.isEmpty()){
+                return R.ok(new PageInfo<>());
+            }
+        }
+        if (query.getLocationIds()!=null && !query.getLocationIds().isEmpty()){
+            taskList = taskList.stream().filter(task -> query.getLocationIds().contains(task.getLocationId())).collect(Collectors.toList());
+            if (taskList.isEmpty()){
+                return R.ok(new PageInfo<>());
+            }
+        }
+        query.setTaskIds(taskList.stream().map(TTask::getId).collect(Collectors.toList()));
+        return R.ok(earlyWarningService.pageList(query));
+    }
+    @Log(title = "预警删除", businessType = BusinessType.DELETE)
+    @ApiOperation(value = "预警删除")
+    @DeleteMapping(value = "/delete")
+    public R<Boolean> edit(@RequestParam String id) {
+        earlyWarningService.removeById(id);
+        return R.ok();
+    }
 }
 

--
Gitblit v1.7.1