Skip to content

Commit

Permalink
Merge pull request #234 from cheng521521/main
Browse files Browse the repository at this point in the history
add whale protocol query
  • Loading branch information
yanyanho committed Apr 16, 2024
2 parents 7082ecb + 90767d0 commit 958c123
Show file tree
Hide file tree
Showing 9 changed files with 328 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ public BaseResponse queryWhale(
@RequestBody QueryWhaleParams query) {
Pageable pageable = null;
if (query.getOrder() == 1) {
pageable = PageRequest.of(pageNumber - 1, pageSize, Sort.by(Sort.Direction.DESC, "amountUsd"));
pageable = PageRequest.of(pageNumber - 1, pageSize,
Sort.by(Sort.Direction.DESC, "amountUsd"));
} else {
pageable = PageRequest.of(pageNumber - 1, pageSize, Sort.by(Sort.Direction.ASC, "amountUsd"));
pageable = PageRequest.of(pageNumber - 1, pageSize,
Sort.by(Sort.Direction.ASC, "amountUsd"));
}
Page<Whale> whaleDataVos = whaleService.queryWhale(pageable, query);
return BaseResponse.successWithData(whaleDataVos);
Expand All @@ -119,10 +121,33 @@ public BaseResponse queryWhaleTx(
@RequestParam(defaultValue = "1") Integer pageNumber,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam String address) {
Pageable pageable = PageRequest.of(pageNumber - 1, pageSize, Sort.by(Sort.Direction.DESC, "createTime"));
Pageable pageable = PageRequest.of(pageNumber - 1, pageSize,
Sort.by(Sort.Direction.DESC, "createTime"));
Page<WhaleTxRow> whaleDataVos = whaleService.queryWhaleTx(pageable, address);
return BaseResponse.successWithData(whaleDataVos);
}

@GetMapping("/query/whale/protocol")
public BaseResponse queryWhaleProtocol(
@RequestParam(defaultValue = "1") Integer pageNumber,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam String address) {
Pageable pageable = PageRequest.of(pageNumber - 1, pageSize,
Sort.by(Sort.Direction.DESC, "createTime"));
return BaseResponse.successWithData(whaleProtocolService.queryWhaleProtocol(address, pageable));
}

@GetMapping("/query/whale/chain/token")
public BaseResponse queryWhaleChainToken(@RequestParam String whaleAddress,
@RequestParam Integer update) {
return BaseResponse.successWithData(whaleService.getUserTotalBalance(whaleAddress, update));
}

@GetMapping("/query/whale/chain/value")
public BaseResponse queryWhaleChainValue(@RequestParam String whaleAddress,@RequestParam Integer update) {
return BaseResponse.successWithData(whaleService.getUserTokenList(whaleAddress,update));
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.dl.officialsite.defi.dao;

import com.dl.officialsite.defi.entity.WhaleChainToken;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
* @ClassName whaleChainTokenRepository
* @Author jackchen
* @Date 2024/4/15 22:52
* @Description TODO
**/
public interface WhaleChainTokenRepository extends JpaRepository<WhaleChainToken, Long>,
JpaSpecificationExecutor<WhaleChainToken> {

List<WhaleChainToken> findByWhaleAddress(String whaleAddress);

@Query(value = "select * from whale_chain_token order by id DESC limit 1", nativeQuery = true)
WhaleChainToken findAgoWhaleChainToken();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.dl.officialsite.defi.dao;

import com.dl.officialsite.defi.entity.WhaleChainValue;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
* @ClassName WhaleChainValueRepository
* @Author jackchen
* @Date 2024/4/15 22:27
* @Description WhaleChainValueRepository
**/
public interface WhaleChainValueRepository extends JpaRepository<WhaleChainValue, Long>,
JpaSpecificationExecutor<WhaleChainValue> {

@Query(value = "select * from whale_chain_value where whale_address = ?1", nativeQuery = true)
List<WhaleChainValue> findByWhaleAddress(String whaleAddress);
}
38 changes: 38 additions & 0 deletions src/main/java/com/dl/officialsite/defi/entity/WhaleChainToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.dl.officialsite.defi.entity;

import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

/**
* @ClassName WhaleChainToken
* @Author jackchen
* @Date 2024/4/15 22:46
* @Description WhaleChainToken
**/
@Data
@Entity
@Table(name = "whale_chain_token")
@EntityListeners(AuditingEntityListener.class)
public class WhaleChainToken {

@Id
private Long id;

private String whaleAddress;

private String chainName;

private String tokenAddress;

private String tokenSymbol;

private String amount;

private String price;

private Integer decimals;
}
36 changes: 36 additions & 0 deletions src/main/java/com/dl/officialsite/defi/entity/WhaleChainValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.dl.officialsite.defi.entity;

import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

/**
* @ClassName WhaleChainValue
* @Author jackchen
* @Date 2024/4/15 22:16
* @Description WhaleChainValue
**/
@Data
@Entity
@Table(name = "whale_chain_value")
@EntityListeners(AuditingEntityListener.class)
public class WhaleChainValue {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String whaleAddress;

private String chainId;

private String chainName;

private String value;

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ public class WhaleProtocol {

private Integer chainId;

private Long createTime;


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import lombok.extern.slf4j.Slf4j;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
* @ClassName WhaleProtocolService
Expand Down Expand Up @@ -198,4 +206,20 @@ private Whale convertToWhale(JSONObject account) {
whale.setAddress(address);
return whale;
}

public Page<WhaleProtocol> queryWhaleProtocol(String address, Pageable pageable) {
Specification<WhaleProtocol> queryParam = new Specification<WhaleProtocol>() {
@Override
public Predicate toPredicate(Root<WhaleProtocol> root, CriteriaQuery<?> criteriaQuery,
CriteriaBuilder criteriaBuilder) {
List<Predicate> predicates = new ArrayList<>();
if (StringUtils.hasText(address)) {
predicates.add(criteriaBuilder.equal(root.get("whaleAddress"), address));
}
return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
}
};
return whaleProtocolRepository.findAll(queryParam, pageable);
}
}

Loading

0 comments on commit 958c123

Please sign in to comment.