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.CarPassGather;
import com.dcsoft.system.vehicle.service.ICarPassGatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 在场记录Controller
 *
 * @author nichun
 * @date 2024-01-08
 */
@RestController
@RequestMapping("/passGather")
public class CarPassGatherController extends BaseController
{
    @Autowired
    private ICarPassGatherService carPassGatherService;

    /**
     * 查询在场记录列表
     */
    @RequiresPermissions("vehicle:passGather:list")
    @GetMapping("/list")
    public TableDataInfo list(CarPassGather carPassGather)
    {
        startPage();
        List<CarPassGather> list = carPassGatherService.selectCarPassGatherList(carPassGather);
        return getDataTable(list);
    }

    /**
     * 导出在场记录列表
     */
    @RequiresPermissions("vehicle:passGather:export")
    @Log(title = "在场记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarPassGather carPassGather)
    {
        List<CarPassGather> list = carPassGatherService.selectCarPassGatherList(carPassGather);
        ExcelUtil<CarPassGather> util = new ExcelUtil<CarPassGather>(CarPassGather.class);
        util.exportExcel(response, list, "在场记录数据");
    }

    /**
     * 获取在场记录详细信息
     */
    @RequiresPermissions("vehicle:passGather:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carPassGatherService.selectCarPassGatherById(id));
    }

    /**
     * 新增在场记录
     */
    @RequiresPermissions("vehicle:passGather:add")
    @Log(title = "在场记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarPassGather carPassGather)
    {
        return toAjax(carPassGatherService.insertCarPassGather(carPassGather));
    }

    /**
     * 修改在场记录
     */
    @RequiresPermissions("vehicle:passGather:edit")
    @Log(title = "在场记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarPassGather carPassGather)
    {
        return toAjax(carPassGatherService.updateCarPassGather(carPassGather));
    }

    /**
     * 删除在场记录
     */
    @RequiresPermissions("vehicle:passGather:remove")
    @Log(title = "在场记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carPassGatherService.deleteCarPassGatherByIds(ids));
    }

    @GetMapping("/parkTop")
    public AjaxResult parkTop(CarPassGather carPassGather)
    {
        List<Map<String,Object>> list = carPassGatherService.parkTop(carPassGather.getParkId());
        return success(list);
    }
}
