package com.djhk.uav.uav.controller;


import com.djhk.common.annotation.Log;
import com.djhk.common.core.controller.BaseController;
import com.djhk.common.core.domain.AjaxResult;
import com.djhk.common.core.page.TableDataInfo;
import com.djhk.common.enums.BusinessType;
import com.djhk.common.utils.poi.ExcelUtil;
import com.djhk.uav.uav.model.UavBattery;
import com.djhk.uav.uav.service.IUavBatteryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 运力Controller
 *
 * @author jiachengshuai
 * @date 2023-02-21
 */
@RestController
@RequestMapping("/battery")
public class UavBatteryController extends BaseController
{
    @Autowired
    private IUavBatteryService uavBatteryService;

    /**
     * 查询运力列表
     */
//    @RequiresPermissions("uav:battery:list")
    @GetMapping("/list")
    public TableDataInfo list(UavBattery uavBattery)
    {
        startPage();
        List<UavBattery> list = uavBatteryService.selectUavBatteryList(uavBattery);
        return getDataTable(list);
    }

    /**
     * 导出运力列表
     */
//    @RequiresPermissions("uav:battery:export")
    @Log(title = "运力", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UavBattery uavBattery)
    {
        List<UavBattery> list = uavBatteryService.selectUavBatteryList(uavBattery);
        ExcelUtil<UavBattery> util = new ExcelUtil<UavBattery>(UavBattery.class);
        util.exportExcel(response, list, "运力数据");
    }

    /**
     * 获取运力详细信息
     */
//    @RequiresPermissions("uav:battery:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(uavBatteryService.selectUavBatteryById(id));
    }

    /**
     * 新增运力
     */
//    @RequiresPermissions("uav:battery:add")
    @Log(title = "运力", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UavBattery uavBattery)
    {
        return toAjax(uavBatteryService.insertUavBattery(uavBattery));
    }

    /**
     * 修改运力
     */
//    @RequiresPermissions("uav:battery:edit")
    @Log(title = "运力", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UavBattery uavBattery)
    {
        return toAjax(uavBatteryService.updateUavBattery(uavBattery));
    }

    /**
     * 删除运力
     */
//    @RequiresPermissions("uav:battery:remove")
    @Log(title = "运力", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(uavBatteryService.deleteUavBatteryByIds(ids));
    }
}
