package com.phm.manage.controller;

import com.phm.common.annotation.Log;
import com.phm.common.core.controller.BaseController;
import com.phm.common.core.domain.AjaxResult;
import com.phm.common.core.page.TableDataInfo;
import com.phm.common.enums.BusinessType;
import com.phm.common.utils.poi.ExcelUtil;
import com.phm.manage.domain.Aeroplane;
import com.phm.manage.service.IAeroplaneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 单机信息Controller
 *
 * @author phm
 * @date 2023-08-22
 */
@RestController
@RequestMapping("/manage/aeroplane")
public class AeroplaneController extends BaseController {
    @Autowired
    private IAeroplaneService aeroplaneService;

    /**
     * 查询单机信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:aeroplane:list')")
    @GetMapping("/list")
    public TableDataInfo list(Aeroplane aeroplane) {
        startPage();
        List<Aeroplane> list = aeroplaneService.selectAeroplaneList(aeroplane);
        return getDataTable(list);
    }

    /**
     * 导出单机信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:aeroplane:export')")
    @Log(title = "单机信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Aeroplane aeroplane) {
        List<Aeroplane> list = aeroplaneService.selectAeroplaneList(aeroplane);
        ExcelUtil<Aeroplane> util = new ExcelUtil<Aeroplane>(Aeroplane.class);
        util.exportExcel(response, list, "单机信息数据");
    }

    /**
     * 获取单机信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:aeroplane:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(aeroplaneService.selectAeroplaneById(id));
    }

    /**
     * 新增单机信息
     */
    @PreAuthorize("@ss.hasPermi('manage:aeroplane:add')")
    @Log(title = "单机信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Aeroplane aeroplane) {
        return toAjax(aeroplaneService.insertAeroplane(aeroplane));
    }

    /**
     * 修改单机信息
     */
    @PreAuthorize("@ss.hasPermi('manage:aeroplane:edit')")
    @Log(title = "单机信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Aeroplane aeroplane) {
        return toAjax(aeroplaneService.updateAeroplane(aeroplane));
    }

    /**
     * 删除单机信息
     */
    @PreAuthorize("@ss.hasPermi('manage:aeroplane:remove')")
    @Log(title = "单机信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(aeroplaneService.deleteAeroplaneByIds(ids));
    }
}
