fix: 微信小程序接口对接修改,联调测试问题修复。
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,36 @@
|
||||
package com.intc.iot.domain.bo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 设备校准请求业务对象
|
||||
*
|
||||
* @author intc
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "设备校准请求对象")
|
||||
public class DeviceCalibrateBo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@Schema(description = "设备ID")
|
||||
@NotNull(message = "设备ID不能为空")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 校准码
|
||||
*/
|
||||
@Schema(description = "校准码")
|
||||
@NotBlank(message = "校准码不能为空")
|
||||
private String code;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.intc.iot.domain.bo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 设备盐度补偿请求业务对象
|
||||
*
|
||||
* @author intc
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "设备盐度补偿请求对象")
|
||||
public class DeviceSalinityCompensationBo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@Schema(description = "设备ID")
|
||||
@NotNull(message = "设备ID不能为空")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 盐度补偿值
|
||||
*/
|
||||
@Schema(description = "盐度补偿值")
|
||||
@NotNull(message = "盐度补偿值不能为空")
|
||||
private Double salinityCompensation;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.intc.iot.domain.bo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 设置设备输入电压类型请求对象
|
||||
*
|
||||
* @author intc
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "设置设备输入电压类型请求对象")
|
||||
public class DeviceVoltageTypeBo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@Schema(description = "设备ID")
|
||||
@NotNull(message = "设备ID不能为空")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 电压类型(1-220V单相,2-220V两相,3-380V三相,4-380V四相)
|
||||
*/
|
||||
@Schema(description = "电压类型(1-220V单相,2-220V两相,3-380V三相,4-380V四相)")
|
||||
@NotNull(message = "电压类型不能为空")
|
||||
private Integer voltageType;
|
||||
}
|
||||
@@ -88,4 +88,23 @@ public interface IotDeviceService {
|
||||
*/
|
||||
Map<String, Object> queryThingModel(String productKey) throws Exception;
|
||||
|
||||
/**
|
||||
* 设置设备校准
|
||||
*
|
||||
* @param iotId 设备ID
|
||||
* @return 是否成功
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
boolean calibrateDevice(String iotId) throws Exception;
|
||||
|
||||
/**
|
||||
* 设置设备盐度补偿
|
||||
*
|
||||
* @param iotId 设备ID
|
||||
* @param salinityCompensation 盐度补偿值
|
||||
* @return 是否成功
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
boolean setSalinityCompensation(String iotId, Double salinityCompensation) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -191,4 +191,44 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean calibrateDevice(String iotId) throws Exception {
|
||||
log.info("设置设备校准,IotId: {}", iotId);
|
||||
|
||||
// 构造属性JSON:{"correct": 1}
|
||||
String properties = "{\"correct\": 1}";
|
||||
|
||||
SetDevicePropertyRequest request = new SetDevicePropertyRequest();
|
||||
request.setIotId(iotId);
|
||||
request.setItems(properties);
|
||||
|
||||
SetDevicePropertyResponse response = acsClient.getAcsResponse(request);
|
||||
|
||||
if (!response.getSuccess()) {
|
||||
log.error("设置设备校准失败,Code: {}, ErrorMessage: {}", response.getCode(), response.getErrorMessage());
|
||||
}
|
||||
|
||||
return response.getSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setSalinityCompensation(String iotId, Double salinityCompensation) throws Exception {
|
||||
log.info("设置设备盐度补偿,IotId: {}, SalinityCompensation: {}", iotId, salinityCompensation);
|
||||
|
||||
// 构造属性JSON:{"salinitySet": value}
|
||||
String properties = String.format("{\"salinitySet\": %s}", salinityCompensation);
|
||||
|
||||
SetDevicePropertyRequest request = new SetDevicePropertyRequest();
|
||||
request.setIotId(iotId);
|
||||
request.setItems(properties);
|
||||
|
||||
SetDevicePropertyResponse response = acsClient.getAcsResponse(request);
|
||||
|
||||
if (!response.getSuccess()) {
|
||||
log.error("设置设备盐度补偿失败,Code: {}, ErrorMessage: {}", response.getCode(), response.getErrorMessage());
|
||||
}
|
||||
|
||||
return response.getSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.intc.iot.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 设备控制辅助工具类
|
||||
*
|
||||
* @author intc
|
||||
*/
|
||||
public class ControllerHelper {
|
||||
|
||||
/**
|
||||
* 获取输入电压属性值
|
||||
* 根据电压类型返回对应的IoT平台属性值
|
||||
* 注意:rated_voltage是结构体类型,尝试只使用phase字段
|
||||
*
|
||||
* @param voltageType 电压类型(1-220V单相,2-220V两相,3-380V三相,4-380V四相)
|
||||
* @return IoT平台属性值的Map
|
||||
*/
|
||||
public static Map<String, Object> getInputVoltageProperty(Integer voltageType) {
|
||||
if (voltageType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
// 尝试只设置phase字段
|
||||
switch (voltageType) {
|
||||
case 1: // 220V单相
|
||||
result.put("phase", "1");
|
||||
break;
|
||||
case 2: // 220V两相
|
||||
result.put("phase", "2");
|
||||
break;
|
||||
case 3: // 380V三相
|
||||
result.put("phase", "3");
|
||||
break;
|
||||
case 4: // 380V四相
|
||||
result.put("phase", "4");
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取电压类型的中文描述
|
||||
*
|
||||
* @param voltageType 电压类型
|
||||
* @return 中文描述
|
||||
*/
|
||||
public static String getVoltageDescription(Integer voltageType) {
|
||||
if (voltageType == null) {
|
||||
return "未知";
|
||||
}
|
||||
|
||||
switch (voltageType) {
|
||||
case 1:
|
||||
return "220V单相";
|
||||
case 2:
|
||||
return "220V两相";
|
||||
case 3:
|
||||
return "380V三相";
|
||||
case 4:
|
||||
return "380V四相";
|
||||
default:
|
||||
return "未知类型";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user