Commit 8513f502 by 111-PC\111

[+]代码规范

1 parent ba4ec619
......@@ -15,7 +15,7 @@ import java.util.List;
* @author zhouhaibao
* @date 2021/5/6 15:19
*/
@FeignClient(name = "${feign.server.name}",url = "${feign.server.url}")
@FeignClient(name = "${smart.feign.server.name}",url = "${smart.feign.server.url}")
public interface SceneClient {
@ResponseBody
......
package cn.com.glsx.consumer.client;
import com.glsx.plat.core.web.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author zhouhaibao
* @date 2021/5/7 14:07
*/
@FeignClient(name = "${smartPlatform.feign.server.name}",url = "${smartPlatform.feign.server.url}")
public interface SmartPlatformClient {
@ResponseBody
@RequestMapping(value = "/device/devices/{device_id}", method = {RequestMethod.GET})
R getDeviceName(@PathVariable("device_id")String deviceId);
}
package cn.com.glsx.consumer.service;
import cn.com.glsx.consumer.client.SceneClient;
import cn.com.glsx.consumer.client.SmartPlatformClient;
import cn.com.glsx.consumer.entity.DeviceVo;
import cn.com.glsx.consumer.utils.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
/**
* @author zhouhaibao
......@@ -23,8 +21,8 @@ public class DeviceService {
@Autowired
private SceneClient sceneClient;
@Value("${getDeviceNameUrl}")
private String getDeviceNameUrl;
@Autowired
private SmartPlatformClient smartPlatformClient;
/**
* 设备绑定
......@@ -47,18 +45,9 @@ public class DeviceService {
}
public String getDeviceName(String devId) {
String name="";
try {
JSONObject jsonObject = HttpUtil.sendGet(getDeviceNameUrl.replace("{device_id}", devId), null, new HashMap<>());
JSONObject message = jsonObject.getJSONObject("message");
if(message!=null){
name = message.getString("name");
}
log.info("设备id{}名称查询结果{}",devId, name);
} catch (Exception e) {
e.printStackTrace();
log.info("设备id{}名称查询结果{}", devId, e.getMessage());
}
return name;
R deviceName = smartPlatformClient.getDeviceName(devId);
String message = deviceName.getMessage();
JSONObject jsonObject = JSONObject.parseObject(message);
return jsonObject.getString("name");
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!