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.weighbridge.domain.TblWeightinfo;
import com.ruoyi.weighbridge.service.ITblWeightinfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 称重单Controller
 * 
 * @author liuhj
 * @date 2022-03-10
 */
@RestController
@RequestMapping("/weighbridge/weightInfo")
public class TblWeightinfoController extends BaseController
{
    @Autowired
    private ITblWeightinfoService tblWeightinfoService;

    /**
     * 查询称重单列表
     */
    @PreAuthorize("@ss.hasPermi('weighbridge:weightInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(TblWeightinfo tblWeightinfo)
    {
        startPage();
        List<TblWeightinfo> list = tblWeightinfoService.selectTblWeightinfoList(tblWeightinfo);
        return getDataTable(list);
    }

    /**
     * 根据车牌号查询称重单列表-不分页
     */
    @GetMapping(value = "getWeightInfo/{plateNo}")
    public AjaxResult getWeightInfo(@PathVariable("plateNo") String plateNo)
    {
        List<TblWeightinfo> list = tblWeightinfoService.selectTblWeightinfoByPlateNo(plateNo);
        return AjaxResult.success(list);
    }

    /**
     * 导出称重单列表
     */
    @PreAuthorize("@ss.hasPermi('weighbridge:weightInfo:export')")
    @Log(title = "称重单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TblWeightinfo tblWeightinfo)
    {
        List<TblWeightinfo> list = tblWeightinfoService.selectTblWeightinfoList(tblWeightinfo);
        ExcelUtil<TblWeightinfo> util = new ExcelUtil<TblWeightinfo>(TblWeightinfo.class);
        util.exportExcel(response, list, "称重单数据");
    }

    /**
     * 获取称重单详细信息
     */
    @PreAuthorize("@ss.hasPermi('weighbridge:weightInfo:query')")
    @GetMapping(value = "/{serialNo}")
    public AjaxResult getInfo(@PathVariable("serialNo") String serialNo)
    {
        return AjaxResult.success(tblWeightinfoService.selectTblWeightinfoBySerialNo(serialNo));
    }

    /**
     * 新增称重单
     */
    @PreAuthorize("@ss.hasPermi('weighbridge:weightInfo:add')")
    @Log(title = "称重单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TblWeightinfo tblWeightinfo)
    {
        return toAjax(tblWeightinfoService.insertTblWeightinfo(tblWeightinfo));
    }

    /**
     * 修改称重单
     */
    @PreAuthorize("@ss.hasPermi('weighbridge:weightInfo:edit')")
    @Log(title = "称重单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TblWeightinfo tblWeightinfo)
    {
        return toAjax(tblWeightinfoService.updateTblWeightinfo(tblWeightinfo));
    }

    /**
     * 删除称重单
     */
    @PreAuthorize("@ss.hasPermi('weighbridge:weightInfo:remove')")
    @Log(title = "称重单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{serialNos}")
    public AjaxResult remove(@PathVariable String[] serialNos)
    {
        return toAjax(tblWeightinfoService.deleteTblWeightinfoBySerialNos(serialNos));
    }
}
