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 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; /** *

* 任务预警 前端控制器 *

* * @author xiaochen * @since 2025-05-28 */ @Api(tags = "任务预警") @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> pageList(@RequestBody TaskWarningQuery query) { List sysUsers = sysUserService.selectAllList(); List locationList = locationService.list(); List taskList = taskCleanerService.list(); if (StringUtils.hasLength(query.getDeptName())){ List list = projectDeptService.lambdaQuery().like(TProjectDept::getProjectName, query.getDeptName()).list(); List listIds = projectDeptService.lambdaQuery().like(TProjectDept::getProjectName, query.getDeptName()).list() .stream().map(TProjectDept::getId).collect(Collectors.toList()); for (TProjectDept tProjectDept : list) { if (tProjectDept.getParentId().equals("0")){ List collect = projectDeptService.lambdaQuery().eq(TProjectDept::getParentId, tProjectDept.getId()).list() .stream().map(TProjectDept::getId).collect(Collectors.toList()); listIds.addAll(collect); listIds.add(tProjectDept.getId()); } } List deptIds = deptService.lambdaQuery().like(TDept::getDeptName, query.getDeptName()).list() .stream().map(TDept::getId).collect(Collectors.toList()); listIds.addAll(deptIds); if (listIds.isEmpty()){ return R.ok(new PageInfo<>()); } List collect = sysUsers.stream().filter(e -> listIds.contains(e.getDeptId())) .map(SysUser::getUserId).collect(Collectors.toList()); query.setPatrolInspectorIds( collect); if (StringUtils.hasLength(query.getPhonenumber())){ List patrolInspectorIds = sysUsers.stream().filter(sysUser -> sysUser.getPhonenumber().contains(query.getPhonenumber()) && listIds.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 patrolInspectorIds = sysUsers.stream().filter(sysUser -> sysUser.getPhonenumber().contains(query.getPhonenumber()) ).map(SysUser::getUserId).collect(Collectors.toList()); query.setPatrolInspectorIds(patrolInspectorIds); 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 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 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{ if (query.getLocationIds()!=null && !query.getLocationIds().isEmpty()){ 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 edit(@RequestParam String id) { earlyWarningService.removeById(id); return R.ok(); } }