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.TbCarRecord;
import com.dcsoft.system.car.service.ITbCarRecordService;
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-26
 */
@RestController
@RequestMapping("/carRecord")
public class TbCarRecordController extends BaseController
{
    @Autowired
    private ITbCarRecordService tbCarRecordService;

    /**
     * 查询车辆通行记录列表
     */
    @RequiresPermissions("car:carRecord:list")
    @GetMapping("/list")
    public TableDataInfo list(TbCarRecord tbCarRecord)
    {
        startPage();
        List<TbCarRecord> list = tbCarRecordService.selectTbCarRecordList(tbCarRecord);
        return getDataTable(list);
    }

    /**
     * 导出车辆通行记录列表
     */
    @RequiresPermissions("car:carRecord:export")
    @Log(title = "车辆通行记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCarRecord tbCarRecord)
    {
        List<TbCarRecord> list = tbCarRecordService.selectTbCarRecordList(tbCarRecord);
        ExcelUtil<TbCarRecord> util = new ExcelUtil<TbCarRecord>(TbCarRecord.class);
        util.exportExcel(response, list, "车辆通行记录数据");
    }

    /**
     * 获取车辆通行记录详细信息
     */
    @RequiresPermissions("car:carRecord:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbCarRecordService.selectTbCarRecordById(id));
    }

    /**
     * 新增车辆通行记录
     */
    @RequiresPermissions("car:carRecord:add")
    @Log(title = "车辆通行记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCarRecord tbCarRecord)
    {
        return toAjax(tbCarRecordService.insertTbCarRecord(tbCarRecord));
    }

    /**
     * 修改车辆通行记录
     */
    @RequiresPermissions("car:carRecord:edit")
    @Log(title = "车辆通行记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCarRecord tbCarRecord)
    {
        return toAjax(tbCarRecordService.updateTbCarRecord(tbCarRecord));
    }

    /**
     * 删除车辆通行记录
     */
    @RequiresPermissions("car:carRecord:remove")
    @Log(title = "车辆通行记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCarRecordService.deleteTbCarRecordByIds(ids));
    }
}
