From 7d80267c3797e557d9d38494306b402c908210c6 Mon Sep 17 00:00:00 2001
From: peternameyakj <908253177@qq.com>
Date: Mon, 12 Aug 2024 15:15:28 +0800
Subject: [PATCH] 新增资金账户以及与交易账户的互转

---
 src/main/java/project/wallet/internal/WalletGatherServiceImpl.java |   59 ++++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/src/main/java/project/wallet/internal/WalletGatherServiceImpl.java b/src/main/java/project/wallet/internal/WalletGatherServiceImpl.java
index 6ed7d3f..3ca985f 100644
--- a/src/main/java/project/wallet/internal/WalletGatherServiceImpl.java
+++ b/src/main/java/project/wallet/internal/WalletGatherServiceImpl.java
@@ -231,8 +231,12 @@
             return resultObject;
         }else {
             //交易账户=>资金账户
-            WalletExtend walletExtend = walletService.saveExtendByPara(partyId, currency);
-            resultObject.setData(walletExtend.getAmount());
+            if("usdt".equals(currency)){
+                resultObject.setData(walletService.saveWalletByPartyId(partyId).getMoney());
+            }else {
+                WalletExtend walletExtend = walletService.saveExtendByPara(partyId, currency);
+                resultObject.setData(walletExtend.getAmount());
+            }
             return resultObject;
         }
     }
@@ -240,25 +244,38 @@
     public ResultObject transferExtendtoGather(WalletGather walletGather,WalletExtend walletExtend,String currency,double amount){
         ResultObject resultObject = new ResultObject();
         resultObject.setCode("0");
-        if(new BigDecimal(walletExtend.getAmount()).compareTo(new BigDecimal(amount)) >= 0){
-            if("usdt".equals(currency)){
-                walletGather.setUsdtMoney(Arith.add(walletGather.getUsdtMoney(), amount));
-            }else if("btc".equals(currency)){
-                walletGather.setBtcMoney(Arith.add(walletGather.getBtcMoney(), amount));
-            }else if("eth".equals(currency)){
-                walletGather.setEthMoney(Arith.add(walletGather.getEthMoney(), amount));
-            }else if("usdc".equals(currency)){
-                walletGather.setUsdcMoney(Arith.add(walletGather.getUsdcMoney(), amount));
+        if("usdt".equals(currency)){
+            Wallet wallet = walletService.saveWalletByPartyId(walletExtend.getPartyId());
+            if(wallet.getMoney() < amount){
+                resultObject.setCode("1");
+                resultObject.setMsg("划转资金不足");
+                return resultObject;
             }
+            walletGather.setUsdtMoney(Arith.add(walletGather.getUsdtMoney(), amount));
         }else {
-            resultObject.setCode("1");
-            resultObject.setMsg("划转资金不足");
-            return resultObject;
+            if(new BigDecimal(walletExtend.getAmount()).compareTo(new BigDecimal(amount)) >= 0){
+                if("btc".equals(currency)){
+                    walletGather.setBtcMoney(Arith.add(walletGather.getBtcMoney(), amount));
+                }else if("eth".equals(currency)){
+                    walletGather.setEthMoney(Arith.add(walletGather.getEthMoney(), amount));
+                }else if("usdc".equals(currency)){
+                    walletGather.setUsdcMoney(Arith.add(walletGather.getUsdcMoney(), amount));
+                }
+            }else {
+                resultObject.setCode("1");
+                resultObject.setMsg("划转资金不足");
+                return resultObject;
+            }
         }
+
 
         ApplicationUtil.executeUpdate(walletGather);
         redisHandler.setAsyn(WalletRedisKeys.WALLET_GATHER_PARTY_ID + walletGather.getPartyId().toString(),walletGather);
-        walletService.updateExtend(walletExtend.getPartyId().toString(), walletExtend.getWallettype(), -amount);
+        if("usdt".equals(currency)){
+            walletService.update(walletGather.getPartyId().toString(),-amount);
+        }else {
+            walletService.updateExtend(walletExtend.getPartyId().toString(), walletExtend.getWallettype(), -amount);
+        }
         resultObject.setMsg("划转成功");
         return resultObject;
     }
@@ -275,7 +292,7 @@
                 return resultObject;
             }
         }else if("btc".equals(currency)){
-            if(new BigDecimal(walletGather.getUsdtMoney()).compareTo(new BigDecimal(amount)) >= 0){
+            if(new BigDecimal(walletGather.getBtcMoney()).compareTo(new BigDecimal(amount)) >= 0){
                 walletGather.setBtcMoney(Arith.sub(walletGather.getBtcMoney(), amount));
             }else {
                 resultObject.setCode("1");
@@ -283,7 +300,7 @@
                 return resultObject;
             }
         }else if("eth".equals(currency)){
-            if(new BigDecimal(walletGather.getUsdtMoney()).compareTo(new BigDecimal(amount)) >= 0){
+            if(new BigDecimal(walletGather.getEthMoney()).compareTo(new BigDecimal(amount)) >= 0){
                 walletGather.setEthMoney(Arith.sub(walletGather.getEthMoney(), amount));
             }else {
                 resultObject.setCode("1");
@@ -291,7 +308,7 @@
                 return resultObject;
             }
         }else if("usdc".equals(currency)){
-            if(new BigDecimal(walletGather.getUsdtMoney()).compareTo(new BigDecimal(amount)) >= 0){
+            if(new BigDecimal(walletGather.getUsdcMoney()).compareTo(new BigDecimal(amount)) >= 0){
                 walletGather.setUsdcMoney(Arith.sub(walletGather.getUsdcMoney(), amount));
             }else {
                 resultObject.setCode("1");
@@ -301,7 +318,11 @@
         }
         ApplicationUtil.executeUpdate(walletGather);
         redisHandler.setAsyn(WalletRedisKeys.WALLET_GATHER_PARTY_ID + walletGather.getPartyId().toString(),walletGather);
-        walletService.updateExtend(walletExtend.getPartyId().toString(), walletExtend.getWallettype(), amount);
+        if("usdt".equals(currency)){
+            walletService.update(walletGather.getPartyId().toString(),amount);
+        }else {
+            walletService.updateExtend(walletExtend.getPartyId().toString(), walletExtend.getWallettype(), amount);
+        }
         resultObject.setMsg("划转成功");
         return resultObject;
     }

--
Gitblit v1.9.3