package com.ruoyi.sim.controller;

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

import com.ruoyi.sim.service.impl.SeatService;
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.sim.domain.Seat;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 座Controller
 *
 * @author tom
 * @date 2024-12-13
 */
@RestController
@RequestMapping("/sim/seat")
@Api("座Controller")
public class SeatController extends BaseController {
    @Autowired
    private SeatService seatService;

    /**
     * 查询座列表
     */
    // @PreAuthorize("@ss.hasPermi('sim:seat:list')")
    @GetMapping("/list")
    public TableDataInfo list(Seat seat) {
        startPage();
        List<Seat> list = seatService.selectSeatList(seat);
        return getDataTable(list);
    }

    /**
     * 查询全部座列表
     */
    // @PreAuthorize("@ss.hasPermi('sim:seat:list')")
    @GetMapping("/listAll")
    @ApiOperation("[老师][轮询]查询全部座列表")
    public TableDataInfo listAll() {
        Seat seat = new Seat();
        startPage();
        List<Seat> list = seatService.selectSeatList(seat);
        return getDataTable(list);
    }

    /**
     * 导出座列表
     */
    @PreAuthorize("@ss.hasPermi('sim:seat:export')")
    @Log(title = "座", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Seat seat) {
        List<Seat> list = seatService.selectSeatList(seat);
        ExcelUtil<Seat> util = new ExcelUtil<Seat>(Seat.class);
        util.exportExcel(response, list, "座数据");
    }

    /**
     * 获取座详细信息
     */
    @PreAuthorize("@ss.hasPermi('sim:seat:query')")
    @GetMapping(value = "/{seatId}")
    public AjaxResult getInfo(@PathVariable("seatId") Long seatId) {
        return success(seatService.selectSeatBySeatId(seatId));
    }

    /**
     * 新增座
     */
    @PreAuthorize("@ss.hasPermi('sim:seat:add')")
    @Log(title = "座", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Seat seat) {
        return toAjax(seatService.insertSeat(seat));
    }

    /**
     * 修改座
     */
    @PreAuthorize("@ss.hasPermi('sim:seat:edit')")
    @Log(title = "座", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Seat seat) {
        return toAjax(seatService.updateSeat(seat));
    }

    /**
     * 删除座
     */
    @PreAuthorize("@ss.hasPermi('sim:seat:remove')")
    @Log(title = "座", businessType = BusinessType.DELETE)
    @DeleteMapping("/{seatIds}")
    public AjaxResult remove(@PathVariable Long[] seatIds) {
        return toAjax(seatService.deleteSeatBySeatIds(seatIds));
    }
}
