package com.ruoyi.app.controller;

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.weighbridge.domain.TblWeightinfo;
import com.ruoyi.weighbridge.service.ITblWeightinfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
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 liuhj
 * @date 2022-03-10
 */
@Api(value = "称重单管理",tags = "称重单管理")
@RestController
@RequestMapping("/app/weightInfo")
public class TblWeightinfoController extends BaseController
{
    @Autowired
    private ITblWeightinfoService tblWeightinfoService;

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

    /**
     * 导出称重单列表
     */
    @ApiOperation("导出称重单列表")
    @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, "称重单数据");
    }

    /**
     * 获取称重单详细信息
     */
    @ApiOperation("获取称重单详细信息")
    @GetMapping(value = "/{serialNo}")
    public AjaxResult getInfo(@PathVariable("serialNo") String serialNo)
    {
        return AjaxResult.success(tblWeightinfoService.selectTblWeightinfoBySerialNo(serialNo));
    }

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

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

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