package com.ruoyi.web.controller.brewery;

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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.brewery.domain.WyBeerQrcodeBatch;
import com.ruoyi.brewery.service.IWyBeerQrcodeBatchService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 批次Controller
 * 
 * @author ruoyi
 * @date 2024-12-21
 */
@Api(tags = "批次")
@RestController
@RequestMapping("/system/brewery/batch")
public class WyBeerQrcodeBatchController extends BaseController
{
    @Autowired
    private IWyBeerQrcodeBatchService wyBeerQrcodeBatchService;

    /**
     * 查询批次列表
     */
    @ApiOperation("查询批次列表")
    @PreAuthorize("@ss.hasPermi('brewery:batch:list')")
    @GetMapping("/list")
    public TableDataInfo list(WyBeerQrcodeBatch wyBeerQrcodeBatch)
    {
        startPage();
        List<WyBeerQrcodeBatch> list = wyBeerQrcodeBatchService.selectWyBeerQrcodeBatchList(wyBeerQrcodeBatch);
        return getDataTable(list);
    }

    /**
     * 导出批次列表
     */
    @ApiOperation("导出批次列表")
    @PreAuthorize("@ss.hasPermi('brewery:batch:export')")
    @Log(title = "批次", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyBeerQrcodeBatch wyBeerQrcodeBatch)
    {
        List<WyBeerQrcodeBatch> list = wyBeerQrcodeBatchService.selectWyBeerQrcodeBatchList(wyBeerQrcodeBatch);
        ExcelUtil<WyBeerQrcodeBatch> util = new ExcelUtil<WyBeerQrcodeBatch>(WyBeerQrcodeBatch.class);
        util.exportExcel(response, list, "批次数据");
    }

    /**
     * 获取批次详细信息
     */
    @ApiOperation("获取批次详细信息")
    @PreAuthorize("@ss.hasPermi('brewery:batch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wyBeerQrcodeBatchService.selectWyBeerQrcodeBatchById(id));
    }

    /**
     * 新增批次
     */
    @ApiOperation("新增批次")
    @PreAuthorize("@ss.hasPermi('brewery:batch:add')")
    @Log(title = "批次", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WyBeerQrcodeBatch wyBeerQrcodeBatch)
    {
        return toAjax(wyBeerQrcodeBatchService.insertWyBeerQrcodeBatch(wyBeerQrcodeBatch));
    }

    /**
     * 修改批次
     */
    @ApiOperation("修改批次")
    @PreAuthorize("@ss.hasPermi('brewery:batch:edit')")
    @Log(title = "批次", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyBeerQrcodeBatch wyBeerQrcodeBatch)
    {
        return toAjax(wyBeerQrcodeBatchService.updateWyBeerQrcodeBatch(wyBeerQrcodeBatch));
    }

    /**
     * 删除批次
     */
    @ApiOperation("删除批次")
    @PreAuthorize("@ss.hasPermi('brewery:batch:remove')")
    @Log(title = "批次", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wyBeerQrcodeBatchService.deleteWyBeerQrcodeBatchByIds(ids));
    }
}
