fix (farm): 设备中心
- 水肥机设备-修改属性接口
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.farm.manager.equipmentproducer.dto.wf.updateparams;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -17,4 +18,9 @@ import java.util.Map;
|
||||
public class UpdateDeviceStatusReqVO {
|
||||
private String deviceId;
|
||||
private Map<String,String> paramStr;
|
||||
|
||||
public String getParamStrAsJson() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
return objectMapper.writeValueAsString(this.paramStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,11 +110,9 @@ public class WaterFertilizerService extends AbstractDeviceService {
|
||||
try {
|
||||
// 转换请求参数
|
||||
UpdateDeviceStatusReqVO wfRequest = (UpdateDeviceStatusReqVO) updateRequest;
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
String json = objectMapper.writeValueAsString(wfRequest);
|
||||
|
||||
// 调用水肥机设备厂商API更新设备属性 POST 请求方式
|
||||
UpdateDeviceStatusRespVO vendorResponse = callWFUpdateDeviceApi(token, json);
|
||||
UpdateDeviceStatusRespVO vendorResponse = callWFUpdateDeviceApi(token, wfRequest);
|
||||
|
||||
// 转换为统一响应格式
|
||||
return convertToUnifiedUpdateResponse(vendorResponse);
|
||||
@@ -203,7 +201,7 @@ public class WaterFertilizerService extends AbstractDeviceService {
|
||||
return httpClientUtils.doGet(url, headers, null, RealTimeDeviceDataRespVO.class);
|
||||
}
|
||||
|
||||
private UpdateDeviceStatusRespVO callWFUpdateDeviceApi(String token, String request) {
|
||||
private UpdateDeviceStatusRespVO callWFUpdateDeviceApi(String token, UpdateDeviceStatusReqVO request) throws Exception {
|
||||
String url = deviceConf.getWaterAndFertilizer().getHosts() + deviceConf.getWaterAndFertilizer().getUrl4();
|
||||
String clientId = deviceConf.getWaterAndFertilizer().getClientId();
|
||||
|
||||
@@ -211,12 +209,15 @@ public class WaterFertilizerService extends AbstractDeviceService {
|
||||
headers.put("Authorization", "Bearer " + token);
|
||||
headers.put("clientId", clientId);
|
||||
|
||||
// // 构建请求体,包含设备ID和参数
|
||||
// Map<String, Object> requestBody = new HashMap<>();
|
||||
// requestBody.put("deviceId", request.getDeviceId());
|
||||
// requestBody.put("paramStr", request.getParamStr());
|
||||
// 构建请求体,包含设备ID和参数
|
||||
Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("deviceId", request.getDeviceId());
|
||||
requestBody.put("paramStr", request.getParamStrAsJson());
|
||||
|
||||
return httpClientUtils.doPost(url, headers, request, UpdateDeviceStatusRespVO.class);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
String json = objectMapper.writeValueAsString(requestBody);
|
||||
|
||||
return httpClientUtils.doPost(url, headers, json, UpdateDeviceStatusRespVO.class);
|
||||
}
|
||||
|
||||
private UpdateDeviceResponse convertToUnifiedUpdateResponse(UpdateDeviceStatusRespVO vendorResponse) {
|
||||
|
||||
@@ -351,7 +351,7 @@ wms:
|
||||
device-manager:
|
||||
# 四情 (文档来源: 物连网农业四情采集api协议.pdf 版本:v2.0.3 日期:2022.08.16)
|
||||
four-situations:
|
||||
hosts: http://api.farm.0531yun.cn # http://farm.0531yun.cn/#/
|
||||
hosts: http://api.farm.0531yun.cn
|
||||
username: cq250904jxtr
|
||||
password: cq250904jxtr
|
||||
global:
|
||||
@@ -375,7 +375,7 @@ device-manager:
|
||||
hosts: https://ryy.mythiot.com
|
||||
username: jishui
|
||||
password: jishui@888
|
||||
clientId: 8db4e3f233bba68d069d2f628ee8a621 # 固定值
|
||||
clientId: e5cd7e4891bf95d1d19206ce24a7b32e # 固定值
|
||||
grantType: password # 固定值
|
||||
url-1: /prod-api/auth/getToken # 获取公钥 POST
|
||||
url-2: /prod-api/agriculture/deviceMain/list # 获取设备列表 GET
|
||||
|
||||
Reference in New Issue
Block a user