peternameyakj
2024-08-08 cbc26f3f148e9f328f4fa1536c30b16946360a81
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package project.wallet.job;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import org.apache.commons.lang3.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import kernel.util.Arith;
import kernel.util.ThreadUtils;
import kernel.web.ApplicationUtil;
import project.Constants;
import project.log.MoneyLog;
import project.log.MoneyLogService;
import project.monitor.AutoMonitorPoolDataService;
import project.monitor.AutoMonitorWalletService;
import project.monitor.mining.MiningConfig;
import project.monitor.mining.MiningConfigService;
import project.monitor.mining.MiningService;
import project.monitor.mining.job.MiningIncome;
import project.monitor.pledge.PledgeConfig;
import project.monitor.pledge.PledgeConfigService;
import project.party.PartyService;
import project.party.model.Party;
import project.party.model.UserRecom;
import project.party.recom.UserRecomService;
import project.syspara.Syspara;
import project.syspara.SysparaService;
import project.wallet.Wallet;
import project.wallet.WalletService;
 
public class WalletIncomeJob {
    private static final Logger logger = LoggerFactory.getLogger(WalletIncomeJob.class);
 
    private MiningConfigService miningConfigService;
 
    private UserRecomService userRecomService;
 
    private List<Party> items;
 
    private MiningService miningService;
 
    private AutoMonitorPoolDataService autoMonitorPoolDataService;
    
    private PartyService partyService;
    
    private SysparaService sysparaService;
    
    private AutoMonitorWalletService autoMonitorWalletService;
 
 
    public void walletIncomeJob() {    
        Syspara syspara = sysparaService.find("balance_income");        
        if(ObjectUtils.isEmpty(syspara)){
            logger.error("余额收益没有配置");
            return;
        }
        if("0".equals(syspara.getValue())) {
            logger.error("余额收益已关闭");
            return;
        }
        List<Party> list = partyService.getAll();
 
        List<Party> items = new ArrayList<Party>();
 
        for (Party party : list) {
            /*
             * 非代理
             */
            if (!Constants.SECURITY_ROLE_AGENT.equals(party.getRolename())
                    && !Constants.SECURITY_ROLE_AGENTLOW.equals(party.getRolename())) {
                items.add(party);
            }
        }
        PledgeConfigService pledgeConfigService =ApplicationUtil.getBean(PledgeConfigService.class);    
        for (int i = 0; i < items.size(); i++) {
            try {
                Party item = items.get(i);
                PledgeConfig pledgeConfig = pledgeConfigService.getConfig(item.getId().toString());
                MiningIncome miningIncome = this.execute(item, pledgeConfig);                
                MoneyLogService moneyLogService = ApplicationUtil.getBean(MoneyLogService.class);
                WalletService walletService = ApplicationUtil.getBean(WalletService.class);
                Wallet wallet = walletService.saveWalletByPartyId(miningIncome.getPartyId());
                double amount_before = wallet.getMoney();
                walletService.update(wallet.getPartyId().toString(), miningIncome.getValue());
                MoneyLog moneylog = new MoneyLog();
                moneylog.setCategory(Constants.MONEYLOG_FINANCE);
                moneylog.setAmount_before(amount_before);
                moneylog.setAmount(miningIncome.getValue());
                moneylog.setAmount_after(Arith.add(wallet.getMoney(), miningIncome.getValue()));
                moneylog.setLog("余额每日收益下发");
                moneylog.setPartyId(wallet.getPartyId());
                moneylog.setWallettype(Constants.WALLET);
                moneylog.setContent_type(Constants.MONEYLOG_CONTENT_FINANCE_PROFIT);
                moneylog.setCreateTime(new Date());
                moneyLogService.save(moneylog);
                ThreadUtils.sleep(50);
            } catch (Exception e) {
                logger.error("walletIncomeJob taskExecutor.execute() fail", e);
            }
        }                
    }
    
    private MiningIncome execute(Party item,PledgeConfig pledgeConfig) {
        MiningIncome miningIncome = new MiningIncome();
        try {
            List<UserRecom> parents = userRecomService.getParents(item.getId().toString());
            MiningConfig config = new MiningConfig();
            config.setConfig(pledgeConfig.getConfig());
            config.setPartyId(item.getId());
            miningIncome = miningService.newIncomeProcess(item, config, parents);
        } catch (Throwable t) {
            logger.error("WalletIncomeJob taskExecutor.execute() fail", t);
        }
        return miningIncome;
    }
 
    public MiningConfigService getMiningConfigService() {
        return miningConfigService;
    }
 
 
    public void setMiningConfigService(MiningConfigService miningConfigService) {
        this.miningConfigService = miningConfigService;
    }
 
 
    public UserRecomService getUserRecomService() {
        return userRecomService;
    }
 
 
    public void setUserRecomService(UserRecomService userRecomService) {
        this.userRecomService = userRecomService;
    }
 
 
    public List<Party> getItems() {
        return items;
    }
 
 
    public void setItems(List<Party> items) {
        this.items = items;
    }
 
 
    public MiningService getMiningService() {
        return miningService;
    }
 
 
    public void setMiningService(MiningService miningService) {
        this.miningService = miningService;
    }
 
 
    public AutoMonitorPoolDataService getAutoMonitorPoolDataService() {
        return autoMonitorPoolDataService;
    }
 
 
    public void setAutoMonitorPoolDataService(AutoMonitorPoolDataService autoMonitorPoolDataService) {
        this.autoMonitorPoolDataService = autoMonitorPoolDataService;
    }
 
 
    public PartyService getPartyService() {
        return partyService;
    }
 
 
    public void setPartyService(PartyService partyService) {
        this.partyService = partyService;
    }
 
 
    public SysparaService getSysparaService() {
        return sysparaService;
    }
 
 
    public void setSysparaService(SysparaService sysparaService) {
        this.sysparaService = sysparaService;
    }
 
 
    public AutoMonitorWalletService getAutoMonitorWalletService() {
        return autoMonitorWalletService;
    }
 
 
    public void setAutoMonitorWalletService(AutoMonitorWalletService autoMonitorWalletService) {
        this.autoMonitorWalletService = autoMonitorWalletService;
    }
    
}