package com.ruoyi.web.controller.bar;

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

import com.ruoyi.web.domain.BarApprovalVO;
import io.swagger.annotations.Api;
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.bar.domain.WyBar;
import com.ruoyi.bar.service.IWyBarService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 酒吧Controller
 * 
 * @author ruoyi
 * @date 2025-01-02
 */
@Api(tags = "酒吧管理")
@RestController
@RequestMapping("/system/bar/bar")
public class WyBarController extends BaseController
{
    @Autowired
    private IWyBarService wyBarService;

    /**
     * 查询酒吧列表
     */
    @PreAuthorize("@ss.hasPermi('system:bar:list')")
    @GetMapping("/list")
    public TableDataInfo list(WyBar wyBar)
    {
        startPage();
        List<WyBar> list = wyBarService.selectWyBarList(wyBar);
        return getDataTable(list);
    }

    /**
     * 导出酒吧列表
     */
    @PreAuthorize("@ss.hasPermi('system:bar:export')")
    @Log(title = "酒吧", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyBar wyBar)
    {
        List<WyBar> list = wyBarService.selectWyBarList(wyBar);
        ExcelUtil<WyBar> util = new ExcelUtil<WyBar>(WyBar.class);
        util.exportExcel(response, list, "酒吧数据");
    }

    /**
     * 获取酒吧详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:bar:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wyBarService.selectWyBarById(id));
    }

    /**
     * 新增酒吧
     */
    @PreAuthorize("@ss.hasPermi('system:bar:add')")
    @Log(title = "酒吧", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WyBar wyBar)
    {
        return toAjax(wyBarService.insertWyBar(wyBar));
    }

    /**
     * 修改酒吧
     */
    @PreAuthorize("@ss.hasPermi('system:bar:edit')")
    @Log(title = "酒吧", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyBar wyBar)
    {
        return toAjax(wyBarService.updateWyBar(wyBar));
    }

    /**
     * 审核酒吧
     */
    @PreAuthorize("@ss.hasPermi('system:bar:approval')")
    @Log(title = "审核酒吧", businessType = BusinessType.UPDATE)
    @PutMapping("/approval")
    public AjaxResult approval(@RequestBody BarApprovalVO barApproval)
    {
        WyBar wyBar = new WyBar();
        wyBar.setId(barApproval.getBarId());
        wyBar.setAuthState(barApproval.getApproval());
        wyBar.setApprovalReason(barApproval.getApprovalReason());
        if (barApproval.getApproval() == 2 && barApproval.getApprovalReason() == null){
            return AjaxResult.error("请填写审核意见");
        }
        return toAjax(wyBarService.approvalWyBar(wyBar));
    }

    /**
     * 删除酒吧
     */
    @PreAuthorize("@ss.hasPermi('system:bar:remove')")
    @Log(title = "酒吧", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wyBarService.deleteWyBarByIds(ids));
    }
}
