package com.ruoyi.system.controller;

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

import com.ruoyi.system.dto.DroneMissionsVo;
import com.ruoyi.system.dto.MissionsDto;
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.DroneMissions;
import com.ruoyi.system.service.IDroneMissionsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 无人机任务Controller
 *
 * @author ruoyi
 * @date 2024-07-24
 */
@RestController
@RequestMapping("/system/missions")
public class DroneMissionsController extends BaseController {
    @Autowired
    private IDroneMissionsService droneMissionsService;

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

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

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

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

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

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

}
