package com.cloud.control.service.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.cloud.common.utils.JsonUtil;
|
import com.cloud.common.utils.RestTemplateUtil;
|
import com.cloud.control.service.DeviceService;
|
import com.cloud.control.utils.EnumStr;
|
import com.cloud.model.common.Result;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.http.MediaType;
|
import org.springframework.stereotype.Service;
|
|
@Slf4j
|
@Service
|
public class DeviceServiceImpl implements DeviceService {
|
|
@Autowired
|
private EnumStr enumStr;
|
|
/**
|
* 通过devId获取节点信息
|
* @param devId
|
* @return
|
*/
|
@Override
|
public JSONObject getNodeByDevId(String devId) {
|
|
String url = "http://" + enumStr.getDeviceServiceUrl()+":" + enumStr.getDeviceServicePort()+
|
"/data/api-d/device/getNodeByDevId";
|
try {
|
JSONObject jsonParam = new JSONObject();
|
jsonParam.put("devId", devId);
|
String resp = RestTemplateUtil.get(url, jsonParam,true);
|
if(StringUtils.isNotEmpty(resp)){
|
Result result = JSONObject.parseObject(resp, Result.class);
|
if(result !=null && result.isSuccess() && result.getData() !=null){
|
return JSONObject.parseObject(result.getData().toString());
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
|
}
|
return null;
|
}
|
}
|