package com.ruoyi.web.bst;

import com.ruoyi.bst.teamUser.domain.TeamUser;
import com.ruoyi.bst.teamUser.domain.TeamUserQuery;
import com.ruoyi.bst.teamUser.domain.TeamUserVO;
import com.ruoyi.bst.teamUser.service.TeamUserService;
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 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 ruoyi
 * @date 2025-05-22
 */
@RestController
@RequestMapping("/bst/teamUser")
public class TeamUserController extends BaseController
{
    @Autowired
    private TeamUserService teamUserService;

    /**
     * 查询拼桌用户列表
     */
    @PreAuthorize("@ss.hasPermi('bst:teamUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeamUserQuery query)
    {
        startPage();
        startOrderBy();
        List<TeamUserVO> list = teamUserService.selectTeamUserList(query);
        return getDataTable(list);
    }

    /**
     * 导出拼桌用户列表
     */
    @PreAuthorize("@ss.hasPermi('bst:teamUser:export')")
    @Log(title = "拼桌用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeamUserQuery query)
    {
        List<TeamUserVO> list = teamUserService.selectTeamUserList(query);
        ExcelUtil<TeamUserVO> util = new ExcelUtil<TeamUserVO>(TeamUserVO.class);
        util.exportExcel(response, list, "拼桌用户数据");
    }

    /**
     * 获取拼桌用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:teamUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(teamUserService.selectTeamUserById(id));
    }

    /**
     * 新增拼桌用户
     */
    @PreAuthorize("@ss.hasPermi('bst:teamUser:add')")
    @Log(title = "拼桌用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeamUser teamUser)
    {
        return toAjax(teamUserService.insertTeamUser(teamUser));
    }

    /**
     * 修改拼桌用户
     */
    @PreAuthorize("@ss.hasPermi('bst:teamUser:edit')")
    @Log(title = "拼桌用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeamUser teamUser)
    {
        return toAjax(teamUserService.updateTeamUser(teamUser));
    }

    /**
     * 删除拼桌用户
     */
    @PreAuthorize("@ss.hasPermi('bst:teamUser:remove')")
    @Log(title = "拼桌用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(teamUserService.deleteTeamUserByIds(ids));
    }
}
