From cc9d558c8cda42d53be7b4545d2f33db26edf777 Mon Sep 17 00:00:00 2001
From: gao <gaoleox@163>
Date: Thu, 28 May 2020 16:46:18 +0800
Subject: [PATCH] Merge branch 'master' of https://chonggaoxiao:xcg523511090712@gitee.com/chonggaoxiao/new_excoin.git

---
 src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java |  215 ++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 147 insertions(+), 68 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 3ddaaeb..719b6a8 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
@@ -2,27 +2,24 @@
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
-
 import javax.annotation.Resource;
 
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xcong.excoin.common.LoginUserUtils;
 import com.xcong.excoin.common.enumerates.CoinTypeEnum;
 import com.xcong.excoin.common.enumerates.MemberWalletCoinEnum;
-import com.xcong.excoin.common.exception.GlobalException;
 import com.xcong.excoin.common.response.Result;
 import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao;
-import com.xcong.excoin.modules.coin.dao.platform.CnyUsdtExchangeDao;
 import com.xcong.excoin.modules.coin.entity.CnyUsdtExchange;
 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.MemberWalletAgentInfoVo;
+import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletCoinInfoVo;
 import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletCoinVo;
+import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletContractInfoVo;
 import com.xcong.excoin.modules.coin.service.CoinService;
 import com.xcong.excoin.modules.member.dao.MemberWalletAgentDao;
 import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
@@ -30,9 +27,10 @@
 import com.xcong.excoin.modules.member.entity.MemberWalletAgentEntity;
 import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
 import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
+import com.xcong.excoin.modules.platform.dao.CnyUsdtExchangeDao;
 import com.xcong.excoin.utils.MessageSourceUtils;
-
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 
 @Service
@@ -54,105 +52,147 @@
 	
 	@Override
 	public Result getWalletCoin() {
-		try {
-			BigDecimal totalUsdt = BigDecimal.ZERO;
 			//获取用户ID
 			Long memberId = LoginUserUtils.getAppLoginUser().getId();
-			
 			CnyUsdtExchange cnyUsdtExchange =cnyUsdtExchangeDao.getCNYAndUSDTOne();
 			BigDecimal cnyUsdt = cnyUsdtExchange.getValue();
 			
+			BigDecimal totalUsdts = BigDecimal.ZERO;
 			if(!StrUtil.isEmpty(memberId.toString())) {
 				
-				List<MemberWalletCoinEntity> MemberWalletCoinlist = memberWalletCoinDao.selectMemberWalletCoinsByMemberId(memberId);
+				List<MemberWalletCoinEntity> memberWalletCoinlist = memberWalletCoinDao.selectMemberWalletCoinsByMemberId(memberId);
+				List<MemberWalletCoinInfoVo> memberWalletCoinInfoVolist = new ArrayList<MemberWalletCoinInfoVo>();
 				
-				if(CollUtil.isNotEmpty(MemberWalletCoinlist)) {
-					for(MemberWalletCoinEntity walletCoin : MemberWalletCoinlist) {
+				if(CollUtil.isNotEmpty(memberWalletCoinlist)) {
+					for(MemberWalletCoinEntity memberWalletCoinEntity : memberWalletCoinlist) {
+						MemberWalletCoinInfoVo memberWalletCoinInfoVo = new MemberWalletCoinInfoVo();
+						memberWalletCoinInfoVo.setAvailableBalance(memberWalletCoinEntity.getAvailableBalance().setScale(4, BigDecimal.ROUND_DOWN));
+						memberWalletCoinInfoVo.setFrozenBalance(memberWalletCoinEntity.getFrozenBalance().setScale(4, BigDecimal.ROUND_DOWN));
+						memberWalletCoinInfoVo.setMemberId(memberWalletCoinEntity.getMemberId());
+						memberWalletCoinInfoVo.setTotalBalance(memberWalletCoinEntity.getTotalBalance().setScale(4, BigDecimal.ROUND_DOWN));
+						memberWalletCoinInfoVo.setWalletCode(memberWalletCoinEntity.getWalletCode());
+						memberWalletCoinInfoVolist.add(memberWalletCoinInfoVo);
+					}
+				}
+				
+				if(CollUtil.isNotEmpty(memberWalletCoinInfoVolist)) {
+					for(MemberWalletCoinInfoVo walletCoin : memberWalletCoinInfoVolist) {
 						if(MemberWalletCoinEnum.WALLETCOINCODE.getValue().equals(walletCoin.getWalletCode())) {	
+							BigDecimal totalUsdt = BigDecimal.ZERO;
 							totalUsdt = walletCoin.getAvailableBalance().add(walletCoin.getFrozenBalance());
+							totalUsdts = totalUsdts.add(totalUsdt);
 							BigDecimal totalCny = totalUsdt.multiply(cnyUsdt);
 							walletCoin.setTotalBalance(totalCny.setScale(4, BigDecimal.ROUND_DOWN));
 						}else {
 							BigDecimal amount = walletCoin.getAvailableBalance().add(walletCoin.getFrozenBalance());
 							BigDecimal closePrice = new BigDecimal("10.0000");
+							BigDecimal totalUsdt = BigDecimal.ZERO;
 							//Double closePrice = symbolsService.getCloseSymbolsBySymbolsName(walletCoin.getWalletCode()+"/USDT");
 							totalUsdt = totalUsdt.add(amount.multiply(closePrice));
-							walletCoin.setTotalBalance(totalUsdt.multiply(closePrice).multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
+							totalUsdts = totalUsdts.add(totalUsdt);
+							walletCoin.setTotalBalance(totalUsdt.multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
 						}
 					}
 				}
 				MemberWalletCoinVo memberWalletCoinVo = new MemberWalletCoinVo();
-				memberWalletCoinVo.setTotalUsdt(totalUsdt.setScale(4, BigDecimal.ROUND_DOWN));
-				memberWalletCoinVo.setTotalCny(totalUsdt.multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
-				memberWalletCoinVo.setWalletCoinEntities(MemberWalletCoinlist);
+				memberWalletCoinVo.setTotalUsdt(totalUsdts.setScale(4, BigDecimal.ROUND_DOWN));
+				memberWalletCoinVo.setTotalCny(totalUsdts.multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
+				memberWalletCoinVo.setMemberWalletCoinInfoVo(memberWalletCoinInfoVolist);
 				return Result.ok(memberWalletCoinVo);
 			}else {
-				List<MemberWalletCoinEntity> MemberWalletCoinlist = new ArrayList<MemberWalletCoinEntity>();
-				MemberWalletCoinEntity coin = new MemberWalletCoinEntity();
+				List<MemberWalletCoinInfoVo> memberWalletCoinlist = new ArrayList<MemberWalletCoinInfoVo>();
+				MemberWalletCoinInfoVo coin = new MemberWalletCoinInfoVo();
 				coin.setAvailableBalance(BigDecimal.ZERO);
 				coin.setTotalBalance(BigDecimal.ZERO);
 				coin.setFrozenBalance(BigDecimal.ZERO);
 				coin.setWalletCode(CoinTypeEnum.BTC.toString());
-				MemberWalletCoinlist.add(coin);
+				memberWalletCoinlist.add(coin);
 				coin.setWalletCode(CoinTypeEnum.ETH.toString());
-				MemberWalletCoinlist.add(coin);
+				memberWalletCoinlist.add(coin);
 				coin.setWalletCode(CoinTypeEnum.LTC.toString());
-				MemberWalletCoinlist.add(coin);
+				memberWalletCoinlist.add(coin);
 				coin.setWalletCode(CoinTypeEnum.BCH.toString());
-				MemberWalletCoinlist.add(coin);
+				memberWalletCoinlist.add(coin);
 				coin.setWalletCode(CoinTypeEnum.USDT.toString());
-				MemberWalletCoinlist.add(coin);
+				memberWalletCoinlist.add(coin);
 				coin.setWalletCode(CoinTypeEnum.EOS.toString());
-				MemberWalletCoinlist.add(coin);
+				memberWalletCoinlist.add(coin);
 				coin.setWalletCode(CoinTypeEnum.XRP.toString());
-				MemberWalletCoinlist.add(coin);
+				memberWalletCoinlist.add(coin);
 				coin.setWalletCode(CoinTypeEnum.ETC.toString());
-				MemberWalletCoinlist.add(coin);
+				memberWalletCoinlist.add(coin);
+				
 				MemberWalletCoinVo memberWalletCoinVo = new MemberWalletCoinVo();
-				memberWalletCoinVo.setTotalUsdt(totalUsdt.setScale(4, BigDecimal.ROUND_DOWN));
-				memberWalletCoinVo.setTotalCny(totalUsdt.multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
-				memberWalletCoinVo.setWalletCoinEntities(MemberWalletCoinlist);
+				memberWalletCoinVo.setTotalUsdt(totalUsdts.setScale(4, BigDecimal.ROUND_DOWN));
+				memberWalletCoinVo.setTotalCny(totalUsdts.multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
+				memberWalletCoinVo.setMemberWalletCoinInfoVo(memberWalletCoinlist);;
 				return Result.ok(memberWalletCoinVo);
 			}
-		} catch (Exception e) {
-			e.printStackTrace();
-			return Result.fail(MessageSourceUtils.getString("member_service_0003"));
-		}
 	}
 
 	@Override
-	public Result getWalletCoinById(Long id) {
-		try {
+	public Result getWalletCoinBySymbol(String symbol) {
 			//获取用户ID
 			Long memberId = LoginUserUtils.getAppLoginUser().getId();
-			MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectById(id);
-			
+			MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId,symbol);
+			MemberWalletCoinInfoVo memberWalletCoinInfoVo = new MemberWalletCoinInfoVo();
+			memberWalletCoinInfoVo.setFrozenBalance(walletCoin.getFrozenBalance());
+			memberWalletCoinInfoVo.setAvailableBalance(walletCoin.getAvailableBalance());
+			memberWalletCoinInfoVo.setMemberId(memberId);
+			memberWalletCoinInfoVo.setWalletCode(symbol);
 			if(!StrUtil.isEmpty(memberId.toString())) {
 				CnyUsdtExchange cnyUsdtExchange =cnyUsdtExchangeDao.getCNYAndUSDTOne();
 				BigDecimal cnyUsdt = cnyUsdtExchange.getValue();
 				BigDecimal total = walletCoin.getAvailableBalance().add(walletCoin.getFrozenBalance());
 				
 				if(MemberWalletCoinEnum.WALLETCOINCODE.getValue().equals(walletCoin.getWalletCode())) {
-					walletCoin.setTotalBalance(total.multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
+					memberWalletCoinInfoVo.setTotalBalance(total.multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
 					
 				}else {
 					BigDecimal closePrice = new BigDecimal("10.0000");
 					//Double closePrice = symbolsService.getCloseSymbolsBySymbolsName(wallet.getCode()+"/USDT");
-					walletCoin.setTotalBalance(total.multiply(closePrice).multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
+					memberWalletCoinInfoVo.setTotalBalance(total.multiply(closePrice).multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
 				}
 			}
-			return Result.ok(walletCoin);
-		} catch (Exception e) {
-			e.printStackTrace();
-			return Result.fail(MessageSourceUtils.getString("member_service_0003"));
-		}
+			return Result.ok(memberWalletCoinInfoVo);
 	}
 
 	@Override
 	public Result getWalletContractById() {
 		
-			return Result.fail(MessageSourceUtils.getString("member_service_0002"));
-		
+			//获取用户ID
+			Long memberId = LoginUserUtils.getAppLoginUser().getId();
+			
+			CnyUsdtExchange cnyUsdtExchange =cnyUsdtExchangeDao.getCNYAndUSDTOne();
+			BigDecimal cnyUsdt = cnyUsdtExchange.getValue();
+			
+			String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
+			MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, walletCode);
+			if(ObjectUtil.isEmpty(walletContract)) {
+				return Result.fail(MessageSourceUtils.getString("member_service_0001"));
+			}
+			/**
+			 * todo
+			 */
+			//获取当前的合约持仓
+			//获取实时盈亏
+			BigDecimal profitAndLoss = new BigDecimal("50.000");
+			//获取总付款
+			BigDecimal totalPayment = new BigDecimal("50.000");
+			BigDecimal lastTotalBalance = new BigDecimal("0");
+			BigDecimal totalBalance = walletContract.getTotalBalance();
+			lastTotalBalance = totalBalance.add(profitAndLoss);
+			if(lastTotalBalance.compareTo(BigDecimal.ZERO) < 0) {
+				lastTotalBalance = new BigDecimal("0");
+			}
+			
+			MemberWalletContractInfoVo memberWalletContractInfoVo = new MemberWalletContractInfoVo();
+			memberWalletContractInfoVo.setFrozenBalance(totalPayment.setScale(4, BigDecimal.ROUND_DOWN));
+			memberWalletContractInfoVo.setAvailableBalance(walletContract.getAvailableBalance());
+			memberWalletContractInfoVo.setTotalBalance(lastTotalBalance.setScale(4, BigDecimal.ROUND_DOWN));
+			memberWalletContractInfoVo.setTotalRMBBalance(lastTotalBalance.multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
+			
+			return Result.ok(memberWalletContractInfoVo);
 	}
 
 	@Override
@@ -276,11 +316,13 @@
 	}
 
 	@Override
-	public Result findWalletContractBySymbol(String symbol) {
-		/**
-		 * ---todo
-		 */
-		return null;
+	public Result findWalletContractBySymbol() {
+		//获取用户ID
+		Long memberId = LoginUserUtils.getAppLoginUser().getId();
+		String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
+		MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, walletCode);
+		BigDecimal availableBalance = walletContract.getAvailableBalance().setScale(4, BigDecimal.ROUND_DOWN);
+		return Result.ok(availableBalance);
 	}
 
 	@Override
@@ -290,26 +332,52 @@
 		
 		MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, symbol);
 		BigDecimal availableBalance = walletCoin.getAvailableBalance().setScale(4, BigDecimal.ROUND_DOWN);
-		walletCoin.setAvailableBalance(availableBalance);
-		return Result.ok(walletCoin);
+		return Result.ok(availableBalance);
 	}
 
 	@Override
 	public Result getWalletCoinRecords() {
 		//获取用户ID
 		Long memberId = LoginUserUtils.getAppLoginUser().getId();
-		
 		List<MemberAccountMoneyChange> coinRecordList = memberAccountMoneyChangeDao.selectWalletCoinRecordsByMemIdTypeSymbol(memberId);
-		return Result.ok(coinRecordList);
+		List<MemberAccountMoneyChangeInfoVo> arrayList = new ArrayList<>();
+		if(CollUtil.isNotEmpty(coinRecordList)) {
+			for(MemberAccountMoneyChange memberAccountMoneyChange : coinRecordList) {
+				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);
+			}
+		}
+		return Result.ok(arrayList);
 	}
 
 	@Override
-	public Result getWalletContractRecords(String symbol) {
+	public Result getWalletContractRecords() {
 		//获取用户ID
 		Long memberId = LoginUserUtils.getAppLoginUser().getId();
-		
+		String symbol = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
 		List<MemberAccountMoneyChange> contractRecordList = memberAccountMoneyChangeDao.selectWalletContractRecordsByMemIdTypeSymbol(symbol,memberId);
-		return Result.ok(contractRecordList);
+		
+		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);
+			}
+		}
+		
+		return Result.ok(arrayList);
 	}
 
 	@Override
@@ -319,7 +387,21 @@
 		
 		List<MemberAccountMoneyChange> contractRecordList = 
 				memberAccountMoneyChangeDao.selectWalletAgentRecordByMemIdTypeSymbol(MemberWalletCoinEnum.WALLETCOINCODE.getValue(),memberId);
-		return Result.ok(contractRecordList);
+		
+		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);
+			}
+		}
+		return Result.ok(arrayList);
 	}
 
 	@Override
@@ -420,15 +502,12 @@
 		
 		CnyUsdtExchange cnyUsdtExchange =cnyUsdtExchangeDao.getCNYAndUSDTOne();
 		BigDecimal cnyUsdt = cnyUsdtExchange.getValue();
-		
 		BigDecimal multiply = availableBalance.multiply(cnyUsdt);
 		
-		walletAgent.setAvailableBalance(availableBalance);
-		Map<String,Object> map = new HashMap<String, Object>();
-		map.put(MemberWalletCoinEnum.WALLETCOINUSDT.getValue(), availableBalance.setScale(4, BigDecimal.ROUND_DOWN));
-		map.put(MemberWalletCoinEnum.WALLETAGENTCNY.getValue(), walletAgent);
-		map.put(MemberWalletCoinEnum.WALLETCOINCNY.getValue(),  multiply.setScale(4, BigDecimal.ROUND_DOWN));
-		return Result.ok(map);
+		MemberWalletAgentInfoVo memberWalletAgentInfoVo = new MemberWalletAgentInfoVo();
+		memberWalletAgentInfoVo.setTotalBalance(availableBalance.setScale(4, BigDecimal.ROUND_DOWN));
+		memberWalletAgentInfoVo.setTotalRMBBalance(multiply.setScale(4, BigDecimal.ROUND_DOWN));
+		return Result.ok(memberWalletAgentInfoVo);
 	}
 
 }

--
Gitblit v1.9.1