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; package cn.iocoder.yudao.module.farm.manager.equipmentproducer.dto.wf.updateparams;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@@ -17,4 +18,9 @@ import java.util.Map;
public class UpdateDeviceStatusReqVO { public class UpdateDeviceStatusReqVO {
private String deviceId; private String deviceId;
private Map<String,String> paramStr; 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 { try {
// 转换请求参数 // 转换请求参数
UpdateDeviceStatusReqVO wfRequest = (UpdateDeviceStatusReqVO) updateRequest; UpdateDeviceStatusReqVO wfRequest = (UpdateDeviceStatusReqVO) updateRequest;
ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writeValueAsString(wfRequest);
// 调用水肥机设备厂商API更新设备属性 POST 请求方式 // 调用水肥机设备厂商API更新设备属性 POST 请求方式
UpdateDeviceStatusRespVO vendorResponse = callWFUpdateDeviceApi(token, json); UpdateDeviceStatusRespVO vendorResponse = callWFUpdateDeviceApi(token, wfRequest);
// 转换为统一响应格式 // 转换为统一响应格式
return convertToUnifiedUpdateResponse(vendorResponse); return convertToUnifiedUpdateResponse(vendorResponse);
@@ -203,7 +201,7 @@ public class WaterFertilizerService extends AbstractDeviceService {
return httpClientUtils.doGet(url, headers, null, RealTimeDeviceDataRespVO.class); 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 url = deviceConf.getWaterAndFertilizer().getHosts() + deviceConf.getWaterAndFertilizer().getUrl4();
String clientId = deviceConf.getWaterAndFertilizer().getClientId(); String clientId = deviceConf.getWaterAndFertilizer().getClientId();
@@ -211,12 +209,15 @@ public class WaterFertilizerService extends AbstractDeviceService {
headers.put("Authorization", "Bearer " + token); headers.put("Authorization", "Bearer " + token);
headers.put("clientId", clientId); headers.put("clientId", clientId);
// // 构建请求体,包含设备ID和参数 // 构建请求体,包含设备ID和参数
// Map<String, Object> requestBody = new HashMap<>(); Map<String, Object> requestBody = new HashMap<>();
// requestBody.put("deviceId", request.getDeviceId()); requestBody.put("deviceId", request.getDeviceId());
// requestBody.put("paramStr", request.getParamStr()); 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) { private UpdateDeviceResponse convertToUnifiedUpdateResponse(UpdateDeviceStatusRespVO vendorResponse) {

View File

@@ -351,7 +351,7 @@ wms:
device-manager: device-manager:
# 四情 (文档来源: 物连网农业四情采集api协议.pdf 版本:v2.0.3 日期:2022.08.16) # 四情 (文档来源: 物连网农业四情采集api协议.pdf 版本:v2.0.3 日期:2022.08.16)
four-situations: four-situations:
hosts: http://api.farm.0531yun.cn # http://farm.0531yun.cn/#/ hosts: http://api.farm.0531yun.cn
username: cq250904jxtr username: cq250904jxtr
password: cq250904jxtr password: cq250904jxtr
global: global:
@@ -375,7 +375,7 @@ device-manager:
hosts: https://ryy.mythiot.com hosts: https://ryy.mythiot.com
username: jishui username: jishui
password: jishui@888 password: jishui@888
clientId: 8db4e3f233bba68d069d2f628ee8a621 # 固定值 clientId: e5cd7e4891bf95d1d19206ce24a7b32e # 固定值
grantType: password # 固定值 grantType: password # 固定值
url-1: /prod-api/auth/getToken # 获取公钥 POST url-1: /prod-api/auth/getToken # 获取公钥 POST
url-2: /prod-api/agriculture/deviceMain/list # 获取设备列表 GET url-2: /prod-api/agriculture/deviceMain/list # 获取设备列表 GET