liuxiaolong
2019-05-06 1043e7be0b7503d7b0f488dc0d8d11a2b8079dee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
    }
}