fix (farm): 设备中心

- 水肥机设备-修改属性接口
This commit is contained in:
达富斌
2025-10-11 13:59:19 +08:00
parent 4e636bf71f
commit 4ff2b18aa2
3 changed files with 18 additions and 11 deletions

View File

@@ -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);
}
}

View File

@@ -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) {