|
@@ -10,6 +10,7 @@ import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
|
|
|
+// TODO @haohao:类注释,写一下,比较好
|
|
|
@Slf4j
|
|
|
public class DeviceDataApiClient implements DeviceDataApi {
|
|
|
|
|
@@ -17,32 +18,32 @@ public class DeviceDataApiClient implements DeviceDataApi {
|
|
|
private final String deviceDataUrl;
|
|
|
|
|
|
// 可以通过构造器把 RestTemplate 和 baseUrl 注入进来
|
|
|
+ // TODO @haohao:可以用 lombok 简化
|
|
|
public DeviceDataApiClient(RestTemplate restTemplate, String deviceDataUrl) {
|
|
|
this.restTemplate = restTemplate;
|
|
|
this.deviceDataUrl = deviceDataUrl;
|
|
|
}
|
|
|
|
|
|
+ // TODO @haohao:返回结果,不用 CommonResult 哈。
|
|
|
@Override
|
|
|
public CommonResult<Boolean> updateDeviceStatus(IotDeviceStatusUpdateReqDTO updateReqDTO) {
|
|
|
- // 示例:如果对应的远程地址是 /rpc-api/iot/device-data/update-status
|
|
|
String url = deviceDataUrl + "/rpc-api/iot/device-data/update-status";
|
|
|
return doPost(url, updateReqDTO, "updateDeviceStatus");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public CommonResult<Boolean> reportDeviceEventData(IotDeviceEventReportReqDTO reportReqDTO) {
|
|
|
- // 示例:如果对应的远程地址是 /rpc-api/iot/device-data/report-event
|
|
|
String url = deviceDataUrl + "/rpc-api/iot/device-data/report-event";
|
|
|
return doPost(url, reportReqDTO, "reportDeviceEventData");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public CommonResult<Boolean> reportDevicePropertyData(IotDevicePropertyReportReqDTO reportReqDTO) {
|
|
|
- // 示例:如果对应的远程地址是 /rpc-api/iot/device-data/report-property
|
|
|
String url = deviceDataUrl + "/rpc-api/iot/device-data/report-property";
|
|
|
return doPost(url, reportReqDTO, "reportDevicePropertyData");
|
|
|
}
|
|
|
|
|
|
+ // TODO @haohao:未来可能有 get 类型哈
|
|
|
/**
|
|
|
* 将与远程服务交互的通用逻辑抽取成一个私有方法
|
|
|
*/
|
|
@@ -51,10 +52,12 @@ public class DeviceDataApiClient implements DeviceDataApi {
|
|
|
try {
|
|
|
// 这里指定返回类型为 CommonResult<?>,根据后台服务返回的实际结构做调整
|
|
|
restTemplate.postForObject(url, requestBody, CommonResult.class);
|
|
|
+ // TODO @haohao:check 结果,是否成功
|
|
|
return success(true);
|
|
|
} catch (Exception e) {
|
|
|
log.error("[{}] Error sending request to URL: {}", actionName, url, e);
|
|
|
return CommonResult.error(400, "Request error: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|