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.Fleet;
import com.phm.manage.service.IFleetService;
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/fleet")
public class FleetController extends BaseController {
    @Autowired
    private IFleetService fleetService;

    /**
     * 查询机队信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:fleet:list')")
    @GetMapping("/list")
    public TableDataInfo list(Fleet fleet) {
        startPage();
        List<Fleet> list = fleetService.selectFleetList(fleet);
        return getDataTable(list);
    }

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

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

    /**
     * 新增机队信息
     */
    @PreAuthorize("@ss.hasPermi('manage:fleet:add')")
    @Log(title = "机队信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Fleet fleet) {
        return toAjax(fleetService.insertFleet(fleet));
    }

    /**
     * 修改机队信息
     */
    @PreAuthorize("@ss.hasPermi('manage:fleet:edit')")
    @Log(title = "机队信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Fleet fleet) {
        return toAjax(fleetService.updateFleet(fleet));
    }

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