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

/**
 * 会议室预约Controller
 *
 * @author ruoyi
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/conferenceOrder")
public class ConferenceRoomOrderController extends BaseController {
    @Autowired
    private IConferenceRoomOrderService conferenceRoomOrderService;

    /**
     * 查询会议室预约列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConferenceRoomOrder conferenceRoomOrder) {
        startPage();
        List<ConferenceRoomOrder> list = conferenceRoomOrderService.selectConferenceRoomOrderList(conferenceRoomOrder);
        return getDataTable(list);
    }

    /**
     * 导出会议室预约列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "会议室预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConferenceRoomOrder conferenceRoomOrder) {
        List<ConferenceRoomOrder> list = conferenceRoomOrderService.selectConferenceRoomOrderList(conferenceRoomOrder);
        ExcelUtil<ConferenceRoomOrder> util = new ExcelUtil<ConferenceRoomOrder>(ConferenceRoomOrder.class);
        util.exportExcel(response, list, "会议室预约数据");
    }

    /**
     * 获取会议室预约详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{conferenceRoomOrderId}")
    public AjaxResult getInfo(@PathVariable("conferenceRoomOrderId") Long conferenceRoomOrderId) {
        return success(conferenceRoomOrderService.selectConferenceRoomOrderByConferenceRoomOrderId(conferenceRoomOrderId));
    }

    /**
     * 新增会议室预约
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "会议室预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConferenceRoomOrder conferenceRoomOrder) {
        return conferenceRoomOrderService.insertConferenceRoomOrder(conferenceRoomOrder);
    }

    /**
     * 修改会议室预约
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "会议室预约", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ConferenceRoomOrder conferenceRoomOrder) {
        return toAjax(conferenceRoomOrderService.updateConferenceRoomOrder(conferenceRoomOrder));
    }

    /**
     * 删除会议室预约
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "会议室预约", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{conferenceRoomOrderIds}")
    public AjaxResult remove(@PathVariable Long[] conferenceRoomOrderIds) {
        return toAjax(conferenceRoomOrderService.deleteConferenceRoomOrderByConferenceRoomOrderIds(conferenceRoomOrderIds));
    }
}
