package com.srs.web.controller.routine;

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

import com.srs.routine.domain.RtFuRoom;
import com.srs.routine.domain.dto.RtFureservationDto;
import com.srs.routine.domain.vo.RtFuResSoltVo;
import com.srs.routine.domain.vo.RtFuReservationVo;
import com.srs.routine.domain.vo.RtfuRoTimeVo;
import com.srs.routine.domain.vo.RtfuyuyueVo;
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 com.srs.routine.domain.RtFuReservation;
import com.srs.routine.service.IRtFuReservationService;
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/reservation")
@Api(value = "一站式社区模块--功能房预约管理", tags = "一站式社区模块--功能房预约管理")
public class RtFuReservationController extends BaseController {
    @Autowired
    private IRtFuReservationService rtFuReservationService;

    /**
     * 查询功能房预约列表
     */
//@PreAuthorize("@ss.hasPermi('routine:reservation:list')")
@GetMapping("/list")
@ApiOperation("一站式社区模块--功能房预约管理--查询功能房预约列表")
    public TableDataInfo list(RtFuReservation rtFuReservation)
    {
        startPage();
        List<RtFuReservationVo> list = rtFuReservationService.selectRtFuReservationList(rtFuReservation);
        return getDataTable(list);
    }
    /**
     * 查询功能房用户预约列表
     */
//@PreAuthorize("@ss.hasPermi('routine:reservation:list')")
    @GetMapping("/resuser/list")
    @ApiOperation("一站式社区模块--功能房预约管理--查询功能房预约列表(当前用户)")
    public TableDataInfo userlist( RtFuReservation rtFuReservation)
    {
        rtFuReservation.setRtCreatRole(getUsername());
        startPage();
        List<RtFuReservationVo> list = rtFuReservationService.selectRtFuReservationByuser(rtFuReservation);
        return getDataTable(list);
    }
    /**
     * 导出功能房预约列表
     */
//    @PreAuthorize("@ss.hasPermi('routine:reservation:export')")
    @Log(title = "功能房预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("一站式社区模块--功能房预约管理--导出功能房预约列表")
    public void export(HttpServletResponse response, RtFureservationDto rtFureservationDto)
    {
        List<RtFureservationDto> list = rtFuReservationService.getexportrtfu();
        ExcelUtil<RtFureservationDto> util = new ExcelUtil<RtFureservationDto>(RtFureservationDto.class);
        util.exportExcel(response, list, "功能房预约数据");
    }
    /**
     * 获取功能房使用情况
     */
//    @PreAuthorize("@ss.hasPermi('routine:room:query')")
    @GetMapping(value = "/Case/{ro_no}/{rt_Time}")
//    @ApiOperation("一站式社区模块--功能房预约管理--获取功能房使用情况（好像没用到）")
    public AjaxResult getInfoCase(@PathVariable("ro_no") String ro_no ,@PathVariable("rt_Time") String rt_Time)
    {
        RtFuResSoltVo list=rtFuReservationService.seletRtfuCase(ro_no,rt_Time);
        return AjaxResult.success(list);
    }
    @GetMapping(value = "/getroTimeinfo/{roNo}")
    @ApiOperation("一站式社区模块--功能房预约管理--获取功能房使用情况")
    public AjaxResult getroTimeinfo(@PathVariable("roNo") String roNo){
        List<RtfuRoTimeVo> list=rtFuReservationService.getroTimeinfo(roNo);
        return AjaxResult.success(list);
    }


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

    @GetMapping (value ="/{ro_no}/{rt_Time}")
    @ApiOperation("一站式社区模块--功能房预约管理--获取功能房预约的预约时间段和可预约时间段")
        public AjaxResult selectRtFuReservationTime(@PathVariable("ro_no") String ro_no,@PathVariable("rt_Time") String rt_Time){
        RtFuResSoltVo list=rtFuReservationService.selectRtFuReservationTime(ro_no,rt_Time);
            return  AjaxResult.success(list);
    }
    @GetMapping(value = "/getyuyue")
    @ApiOperation("一站式社区模块--功能房预约--预约时间段")
    public AjaxResult getyuyue(RtFuReservation rtFuReservation){
        RtfuyuyueVo list=rtFuReservationService.getyuyue(rtFuReservation);
        return  AjaxResult.success(list);
    }
    /**
     * 新增功能房预约
     */
//    @PreAuthorize("@ss.hasPermi('routine:reservation:add')")
    @Log(title = "功能房预约", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("一站式社区模块--功能房预约管理--新增功能房预约")
    public AjaxResult add(@RequestBody RtFuReservation rtFuReservation)
    {
        rtFuReservation.setRtCreatRole(getUsername());
//        rtFuReservation.setRtDepar(getLoginUser().getUser().getDept().getDeptName());
        rtFuReservation.setRtDepar(getLoginUser().getUser().getDept().getDeptName());
        return rtFuReservationService.insertRtFuReservation(rtFuReservation);
    }

    /**
     * 修改功能房预约
     */
//    @PreAuthorize("@ss.hasPermi('routine:reservation:edit')")
    @Log(title = "功能房预约", businessType = BusinessType.UPDATE)
        @PostMapping("/update")
    @ApiOperation("一站式社区模块--功能房预约管理--修改功能房预约")
    public AjaxResult edit(@RequestBody RtFuReservation rtFuReservation)
    {
        return rtFuReservationService.updateRtFuReservation(rtFuReservation);
    }

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

    @Log(title = "功能房预约", businessType = BusinessType.DELETE)
        @PostMapping("/redele/{re_no}")
    @ApiOperation("一站式社区模块--功能房预约管理--删除功能房和预约信息")
    public AjaxResult remove(@PathVariable String re_no)
    {
        return toAjax(rtFuReservationService.deleteRtFuReservationByreNo(re_no));
    }
}
