Skip to content

Commit

Permalink
add lastupdatetimestamp update
Browse files Browse the repository at this point in the history
  • Loading branch information
liberhe committed Jan 22, 2024
1 parent a549a1a commit 1011297
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/main/java/com/dl/officialsite/redpacket/RedPacketService.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class RedPacketService {

public CloseableHttpClient httpClient = HttpClients.createDefault();

private String lastUpdateTimestamp= "";

@Scheduled(cron = "${jobs.redpacket.corn:0/10 * * * * ?}")

public void updateRedpacketStatus() throws IOException {
Expand All @@ -60,13 +62,22 @@ public void updateRedpacketStatus() throws IOException {
JsonObject jsonObject = JsonParser.parseString(jsonResponse).getAsJsonObject();
JsonObject data = jsonObject.getAsJsonObject("data");
JsonArray redpacketsArray = data.getAsJsonArray("redpackets");
JsonArray lastupdatesArray = data.getAsJsonArray("lastupdates");
String lastTimestampFromGraph = lastupdatesArray.get(0).getAsString();
if(Objects.equals(lastTimestampFromGraph, lastUpdateTimestamp)){
return;
} else {
lastUpdateTimestamp = lastTimestampFromGraph;
}


List<RedPacket> redPacketList = redPacketRepository.findByStatusAndChainId(0, chainId);

for (int i = 0; i < redpacketsArray.size(); i++) {
// Access each element in the array
JsonObject redpacketObject = redpacketsArray.get(i).getAsJsonObject();

log.info(redpacketObject.toString());
//log.info(redpacketObject.toString());
Long id = redpacketObject.get("nonce").getAsLong();
// String name = redpacketObject.get("name").getAsString();
for (int j = 0; j < redPacketList.size(); j++) {
Expand Down Expand Up @@ -138,7 +149,10 @@ private HttpEntity getHttpEntityFromChain(String chainId) throws IOException {
" claimer" +
" claimedValue " +
" }" +
" }" +

" lastupdates ( orderBy : lastupdateTimestamp , orderDirection: desc) {\n" +
" lastupdateTimestamp\n" +
" }" +
"}\"";


Expand Down

0 comments on commit 1011297

Please sign in to comment.