package com.ruoyi.brewery.controller;

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

import com.ruoyi.brewery.domain.WyGoods;
import com.ruoyi.common.utils.SecurityUtils;
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.WyBreweryTagPrintTemplate;
import com.ruoyi.brewery.service.IWyBreweryTagPrintTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 品牌方标签套打模板Controller
 * 
 * @author ruoyi
 * @date 2025-02-15
 */
@Api(tags = "品牌方标签套打模板管理")
@RestController
@RequestMapping("/brewery/breweryTagPrintTemplate")
public class WyBreweryTagPrintTemplateController extends BaseController
{
    @Autowired
    private IWyBreweryTagPrintTemplateService wyBreweryTagPrintTemplateService;


    /**
     * 查询所有品牌方标签套打模板列表
     */
    @ApiOperation(value = "查询所有品牌方标签套打模板列表", notes = "查询所有品牌方标签套打模板列表")
    @PreAuthorize("@bss.hasPermi('brewery:breweryTagPrintTemplate:allList')")
    @GetMapping("/allList")
    public AjaxResult allList(WyBreweryTagPrintTemplate wyBreweryTagPrintTemplate)
    {
        wyBreweryTagPrintTemplate.setBreweryId(SecurityUtils.getBreweryLoginUser().getBreweryId());
        List<WyBreweryTagPrintTemplate> list = wyBreweryTagPrintTemplateService.selectWyBreweryTagPrintTemplateList(wyBreweryTagPrintTemplate);
        return AjaxResult.success(list);
    }

    /**
     * 查询品牌方标签套打模板列表
     */
    @ApiOperation(value = "查询品牌方标签套打模板列表", notes = "查询品牌方标签套打模板列表")
    @PreAuthorize("@bss.hasPermi('brewery:breweryTagPrintTemplate:list')")
    @GetMapping("/list")
    public TableDataInfo list(WyBreweryTagPrintTemplate wyBreweryTagPrintTemplate)
    {
        wyBreweryTagPrintTemplate.setBreweryId(SecurityUtils.getBreweryLoginUser().getBreweryId());
        startPage();
        List<WyBreweryTagPrintTemplate> list = wyBreweryTagPrintTemplateService.selectWyBreweryTagPrintTemplateList(wyBreweryTagPrintTemplate);
        return getDataTable(list);
    }

    /**
     * 导出品牌方标签套打模板列表
     */
    @ApiOperation(value = "导出品牌方标签套打模板列表", notes = "导出品牌方标签套打模板列表")
    @PreAuthorize("@bss.hasPermi('brewery:breweryTagPrintTemplate:export')")
    @Log(title = "品牌方标签套打模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyBreweryTagPrintTemplate wyBreweryTagPrintTemplate)
    {
        wyBreweryTagPrintTemplate.setBreweryId(SecurityUtils.getBreweryLoginUser().getBreweryId());
        List<WyBreweryTagPrintTemplate> list = wyBreweryTagPrintTemplateService.selectWyBreweryTagPrintTemplateList(wyBreweryTagPrintTemplate);
        ExcelUtil<WyBreweryTagPrintTemplate> util = new ExcelUtil<WyBreweryTagPrintTemplate>(WyBreweryTagPrintTemplate.class);
        util.exportExcel(response, list, "品牌方标签套打模板数据");
    }

    /**
     * 获取品牌方标签套打模板详细信息
     */
    @ApiOperation(value = "获取品牌方标签套打模板详细信息", notes = "获取品牌方标签套打模板详细信息")
    @PreAuthorize("@bss.hasPermi('brewery:breweryTagPrintTemplate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        validate(id);
        return success(wyBreweryTagPrintTemplateService.selectWyBreweryTagPrintTemplateById(id));
    }

    /**
     * 新增品牌方标签套打模板
     */
    @ApiOperation(value = "新增品牌方标签套打模板", notes = "新增品牌方标签套打模板")
    @PreAuthorize("@bss.hasPermi('brewery:breweryTagPrintTemplate:add')")
    @Log(title = "品牌方标签套打模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WyBreweryTagPrintTemplate wyBreweryTagPrintTemplate)
    {
        wyBreweryTagPrintTemplate.setBreweryId(SecurityUtils.getBreweryLoginUser().getBreweryId());
        return toAjax(wyBreweryTagPrintTemplateService.insertWyBreweryTagPrintTemplate(wyBreweryTagPrintTemplate));
    }

    /**
     * 修改品牌方标签套打模板
     */
    @ApiOperation(value = "修改品牌方标签套打模板", notes = "修改品牌方标签套打模板")
    @PreAuthorize("@bss.hasPermi('brewery:breweryTagPrintTemplate:edit')")
    @Log(title = "品牌方标签套打模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyBreweryTagPrintTemplate wyBreweryTagPrintTemplate)
    {
        validate(wyBreweryTagPrintTemplate.getId());
        return toAjax(wyBreweryTagPrintTemplateService.updateWyBreweryTagPrintTemplate(wyBreweryTagPrintTemplate));
    }

    /**
     * 删除品牌方标签套打模板
     */
    @ApiOperation(value = "删除品牌方标签套打模板", notes = "删除品牌方标签套打模板")
    @PreAuthorize("@bss.hasPermi('brewery:breweryTagPrintTemplate:remove')")
    @Log(title = "品牌方标签套打模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        validate(id);
        return toAjax(wyBreweryTagPrintTemplateService.deleteWyBreweryTagPrintTemplateById(id));
    }

    private void validate(Long id) {
        final WyBreweryTagPrintTemplate wyBreweryTagPrintTemplate = wyBreweryTagPrintTemplateService.selectWyBreweryTagPrintTemplateById(id);
        if (wyBreweryTagPrintTemplate == null) {
            throw new IllegalArgumentException("模板不存在");
        }
        if (!SecurityUtils.getBreweryLoginUser().getBreweryId().equals(wyBreweryTagPrintTemplate.getBreweryId())) {
            throw new IllegalArgumentException("只能操作自己的品牌方的模板");
        }
    }
}
