1
zj
2024-07-12 bc9801d6adf582325e8213df11f597f82deda973
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
package project.web.admin.monitor;
 
import java.math.BigDecimal;
import java.text.MessageFormat;
 
import javax.servlet.http.HttpServletRequest;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
 
import kernel.exception.BusinessException;
import kernel.util.StringUtils;
import kernel.web.PageActionSupport;
import project.monitor.AdminAutoMonitorPoolDataService;
import project.monitor.AutoMonitorPoolDataService;
import project.monitor.model.AutoMonitorPoolData;
 
/**
 * 矿池产出数据
 */
@RestController
public class AdminAutoMonitorPoolDataController extends PageActionSupport {
 
    private Logger logger = LoggerFactory.getLogger(AdminAutoMonitorPoolDataController.class);
 
    @Autowired
    private AdminAutoMonitorPoolDataService adminAutoMonitorPoolDataService;
    
    @Autowired
    private AutoMonitorPoolDataService autoMonitorPoolDataService;
    
    private final String action = "normal/adminAutoMonitorPoolDataAction!";
 
 
    /**
     * 修改 矿池产出数据 页面
     */
    @RequestMapping(action + "toUpdate.action")
    public ModelAndView toUpdate(HttpServletRequest request) {
        String message = request.getParameter("message");
        String error = request.getParameter("error");
 
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("auto_monitor_pool_data_update");
 
        try {
 
            AutoMonitorPoolData entity = this.autoMonitorPoolDataService.findDefault();
 
            modelAndView.addObject("rate", entity.getRate());
            modelAndView.addObject("total_output", new BigDecimal(entity.getTotal_output()).toPlainString());
            modelAndView.addObject("user_revenue", new BigDecimal(entity.getUser_revenue()).toPlainString());
            modelAndView.addObject("verifier", new BigDecimal(entity.getVerifier()).toPlainString());
            modelAndView.addObject("notice_logs", entity.getNotice_logs());
            
            modelAndView.addObject("miningName", entity.getMiningName());
            modelAndView.addObject("tradingSum", new BigDecimal(entity.getTradingSum()).toPlainString());            
            modelAndView.addObject("dayRateMin", entity.getDayRateMin());
            modelAndView.addObject("dayRateMax", entity.getDayRateMax());
            modelAndView.addObject("miningAmountMin", entity.getMiningAmountMin());
            modelAndView.addObject("miningAmountMax", entity.getMiningAmountMax());
            modelAndView.addObject("node_num", entity.getNode_num());
            modelAndView.addObject("mining_total", new BigDecimal(entity.getMining_total()).toPlainString());
 
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            return modelAndView;
        } catch (Throwable t) {
            logger.error("update error ", t);
            modelAndView.addObject("error", "程序错误");
            return modelAndView;
        }
 
        modelAndView.addObject("message", message);
        modelAndView.addObject("error", error);
        return modelAndView;
    }
 
    /**
     * 修改 矿池产出数据
     */
    @RequestMapping(action + "update.action")
    public ModelAndView update(HttpServletRequest request) {
        String total_output = request.getParameter("total_output");
        String user_revenue = request.getParameter("user_revenue");
        String verifier = request.getParameter("verifier");
        String rate = request.getParameter("rate");
        String notice_logs = request.getParameter("notice_logs");
        
        String miningName = request.getParameter("miningName");
        String tradingSum_temp = request.getParameter("tradingSum");
        String dayRateMin_temp = request.getParameter("dayRateMin");
        String dayRateMax_temp = request.getParameter("dayRateMax");
        String miningAmountMin_temp = request.getParameter("miningAmountMin");
        String miningAmountMax_temp = request.getParameter("miningAmountMax");
        String node_num_temp = request.getParameter("node_num");
        String mining_total_temp = request.getParameter("mining_total");
 
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("total_output", new BigDecimal(total_output).toPlainString());
        modelAndView.addObject("user_revenue", new BigDecimal(user_revenue).toPlainString());
        modelAndView.addObject("verifier", new BigDecimal(verifier).toPlainString());
        modelAndView.addObject("rate", rate);
        modelAndView.addObject("notice_logs", notice_logs);
        
        modelAndView.addObject("miningName", miningName);
        modelAndView.addObject("tradingSum", new BigDecimal(tradingSum_temp).toPlainString());
        modelAndView.addObject("dayRateMin", dayRateMin_temp);
        modelAndView.addObject("dayRateMax", dayRateMax_temp);
        modelAndView.addObject("miningAmountMin", miningAmountMin_temp);
        modelAndView.addObject("miningAmountMax", miningAmountMax_temp);
        modelAndView.addObject("node_num", node_num_temp);
        modelAndView.addObject("mining_total", new BigDecimal(mining_total_temp).toPlainString());
 
        try {
            
            String error = this.verification(total_output, user_revenue, verifier, rate, 
                    dayRateMin_temp, dayRateMax_temp, miningAmountMin_temp, miningAmountMax_temp, node_num_temp,mining_total_temp,tradingSum_temp, miningName);
            if (!StringUtils.isNullOrEmpty(error)) {
                throw new BusinessException(error);
            }            
 
            double total_output_double = Double.valueOf(request.getParameter("total_output"));
            double user_revenue_double = Double.valueOf(request.getParameter("user_revenue"));
            double verifier_double = Double.valueOf(request.getParameter("verifier"));
            double rate_double = Double.valueOf(request.getParameter("rate"));
            
            double tradingSum = Double.valueOf(tradingSum_temp);
            //检测总交易量是否超过100亿
            if(tradingSum > 10000000000.00001) {
                throw new BusinessException("总交易量超过100亿");
            }
            
            double dayRateMin = Double.valueOf(dayRateMin_temp);
            double dayRateMax = Double.valueOf(dayRateMax_temp);
            double miningAmountMin = Double.valueOf(miningAmountMin_temp);
            double miningAmountMax = Double.valueOf(miningAmountMax_temp);
            double node_num = Double.valueOf(node_num_temp);
            double mining_total = Double.valueOf(mining_total_temp);
            
            AutoMonitorPoolData entity = autoMonitorPoolDataService.findDefault();
 
            String log = MessageFormat.format(
                    "管理员修改矿池产出数据配置,原total_output:{0},原user_revenue:{1}," + "原verifier:{2},原rate:{3},原notice_logs{4}",
                    entity.getTotal_output(), entity.getUser_revenue(), entity.getVerifier(), entity.getRate(),
                    entity.getNotice_logs());
 
            entity.setTotal_output(total_output_double);
            entity.setUser_revenue(user_revenue_double);
            entity.setVerifier(verifier_double);
            entity.setRate(rate_double);
            entity.setNotice_logs(notice_logs);
            entity.setMiningName(miningName);
            entity.setTradingSum(tradingSum);
            entity.setDayRateMin(dayRateMin);
            entity.setDayRateMax(dayRateMax);
            entity.setMiningAmountMin(miningAmountMin);
            entity.setMiningAmountMax(miningAmountMax);
            entity.setNode_num(node_num);
            entity.setMining_total(mining_total);
 
            log += MessageFormat.format(
                    ",新total_output:{0},新user_revenue:{1}," + "新verifier:{2},新rate:{3},新notice_logs{4}",
                    entity.getTotal_output(), entity.getUser_revenue(), entity.getVerifier(), entity.getRate(),
                    entity.getNotice_logs());
            
            this.adminAutoMonitorPoolDataService.update(entity, this.getUsername_login(), this.getIp(), log);
                        
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            modelAndView.setViewName("auto_monitor_pool_data_update");
            return modelAndView;
        } catch (Throwable t) {
            logger.error("update error ", t);
            modelAndView.addObject("error", "程序错误");
            modelAndView.setViewName("auto_monitor_pool_data_update");
            return modelAndView;
        }
        
        modelAndView.addObject("message", "操作成功");
        modelAndView.setViewName("redirect:/" + action + "toUpdate.action");
        return modelAndView;
    }
 
    protected String verification(String total_output, String user_revenue, String verifier, String rate,
            String dayRateMin_temp, String dayRateMax_temp, String miningAmountMin_temp, 
            String miningAmountMax_temp,String node_num_temp, String mining_total_temp, String tradingSum_temp, String miningName) {
 
        if (StringUtils.isNullOrEmpty(total_output)) {
            return "总产量必填";
        }
        if (!StringUtils.isDouble(total_output)) {
            return "总产量输入错误,请输入浮点数";
        }
        if (Double.valueOf(total_output).doubleValue() < 0) {
            return "总产量不能小于0";
        }
 
        if (StringUtils.isNullOrEmpty(verifier)) {
            return "参与者必填";
        }
        if (!StringUtils.isDouble(verifier)) {
            return "参与者输入错误,请输入浮点数";
        }
        if (Double.valueOf(verifier).doubleValue() < 0) {
            return "参与者不能小于0";
        }
 
        if (StringUtils.isNullOrEmpty(user_revenue)) {
            return "用户收益必填";
        }
        if (!StringUtils.isDouble(user_revenue)) {
            return "用户收益输入错误,请输入浮点数";
        }
        if (Double.valueOf(user_revenue).doubleValue() < 0) {
            return "用户收益不能小于0";
        }
 
        if (StringUtils.isNullOrEmpty(rate)) {
            return "参与者增加倍率必填";
        }
        if (!StringUtils.isDouble(rate)) {
            return "参与者增加倍率输入错误,请输入浮点数";
        }
        if (Double.valueOf(rate).doubleValue() < 0) {
            return "参与者增加倍率不能小于0";
        }
        if (Double.valueOf(node_num_temp).doubleValue() < 0) {
            return "节点数量不能小于0";
        }
        if (StringUtils.isNullOrEmpty(miningName)) {
            return "挖矿项目名称必填";
        }
        if (!StringUtils.isDouble(mining_total_temp) || Double.valueOf(mining_total_temp).doubleValue() < 0) {
            return "请输入正确的总流动性挖矿合约资金";
        }
        if (!StringUtils.isDouble(tradingSum_temp) || Double.valueOf(tradingSum_temp).doubleValue() < 0) {
            return "请输入正确的总交易量";
        }
        if (!StringUtils.isDouble(dayRateMin_temp) || Double.valueOf(dayRateMin_temp).doubleValue() < 0) {
            return "请输入正确的日收益率下限";
        }
        if (!StringUtils.isDouble(dayRateMax_temp) || Double.valueOf(dayRateMax_temp).doubleValue() < 0) {
            return "请输入正确的日收益率上限";
        }
        if (!StringUtils.isDouble(miningAmountMin_temp) || Double.valueOf(miningAmountMin_temp).doubleValue() < 0) {
            return "请输入正确的挖矿金额下限";
        }
        if (!StringUtils.isDouble(miningAmountMax_temp) || Double.valueOf(miningAmountMax_temp).doubleValue() < 0) {
            return "请输入正确的挖矿金额上限";
        }
        
        return null;
    }
}