1
zj
2024-06-13 8eea5be3b36875bd4ffe70e6c3a5bb07b1d829bf
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
package com.yami.trading.api.controller.trader;
 
import com.yami.trading.bean.model.User;
import com.yami.trading.bean.trader.domain.Trader;
import com.yami.trading.bean.trader.domain.TraderFollowUser;
import com.yami.trading.common.exception.BusinessException;
import com.yami.trading.common.web.ResultObject;
import com.yami.trading.security.common.util.SecurityUtils;
import com.yami.trading.service.trader.TraderFollowUserService;
import com.yami.trading.service.trader.TraderService;
import com.yami.trading.service.user.UserService;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
 
/**
 * 用户准备跟随交易员api接口
 */
@RestController
@CrossOrigin
@RequestMapping()
public class ApiTraderFollowUserController {
    private static final long serialVersionUID = 623416500874018208L;
    /**
     * 交易员api接口
     */
    private static Log logger = LogFactory.getLog(ApiTraderFollowUserController.class);
    
    @Autowired
    private TraderFollowUserService traderFollowUserService;
    
    @Autowired
    private TraderService traderService;
 
    @Autowired
    private UserService userService;
 
//    private String trader_id;
//
//    private String trader_name;
//
//    /**
//     * 跟随购买品种 symbol
//     */
//    private String symbol;
//    /**
//     * 跟单固定张数/固定比例---选择 1,固定张数�?2,固定比�?
//     */
//    private String follow_type;
//
//    /**
//     * 跟单张数或比�?---具体�?
//     */
//    private double volume;
//    /**
//     * �?大持仓张�?
//     */
//    private double volume_max;
//    /**
//     * 止盈百分�?
//     */
//    private double stop_profit;
//    /**
//     * 止损百分�?
//     */
//    private double stop_loss;
    
    private final String action = "/api/traderFollowUser!";
 
    /**
     * 用户跟随交易员
     */
    @RequestMapping(action + "save.action")
    public Object saveCreate(HttpServletRequest request) {
        ResultObject resultObject = new ResultObject();
        String follow_type = request.getParameter("follow_type");
        String stop_loss = request.getParameter("stop_loss");
        String stop_profit = request.getParameter("stop_profit");
        String symbol = request.getParameter("symbol");
        String volume = request.getParameter("volume");
        String volume_max = request.getParameter("volume_max");
        String trader_id = request.getParameter("trader_id");
 
        String partyId = SecurityUtils.getCurrentUserId();
        try {
 
//            Object object = this.sessionTokenService.cacheGet(session_token);
//            this.sessionTokenService.del(session_token);
//            if ((object == null) || (!this.getLoginPartyId().equals((String) object))) {
//                resultObject.setCode("1");
//                resultObject.setMsg("请稍后再试");
//                return resultObject;
//            }
 
            User user = userService.getById(partyId);
 
//            if (!party.getKyc_authority()) {
//                resultObject.setCode("401");
//                resultObject.setMsg(error);
//                this.result = JsonUtils.getJsonString(resultObject);
//                out.println(this.result);
//                return null;
//            }
            TraderFollowUser entity = new TraderFollowUser();
            entity.setPartyId(partyId);
            entity.setUsername(user.getUserName());
            /**
             * 跟单固定张数/固定比例---选择 1,固定张数量,固定比例
             */
            entity.setFollowType(follow_type);
            entity.setStopLoss(Double.parseDouble(stop_loss));
            entity.setStopProfit(Double.parseDouble(stop_profit));
            entity.setSymbol(symbol);
            entity.setVolume(Double.parseDouble(volume));
            entity.setVolumeMax(Double.parseDouble(volume_max));
            /**
             * 状态 是否还在跟随状随 1,跟随,取消跟随
             */
            entity.setState("1");
 
            this.traderFollowUserService.save(entity, trader_id);
            resultObject.setCode("0");
        } catch (BusinessException e) {
            resultObject.setCode(e.getSign() + "");
            resultObject.setMsg(e.getMessage());
        } catch (Exception e) {
            resultObject.setCode("1");
            resultObject.setMsg("程序错误");
            logger.error("error:", e.fillInStackTrace());
        } finally {
 
        }
 
        return resultObject;
    }
 
    @RequestMapping(action + "choose.action")
    public Object chooseDays(HttpServletRequest request) {
        ResultObject resultObject = new ResultObject();
        String daysSetting = request.getParameter("daysSetting");
        String partyId = SecurityUtils.getCurrentUserId();
        User user = userService.findByUserId(partyId);
        user.setDaysSetting(daysSetting);
 
        userService.updateById(user);
 
        resultObject.setCode("0");
        resultObject.setMsg("设置成功!");
 
        return resultObject;
    }
 
    @RequestMapping(action + "changeFollow.action")
    public Object changeFollow(HttpServletRequest request) {
        ResultObject resultObject = new ResultObject();
        String follow_type = request.getParameter("follow_type");
        String stop_loss = request.getParameter("stop_loss");
        String stop_profit = request.getParameter("stop_profit");
        String symbol = request.getParameter("symbol");
        String volume = request.getParameter("volume");
        String volume_max = request.getParameter("volume_max");
        String trader_id = request.getParameter("trader_id");
 
        String partyId = SecurityUtils.getCurrentUserId();
        try {
 
//            Object object = this.sessionTokenService.cacheGet(session_token);
//            this.sessionTokenService.del(session_token);
//            if ((object == null) || (!this.getLoginPartyId().equals((String) object))) {
//                resultObject.setCode("1");
//                resultObject.setMsg("请稍后再试");
//                return resultObject;
//            }
 
            User user = userService.getById(partyId);
//            if (!party.getKyc_authority()) {
//                resultObject.setCode("401");
//                resultObject.setMsg(error);
//                this.result = JsonUtils.getJsonString(resultObject);
//                out.println(this.result);
//                return null;
//            }
            Trader trader = this.traderService.findById(trader_id);
            TraderFollowUser entity = this.traderFollowUserService.findByPartyIdAndTrader_partyId(partyId,
                    trader.getPartyId());
            /**
             * 跟单固定张数/固定比例---选择 1,固定张数�?2,固定比�?
             */
            entity.setFollowType(follow_type);
            entity.setStopLoss(Double.parseDouble(stop_loss));
            entity.setStopProfit(Double.parseDouble(stop_profit));
            entity.setSymbol(symbol);
            entity.setVolume(Double.parseDouble(volume));
            entity.setVolumeMax(Double.parseDouble(volume_max));
            /**
             * 状�?? 是否还在跟随状�?? 1,跟随�?2,取消跟�?
             */
            entity.setState("1");
 
            this.traderFollowUserService.update(entity);
            resultObject.setCode("0");
        } catch (BusinessException e) {
            resultObject.setCode(e.getSign() + "");
            resultObject.setMsg(e.getMessage());
        } catch (Exception e) {
            resultObject.setCode("1");
            resultObject.setMsg("程序错误");
            logger.error("error:", e.fillInStackTrace());
        } finally {
 
        }
 
        return resultObject;
    }
 
    /**
     * 取消跟随
     */
    @RequestMapping(action + "cancelFollow.action")
    public Object cancelFollow(HttpServletRequest request) {
        ResultObject resultObject = new ResultObject();
        String trader_id = request.getParameter("trader_id");
 
        String partyId = SecurityUtils.getCurrentUserId();
        try {
            Trader trader = traderService.findById(trader_id);
            TraderFollowUser traderFollowUser = this.traderFollowUserService.findByPartyIdAndTrader_partyId(partyId,
                    trader.getPartyId().toString());
            if (traderFollowUser != null) {
                this.traderFollowUserService.deleteCancel(traderFollowUser.getUuid());
            }
 
            resultObject.setCode("0");
        } catch (BusinessException e) {
            resultObject.setCode(e.getSign() + "");
            resultObject.setMsg(e.getMessage());
        } catch (Exception e) {
            resultObject.setCode("1");
            resultObject.setMsg("程序错误");
            logger.error("error:", e.fillInStackTrace());
        } finally {
 
        }
 
        return resultObject;
    }
 
}