package com.srs.web.controller.staff;

import com.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.core.page.TableDataInfo;
import com.srs.common.enums.BusinessType;
import com.srs.common.utils.SecurityUtils;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.staff.domain.StaffOneStopRoomReservation;
import com.srs.staff.service.IStaffOneStopRoomReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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 chc
 * @date 2024-08-12
 */
@RestController
@RequestMapping("/staff/roomReservation")
@Api(value = "一站式社区-功能房-预约记录管理", tags = "一站式社区-功能房-预约记录管理")
public class StaffOneStopRoomReservationController extends BaseController {
    @Autowired
    private IStaffOneStopRoomReservationService staffOneStopRoomReservationService;

    /**
     * 查询一站式社区-功能房-预约记录列表
     */
    @PreAuthorize("@ss.hasPermi('staff:roomReservation:list')")
    @GetMapping("/list")
    @ApiOperation("查询一站式社区-功能房-预约记录列表")
    public TableDataInfo list(StaffOneStopRoomReservation staffOneStopRoomReservation) {
        startPage();
        List<StaffOneStopRoomReservation> list = staffOneStopRoomReservationService.selectStaffOneStopRoomReservationList(staffOneStopRoomReservation);
        return getDataTable(list);
    }

    /**
     * 查询一站式社区-功能房-预约记录列表
     */
    @PreAuthorize("@ss.hasPermi('staff:roomReservation:list')")
    @GetMapping("/listByUserName")
    @ApiOperation("查询一站式社区-功能房-预约记录列表")
    public TableDataInfo listByUserName(StaffOneStopRoomReservation staffOneStopRoomReservation) {
        startPage();
        staffOneStopRoomReservation.setCreateBy(SecurityUtils.getUsername());
        List<StaffOneStopRoomReservation> list = staffOneStopRoomReservationService.selectStaffOneStopRoomReservationList(staffOneStopRoomReservation);
        return getDataTable(list);
    }

    /**
     * 导出一站式社区-功能房-预约记录列表
     */
    @PreAuthorize("@ss.hasPermi('staff:roomReservation:export')")
    @Log(title = "一站式社区-功能房-预约记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出一站式社区-功能房-预约记录列表")
    public void export(HttpServletResponse response, StaffOneStopRoomReservation staffOneStopRoomReservation) {
        List<StaffOneStopRoomReservation> list = staffOneStopRoomReservationService.selectStaffOneStopRoomReservationList(staffOneStopRoomReservation);
        ExcelUtil<StaffOneStopRoomReservation> util = new ExcelUtil<StaffOneStopRoomReservation>(StaffOneStopRoomReservation.class);
        util.exportExcel(response, list, "一站式社区-功能房-预约记录数据");
    }

    /**
     * 获取一站式社区-功能房-预约记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('staff:roomReservation:query')")
    @GetMapping(value = "/{rtId}")
    @ApiOperation("获取一站式社区-功能房-预约记录详细信息")
    public AjaxResult getInfo(@PathVariable("rtId") Long rtId) {
        return success(staffOneStopRoomReservationService.selectStaffOneStopRoomReservationByRtId(rtId));
    }

    /**
     * 根据时间获取功能房时间段-判断时间段是否被占用
     */
    @PreAuthorize("@ss.hasPermi('staff:roomReservation:query')")
    @GetMapping(value = "/getRoomByRoomNoAndTime")
    @ApiOperation("根据时间获取功能房时间段-判断时间段是否被占用")
    public AjaxResult getRoomByRoomNoAndTime(@ApiParam(value = "功能房编号", required = true) @RequestParam String roomNo, @ApiParam(value = "预约日期（如：2024-08-19）", required = true) @RequestParam String rtTime) {
        return success(staffOneStopRoomReservationService.selectStaffOneStopRoomReservationByRtTime(roomNo, rtTime));
    }

    /**
     * 新增一站式社区-功能房-预约记录
     */
    @PreAuthorize("@ss.hasPermi('staff:roomReservation:add')")
    @Log(title = "一站式社区-功能房-预约记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增一站式社区-功能房-预约记录")
    public AjaxResult add(@RequestBody StaffOneStopRoomReservation staffOneStopRoomReservation) {
        return toAjax(staffOneStopRoomReservationService.insertStaffOneStopRoomReservation(staffOneStopRoomReservation));
    }

    /**
     * 修改一站式社区-功能房-预约记录
     */
    @PreAuthorize("@ss.hasPermi('staff:roomReservation:edit')")
    @Log(title = "一站式社区-功能房-预约记录", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改一站式社区-功能房-预约记录")
    public AjaxResult edit(@RequestBody StaffOneStopRoomReservation staffOneStopRoomReservation) {
        return toAjax(staffOneStopRoomReservationService.updateStaffOneStopRoomReservation(staffOneStopRoomReservation));
    }

    /**
     * 删除一站式社区-功能房-预约记录
     */
    @PreAuthorize("@ss.hasPermi('staff:roomReservation:remove')")
    @Log(title = "一站式社区-功能房-预约记录", businessType = BusinessType.DELETE)
    @PostMapping("/{rtIds}")
    @ApiOperation("删除一站式社区-功能房-预约记录")
    public AjaxResult remove(@PathVariable Long[] rtIds) {
        return toAjax(staffOneStopRoomReservationService.deleteStaffOneStopRoomReservationByRtIds(rtIds));
    }
}
