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