|
@@ -1,13 +1,14 @@
|
|
|
package com.ruoyi.ems.handle;
|
|
package com.ruoyi.ems.handle;
|
|
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.huashe.common.exception.Assert;
|
|
import com.huashe.common.exception.Assert;
|
|
|
import com.huashe.common.exception.BusinessException;
|
|
import com.huashe.common.exception.BusinessException;
|
|
|
import com.huashe.common.utils.DateUtils;
|
|
import com.huashe.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.redis.service.RedisService;
|
|
import com.ruoyi.common.redis.service.RedisService;
|
|
|
-import com.ruoyi.ems.config.InDoorEnergyConfig;
|
|
|
|
|
-import com.ruoyi.ems.core.InDoorEnergyTemplate;
|
|
|
|
|
|
|
+import com.ruoyi.ems.config.BaCtlConfig;
|
|
|
|
|
+import com.ruoyi.ems.core.BaCtlEnergyTemplate;
|
|
|
import com.ruoyi.ems.domain.ElecMeterH;
|
|
import com.ruoyi.ems.domain.ElecMeterH;
|
|
|
import com.ruoyi.ems.domain.ElecPgSupplyH;
|
|
import com.ruoyi.ems.domain.ElecPgSupplyH;
|
|
|
import com.ruoyi.ems.domain.EmsDevice;
|
|
import com.ruoyi.ems.domain.EmsDevice;
|
|
@@ -36,6 +37,7 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -45,7 +47,7 @@ import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 室内能耗对接处理
|
|
|
|
|
|
|
+ * BA楼控处理类
|
|
|
* <功能详细描述>
|
|
* <功能详细描述>
|
|
|
*
|
|
*
|
|
|
* @author lvwenbin
|
|
* @author lvwenbin
|
|
@@ -54,14 +56,26 @@ import java.util.stream.Collectors;
|
|
|
* @since [产品/模块版本]
|
|
* @since [产品/模块版本]
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
-public class InDoorEnergyHandler extends BaseMeterDevHandler {
|
|
|
|
|
- private static final Logger log = LoggerFactory.getLogger(InDoorEnergyHandler.class);
|
|
|
|
|
|
|
+public class BaCtlHandler extends BaseMeterDevHandler {
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(BaCtlHandler.class);
|
|
|
|
|
|
|
|
// 对接系统
|
|
// 对接系统
|
|
|
- private static final String SYS_MODE_CODE = "M_W4_SYS_IN_DOOR";
|
|
|
|
|
|
|
+ private static final String SYS_MODE_CODE = "M_W4_SYS_BA";
|
|
|
|
|
|
|
|
- // 设备模型代码
|
|
|
|
|
- private static final String DEV_MODE_CODE = "M_W4_SM_INDOOR_ENERGY";
|
|
|
|
|
|
|
+ // 网关模型代码
|
|
|
|
|
+ private static final String GATEWAY_MODEL = "M_W4_DEV_BA_GA";
|
|
|
|
|
+
|
|
|
|
|
+ // 电表测点模型代码
|
|
|
|
|
+ private static final String METER_MODEL_E = "M_W4_DEV_BA_METER_E";
|
|
|
|
|
+
|
|
|
|
|
+ // 水表测点模型代码
|
|
|
|
|
+ private static final String METER_MODEL_W = "M_W4_DEV_BA_METER_W";
|
|
|
|
|
+
|
|
|
|
|
+ // DDC点位模型代码
|
|
|
|
|
+ private static final String DDC_MODEL = "M_Z_DEV_BA_DDC";
|
|
|
|
|
+
|
|
|
|
|
+ // 照明模型代码
|
|
|
|
|
+ private static final String LIGHT_MODEL = "M_Z_DEV_BA_LIGHT";
|
|
|
|
|
|
|
|
// 设备子系统代码
|
|
// 设备子系统代码
|
|
|
private static final String SUBSYSTEM_CODE = "SYS_NHJC";
|
|
private static final String SUBSYSTEM_CODE = "SYS_NHJC";
|
|
@@ -79,7 +93,7 @@ public class InDoorEnergyHandler extends BaseMeterDevHandler {
|
|
|
private IEmsObjAttrValueService objAttrValueService;
|
|
private IEmsObjAttrValueService objAttrValueService;
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
- private InDoorEnergyConfig config;
|
|
|
|
|
|
|
+ private BaCtlConfig config;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RedisService redisService;
|
|
private RedisService redisService;
|
|
@@ -87,7 +101,21 @@ public class InDoorEnergyHandler extends BaseMeterDevHandler {
|
|
|
@Override
|
|
@Override
|
|
|
public List<MeterDevice> getMeterDeviceList() {
|
|
public List<MeterDevice> getMeterDeviceList() {
|
|
|
QueryDevice queryDevice = new QueryDevice();
|
|
QueryDevice queryDevice = new QueryDevice();
|
|
|
- queryDevice.setDeviceModel(DEV_MODE_CODE);
|
|
|
|
|
|
|
+ queryDevice.setDeviceModel(METER_MODEL_E);
|
|
|
|
|
+ queryDevice.setDeviceEnable(1);
|
|
|
|
|
+ List<MeterDevice> list = new ArrayList<>(meterDeviceService.selectMeterDeviceList(queryDevice));
|
|
|
|
|
+
|
|
|
|
|
+ QueryDevice queryDevice2 = new QueryDevice();
|
|
|
|
|
+ queryDevice2.setDeviceModel(METER_MODEL_W);
|
|
|
|
|
+ queryDevice2.setDeviceEnable(1);
|
|
|
|
|
+ list.addAll(meterDeviceService.selectMeterDeviceList(queryDevice2));
|
|
|
|
|
+
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<MeterDevice> getMeterDeviceList(String modelCode) {
|
|
|
|
|
+ QueryDevice queryDevice = new QueryDevice();
|
|
|
|
|
+ queryDevice.setDeviceModel(modelCode);
|
|
|
queryDevice.setDeviceEnable(1);
|
|
queryDevice.setDeviceEnable(1);
|
|
|
return meterDeviceService.selectMeterDeviceList(queryDevice);
|
|
return meterDeviceService.selectMeterDeviceList(queryDevice);
|
|
|
}
|
|
}
|
|
@@ -95,7 +123,7 @@ public class InDoorEnergyHandler extends BaseMeterDevHandler {
|
|
|
@Override
|
|
@Override
|
|
|
public List<EmsDevice> getDeviceList() {
|
|
public List<EmsDevice> getDeviceList() {
|
|
|
QueryDevice queryDevice = new QueryDevice();
|
|
QueryDevice queryDevice = new QueryDevice();
|
|
|
- queryDevice.setDeviceModel(DEV_MODE_CODE);
|
|
|
|
|
|
|
+ queryDevice.setDeviceModel(GATEWAY_MODEL);
|
|
|
return deviceService.selectList(queryDevice);
|
|
return deviceService.selectList(queryDevice);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -157,7 +185,8 @@ public class InDoorEnergyHandler extends BaseMeterDevHandler {
|
|
|
String statusKey = "interfaceStatus";
|
|
String statusKey = "interfaceStatus";
|
|
|
|
|
|
|
|
// 查询当前状态
|
|
// 查询当前状态
|
|
|
- EmsObjAttrValue currentStatus = objAttrValueService.selectObjAttrValue(SYS_MODE_CODE, SUBSYSTEM_CODE, statusKey);
|
|
|
|
|
|
|
+ EmsObjAttrValue currentStatus = objAttrValueService.selectObjAttrValue(SYS_MODE_CODE, SUBSYSTEM_CODE,
|
|
|
|
|
+ statusKey);
|
|
|
|
|
|
|
|
String newStatus = isOnline ? "1" : "0";
|
|
String newStatus = isOnline ? "1" : "0";
|
|
|
String oldStatus = currentStatus != null ? currentStatus.getAttrValue() : null;
|
|
String oldStatus = currentStatus != null ? currentStatus.getAttrValue() : null;
|
|
@@ -183,32 +212,31 @@ public class InDoorEnergyHandler extends BaseMeterDevHandler {
|
|
|
|
|
|
|
|
private void meterReadingGw(String modeCode, String abilityKey, String objCode) {
|
|
private void meterReadingGw(String modeCode, String abilityKey, String objCode) {
|
|
|
// 查询当前设备的接口属性值
|
|
// 查询当前设备的接口属性值
|
|
|
- List<EmsObjAttrValue> attrValues = objAttrValueService.selectByObjCode(modeCode, objCode);
|
|
|
|
|
- attrValues = attrValues.stream()
|
|
|
|
|
- // 过滤条件:attrKey以"interface"开头
|
|
|
|
|
- .filter(attr -> StringUtils.startsWith(attr.getAttrKey(), "interface"))
|
|
|
|
|
- // 收集为新的List
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
|
|
+ EmsObjAttrValue subDevAttr = objAttrValueService.selectObjAttrValue(modeCode, objCode, "subDev");
|
|
|
|
|
|
|
|
- Set<String> pointIdSet = getPointIds(attrValues);
|
|
|
|
|
- CodesValReq req = new CodesValReq(pointIdSet);
|
|
|
|
|
|
|
+ if (null != subDevAttr && StringUtils.isNotEmpty(subDevAttr.getAttrValue())) {
|
|
|
|
|
+ JSONArray subDevs = JSON.parseArray(subDevAttr.getAttrValue());
|
|
|
|
|
+ Set<String> pointIdSet = subDevs.stream().map(item -> ((JSONObject) item).getString("deviceCode"))
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
|
|
|
- // 调用能耗数据接口获取实时数据
|
|
|
|
|
- InDoorEnergyTemplate template = new InDoorEnergyTemplate(config.getUrl());
|
|
|
|
|
- String callRes = template.getCodesVal(req);
|
|
|
|
|
- JSONObject resJson = JSONObject.parseObject(callRes);
|
|
|
|
|
|
|
+ CodesValReq req = new CodesValReq(pointIdSet);
|
|
|
|
|
|
|
|
- if (resJson.getInteger("code") == 200) {
|
|
|
|
|
- saveCallLog(objCode, modeCode, abilityKey, 0, JSON.toJSONString(req), callRes);
|
|
|
|
|
|
|
+ // 调用能耗数据接口获取实时数据
|
|
|
|
|
+ String callRes = new BaCtlEnergyTemplate(config.getUrl()).getCodesVal(req);
|
|
|
|
|
+ JSONObject resJson = JSONObject.parseObject(callRes);
|
|
|
|
|
|
|
|
- String dataStr = resJson.getString("ResultPointObjArr");
|
|
|
|
|
- List<CodesVal> retList = JSONObject.parseArray(dataStr, CodesVal.class);
|
|
|
|
|
- // 更新设备属性
|
|
|
|
|
- updateDeviceAttrList(attrValues, retList);
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- saveCallLog(objCode, modeCode, abilityKey, 2, JSON.toJSONString(req), callRes);
|
|
|
|
|
- throw new BusinessException(-1, resJson.getString("error"));
|
|
|
|
|
|
|
+ if (resJson.getInteger("code") == 200) {
|
|
|
|
|
+ saveCallLog(objCode, modeCode, abilityKey, 0, JSON.toJSONString(req), callRes);
|
|
|
|
|
+
|
|
|
|
|
+ String dataStr = resJson.getString("ResultPointObjArr");
|
|
|
|
|
+ List<CodesVal> retList = JSON.parseArray(dataStr, CodesVal.class);
|
|
|
|
|
+ // 更新设备属性
|
|
|
|
|
+ updateDeviceAttrList(objCode, subDevs, retList);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ saveCallLog(objCode, modeCode, abilityKey, 2, JSON.toJSONString(req), callRes);
|
|
|
|
|
+ throw new BusinessException(-1, resJson.getString("error"));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -221,16 +249,15 @@ public class InDoorEnergyHandler extends BaseMeterDevHandler {
|
|
|
int cnt = 0;
|
|
int cnt = 0;
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- // 获取所有能源设备列表
|
|
|
|
|
- List<EmsDevice> deviceList = getDeviceList();
|
|
|
|
|
|
|
+ List<EmsObjAttrValue> gwDeviceList = objAttrValueService.selectByAttrKey(GATEWAY_MODEL, "subDev");
|
|
|
|
|
|
|
|
- // 遍历每个能源设备
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(deviceList)) {
|
|
|
|
|
|
|
+ // 遍历每个网关设备
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(gwDeviceList)) {
|
|
|
// 调用能耗数据接口获取实时数据
|
|
// 调用能耗数据接口获取实时数据
|
|
|
- InDoorEnergyTemplate template = new InDoorEnergyTemplate(config.getUrl());
|
|
|
|
|
|
|
+ BaCtlEnergyTemplate template = new BaCtlEnergyTemplate(config.getUrl());
|
|
|
|
|
|
|
|
- for (EmsDevice emsDevice : deviceList) {
|
|
|
|
|
- cnt += meterDevCollect(template, emsDevice);
|
|
|
|
|
|
|
+ for (EmsObjAttrValue gwDevice : gwDeviceList) {
|
|
|
|
|
+ cnt += meterDevCollect(template, gwDevice);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -241,100 +268,77 @@ public class InDoorEnergyHandler extends BaseMeterDevHandler {
|
|
|
return cnt;
|
|
return cnt;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private int meterDevCollect(InDoorEnergyTemplate template, EmsDevice emsDevice) {
|
|
|
|
|
|
|
+ private int meterDevCollect(BaCtlEnergyTemplate template, EmsObjAttrValue subDevAttr) {
|
|
|
int cnt = 0;
|
|
int cnt = 0;
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- // 查询当前设备的接口属性值
|
|
|
|
|
- List<EmsObjAttrValue> attrValues = objAttrValueService.selectByObjCode(DEV_MODE_CODE,
|
|
|
|
|
- emsDevice.getDeviceCode());
|
|
|
|
|
- attrValues = attrValues.stream()
|
|
|
|
|
- // 过滤条件:attrKey以"interface"开头
|
|
|
|
|
- .filter(attr -> StringUtils.startsWith(attr.getAttrKey(), "interface"))
|
|
|
|
|
- // 收集为新的List
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
- Set<String> pointIdSet = getPointIds(attrValues);
|
|
|
|
|
- CodesValReq req = new CodesValReq(pointIdSet);
|
|
|
|
|
|
|
|
|
|
- // 调用能耗数据接口获取实时数据
|
|
|
|
|
- String callRes = template.getCodesVal(req);
|
|
|
|
|
- JSONObject resJson = JSONObject.parseObject(callRes);
|
|
|
|
|
- Assert.isTrue(StringUtils.equals(resJson.getString("code"), "200"), resJson.getInteger("code"),
|
|
|
|
|
- resJson.getString("error"));
|
|
|
|
|
- int callStatus = StringUtils.equals(resJson.getString("code"), "200") ? 0 : 2;
|
|
|
|
|
- saveCallLog(emsDevice.getDeviceCode(), DEV_MODE_CODE, "MeterReadingGw", callStatus, JSON.toJSONString(req),
|
|
|
|
|
- callRes);
|
|
|
|
|
|
|
+ if (null != subDevAttr && StringUtils.isNotEmpty(subDevAttr.getAttrValue())) {
|
|
|
|
|
+ JSONArray subDevs = JSON.parseArray(subDevAttr.getAttrValue());
|
|
|
|
|
+ Set<String> pointIdSet = subDevs.stream().map(item -> ((JSONObject) item).getString("deviceCode"))
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
|
|
|
- String dataStr = resJson.getString("ResultPointObjArr");
|
|
|
|
|
- List<CodesVal> retList = JSONObject.parseArray(dataStr, CodesVal.class);
|
|
|
|
|
|
|
+ CodesValReq req = new CodesValReq(pointIdSet);
|
|
|
|
|
|
|
|
- // 更新设备属性
|
|
|
|
|
- updateDeviceAttrList(attrValues, retList);
|
|
|
|
|
|
|
+ // 调用能耗数据接口获取实时数据
|
|
|
|
|
+ String callRes = template.getCodesVal(req);
|
|
|
|
|
+ JSONObject resJson = JSONObject.parseObject(callRes);
|
|
|
|
|
+ Assert.isTrue(StringUtils.equals(resJson.getString("code"), "200"), resJson.getInteger("code"),
|
|
|
|
|
+ resJson.getString("error"));
|
|
|
|
|
+ int callStatus = StringUtils.equals(resJson.getString("code"), "200") ? 0 : 2;
|
|
|
|
|
+ saveCallLog(subDevAttr.getObjCode(), GATEWAY_MODEL, "MeterReadingGw", callStatus,
|
|
|
|
|
+ JSON.toJSONString(req), callRes);
|
|
|
|
|
+
|
|
|
|
|
+ String dataStr = resJson.getString("ResultPointObjArr");
|
|
|
|
|
+ List<CodesVal> retList = JSON.parseArray(dataStr, CodesVal.class);
|
|
|
|
|
+
|
|
|
|
|
+ // 更新设备属性
|
|
|
|
|
+ updateDeviceAttrList(subDevAttr.getObjCode(), subDevs, retList);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
catch (Exception e) {
|
|
catch (Exception e) {
|
|
|
- log.error("meterDevHourProd error! deviceCode:{}", emsDevice.getDeviceCode(), e);
|
|
|
|
|
|
|
+ log.error("meterDevHourProd error! deviceCode:{}", subDevAttr.getObjCode(), e);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return cnt;
|
|
return cnt;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void updateDeviceAttrList(List<EmsObjAttrValue> attrValues, List<CodesVal> retList) {
|
|
|
|
|
|
|
+ private void updateDeviceAttrList(String gwDevieCode, JSONArray subDevs, List<CodesVal> retList) {
|
|
|
try {
|
|
try {
|
|
|
// 将新采集数据转换为Map
|
|
// 将新采集数据转换为Map
|
|
|
Map<String, CodesVal> codesValMap = retList.stream()
|
|
Map<String, CodesVal> codesValMap = retList.stream()
|
|
|
.collect(Collectors.toMap(CodesVal::getPointId, Function.identity()));
|
|
.collect(Collectors.toMap(CodesVal::getPointId, Function.identity()));
|
|
|
|
|
|
|
|
- for (EmsObjAttrValue dbAttr : attrValues) {
|
|
|
|
|
- // 更新列表中的值
|
|
|
|
|
- boolean dbNeedUpdate = false;
|
|
|
|
|
- String dbAttrValue = dbAttr.getAttrValue();
|
|
|
|
|
- List<ObjAttrTableItem> dbItems = JSON.parseArray(dbAttrValue, ObjAttrTableItem.class);
|
|
|
|
|
-
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(dbItems)) {
|
|
|
|
|
- Map<String, ObjAttrTableItem> itemMap = dbItems.stream()
|
|
|
|
|
- .collect(Collectors.toMap(ObjAttrTableItem::getKey, Function.identity()));
|
|
|
|
|
-
|
|
|
|
|
- for (Map.Entry<String, ObjAttrTableItem> dbItemEntry : itemMap.entrySet()) {
|
|
|
|
|
- String pointId = dbItemEntry.getKey();
|
|
|
|
|
- ObjAttrTableItem dbItem = dbItemEntry.getValue();
|
|
|
|
|
-
|
|
|
|
|
- CodesVal syncCodesVal = codesValMap.get(pointId);
|
|
|
|
|
-
|
|
|
|
|
- if (null != syncCodesVal) {
|
|
|
|
|
- // 数据验证和处理
|
|
|
|
|
- DataValidationResult validationResult = validateMeterData(dbAttr.getObjCode(), pointId,
|
|
|
|
|
- dbItem.getValue(), syncCodesVal.getValue());
|
|
|
|
|
-
|
|
|
|
|
- if (validationResult.isValid()) {
|
|
|
|
|
- // 更新缓存中的数据
|
|
|
|
|
- String hKey = NEW_HOUR_READING + "-" + pointId;
|
|
|
|
|
- redisService.setCacheMapValue(dbAttr.getObjCode(), hKey,
|
|
|
|
|
- validationResult.getValidValue());
|
|
|
|
|
-
|
|
|
|
|
- if (!StringUtils.equals(validationResult.getValidValue(), dbItem.getValue())
|
|
|
|
|
- || !StringUtils.equals(syncCodesVal.getTime(), dbItem.getUpdateTime())) {
|
|
|
|
|
- dbNeedUpdate = true;
|
|
|
|
|
-
|
|
|
|
|
- dbItem.setValue(validationResult.getValidValue());
|
|
|
|
|
- dbItem.setUpdateTime(syncCodesVal.getTime());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- // 记录异常数据但不更新
|
|
|
|
|
- log.warn("检测到异常抄表数据 - 设备:{}, 测点:{}, 旧值:{}, 新值:{}, 原因:{}",
|
|
|
|
|
- dbAttr.getObjCode(), pointId, dbItem.getValue(), syncCodesVal.getValue(),
|
|
|
|
|
- validationResult.getReason());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ for (Object subDev : subDevs) {
|
|
|
|
|
+ JSONObject subDevObj = (JSONObject) subDev;
|
|
|
|
|
+ String pointId = subDevObj.getString("deviceCode");
|
|
|
|
|
+ String modelCode = subDevObj.getString("modelCode");
|
|
|
|
|
+
|
|
|
|
|
+ CodesVal syncCodesVal = codesValMap.get(pointId);
|
|
|
|
|
+
|
|
|
|
|
+ if (null != syncCodesVal) {
|
|
|
|
|
+ EmsObjAttrValue dbAttr = objAttrValueService.selectObjAttrValue(modelCode, pointId, "value");
|
|
|
|
|
+
|
|
|
|
|
+ // 数据验证和处理
|
|
|
|
|
+ DataValidationResult validationResult = validateMeterData(gwDevieCode, pointId,
|
|
|
|
|
+ dbAttr.getAttrValue(), syncCodesVal.getValue());
|
|
|
|
|
+
|
|
|
|
|
+ if (validationResult.isValid()) {
|
|
|
|
|
+ // 更新缓存中的数据
|
|
|
|
|
+ String hKey = NEW_HOUR_READING + "-" + pointId;
|
|
|
|
|
+ redisService.setCacheMapValue(gwDevieCode, hKey, validationResult.getValidValue());
|
|
|
|
|
+
|
|
|
|
|
+ if (!StringUtils.equals(validationResult.getValidValue(), dbAttr.getAttrValue())) {
|
|
|
|
|
+ objAttrValueService.updateObjAttrValue(modelCode, pointId, "value",
|
|
|
|
|
+ validationResult.getValidValue());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 如果有更新,则保存回数据库
|
|
|
|
|
- if (dbNeedUpdate) {
|
|
|
|
|
- dbAttrValue = JSON.toJSONString(dbItems);
|
|
|
|
|
- objAttrValueService.updateObjAttrValue(dbAttr.getModelCode(), dbAttr.getObjCode(),
|
|
|
|
|
- dbAttr.getAttrKey(), dbAttrValue);
|
|
|
|
|
|
|
+ else {
|
|
|
|
|
+ // 记录异常数据但不更新
|
|
|
|
|
+ log.warn("检测到异常抄表数据 - 设备:{}, 测点:{}, 旧值:{}, 新值:{}, 原因:{}",
|
|
|
|
|
+ dbAttr.getObjCode(), pointId, dbAttr.getAttrValue(), syncCodesVal.getValue(),
|
|
|
|
|
+ validationResult.getReason());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -351,32 +355,61 @@ public class InDoorEnergyHandler extends BaseMeterDevHandler {
|
|
|
int cnt = 0;
|
|
int cnt = 0;
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- // 获取所有能源设备列表
|
|
|
|
|
- List<EmsDevice> deviceList = getDeviceList();
|
|
|
|
|
- List<MeterDevice> meterDeviceList = getMeterDeviceList();
|
|
|
|
|
- List<ElecMeterH> allElecMeterHList = new ArrayList<>();
|
|
|
|
|
-
|
|
|
|
|
- // 遍历每个能源设备
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(deviceList)) {
|
|
|
|
|
- for (EmsDevice emsDevice : deviceList) {
|
|
|
|
|
- // 产出表计小时计量数据
|
|
|
|
|
- MeterHourProdResult result = meterDevHourProd(emsDevice, meterDeviceList);
|
|
|
|
|
-
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(result.getElecMeterHList())) {
|
|
|
|
|
- elecMeterHService.insertBatch(result.getElecMeterHList());
|
|
|
|
|
- allElecMeterHList.addAll(result.getElecMeterHList());
|
|
|
|
|
|
|
+ // 计量设备-网关设备映射集合
|
|
|
|
|
+ Map<String, EmsDevice> refParentMap = getRefParentMap();
|
|
|
|
|
+
|
|
|
|
|
+ // 电表
|
|
|
|
|
+ List<MeterDevice> meterDeviceList = getMeterDeviceList(METER_MODEL_E);
|
|
|
|
|
+
|
|
|
|
|
+ // 计算电表小时数据
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(meterDeviceList)) {
|
|
|
|
|
+ Map<String, Price> priceMap = new ConcurrentHashMap<>();
|
|
|
|
|
+ Date date = DateUtils.adjustHour(new Date(), -1);
|
|
|
|
|
+ List<ElecMeterH> elecMeterHList = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (MeterDevice meterDevice : meterDeviceList) {
|
|
|
|
|
+ EmsDevice gwDevice = refParentMap.get(meterDevice.getDeviceCode());
|
|
|
|
|
+ ElecMeterH elecMeterH = workElecMeterReading(gwDevice, meterDevice);
|
|
|
|
|
+
|
|
|
|
|
+ if (null != elecMeterH) {
|
|
|
|
|
+ Price price = priceMap.computeIfAbsent(gwDevice.getAreaCode(),
|
|
|
|
|
+ k -> priceService.getElecHourPrice(gwDevice.getAreaCode(), date));
|
|
|
|
|
+ completeElecPrice(elecMeterH, price);
|
|
|
|
|
+ elecMeterHList.add(elecMeterH);
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(result.getWaterMeterHList())) {
|
|
|
|
|
- waterMeterHService.insertBatch(result.getWaterMeterHList());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(elecMeterHList)) {
|
|
|
|
|
+ elecMeterHService.insertBatch(elecMeterHList);
|
|
|
|
|
+ cnt += elecMeterHList.size();
|
|
|
|
|
+ generatePgSupplyData(elecMeterHList);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 水表
|
|
|
|
|
+ meterDeviceList = getMeterDeviceList(METER_MODEL_W);
|
|
|
|
|
+
|
|
|
|
|
+ // 计算水表小时数据
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(meterDeviceList)) {
|
|
|
|
|
+ Map<String, FdEnergyPriceConfig> priceMap = new ConcurrentHashMap<>();
|
|
|
|
|
+ List<WaterMeterH> waterMeterHList = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (MeterDevice meterDevice : meterDeviceList) {
|
|
|
|
|
+ EmsDevice gwDevice = refParentMap.get(meterDevice.getDeviceCode());
|
|
|
|
|
+ WaterMeterH waterMeterH = workWaterMeterReading(gwDevice, meterDevice);
|
|
|
|
|
|
|
|
- cnt += result.getElecMeterHList().size() + result.getWaterMeterHList().size();
|
|
|
|
|
|
|
+ if (null != waterMeterH) {
|
|
|
|
|
+ FdEnergyPriceConfig price = priceMap.computeIfAbsent(gwDevice.getAreaCode(),
|
|
|
|
|
+ k -> fdEnergyPriceConfigService.selectByAreaCode(gwDevice.getAreaCode(), 70));
|
|
|
|
|
+ completeWaterPrice(waterMeterH, price);
|
|
|
|
|
+ waterMeterHList.add(waterMeterH);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 统一处理市电供应数据(避免重复)
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(allElecMeterHList)) {
|
|
|
|
|
- generatePgSupplyData(allElecMeterHList);
|
|
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(waterMeterHList)) {
|
|
|
|
|
+ waterMeterHService.insertBatch(waterMeterHList);
|
|
|
|
|
+ cnt += waterMeterHList.size();
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -387,82 +420,53 @@ public class InDoorEnergyHandler extends BaseMeterDevHandler {
|
|
|
return cnt;
|
|
return cnt;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 修改后的单设备计量产出方法,返回详细结果
|
|
|
|
|
- */
|
|
|
|
|
- private MeterHourProdResult meterDevHourProd(EmsDevice emsDevice, List<MeterDevice> meterDeviceList) {
|
|
|
|
|
- MeterHourProdResult result = new MeterHourProdResult();
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- // 查询当前设备的接口属性值
|
|
|
|
|
- List<EmsObjAttrValue> attrValues = objAttrValueService.selectByObjCode(DEV_MODE_CODE,
|
|
|
|
|
- emsDevice.getDeviceCode());
|
|
|
|
|
- attrValues = attrValues.stream()
|
|
|
|
|
- // 过滤条件:attrKey以"interface"开头
|
|
|
|
|
- .filter(attr -> StringUtils.startsWith(attr.getAttrKey(), "interface"))
|
|
|
|
|
- // 收集为新的List
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
- Set<String> pointIdSet = getPointIds(attrValues);
|
|
|
|
|
-
|
|
|
|
|
- // 电表过滤
|
|
|
|
|
- List<MeterDevice> elecDevs = meterDeviceList.stream()
|
|
|
|
|
- .filter(device -> pointIdSet.contains(device.getDeviceCode()) && 45 == device.getMeterCls())
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
- // 电表抄表数据保存
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(elecDevs)) {
|
|
|
|
|
- List<ElecMeterH> elecMeterHList = saveElecMeterReading(emsDevice, elecDevs);
|
|
|
|
|
- result.setElecMeterHList(elecMeterHList);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 水表过滤
|
|
|
|
|
- List<MeterDevice> waterDevs = meterDeviceList.stream()
|
|
|
|
|
- .filter(device -> pointIdSet.contains(device.getDeviceCode()) && 70 == device.getMeterCls())
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
- // 水表抄表数据保存
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(waterDevs)) {
|
|
|
|
|
- List<WaterMeterH> waterMeterHList = saveWaterMeterReading(emsDevice, waterDevs);
|
|
|
|
|
- result.setWaterMeterHList(waterMeterHList);
|
|
|
|
|
|
|
+ private Map<String, EmsDevice> getRefParentMap() {
|
|
|
|
|
+ Map<String, EmsDevice> refParentMap = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ List<EmsObjAttrValue> attrValues = objAttrValueService.selectByAttrKey(GATEWAY_MODEL, "subDev");
|
|
|
|
|
+ Map<String, String> attrValueMap = attrValues.stream()
|
|
|
|
|
+ .collect(Collectors.toMap(EmsObjAttrValue::getObjCode, EmsObjAttrValue::getAttrValue));
|
|
|
|
|
+
|
|
|
|
|
+ // 网关设备列表
|
|
|
|
|
+ List<EmsDevice> gwDevices = getDeviceList();
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(gwDevices)) {
|
|
|
|
|
+ for (EmsDevice gwDevice : gwDevices) {
|
|
|
|
|
+ String subDevStr = attrValueMap.get(gwDevice.getDeviceCode());
|
|
|
|
|
+ if (StringUtils.isNotBlank(subDevStr)) {
|
|
|
|
|
+ JSONArray jsonArray = JSON.parseArray(subDevStr);
|
|
|
|
|
+ jsonArray.forEach(obj -> {
|
|
|
|
|
+ JSONObject jsonObject = (JSONObject) obj;
|
|
|
|
|
+ refParentMap.put(jsonObject.getString("deviceCode"), gwDevice);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- catch (Exception e) {
|
|
|
|
|
- log.error("meterDevHourProd error! deviceCode:{}", emsDevice.getDeviceCode(), e);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- return result;
|
|
|
|
|
|
|
+ return refParentMap;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private List<ElecMeterH> saveElecMeterReading(EmsDevice gwDevice, List<MeterDevice> deviceList) {
|
|
|
|
|
- Map<String, Price> priceMap = new ConcurrentHashMap<>();
|
|
|
|
|
- List<ElecMeterH> meterHList = new ArrayList<>();
|
|
|
|
|
- Date date = DateUtils.adjustHour(new Date(), -1);
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修改后的单设备计量产出方法,返回详细结果
|
|
|
|
|
+ */
|
|
|
|
|
|
|
|
- for (MeterDevice meterDevice : deviceList) {
|
|
|
|
|
- // 读取最新抄表值
|
|
|
|
|
- String newMeterReading = redisService.getCacheMapValue(gwDevice.getDeviceCode(),
|
|
|
|
|
- NEW_HOUR_READING + "-" + meterDevice.getDeviceCode());
|
|
|
|
|
|
|
+ private ElecMeterH workElecMeterReading(EmsDevice gwDevice, MeterDevice meterDevice) {
|
|
|
|
|
+ ElecMeterH elecMeterH = null;
|
|
|
|
|
|
|
|
- if (null != newMeterReading) {
|
|
|
|
|
- String lastCacheKey = LAST_HOUR_READING + "-" + meterDevice.getDeviceCode();
|
|
|
|
|
|
|
+ // 读取最新抄表值
|
|
|
|
|
+ String newMeterReading = redisService.getCacheMapValue(gwDevice.getDeviceCode(),
|
|
|
|
|
+ NEW_HOUR_READING + "-" + meterDevice.getDeviceCode());
|
|
|
|
|
|
|
|
- // 读取历史抄表
|
|
|
|
|
- String lastMeterReading = redisService.getCacheMapValue(gwDevice.getDeviceCode(), lastCacheKey);
|
|
|
|
|
|
|
+ if (null != newMeterReading) {
|
|
|
|
|
+ String lastCacheKey = LAST_HOUR_READING + "-" + meterDevice.getDeviceCode();
|
|
|
|
|
|
|
|
- ElecMeterH elecMeterH = getElecMeterH(gwDevice.getDeviceCode(), meterDevice, lastMeterReading,
|
|
|
|
|
- newMeterReading);
|
|
|
|
|
|
|
+ // 读取历史抄表
|
|
|
|
|
+ String lastMeterReading = redisService.getCacheMapValue(gwDevice.getDeviceCode(), lastCacheKey);
|
|
|
|
|
|
|
|
- if (null != elecMeterH) {
|
|
|
|
|
- Price price = priceMap.computeIfAbsent(gwDevice.getAreaCode(),
|
|
|
|
|
- k -> priceService.getElecHourPrice(gwDevice.getAreaCode(), date));
|
|
|
|
|
- completeElecPrice(elecMeterH, price);
|
|
|
|
|
- meterHList.add(elecMeterH);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ elecMeterH = getElecMeterH(gwDevice.getDeviceCode(), meterDevice, lastMeterReading, newMeterReading);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return meterHList;
|
|
|
|
|
|
|
+ return elecMeterH;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -530,35 +534,24 @@ public class InDoorEnergyHandler extends BaseMeterDevHandler {
|
|
|
return elecMeterH;
|
|
return elecMeterH;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private List<WaterMeterH> saveWaterMeterReading(EmsDevice gwDevice, List<MeterDevice> deviceList) {
|
|
|
|
|
- Map<String, FdEnergyPriceConfig> priceMap = new ConcurrentHashMap<>();
|
|
|
|
|
- List<WaterMeterH> meterHList = new ArrayList<>();
|
|
|
|
|
-
|
|
|
|
|
- for (MeterDevice meterDevice : deviceList) {
|
|
|
|
|
- // 读取最新抄表值
|
|
|
|
|
- String newMeterReading = redisService.getCacheMapValue(gwDevice.getDeviceCode(),
|
|
|
|
|
- NEW_HOUR_READING + "-" + meterDevice.getDeviceCode());
|
|
|
|
|
|
|
+ private WaterMeterH workWaterMeterReading(EmsDevice gwDevice, MeterDevice meterDevice) {
|
|
|
|
|
+ WaterMeterH waterMeterH = null;
|
|
|
|
|
|
|
|
- if (null != newMeterReading) {
|
|
|
|
|
- String lastCacheKey = LAST_HOUR_READING + "-" + meterDevice.getDeviceCode();
|
|
|
|
|
|
|
+ // 读取最新抄表值
|
|
|
|
|
+ String newMeterReading = redisService.getCacheMapValue(gwDevice.getDeviceCode(),
|
|
|
|
|
+ NEW_HOUR_READING + "-" + meterDevice.getDeviceCode());
|
|
|
|
|
|
|
|
- // 读取历史抄表
|
|
|
|
|
- String lastMeterReading = redisService.getCacheMapValue(gwDevice.getDeviceCode(), lastCacheKey);
|
|
|
|
|
|
|
+ if (null != newMeterReading) {
|
|
|
|
|
+ String lastCacheKey = LAST_HOUR_READING + "-" + meterDevice.getDeviceCode();
|
|
|
|
|
|
|
|
- // 组装水表抄报数据
|
|
|
|
|
- WaterMeterH waterMeterH = getWaterMeterH(gwDevice.getDeviceCode(), meterDevice, lastMeterReading,
|
|
|
|
|
- newMeterReading);
|
|
|
|
|
|
|
+ // 读取历史抄表
|
|
|
|
|
+ String lastMeterReading = redisService.getCacheMapValue(gwDevice.getDeviceCode(), lastCacheKey);
|
|
|
|
|
|
|
|
- if (null != waterMeterH) {
|
|
|
|
|
- FdEnergyPriceConfig price = priceMap.computeIfAbsent(gwDevice.getAreaCode(),
|
|
|
|
|
- k -> fdEnergyPriceConfigService.selectByAreaCode(gwDevice.getAreaCode(), 70));
|
|
|
|
|
- completeWaterPrice(waterMeterH, price);
|
|
|
|
|
- meterHList.add(waterMeterH);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 组装水表抄报数据
|
|
|
|
|
+ waterMeterH = getWaterMeterH(gwDevice.getDeviceCode(), meterDevice, lastMeterReading, newMeterReading);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return meterHList;
|
|
|
|
|
|
|
+ return waterMeterH;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -817,31 +810,6 @@ public class InDoorEnergyHandler extends BaseMeterDevHandler {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 单个设备的计量数据产出结果
|
|
|
|
|
- */
|
|
|
|
|
- private static class MeterHourProdResult {
|
|
|
|
|
- private List<ElecMeterH> elecMeterHList = new ArrayList<>();
|
|
|
|
|
-
|
|
|
|
|
- private List<WaterMeterH> waterMeterHList = new ArrayList<>();
|
|
|
|
|
-
|
|
|
|
|
- public List<ElecMeterH> getElecMeterHList() {
|
|
|
|
|
- return elecMeterHList;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void setElecMeterHList(List<ElecMeterH> elecMeterHList) {
|
|
|
|
|
- this.elecMeterHList = elecMeterHList;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public List<WaterMeterH> getWaterMeterHList() {
|
|
|
|
|
- return waterMeterHList;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void setWaterMeterHList(List<WaterMeterH> waterMeterHList) {
|
|
|
|
|
- this.waterMeterHList = waterMeterHList;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
* 数据验证结果内部类
|
|
* 数据验证结果内部类
|
|
|
*/
|
|
*/
|
|
|
private static class DataValidationResult {
|
|
private static class DataValidationResult {
|