package com.ruoyi.weighbridge.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.DibangCar;
import com.ruoyi.weighbridge.service.IDibangCarService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆Controller
 * 
 * @author liuhj
 * @date 2022-03-10
 */
@RestController
@RequestMapping("/weighbridge/dibangCar")
public class DibangCarController extends BaseController
{
    @Autowired
    private IDibangCarService dibangCarService;

    /**
     * 查询车辆列表
     */
    @PreAuthorize("@ss.hasPermi('weighbridge:dibangCar:list')")
    @GetMapping("/list")
    public TableDataInfo list(DibangCar dibangCar)
    {
        startPage();
        List<DibangCar> list = dibangCarService.selectDibangCarList(dibangCar);
        return getDataTable(list);
    }

    /**
     * 导出车辆列表
     */
    @PreAuthorize("@ss.hasPermi('weighbridge:dibangCar:export')")
    @Log(title = "车辆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DibangCar dibangCar)
    {
        List<DibangCar> list = dibangCarService.selectDibangCarList(dibangCar);
        ExcelUtil<DibangCar> util = new ExcelUtil<DibangCar>(DibangCar.class);
        util.exportExcel(response, list, "车辆数据");
    }

    /**
     * 获取车辆详细信息
     */
    @PreAuthorize("@ss.hasPermi('weighbridge:dibangCar:query')")
    @GetMapping(value = "/{carId}")
    public AjaxResult getInfo(@PathVariable("carId") String carId)
    {
        return AjaxResult.success(dibangCarService.selectDibangCarByCarId(carId));
    }

    /**
     * 新增车辆
     */
    @PreAuthorize("@ss.hasPermi('weighbridge:dibangCar:add')")
    @Log(title = "车辆", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DibangCar dibangCar)
    {
        return toAjax(dibangCarService.insertDibangCar(dibangCar));
    }

    /**
     * 修改车辆
     */
    @PreAuthorize("@ss.hasPermi('weighbridge:dibangCar:edit')")
    @Log(title = "车辆", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DibangCar dibangCar)
    {
        return toAjax(dibangCarService.updateDibangCar(dibangCar));
    }

    /**
     * 删除车辆
     */
    @PreAuthorize("@ss.hasPermi('weighbridge:dibangCar:remove')")
    @Log(title = "车辆", businessType = BusinessType.DELETE)
	@DeleteMapping("/{carIds}")
    public AjaxResult remove(@PathVariable String[] carIds)
    {
        return toAjax(dibangCarService.deleteDibangCarByCarIds(carIds));
    }
}
