From cc6d44ddf61b67225461b159f0eccdf597982c10 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 18 Mar 2021 18:14:52 +0800
Subject: [PATCH] modify
---
src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java | 284 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 267 insertions(+), 17 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 23915c1..a3e53bb 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,8 +2,12 @@
import java.math.BigDecimal;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+
import javax.annotation.Resource;
+import javax.validation.Valid;
import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
import org.springframework.stereotype.Service;
@@ -20,18 +24,25 @@
import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange;
import com.xcong.excoin.modules.coin.entity.OrderCoinsDealEntity;
import com.xcong.excoin.modules.coin.mapper.MemberAccountMoneyChangeMapper;
+import com.xcong.excoin.modules.coin.parameter.dto.CoinInListDto;
import com.xcong.excoin.modules.coin.parameter.dto.RecordsPageDto;
import com.xcong.excoin.modules.coin.parameter.vo.AllWalletCoinVo;
+import com.xcong.excoin.modules.coin.parameter.vo.CoinInListVo;
+import com.xcong.excoin.modules.coin.parameter.vo.ContractSymbolListVo;
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.MemberCoinChargeDao;
+import com.xcong.excoin.modules.member.dao.MemberCoinWithdrawDao;
import com.xcong.excoin.modules.member.dao.MemberDao;
import com.xcong.excoin.modules.member.dao.MemberWalletAgentDao;
import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
import com.xcong.excoin.modules.member.dao.MemberWalletContractDao;
+import com.xcong.excoin.modules.member.entity.MemberCoinChargeEntity;
+import com.xcong.excoin.modules.member.entity.MemberCoinWithdrawEntity;
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletAgentEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
@@ -45,6 +56,7 @@
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
+import jnr.ffi.Struct.int16_t;
@Service
public class CoinServiceImpl extends ServiceImpl<MemberWalletCoinDao, MemberWalletCoinEntity> implements CoinService {
@@ -63,6 +75,10 @@
MemberWalletAgentDao memberWalletAgentDao;
@Resource
MemberDao memberDao;
+ @Resource
+ MemberCoinChargeDao memberCoinChargeDao;
+ @Resource
+ MemberCoinWithdrawDao memberCoinWithdrawDao;
@Resource
RedisUtils redisUtils;
@@ -180,22 +196,24 @@
//获取用户ID
Long memberId = LoginUserUtils.getAppLoginUser().getId();
-
PlatformCnyUsdtExchangeEntity 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"));
- }
-
- MemberWalletContractInfoVo memberWalletContractInfoVo = new MemberWalletContractInfoVo();
- memberWalletContractInfoVo.setFrozenBalance(walletContract.getFrozenBalance().setScale(4, BigDecimal.ROUND_DOWN));
- memberWalletContractInfoVo.setAvailableBalance(walletContract.getAvailableBalance().setScale(4, BigDecimal.ROUND_DOWN));
- memberWalletContractInfoVo.setTotalBalance(walletContract.getTotalBalance().setScale(4, BigDecimal.ROUND_DOWN));
- memberWalletContractInfoVo.setTotalRMBBalance(walletContract.getTotalBalance().multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
-
+
+ Map<String, Object> columnMap = new HashMap<String, Object>();
+ columnMap.put("member_id", memberId);
+ columnMap.put("wallet_code", "USDT");
+ List<MemberWalletContractEntity> selectByMap = memberWalletContractDao.selectByMap(columnMap);
+ MemberWalletContractInfoVo memberWalletContractInfoVo = new MemberWalletContractInfoVo();
+ if(CollUtil.isNotEmpty(selectByMap)) {
+ for(MemberWalletContractEntity memberWalletContractEntity : selectByMap) {
+ memberWalletContractInfoVo.setFrozenBalance(memberWalletContractEntity.getFrozenBalance().setScale(4, BigDecimal.ROUND_DOWN));
+ memberWalletContractInfoVo.setAvailableBalance(memberWalletContractEntity.getAvailableBalance().setScale(4, BigDecimal.ROUND_DOWN));
+ memberWalletContractInfoVo.setTotalCoin(memberWalletContractEntity.getTotalBalance().setScale(4, BigDecimal.ROUND_DOWN));
+ memberWalletContractInfoVo.setAvailableCoin(memberWalletContractEntity.getTotalBalance().multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
+ memberWalletContractInfoVo.setWalletCode(memberWalletContractEntity.getWalletCode()+"/USDT");
+ }
+ }
+
return Result.ok(memberWalletContractInfoVo);
}
@@ -446,11 +464,10 @@
}
@Override
- public Result findWalletContractBySymbol() {
+ public Result findWalletContractBySymbol(String symbol) {
//获取用户ID
Long memberId = LoginUserUtils.getAppLoginUser().getId();
- String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
- MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, walletCode);
+ MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, symbol);
BigDecimal availableBalance = walletContract.getAvailableBalance().setScale(4, BigDecimal.ROUND_DOWN);
return Result.ok(availableBalance);
}
@@ -797,4 +814,237 @@
return Result.ok(allWalletCoinVo);
}
+ @Override
+ public Result getContractSymbolList() {
+ //获取用户ID
+ Long memberId = LoginUserUtils.getAppLoginUser().getId();
+ List<ContractSymbolListVo> list = memberWalletContractDao.findContractSymbolListBymemberId(memberId);
+ if(CollUtil.isNotEmpty(list)) {
+ for(ContractSymbolListVo contractSymbolListVo : list) {
+ String walletCode = contractSymbolListVo.getWalletCode();
+ walletCode = walletCode+"/USDT";
+ contractSymbolListVo.setWalletCode(walletCode);
+ }
+ }
+ return Result.ok(list);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public Result contractInTransfer(BigDecimal balance, String symbolIn, String symbolOut) {
+ //获取用户ID
+ Long memberId = LoginUserUtils.getAppLoginUser().getId();
+ //转入转出不能是同一账户
+ if(symbolIn.equals(symbolOut)) {
+ return Result.fail(MessageSourceUtils.getString("member_service_0098"));
+ }
+ if (balance.compareTo(BigDecimal.ZERO) <= 0) {
+ return Result.fail(MessageSourceUtils.getString("member_service_0004"));
+ }
+
+ MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, symbolOut);
+ BigDecimal availableBalance = walletContract.getAvailableBalance();
+ // 扣币
+ BigDecimal availableSubtract = availableBalance.subtract(balance);
+ if (availableSubtract.compareTo(BigDecimal.ZERO) < 0) {
+ return Result.fail(MessageSourceUtils.getString("member_service_0007"));
+ }
+ BigDecimal totalBalance = walletContract.getTotalBalance();
+ BigDecimal totalSubtract = totalBalance.subtract(balance);
+
+ walletContract.setAvailableBalance(availableSubtract);
+ walletContract.setTotalBalance(totalSubtract);
+ int updateWalletCoinById = memberWalletContractDao.updateById(walletContract);
+ if (updateWalletCoinById < 1) {
+ return Result.fail(MessageSourceUtils.getString("member_service_0096"));
+ }
+
+ //更新合约全仓模式下的订单权益
+ MemberEntity memberEntity = memberDao.selectById(memberId);
+ String symbols = symbolOut+"/USDT";
+ ThreadPoolUtils.sendWholeForceClosingPrice(symbols, memberEntity);
+
+ // 加币
+ // 查询合约账户
+ MemberWalletContractEntity walletContractIn = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, symbolIn);
+ BigDecimal availableBalanceIn = walletContractIn.getAvailableBalance();
+ BigDecimal addIn = availableBalanceIn.add(balance);
+ walletContractIn.setAvailableBalance(addIn);
+ BigDecimal totalBalanceIn = walletContractIn.getTotalBalance();
+ BigDecimal totalBigDecimalIn = totalBalanceIn.add(balance);
+ walletContractIn.setTotalBalance(totalBigDecimalIn);
+ int updateWalletContractById = memberWalletContractDao.updateById(walletContractIn);
+ if (updateWalletContractById < 1) {
+ return Result.fail(MessageSourceUtils.getString("member_service_0096"));
+ }
+
+ //更新合约全仓模式下的订单权益
+ String symbolIns = symbolIn+"/USDT";
+ ThreadPoolUtils.sendWholeForceClosingPrice(symbolIns, memberEntity);
+
+ ThreadPoolUtils.sendWholePrice(memberId);
+
+ //添加币币资金划转历史记录
+ MemberAccountMoneyChange memberAccountRecord = new MemberAccountMoneyChange();
+ memberAccountRecord.setContent("转出至合约"+symbolIn+"账户");
+ memberAccountRecord.setMemberId(memberId);
+ memberAccountRecord.setAmount(balance.negate());
+ memberAccountRecord.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER);
+ memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_CONTRACT);
+ memberAccountMoneyChangeDao.insert(memberAccountRecord);
+
+ //添加合约资金划转历史记录
+ memberAccountRecord.setContent("由合约"+symbolOut+"账户转入至合约"+symbolIn+"账户");
+ memberAccountRecord.setAmount(balance);
+ memberAccountMoneyChangeDao.insert(memberAccountRecord);
+
+ return Result.ok(MessageSourceUtils.getString("member_service_0006"));
+ }
+
+ @Override
+ public Result coinInList(@Valid CoinInListDto coinInListDto) {
+ //获取用户ID
+ Long memberId = LoginUserUtils.getAppLoginUser().getId();
+ int type = coinInListDto.getType();
+ //充币记录
+ if(type == 1) {
+ Page<MemberCoinChargeEntity> page = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ MemberCoinChargeEntity memberCoinChargeEntity = new MemberCoinChargeEntity();
+ memberCoinChargeEntity.setMemberId(memberId);
+ IPage<MemberCoinChargeEntity> memberCoinCharge = memberCoinChargeDao.findMemberCoinChargeInPage(page, memberCoinChargeEntity);
+ List<MemberCoinChargeEntity> records = memberCoinCharge.getRecords();
+
+ Page<CoinInListVo> responsePage = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ if(CollUtil.isNotEmpty(records)) {
+ ArrayList<CoinInListVo> arrayList = new ArrayList<>();
+ for(MemberCoinChargeEntity memberCoinChargeEntitys : records) {
+ CoinInListVo coinInListVo = new CoinInListVo();
+ coinInListVo.setSymbol(memberCoinChargeEntitys.getSymbol());
+ coinInListVo.setAmount(memberCoinChargeEntitys.getAmount());
+ coinInListVo.setContent("充币");
+ coinInListVo.setStatus(memberCoinChargeEntitys.getStatus());
+ coinInListVo.setUpdateTime(memberCoinChargeEntitys.getUpdateTime());
+ arrayList.add(coinInListVo);
+ }
+ responsePage.setRecords(arrayList);
+ }
+ return Result.ok(responsePage);
+ }
+ //提币记录
+ if(type == 2) {
+ Page<MemberCoinWithdrawEntity> page = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ MemberCoinWithdrawEntity memberCoinWithdrawEntity = new MemberCoinWithdrawEntity();
+ memberCoinWithdrawEntity.setMemberId(memberId);
+ IPage<MemberCoinWithdrawEntity> memberCoinWithdraw = memberCoinWithdrawDao.findMemberCoinWithdrawInPage(page, memberCoinWithdrawEntity);
+ List<MemberCoinWithdrawEntity> records = memberCoinWithdraw.getRecords();
+
+ Page<CoinInListVo> responsePage = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ if(CollUtil.isNotEmpty(records)) {
+ ArrayList<CoinInListVo> arrayList = new ArrayList<>();
+ for(MemberCoinWithdrawEntity memberCoinWithdrawEntitys : records) {
+ CoinInListVo coinInListVo = new CoinInListVo();
+ coinInListVo.setSymbol(memberCoinWithdrawEntitys.getSymbol());
+ coinInListVo.setAmount(memberCoinWithdrawEntitys.getAmount());
+ coinInListVo.setContent("提币");
+ int status = memberCoinWithdrawEntitys.getStatus();
+ int statusOut = 0;
+ if(status == 1) {
+ statusOut = 0;
+ }
+ if(status == 2) {
+ statusOut = 1;
+ }
+ if(status == 3) {
+ statusOut = 2;
+ }
+ coinInListVo.setStatus(statusOut);
+ coinInListVo.setUpdateTime(memberCoinWithdrawEntitys.getUpdateTime());
+ coinInListVo.setIsInside(memberCoinWithdrawEntitys.getIsInside());
+ arrayList.add(coinInListVo);
+ }
+ responsePage.setRecords(arrayList);
+ }
+ return Result.ok(responsePage);
+ }
+ //划转记录
+ if(type == 3) {
+ Page<MemberAccountMoneyChange> page = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ MemberAccountMoneyChange memberAccountMoneyChange = new MemberAccountMoneyChange();
+ memberAccountMoneyChange.setMemberId(memberId);
+ IPage<MemberAccountMoneyChange> list = memberAccountMoneyChangeDao.coinInList(page, memberAccountMoneyChange);
+ List<MemberAccountMoneyChange> records = list.getRecords();
+
+ Page<CoinInListVo> responsePage = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ if(CollUtil.isNotEmpty(records)) {
+ ArrayList<CoinInListVo> arrayList = new ArrayList<>();
+ for(MemberAccountMoneyChange memberAccountMoneyChanges : records) {
+ CoinInListVo coinInListVo = new CoinInListVo();
+ coinInListVo.setSymbol(memberAccountMoneyChanges.getSymbol());
+ coinInListVo.setAmount(memberAccountMoneyChanges.getAmount());
+ coinInListVo.setContent(memberAccountMoneyChanges.getContent());
+ coinInListVo.setStatus(memberAccountMoneyChanges.getStatus());
+ coinInListVo.setUpdateTime(memberAccountMoneyChanges.getUpdateTime());
+ arrayList.add(coinInListVo);
+ }
+ responsePage.setRecords(arrayList);
+ }
+ return Result.ok(responsePage);
+ }
+ //其他记录
+ if(type == 4) {
+ Page<OrderCoinsDealEntity> page = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ MemberAccountMoneyChange memberAccountMoneyChange = new MemberAccountMoneyChange();
+ memberAccountMoneyChange.setMemberId(memberId);
+ IPage<MemberAccountMoneyChange> list = memberAccountMoneyChangeDao.selectWalletAgentIntoRecordsByMemIdTypeSymbol(page, memberAccountMoneyChange);
+ List<MemberAccountMoneyChange> records = list.getRecords();
+
+ Page<CoinInListVo> responsePage = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ if(CollUtil.isNotEmpty(records)) {
+ ArrayList<CoinInListVo> arrayList = new ArrayList<>();
+ for(MemberAccountMoneyChange memberAccountMoneyChanges : records) {
+ CoinInListVo coinInListVo = new CoinInListVo();
+ coinInListVo.setSymbol(memberAccountMoneyChanges.getSymbol());
+ coinInListVo.setAmount(memberAccountMoneyChanges.getAmount());
+ coinInListVo.setContent(memberAccountMoneyChanges.getContent());
+ coinInListVo.setStatus(memberAccountMoneyChanges.getStatus());
+ coinInListVo.setUpdateTime(memberAccountMoneyChanges.getUpdateTime());
+ arrayList.add(coinInListVo);
+ }
+ responsePage.setRecords(arrayList);
+ }
+ return Result.ok(responsePage);
+ }
+
+ return Result.fail(MessageSourceUtils.getString("member_controller_0005"));
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
}
--
Gitblit v1.9.1