sakuya 3 gadi atpakaļ
vecāks
revīzija
885f38a42e

+ 6 - 0
eladmin-common/pom.xml

@@ -10,6 +10,7 @@
     <modelVersion>4.0.0</modelVersion>
     <properties>
         <hutool.version>5.3.4</hutool.version>
+        <netty-socketio.version>1.7.11</netty-socketio.version>
     </properties>
 
     <artifactId>eladmin-common</artifactId>
@@ -22,5 +23,10 @@
             <artifactId>hutool-all</artifactId>
             <version>${hutool.version}</version>
         </dependency>
+        <dependency>
+            <groupId>com.corundumstudio.socketio</groupId>
+            <artifactId>netty-socketio</artifactId>
+            <version>${netty-socketio.version}</version>
+        </dependency>
     </dependencies>
 </project>

+ 1 - 1
eladmin-common/src/main/java/me/zhengjie/config/RedisConfig.java

@@ -83,7 +83,7 @@ public class RedisConfig extends CachingConfigurerSupport {
         // 全局开启AutoType,这里方便开发,使用全局的方式
         ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
         // 建议使用这种方式,小范围指定白名单
-        // ParserConfig.getGlobalInstance().addAccept("me.zhengjie.domain");
+        ParserConfig.getGlobalInstance().addAccept("me.zhengjie.");
         // key的序列化采用StringRedisSerializer
         template.setKeySerializer(new StringRedisSerializer());
         template.setHashKeySerializer(new StringRedisSerializer());

+ 1 - 1
eladmin-common/src/main/java/me/zhengjie/exception/handler/GlobalExceptionHandler.java

@@ -66,7 +66,7 @@ public class GlobalExceptionHandler {
 	@ExceptionHandler(Exception.class)
 	public ResponseDTO<?> exceptionHandler(Exception e) {
 		log.error("error: {}", e.getMessage());
-//		e.printStackTrace();
+		e.printStackTrace();
 		// http 请求方式错误
 		if (e instanceof HttpRequestMethodNotSupportedException) {
 			return ResponseDTO.error(ResultCode.REQUEST_METHOD_ERROR);

+ 3 - 4
eladmin-system/src/main/java/me/zhengjie/base/mq/ClientCache.java

@@ -1,4 +1,4 @@
-package me.zhengjie.base.mq;
+package me.zhengjie.utils;
 
 import com.corundumstudio.socketio.SocketIOClient;
 import org.springframework.stereotype.Component;
@@ -23,7 +23,7 @@ public class ClientCache {
 	/**
 	 * 存入本地缓存
 	 *
-	 * @param userId         用户ID
+	 * @param sname         用户ID
 	 * @param sessionId      页面sessionID
 	 * @param socketIOClient 页面对应的通道连接信息
 	 */
@@ -43,7 +43,7 @@ public class ClientCache {
 	/**
 	 * 根据用户ID获取所有通道信息
 	 *
-	 * @param userId
+	 * @param sname
 	 * @return
 	 */
 	public HashMap<UUID, SocketIOClient> getUserClient(String sname) {
@@ -58,7 +58,6 @@ public class ClientCache {
 	 * 根据用户ID及页面sessionID删除页面链接信息
 	 *
 	 * @param userId
-	 * @param sessionId
 	 */
 	public void deleteSessionClient(String userId) {
 		concurrentHashMap.remove(userId);

+ 7 - 29
eladmin-common/src/main/java/me/zhengjie/utils/SecurityUtils.java

@@ -20,12 +20,11 @@ import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import lombok.extern.slf4j.Slf4j;
 import me.zhengjie.exception.BadRequestException;
-import me.zhengjie.utils.enums.DataScopeEnum;
 import org.springframework.http.HttpStatus;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.security.core.userdetails.UserDetailsService;
+
 import java.util.List;
 
 /**
@@ -41,34 +40,25 @@ public class SecurityUtils {
      * @return UserDetails
      */
     public static UserDetails getCurrentUser() {
-        UserDetailsService userDetailsService = SpringContextHolder.getBean(UserDetailsService.class);
-        return userDetailsService.loadUserByUsername(getCurrentUsername());
-    }
-
-    /**
-     * 获取系统用户名称
-     *
-     * @return 系统用户名称
-     */
-    public static String getCurrentUsername() {
         final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
         if (authentication == null) {
             throw new BadRequestException(HttpStatus.UNAUTHORIZED, "当前登录状态过期");
         }
         if (authentication.getPrincipal() instanceof UserDetails) {
             UserDetails userDetails = (UserDetails) authentication.getPrincipal();
-            return userDetails.getUsername();
+            return userDetails;
         }
         throw new BadRequestException(HttpStatus.UNAUTHORIZED, "找不到当前登录的信息");
     }
 
     /**
-     * 获取系统用户ID
-     * @return 系统用户ID
+     * 获取系统用户名称
+     *
+     * @return 系统用户名称
      */
-    public static Long getCurrentUserId() {
+    public static String getCurrentUsername() {
         UserDetails userDetails = getCurrentUser();
-        return new JSONObject(new JSONObject(userDetails).get("user")).get("id", Long.class);
+        return userDetails.getUsername();
     }
 
     /**
@@ -80,16 +70,4 @@ public class SecurityUtils {
         JSONArray array = JSONUtil.parseArray(new JSONObject(userDetails).get("dataScopes"));
         return JSONUtil.toList(array,Long.class);
     }
-
-    /**
-     * 获取数据权限级别
-     * @return 级别
-     */
-    public static String getDataScopeType() {
-        List<Long> dataScopes = getCurrentUserDataScope();
-        if(dataScopes.size() != 0){
-            return "";
-        }
-        return DataScopeEnum.ALL.getValue();
-    }
 }

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/modules/mnt/websocket/MsgType.java

@@ -13,7 +13,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package me.zhengjie.modules.mnt.websocket;
+package me.zhengjie.websocket;
 
 /**
  * @author ZhangHouYing

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/modules/mnt/websocket/SocketMsg.java

@@ -13,7 +13,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package me.zhengjie.modules.mnt.websocket;
+package me.zhengjie.websocket;
 
 import lombok.Data;
 

+ 3 - 8
eladmin-system/src/main/java/me/zhengjie/modules/mnt/websocket/WebSocketEventListenner.java

@@ -1,4 +1,4 @@
-package me.zhengjie.modules.mnt.websocket;
+package me.zhengjie.websocket;
 
 import com.corundumstudio.socketio.AckRequest;
 import com.corundumstudio.socketio.HandshakeData;
@@ -7,18 +7,13 @@ import com.corundumstudio.socketio.annotation.OnConnect;
 import com.corundumstudio.socketio.annotation.OnDisconnect;
 import com.corundumstudio.socketio.annotation.OnEvent;
 import lombok.extern.slf4j.Slf4j;
-import me.zhengjie.base.mq.ClientCache;
+import me.zhengjie.utils.ClientCache;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
-
 import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import java.util.*;
 
 /**
  * @author litong

+ 2 - 2
eladmin-system/src/main/java/me/zhengjie/modules/mnt/websocket/WebSocketServer.java

@@ -13,7 +13,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package me.zhengjie.modules.mnt.websocket;
+package me.zhengjie.websocket;
 
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
@@ -129,7 +129,7 @@ public class WebSocketServer {
 	/**
 	 * 群发自定义消息
 	 * */
-	public static void sendInfo(SocketMsg socketMsg,@PathParam("sid") String sid) throws IOException {
+	public static void sendInfo(SocketMsg socketMsg, @PathParam("sid") String sid) throws IOException {
 		String message = JSONObject.toJSONString(socketMsg);
 		log.info("推送消息到"+sid+",推送内容:"+message);
 		for (WebSocketServer item : webSocketSet) {