From cc62127fe9fe8a32343e2c9d079e9118c504e15d Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Fri, 10 Jul 2020 12:17:20 +0800 Subject: [PATCH] Merge branch 'master' of https://gitee.com/chonggaoxiao/new_excoin --- src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java | 43 +++++++++++++++++++++++++++++++++++-------- 1 files changed, 35 insertions(+), 8 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 5f330e7..84c82d9 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 @@ -19,7 +19,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -38,15 +37,11 @@ import com.xcong.excoin.modules.coin.parameter.dto.FindAllWalletCoinOrderDto; 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.contract.entity.ContractOrderEntity; -import com.xcong.excoin.modules.contract.mapper.ContractOrderEntityMapper; -import com.xcong.excoin.modules.contract.parameter.vo.OrderListVo; import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao; import com.xcong.excoin.modules.member.entity.MemberSelectSymbolsEntity; import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity; @@ -166,7 +161,7 @@ public Result submitSalesWalletCoinOrder(String symbol, Integer type, Integer tradeType, BigDecimal price, BigDecimal amount) { //获取用户ID Long memberId = LoginUserUtils.getAppLoginUser().getId(); - + BigDecimal nowPriceinBigDecimal = price; //查询当前价 BigDecimal nowPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(symbol + "/USDT"))); @@ -204,7 +199,8 @@ // 创建订单 OrderCoinsEntity order = new OrderCoinsEntity(); - if (OrderCoinsEntity.TRADETYPE_FIXEDPRICE.equals(tradeType)) { + if ((OrderCoinsEntity.TRADETYPE_FIXEDPRICE.equals(tradeType) && type.equals(1) && price.compareTo(nowPrice) < 0) + || (OrderCoinsEntity.TRADETYPE_FIXEDPRICE.equals(tradeType) && type.equals(2) && price.compareTo(nowPrice) > 0)) { // 如果是限价交易直接插入主表数据 order.setMemberId(memberId); order.setOrderNo(generateSimpleSerialno(memberId.toString())); @@ -248,6 +244,14 @@ order.setEntrustCnt(amount); order.setEntrustPrice(price); order.setDealCnt(amount); + if ((OrderCoinsEntity.TRADETYPE_FIXEDPRICE.equals(tradeType) && type.equals(1) && price.compareTo(nowPrice) >= 0) + || (OrderCoinsEntity.TRADETYPE_FIXEDPRICE.equals(tradeType) && type.equals(2) && price.compareTo(nowPrice) <= 0)) { + // 手续费用(手续费=建仓价X数量X手续费率) + closingPrice = nowPrice.multiply(amount).multiply(tradeSetting.getCoinFeeRatio()); + //总费用 = 成交价*数量+手续费 + totalPayPrice = nowPrice.multiply(amount).add(closingPrice); + price = nowPrice; + } order.setDealPrice(price); order.setDealAmount(totalPayPrice); order.setOrderStatus(OrderCoinsEntity.ORDERSTATUS_DONE); @@ -263,7 +267,7 @@ detail.setTradeType(tradeType); detail.setSymbol(symbol); detail.setSymbolCnt(amount); - detail.setEntrustPrice(price); + detail.setEntrustPrice(nowPriceinBigDecimal); detail.setDealPrice(price); detail.setDealAmount(totalPayPrice); detail.setFeeAmount(closingPrice); @@ -318,6 +322,14 @@ List<OrderCoinsEntity> findCoinOrderListByMemberIdAndSysmbol = orderCoinsDao.findCoinOrderListByMemberIdAndSysmbol(memberId, symbol, status); if (CollUtil.isNotEmpty(findCoinOrderListByMemberIdAndSysmbol)) { for (OrderCoinsEntity orderCoinsEntity : findCoinOrderListByMemberIdAndSysmbol) { + orderCoinsEntity.setFeeAmount(orderCoinsEntity.getFeeAmount().setScale(4, BigDecimal.ROUND_DOWN)); + orderCoinsEntity.setMarkPrice(orderCoinsEntity.getMarkPrice().setScale(4, BigDecimal.ROUND_DOWN)); + orderCoinsEntity.setEntrustCnt(orderCoinsEntity.getEntrustCnt().setScale(4, BigDecimal.ROUND_DOWN)); + orderCoinsEntity.setEntrustPrice(orderCoinsEntity.getEntrustPrice().setScale(4, BigDecimal.ROUND_DOWN)); + orderCoinsEntity.setDealCnt(orderCoinsEntity.getDealCnt().setScale(4, BigDecimal.ROUND_DOWN)); + orderCoinsEntity.setDealPrice(orderCoinsEntity.getDealPrice().setScale(4, BigDecimal.ROUND_DOWN)); + orderCoinsEntity.setDealAmount(orderCoinsEntity.getDealAmount().setScale(4, BigDecimal.ROUND_DOWN)); + OrderWalletCoinVo entityToVo = OrderWalletCoinMapper.INSTANCE.entityToVo(orderCoinsEntity); arrayList.add(entityToVo); } @@ -415,6 +427,16 @@ orderCoinsDealEntity.setMemberId(memberId); orderCoinsDealEntity.setSymbol(findAllWalletCoinOrderDto.getSymbol()); IPage<OrderCoinsDealEntity> list = orderCoinDealDao.findAllWalletCoinOrderInPage(page, orderCoinsDealEntity); + List<OrderCoinsDealEntity> records = list.getRecords(); + if(CollUtil.isNotEmpty(records)) { + for(OrderCoinsDealEntity OrderCoinsDealEntity : records) { + orderCoinsDealEntity.setSymbolCnt(orderCoinsDealEntity.getSymbolCnt()); + OrderCoinsDealEntity.setEntrustPrice(orderCoinsDealEntity.getEntrustPrice().setScale(4, BigDecimal.ROUND_DOWN)); + orderCoinsDealEntity.setDealPrice(orderCoinsDealEntity.getDealPrice().setScale(4, BigDecimal.ROUND_DOWN)); + orderCoinsDealEntity.setDealAmount(orderCoinsDealEntity.getDealAmount().setScale(4, BigDecimal.ROUND_DOWN)); + orderCoinsDealEntity.setFeeAmount(orderCoinsDealEntity.getFeeAmount().setScale(4, BigDecimal.ROUND_DOWN)); + } + } Page<OrderWalletCoinDealVo> pageEntityToPageVo = OrderWalletCoinDealMapper.INSTANCE.pageEntityToPageVo(list); return Result.ok(pageEntityToPageVo); @@ -425,6 +447,11 @@ //获取用户ID Long memberId = LoginUserUtils.getAppLoginUser().getId(); OrderCoinsDealEntity selectWalletCoinOrder = orderCoinDealDao.selectWalletCoinOrder(orderId, memberId); + selectWalletCoinOrder.setSymbolCnt(selectWalletCoinOrder.getSymbolCnt()); + selectWalletCoinOrder.setEntrustPrice(selectWalletCoinOrder.getEntrustPrice().setScale(4, BigDecimal.ROUND_DOWN)); + selectWalletCoinOrder.setDealPrice(selectWalletCoinOrder.getDealPrice().setScale(4, BigDecimal.ROUND_DOWN)); + selectWalletCoinOrder.setDealAmount(selectWalletCoinOrder.getDealAmount().setScale(4, BigDecimal.ROUND_DOWN)); + selectWalletCoinOrder.setFeeAmount(selectWalletCoinOrder.getFeeAmount().setScale(4, BigDecimal.ROUND_DOWN)); OrderWalletCoinDealVo entityToVo = OrderWalletCoinDealMapper.INSTANCE.entityToVoOrder(selectWalletCoinOrder); return Result.ok(entityToVo); } -- Gitblit v1.9.1