|
@@ -19,11 +19,13 @@ import com.ruoyi.ems.domain.WaterMeterH;
|
|
|
import com.ruoyi.ems.enums.DevObjType;
|
|
import com.ruoyi.ems.enums.DevObjType;
|
|
|
import com.ruoyi.ems.model.AbilityPayload;
|
|
import com.ruoyi.ems.model.AbilityPayload;
|
|
|
import com.ruoyi.ems.model.BoundaryObj;
|
|
import com.ruoyi.ems.model.BoundaryObj;
|
|
|
|
|
+import com.ruoyi.ems.model.CallData;
|
|
|
import com.ruoyi.ems.model.CallResponse;
|
|
import com.ruoyi.ems.model.CallResponse;
|
|
|
import com.ruoyi.ems.model.Price;
|
|
import com.ruoyi.ems.model.Price;
|
|
|
import com.ruoyi.ems.model.QueryDevice;
|
|
import com.ruoyi.ems.model.QueryDevice;
|
|
|
import com.ruoyi.ems.model.idenergy.CodesVal;
|
|
import com.ruoyi.ems.model.idenergy.CodesVal;
|
|
|
import com.ruoyi.ems.model.idenergy.CodesValReq;
|
|
import com.ruoyi.ems.model.idenergy.CodesValReq;
|
|
|
|
|
+import com.ruoyi.ems.model.idenergy.CodesValSetReq;
|
|
|
import com.ruoyi.ems.service.IEmsObjAttrValueService;
|
|
import com.ruoyi.ems.service.IEmsObjAttrValueService;
|
|
|
import com.ruoyi.ems.util.PingUtils;
|
|
import com.ruoyi.ems.util.PingUtils;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
@@ -152,13 +154,46 @@ public class BaCtlHandler extends BaseMeterDevHandler {
|
|
|
meterReadingGw(device.getDeviceModel(), "MeterReadingGw", device.getDeviceCode());
|
|
meterReadingGw(device.getDeviceModel(), "MeterReadingGw", device.getDeviceCode());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ else if (StringUtils.equals("SyncXfDevAttr", param.getAbilityKey())) {
|
|
|
|
|
+ xfCollect();
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (StringUtils.equals("SyncAuhDevAttr", param.getAbilityKey())) {
|
|
|
|
|
+ ahuCollect();
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (StringUtils.equals("SyncWtDevAttr", param.getAbilityKey())) {
|
|
|
|
|
+ wtCollect();
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (StringUtils.equals("SyncWpDevAttr", param.getAbilityKey())) {
|
|
|
|
|
+ wpCollect();
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (StringUtils.equals("SyncLightDevAttr", param.getAbilityKey())) {
|
|
|
|
|
+ lightCollect();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
callResponse = new CallResponse<>(0, "成功");
|
|
callResponse = new CallResponse<>(0, "成功");
|
|
|
}
|
|
}
|
|
|
else if (DevObjType.DEVC.getCode() == param.getObjType()) {
|
|
else if (DevObjType.DEVC.getCode() == param.getObjType()) {
|
|
|
- if (StringUtils.equals("MeterReadingGw", param.getAbilityKey())) {
|
|
|
|
|
|
|
+ if (StringUtils.equals("MeterReadingGw", param.getAbilityKey()) && StringUtils.equals(param.getModelCode(), GATEWAY_MODEL)) {
|
|
|
meterReadingGw(param.getModelCode(), param.getAbilityKey(), param.getObjCode());
|
|
meterReadingGw(param.getModelCode(), param.getAbilityKey(), param.getObjCode());
|
|
|
}
|
|
}
|
|
|
|
|
+ else if (StringUtils.equals("StartStopCtl", param.getAbilityKey()) && StringUtils.equals(param.getModelCode(), METER_MODEL_XF)) {
|
|
|
|
|
+ Map<String, String> xfMapper = config.getXfMapper();
|
|
|
|
|
+ String pointId = xfMapper.get(String.format("%s.%s", param.getObjCode(), "setCtl-StartStop"));
|
|
|
|
|
+ Assert.notEmpty(pointId, -1, "该设备未配置控制测点pointId.");
|
|
|
|
|
+ devAbilityCall(METER_MODEL_XF, param.getObjCode(), pointId, param.getAbilityKey(), param.getAbilityParam());
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (StringUtils.equals("StartStopCtl", param.getAbilityKey()) && StringUtils.equals(param.getModelCode(), METER_MODEL_AHU)) {
|
|
|
|
|
+ Map<String, String> ahuMapper = config.getAhuMapper();
|
|
|
|
|
+ String pointId = ahuMapper.get(String.format("%s.%s", param.getObjCode(), "setCtl-StartStop"));
|
|
|
|
|
+ Assert.notEmpty(pointId, -1, "该设备未配置控制测点pointId.");
|
|
|
|
|
+ devAbilityCall(METER_MODEL_AHU, param.getObjCode(), pointId, param.getAbilityKey(), param.getAbilityParam());
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (StringUtils.equals("OnOffCtl", param.getAbilityKey()) && StringUtils.equals(param.getModelCode(), METER_MODEL_AHU)) {
|
|
|
|
|
+ Map<String, String> lightMapper = config.getLightMapper();
|
|
|
|
|
+ String pointId = lightMapper.get(String.format("%s.%s", param.getObjCode(), "setCtl-OnOff"));
|
|
|
|
|
+ Assert.notEmpty(pointId, -1, "该设备未配置控制测点pointId.");
|
|
|
|
|
+ devAbilityCall(METER_MODEL_LIGHT, param.getObjCode(), pointId, param.getAbilityKey(), param.getAbilityParam());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
callResponse = new CallResponse<>(0, "成功");
|
|
callResponse = new CallResponse<>(0, "成功");
|
|
|
}
|
|
}
|
|
@@ -175,50 +210,18 @@ public class BaCtlHandler extends BaseMeterDevHandler {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void refreshOnline() {
|
|
public void refreshOnline() {
|
|
|
- try {
|
|
|
|
|
- // 1. 从URL中提取IP地址
|
|
|
|
|
- String url = config.getUrl();
|
|
|
|
|
- if (StringUtils.isBlank(url)) {
|
|
|
|
|
- log.warn("能耗监测系统URL配置为空,跳过心跳检测");
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- String ipAddress = PingUtils.extractIpFromUrl(url);
|
|
|
|
|
- if (StringUtils.isBlank(ipAddress)) {
|
|
|
|
|
- log.warn("无法从URL中提取IP地址: {}", url);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 2. 执行ping检测
|
|
|
|
|
- boolean isOnline = PingUtils.pingHost(ipAddress, 3000); // 3秒超时
|
|
|
|
|
-
|
|
|
|
|
- // 3. 获取当前系统状态
|
|
|
|
|
- String statusKey = "interfaceStatus";
|
|
|
|
|
-
|
|
|
|
|
- // 查询当前状态
|
|
|
|
|
- EmsObjAttrValue currentStatus = objAttrValueService.selectObjAttrValue(SYS_MODE_CODE, SUBSYSTEM_CODE,
|
|
|
|
|
- statusKey);
|
|
|
|
|
-
|
|
|
|
|
- String newStatus = isOnline ? "1" : "0";
|
|
|
|
|
- String oldStatus = currentStatus != null ? currentStatus.getAttrValue() : null;
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 4. 状态发生变化时更新并记录
|
|
|
|
|
- if (!StringUtils.equals(oldStatus, newStatus)) {
|
|
|
|
|
- log.info("能耗监测系统连接状态变化: {} -> {}, IP: {}", oldStatus, newStatus, ipAddress);
|
|
|
|
|
|
|
+ public void devAbilityCall(String modelCode, String deviceId, String pointId, String abilityKey, String paramValue) {
|
|
|
|
|
+ CodesVal codesVal = new CodesVal();
|
|
|
|
|
+ codesVal.setPointId(pointId);
|
|
|
|
|
+ codesVal.setValue(paramValue);
|
|
|
|
|
|
|
|
- // 更新系统属性状态
|
|
|
|
|
- objAttrValueService.updateObjAttrValue(SYS_MODE_CODE, SUBSYSTEM_CODE, statusKey, newStatus);
|
|
|
|
|
|
|
+ BaCtlEnergyTemplate template = new BaCtlEnergyTemplate(config.getUrl());
|
|
|
|
|
+ CallData<String> callData = template.setCodesVal(new CodesValSetReq(codesVal));
|
|
|
|
|
|
|
|
- String key = isOnline ? "connect" : "disconnect";
|
|
|
|
|
- triggerEvent(SYS_MODE_CODE, SUBSYSTEM_CODE, key, null, new Date());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 5. 记录心跳日志(可选,用于调试)
|
|
|
|
|
- log.debug("能耗监测系统心跳检测完成 - IP: {}, 状态: {}", ipAddress, isOnline ? "在线" : "离线");
|
|
|
|
|
- }
|
|
|
|
|
- catch (Exception e) {
|
|
|
|
|
- log.error("能耗监测系统心跳检测异常", e);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ saveCallLog(deviceId, modelCode, abilityKey, callData.getCallStatus(),
|
|
|
|
|
+ callData.getCallPayload(), callData.getResPayload());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void meterReadingGw(String modeCode, String abilityKey, String objCode) {
|
|
private void meterReadingGw(String modeCode, String abilityKey, String objCode) {
|
|
@@ -233,7 +236,8 @@ public class BaCtlHandler extends BaseMeterDevHandler {
|
|
|
CodesValReq req = new CodesValReq(pointIdSet);
|
|
CodesValReq req = new CodesValReq(pointIdSet);
|
|
|
|
|
|
|
|
// 调用能耗数据接口获取实时数据
|
|
// 调用能耗数据接口获取实时数据
|
|
|
- String callRes = new BaCtlEnergyTemplate(config.getUrl()).getCodesVal(req);
|
|
|
|
|
|
|
+ CallData<String> callData = new BaCtlEnergyTemplate(config.getUrl()).getCodesVal(req);
|
|
|
|
|
+ String callRes = callData.getResPayload();
|
|
|
JSONObject resJson = JSONObject.parseObject(callRes);
|
|
JSONObject resJson = JSONObject.parseObject(callRes);
|
|
|
|
|
|
|
|
if (resJson.getInteger("code") == 200) {
|
|
if (resJson.getInteger("code") == 200) {
|
|
@@ -367,7 +371,8 @@ public class BaCtlHandler extends BaseMeterDevHandler {
|
|
|
CodesValReq req = new CodesValReq(pointIdSet);
|
|
CodesValReq req = new CodesValReq(pointIdSet);
|
|
|
|
|
|
|
|
// 调用能耗数据接口获取实时数据
|
|
// 调用能耗数据接口获取实时数据
|
|
|
- String callRes = template.getCodesVal(req);
|
|
|
|
|
|
|
+ CallData<String> callData = template.getCodesVal(req);
|
|
|
|
|
+ String callRes = callData.getResPayload();
|
|
|
JSONObject resJson = JSONObject.parseObject(callRes);
|
|
JSONObject resJson = JSONObject.parseObject(callRes);
|
|
|
Assert.isTrue(StringUtils.equals(resJson.getString("code"), "200"), resJson.getInteger("code"),
|
|
Assert.isTrue(StringUtils.equals(resJson.getString("code"), "200"), resJson.getInteger("code"),
|
|
|
resJson.getString("error"));
|
|
resJson.getString("error"));
|
|
@@ -393,16 +398,18 @@ public class BaCtlHandler extends BaseMeterDevHandler {
|
|
|
String deviceCode = device.getDeviceCode();
|
|
String deviceCode = device.getDeviceCode();
|
|
|
Map<String, String> paramKeys = config.getXfMapper();
|
|
Map<String, String> paramKeys = config.getXfMapper();
|
|
|
|
|
|
|
|
- Set<String> pointIds = paramKeys.entrySet().stream()
|
|
|
|
|
- .filter(entry -> StringUtils.startsWith(entry.getKey(), deviceCode))
|
|
|
|
|
- .flatMap(entry -> Arrays.stream(StringUtils.split(entry.getValue(), ","))).map(String::trim)
|
|
|
|
|
- .collect(Collectors.toSet());
|
|
|
|
|
|
|
+ Set<String> pointIds = paramKeys.entrySet().stream().filter(
|
|
|
|
|
+ entry -> StringUtils.startsWith(entry.getKey(), deviceCode)
|
|
|
|
|
+ && !StringUtils.startsWith(entry.getKey(), deviceCode + ".setCtl-"))
|
|
|
|
|
+ .flatMap(entry -> Arrays.stream(StringUtils.split(entry.getValue(), ",")))
|
|
|
|
|
+ .map(String::trim).collect(Collectors.toSet());
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(pointIds)) {
|
|
if (CollectionUtils.isNotEmpty(pointIds)) {
|
|
|
CodesValReq req = new CodesValReq(pointIds);
|
|
CodesValReq req = new CodesValReq(pointIds);
|
|
|
|
|
|
|
|
// 调用能耗数据接口获取实时数据
|
|
// 调用能耗数据接口获取实时数据
|
|
|
- String callRes = new BaCtlEnergyTemplate(config.getUrl()).getCodesVal(req);
|
|
|
|
|
|
|
+ CallData<String> callData = new BaCtlEnergyTemplate(config.getUrl()).getCodesVal(req);
|
|
|
|
|
+ String callRes = callData.getResPayload();
|
|
|
JSONObject resJson = JSONObject.parseObject(callRes);
|
|
JSONObject resJson = JSONObject.parseObject(callRes);
|
|
|
Assert.isTrue(StringUtils.equals(resJson.getString("code"), "200"), resJson.getInteger("code"),
|
|
Assert.isTrue(StringUtils.equals(resJson.getString("code"), "200"), resJson.getInteger("code"),
|
|
|
resJson.getString("error"));
|
|
resJson.getString("error"));
|
|
@@ -445,7 +452,8 @@ public class BaCtlHandler extends BaseMeterDevHandler {
|
|
|
Map<String, String> paramKeys = config.getAhuMapper();
|
|
Map<String, String> paramKeys = config.getAhuMapper();
|
|
|
|
|
|
|
|
Set<String> pointIds = paramKeys.entrySet().stream()
|
|
Set<String> pointIds = paramKeys.entrySet().stream()
|
|
|
- .filter(entry -> StringUtils.startsWith(entry.getKey(), deviceCode))
|
|
|
|
|
|
|
+ .filter(entry -> StringUtils.startsWith(entry.getKey(), deviceCode)
|
|
|
|
|
+ && !StringUtils.startsWith(entry.getKey(), deviceCode + ".setCtl-"))
|
|
|
.flatMap(entry -> Arrays.stream(StringUtils.split(entry.getValue(), ","))).map(String::trim)
|
|
.flatMap(entry -> Arrays.stream(StringUtils.split(entry.getValue(), ","))).map(String::trim)
|
|
|
.collect(Collectors.toSet());
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
@@ -453,7 +461,8 @@ public class BaCtlHandler extends BaseMeterDevHandler {
|
|
|
CodesValReq req = new CodesValReq(pointIds);
|
|
CodesValReq req = new CodesValReq(pointIds);
|
|
|
|
|
|
|
|
// 调用能耗数据接口获取实时数据
|
|
// 调用能耗数据接口获取实时数据
|
|
|
- String callRes = new BaCtlEnergyTemplate(config.getUrl()).getCodesVal(req);
|
|
|
|
|
|
|
+ CallData<String> callData = new BaCtlEnergyTemplate(config.getUrl()).getCodesVal(req);
|
|
|
|
|
+ String callRes = callData.getResPayload();
|
|
|
JSONObject resJson = JSONObject.parseObject(callRes);
|
|
JSONObject resJson = JSONObject.parseObject(callRes);
|
|
|
Assert.isTrue(StringUtils.equals(resJson.getString("code"), "200"), resJson.getInteger("code"),
|
|
Assert.isTrue(StringUtils.equals(resJson.getString("code"), "200"), resJson.getInteger("code"),
|
|
|
resJson.getString("error"));
|
|
resJson.getString("error"));
|
|
@@ -498,7 +507,8 @@ public class BaCtlHandler extends BaseMeterDevHandler {
|
|
|
CodesValReq req = new CodesValReq(pointIds);
|
|
CodesValReq req = new CodesValReq(pointIds);
|
|
|
|
|
|
|
|
// 调用能耗数据接口获取实时数据
|
|
// 调用能耗数据接口获取实时数据
|
|
|
- String callRes = new BaCtlEnergyTemplate(config.getUrl()).getCodesVal(req);
|
|
|
|
|
|
|
+ CallData<String> callData = new BaCtlEnergyTemplate(config.getUrl()).getCodesVal(req);
|
|
|
|
|
+ String callRes = callData.getResPayload();
|
|
|
JSONObject resJson = JSONObject.parseObject(callRes);
|
|
JSONObject resJson = JSONObject.parseObject(callRes);
|
|
|
Assert.isTrue(StringUtils.equals(resJson.getString("code"), "200"), resJson.getInteger("code"),
|
|
Assert.isTrue(StringUtils.equals(resJson.getString("code"), "200"), resJson.getInteger("code"),
|
|
|
resJson.getString("error"));
|
|
resJson.getString("error"));
|
|
@@ -530,7 +540,8 @@ public class BaCtlHandler extends BaseMeterDevHandler {
|
|
|
CodesValReq req = new CodesValReq(pointIds);
|
|
CodesValReq req = new CodesValReq(pointIds);
|
|
|
|
|
|
|
|
// 调用能耗数据接口获取实时数据
|
|
// 调用能耗数据接口获取实时数据
|
|
|
- String callRes = new BaCtlEnergyTemplate(config.getUrl()).getCodesVal(req);
|
|
|
|
|
|
|
+ CallData<String> callData = new BaCtlEnergyTemplate(config.getUrl()).getCodesVal(req);
|
|
|
|
|
+ String callRes = callData.getResPayload();
|
|
|
JSONObject resJson = JSONObject.parseObject(callRes);
|
|
JSONObject resJson = JSONObject.parseObject(callRes);
|
|
|
Assert.isTrue(StringUtils.equals(resJson.getString("code"), "200"), resJson.getInteger("code"),
|
|
Assert.isTrue(StringUtils.equals(resJson.getString("code"), "200"), resJson.getInteger("code"),
|
|
|
resJson.getString("error"));
|
|
resJson.getString("error"));
|
|
@@ -554,7 +565,8 @@ public class BaCtlHandler extends BaseMeterDevHandler {
|
|
|
Map<String, String> paramKeys = config.getLightMapper();
|
|
Map<String, String> paramKeys = config.getLightMapper();
|
|
|
|
|
|
|
|
Set<String> pointIds = paramKeys.entrySet().stream()
|
|
Set<String> pointIds = paramKeys.entrySet().stream()
|
|
|
- .filter(entry -> StringUtils.startsWith(entry.getKey(), deviceCode))
|
|
|
|
|
|
|
+ .filter(entry -> StringUtils.startsWith(entry.getKey(), deviceCode)
|
|
|
|
|
+ && !StringUtils.startsWith(entry.getKey(), deviceCode + ".setCtl-"))
|
|
|
.flatMap(entry -> Arrays.stream(StringUtils.split(entry.getValue(), ","))).map(String::trim)
|
|
.flatMap(entry -> Arrays.stream(StringUtils.split(entry.getValue(), ","))).map(String::trim)
|
|
|
.collect(Collectors.toSet());
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
@@ -562,7 +574,8 @@ public class BaCtlHandler extends BaseMeterDevHandler {
|
|
|
CodesValReq req = new CodesValReq(pointIds);
|
|
CodesValReq req = new CodesValReq(pointIds);
|
|
|
|
|
|
|
|
// 调用能耗数据接口获取实时数据
|
|
// 调用能耗数据接口获取实时数据
|
|
|
- String callRes = new BaCtlEnergyTemplate(config.getUrl()).getCodesVal(req);
|
|
|
|
|
|
|
+ CallData<String> callData = new BaCtlEnergyTemplate(config.getUrl()).getCodesVal(req);
|
|
|
|
|
+ String callRes = callData.getResPayload();
|
|
|
JSONObject resJson = JSONObject.parseObject(callRes);
|
|
JSONObject resJson = JSONObject.parseObject(callRes);
|
|
|
Assert.isTrue(StringUtils.equals(resJson.getString("code"), "200"), resJson.getInteger("code"),
|
|
Assert.isTrue(StringUtils.equals(resJson.getString("code"), "200"), resJson.getInteger("code"),
|
|
|
resJson.getString("error"));
|
|
resJson.getString("error"));
|