xiaoyong931011
2020-05-25 6f44fa20505ec0b1c95b460043f25b9050511aa0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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"));
    }
 
}