upd: 编码规范
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,21 +1,3 @@
|
||||
/*
|
||||
* <<
|
||||
* Davinci
|
||||
* ==
|
||||
* Copyright (C) 2016 - 2019 EDP
|
||||
* ==
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* >>
|
||||
*
|
||||
*/
|
||||
package cn.odboy.mybatis.constant;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,7 +50,7 @@ public class EasyServiceImpl<M extends EasyMapper<T>, T> extends ServiceImpl<M,
|
||||
* @param resources /
|
||||
*/
|
||||
public <G> int quickSave(G resources) {
|
||||
return this.getBaseMapper().insert(BeanUtil.copyProperties(resources, this.getEntityClass()));
|
||||
return getBaseMapper().insert(BeanUtil.copyProperties(resources, this.getEntityClass()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ public class EasyServiceImpl<M extends EasyMapper<T>, T> extends ServiceImpl<M,
|
||||
* @param resources /
|
||||
*/
|
||||
public <G> int quickSaveBatch(List<G> resources) {
|
||||
return this.getBaseMapper().insertBatchSomeColumn(BeanUtil.copyToList(resources, this.getEntityClass()));
|
||||
return getBaseMapper().insertBatchSomeColumn(BeanUtil.copyToList(resources, this.getEntityClass()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,7 +68,7 @@ public class EasyServiceImpl<M extends EasyMapper<T>, T> extends ServiceImpl<M,
|
||||
* @param resources /
|
||||
*/
|
||||
public <G> int quickModifyById(G resources) {
|
||||
return this.getBaseMapper().updateById(BeanUtil.copyProperties(resources, this.getEntityClass()));
|
||||
return getBaseMapper().updateById(BeanUtil.copyProperties(resources, this.getEntityClass()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,18 +1,3 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.odboy.util;
|
||||
|
||||
import cn.odboy.mybatis.constant.DataTypeEnum;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Tian Jun
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.odboy.websocket;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author ZhangHouYing
|
||||
* @date 2019-08-10 9:55
|
||||
*/
|
||||
@Data
|
||||
public class WebSocketMsg {
|
||||
private String msg;
|
||||
private WebSocketMsgTypeEnum msgType;
|
||||
|
||||
public WebSocketMsg(String msg, WebSocketMsgTypeEnum msgType) {
|
||||
this.msg = msg;
|
||||
this.msgType = msgType;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.odboy.websocket;
|
||||
|
||||
/**
|
||||
* @author ZhangHouYing
|
||||
* @date 2019-08-10 9:56
|
||||
*/
|
||||
public enum WebSocketMsgTypeEnum {
|
||||
/**
|
||||
* 连接
|
||||
*/
|
||||
CONNECT,
|
||||
/**
|
||||
* 关闭
|
||||
*/
|
||||
CLOSE,
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
INFO,
|
||||
/**
|
||||
* 错误
|
||||
*/
|
||||
ERROR
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package cn.odboy.websocket;
|
||||
package cn.odboy.websocket.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package cn.odboy.websocket;
|
||||
package cn.odboy.websocket.config;
|
||||
|
||||
import io.undertow.server.DefaultByteBufferPool;
|
||||
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package cn.odboy.websocket.constant;
|
||||
|
||||
|
||||
public enum WebSocketMsgTypeEnum {
|
||||
/**
|
||||
* 连接
|
||||
*/
|
||||
CONNECT,
|
||||
/**
|
||||
* 关闭
|
||||
*/
|
||||
CLOSE,
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
INFO,
|
||||
/**
|
||||
* 错误
|
||||
*/
|
||||
ERROR
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package cn.odboy.websocket.context;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class WebSocketClientManager {
|
||||
/**
|
||||
* concurrent包的线程安全Map,用来存放每个客户端对应的MyWebSocket对象。(分布式必出问题)
|
||||
*/
|
||||
private static final Map<String, WebSocketServer> CLIENT = new ConcurrentHashMap<>();
|
||||
|
||||
public static void addClient(String sid, WebSocketServer webSocketServer) {
|
||||
// 如果存在就先删除一个,防止重复推送消息
|
||||
CLIENT.remove(sid);
|
||||
CLIENT.put(sid, webSocketServer);
|
||||
}
|
||||
|
||||
public static void removeClient(String sid) {
|
||||
CLIENT.remove(sid);
|
||||
}
|
||||
|
||||
public static Collection<WebSocketServer> getAllClient() {
|
||||
return CLIENT.values();
|
||||
}
|
||||
|
||||
public static WebSocketServer getClientBySid(String sid) {
|
||||
return CLIENT.get(sid);
|
||||
}
|
||||
}
|
||||
+16
-39
@@ -1,22 +1,9 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.odboy.websocket;
|
||||
package cn.odboy.websocket.context;
|
||||
|
||||
import cn.odboy.websocket.dto.WebSocketMsgDto;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.websocket.*;
|
||||
@@ -27,18 +14,11 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author ZhangHouYing
|
||||
* @date 2019-08-10 15:46
|
||||
*/
|
||||
@ServerEndpoint("/webSocket/{sid}")
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@ServerEndpoint("/webSocket/{sid}")
|
||||
public class WebSocketServer {
|
||||
/**
|
||||
* concurrent包的线程安全Map,用来存放每个客户端对应的MyWebSocket对象。(分布式必出问题)
|
||||
*/
|
||||
private static final Map<String, WebSocketServer> CLIENT = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* 与某个客户端的连接会话,需要通过它来给客户端发送数据
|
||||
*/
|
||||
@@ -54,10 +34,8 @@ public class WebSocketServer {
|
||||
@OnOpen
|
||||
public void onOpen(Session session, @PathParam("sid") String sid) {
|
||||
this.session = session;
|
||||
// 如果存在就先删除一个,防止重复推送消息
|
||||
CLIENT.remove(sid);
|
||||
CLIENT.put(sid, this);
|
||||
this.sid = sid;
|
||||
WebSocketClientManager.addClient(sid, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +43,7 @@ public class WebSocketServer {
|
||||
*/
|
||||
@OnClose
|
||||
public void onClose() {
|
||||
CLIENT.remove(this.sid);
|
||||
WebSocketClientManager.removeClient(this.sid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +53,7 @@ public class WebSocketServer {
|
||||
*/
|
||||
@OnMessage
|
||||
public void onMessage(String message, Session session) {
|
||||
log.info("收到来{}的信息:{}", sid, message);
|
||||
log.info("收到来 sid={} 的信息: {}", sid, message);
|
||||
sendToAll(message);
|
||||
}
|
||||
|
||||
@@ -85,40 +63,39 @@ public class WebSocketServer {
|
||||
* @param message /
|
||||
*/
|
||||
private static void sendToAll(String message) {
|
||||
//
|
||||
for (WebSocketServer item : CLIENT.values()) {
|
||||
for (WebSocketServer item : WebSocketClientManager.getAllClient()) {
|
||||
try {
|
||||
item.sendMessage(message);
|
||||
item.innerSendMessage(message);
|
||||
} catch (IOException e) {
|
||||
log.error("发送消息给{}失败", item.sid, e);
|
||||
log.error("发送消息给 sid={} 失败", item.sid, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OnError
|
||||
public void onError(Session session, Throwable error) {
|
||||
log.error("发生错误");
|
||||
log.error("WebSocket sid={} 发生错误", this.sid, error);
|
||||
error.printStackTrace();
|
||||
}
|
||||
|
||||
/**
|
||||
* 实现服务器主动推送
|
||||
*/
|
||||
private void sendMessage(String message) throws IOException {
|
||||
private void innerSendMessage(String message) throws IOException {
|
||||
this.session.getBasicRemote().sendText(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 群发自定义消息
|
||||
*/
|
||||
public static void sendInfo(WebSocketMsg webSocketMsg, @PathParam("sid") String sid) throws IOException {
|
||||
String message = JSON.toJSONString(webSocketMsg);
|
||||
public static void sendMessage(WebSocketMsgDto webSocketMsgDto, @PathParam("sid") String sid) throws IOException {
|
||||
String message = JSON.toJSONString(webSocketMsgDto);
|
||||
log.info("推送消息到{},推送内容:{}", sid, message);
|
||||
try {
|
||||
if (sid == null) {
|
||||
sendToAll(message);
|
||||
} else {
|
||||
CLIENT.get(sid).sendMessage(message);
|
||||
WebSocketClientManager.getClientBySid(sid).innerSendMessage(message);
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.odboy.websocket.dto;
|
||||
|
||||
import cn.odboy.websocket.constant.WebSocketMsgTypeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WebSocketMsgDto {
|
||||
private String msg;
|
||||
private WebSocketMsgTypeEnum msgType;
|
||||
|
||||
public WebSocketMsgDto(String msg, WebSocketMsgTypeEnum msgType) {
|
||||
this.msg = msg;
|
||||
this.msgType = msgType;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user