package com.jeeplus.business.meetingRoom.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.business.meetingRoom.domain.MeetingRoom;
import com.jeeplus.business.meetingRoom.service.MeetingRoomService;
import com.jeeplus.business.meetingRoom.service.dto.MeetingRoomDTO;
import com.jeeplus.common.utils.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

@Slf4j
@Api(tags ="嘉溢会议室预约")
@RestController
@RequestMapping(value = "/meetingRoom")
public class MeetingRoomController {

    @Autowired
    private MeetingRoomService meetingRoomService;


    /**
     * 会议室列表
     */
    @ApiOperation(value = "会议室列表")
    @GetMapping(value = "/list")
    public ResponseEntity<IPage<MeetingRoom>> findPageList(MeetingRoom meetingRoom, Page<MeetingRoom> page) throws Exception {
       IPage<MeetingRoom> iPage= meetingRoomService.findPageList(meetingRoom,page);
       return ResponseEntity.ok(iPage);
    }


    /**
     * 会议室添加/修改
     */
    @ApiOperation(value = "会议室添加/修改")
    @PostMapping(value = "/saveForm")
    public ResponseEntity saveForm(@RequestBody MeetingRoomDTO meetingRoomDTO){
        String id=meetingRoomService.saveForm(meetingRoomDTO);
        return ResponseUtil.newInstance().add("businessTable","jy_meeting_room").add("businessId",id).ok("操作成功");
    }

    /**
     * 根据id查询会议室信息
     */
    @ApiOperation(value = "根据id查询会议室信息")
    @GetMapping(value = "/findById")
    public ResponseEntity<MeetingRoomDTO> findById(@RequestParam String id){
        MeetingRoomDTO roomDTO=meetingRoomService.findById(id);
        return ResponseEntity.ok(roomDTO);
    }

    /**
     * 根据id修改状态status
     * @param
     */
    @ApiOperation(value = "根据id修改状态status")
    @PostMapping(value = "/updateStatusById")
    public void updateStatusById(String id,String status) {
        meetingRoomService.updateStatusById(id,status);
    }

    /**
     * 根据会议开始时间查询最近结束的会议时间
     */
    @ApiOperation(value = "根据会议开始时间查询最近结束的会议时间")
    @GetMapping(value = "/checkTime")
    public Boolean checkTime(@RequestParam String startTime) throws ParseException {
        Boolean check=meetingRoomService.checkTime(startTime);
        return check;
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id删除")
    @GetMapping(value = "/deleteById")
    public ResponseEntity<String> deleteById(@RequestParam String id){
        String s = meetingRoomService.deleteById(id);
        return ResponseEntity.ok(s);
    }







}
