package com.srs.web.controller.routine;

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

import com.srs.routine.domain.RtFuReservation;
import com.srs.routine.domain.vo.RtFuResSoltVo;
import com.srs.routine.domain.vo.RtFuRoomVo;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;

import com.srs.routine.domain.RtFuRoom;
import com.srs.routine.service.IRtFuRoomService;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.enums.BusinessType;
import com.srs.common.annotation.Log;
import com.srs.common.core.page.TableDataInfo;

/**
 * 功能房Controller
 *
 * @author srs
 * @date 2024-07-12
 */
@RestController
@RequestMapping("/routine/room")
@Api(value = "一站式社区模块-功能房管理", tags = "一站式社区模块-功能房管理")
public class RtFuRoomController extends BaseController {
    @Autowired
    private IRtFuRoomService rtFuRoomService;

    /**
     * 查询功能房列表
     */
//@PreAuthorize("@ss.hasPermi('routine:room:list')")
//@GetMapping("/list")
//@ApiOperation("一站式社区模块-功能房管理-查询功能房列表")
//    public TableDataInfo list(RtFuRoom rtFuRoom)
//    {
//        startPage();
//        List<RtFuRoom> list = rtFuRoomService.selectRtFuRoomList(rtFuRoom);
//        return getDataTable(list);
//    }

    @GetMapping("/list")
    @ApiOperation("一站式社区模块-功能房管理-查询功能房列表")
    public TableDataInfo listVo(RtFuRoomVo rtFuRoomVo)
    {
        startPage();
        List<RtFuRoomVo> list = rtFuRoomService.selectRtFuRoomListVo(rtFuRoomVo);
        return getDataTable(list);
    }
    /**
     * 导出功能房列表
     */
//    @PreAuthorize("@ss.hasPermi('routine:room:export')")
    @Log(title = "功能房", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("一站式社区模块-功能房管理-导出功能房列表")
    public void export(HttpServletResponse response, RtFuRoom rtFuRoom)
    {
        List<RtFuRoom> list = rtFuRoomService.selectRtFuRoomList(rtFuRoom);
        ExcelUtil<RtFuRoom> util = new ExcelUtil<RtFuRoom>(RtFuRoom.class);
        util.exportExcel(response, list, "功能房数据");
    }

    /**
     * 获取功能房详细信息
     */
//    @PreAuthorize("@ss.hasPermi('routine:room:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("一站式社区模块-功能房管理-获取功能房详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        RtFuRoomVo list=rtFuRoomService.selectRtFuRoomById(id);
        return AjaxResult.success(list);
    }


    /**
     * 获取功能房预约详细信息
     */
//    @PreAuthorize("@ss.hasPermi('routine:room:name:query')")
    @GetMapping(value = "/names/{room_name}")
//    @ApiOperation("一站式社区模块-功能房管理--获取功能房预约信息")
    public AjaxResult getroominfo(@PathVariable("room_name") String room_name){
        List<RtFuRoomVo> list=rtFuRoomService.selectRtFuRoomByroom(room_name);
        return AjaxResult.success(list);
    }

//    @PreAuthorize("@ss.hasPermi('routine:room:name:query')")
    @GetMapping(value = "/name/{ro_no}")
    @ApiOperation("一站式社区模块-功能房管理--功能房的信息")
    public AjaxResult getroomsolt(@PathVariable("ro_no") String ro_no){
        RtFuResSoltVo list=rtFuRoomService.selectRtFuRoomByRoNo(ro_no);
        return AjaxResult.success(list);
    }

    /**
     * 新增功能房
     */
//    @PreAuthorize("@ss.hasPermi('routine:room:add')")
    @Log(title = "功能房", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("一站式社区模块-功能房管理-新增功能房")
    public AjaxResult add(@RequestBody RtFuRoom rtFuRoom)
    {
        rtFuRoom.setRoomUser(getUsername());
        rtFuRoom.setRoomDepar(getLoginUser().getUser().getDept().getDeptName());
        return rtFuRoomService.insertRtFuRoom(rtFuRoom);
    }

    /**
     * 修改功能房
     */
//    @PreAuthorize("@ss.hasPermi('routine:room:edit')")
    @Log(title = "功能房", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("一站式社区模块-功能房管理-修改功能房")
    public AjaxResult edit(@RequestBody RtFuRoom rtFuRoom)
    {
        rtFuRoom.setRoomUpuser(getUsername());
        return rtFuRoomService.updateRtFuRoom(rtFuRoom);
    }

    @Log(title = "功能房", businessType = BusinessType.UPDATE)
        @PostMapping("/changeStatus/update")
    @ApiOperation("一站式社区模块-功能房管理-修改功能房状态")
    public AjaxResult editsta(@RequestBody RtFuRoom rtFuRoom)
    {
        rtFuRoom.setRoomUpuser(getUsername());
        return rtFuRoomService.updateRtfuSta(rtFuRoom);
    }

    /**
     * 删除功能房
     */
//    @PreAuthorize("@ss.hasPermi('routine:room:remove')")
    @Log(title = "功能房", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("一站式社区模块-功能房管理-删除功能房")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rtFuRoomService.deleteRtFuRoomByIds(ids));
    }
}
