xiaoyong931011
2020-05-30 d2e6c0aba08b697ca5618affc2c34af9a37bbe2b
src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java
@@ -29,6 +29,7 @@
import com.xcong.excoin.modules.coin.entity.OrderCoinsEntity;
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;
@@ -153,8 +154,7 @@
   @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();
         
@@ -277,7 +277,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);
            }
         }
@@ -321,10 +322,10 @@
   @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"));
@@ -334,7 +335,7 @@
               
               String symbol = orderCoinsEntity.getSymbol();
               
               if(orderCoinsEntity.getOrderType() == OrderCoinsEntity.TRADETYPE_FIXEDPRICE) {
               if(OrderCoinsEntity.ORDERTYPE_BUY.equals(orderCoinsEntity.getOrderType())) {
                  //如果是限价买入,撤单将USDT账户冻结金额返回
                  String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
                  MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, walletCode);
@@ -342,7 +343,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));
@@ -360,13 +361,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();
@@ -380,7 +380,6 @@
                     return Result.ok(MessageSourceUtils.getString("order_service_0013"));
                  }
               }
               OrderCoinsDealEntity detail = new OrderCoinsDealEntity();
               detail.setMemberId(memberId);
               detail.setOrderId(orderCoinsEntity.getId());
@@ -388,6 +387,7 @@
               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));
@@ -462,4 +462,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);
   }
}