20260121:优化引用模型取值逻辑
This commit is contained in:
parent
e7e1a9d577
commit
652a32b797
@ -517,8 +517,13 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
// 判断是否有纯计算物模型 有:需要获取设备级别物模型 无:直接使用产品级别物模型即可
|
||||
boolean isCalculated = thingsModelValueRemarkItem.stream().anyMatch(ThingsModelSimpleItem::isCalculated);
|
||||
Map<String, ThingsModelValueItem> calculatedModelMap = new HashMap<>();
|
||||
Map<String, String> thingsModelValueMap = new HashMap<>();
|
||||
if (isCalculated) {
|
||||
calculatedModelMap = itslCache.getDeviceCalculatedModelMap(serialNumber);
|
||||
thingsModelValueMap = thingsModelValueRemarkItem.stream().filter(things -> !things.isCalculated())
|
||||
.collect(Collectors.toMap(ThingsModelSimpleItem::getId,
|
||||
ThingsModelSimpleItem::getValue,
|
||||
(oldValue, newValue) -> oldValue));
|
||||
}
|
||||
for (ThingsModelSimpleItem item : thingsModelValueRemarkItem) {
|
||||
String identity = item.getId();
|
||||
@ -561,41 +566,13 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
// 获取引用的其他物模型的值
|
||||
for (String refIdentifier : referencedIdentifiers) {
|
||||
if (!refIdentifier.equals(identity)) { // 避免循环引用自己
|
||||
try {
|
||||
// 优先从当前消息中查找
|
||||
String refValue = null;
|
||||
for (ThingsModelSimpleItem currentItem : thingsModelValueRemarkItem) {
|
||||
String currentId = currentItem.getId();
|
||||
if (currentId.startsWith("array_")) {
|
||||
currentId = currentId.substring(9);
|
||||
}
|
||||
if (currentId.equals(refIdentifier)) {
|
||||
refValue = currentItem.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果当前消息中没有,再从缓存读取
|
||||
if (refValue == null) {
|
||||
ValueItem refValueItem = itslValueCache.getCacheIdentifier(
|
||||
input.getProductId(),
|
||||
serialNumber,
|
||||
refIdentifier);
|
||||
if (refValueItem != null && StringUtils.isNotEmpty(refValueItem.getValue())) {
|
||||
refValue = refValueItem.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
String refValue = thingsModelValueMap.get(refIdentifier);
|
||||
if (refValue != null && !refValue.isEmpty()) {
|
||||
params.put("{" + refIdentifier + "}", refValue);
|
||||
} else {
|
||||
params.put("{" + refIdentifier + "}", "0");
|
||||
log.warn("=>计算公式引用的物模型值不存在[{}],标识符:[{}],使用默认值0", input.getProductId(), refIdentifier);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("=>获取计算公式引用的物模型值失败[{}],标识符:[{}],错误:{}",
|
||||
input.getProductId(), refIdentifier, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user