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.Missions;
import com.ruoyi.system.service.IMissionsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 无人机任务Controller
 *
 * @author ruoyi
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/system/new/missions")
public class MissionsController extends BaseController
{
    @Autowired
    private IMissionsService missionsService;

    /**
     * 查询无人机任务列表
     */
    // @PreAuthorize("@ss.hasPermi('system:missions:list')")
    @GetMapping("/list")
    public TableDataInfo list(Missions missions)
    {
        startPage();
        List<Missions> list = missionsService.selectMissionsList(missions);
        return getDataTable(list);
    }

    /**
     * 导出无人机任务列表
     */
    // @PreAuthorize("@ss.hasPermi('system:missions:export')")
    @Log(title = "无人机任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Missions missions)
    {
        List<Missions> list = missionsService.selectMissionsList(missions);
        ExcelUtil<Missions> util = new ExcelUtil<Missions>(Missions.class);
        util.exportExcel(response, list, "无人机任务数据");
    }

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

    /**
     * 新增无人机任务
     */
    // @PreAuthorize("@ss.hasPermi('system:missions:add')")
    @Log(title = "无人机任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Missions missions)
    {
        return toAjax(missionsService.insertMissions(missions));
    }

    /**
     * 修改无人机任务
     */
    // @PreAuthorize("@ss.hasPermi('system:missions:edit')")
    @Log(title = "无人机任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Missions missions)
    {
        return toAjax(missionsService.updateMissions(missions));
    }

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