|
|
@@ -14,8 +14,9 @@ import com.crm.rely.backend.core.exception.ServiceException;
|
|
|
import com.crm.rely.backend.core.pojo.table.SysConfigTable;
|
|
|
import com.crm.rely.backend.model.config.VaultodyConfig;
|
|
|
import com.crm.rely.backend.model.constant.ConfigConstants;
|
|
|
-import com.crm.rely.backend.model.dto.vaultody.vaults.VaultTransaction;
|
|
|
+import com.crm.rely.backend.model.constant.ManagerConstants;
|
|
|
import com.crm.rely.backend.model.dto.vaultody.vaults.TransactionItemDto;
|
|
|
+import com.crm.rely.backend.model.dto.vaultody.vaults.VaultTransaction;
|
|
|
import com.crm.rely.backend.model.dto.vaultody.vaults.VaultodyVaultsListDto;
|
|
|
import com.crm.rely.backend.model.dto.vaultody.vaults.response.*;
|
|
|
import com.crm.rely.backend.model.entity.vaultody.vaults.VaultTransactionsEntity;
|
|
|
@@ -28,7 +29,6 @@ import com.crm.rely.backend.util.UUIDUtil;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
-import org.jetbrains.annotations.NotNull;
|
|
|
import org.jsoup.Connection;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -41,6 +41,7 @@ import javax.crypto.spec.SecretKeySpec;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@@ -70,7 +71,7 @@ public class VaultodyServiceImpl implements VaultodyService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
+ public static void main2(String[] args) {
|
|
|
String s = "{\n" +
|
|
|
" \"apiKey\": \"6f3cc6caf513a5cde2df5d3ed805e3703d4d43b2\",\n" +
|
|
|
" \"apiSecret\": \"MLjTUAYgxSM2dg==\",\n" +
|
|
|
@@ -86,6 +87,46 @@ public class VaultodyServiceImpl implements VaultodyService {
|
|
|
System.out.println(AESUtil.decrypt(AESUtil.encrypt(s, "bfa5559109f94c78af615bcf00d52060"), "bfa5559109f94c78af615bcf00d52060"));
|
|
|
}
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String s = "{\n" +
|
|
|
+ " \"apiKey\": \"6f3cc6caf513a5cde2df5d3ed805e3703d4d43b2\",\n" +
|
|
|
+ " \"apiSecret\": \"MLjTUAYgxSM2dg==\",\n" +
|
|
|
+ " \"passphrase\": \"7UGMi2*t0h\",\n" +
|
|
|
+ " \"vaultId\": \"\",\n" +
|
|
|
+ " \"baseUrl\": \"https://rest.vaultody.com\",\n" +
|
|
|
+ " \"vaultsListUrl\": \"/vaults/test\",\n" +
|
|
|
+ " \"network\": \"\",\n" +
|
|
|
+ " \"vaultsTransactionsPathTemplate\": \"/vaults/%s/transactions\",\n" +
|
|
|
+ " \"webhooksPassphrase\": \"\",\n" +
|
|
|
+ " \"vaultodyList\": [\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"apiKey\": \"6f3cc6caf513a5cde2df5d3ed805e3703d4d43b2\",\n" +
|
|
|
+ " \"apiSecret\": \"MLjTUAYgxSM2dg==\",\n" +
|
|
|
+ " \"passphrase\": \"7UGMi2*t0h\",\n" +
|
|
|
+ " \"vaultId\": \"69cb34038d64830006453c0c\",\n" +
|
|
|
+ " \"baseUrl\": \"https://rest.vaultody.com\",\n" +
|
|
|
+ " \"vaultsListUrl\": \"/vaults/test\",\n" +
|
|
|
+ " \"network\": \"\",\n" +
|
|
|
+ " \"vaultsTransactionsPathTemplate\": \"/vaults/%s/transactions\",\n" +
|
|
|
+ " \"webhooksPassphrase\": \"\"\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"apiKey\": \"002key\",\n" +
|
|
|
+ " \"apiSecret\": \"002pwd\",\n" +
|
|
|
+ " \"passphrase\": \"7UGMi2*t0h\",\n" +
|
|
|
+ " \"vaultId\": \"002\",\n" +
|
|
|
+ " \"baseUrl\": \"https://rest.vaultody.com\",\n" +
|
|
|
+ " \"vaultsListUrl\": \"/vaults/test\",\n" +
|
|
|
+ " \"network\": \"\",\n" +
|
|
|
+ " \"vaultsTransactionsPathTemplate\": \"/vaults/%s/transactions\",\n" +
|
|
|
+ " \"webhooksPassphrase\": \"\"\n" +
|
|
|
+ " }\n" +
|
|
|
+ " ]\n" +
|
|
|
+ "}";
|
|
|
+ System.out.println(AESUtil.encrypt(s, "bfa5559109f94c78af615bcf00d52060"));
|
|
|
+ System.out.println(AESUtil.decrypt(AESUtil.encrypt(s, "bfa5559109f94c78af615bcf00d52060"), "bfa5559109f94c78af615bcf00d52060"));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Coin
|
|
|
*/
|
|
|
@@ -161,6 +202,30 @@ public class VaultodyServiceImpl implements VaultodyService {
|
|
|
return vaultodyConfig;
|
|
|
}
|
|
|
|
|
|
+ public VaultodyConfig getVaultodyConfig(String vaultId) {
|
|
|
+ SysVaultodyConfigTable configTable = vaultodyConfigService.getByCode(ConfigConstants.VAULTODY_MANAGER_CONFIG);
|
|
|
+ if (configTable == null) {
|
|
|
+ throw ServiceException.exception(Constants.SYSTEM_ERROR);
|
|
|
+ }
|
|
|
+ String aesKey = getPropertyKey();
|
|
|
+
|
|
|
+ String property = AESUtil.decrypt(configTable.getValue(), aesKey);
|
|
|
+ System.out.println(property);
|
|
|
+ VaultodyConfig vaultodyConfig = JSON.parseObject(property, VaultodyConfig.class);
|
|
|
+ List<VaultodyConfig> vaultodyList = vaultodyConfig.getVaultodyList();
|
|
|
+ if(CollectionUtils.isEmpty(vaultodyList)){
|
|
|
+ throw ServiceException.exception(ManagerConstants.NOT_PERMIT);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, VaultodyConfig> list = vaultodyList.stream().collect(Collectors.toMap(VaultodyConfig::getVaultId, v -> v));
|
|
|
+ VaultodyConfig config = new VaultodyConfig();
|
|
|
+ if(list.containsKey(vaultId)){
|
|
|
+ config = list.get(vaultId);
|
|
|
+ }
|
|
|
+
|
|
|
+ return config;
|
|
|
+ }
|
|
|
+
|
|
|
private String getPropertyKey() throws ServiceException {
|
|
|
SysConfigTable table = sysConfigService.getByCode(ConfigConstants.VAULTODY_FINANCE_PROPERTY_KEY);
|
|
|
if (table == null) {
|
|
|
@@ -214,9 +279,8 @@ public class VaultodyServiceImpl implements VaultodyService {
|
|
|
return BaseResultDto.success(dtos);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public BaseResultDto vaultsTransactions(VaultTransactionsEntity entity) throws Exception{
|
|
|
- VaultodyConfig config = getVaultodyConfig();
|
|
|
+ public VaultTransaction query3Items(VaultTransactionsEntity entity) throws Exception{
|
|
|
+ VaultodyConfig config = getVaultodyConfig(entity.getVaultId());
|
|
|
String apiKey = config.getApiKey();
|
|
|
String apiSecret = config.getApiSecret(); // Base64编码的secret
|
|
|
String passphrase = config.getPassphrase();
|
|
|
@@ -250,7 +314,8 @@ public class VaultodyServiceImpl implements VaultodyService {
|
|
|
Connection.Response response = HttpUtil.get(baseUrl + requestPath, headers, params);
|
|
|
log.info("response.statusCode: {} , response.body: {}",response.statusCode() , response.body());
|
|
|
if (response.statusCode() != 200) {
|
|
|
- return BaseResultDto.error(response.statusMessage());
|
|
|
+ log.error("response.statusCode() != 200,{}","3Item Error!");
|
|
|
+ throw ServiceException.exception(Constants.SYSTEM_ERROR);
|
|
|
}
|
|
|
TransactionResponse responseDto = JSON.parseObject(response.body(), TransactionResponse.class);
|
|
|
ResponseData data = responseDto.getData();
|
|
|
@@ -274,7 +339,7 @@ public class VaultodyServiceImpl implements VaultodyService {
|
|
|
recipient.setAmount("0.0003");
|
|
|
recipient.setAmountUnit("ETH");
|
|
|
recipient.setIsVaultAddress("false");
|
|
|
- recipient.setLabel("Address name");
|
|
|
+ recipient.setLabel("收款钱包名称");
|
|
|
recipients.add(recipient);
|
|
|
|
|
|
List<TransactionParticipant> senders = new LinkedList<>();
|
|
|
@@ -284,7 +349,7 @@ public class VaultodyServiceImpl implements VaultodyService {
|
|
|
sender.setAmount("0.0003");
|
|
|
sender.setAmountUnit("ETH");
|
|
|
sender.setIsVaultAddress("true");
|
|
|
- sender.setLabel("Address name");
|
|
|
+ sender.setLabel("付款钱包名称");
|
|
|
senders.add(sender);
|
|
|
|
|
|
|
|
|
@@ -301,7 +366,7 @@ public class VaultodyServiceImpl implements VaultodyService {
|
|
|
data.setItems(items);
|
|
|
}
|
|
|
VaultTransaction vaultTransaction = getVaultTransaction(data);
|
|
|
- return BaseResultDto.success(vaultTransaction);
|
|
|
+ return vaultTransaction;
|
|
|
}
|
|
|
|
|
|
private VaultTransaction getVaultTransaction(ResponseData data) {
|
|
|
@@ -329,6 +394,8 @@ public class VaultodyServiceImpl implements VaultodyService {
|
|
|
dto.setMinedInBlockHeight(item.getMinedInBlockHeight());
|
|
|
dto.setFeeAmount(item.getTransactionFee().getAmount());
|
|
|
dto.setFeeAmountUnit(item.getTransactionFee().getAmountUnit());
|
|
|
+ dto.setSenderLabel(item.getSenders().get(0).getLabel());
|
|
|
+ dto.setRecipientLabel(item.getRecipients().get(0).getLabel());
|
|
|
list.add(dto);
|
|
|
}
|
|
|
vaultTransaction.setList(list);
|
|
|
@@ -336,9 +403,8 @@ public class VaultodyServiceImpl implements VaultodyService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<TransactionItemDto> queryExportItems (VaultTransactionsEntity entity) throws Exception{
|
|
|
- VaultTransaction result = (VaultTransaction)vaultsTransactions(entity).getData();
|
|
|
- return result.getList();
|
|
|
+ public List<TransactionItemTable> queryExportItems (VaultTransactionsEntity entity) throws Exception{
|
|
|
+ return finAllByVaultId(entity.getVaultId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -352,12 +418,19 @@ public class VaultodyServiceImpl implements VaultodyService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public VaultTransaction vaultTransaction(VaultTransactionsEntity entity) throws Exception{
|
|
|
- return (VaultTransaction)vaultsTransactions(entity).getData();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public BaseResultDto searchList(VaultTransactionsSearchEntity entity) {
|
|
|
+ public BaseResultDto searchList(VaultTransactionsSearchEntity entity) throws Exception {
|
|
|
+ List<TransactionItemTable> tables = new LinkedList<>();
|
|
|
+ List<TransactionItemDto> list = queryWithFilter(entity.getVaultId());
|
|
|
+ if(!CollectionUtils.isEmpty(list)){
|
|
|
+ for (TransactionItemDto transactionItemDto : list) {
|
|
|
+ TransactionItemTable table = new TransactionItemTable() ;
|
|
|
+ BeanUtils.copyProperties(transactionItemDto, table);
|
|
|
+ table.setVaultId(entity.getVaultId());
|
|
|
+ table.setItemId(transactionItemDto.getId());
|
|
|
+ tables.add(table);
|
|
|
+ }
|
|
|
+ batchSave(tables);
|
|
|
+ }
|
|
|
Integer count = transactionItemMapper.countList(entity);
|
|
|
if (count == null || count <= 0) {
|
|
|
return ResultWithPagerDto.success(new PageDto(), new ArrayList<>());
|
|
|
@@ -371,4 +444,61 @@ public class VaultodyServiceImpl implements VaultodyService {
|
|
|
|
|
|
return ResultWithPagerDto.success(pageDto, dtos);
|
|
|
}
|
|
|
+
|
|
|
+ public List<TransactionItemDto> queryWithFilter(String vaultId) throws Exception {
|
|
|
+ VaultTransactionsEntity entity = new VaultTransactionsEntity();
|
|
|
+ entity.setVaultId(vaultId);
|
|
|
+ List<TransactionItemDto> result = new ArrayList<>();
|
|
|
+
|
|
|
+ // 先获取数据库中已存在的item ID列表
|
|
|
+ List<String> existingItemIds = recordByVaultId(vaultId);
|
|
|
+ Set<String> existingIdSet = new HashSet<>(existingItemIds);
|
|
|
+
|
|
|
+ VaultTransaction vaultTransaction = query3Items(entity);
|
|
|
+
|
|
|
+ // 处理第一页数据
|
|
|
+ if (vaultTransaction.getList() != null && !vaultTransaction.getList().isEmpty()) {
|
|
|
+ List<TransactionItemDto> filteredList = filterExistingItems(vaultTransaction.getList(), existingIdSet);
|
|
|
+ result.addAll(filteredList);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 分页查询剩余数据
|
|
|
+ while (Boolean.TRUE.equals(vaultTransaction.getHasMore())
|
|
|
+ && vaultTransaction.getList() != null
|
|
|
+ && !vaultTransaction.getList().isEmpty()) {
|
|
|
+
|
|
|
+ String lastId = vaultTransaction.getList().get(vaultTransaction.getList().size() - 1).getId();
|
|
|
+ entity.setStartingAfter(lastId);
|
|
|
+
|
|
|
+ vaultTransaction = query3Items(entity);
|
|
|
+
|
|
|
+ if (vaultTransaction.getList() != null && !vaultTransaction.getList().isEmpty()) {
|
|
|
+ List<TransactionItemDto> filteredList = filterExistingItems(vaultTransaction.getList(), existingIdSet);
|
|
|
+ result.addAll(filteredList);
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<TransactionItemDto> filterExistingItems(List<TransactionItemDto> items, Set<String> existingIdSet) {
|
|
|
+ if (items == null || items.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ return items.stream()
|
|
|
+ .filter(item -> item != null && item.getId() != null)
|
|
|
+ .filter(item -> !existingIdSet.contains(item.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> recordByVaultId(String vaultId){
|
|
|
+ List<TransactionItemTable> list = finAllByVaultId(vaultId);
|
|
|
+ if(CollectionUtils.isEmpty(list)){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return list.stream().map(TransactionItemTable::getItemId).toList();
|
|
|
+ }
|
|
|
}
|