Skip to content

Commit

Permalink
Merge pull request #63 from yanyanho/main
Browse files Browse the repository at this point in the history
fix the redpacket sync task cause the  db unconnect
  • Loading branch information
yanyanho authored Dec 2, 2023
2 parents 4382661 + d60f63d commit 2ce5fb9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 42 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/dl/officialsite/hiring/Hiring.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


public class Hiring {

private String headline;
private String employer;
private String jd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ public interface RedPacketRepository extends JpaRepository<RedPacket, String>,

RedPacket findByIdAndStatus(@Param("id") String id, @Param("status") Integer status);

List<RedPacket> findByStatus(@Param("status") Integer status);

}

82 changes: 45 additions & 37 deletions src/main/java/com/dl/officialsite/redpacket/RedPacketService.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class RedPacketService {

@Scheduled(cron = "0 0/3 * * * ? ")
public void updateRedpacketStatus() throws IOException {
log.info("schedule task begin --------------------- " );
log.info("schedule task begin --------------------- ");
HttpPost request = new HttpPost("https://api.studio.thegraph.com/proxy/55957/dapp-learning-redpacket/version/latest");
request.setHeader("Content-Type", "application/json");
// Define your GraphQL query
Expand Down Expand Up @@ -87,50 +87,58 @@ public void updateRedpacketStatus() throws IOException {
JsonObject data = jsonObject.getAsJsonObject("data");
JsonArray redpacketsArray = data.getAsJsonArray("redpackets");

//log.info("redpacket array : " + redpacketsArray);
log.info("redpacket array : " + redpacketsArray);
List<RedPacket> redPacketList = redPacketRepository.findByStatus(0);

for (int i = 0; i < redpacketsArray.size(); i++) {
// Access each element in the array
JsonObject redpacketObject = redpacketsArray.get(i).getAsJsonObject();
// log.info("redpackt object : " + redpacketObject);
// log.info("redpackt object : " + redpacketObject);
String id = redpacketObject.get("id").getAsString();
// log.info("id: " + id);
RedPacket redPacket = redPacketRepository.findByIdAndStatus(id,0);
log.info("redPacket: " + redPacket);
if(redPacket == null )
continue;
String hasRefundedOrAllClaimed = redpacketObject.get("hasRefundedOrAllClaimed").getAsString();
Boolean claimed = redpacketObject.get("hasRefundedOrAllClaimed").getAsBoolean();

if (claimed) {
log.info( "redpacket id: "+id + "claimed: " );
redPacket.setStatus(1);
redPacketRepository.save(redPacket);
continue;
}
JsonArray claimers = redpacketObject.getAsJsonArray("claimers");

// redPacket.getAddressList() is the total claimer.
if(claimers.size() == redPacket.getAddressList().size()) {
log.info( "redpacket id: "+id + " aLL claimed " );
redPacket.setStatus(1);
redPacketRepository.save(redPacket);
continue;
}
// log.info("id: " + id);
for (int j = 0; j < redPacketList.size(); j++) {

RedPacket redPacket = redPacketList.get(j);
log.info("redPacket: " + redPacket);
if (!redPacketList.get(j).getId().equals(id))
continue;

// Boolean claimed = redpacketObject.get("hasRefundedOrAllClaimed").getAsBoolean();
//
// if (claimed) {
// log.info("redpacket id: " + id + "claimed: ");
// redPacket.setStatus(1);
// redPacketRepository.save(redPacket);
// continue;
// }


JsonArray claimers = redpacketObject.getAsJsonArray("claimers");

// redPacket.getAddressList() is the total claimer.
if (claimers.size() == redPacket.getAddressList().size()) {
log.info("redpacket id: " + id + " aLL claimed ");
redPacket.setStatus(1);
redPacketRepository.save(redPacket);
continue;
}

if (claimers.size() > redPacket.getClaimedAddress().size()) {
ArrayList<String> claimersList = new ArrayList<>();
if (claimers.size() > redPacket.getClaimedAddress().size()) {
ArrayList<String> claimersList = new ArrayList<>();

for (int j = 0; j < claimers.size(); j++) {
String s = claimers.get(j).getAsJsonObject().get("claimer").getAsString();
//log.info("claimer address: " + s);
claimersList.add(s);
}
redPacket.setClaimedAddress(claimersList);
log.info( "update claimed address : " + id );
redPacketRepository.save(redPacket);
}
//todo
for (int k = 0; k < claimers.size(); k++) {
String s = claimers.get(k).getAsJsonObject().get("claimer").getAsString();
//log.info("claimer address: " + s);
claimersList.add(s);
}
redPacket.setClaimedAddress(claimersList);
log.info("update claimed address : " + id);
redPacketRepository.save(redPacket);


}
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/DB/data-mysql.SQL
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

INSERT INTO team ( team_name, team_profile, administrator, authority)
VALUES ("Dapp-Learning DAO co-founders", "Initial founding members and those who contributed significantly, Taking charge of community vault.", "0x1F7b953113f4dFcBF56a1688529CC812865840e1", 10),
("Dapp-Learning DAO builders", "Those who are willing to participate in the community and make outstanding contributions to community building", "", 9),
("Dapp-Learning DAO PR reviewers", "Responsible for review PR of our repository", "", 8),
("Dapp-Learning DAO sharing group", "sharing in Dapp-Learning and earn reward", "", 7),
("Dapp-Learning DAO translation group", "Translate blockchain-related documents ", "", 6);
("Dapp-Learning DAO builders", "Those who are willing to participate in the community and make outstanding contributions to community building", "0x1F7b953113f4dFcBF56a1688529CC812865840e1", 9),
("Dapp-Learning DAO PR reviewers", "Responsible for review PR of our repository", "0x1F7b953113f4dFcBF56a1688529CC812865840e1", 8),
("Dapp-Learning DAO sharing group", "sharing in Dapp-Learning and earn reward", "0x1F7b953113f4dFcBF56a1688529CC812865840e1", 7),
("Dapp-Learning DAO translation group", "Translate blockchain-related documents ", "0x1F7b953113f4dFcBF56a1688529CC812865840e1", 6);
2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ spring:
username: root
#password: 12345678
password: {{SPRING_DATASOURCE_PASSWORD}}
maximum-pool-size: 20

jpa:
hibernate:
ddl-auto: update
Expand Down

0 comments on commit 2ce5fb9

Please sign in to comment.