1
zj
2025-06-23 dc9bd22833255bc602dd42c7f603ecb50842ab35
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
package project.data.task;
 
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import kernel.exception.BusinessException;
import kernel.util.Arith;
import kernel.util.ThreadUtils;
import project.data.DataService;
import project.data.model.Realtime;
import project.user.UserDataService;
import project.wallet.Wallet;
import project.wallet.WalletExtend;
import project.wallet.WalletService;
 
/**
 * 用户每日统计钱包持有金额
 *
 */
public class UserDataHoldingMoneyJob {
    
    private static final Logger logger = LoggerFactory.getLogger(UserDataHoldingMoneyJob.class);
 
    private WalletService walletService;
    private UserDataService userDataService;
    private DataService dataService;
    
    public void taskJob() {
        try {
            Map<String, Double> party_amount = new HashMap<String, Double>();
            /**
             * usdt资产
             */
            List<Wallet> wallets = walletService.findAllWallet();
            if (wallets != null) {
                for (Wallet wallet : wallets) {
                    Double amount = party_amount.get(wallet.getPartyId().toString());
                    if (amount == null) {
                        amount = 0D;
                    }
                    if (amount != 0 || wallet.getMoney() != 0) {
                        party_amount.put(wallet.getPartyId().toString(), Arith.add(amount, wallet.getMoney()));
                    }
    
                }
            }
            /**
             * 各类币种资产
             */
            List<WalletExtend> walletExtends = walletService.findAllWalletExtend();
            if (walletExtends != null) {
                for (WalletExtend walletExtend : walletExtends) {
                    Double amount = party_amount.get(walletExtend.getPartyId().toString());
                    if (amount == null) {
                        amount = 0D;
                    }
                    if (amount != 0 || walletExtend.getAmount() != 0) {
                        List<Realtime> realtime_list = this.dataService.realtime(walletExtend.getWallettype());
                        Realtime realtime = null;
                        if (realtime_list.size() > 0) {
                            realtime = realtime_list.get(0);
                        } else {
                            throw new BusinessException("系统错误,请稍后重试");
                        }
    
                        party_amount.put(walletExtend.getPartyId().toString(),
                                Arith.add(amount, Arith.mul(realtime.getClose(), walletExtend.getAmount())));
                    }
                }
            }
            
            for(String partyId:party_amount.keySet()) {
                userDataService.saveHodingMoneyHandle(partyId, party_amount.get(partyId)==null?0d:party_amount.get(partyId));
            }
        } catch (Throwable e) {
            logger.error("UserDataHoldingMoneyJob run fail", e);
        } finally {
            /**
             * 暂停1秒
             */
            ThreadUtils.sleep(1000);
        }
    }
 
    public void setWalletService(WalletService walletService) {
        this.walletService = walletService;
    }
 
    public void setUserDataService(UserDataService userDataService) {
        this.userDataService = userDataService;
    }
 
    public void setDataService(DataService dataService) {
        this.dataService = dataService;
    }
    
    
}