package com.pm.web.controller.meeting;

import com.pm.common.config.PageData;
import com.pm.common.core.controller.BaseController;
import com.pm.common.core.domain.AjaxResult;
import com.pm.common.core.page.TableDataInfo;
import com.pm.interfaceInfo.service.InterfaceInfoService;
import com.pm.topology.service.IItemTopologyService;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

/**
 * 会议管理
 */
@RestController
@RequestMapping("/meeting/info")
public class MeetingController  extends BaseController
{

    @Autowired
    private InterfaceInfoService interfaceInfoService;

    //@PreAuthorize("@ss.hasPermi('device:control:list')")
    @GetMapping("/list")
    public String list()
    {
        PageData pd = this.getPageData();
        Response response = null;
        try{
            String name = "";
            String appoint_time = "";
            if (pd.containsKey("search")){
                name = pd.getString("search");
            }
            if (pd.containsKey("appoint_time")){
                appoint_time = pd.getString("appoint_time");
            }
            String info = "{\n" +
                    "  \"date\": \""+pd.getString("date")+"\",\n" +
                    "  \"search\": \""+name+"\",\n" +
                    "  \"locationId\": [],\n" +
                    "  \"capacity\": [],\n" +
                    "  \"deviceType\": [],\n" +
                    "  \"roomType\": [\n" +
                    "    -1\n" +
                    "  ],\n" +
                    "  \"appoint_time\": \""+appoint_time+"\",\n" +
                    "  \"status\": 1,\n" +
                    "  \"page\": "+pd.getInteger("pageNum")+",\n" +
                    "  \"page_size\": "+pd.getInteger("pageSize")+"\n" +
                    "}";
            PageData interface_info = interfaceInfoService.selectInterfaceInfoByName("会议");
            OkHttpClient client = new OkHttpClient().newBuilder()
                    .build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = RequestBody.create(mediaType, info);
            Request request = new Request.Builder()
                    .url(interface_info.getString("url"))
                    .method("POST", body)
                    .addHeader("Content-Type", "application/json")
                    .build();
            response = client.newCall(request).execute();
        } catch (Exception e){
            e.printStackTrace();
        }
        try {
            return response.body().string();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
