|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; |
|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; |
|
4
|
import com.crossoverjie.cim.common.enums.StatusEnum;
|
4
|
import com.crossoverjie.cim.common.enums.StatusEnum;
|
|
5
|
import com.crossoverjie.cim.common.exception.CIMException;
|
5
|
import com.crossoverjie.cim.common.exception.CIMException;
|
|
6
|
import com.crossoverjie.cim.common.pojo.CIMUserInfo;
|
6
|
import com.crossoverjie.cim.common.pojo.CIMUserInfo;
|
|
|
|
7
|
+import com.crossoverjie.cim.common.util.RouteInfoParseUtil;
|
|
7
|
import com.crossoverjie.cim.route.service.AccountService;
|
8
|
import com.crossoverjie.cim.route.service.AccountService;
|
|
8
|
import com.crossoverjie.cim.route.service.UserInfoCacheService;
|
9
|
import com.crossoverjie.cim.route.service.UserInfoCacheService;
|
|
9
|
import com.crossoverjie.cim.route.vo.req.ChatReqVO;
|
10
|
import com.crossoverjie.cim.route.vo.req.ChatReqVO;
|
|
@@ -33,7 +34,7 @@ import static com.crossoverjie.cim.route.constant.Constant.ROUTE_PREFIX; |
|
@@ -33,7 +34,7 @@ import static com.crossoverjie.cim.route.constant.Constant.ROUTE_PREFIX; |
|
33
|
* Function:
|
34
|
* Function:
|
|
34
|
*
|
35
|
*
|
|
35
|
* @author crossoverJie
|
36
|
* @author crossoverJie
|
|
36
|
- * Date: 2018/12/23 21:58
|
37
|
+ * Date: 2018/12/23 21:58
|
|
37
|
* @since JDK 1.8
|
38
|
* @since JDK 1.8
|
|
38
|
*/
|
39
|
*/
|
|
39
|
@Service
|
40
|
@Service
|
|
@@ -44,7 +45,7 @@ public class AccountServiceRedisImpl implements AccountService { |
|
@@ -44,7 +45,7 @@ public class AccountServiceRedisImpl implements AccountService { |
|
44
|
private RedisTemplate<String, String> redisTemplate;
|
45
|
private RedisTemplate<String, String> redisTemplate;
|
|
45
|
|
46
|
|
|
46
|
@Autowired
|
47
|
@Autowired
|
|
47
|
- private UserInfoCacheService userInfoCacheService ;
|
48
|
+ private UserInfoCacheService userInfoCacheService;
|
|
48
|
|
49
|
|
|
49
|
@Autowired
|
50
|
@Autowired
|
|
50
|
private OkHttpClient okHttpClient;
|
51
|
private OkHttpClient okHttpClient;
|
|
@@ -84,9 +85,9 @@ public class AccountServiceRedisImpl implements AccountService { |
|
@@ -84,9 +85,9 @@ public class AccountServiceRedisImpl implements AccountService { |
|
84
|
|
85
|
|
|
85
|
//登录成功,保存登录状态
|
86
|
//登录成功,保存登录状态
|
|
86
|
boolean status = userInfoCacheService.saveAndCheckUserLoginStatus(loginReqVO.getUserId());
|
87
|
boolean status = userInfoCacheService.saveAndCheckUserLoginStatus(loginReqVO.getUserId());
|
|
87
|
- if (status == false){
|
88
|
+ if (status == false) {
|
|
88
|
//重复登录
|
89
|
//重复登录
|
|
89
|
- return StatusEnum.REPEAT_LOGIN ;
|
90
|
+ return StatusEnum.REPEAT_LOGIN;
|
|
90
|
}
|
91
|
}
|
|
91
|
|
92
|
|
|
92
|
return StatusEnum.SUCCESS;
|
93
|
return StatusEnum.SUCCESS;
|
|
@@ -120,7 +121,7 @@ public class AccountServiceRedisImpl implements AccountService { |
|
@@ -120,7 +121,7 @@ public class AccountServiceRedisImpl implements AccountService { |
|
120
|
try {
|
121
|
try {
|
|
121
|
scan.close();
|
122
|
scan.close();
|
|
122
|
} catch (IOException e) {
|
123
|
} catch (IOException e) {
|
|
123
|
- LOGGER.error("IOException",e);
|
124
|
+ LOGGER.error("IOException", e);
|
|
124
|
}
|
125
|
}
|
|
125
|
|
126
|
|
|
126
|
return routes;
|
127
|
return routes;
|
|
@@ -130,20 +131,18 @@ public class AccountServiceRedisImpl implements AccountService { |
|
@@ -130,20 +131,18 @@ public class AccountServiceRedisImpl implements AccountService { |
|
130
|
public CIMServerResVO loadRouteRelatedByUserId(Long userId) {
|
131
|
public CIMServerResVO loadRouteRelatedByUserId(Long userId) {
|
|
131
|
String value = redisTemplate.opsForValue().get(ROUTE_PREFIX + userId);
|
132
|
String value = redisTemplate.opsForValue().get(ROUTE_PREFIX + userId);
|
|
132
|
|
133
|
|
|
133
|
- if (value == null){
|
|
|
|
134
|
- throw new CIMException(OFF_LINE) ;
|
134
|
+ if (value == null) {
|
|
|
|
135
|
+ throw new CIMException(OFF_LINE);
|
|
135
|
}
|
136
|
}
|
|
136
|
|
137
|
|
|
137
|
- String[] server = value.split(":");
|
|
|
|
138
|
- CIMServerResVO cimServerResVO = new CIMServerResVO(server[0], Integer.parseInt(server[1]), Integer.parseInt(server[2]));
|
138
|
+ CIMServerResVO cimServerResVO = new CIMServerResVO(RouteInfoParseUtil.parse(value));
|
|
139
|
return cimServerResVO;
|
139
|
return cimServerResVO;
|
|
140
|
}
|
140
|
}
|
|
141
|
|
141
|
|
|
142
|
private void parseServerInfo(Map<Long, CIMServerResVO> routes, String key) {
|
142
|
private void parseServerInfo(Map<Long, CIMServerResVO> routes, String key) {
|
|
143
|
long userId = Long.valueOf(key.split(":")[1]);
|
143
|
long userId = Long.valueOf(key.split(":")[1]);
|
|
144
|
String value = redisTemplate.opsForValue().get(key);
|
144
|
String value = redisTemplate.opsForValue().get(key);
|
|
145
|
- String[] server = value.split(":");
|
|
|
|
146
|
- CIMServerResVO cimServerResVO = new CIMServerResVO(server[0], Integer.parseInt(server[1]), Integer.parseInt(server[2]));
|
145
|
+ CIMServerResVO cimServerResVO = new CIMServerResVO(RouteInfoParseUtil.parse(value));
|
|
147
|
routes.put(userId, cimServerResVO);
|
146
|
routes.put(userId, cimServerResVO);
|
|
148
|
}
|
147
|
}
|
|
149
|
|
148
|
|
|
@@ -167,7 +166,7 @@ public class AccountServiceRedisImpl implements AccountService { |
|
@@ -167,7 +166,7 @@ public class AccountServiceRedisImpl implements AccountService { |
|
167
|
if (!response.isSuccessful()) {
|
166
|
if (!response.isSuccessful()) {
|
|
168
|
throw new IOException("Unexpected code " + response);
|
167
|
throw new IOException("Unexpected code " + response);
|
|
169
|
}
|
168
|
}
|
|
170
|
- }finally {
|
169
|
+ } finally {
|
|
171
|
response.body().close();
|
170
|
response.body().close();
|
|
172
|
}
|
171
|
}
|
|
173
|
}
|
172
|
}
|
|
@@ -178,7 +177,7 @@ public class AccountServiceRedisImpl implements AccountService { |
|
@@ -178,7 +177,7 @@ public class AccountServiceRedisImpl implements AccountService { |
|
178
|
// TODO: 2019-01-21 改为一个原子命令,以防数据一致性
|
177
|
// TODO: 2019-01-21 改为一个原子命令,以防数据一致性
|
|
179
|
|
178
|
|
|
180
|
//删除路由
|
179
|
//删除路由
|
|
181
|
- redisTemplate.delete(ROUTE_PREFIX + userId) ;
|
180
|
+ redisTemplate.delete(ROUTE_PREFIX + userId);
|
|
182
|
|
181
|
|
|
183
|
//删除登录状态
|
182
|
//删除登录状态
|
|
184
|
userInfoCacheService.removeLoginStatus(userId);
|
183
|
userInfoCacheService.removeLoginStatus(userId);
|