package com.ruoyi.web.controller.bar;

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

import com.ruoyi.common.core.domain.entity.WyBarUserRole;
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.service.IWyBarUserRoleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 品牌方用户和角色关联Controller
 * 
 * @author ruoyi
 * @date 2025-01-04
 */
@RestController
@RequestMapping("/system/bar/BarRole")
public class WyBarUserRoleController extends BaseController
{
    @Autowired
    private IWyBarUserRoleService wyBarUserRoleService;

    /**
     * 查询品牌方用户和角色关联列表
     */
    @PreAuthorize("@ss.hasPermi('bar:BarRole:list')")
    @GetMapping("/list")
    public TableDataInfo list(WyBarUserRole wyBarUserRole)
    {
        startPage();
        List<WyBarUserRole> list = wyBarUserRoleService.selectWyBarUserRoleList(wyBarUserRole);
        return getDataTable(list);
    }

    /**
     * 导出品牌方用户和角色关联列表
     */
    @PreAuthorize("@ss.hasPermi('bar:BarRole:export')")
    @Log(title = "品牌方用户和角色关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyBarUserRole wyBarUserRole)
    {
        List<WyBarUserRole> list = wyBarUserRoleService.selectWyBarUserRoleList(wyBarUserRole);
        ExcelUtil<WyBarUserRole> util = new ExcelUtil<WyBarUserRole>(WyBarUserRole.class);
        util.exportExcel(response, list, "品牌方用户和角色关联数据");
    }

    /**
     * 获取品牌方用户和角色关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('bar:BarRole:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(wyBarUserRoleService.selectWyBarUserRoleByUserId(userId));
    }

    /**
     * 新增品牌方用户和角色关联
     */
    @PreAuthorize("@ss.hasPermi('bar:BarRole:add')")
    @Log(title = "品牌方用户和角色关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WyBarUserRole wyBarUserRole)
    {
        return toAjax(wyBarUserRoleService.insertWyBarUserRole(wyBarUserRole));
    }

    /**
     * 修改品牌方用户和角色关联
     */
    @PreAuthorize("@ss.hasPermi('bar:BarRole:edit')")
    @Log(title = "品牌方用户和角色关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyBarUserRole wyBarUserRole)
    {
        return toAjax(wyBarUserRoleService.updateWyBarUserRole(wyBarUserRole));
    }

    /**
     * 删除品牌方用户和角色关联
     */
    @PreAuthorize("@ss.hasPermi('bar:BarRole:remove')")
    @Log(title = "品牌方用户和角色关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(wyBarUserRoleService.deleteWyBarUserRoleByUserIds(userIds));
    }
}
