ソースを参照

解决pending和history无法修改bug

JiahengHe 2 年 前
コミット
fc0f63b829

+ 21 - 3
src/main/java/modules/tx/TxService.java

@@ -68,12 +68,10 @@ public class TxService {
 		return SaveUtil.saveOrUpdate(tx);
 	}
 
-	public int saveOrUpdate(Model<? extends Model<?>> subModel, Tx tx, List<? extends Model<?>> transferList) {
-
+	public int saveBatch(Model<? extends Model<?>> subModel, Tx tx, List<? extends Model<?>> transferList) {
 		AtomicInteger code = new AtomicInteger();
 
 		Db.tx(() -> {
-//			SaveUtil.saveOrUpdate(tx);
 			code.set(SaveUtil.save(subModel));
 			return true;
 		});
@@ -89,6 +87,26 @@ public class TxService {
 		return code.get();
 	}
 
+	public int saveOrUpdate(Model<? extends Model<?>> subModel, Tx tx, List<? extends Model<?>> transferList) {
+
+		AtomicInteger code = new AtomicInteger();
+
+		Db.tx(() -> {
+			code.set(SaveUtil.saveOrUpdate(subModel));
+			return true;
+		});
+
+		Db.tx(() -> {
+			if (transferList!=null && code.get() == SaveUtil.SAVE_CODE && transferList.size() > 0) {
+				boolean result = transferService.updateTransferList(transferList, tx.getChainId(), tx.getHash());
+				return result;
+			}
+			return true;
+		});
+
+		return code.get();
+	}
+
 	public List<Record> findTxByHash(String hash){
 		return Db.template("tx.findTxByHash", hash).find();
 	}

+ 1 - 1
src/main/java/modules/tx/history/HistoryService.java

@@ -36,7 +36,7 @@ public class HistoryService {
 			List<HistoryTransfer> historyTransferList = TransferFactory.parseHistoryTransferList(
 					history.getChainId(), history.getHash(), jsonStr);
 			try {
-				txService.saveOrUpdate(history, tx, historyTransferList);
+				txService.saveBatch(history, tx, historyTransferList);
 			}catch (Exception ex){
 				errorStrs.add(jsonStr);
 			}

+ 1 - 1
src/main/java/modules/tx/pending/PendingService.java

@@ -31,7 +31,7 @@ public class PendingService {
 			List<PendingTransfer> pendingTransferList = TransferFactory.parsePendingTransferList(
 					pending.getChainId(), pending.getHash(), jsonStr);
 			try {
-				txService.saveOrUpdate(pending, tx, pendingTransferList);
+				txService.saveBatch(pending, tx, pendingTransferList);
 			}catch (Exception ex){
 				errorStrs.add(jsonStr);
 			}

+ 12 - 0
src/main/java/modules/tx/transfer/TransferService.java

@@ -33,6 +33,18 @@ public class TransferService {
 		boolean result = Arrays.stream(Db.batchSave(transferList, totalSize)).sum() == totalSize;
 		return result;
 	}
+
+	public boolean updateTransferList(List<? extends Model<?>> transferList, Integer chainId, String hash) {
+		int totalSize = transferList.size();
+//	    没有修改方法,只有写入方法,先删除再写入
+		Db.template("transfer.deleteByMainId", TableUtil.getTableName(transferList.get(0)),chainId+hash).delete();
+		Integer num = Db.template("transfer.getCountByMainId",TableUtil.getTableName(transferList.get(0)),chainId+hash).queryInt();
+		if(num > 0){
+			return true;
+		}
+		boolean result = Arrays.stream(Db.batchSave(transferList, totalSize)).sum() == totalSize;
+		return result;
+	}
 	
 	public List<Record> findTransferByChainIdAndHash(String table, int chainId, String hash) {
 		String mainId = chainId + hash;

+ 4 - 4
src/test/http/tx/PendingTest.http

@@ -5,12 +5,12 @@ Content-Type: application/json
 {
   "list": [
     {
-      "chainId": 4,
+      "chainId": 6,
       "hash": "0x25fff6cc8a066a5132a9b2b37e0b1204a7a12b9669572104b4d58c971be07b81",
       "blockNumber": 123,
       "fromAddress": "0x8A9009847570FdbCc676c7fD547aB26A358a5005",
       "toAddress": "0x8A9009847570FdbCc676c7fD547aB26A358a5005",
-      "method": "method1",
+      "method": "method2",
       "status": "status",
       "transactionIndex": 0,
       "nonce": 0,
@@ -108,8 +108,8 @@ Content-Type: application/json
   "blockNumber": 123,
   "fromAddress": "0x8A9009847570FdbCc676c7fD547aB26A358a5005",
   "toAddress": "0x8A9009847570FdbCc676c7fD547aB26A358a5005",
-  "method": "method1",
-  "status": "status",
+  "method": "method2",
+  "status": "status3",
   "transactionIndex": 0,
   "nonce": 0,
   "gasPriceStr": "13333",