zj
2025-10-17 bbc4713b23778aebc1eb3d46cb04d539179d883d
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
package com.yami.trading.admin.controller.trader;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yami.trading.admin.model.TraderUserListModel;
import com.yami.trading.admin.model.trader.TraderUserModel;
import com.yami.trading.bean.model.User;
import com.yami.trading.bean.trader.domain.TraderUser;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.BusinessException;
import com.yami.trading.common.util.StringUtils;
import com.yami.trading.service.trader.AdminTraderUserService;
import com.yami.trading.service.user.UserService;
import io.swagger.annotations.Api;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.text.SimpleDateFormat;
import java.util.HashMap;
 
 
@RestController
@CrossOrigin
@RequestMapping()
@Api(tags = "交易员用户管理")
public class AdminTraderUserController {
    private static Log logger = LogFactory.getLog(AdminTraderUserController.class);
 
    @Autowired
    private AdminTraderUserService adminTraderUserService;
    
    @Autowired
    private UserService userService;
 
//    /**
//     * 查询参数
//     */
//    private String name_para;
//
//    private String username_para;
//
//    private String rolename_para;
//
//    /**
//     * 修改参数
//     */
//
//    /**
//     * 用户Uid
//     */
//    private String usercode;
//
//    private String id;
//
//    private String name;
//    
//    private String error;
//    
//    /**
//     * 累计金额
//     */
//    private double amount_sum;
//
//    /**
//     * 累计收益
//     */
//    private double profit;
//
//    /**
//     * 入驻时间----CREATE_TIME
//     */
//    private Date create_time;
 
    private final String action = "/normal/adminTraderUser!";
    
    @RequestMapping(action + "list.action")
    public Result list(TraderUserListModel model, Page page) {
 
        page = this.adminTraderUserService.pagedQuery(page, model.getName_para(), model.getUsername_para());
//        for (Map<String, Object> data : (List<Map<String, Object>>) (page.getElements())) {
//            data.put("profit_ratio", Arith.mul(Double.parseDouble(data.get("profit_ratio").toString()), 100));
//            data.put("profit_share_ratio",
//                    Arith.mul(Double.parseDouble(data.get("profit_share_ratio").toString()), 100));
//
//        }
        HashMap<String,Object> resultDict=new HashMap<String,Object>();
        resultDict.put("pageSize", page.getSize());
        resultDict.put("pageNo", page.getCurrent());
        resultDict.put("page", page);
        
        return Result.succeed(resultDict, "获取数据成功");
    }
 
//    @RequestMapping(action + "toAdd.action")
//    public String toAdd() {
//        return "add";
//    }
 
    
 
    @RequestMapping(action + "add.action")
    public Result add(@RequestBody TraderUserModel model) {
        String usercode = model.getUsercode();
        
        String name = model.getName();
        String amount_sum = model.getAmountSum();
        String profit = model.getProfit();
        String create_time = model.getCreateTime();
        
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        
        try {
 
            String error = verification(usercode, name, amount_sum, profit, create_time);
            if (!StringUtils.isNullOrEmpty(error)) throw new BusinessException(error);
 
            User party = userService.findUserByUserCode(usercode);
            if (party == null) {
                error = "UID不存在!";
                throw new BusinessException(error);
            }
 
            TraderUser trader_user = new TraderUser();
            trader_user.setPartyId(party.getUserId());
            trader_user.setName(name);
            trader_user.setAmountSum(Double.parseDouble(amount_sum));
            trader_user.setProfit(Double.parseDouble(profit));
            trader_user.setCreateTime(sdf.parse(create_time));
 
            this.adminTraderUserService.save(trader_user);
        } catch (BusinessException e) {
            return Result.failed("1", e.getMessage());
        } catch (Throwable t) {
            logger.error("AdminTraderUserAction.add error ", t);
            return Result.failed("1", t.getMessage());
        }
        return Result.succeed("添加成功!");
    }
 
//    private String verificationUpdate(String usercode, String name, String amount_sum, String profit, String create_time) {
//        if (create_time == null)
//            return "请输入入驻时间";
//        if (Double.parseDouble(amount_sum) < 0.0D)
//            return "累计金额不能小于0";
//        if (Double.parseDouble(profit) < 0.0D)
//            return "累计收益不能小于0";
//        if (StringUtils.isEmptyString(name))
//            return "请输入名称";
//
//        return null;
//    }
 
    
    @RequestMapping(action + "toUpdate.action")
    public Result toUpdate(HttpServletRequest request) {
        String id = request.getParameter("uuid");
        
        TraderUser trader_user = adminTraderUserService.findById(id);
        User user = userService.findByUserId(trader_user.getPartyId());
        trader_user.setUserCode(user.getUserCode());
 
//        this.name = trader_user.getName();
//        this.amount_sum = trader_user.getAmount_sum();
//        this.profit = trader_user.getProfit();
//        this.create_time = trader_user.getCreate_time();
//
//        return "update";
        return Result.succeed(trader_user, "获取数据成功!");
    }
 
    
    @RequestMapping(action + "update.action")
    public Result update(@RequestBody TraderUserModel model) {
        String id = model.getUuid();
        String usercode = model.getUsercode();
 
        String name = model.getName();
        String amount_sum = model.getAmountSum();
        String profit = model.getProfit();
        String create_time = model.getCreateTime();
        
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        
        TraderUser trader_user = this.adminTraderUserService.findById(id);
        try {
            String error = verification(usercode, name, amount_sum, profit, create_time);
            if (!StringUtils.isNullOrEmpty(error)) throw new BusinessException(error);
 
            trader_user.setName(name);
            trader_user.setAmountSum(Double.parseDouble(amount_sum));
            trader_user.setProfit(Double.parseDouble(profit));
            trader_user.setCreateTime(sdf.parse(create_time));
 
            this.adminTraderUserService.update(trader_user);
            return Result.succeed( "更新成功!");
        } catch (BusinessException e) {
            return Result.failed("1", e.getMessage());
        } catch (Throwable t) {
            logger.error("update error ", t);
            return Result.failed("1", t.getMessage());
        }
    }
 
    @RequestMapping(action + "delete.action")
    public Result toDelete(HttpServletRequest request) {
        String id = request.getParameter("uuid");
        try {
 
            this.adminTraderUserService.delete(id);
            return Result.succeed("删除成功!");
        } catch (BusinessException e) {
            return Result.failed("1", e.getMessage());
        } catch (Throwable t) {
            logger.error("update error ", t);
            return Result.failed("1", t.getMessage());
        }
    }
 
    private String verification(String usercode, String name, String amount_sum, String profit, String create_time) {
        if (create_time == null)
            return "请输入入驻时间";
        if (Double.parseDouble(amount_sum) < 0.0D)
            return "累计金额不能小于0";
        if (Double.parseDouble(profit) < 0.0D)
            return "累计收益不能小于0";
        if (StringUtils.isEmptyString(name))
            return "请输入名称";
 
        return null;
    }
 
}