From ed053177a03da095f10d112898233913b2b5fc27 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Wed, 03 Jun 2020 19:38:04 +0800
Subject: [PATCH] modify
---
src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java | 141 ++++++++++++++++++++++++++++-------------------
1 files changed, 84 insertions(+), 57 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java b/src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java
index eed4b40..3fa8f02 100644
--- a/src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java
@@ -12,6 +12,7 @@
import javax.annotation.Resource;
+import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -23,25 +24,28 @@
import com.xcong.excoin.modules.coin.dao.MemberSelectSymbolsDao;
import com.xcong.excoin.modules.coin.dao.OrderCoinDealDao;
import com.xcong.excoin.modules.coin.dao.OrderCoinsDao;
-import com.xcong.excoin.modules.coin.dao.platform.CnyUsdtExchangeDao;
-import com.xcong.excoin.modules.coin.dao.platform.TradeSettingDao;
-import com.xcong.excoin.modules.coin.entity.CnyUsdtExchange;
import com.xcong.excoin.modules.coin.entity.MemberAccountFlowEntity;
import com.xcong.excoin.modules.coin.entity.OrderCoinsDealEntity;
import com.xcong.excoin.modules.coin.entity.OrderCoinsEntity;
-import com.xcong.excoin.modules.coin.entity.PlatformTradeSettingEntity;
import com.xcong.excoin.modules.coin.mapper.OrderWalletCoinDealMapper;
import com.xcong.excoin.modules.coin.mapper.OrderWalletCoinMapper;
+import com.xcong.excoin.modules.coin.parameter.vo.FindCollectListVo;
import com.xcong.excoin.modules.coin.parameter.vo.MemberSelectSymbolsVo;
import com.xcong.excoin.modules.coin.parameter.vo.OrderWalletCoinDealListVo;
import com.xcong.excoin.modules.coin.parameter.vo.OrderWalletCoinDealVo;
+import com.xcong.excoin.modules.coin.parameter.vo.OrderWalletCoinListVo;
import com.xcong.excoin.modules.coin.parameter.vo.OrderWalletCoinVo;
import com.xcong.excoin.modules.coin.parameter.vo.TransactionPageOfWalletCoinVo;
import com.xcong.excoin.modules.coin.service.OrderCoinService;
import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
import com.xcong.excoin.modules.member.entity.MemberSelectSymbolsEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
+import com.xcong.excoin.modules.platform.dao.PlatformCnyUsdtExchangeDao;
+import com.xcong.excoin.modules.platform.dao.TradeSettingDao;
+import com.xcong.excoin.modules.platform.entity.PlatformTradeSettingEntity;
+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;
@@ -58,13 +62,15 @@
@Resource
MemberSelectSymbolsDao memberSelectSymbolsDao;
@Resource
- CnyUsdtExchangeDao cnyUsdtExchangeDao;
+ PlatformCnyUsdtExchangeDao cnyUsdtExchangeDao;
@Resource
OrderCoinsDao orderCoinsDao;
@Resource
OrderCoinDealDao orderCoinDealDao;
@Resource
MemberAccountFlowEntityDao memberAccountFlowEntityDao;
+ @Resource
+ RedisUtils redisUtils;
@Override
public String generateSimpleSerialno(String userId) {
@@ -92,7 +98,7 @@
}
@Override
- public Result enterTransactionPageOfWalletCoin(String symbol, String type) {
+ public Result enterTransactionPageOfWalletCoin(String symbol) {
if (StrUtil.isBlank(symbol)) {
return Result.fail(MessageSourceUtils.getString("order_service_0001"));
}
@@ -108,16 +114,12 @@
//获取USDT的币币账户信息
MemberWalletCoinEntity walletCoinUsdt = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId,
MemberWalletCoinEnum.WALLETCOINCODE.getValue());
- /**
- * todo
- */
- //获取某个币种的收盘价
- //Double closePrice = symbolsService.getCloseSymbolsBySymbolsName(symbol+"/USDT");
- BigDecimal closePrice = new BigDecimal("100.0000");
+
+ BigDecimal closePrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(symbol+"/USDT")));
List<MemberSelectSymbolsEntity> memSymbols = memberSelectSymbolsDao.selectSymbolByMemIdAndSymbol(memberId, symbol);
-
- CnyUsdtExchange cnyUsdtExchange = cnyUsdtExchangeDao.getCNYAndUSDTOne();
+
+ PlatformCnyUsdtExchangeEntity cnyUsdtExchange = cnyUsdtExchangeDao.getCNYAndUSDTOne();
BigDecimal cnyUsdt = cnyUsdtExchange.getValue();
TransactionPageOfWalletCoinVo transactionPageOfWalletCoinVo = new TransactionPageOfWalletCoinVo();
//是否自选
@@ -131,36 +133,30 @@
// 点差
transactionPageOfWalletCoinVo.setSpread(tradeSetting.getSpread().setScale(4, BigDecimal.ROUND_DOWN));
// 手续费用率
- transactionPageOfWalletCoinVo.setFeeRatio(tradeSetting.getFeeRatio().setScale(4, BigDecimal.ROUND_DOWN));
+ transactionPageOfWalletCoinVo.setFeeRatio(tradeSetting.getCoinFeeRatio().setScale(4, BigDecimal.ROUND_DOWN));
// 用户可用金额
- if(MemberWalletCoinEnum.ENTERTRANSACTIONPAGEOFWALLETCOIN_BUY.getValue().equals(type)) {//买入
- transactionPageOfWalletCoinVo.setAvailableBalance(walletCoinUsdt.getAvailableBalance().setScale(4, BigDecimal.ROUND_DOWN));
- }else {
- transactionPageOfWalletCoinVo.setAvailableBalance(walletCoin.getAvailableBalance().setScale(4, BigDecimal.ROUND_DOWN));
- }
+ transactionPageOfWalletCoinVo.setAvailableBalanceBuy(walletCoinUsdt.getAvailableBalance().setScale(4, BigDecimal.ROUND_DOWN));
+ transactionPageOfWalletCoinVo.setAvailableBalanceSell(walletCoin.getAvailableBalance().setScale(4, BigDecimal.ROUND_DOWN));
//当前价
transactionPageOfWalletCoinVo.setCurrentPrice(closePrice.setScale(4, BigDecimal.ROUND_DOWN));
//比例
transactionPageOfWalletCoinVo.setCnyUsdt(cnyUsdt.setScale(4, BigDecimal.ROUND_DOWN));
//换算成人民币的币种价格
transactionPageOfWalletCoinVo.setCurrentPriceCny(cnyUsdt.multiply(closePrice).setScale(4, BigDecimal.ROUND_DOWN));
+
+ transactionPageOfWalletCoinVo.setSymbol(symbol);
return Result.ok(transactionPageOfWalletCoinVo);
}
@Override
@Transactional
- public Result submitSalesWalletCoinOrder(String symbol, Integer type, Integer tradeType, BigDecimal price,
- BigDecimal amount) {
+ public Result submitSalesWalletCoinOrder(String symbol, Integer type, Integer tradeType, BigDecimal price,BigDecimal amount) {
//获取用户ID
Long memberId = LoginUserUtils.getAppLoginUser().getId();
- /**
- * todo
- */
//查询当前价
- //BigDecimal nowPrice = new BigDecimal(redisUtil.getString(CoinTypeConConvert.convertToKey(symbol+"/USDT")));
+ BigDecimal nowPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(symbol+"/USDT")));
- BigDecimal nowPrice = new BigDecimal("10.0000");
// 获取交易管理的杠杠倍率,手续费率等信息,由平台进行设置
symbol = symbol.toUpperCase();
MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, symbol);
@@ -173,7 +169,7 @@
return Result.fail(MessageSourceUtils.getString("order_service_0009"));
}
// 手续费用(手续费=建仓价X数量X手续费率)
- BigDecimal closingPrice = price.multiply(amount).multiply(new BigDecimal(MemberWalletCoinEnum.SUBMITSALESWALLETCOINORDER_SERVICERATE.getValue()));
+ BigDecimal closingPrice = price.multiply(amount).multiply(tradeSetting.getCoinFeeRatio());
//总费用 = 成交价*数量+手续费
BigDecimal totalPayPrice = price.multiply(amount).add(closingPrice);
@@ -258,6 +254,7 @@
detail.setDealPrice(price.setScale(4, BigDecimal.ROUND_DOWN));
detail.setDealAmount(totalPayPrice.setScale(4, BigDecimal.ROUND_DOWN));
detail.setFeeAmount(closingPrice.setScale(4, BigDecimal.ROUND_DOWN));
+ detail.setOrderStatus(OrderCoinsDealEntity.ORDERSTATUS_DONE);
orderCoinDealDao.insert(detail);
if(OrderCoinsEntity.ORDERTYPE_BUY.equals(type)) {
@@ -273,7 +270,8 @@
walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().subtract(amount).setScale(4, BigDecimal.ROUND_DOWN));
memberWalletCoinDao.updateById(walletCoin);
- walletCoinUsdt.setAvailableBalance(walletCoinUsdt.getAvailableBalance().add(totalPayPrice).setScale(4, BigDecimal.ROUND_DOWN));
+ BigDecimal subtract = totalPayPrice.subtract(closingPrice).subtract(closingPrice);
+ walletCoinUsdt.setAvailableBalance(walletCoinUsdt.getAvailableBalance().add(subtract).setScale(4, BigDecimal.ROUND_DOWN));
memberWalletCoinDao.updateById(walletCoinUsdt);
}
}
@@ -301,18 +299,26 @@
public Result getEntrustWalletCoinOrder(String symbol, Integer status) {
//获取用户ID
Long memberId = LoginUserUtils.getAppLoginUser().getId();
+ OrderWalletCoinListVo orderWalletCoinListVo = new OrderWalletCoinListVo();
- OrderCoinsEntity orderCoin = orderCoinsDao.findCoinOrderListByMemberIdAndSysmbol(memberId, symbol, status);
- OrderWalletCoinVo entityToVo = OrderWalletCoinMapper.INSTANCE.entityToVo(orderCoin);
- return Result.ok(entityToVo);
+ List<OrderWalletCoinVo> arrayList = new ArrayList<>();
+ List<OrderCoinsEntity> findCoinOrderListByMemberIdAndSysmbol = orderCoinsDao.findCoinOrderListByMemberIdAndSysmbol(memberId, symbol, status);
+ if(CollUtil.isNotEmpty(findCoinOrderListByMemberIdAndSysmbol)) {
+ for(OrderCoinsEntity orderCoinsEntity : findCoinOrderListByMemberIdAndSysmbol) {
+ OrderWalletCoinVo entityToVo = OrderWalletCoinMapper.INSTANCE.entityToVo(orderCoinsEntity);
+ arrayList.add(entityToVo);
+ }
+ }
+ orderWalletCoinListVo.setOrderWalletCoinVo(arrayList);
+ return Result.ok(arrayList);
}
@Override
@Transactional
- public Result cancelEntrustWalletCoinOrder(String orderNo) {
+ public Result cancelEntrustWalletCoinOrder(String orderId) {
//获取用户ID
Long memberId = LoginUserUtils.getAppLoginUser().getId();
- OrderCoinsEntity orderCoinsEntity = orderCoinsDao.findWalletCoinOrderByOrderNo(orderNo);
+ OrderCoinsEntity orderCoinsEntity = orderCoinsDao.selectById(orderId);
if(ObjectUtil.isNotEmpty(orderCoinsEntity) && orderCoinsEntity.getMemberId() == memberId) {
if(orderCoinsEntity.getOrderStatus() == OrderCoinsEntity.ORDERSTATUS_CANCEL){
return Result.fail(MessageSourceUtils.getString("order_service_0012"));
@@ -322,7 +328,22 @@
String symbol = orderCoinsEntity.getSymbol();
- if(orderCoinsEntity.getOrderType() == OrderCoinsEntity.TRADETYPE_FIXEDPRICE) {
+ OrderCoinsDealEntity detail = new OrderCoinsDealEntity();
+ detail.setMemberId(memberId);
+ detail.setOrderId(orderCoinsEntity.getId());
+ detail.setOrderNo(generateSimpleSerialno(memberId.toString()));
+ detail.setOrderType(orderCoinsEntity.getOrderType());
+ detail.setTradeType(orderCoinsEntity.getTradeType());
+ detail.setSymbol(symbol);
+ detail.setOrderStatus(OrderCoinsDealEntity.ORDERSTATUS_CANCEL);
+ detail.setSymbolCnt(orderCoinsEntity.getEntrustCnt());
+ detail.setEntrustPrice(orderCoinsEntity.getEntrustPrice().setScale(4, BigDecimal.ROUND_DOWN));
+ detail.setDealPrice(orderCoinsEntity.getDealPrice().setScale(4, BigDecimal.ROUND_DOWN));
+ detail.setDealAmount(orderCoinsEntity.getDealAmount().setScale(4, BigDecimal.ROUND_DOWN));
+ detail.setFeeAmount(orderCoinsEntity.getFeeAmount().setScale(4, BigDecimal.ROUND_DOWN));
+ orderCoinDealDao.insert(detail);
+
+ if(OrderCoinsEntity.ORDERTYPE_BUY.equals(orderCoinsEntity.getOrderType())) {
//如果是限价买入,撤单将USDT账户冻结金额返回
String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, walletCode);
@@ -330,7 +351,7 @@
if (ObjectUtil.isNotEmpty(walletCoin)) {
//手续费 = 开仓价*数量*手续费率
//返还金额=开仓价*未成交数量+手续费
- BigDecimal returnBalance = orderCoinsEntity.getEntrustPrice().add(orderCoinsEntity.getFeeAmount());
+ BigDecimal returnBalance = orderCoinsEntity.getDealAmount();
walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(returnBalance).setScale(4, BigDecimal.ROUND_DOWN));
walletCoin.setFrozenBalance(walletCoin.getFrozenBalance().subtract(returnBalance).setScale(4, BigDecimal.ROUND_DOWN));
@@ -348,13 +369,12 @@
}
}else {
//如果是限价卖出,撤单将对应的钱包冻结金额返回
- String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
- MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, walletCode);
+ MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, symbol);
if (ObjectUtil.isNotEmpty(walletCoin)) {
//返还金额=开仓价*未成交数量
BigDecimal returnBalance = walletCoin.getAvailableBalance().add(walletCoin.getFrozenBalance());
walletCoin.setAvailableBalance(returnBalance.setScale(4, BigDecimal.ROUND_DOWN));
- walletCoin.setFrozenBalance(BigDecimal.ZERO);
+ walletCoin.setFrozenBalance(walletCoin.getFrozenBalance().subtract(returnBalance).setScale(4, BigDecimal.ROUND_DOWN));
memberWalletCoinDao.updateById(walletCoin);
// 流水记录
MemberAccountFlowEntity record = new MemberAccountFlowEntity();
@@ -368,36 +388,22 @@
return Result.ok(MessageSourceUtils.getString("order_service_0013"));
}
}
-
- OrderCoinsDealEntity detail = new OrderCoinsDealEntity();
- detail.setMemberId(memberId);
- detail.setOrderId(orderCoinsEntity.getId());
- detail.setOrderNo(generateSimpleSerialno(memberId.toString()));
- detail.setOrderType(orderCoinsEntity.getOrderType());
- detail.setTradeType(orderCoinsEntity.getTradeType());
- detail.setSymbol(symbol);
- detail.setSymbolCnt(orderCoinsEntity.getEntrustCnt());
- detail.setEntrustPrice(orderCoinsEntity.getEntrustPrice().setScale(4, BigDecimal.ROUND_DOWN));
- detail.setDealPrice(orderCoinsEntity.getDealPrice().setScale(4, BigDecimal.ROUND_DOWN));
- detail.setDealAmount(orderCoinsEntity.getDealAmount().setScale(4, BigDecimal.ROUND_DOWN));
- detail.setFeeAmount(orderCoinsEntity.getFeeAmount().setScale(4, BigDecimal.ROUND_DOWN));
- orderCoinDealDao.insert(detail);
}
return Result.fail(MessageSourceUtils.getString("order_service_0043"));
}
@Override
- public Result findAllWalletCoinOrder() {
+ public Result findAllWalletCoinOrder(String symbol) {
//获取用户ID
Long memberId = LoginUserUtils.getAppLoginUser().getId();
OrderWalletCoinDealListVo orderWalletCoinDealListVo = new OrderWalletCoinDealListVo();
List<OrderWalletCoinDealVo> arrayList = new ArrayList<OrderWalletCoinDealVo>();
- List<OrderCoinsDealEntity> selectAllWalletCoinOrder = orderCoinDealDao.selectAllWalletCoinOrder(memberId);
+ List<OrderCoinsDealEntity> selectAllWalletCoinOrder = orderCoinDealDao.selectAllWalletCoinOrderBySymbol(memberId,symbol);
if(CollUtil.isNotEmpty(selectAllWalletCoinOrder)) {
for(OrderCoinsDealEntity orderCoinsDealEntity: selectAllWalletCoinOrder) {
- OrderWalletCoinDealVo entityToVo = OrderWalletCoinDealMapper.INSTANCE.entityToVo(orderCoinsDealEntity);
+ OrderWalletCoinDealVo entityToVo = OrderWalletCoinDealMapper.INSTANCE.entityToVoOrder(orderCoinsDealEntity);
arrayList.add(entityToVo);
}
}
@@ -410,7 +416,7 @@
//获取用户ID
Long memberId = LoginUserUtils.getAppLoginUser().getId();
OrderCoinsDealEntity selectWalletCoinOrder = orderCoinDealDao.selectWalletCoinOrder(orderId,memberId);
- OrderWalletCoinDealVo entityToVo = OrderWalletCoinDealMapper.INSTANCE.entityToVo(selectWalletCoinOrder);
+ OrderWalletCoinDealVo entityToVo = OrderWalletCoinDealMapper.INSTANCE.entityToVoOrder(selectWalletCoinOrder);
return Result.ok(entityToVo);
}
@@ -428,6 +434,7 @@
}else {
Map<String, Object> columnMap = new HashMap<>();
columnMap.put("symbol", symbol);
+ columnMap.put("member_id", memberId);
memberSelectSymbolsDao.deleteByMap(columnMap);;
return Result.ok(MessageSourceUtils.getString("order_service_0016"));
}
@@ -449,4 +456,24 @@
return Result.ok(memberSelectSymbolsVo);
}
+ @Override
+ public Result findCollectList() {
+ //获取用户ID
+ Long memberId = LoginUserUtils.getAppLoginUser().getId();
+ List<MemberSelectSymbolsEntity> selectByMap = memberSelectSymbolsDao.selectSymbolByMemId(memberId);
+
+ FindCollectListVo findCollectListVo = new FindCollectListVo();
+ List<MemberSelectSymbolsVo> arrayList = new ArrayList<>();
+ if(CollUtil.isNotEmpty(selectByMap)) {
+ for(MemberSelectSymbolsEntity memberSelectSymbolsEntity : selectByMap) {
+ MemberSelectSymbolsVo memberSelectSymbolsVo = new MemberSelectSymbolsVo();
+ memberSelectSymbolsVo.setSymbol(memberSelectSymbolsEntity.getSymbol());
+ arrayList.add(memberSelectSymbolsVo);
+ }
+ }
+ findCollectListVo.setMemberSelectSymbolsVo(arrayList);
+
+ return Result.ok(findCollectListVo);
+ }
+
}
--
Gitblit v1.9.1