소스 검색

搜索transfer算法的调整

龚成明 2 년 전
부모
커밋
6f8eee180f

+ 4 - 0
src/main/java/modules/address/token/TokenService.java

@@ -39,4 +39,8 @@ public class TokenService {
 	public List<Record> findByChainId(int chainId, int pageNumber, int pageSize) {
 		return Db.template("address.findByChainId", TableUtil.getTableName(Token.class), chainId).paginate(pageNumber, pageSize).getList();
 	}
+	
+	public String findSymbolByChainIdAndHash(int chainId, String hash) {
+		return Db.template("token.findSymbolByChainIdAndHash", chainId, hash).queryStr();
+	}
 }

+ 6 - 0
src/main/java/modules/address/token/token.sqlt

@@ -0,0 +1,6 @@
+#查询token的symbol
+#sql("findSymbolByChainIdAndHash")
+select symbol as tokenSymbol
+from t_token
+where t.chainId=#para(0) and t.hash=#para(1)
+#end

+ 13 - 3
src/main/java/modules/tx/transfer/TransferService.java

@@ -1,13 +1,12 @@
 package modules.tx.transfer;
 
-import com.alibaba.fastjson.JSONObject;
 import com.jfinal.aop.Inject;
 import com.jfinal.plugin.activerecord.Db;
 import com.jfinal.plugin.activerecord.Model;
 import com.jfinal.plugin.activerecord.Record;
-import common.model.HistoryTransfer;
 import modules.address.AddressService;
 import modules.address.factory.FactoryService;
+import modules.address.token.TokenService;
 
 import java.util.Arrays;
 import java.util.List;
@@ -16,9 +15,11 @@ public class TransferService {
 	@Inject
 	AddressService addressService;
 	@Inject
+	TokenService tokenService;
+	@Inject
 	FactoryService factoryService;
 	
-	static String[] QUERY_TABLE_PRIORITY = {"t_address", "t_v2_lp", "t_v3_lp", "t_bal_lp", "t_token"};
+	static String[] QUERY_TABLE_PRIORITY = {"t_address", "t_v2_lp", "t_v3_lp", "t_bal_lp"};
 	
 	public boolean saveTransferList(List<? extends Model<?>> transferList) {
 		int totalSize = transferList.size();
@@ -39,6 +40,7 @@ public class TransferService {
 	}
 	
 	public void putNameToTransferByKey(Record transfer, String key, int chainId, String hash) {
+		// 按优先级索引,QUERY_TABLE_PRIORITY
 		for (String tableName: QUERY_TABLE_PRIORITY) {
 			String nameValue = addressService.findNameByTableAndChainIdAndHash(tableName, chainId, hash);
 			if (nameValue != null) {
@@ -47,6 +49,14 @@ public class TransferService {
 			}
 		}
 		
+		// 按优先级索引,搜索token的symbol
+		String tokenSymbol = tokenService.findSymbolByChainIdAndHash(chainId, hash);
+		if (tokenSymbol != null) {
+			transfer.put(key + "Symbol", tokenSymbol);
+			return;
+		}
+		
+		// 最后查router的name
 		String nameValue = factoryService.findNameByChainIdAndRouter(chainId, hash);
 		if (nameValue != null) transfer.put(key + "Name", nameValue);
 	}