package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.dto.FlightTasksVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FlightTasks;
import com.ruoyi.system.service.IFlightTasksService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务Controller
 *
 * @author ruoyi
 * @date 2024-07-24
 */
@RestController
@RequestMapping("/system/tasks")
public class FlightTasksController extends BaseController {
    @Autowired
    private IFlightTasksService flightTasksService;

    /**
     * 查询任务列表
     */
    // @PreAuthorize("@ss.hasPermi('system:tasks:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlightTasks flightTasks) {
        startPage();
        List<FlightTasksVo> list = flightTasksService.selectFlightTasksVoList(flightTasks);
        return getDataTable(list);
    }

    /**
     * 导出任务列表
     */
    // @PreAuthorize("@ss.hasPermi('system:tasks:export')")
    @Log(title = "任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlightTasks flightTasks) {
        List<FlightTasks> list = flightTasksService.selectFlightTasksList(flightTasks);
        ExcelUtil<FlightTasks> util = new ExcelUtil<FlightTasks>(FlightTasks.class);
        util.exportExcel(response, list, "任务数据");
    }

    /**
     * 获取任务详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:tasks:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(flightTasksService.selectFlightTasksById(id));
    }

    /**
     * 新增任务
     */
    // @PreAuthorize("@ss.hasPermi('system:tasks:add')")
    @Log(title = "任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlightTasks flightTasks) {
        return toAjax(flightTasksService.insertFlightTasks(flightTasks));
    }

    /**
     * 修改任务
     */
    // @PreAuthorize("@ss.hasPermi('system:tasks:edit')")
    @Log(title = "任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlightTasks flightTasks) {
        return toAjax(flightTasksService.updateFlightTasks(flightTasks));
    }

    /**
     * 删除任务
     */
    // @PreAuthorize("@ss.hasPermi('system:tasks:remove')")
    @Log(title = "任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(flightTasksService.deleteFlightTasksByIds(ids));
    }
}
