Commit 99cfdb17 by huangjy

fix:同步更新iot设备名称,todo

parent 41d7fe28
...@@ -14,6 +14,8 @@ import com.makeit.module.iot.vo.ResponseMessage; ...@@ -14,6 +14,8 @@ import com.makeit.module.iot.vo.ResponseMessage;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -49,6 +51,7 @@ public class IotCommonService { ...@@ -49,6 +51,7 @@ public class IotCommonService {
} }
public ResponseMessage sendPatch(String url, HttpRequest request) throws IOException { public ResponseMessage sendPatch(String url, HttpRequest request) throws IOException {
Response response = request.patch(); Response response = request.patch();
ResponseMessage responseMessage = getResponseMessage(url, response); ResponseMessage responseMessage = getResponseMessage(url, response);
return responseMessage; return responseMessage;
} }
......
...@@ -73,15 +73,17 @@ public class IotProductDeviceService extends IotCommonService { ...@@ -73,15 +73,17 @@ public class IotProductDeviceService extends IotCommonService {
} }
@Async @Async
public void syncUpdateDeviceInfo(String id,String name) { public void syncUpdateDeviceInfo(String id, String name, String productId) {
String url = iotUrl + "/device-instance"; String url = iotUrl + "/device-instance";
// 条件可以自己改
Map<String,Object> reqMap = Maps.newHashMap(); Map<String,Object> reqMap = Maps.newHashMap();
reqMap.put("id",id); reqMap.put("id",id);
reqMap.put("name",name); reqMap.put("name",name);
reqMap.put("productId",productId);
String body = JsonUtil.toJson(reqMap); String body = JsonUtil.toJson(reqMap);
HttpRequest request = buildRequest(url, body); HttpRequest request = buildRequest(url, body);
request.encode("UTF-8");
request.contentType("application/json");
try { try {
ResponseMessage responseMessage = sendPatch(url, request); ResponseMessage responseMessage = sendPatch(url, request);
if (responseMessage.getStatus() == 200) { if (responseMessage.getStatus() == 200) {
......
...@@ -128,7 +128,7 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -128,7 +128,7 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
deviceCacheUtil.put(db); deviceCacheUtil.put(db);
iotProductDeviceService.syncUpdateDeviceInfo(db.getOriDeviceId(),dto.getName()); // iotProductDeviceService.syncUpdateDeviceInfo(db.getOriDeviceId(),dto.getName(),db.getProductId());
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment