package org.ts.ddcs.Tool;

import com.alibaba.fastjson.JSONObject;
import org.ts.ddcs.log.LogHelper;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.net.URI;

@Component
public class HttpRest {
    public static  JSONObject  HttpRequest(JSONObject body){
        try {
            RestTemplate restTemplate = new RestTemplate();
            JSONObject result = restTemplate.postForObject(new URI("http://localhost:8805/DataCollectServer/Manage/Command"), body, JSONObject.class);
            if (result != null) {
                if (result.getString("code").equals("0")) {
                    return  result.getJSONObject("respons");
                }
            }
            LogHelper.info("************************  send read command fail !********************************");

        }catch (Exception e){
           LogHelper.error(e);
        }
        return null;
    }


}
