fix: 控制器新增时候,电压设置bug修复。
This commit is contained in:
@@ -903,16 +903,29 @@ public class IotController extends BaseController {
|
||||
// 设置设备属性
|
||||
Map<String, Object> properties = new java.util.HashMap<>();
|
||||
|
||||
// 设置额定电压 - rated_voltage 是结构体类型
|
||||
// 根据C#代码,需要调用 ControllerHelper.GetInputVoltageProperty
|
||||
// 该方法返回一个特定结构的对象
|
||||
Integer voltValue = getVoltageValue(bo.getInputVoltage());
|
||||
if (voltValue == null) {
|
||||
return R.fail("电压参数错误");
|
||||
// 构建 rated_voltage 结构体并写入属性
|
||||
Map<String, Object> ratedVoltageStruct = new java.util.HashMap<>();
|
||||
switch (bo.getInputVoltage()) {
|
||||
case 1:
|
||||
ratedVoltageStruct.put("voltage", 220);
|
||||
ratedVoltageStruct.put("phase", "A");
|
||||
break;
|
||||
case 2:
|
||||
ratedVoltageStruct.put("voltage", 220);
|
||||
ratedVoltageStruct.put("phase", "B");
|
||||
break;
|
||||
case 3:
|
||||
ratedVoltageStruct.put("voltage", 220);
|
||||
ratedVoltageStruct.put("phase", "C");
|
||||
break;
|
||||
case 4:
|
||||
ratedVoltageStruct.put("voltage", 380);
|
||||
ratedVoltageStruct.put("phase", "ABC");
|
||||
break;
|
||||
default:
|
||||
return R.fail("电压参数错误");
|
||||
}
|
||||
|
||||
// 暂时跳过 rated_voltage 设置,先设置其他属性
|
||||
// properties.put("rated_voltage", ratedVoltageStruct);
|
||||
properties.put("rated_voltage", ratedVoltageStruct);
|
||||
|
||||
// 如果是三相380V四线,设置输出电压
|
||||
if (bo.getInputVoltage() == 4) {
|
||||
@@ -1012,11 +1025,12 @@ public class IotController extends BaseController {
|
||||
device.setPhaseDifference(0.0);
|
||||
}
|
||||
|
||||
device.setOxyWarnCallOpen(1);
|
||||
device.setOxyWarnCallNoDis(1);
|
||||
|
||||
if (bo.getIsOxygenUsed()) {
|
||||
device.setSalinityCompensation(bo.getSalinityCompensation());
|
||||
device.setOxyWarnLower(bo.getOxyWarnLower());
|
||||
device.setOxyWarnCallOpen(1);
|
||||
device.setOxyWarnCallNoDis(1);
|
||||
|
||||
// 如果有塘口且开关列表包含0(设备自身),则设置设备的塘口ID
|
||||
if (bo.getPondId() != null && bo.getPondId() > 0
|
||||
@@ -1186,16 +1200,53 @@ public class IotController extends BaseController {
|
||||
deviceSwitchMapper.insert(deviceSwitch);
|
||||
}
|
||||
|
||||
// 计算故障码对应的开关序号
|
||||
int switchIndex = 0; // 0表示设备自身
|
||||
if (errorCode != 0) {
|
||||
// 三相输入缺相 (强制4路开关断开)
|
||||
if (errorCode >= 0x1001 && errorCode <= 0x1003) {
|
||||
switchIndex = 0;
|
||||
// 三相过压欠压
|
||||
} else if (errorCode >= 0x1004 && errorCode <= 0x1009) {
|
||||
switchIndex = 0;
|
||||
// 三相开关缺相 (每路3个相位)
|
||||
} else if (errorCode >= 0x100A && errorCode <= 0x1019) {
|
||||
int tempIndex = errorCode - 0x100A;
|
||||
switchIndex = tempIndex / 3 + 1;
|
||||
// 三相开关过流 (每路3个相位)
|
||||
} else if (errorCode >= 0x101A && errorCode <= 0x1029) {
|
||||
int tempIndex = errorCode - 0x101A;
|
||||
switchIndex = tempIndex / 3 + 1;
|
||||
// 三相开关欠流 (每路3个相位)
|
||||
} else if (errorCode >= 0x102A && errorCode <= 0x1039) {
|
||||
int tempIndex = errorCode - 0x102A;
|
||||
switchIndex = tempIndex / 3 + 1;
|
||||
// 三相开关电流为空
|
||||
} else if (errorCode >= 0x103A && errorCode <= 0x103D) {
|
||||
switchIndex = errorCode - 0x103A + 1;
|
||||
// 单相开关过流
|
||||
} else if (errorCode >= 0x2003 && errorCode <= 0x2006) {
|
||||
switchIndex = errorCode - 0x2003 + 1;
|
||||
// 单相开关欠流
|
||||
} else if (errorCode >= 0x2007 && errorCode <= 0x200A) {
|
||||
switchIndex = errorCode - 0x2007 + 1;
|
||||
// 单相开关电流为空
|
||||
} else if (errorCode >= 0x200B && errorCode <= 0x200E) {
|
||||
switchIndex = errorCode - 0x200B + 1;
|
||||
// 断电告警
|
||||
} else if (errorCode == 0x3001) {
|
||||
warnCode |= 0x0020; // ErrorPowerOff
|
||||
}
|
||||
}
|
||||
|
||||
// 保存故障码记录
|
||||
if (errorCode != 0) {
|
||||
Date createTime = new Date();
|
||||
DeviceErrorCode errorCodeData = new DeviceErrorCode();
|
||||
errorCodeData.setDeviceId(device.getId());
|
||||
errorCodeData.setSwitchIndex(0); // 0表示设备本身的故障码
|
||||
errorCodeData.setSwitchIndex(switchIndex);
|
||||
errorCodeData.setErrorCode(errorCode);
|
||||
// 注意:DeviceErrorCode继承自TenantEntity,已包含createTime和updateTime字段
|
||||
deviceErrorCodeMapper.insert(errorCodeData);
|
||||
log.info("保存设备故障码: deviceId={}, errorCode={}", device.getId(), errorCode);
|
||||
log.info("保存设备故障码: deviceId={}, switchIndex={}, errorCode={}", device.getId(), switchIndex, errorCode);
|
||||
}
|
||||
|
||||
return R.ok();
|
||||
|
||||
Reference in New Issue
Block a user