gao
2020-05-25 73699775f5546177ce71e3bae33d83a8aa346793
src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java
New file
@@ -0,0 +1,109 @@
package com.xcong.excoin.modules.coin.service.impl;
import java.math.BigDecimal;
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.MemberWalletCoinEnum;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.coin.dao.MemberSelectSymbolsDao;
import com.xcong.excoin.modules.coin.dao.OrderCoinDao;
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.OrderCoinsEntity;
import com.xcong.excoin.modules.coin.entity.PlatformTradeSettingEntity;
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.utils.MessageSourceUtils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
@Service
public class OrderCoinServiceImpl extends ServiceImpl<OrderCoinDao, OrderCoinsEntity> implements OrderCoinService{
   @Resource
   TradeSettingDao platformTradeSettingDao;
   @Resource
   MemberWalletCoinDao memberWalletCoinDao;
   @Resource
   MemberSelectSymbolsDao memberSelectSymbolsDao;
   @Resource
   CnyUsdtExchangeDao cnyUsdtExchangeDao;
   @Override
   public Result enterTransactionPageOfWalletCoin(String symbol, String type) {
      if (StrUtil.isBlank(symbol)) {
         return Result.fail(MessageSourceUtils.getString("order_service_0001"));
      }
      //获取用户ID
      Long memberId = LoginUserUtils.getAppLoginUser().getId();
      //获取该币种的币币账户信息
      MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, symbol);
      PlatformTradeSettingEntity tradeSetting = platformTradeSettingDao.findTradeSetting();
      if (tradeSetting == null) {
         return Result.fail(MessageSourceUtils.getString("order_service_0003"));
      }
      //获取USDT的币币账户信息
      MemberWalletCoinEntity walletCoinUsdt = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId,
                                             MemberWalletCoinEnum.WALLETCOINCODE.getValue());
      /**
       * todo
       */
      //获取某个币种的收盘价
      //Double closePrice = symbolsService.getCloseSymbolsBySymbolsName(symbol+"/USDT");
      BigDecimal closePrice = new BigDecimal("100.0000");
      List<MemberSelectSymbolsEntity> memSymbols = memberSelectSymbolsDao.selectSymbolByMemIdAndSymbol(memberId, symbol);
      CnyUsdtExchange cnyUsdtExchange = cnyUsdtExchangeDao.getCNYAndUSDTOne();
      BigDecimal cnyUsdt = cnyUsdtExchange.getValue();
      Map<String, Object> map = new HashMap<String, Object>();
      if(CollUtil.isEmpty(memSymbols)) {
         map.put(MemberWalletCoinEnum.ENTERTRANSACTIONPAGEOFWALLETCOIN_ISCOLLECT_NO.getName(),
               MemberWalletCoinEnum.ENTERTRANSACTIONPAGEOFWALLETCOIN_ISCOLLECT_NO.getValue());//是否已经自选该币种
      }else {
         map.put(MemberWalletCoinEnum.ENTERTRANSACTIONPAGEOFWALLETCOIN_ISCOLLECT_YES.getName(),
               MemberWalletCoinEnum.ENTERTRANSACTIONPAGEOFWALLETCOIN_ISCOLLECT_YES.getValue());//是否已经自选该币种
      }
      if (ObjectUtil.isEmpty(walletCoin))
         return Result.fail(MessageSourceUtils.getString("order_service_0003"));
      map.put(MemberWalletCoinEnum.ENTERTRANSACTIONPAGEOFWALLETCOIN_SPREAD.getValue(), tradeSetting.getSpread());// 点差
      map.put(MemberWalletCoinEnum.ENTERTRANSACTIONPAGEOFWALLETCOIN_CLOSINGRATIO.getValue(), tradeSetting.getFeeRatio());// 手续费用率
      if(MemberWalletCoinEnum.ENTERTRANSACTIONPAGEOFWALLETCOIN_BUY.getValue().equals(type)) {//买入
         map.put(MemberWalletCoinEnum.ENTERTRANSACTIONPAGEOFWALLETCOIN_MEMBERMONEY.getValue(), walletCoinUsdt.getAvailableBalance());// 用户可用金额
      }else {
         map.put(MemberWalletCoinEnum.ENTERTRANSACTIONPAGEOFWALLETCOIN_MEMBERMONEY.getValue(), walletCoin.getAvailableBalance());// 用户可用金额
      }
      map.put(MemberWalletCoinEnum.ENTERTRANSACTIONPAGEOFWALLETCOIN_CURRENTPRICE.getValue(), closePrice);//当前价
      map.put(MemberWalletCoinEnum.ENTERTRANSACTIONPAGEOFWALLETCOIN_CNYUSDT.getValue(), cnyUsdt);//比例
      map.put(MemberWalletCoinEnum.ENTERTRANSACTIONPAGEOFWALLETCOIN_CURRENTPRICECNY.getValue(), cnyUsdt.multiply(closePrice));//换算成人民币的币种价格
      return Result.ok(map);
}
   @Override
   @Transactional
   public Result submitSalesWalletCoinOrder(String symbol, Integer type, Integer tradeType, BigDecimal price,
         BigDecimal amount) {
      return Result.ok(MessageSourceUtils.getString("order_service_0011"));
   }
}