package com.dcsoft.system.vehicle.controller;

import com.dcsoft.common.core.utils.poi.ExcelUtil;
import com.dcsoft.common.core.web.controller.BaseController;
import com.dcsoft.common.core.web.domain.AjaxResult;
import com.dcsoft.common.core.web.page.TableDataInfo;
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.vehicle.domain.CarPassRecord;
import com.dcsoft.system.vehicle.service.ICarPassRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 通行记录Controller
 *
 * @author nichun
 * @date 2024-01-03
 */
@RestController
@RequestMapping("/carPassRecord")
public class CarPassRecordController extends BaseController
{
    @Autowired
    private ICarPassRecordService carPassRecordService;

    /**
     * 查询通行记录列表
     */
    @RequiresPermissions("system:carPassRecord:list")
    @GetMapping("/list")
    public TableDataInfo list(CarPassRecord carPassRecord)
    {
        startPage();
        List<CarPassRecord> list = carPassRecordService.selectCarPassRecordList(carPassRecord);
        return getDataTable(list);
    }

    /**
     * 导出通行记录列表
     */
    @RequiresPermissions("system:carPassRecord:export")
    @Log(title = "通行记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarPassRecord carPassRecord)
    {
        List<CarPassRecord> list = carPassRecordService.selectCarPassRecordList(carPassRecord);
        ExcelUtil<CarPassRecord> util = new ExcelUtil<CarPassRecord>(CarPassRecord.class);
        util.exportExcel(response, list, "通行记录数据");
    }

    /**
     * 获取通行记录详细信息
     */
    @RequiresPermissions("system:carPassRecord:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carPassRecordService.selectCarPassRecordById(id));
    }

    /**
     * 新增通行记录
     */
    @RequiresPermissions("system:carPassRecord:add")
    @Log(title = "通行记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarPassRecord carPassRecord)
    {
        return toAjax(carPassRecordService.insertCarPassRecord(carPassRecord));
    }

    /**
     * 修改通行记录
     */
    @RequiresPermissions("system:carPassRecord:edit")
    @Log(title = "通行记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarPassRecord carPassRecord)
    {
        return toAjax(carPassRecordService.updateCarPassRecord(carPassRecord));
    }

    /**
     * 删除通行记录
     */
    @RequiresPermissions("system:carPassRecord:remove")
    @Log(title = "通行记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carPassRecordService.deleteCarPassRecordByIds(ids));
    }
}
