From c326372b71da84c449b6097af5e281cd6fb46e2c Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Mon, 08 Jun 2020 15:41:35 +0800
Subject: [PATCH] 20200608  代码提交

---
 src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java |   83 +++++++++++++++++++++++++++++------------
 1 files changed, 58 insertions(+), 25 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java b/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
index 0e8d92e..bab36aa 100644
--- a/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
@@ -16,6 +16,7 @@
 import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao;
 import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange;
 import com.xcong.excoin.modules.coin.parameter.vo.MemberAccountMoneyChangeInfoVo;
+import com.xcong.excoin.modules.coin.parameter.vo.MemberAgentIntoInfoVo;
 import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletAgentInfoVo;
 import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletCoinInfoVo;
 import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletCoinVo;
@@ -28,7 +29,10 @@
 import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
 import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
 import com.xcong.excoin.modules.platform.dao.PlatformCnyUsdtExchangeDao;
+import com.xcong.excoin.utils.CoinTypeConvert;
 import com.xcong.excoin.utils.MessageSourceUtils;
+import com.xcong.excoin.utils.RedisUtils;
+
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
@@ -48,6 +52,8 @@
     MemberAccountMoneyChangeDao memberAccountMoneyChangeDao;
     @Resource
     MemberWalletAgentDao memberWalletAgentDao;
+    @Resource
+    RedisUtils redisUtils;
 
 
     @Override
@@ -82,15 +88,16 @@
                         totalUsdt = walletCoin.getAvailableBalance().add(walletCoin.getFrozenBalance());
                         totalUsdts = totalUsdts.add(totalUsdt);
                         BigDecimal totalCny = totalUsdt.multiply(cnyUsdt);
-                        walletCoin.setTotalBalance(totalCny.setScale(4, BigDecimal.ROUND_DOWN));
+                        walletCoin.setTotalBalance(totalCny);
                     } else {
                         BigDecimal amount = walletCoin.getAvailableBalance().add(walletCoin.getFrozenBalance());
-                        BigDecimal closePrice = new BigDecimal("10.0000");
+                        // 获取最新价
+                        BigDecimal closePrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(walletCoin.getWalletCode()+"/USDT")));
                         BigDecimal totalUsdt = BigDecimal.ZERO;
                         //Double closePrice = symbolsService.getCloseSymbolsBySymbolsName(walletCoin.getWalletCode()+"/USDT");
                         totalUsdt = totalUsdt.add(amount.multiply(closePrice));
                         totalUsdts = totalUsdts.add(totalUsdt);
-                        walletCoin.setTotalBalance(totalUsdt.multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
+                        walletCoin.setTotalBalance(totalUsdt.multiply(cnyUsdt));
                     }
                 }
             }
@@ -150,7 +157,7 @@
                 memberWalletCoinInfoVo.setTotalBalance(total.multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
 
             } else {
-                BigDecimal closePrice = new BigDecimal("10.0000");
+            	BigDecimal closePrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(symbol+"/USDT")));
                 //Double closePrice = symbolsService.getCloseSymbolsBySymbolsName(wallet.getCode()+"/USDT");
                 memberWalletCoinInfoVo.setTotalBalance(total.multiply(closePrice).multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
             }
@@ -177,9 +184,9 @@
          */
         //获取当前的合约持仓
         //获取实时盈亏
-        BigDecimal profitAndLoss = new BigDecimal("50.000");
+        BigDecimal profitAndLoss = new BigDecimal("0");
         //获取总付款
-        BigDecimal totalPayment = new BigDecimal("50.000");
+        BigDecimal totalPayment = new BigDecimal("0");
         BigDecimal lastTotalBalance = new BigDecimal("0");
         BigDecimal totalBalance = walletContract.getTotalBalance();
         lastTotalBalance = totalBalance.add(profitAndLoss);
@@ -229,10 +236,10 @@
             MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, walletCode);
             BigDecimal availableBalance = walletContract.getAvailableBalance();
             BigDecimal add = availableBalance.add(balance);
-            walletContract.setAvailableBalance(add.setScale(4, BigDecimal.ROUND_DOWN));
+            walletContract.setAvailableBalance(add);
             BigDecimal totalBalance = walletContract.getTotalBalance();
             BigDecimal totalBigDecimal = totalBalance.add(balance);
-            walletContract.setTotalBalance(totalBigDecimal.setScale(4, BigDecimal.ROUND_DOWN));
+            walletContract.setTotalBalance(totalBigDecimal);
             int updateWalletContractById = memberWalletContractDao.updateById(walletContract);
             if (updateWalletContractById < 1) {
                 return Result.fail(MessageSourceUtils.getString("member_service_0096"));
@@ -241,7 +248,7 @@
             MemberAccountMoneyChange memberAccountRecord = new MemberAccountMoneyChange();
             memberAccountRecord.setContent(MemberWalletCoinEnum.CONTENTTOCONTRACT.getValue());
             memberAccountRecord.setMemberId(memberId);
-            memberAccountRecord.setAmount(balance.negate().setScale(4, BigDecimal.ROUND_DOWN));
+            memberAccountRecord.setAmount(balance.negate());
             memberAccountRecord.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER);
             memberAccountRecord.setSymbol(MemberWalletCoinEnum.WALLETCOINCODE.getValue());
             memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_COIN);
@@ -250,7 +257,7 @@
             //添加合约资金划转历史记录
             memberAccountRecord.setContent(MemberWalletCoinEnum.CONTENTFROMWALLETCOIN.getValue());
             memberAccountRecord.setSymbol(MemberWalletCoinEnum.WALLETCOINCODE.getValue());
-            memberAccountRecord.setAmount(balance.setScale(4, BigDecimal.ROUND_DOWN));
+            memberAccountRecord.setAmount(balance);
             memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_CONTRACT);
             memberAccountMoneyChangeDao.insert(memberAccountRecord);
         }
@@ -277,8 +284,8 @@
         BigDecimal totalBalance = walletContract.getTotalBalance();
         BigDecimal totalSubtract = totalBalance.subtract(balance);
 
-        walletContract.setAvailableBalance(availableSubtract.setScale(4, BigDecimal.ROUND_DOWN));
-        walletContract.setTotalBalance(totalSubtract.setScale(4, BigDecimal.ROUND_DOWN));
+        walletContract.setAvailableBalance(availableSubtract);
+        walletContract.setTotalBalance(totalSubtract);
         int updateWalletCoinById = memberWalletContractDao.updateById(walletContract);
         if (updateWalletCoinById < 1) {
             return Result.fail(MessageSourceUtils.getString("member_service_0096"));
@@ -290,8 +297,8 @@
         BigDecimal walletCoinTotalBalance = walletCoin.getTotalBalance();
         BigDecimal CoinTotalBalance = walletCoinTotalBalance.add(balance);
 
-        walletCoin.setAvailableBalance(CoinAvailableBalance.setScale(4, BigDecimal.ROUND_DOWN));
-        walletCoin.setTotalBalance(CoinTotalBalance.setScale(4, BigDecimal.ROUND_DOWN));
+        walletCoin.setAvailableBalance(CoinAvailableBalance);
+        walletCoin.setTotalBalance(CoinTotalBalance);
         int updateById = memberWalletCoinDao.updateById(walletCoin);
         if (updateById < 1) {
             return Result.fail(MessageSourceUtils.getString("member_service_0096"));
@@ -301,7 +308,7 @@
         MemberAccountMoneyChange memberAccountRecord = new MemberAccountMoneyChange();
         memberAccountRecord.setContent(MemberWalletCoinEnum.CONTENTTOWALLETCOIN.getValue());
         memberAccountRecord.setMemberId(memberId);
-        memberAccountRecord.setAmount(balance.negate().setScale(4, BigDecimal.ROUND_DOWN));
+        memberAccountRecord.setAmount(balance.negate());
         memberAccountRecord.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER);
         memberAccountRecord.setSymbol(walletCode);
         memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_CONTRACT);
@@ -311,7 +318,7 @@
         memberAccountRecord.setContent(MemberWalletCoinEnum.CONTENTFROMCONTRACT.getValue());
         memberAccountRecord.setSymbol(walletCode);
         memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_COIN);
-        memberAccountRecord.setAmount(balance.setScale(4, BigDecimal.ROUND_DOWN));
+        memberAccountRecord.setAmount(balance);
         memberAccountMoneyChangeDao.insert(memberAccountRecord);
         return Result.ok(MessageSourceUtils.getString("member_service_0006"));
     }
@@ -429,8 +436,8 @@
             return Result.fail(MessageSourceUtils.getString("member_service_0008"));
         }
 
-        walletAgent.setAvailableBalance(available.setScale(4, BigDecimal.ROUND_DOWN));
-        walletAgent.setTotalBalance(total.setScale(4, BigDecimal.ROUND_DOWN));
+        walletAgent.setAvailableBalance(available);
+        walletAgent.setTotalBalance(total);
 
         int i = memberWalletAgentDao.updateById(walletAgent);
         if (i < 1) {
@@ -444,8 +451,8 @@
             BigDecimal walletCoinAvailableBalance = walletCoin.getAvailableBalance();
             BigDecimal walletCoinTotalBalance = walletCoin.getTotalBalance();
 
-            walletCoin.setAvailableBalance(walletCoinAvailableBalance.add(balance).setScale(4, BigDecimal.ROUND_DOWN));
-            walletCoin.setTotalBalance(walletCoinTotalBalance.add(balance).setScale(4, BigDecimal.ROUND_DOWN));
+            walletCoin.setAvailableBalance(walletCoinAvailableBalance.add(balance));
+            walletCoin.setTotalBalance(walletCoinTotalBalance.add(balance));
 
             int updateById = memberWalletCoinDao.updateById(walletCoin);
             if (updateById < 1) {
@@ -457,7 +464,7 @@
             memberAccountRecord.setSymbol(walletCode);
             memberAccountRecord.setContent(MemberWalletCoinEnum.CONTENTFROMAGENT.getValue());
             memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_COIN);
-            memberAccountRecord.setAmount(balance.setScale(4, BigDecimal.ROUND_DOWN));
+            memberAccountRecord.setAmount(balance);
             memberAccountMoneyChangeDao.insert(memberAccountRecord);
             memberAccountRecord.setContent(MemberWalletCoinEnum.CONTENTTOWALLETCOIN.getValue());
 
@@ -467,8 +474,8 @@
             BigDecimal walletContractAvailableBalance = walletContract.getAvailableBalance();
             BigDecimal walletContractTotalBalance = walletContract.getTotalBalance();
 
-            walletContract.setAvailableBalance(walletContractAvailableBalance.add(balance).setScale(4, BigDecimal.ROUND_DOWN));
-            walletContract.setTotalBalance(walletContractTotalBalance.add(balance).setScale(4, BigDecimal.ROUND_DOWN));
+            walletContract.setAvailableBalance(walletContractAvailableBalance.add(balance));
+            walletContract.setTotalBalance(walletContractTotalBalance.add(balance));
 
             int updateById = memberWalletContractDao.updateById(walletContract);
             if (updateById < 1) {
@@ -481,11 +488,11 @@
             memberAccountRecord.setSymbol(walletCode);
             memberAccountRecord.setContent(MemberWalletCoinEnum.CONTENTFROMAGENT.getValue());
             memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_CONTRACT);
-            memberAccountRecord.setAmount(balance.setScale(4, BigDecimal.ROUND_DOWN));
+            memberAccountRecord.setAmount(balance);
             memberAccountMoneyChangeDao.insert(memberAccountRecord);
             memberAccountRecord.setContent(MemberWalletCoinEnum.CONTENTTOCONTRACT.getValue());
         }
-        memberAccountRecord.setAmount(balance.negate().setScale(4, BigDecimal.ROUND_DOWN));
+        memberAccountRecord.setAmount(balance.negate());
         memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_AGENT);
         memberAccountMoneyChangeDao.insert(memberAccountRecord);
 
@@ -511,4 +518,30 @@
         return Result.ok(memberWalletAgentInfoVo);
     }
 
+	@Override
+	public Result getWalletAgentIntoRecords() {
+	        //获取用户ID
+	        Long memberId = LoginUserUtils.getAppLoginUser().getId();
+
+	        List<MemberAccountMoneyChange> contractRecordList =
+	                memberAccountMoneyChangeDao.selectWalletAgentIntoRecordsByMemIdTypeSymbol(memberId);
+
+	        MemberAgentIntoInfoVo memberAgentIntoInfoVo = new MemberAgentIntoInfoVo();
+	        List<MemberAccountMoneyChangeInfoVo> arrayList = new ArrayList<>();
+	        if (ObjectUtil.isNotNull(contractRecordList)) {
+	            for (MemberAccountMoneyChange memberAccountMoneyChange : contractRecordList) {
+	                MemberAccountMoneyChangeInfoVo memberAccountMoneyChangeInfoVo = new MemberAccountMoneyChangeInfoVo();
+	                memberAccountMoneyChangeInfoVo.setAmount(memberAccountMoneyChange.getAmount());
+	                memberAccountMoneyChangeInfoVo.setContent(memberAccountMoneyChange.getContent());
+	                memberAccountMoneyChangeInfoVo.setStatus(memberAccountMoneyChange.getStatus());
+	                memberAccountMoneyChangeInfoVo.setSymbol(memberAccountMoneyChange.getSymbol());
+	                memberAccountMoneyChangeInfoVo.setType(memberAccountMoneyChange.getType());
+	                memberAccountMoneyChangeInfoVo.setUpdateTime(memberAccountMoneyChange.getUpdateTime());
+	                arrayList.add(memberAccountMoneyChangeInfoVo);
+	            }
+	        }
+	        memberAgentIntoInfoVo.setMemberAccountMoneyChangeInfoVo(arrayList);
+	        return Result.ok(memberAgentIntoInfoVo);
+	}
+
 }

--
Gitblit v1.9.1