package com.ruoyi.inspect.controller; import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWell; import com.ruoyi.alarmpoints.well.service.IArdAlarmpointsWellService; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.inspect.service.IArdVideoInspectTaskService; import com.ruoyi.inspect.service.impl.InspectionTaskManager; import com.ruoyi.system.service.ISysDeptService; import com.ruoyi.utils.gis.GisUtil; import com.ruoyi.utils.gis.Point; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.stream.Collectors; /** * @Description: 巡检任务controller * @ClassName: TaskController * @Author: 刘苏义 * @Date: 2023年06月01日9:19 * @Version: 1.0 **/ @RestController @Api(tags = "巡检任务") @RequestMapping("/inspect/control") public class TaskController { @Autowired private InspectionTaskManager inspectionTaskManager; @Autowired IArdVideoInspectTaskService ardVideoInspectTaskService; @Autowired IArdAlarmpointsWellService ardAlarmpointsWellService; @Autowired private ISysDeptService deptService; @PreAuthorize("@ss.hasPermi('inspect:control:manual')") @GetMapping("/startTask/{taskId}") @ApiOperation("手动开启巡检") AjaxResult startTask(@PathVariable String taskId) { boolean enablemanualTask = ardVideoInspectTaskService.isEnablemanualTask(taskId); if (enablemanualTask) { // 开启巡检任务 inspectionTaskManager.startInspectionTask(taskId); return AjaxResult.success(); } else { return AjaxResult.error(); } } @GetMapping("/startTask/{taskId}/noPerm") @ApiOperation("手动开启巡检-不校验权限") AjaxResult startTaskNoPerm(@PathVariable String taskId) { boolean enablemanualTask = ardVideoInspectTaskService.isEnablemanualTask(taskId); if (enablemanualTask) { // 开启巡检任务 inspectionTaskManager.startInspectionTask(taskId); return AjaxResult.success(); } else { return AjaxResult.error(); } } @PreAuthorize("@ss.hasPermi('inspect:control:manual')") @ApiOperation("手动停止巡检") @GetMapping("/stopTask/{taskId}") AjaxResult stopTask(@PathVariable String taskId) { // 停止巡检任务 inspectionTaskManager.stopInspectionTask(taskId); return AjaxResult.success(); } @ApiOperation("手动停止巡检-不校验权限") @GetMapping("/stopTask/{taskId}/noPerm") AjaxResult stopTaskNoPerm(@PathVariable String taskId) { // 停止巡检任务 inspectionTaskManager.stopInspectionTask(taskId); return AjaxResult.success(); } @PreAuthorize("@ss.hasPermi('inspect:control:manual')") @ApiOperation("查询已启动任务") @GetMapping("/getTaskList") AjaxResult getTaskList() { // 停止巡检任务 Set taskIds = inspectionTaskManager.getTaskMap().keySet(); return AjaxResult.success(taskIds); } @ApiOperation("查询已启动任务-不校验权限") @GetMapping("/getTaskList/noPerm") AjaxResult getTaskListNoPerm() { // 停止巡检任务 Set taskIds = inspectionTaskManager.getTaskMap().keySet(); return AjaxResult.success(taskIds); } @ApiOperation("查询范围内的井") @PostMapping("/getWellListByPolygon") AjaxResult getWellListByPolygon(@RequestBody List points) { List inPolygonWellList = deptService.selectDeptList(new SysDept()).stream() .map(dept -> { ArdAlarmpointsWell ardAlarmpointsWell = new ArdAlarmpointsWell(); ardAlarmpointsWell.setDeptId(dept.getDeptId()); return ardAlarmpointsWellService.selectArdAlarmpointsWellList(ardAlarmpointsWell).stream() .filter(well -> well.getLongitude() != null && well.getLatitude() != null) .filter(well -> GisUtil.isInPolygon(new Point(well.getLongitude(), well.getLatitude()), points)) .collect(Collectors.toList()); }) .flatMap(List::stream) .collect(Collectors.toList()); return AjaxResult.success(inPolygonWellList); } }