package com.ics.controller.mobile.meeting;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ics.admin.domain.BuildingDetail;
import com.ics.admin.domain.Customer;
import com.ics.admin.domain.Park;
import com.ics.admin.domain.Room;
import com.ics.admin.domain.meeting.*;
import com.ics.admin.domain.meeting.vo.MeetingAmountVo;
import com.ics.admin.domain.meeting.vo.UserCustomerVo;
import com.ics.admin.mapper.meeting.RoomContentMapper;
import com.ics.admin.mapper.meeting.RoomEquipmentMapper;
import com.ics.admin.service.*;
import com.ics.admin.service.meeting.*;
import com.ics.common.core.controller.BaseController;
import com.ics.common.core.domain.IcsCustomerStaff;
import com.ics.common.core.domain.R;
import com.ics.common.core.page.PageDomain;
import com.ics.common.core.page.TableSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wf.jwtp.annotation.Ignore;
import org.wf.jwtp.annotation.RequiresPermissions;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/api/room")
public class ApiRoomController extends BaseController {

    @Autowired
    private IRoomContentService roomContentService;


    @Autowired
    private ICustomerTicketService customerTicketService;

    @Autowired
    private IReservationService reservationService;

    @Autowired
    private IReservationPersonService reservationPersonService;

    @Autowired
    private ICustomerService customerService;

    @Autowired
    private RoomContentMapper roomContentMapper;

    @Autowired
    private IRoomService roomService;

    @Autowired
    private IBuildingDetailService buildingDetailService;

    @Autowired
    private IIcsCustomerStaffService customerStaffService;

    @Autowired
    private ITicketService ticketService;

    @Autowired
    private IParkService parkService;

    @Autowired
    private IRoomEquipmentService roomEquipmentService;


    /**
     * 获取房间内容
     */
    @Ignore
    @PostMapping("list")
    public R list(@RequestBody HashMap<String,Long> map) {
        Long parkId = map.get("parkId");
        RoomContent roomContent1 = new RoomContent();
        if (parkId != null){
            roomContent1.setParkId(parkId);
        }
        List<RoomContent> roomContents = roomContentService.selectApiRoomList(roomContent1);
        for (RoomContent roomContent : roomContents) {
            RoomEquipment roomEquipment = roomEquipmentService.selectRoomId(roomContent.getRoomId());
            if (null != roomEquipment){
                roomContent.setEquipmentId(roomEquipment.getEquipmentId());
            }
            Long roomId = roomContent.getRoomId();
            Room room = roomService.selectRoomById(roomId);
            if (room != null){
                roomContent.setRoomName(room.getName());
                BuildingDetail buildingDetail = buildingDetailService.selectBuildingDetailById(room.getBuildingId());
                if (buildingDetail != null) {
                    roomContent.setBuildingName(buildingDetail.getFloorName());
                }
            }

        }
        return R.data(roomContents);
    }

    /**
     * 查询今日的会议和正常进行的会议
     */
    @Ignore
    @PostMapping("todayMeeting")
    public R todayMeeting(@RequestBody RoomContent roomContent) {
        List<Reservation> roomContents=roomContentService.todayMeeting(roomContent);
        return R.data(roomContents);
    }


    /**
     * 查询所有的园区
     */
    @Ignore
    @GetMapping("selectParkList")
    public R selectParkList(Long tenantId) {
        Park park = new Park();
        List<Park> parkList = parkService.selectParkList(park);
        return R.data(parkList);
    }

    /**
     * 查询企业
     */
    @Ignore
    @PostMapping ("selectCustomerListByParkId")
    public R selectCustomerList(@RequestBody HashMap<String,Long> map) {
        Long parkId = map.get("parkId");
        Customer customer1 = new Customer();
        customer1.setParkId(parkId);
        return R.data(customerService.selectCustomerList(customer1));
    }


    /**
     * 查询企业
     */
    @Ignore
    @PostMapping ("selectCustomerList")
    public R selectCustomerList(@RequestBody RoomContent roomContent) {

        Customer customer = customerService.selectCustomerById(roomContent.getCustomerId());
        return R.data(customer);
    }
}


