package com.cmvr.web.controller.aima;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cmvr.common.annotation.Log;
import com.cmvr.common.core.controller.BaseController;
import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.common.enums.BusinessType;
import com.cmvr.aima.domain.AimaVehicle;
import com.cmvr.aima.service.IAimaVehicleService;
import com.cmvr.common.utils.poi.ExcelUtil;
import com.cmvr.common.core.page.TableDataInfo;

@RestController
@RequestMapping("/aima/vehicle")
@Api(tags = "爱玛电动车--车辆管理")
public class AimaVehicleController extends BaseController {
    @Autowired
    private IAimaVehicleService aimaVehicleService;

    @ApiOperation("查询车辆列表")
    @PreAuthorize("@ss.hasPermi('aima:vehicle:list')")
    @GetMapping("/list")
    public TableDataInfo list(AimaVehicle aimaVehicle) {
        startPage();
        List<AimaVehicle> list = aimaVehicleService.selectAimaVehicleList(aimaVehicle);
        return getDataTable(list);
    }

    @ApiOperation("导出车辆列表")
    @PreAuthorize("@ss.hasPermi('aima:vehicle:export')")
    @Log(title = "车辆管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AimaVehicle aimaVehicle) {
        List<AimaVehicle> list = aimaVehicleService.selectAimaVehicleList(aimaVehicle);
        ExcelUtil<AimaVehicle> util = new ExcelUtil<>(AimaVehicle.class);
        util.exportExcel(response, list, "车辆数据");
    }

    @ApiOperation("获取车辆详细信息")
    @PreAuthorize("@ss.hasPermi('aima:vehicle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(aimaVehicleService.selectAimaVehicleById(id));
    }

    @ApiOperation("新增车辆")
    @PreAuthorize("@ss.hasPermi('aima:vehicle:add')")
    @Log(title = "车辆管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AimaVehicle aimaVehicle) {
        return toAjax(aimaVehicleService.insertAimaVehicle(aimaVehicle));
    }

    @ApiOperation("修改车辆")
    @PreAuthorize("@ss.hasPermi('aima:vehicle:edit')")
    @Log(title = "车辆管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AimaVehicle aimaVehicle) {
        return toAjax(aimaVehicleService.updateAimaVehicle(aimaVehicle));
    }

    @ApiOperation("删除车辆")
    @PreAuthorize("@ss.hasPermi('aima:vehicle:remove')")
    @Log(title = "车辆管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(aimaVehicleService.deleteAimaVehicleByIds(ids));
    }
}
