package com.ruoyi.web.controller.visitor;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.visitor.VisitorRecords;
import com.ruoyi.system.service.IVisitorRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 访客车辆登记Controller
 *
 * @author boman
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/wuYe/visitorRecords")
public class VisitorRecordsController extends BaseController
{
    @Autowired
    private IVisitorRecordsService visitorRecordsService;

/**
 * 查询访客车辆登记列表
 */
@PreAuthorize("@ss.hasPermi('wuYe:visitorRecords:list')")
@GetMapping("/list")
    public TableDataInfo list(VisitorRecords visitorRecords)
    {
        startPage();
        List<VisitorRecords> list = visitorRecordsService.selectVisitorRecordsList(visitorRecords);
        return getDataTable(list);
    }

    /**
     * 导出访客车辆登记列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:visitorRecords:export')")
    @Log(title = "访客车辆登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VisitorRecords visitorRecords)
    {
        List<VisitorRecords> list = visitorRecordsService.selectVisitorRecordsList(visitorRecords);
        ExcelUtil<VisitorRecords> util = new ExcelUtil<VisitorRecords>(VisitorRecords.class);
        util.exportExcel(response, list, "访客车辆登记数据");
    }

    /**
     * 获取访客车辆登记详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:visitorRecords:query')")
    @GetMapping(value = "/{visitorRecordsId}")
    public AjaxResult getInfo(@PathVariable("visitorRecordsId") Long visitorRecordsId)
    {
        return success(visitorRecordsService.selectVisitorRecordsByVisitorRecordsId(visitorRecordsId));
    }

    /**
     * 新增访客车辆登记
     */
    @PreAuthorize("@ss.hasPermi('wuYe:visitorRecords:add')")
    @Log(title = "访客车辆登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VisitorRecords visitorRecords)
    {
        return toAjax(visitorRecordsService.insertVisitorRecords(visitorRecords));
    }

    /**
     * 修改访客车辆登记
     */
    @PreAuthorize("@ss.hasPermi('wuYe:visitorRecords:edit')")
    @Log(title = "访客车辆登记", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody VisitorRecords visitorRecords)
    {
        return toAjax(visitorRecordsService.updateVisitorRecords(visitorRecords));
    }

    /**
     * 删除访客车辆登记
     */
    @PreAuthorize("@ss.hasPermi('wuYe:visitorRecords:remove')")
    @Log(title = "访客车辆登记", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{visitorRecordsIds}")
    public AjaxResult remove(@PathVariable Long[] visitorRecordsIds)
    {
        return toAjax(visitorRecordsService.deleteVisitorRecordsByVisitorRecordsIds(visitorRecordsIds));
    }
}
