作者 crossoverJie

:bug: Fixing a bug.登录状态判断

@@ -66,10 +66,6 @@ @@ -66,10 +66,6 @@
66 <artifactId>spring-boot-starter-actuator</artifactId> 66 <artifactId>spring-boot-starter-actuator</artifactId>
67 </dependency> 67 </dependency>
68 68
69 - <dependency>  
70 - <groupId>de.codecentric</groupId>  
71 - <artifactId>spring-boot-admin-starter-client</artifactId>  
72 - </dependency>  
73 69
74 <dependency> 70 <dependency>
75 <groupId>ch.qos.logback</groupId> 71 <groupId>ch.qos.logback</groupId>
@@ -3,6 +3,10 @@ package com.crossoverjie.cim.common.enums; @@ -3,6 +3,10 @@ package com.crossoverjie.cim.common.enums;
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.List; 4 import java.util.List;
5 5
  6 +/**
  7 + * @author crossoverJie
  8 + */
  9 +
6 public enum StatusEnum { 10 public enum StatusEnum {
7 11
8 /** 成功 */ 12 /** 成功 */
@@ -20,6 +24,9 @@ public enum StatusEnum { @@ -20,6 +24,9 @@ public enum StatusEnum {
20 /** 账号不在线 */ 24 /** 账号不在线 */
21 OFF_LINE("7000", "你选择的账号不在线,请重新选择!"), 25 OFF_LINE("7000", "你选择的账号不在线,请重新选择!"),
22 26
  27 + /** 登录信息不匹配 */
  28 + ACCOUNT_NOT_MATCH("9000", "登录信息不匹配!"),
  29 +
23 /** 请求限流 */ 30 /** 请求限流 */
24 REQUEST_LIMIT("6000", "请求限流"), 31 REQUEST_LIMIT("6000", "请求限流"),
25 ; 32 ;
@@ -74,11 +74,6 @@ @@ -74,11 +74,6 @@
74 </dependency> 74 </dependency>
75 75
76 <dependency> 76 <dependency>
77 - <groupId>de.codecentric</groupId>  
78 - <artifactId>spring-boot-admin-starter-client</artifactId>  
79 - </dependency>  
80 -  
81 - <dependency>  
82 <groupId>ch.qos.logback</groupId> 77 <groupId>ch.qos.logback</groupId>
83 <artifactId>logback-classic</artifactId> 78 <artifactId>logback-classic</artifactId>
84 </dependency> 79 </dependency>
@@ -144,8 +144,8 @@ public class RouteController { @@ -144,8 +144,8 @@ public class RouteController {
144 BaseResponse<CIMServerResVO> res = new BaseResponse(); 144 BaseResponse<CIMServerResVO> res = new BaseResponse();
145 145
146 //登录校验 146 //登录校验
147 - boolean login = accountService.login(loginReqVO);  
148 - if (login) { 147 + StatusEnum status = accountService.login(loginReqVO);
  148 + if (status == StatusEnum.SUCCESS) {
149 String server = serverCache.selectServer(); 149 String server = serverCache.selectServer();
150 String[] serverInfo = server.split(":"); 150 String[] serverInfo = server.split(":");
151 CIMServerResVO vo = new CIMServerResVO(serverInfo[0], Integer.parseInt(serverInfo[1]),Integer.parseInt(serverInfo[2])); 151 CIMServerResVO vo = new CIMServerResVO(serverInfo[0], Integer.parseInt(serverInfo[1]),Integer.parseInt(serverInfo[2]));
@@ -154,12 +154,10 @@ public class RouteController { @@ -154,12 +154,10 @@ public class RouteController {
154 accountService.saveRouteInfo(loginReqVO,server); 154 accountService.saveRouteInfo(loginReqVO,server);
155 155
156 res.setDataBody(vo); 156 res.setDataBody(vo);
157 - res.setCode(StatusEnum.SUCCESS.getCode());  
158 - res.setMessage(StatusEnum.SUCCESS.getMessage());  
159 - } else {  
160 - res.setCode(StatusEnum.REPEAT_LOGIN.getCode());  
161 - res.setMessage(StatusEnum.REPEAT_LOGIN.getMessage()); 157 +
162 } 158 }
  159 + res.setCode(status.getCode());
  160 + res.setMessage(status.getMessage());
163 161
164 return res; 162 return res;
165 } 163 }
1 package com.crossoverjie.cim.route.service; 1 package com.crossoverjie.cim.route.service;
2 2
  3 +import com.crossoverjie.cim.common.enums.StatusEnum;
3 import com.crossoverjie.cim.route.vo.req.ChatReqVO; 4 import com.crossoverjie.cim.route.vo.req.ChatReqVO;
4 import com.crossoverjie.cim.route.vo.req.LoginReqVO; 5 import com.crossoverjie.cim.route.vo.req.LoginReqVO;
5 import com.crossoverjie.cim.route.vo.res.CIMServerResVO; 6 import com.crossoverjie.cim.route.vo.res.CIMServerResVO;
@@ -30,7 +31,7 @@ public interface AccountService { @@ -30,7 +31,7 @@ public interface AccountService {
30 * @return true 成功 false 失败 31 * @return true 成功 false 失败
31 * @throws Exception 32 * @throws Exception
32 */ 33 */
33 - boolean login(LoginReqVO loginReqVO) throws Exception ; 34 + StatusEnum login(LoginReqVO loginReqVO) throws Exception ;
34 35
35 /** 36 /**
36 * 保存路由信息 37 * 保存路由信息
1 package com.crossoverjie.cim.route.service.impl; 1 package com.crossoverjie.cim.route.service.impl;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
  4 +import com.crossoverjie.cim.common.enums.StatusEnum;
4 import com.crossoverjie.cim.common.exception.CIMException; 5 import com.crossoverjie.cim.common.exception.CIMException;
5 import com.crossoverjie.cim.common.pojo.CIMUserInfo; 6 import com.crossoverjie.cim.common.pojo.CIMUserInfo;
6 import com.crossoverjie.cim.route.service.AccountService; 7 import com.crossoverjie.cim.route.service.AccountService;
@@ -69,26 +70,26 @@ public class AccountServiceRedisImpl implements AccountService { @@ -69,26 +70,26 @@ public class AccountServiceRedisImpl implements AccountService {
69 } 70 }
70 71
71 @Override 72 @Override
72 - public boolean login(LoginReqVO loginReqVO) throws Exception { 73 + public StatusEnum login(LoginReqVO loginReqVO) throws Exception {
73 //再去Redis里查询 74 //再去Redis里查询
74 String key = ACCOUNT_PREFIX + loginReqVO.getUserId(); 75 String key = ACCOUNT_PREFIX + loginReqVO.getUserId();
75 String userName = redisTemplate.opsForValue().get(key); 76 String userName = redisTemplate.opsForValue().get(key);
76 if (null == userName) { 77 if (null == userName) {
77 - return false; 78 + return StatusEnum.ACCOUNT_NOT_MATCH;
78 } 79 }
79 80
80 if (!userName.equals(loginReqVO.getUserName())) { 81 if (!userName.equals(loginReqVO.getUserName())) {
81 - return false; 82 + return StatusEnum.ACCOUNT_NOT_MATCH;
82 } 83 }
83 84
84 //登录成功,保存登录状态 85 //登录成功,保存登录状态
85 boolean status = userInfoCacheService.saveAndCheckUserLoginStatus(loginReqVO.getUserId()); 86 boolean status = userInfoCacheService.saveAndCheckUserLoginStatus(loginReqVO.getUserId());
86 if (status == false){ 87 if (status == false){
87 //重复登录 88 //重复登录
88 - return false; 89 + return StatusEnum.REPEAT_LOGIN ;
89 } 90 }
90 91
91 - return true; 92 + return StatusEnum.SUCCESS;
92 } 93 }
93 94
94 @Override 95 @Override
@@ -64,10 +64,6 @@ @@ -64,10 +64,6 @@
64 <artifactId>spring-boot-starter-actuator</artifactId> 64 <artifactId>spring-boot-starter-actuator</artifactId>
65 </dependency> 65 </dependency>
66 66
67 - <dependency>  
68 - <groupId>de.codecentric</groupId>  
69 - <artifactId>spring-boot-admin-starter-client</artifactId>  
70 - </dependency>  
71 67
72 <dependency> 68 <dependency>
73 <groupId>io.netty</groupId> 69 <groupId>io.netty</groupId>