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);
|
boolean isCalculated = thingsModelValueRemarkItem.stream().anyMatch(ThingsModelSimpleItem::isCalculated);
|
||||||
Map<String, ThingsModelValueItem> calculatedModelMap = new HashMap<>();
|
Map<String, ThingsModelValueItem> calculatedModelMap = new HashMap<>();
|
||||||
|
Map<String, String> thingsModelValueMap = new HashMap<>();
|
||||||
if (isCalculated) {
|
if (isCalculated) {
|
||||||
calculatedModelMap = itslCache.getDeviceCalculatedModelMap(serialNumber);
|
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) {
|
for (ThingsModelSimpleItem item : thingsModelValueRemarkItem) {
|
||||||
String identity = item.getId();
|
String identity = item.getId();
|
||||||
@ -561,40 +566,12 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||||||
// 获取引用的其他物模型的值
|
// 获取引用的其他物模型的值
|
||||||
for (String refIdentifier : referencedIdentifiers) {
|
for (String refIdentifier : referencedIdentifiers) {
|
||||||
if (!refIdentifier.equals(identity)) { // 避免循环引用自己
|
if (!refIdentifier.equals(identity)) { // 避免循环引用自己
|
||||||
try {
|
String refValue = thingsModelValueMap.get(refIdentifier);
|
||||||
// 优先从当前消息中查找
|
if (refValue != null && !refValue.isEmpty()) {
|
||||||
String refValue = null;
|
params.put("{" + refIdentifier + "}", refValue);
|
||||||
for (ThingsModelSimpleItem currentItem : thingsModelValueRemarkItem) {
|
} else {
|
||||||
String currentId = currentItem.getId();
|
params.put("{" + refIdentifier + "}", "0");
|
||||||
if (currentId.startsWith("array_")) {
|
log.warn("=>计算公式引用的物模型值不存在[{}],标识符:[{}],使用默认值0", input.getProductId(), refIdentifier);
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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