package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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.OneClickTakeoff;
import com.ruoyi.system.service.IOneClickTakeoffService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 一键起飞Controller
 *
 * @author ruoyi
 * @date 2024-08-09
 */
@RestController
@RequestMapping("/system/takeoff")
public class OneClickTakeoffController extends BaseController
{
    @Autowired
    private IOneClickTakeoffService oneClickTakeoffService;

    /**
     * 查询一键起飞列表
     */
    // @PreAuthorize("@ss.hasPermi('system:takeoff:list')")
    @GetMapping("/list")
    public TableDataInfo list(OneClickTakeoff oneClickTakeoff)
    {
        startPage();
        List<OneClickTakeoff> list = oneClickTakeoffService.selectOneClickTakeoffList(oneClickTakeoff);
        return getDataTable(list);
    }

    /**
     * 导出一键起飞列表
     */
    // @PreAuthorize("@ss.hasPermi('system:takeoff:export')")
    @Log(title = "一键起飞", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OneClickTakeoff oneClickTakeoff)
    {
        List<OneClickTakeoff> list = oneClickTakeoffService.selectOneClickTakeoffList(oneClickTakeoff);
        ExcelUtil<OneClickTakeoff> util = new ExcelUtil<OneClickTakeoff>(OneClickTakeoff.class);
        util.exportExcel(response, list, "一键起飞数据");
    }

    /**
     * 获取一键起飞详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:takeoff:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(oneClickTakeoffService.selectOneClickTakeoffById(id));
    }

    /**
     * 新增一键起飞
     */
    // @PreAuthorize("@ss.hasPermi('system:takeoff:add')")
    @Log(title = "一键起飞", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OneClickTakeoff oneClickTakeoff)
    {
        return toAjax(oneClickTakeoffService.insertOneClickTakeoff(oneClickTakeoff));
    }

    /**
     * 修改一键起飞
     */
    // @PreAuthorize("@ss.hasPermi('system:takeoff:edit')")
    @Log(title = "一键起飞", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OneClickTakeoff oneClickTakeoff)
    {
        return toAjax(oneClickTakeoffService.updateOneClickTakeoff(oneClickTakeoff));
    }

    /**
     * 删除一键起飞
     */
    // @PreAuthorize("@ss.hasPermi('system:takeoff:remove')")
    @Log(title = "一键起飞", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(oneClickTakeoffService.deleteOneClickTakeoffByIds(ids));
    }
}
