Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(msc-integration): remove duplicate history data in synchronization #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,21 @@ private void syncPropertiesHistory(Device device, long lastSyncTime) {
page.getData().getList().forEach(item -> {
val objectMapper = mscClientProvider.getMscClient().getObjectMapper();
val properties = objectMapper.convertValue(item.getProperties(), JsonNode.class);
saveHistoryData(device.getKey(), null, properties, item.getTs() == null ? TimeUtils.currentTimeMillis() : item.getTs(), isLatestData.get());
saveHistoryData(device.getKey(), null, properties, truncateTimestampMs(item.getTs()), isLatestData.get());
if (isLatestData.get()) {
isLatestData.set(false);
}
});
}
}

private static long truncateTimestampMs(Long ts) {
if (ts == null) {
return TimeUtils.currentTimeMillis();
}
return ts - ts % 1000;
}

public void saveHistoryData(String deviceKey, String eventId, JsonNode data, long timestampMs, boolean isLatestData) {
val payload = eventId == null
? MscTslUtils.convertJsonNodeToExchangePayload(deviceKey, data)
Expand Down