|
@@ -4,7 +4,8 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import thyyxxk.webserver.config.exception.ExceptionEnum;
|
|
|
-import thyyxxk.webserver.entity.inpatient.patient.Patient;
|
|
|
+import thyyxxk.webserver.service.zhuyuanyisheng.EmrWebSocketServer;
|
|
|
+import thyyxxk.webserver.utils.ListUtil;
|
|
|
import thyyxxk.webserver.utils.TokenUtil;
|
|
|
|
|
|
import javax.websocket.*;
|
|
@@ -26,22 +27,21 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
|
public class WebSocketServer {
|
|
|
private static final AtomicInteger ONLINE_COUNT = new AtomicInteger();
|
|
|
private static final ConcurrentHashMap<String, Session> SESSION_MAP = new ConcurrentHashMap<>();
|
|
|
- private static final ConcurrentHashMap<String, Session> EMR_MAP = new ConcurrentHashMap<>();
|
|
|
- private static final AtomicInteger EMR_COUNT = new AtomicInteger();
|
|
|
+ private static final ConcurrentHashMap<String, List<Session>> EMR_MAP = new ConcurrentHashMap<>();
|
|
|
|
|
|
@OnOpen
|
|
|
public void onOpen(Session session, @PathParam("sid") String sid) {
|
|
|
+
|
|
|
if ("update".equals(sid)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (sid.endsWith("Emr")) {
|
|
|
- EMR_MAP.put(sid, session);
|
|
|
- EMR_COUNT.incrementAndGet();
|
|
|
- log.info("有新的电子病历连接加入:{},当前在线人数为:{}", sid, ONLINE_COUNT.get());
|
|
|
+ if (sid.startsWith("emr")) {
|
|
|
+ emrOnOpen(session, sid);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
if (!sid.endsWith("Screen")) {
|
|
|
SESSION_MAP.forEach((item, index) -> {
|
|
|
if (sid.split("-")[0].equals(item.split("-")[0])) {
|
|
@@ -56,10 +56,9 @@ public class WebSocketServer {
|
|
|
}
|
|
|
|
|
|
@OnClose
|
|
|
- public void onClose(@PathParam("sid") String sid) {
|
|
|
- if (sid.endsWith("Emr")) {
|
|
|
- EMR_MAP.remove(sid);
|
|
|
- EMR_COUNT.decrementAndGet();
|
|
|
+ public void onClose(Session session, @PathParam("sid") String sid) {
|
|
|
+ if (sid.startsWith("emr")) {
|
|
|
+ emrClose(session, sid);
|
|
|
return;
|
|
|
}
|
|
|
SESSION_MAP.remove(sid);
|
|
@@ -67,6 +66,16 @@ public class WebSocketServer {
|
|
|
log.info("有一连接关闭:{},当前在线人数为:{}", sid, ONLINE_COUNT.get());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public static void emrSendMessage(Session session, String msg) {
|
|
|
+ try {
|
|
|
+ session.getBasicRemote().sendText(msg);
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@OnMessage
|
|
|
public void onMessage(String message) {
|
|
|
log.info("收到信息:{}", message);
|
|
@@ -77,16 +86,6 @@ public class WebSocketServer {
|
|
|
log.error("【session id: " + session.getId() + "】Socket连接发生错误", error);
|
|
|
}
|
|
|
|
|
|
- public static List<Patient> getEditorUsersByPatNo() {
|
|
|
- List<Patient> p = new ArrayList<>();
|
|
|
-
|
|
|
- for (Map.Entry<String, Session> item : EMR_MAP.entrySet()) {
|
|
|
- log.info("数据:{}", item.getKey());
|
|
|
- }
|
|
|
-
|
|
|
- return p;
|
|
|
- }
|
|
|
-
|
|
|
public static String getSid() {
|
|
|
String token = TokenUtil.getTokenUserId();
|
|
|
for (Map.Entry<String, Session> entry : SESSION_MAP.entrySet()) {
|
|
@@ -181,4 +180,51 @@ public class WebSocketServer {
|
|
|
public static int getOnlineCount() {
|
|
|
return ONLINE_COUNT.get();
|
|
|
}
|
|
|
+
|
|
|
+ public static List<Session> getEmrMap(String sid) {
|
|
|
+ return EMR_MAP.get(sid);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void emrOnOpen(Session session, String sid) {
|
|
|
+ if (EMR_MAP.containsKey(sid)) {
|
|
|
+ List<Session> temp = EMR_MAP.get(sid);
|
|
|
+ temp.add(session);
|
|
|
+ EMR_MAP.replace(sid, temp);
|
|
|
+ } else {
|
|
|
+ List<Session> temp = new ArrayList<>();
|
|
|
+ temp.add(session);
|
|
|
+ EMR_MAP.put(sid, temp);
|
|
|
+ }
|
|
|
+ List<Session> temp = EMR_MAP.get(sid);
|
|
|
+ for (Session item : temp) {
|
|
|
+ if (!item.getQueryString().equals(session.getQueryString())) {
|
|
|
+ emrSendMessage(item, String.format("{\"connectToJoin\": \"%s\"}", EmrWebSocketServer.sessionParseUserCode(session)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ emrSendMessage(session, "{\"connect\": true}");
|
|
|
+ log.info("有新的电子病历连接加入:{}", sid);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void emrClose(Session session, String sid) {
|
|
|
+ List<Session> temp = EMR_MAP.get(sid);
|
|
|
+
|
|
|
+ temp.removeIf(item -> {
|
|
|
+ if (item.getQueryString().equals(session.getQueryString())) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ emrSendMessage(item, String.format("{\"exitEmrEditor\": \"%s\"}", EmrWebSocketServer.sessionParseUserCode(session)));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (ListUtil.isBlank(temp)) {
|
|
|
+ EMR_MAP.remove(sid);
|
|
|
+ EmrWebSocketServer.clearChatHistoryBySid(sid);
|
|
|
+ } else {
|
|
|
+ EMR_MAP.replace(sid, temp);
|
|
|
+ }
|
|
|
+ log.info("电子病历关闭:{} ", sid);
|
|
|
+ }
|
|
|
+
|
|
|
}
|