package com.ruoyi.web.controller.conference;

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

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.system.domain.ConferenceRoom;
import com.ruoyi.system.service.IConferenceRoomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会议室Controller
 *
 * @author ruoyi
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/conference")
public class ConferenceRoomController extends BaseController {
    @Autowired
    private IConferenceRoomService conferenceRoomService;

    /**
     * 查询会议室列表
     */
    @PreAuthorize("@ss.hasPermi('system:room:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConferenceRoom conferenceRoom) {
        startPage();
        List<ConferenceRoom> list = conferenceRoomService.selectConferenceRoomList(conferenceRoom);
        return getDataTable(list);
    }

    /**
     * 导出会议室列表
     */
    @PreAuthorize("@ss.hasPermi('system:room:export')")
    @Log(title = "会议室", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConferenceRoom conferenceRoom) {
        List<ConferenceRoom> list = conferenceRoomService.selectConferenceRoomList(conferenceRoom);
        ExcelUtil<ConferenceRoom> util = new ExcelUtil<ConferenceRoom>(ConferenceRoom.class);
        util.exportExcel(response, list, "会议室数据");
    }

    /**
     * 获取会议室详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:room:query')")
    @GetMapping(value = "/{conferenceRoomId}")
    public AjaxResult getInfo(@PathVariable("conferenceRoomId") Long conferenceRoomId) {
        return success(conferenceRoomService.selectConferenceRoomByConferenceRoomId(conferenceRoomId));
    }

    /**
     * 新增会议室
     */
    @PreAuthorize("@ss.hasPermi('system:room:add')")
    @Log(title = "会议室", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConferenceRoom conferenceRoom) {
        return toAjax(conferenceRoomService.insertConferenceRoom(conferenceRoom));
    }

    /**
     * 修改会议室
     */
    @PreAuthorize("@ss.hasPermi('system:room:edit')")
    @Log(title = "会议室", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ConferenceRoom conferenceRoom) {
        return toAjax(conferenceRoomService.updateConferenceRoom(conferenceRoom));
    }

    /**
     * 删除会议室
     */
    @PreAuthorize("@ss.hasPermi('system:room:remove')")
    @Log(title = "会议室", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{conferenceRoomIds}")
    public AjaxResult remove(@PathVariable Long[] conferenceRoomIds) {
        return toAjax(conferenceRoomService.deleteConferenceRoomByConferenceRoomIds(conferenceRoomIds));
    }
}
