EcEntrustInfoBiz.java
3.3 KB
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
package com.cjs.site.biz.ec;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import com.cjs.site.model.entrust.EcEntrustInfo;
import com.cjs.site.model.user.UserAttentionInfo;
import com.cjs.site.util.lang.JsonUtil;
/**
* 买卖委托信息
*
* @author tongyufu
*
*/
@Service
public class EcEntrustInfoBiz {
public String processData(String data, String flag) {
Map<String, Object> result = new HashMap<String, Object>();
result.put("flag", flag);
result.put("data", JsonUtil.fromJson(data, Object.class));
return JsonUtil.toJson(result);
}
public void sendToInnovate(WebSocketSession session, List<EcEntrustInfo> entrusts, String[] innovates)
throws IOException
{
if ((entrusts == null) || (innovates == null) || (entrusts.isEmpty()) || (innovates.length <= 0)) {
return;
}
List userEntrusts = new ArrayList();
for (EcEntrustInfo entrust : entrusts) {
for (String obj : innovates) {
if (StringUtils.equals(entrust.getOtcCode(), obj)) {
userEntrusts.add(entrust);
break;
}
}
}
if (!userEntrusts.isEmpty())
session.sendMessage(new TextMessage(JsonUtil.toJson(userEntrusts)));
}
/**
* 发送到用户自选行情
*
* @param session
* @param entrusts
* @param attentions
* @throws IOException
*/
public void sendToClient(WebSocketSession session, List<EcEntrustInfo> entrusts,
List<UserAttentionInfo> attentions) throws IOException {
if (entrusts == null || attentions == null || entrusts.isEmpty() || attentions.isEmpty()) {
return;
}
List<EcEntrustInfo> userEntrusts = new ArrayList<EcEntrustInfo>();
for (EcEntrustInfo entrust : entrusts) {
for (UserAttentionInfo attention : attentions) {
if (StringUtils.equals(entrust.getOtcCode(), attention.getOtcCode())) {
userEntrusts.add(entrust);
break;
}
}
}
if (!userEntrusts.isEmpty()) {
session.sendMessage(new TextMessage(JsonUtil.toJson(userEntrusts)));
}
}
/**
* 发送到用户自选行情
*
* @param sessions
* @param entrusts 行情
* @throws IOException
*/
public void sendToClient(final Map<WebSocketSession, List<UserAttentionInfo>> sessions,
final List<EcEntrustInfo> entrusts) throws IOException {
final EcEntrustInfoBiz biz = this;
new Thread(new Runnable() {
@Override
public void run() {
for (WebSocketSession session : sessions.keySet()) {
try {
biz.sendToClient(session, entrusts, sessions.get(session));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}).start();
}
}