package com.ruoyi.web.bst;

import com.ruoyi.bst.team.domain.Team;
import com.ruoyi.bst.team.domain.TeamQuery;
import com.ruoyi.bst.team.domain.TeamVO;
import com.ruoyi.bst.team.service.TeamService;
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/team")
public class TeamController extends BaseController
{
    @Autowired
    private TeamService teamService;

    /**
     * 查询拼桌列表
     */
    @PreAuthorize("@ss.hasPermi('bst:team:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeamQuery query)
    {
        startPage();
        startOrderBy();
        List<TeamVO> list = teamService.selectTeamList(query);
        return getDataTable(list);
    }

    /**
     * 导出拼桌列表
     */
    @PreAuthorize("@ss.hasPermi('bst:team:export')")
    @Log(title = "拼桌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeamQuery query)
    {
        List<TeamVO> list = teamService.selectTeamList(query);
        ExcelUtil<TeamVO> util = new ExcelUtil<TeamVO>(TeamVO.class);
        util.exportExcel(response, list, "拼桌数据");
    }

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

    /**
     * 新增拼桌
     */
    @PreAuthorize("@ss.hasPermi('bst:team:add')")
    @Log(title = "拼桌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Team team)
    {
        return toAjax(teamService.insertTeam(team));
    }

    /**
     * 修改拼桌
     */
    @PreAuthorize("@ss.hasPermi('bst:team:edit')")
    @Log(title = "拼桌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Team team)
    {
        return toAjax(teamService.updateTeam(team));
    }

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