1
zj
52 mins ago 544a424a02945e8e4f68d5261abddfce9f337957
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package com.yami.trading.service.user.impl;
 
import cn.hutool.json.JSONUtil;
import com.yami.trading.bean.model.Wallet;
import com.yami.trading.bean.model.WalletExtend;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.common.util.StringUtils;
import com.yami.trading.service.WalletService;
import com.yami.trading.service.user.UserRecomService;
import com.yami.trading.service.user.UserStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;
 
@Service
@Slf4j
public class UserStatisticsServiceImpl  implements UserStatisticsService {
 
 
    @Autowired
    UserRecomService userRecomService;
    @Autowired
    WalletService walletService;
 
 
    @Override
     public List<Map<String,Object>> getAssetsAll(String loginPartyId,String targetPartyId) {
 
        // 上提到controller了
        if (!StringUtils.isNullOrEmpty(loginPartyId)) {
//            List<String> children = this.userRecomService.findChildren(loginPartyId);
//            if (children.size() == 0) {
//                return new ArrayList<>();
//            }
//            if(!children.contains(targetPartyId)) throw new BusinessException("目标用户不属于登录人下级");
        }
        Map<String, Object> moneyAll = walletService.getMoneyAll(targetPartyId);
        Map<String, Object> nameMap = getNameMap();
        List<Map<String,Object>> result = new LinkedList<Map<String,Object>>();
 
        for(Map.Entry<String, Object> entry :nameMap.entrySet()) {
            if("money_trader".equals(entry.getKey())) {
                continue;
            }
            Map<String,Object> data = new HashMap<String,Object>();
            data.put("name", entry.getValue());
            data.put("value", moneyAll.get(entry.getKey()));
            result.add(data);
        }
        return result;
    }
 
 
    public Map<String,Object> getNameMap(){
        Map<String,Object> data = new LinkedHashMap<String, Object>();
        data.put("total", "总资产");
        data.put("money_all_coin", "钱包资产折合[USDT]");
        data.put("money_miner", "矿机");
        data.put("money_finance", "理财");
 
        data.put("forex_money_contract", "外汇永续合约");
        data.put("forex_money_futures", "外汇交割合约");
 
        data.put("indices_money_contract",  "ETF永续合约");
        data.put("indices_money_futures",  "ETF交割合约");
 
        data.put("cryptos_money_contract", "数字货币永续合约");
        data.put("cryptos_money_futures", "数字货币交割合约");
 
        data.put("us_stocks_money_contract", "美股永续合约");
        data.put("us_stocks_money_futures", "美股交割合约");
 
//        data.put("commodities_money_contract", "大宗商品永续合约");
//        data.put("commodities_money_futures", "大宗商品交割合约");
        return data;
    }
 
    @Override
    public List<Map<String,Object>> getWalletExtends(String loginPartyId, String targetPartyId) {
//        if (!StringUtils.isNullOrEmpty(loginPartyId)) {
//            List<String> children = this.userRecomService.findChildren(loginPartyId);
//            if (children.size() == 0) {
//                return new ArrayList<>();
//            }
//            if(!children.contains(targetPartyId)) throw new YamiShopBindException("目标用户不属于登录人下级");
//        }
        DecimalFormat df2 = new DecimalFormat("#.########");
        // 向下取整
        df2.setRoundingMode(RoundingMode.FLOOR);
        List<WalletExtend> findExtend = walletService.findExtend(targetPartyId);
        List<Map<String,Object>> result = new LinkedList<Map<String,Object>>();
        if(ObjectUtils.isNotEmpty(findExtend)) {
            for(WalletExtend we : findExtend) {
                if(ObjectUtils.isNotEmpty(we)) {
                    Map<String,Object> data = new HashMap<String,Object>();
                    if ("USDT_USER".equals(we.getWallettype())
                            || "ETH_DAPP".equals(we.getWallettype())
                            || "USDT_DAPP".equals(we.getWallettype())
                            || "ETH_USER".equals(we.getWallettype())) {
                        continue;
                    }
                    data.put("wallettype", we.getWallettype());
 
 
 
                    data.put("amount",    new BigDecimal(Double.valueOf(df2.format(we.getAmount()))));
                    data.put("lock_amount",null==we?0: new BigDecimal(Double.valueOf(df2.format(we.getLockAmount()))));
                    data.put("freeze_amount",null==we?0: new BigDecimal(Double.valueOf(df2.format(we.getFreezeAmount()))));
                   String walletType=we.getWallettype();
                    if (we.getWallettype()==null){
                        walletType="";
                    }
                    if (!walletType.toUpperCase().equals("USDT")) {
                        result.add(data);
                    }
                }
            }
        }
        Map<String,Object> data = new HashMap<String,Object>();
        Wallet wallet = walletService.saveWalletByPartyId(targetPartyId);
        data.put("wallettype", "usdt");
        data.put("amount",null==wallet?0: new BigDecimal(Double.valueOf(df2.format(wallet.getMoney()))));
        data.put("lock_amount",null==wallet?0: new BigDecimal(Double.valueOf(df2.format(wallet.getLockMoney()))));
        data.put("freeze_amount",null==wallet?0: new BigDecimal(Double.valueOf(df2.format(wallet.getFreezeMoney()))));
        result.add(0,data);
        return result;
    }
}