20260401:网关设备跨计算数据推送(bug重复推送数据)
This commit is contained in:
parent
a3a5b6a719
commit
652caf9157
@ -13,17 +13,17 @@ import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.common.utils.wechat.WechatUtils;
|
||||
import com.fastbee.common.wechat.WeChatAppResult;
|
||||
import com.fastbee.iot.cache.ITSLCache;
|
||||
import com.fastbee.iot.domain.SubGateway;
|
||||
import com.fastbee.iot.domain.PushModelItem;
|
||||
import com.fastbee.iot.domain.SocialUser;
|
||||
import com.fastbee.iot.domain.ThingsModel;
|
||||
import com.fastbee.iot.domain.SubGateway;
|
||||
import com.fastbee.iot.domain.ThingsModelPushConfig;
|
||||
import com.fastbee.iot.model.ThingsModels.ThingsModelValueItem;
|
||||
import com.fastbee.iot.model.ThingsModels.ValueItem;
|
||||
import com.fastbee.iot.model.gateWay.SubDeviceListVO;
|
||||
import com.fastbee.iot.service.ISubGatewayService;
|
||||
import com.fastbee.iot.service.IThingsModelService;
|
||||
import com.fastbee.iot.service.IThingsModelPushConfigService;
|
||||
import com.fastbee.iot.service.ISocialUserService;
|
||||
import com.fastbee.iot.service.ISubGatewayService;
|
||||
import com.fastbee.iot.service.IThingsModelPushConfigService;
|
||||
import com.fastbee.iot.service.IThingsModelService;
|
||||
import com.fastbee.notify.core.wechat.vo.TemplateDataVo;
|
||||
import com.fastbee.notify.core.wechat.vo.WeChatPublicAccountPushVO;
|
||||
import com.fastbee.notify.domain.NotifyChannel;
|
||||
@ -161,15 +161,16 @@ public class ThingsModelPushHandler {
|
||||
}
|
||||
Map<String, ValueItem> cacheMap = itslCache.getSimpleThingsModelValueItemByCache(redisKey);
|
||||
Map<Integer, SubDeviceListVO> subDeviceBySlaveId = null;
|
||||
Map<String, ThingsModel> calculatedModelCache = new HashMap<>();
|
||||
Map<String, ThingsModelValueItem> calculatedModelCache = new HashMap<>();
|
||||
|
||||
// 设备类型
|
||||
Integer deviceType = config.getDeviceType();
|
||||
|
||||
for (PushModelItem item : config.getItems()) {
|
||||
ValueItem valueItem = cacheMap.get(item.getIdentifier());
|
||||
String value;
|
||||
Date ts;
|
||||
if (valueItem != null) {
|
||||
value = valueItem.getValue();
|
||||
ts = valueItem.getTs();
|
||||
} else {
|
||||
if (deviceType != null && deviceType == 2) {
|
||||
// 如果缓存里没有,尝试按网关计算物模型公式计算(跨设备引用)
|
||||
if (subDeviceBySlaveId == null) {
|
||||
subDeviceBySlaveId = loadSubDeviceBySlaveId(config.getDeviceId());
|
||||
@ -177,6 +178,9 @@ public class ThingsModelPushHandler {
|
||||
ComputedValue computed = tryComputeGatewayCalculatedValue(config, serialNumber, item.getIdentifier(), subDeviceBySlaveId, calculatedModelCache);
|
||||
value = computed != null ? computed.value : null;
|
||||
ts = computed != null ? computed.ts : null;
|
||||
} else {
|
||||
value = valueItem.getValue();
|
||||
ts = valueItem.getTs();
|
||||
}
|
||||
if (config.getLastPushTime() != null && ts != null && ts.before(config.getLastPushTime())) {
|
||||
log.warn("[Push] configId={} sn={} item={} value={} 时间{}早于上次推送时间{},跳过",
|
||||
@ -259,27 +263,17 @@ public class ThingsModelPushHandler {
|
||||
String gwSerialNumber,
|
||||
String identifier,
|
||||
Map<Integer, SubDeviceListVO> subDeviceBySlaveId,
|
||||
Map<String, ThingsModel> calculatedModelCache) {
|
||||
Map<String, ThingsModelValueItem> calculatedModelCache) {
|
||||
if (config == null || config.getProductId() == null || StringUtils.isEmpty(identifier)) {
|
||||
return null;
|
||||
}
|
||||
ThingsModel model;
|
||||
ThingsModelValueItem model;
|
||||
if (calculatedModelCache != null && calculatedModelCache.containsKey(identifier)) {
|
||||
model = calculatedModelCache.get(identifier);
|
||||
} else {
|
||||
ThingsModel query = new ThingsModel();
|
||||
query.setProductId(config.getProductId());
|
||||
query.setIdentifier(identifier);
|
||||
query.setIsCalculated(1);
|
||||
query.setSerialNumber(gwSerialNumber);
|
||||
try {
|
||||
model = thingsModelService.selectSingleThingsModel(query);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
if (calculatedModelCache != null) {
|
||||
calculatedModelCache.put(identifier, model);
|
||||
}
|
||||
Map<String, ThingsModelValueItem> calculatedModelMap = itslCache.getDeviceCalculatedModelMap(gwSerialNumber);
|
||||
calculatedModelCache.putAll(calculatedModelMap);
|
||||
model = calculatedModelMap.get(identifier);
|
||||
}
|
||||
if (model == null || model.getIsCalculated() == null ||
|
||||
model.getIsCalculated() != 1 || StringUtils.isEmpty(model.getFormula())) {
|
||||
@ -312,9 +306,10 @@ public class ThingsModelPushHandler {
|
||||
val = v.getValue();
|
||||
}
|
||||
if (v != null && v.getTs() != null) {
|
||||
if (maxTs == null || v.getTs().after(maxTs)) {
|
||||
maxTs = v.getTs();
|
||||
}
|
||||
// if (maxTs == null || v.getTs().after(maxTs)) {
|
||||
// maxTs = v.getTs();
|
||||
// }
|
||||
maxTs = v.getTs();
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user