package com.dcsoft.system.car.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.dcsoft.common.log.annotation.Log;
import com.dcsoft.common.log.enums.BusinessType;
import com.dcsoft.common.security.annotation.RequiresPermissions;
import com.dcsoft.system.car.domain.TbCar;
import com.dcsoft.system.car.service.ITbCarService;
import com.dcsoft.common.core.web.controller.BaseController;
import com.dcsoft.common.core.web.domain.AjaxResult;
import com.dcsoft.common.core.utils.poi.ExcelUtil;
import com.dcsoft.common.core.web.page.TableDataInfo;

/**
 * 车辆信息Controller
 *
 * @author nichun
 * @date 2023-07-24
 */
@RestController
@RequestMapping("/car")
public class TbCarController extends BaseController
{
    @Autowired
    private ITbCarService tbCarService;

    /**
     * 查询车辆信息列表
     */
    @RequiresPermissions("system:car:list")
    @GetMapping("/list")
    public TableDataInfo list(TbCar tbCar)
    {
        startPage();
        List<TbCar> list = tbCarService.selectTbCarList(tbCar);
        return getDataTable(list);
    }

    /**
     * 导出车辆信息列表
     */
    @RequiresPermissions("system:car:export")
    @Log(title = "车辆信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCar tbCar)
    {
        List<TbCar> list = tbCarService.selectTbCarList(tbCar);
        ExcelUtil<TbCar> util = new ExcelUtil<TbCar>(TbCar.class);
        util.exportExcel(response, list, "车辆信息数据");
    }

    /**
     * 获取车辆信息详细信息
     */
    @RequiresPermissions("system:car:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbCarService.selectTbCarById(id));
    }

    /**
     * 新增车辆信息
     */
    @RequiresPermissions("system:car:add")
    @Log(title = "车辆信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCar tbCar)
    {
        return toAjax(tbCarService.insertTbCar(tbCar));
    }

    /**
     * 修改车辆信息
     */
    @RequiresPermissions("system:car:edit")
    @Log(title = "车辆信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCar tbCar)
    {
        return toAjax(tbCarService.updateTbCar(tbCar));
    }

    /**
     * 删除车辆信息
     */
    @RequiresPermissions("system:car:remove")
    @Log(title = "车辆信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCarService.deleteTbCarByIds(ids));
    }

    /**
     * 车辆数据统计
     * @return
     */
    @Log(title = "车辆数据统计", businessType = BusinessType.DELETE)
    @PostMapping("/queryCarCount")
    public AjaxResult queryCarCount()
    {
        return success(tbCarService.queryCarCount());
    }

}
