From 233663729433f6c52424d6bab2e9a5ff91fcc943 Mon Sep 17 00:00:00 2001 From: wangwei <1610949092@qq.com> Date: Fri, 21 Jun 2024 10:57:34 +0800 Subject: [PATCH] =?UTF-8?q?6/21=20=E5=90=8C=E6=AD=A5=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9E=9A=E4=B8=BE=E4=BB=A5=E5=8F=8A=E6=B1=87?= =?UTF-8?q?=E6=80=BB=E6=97=A5=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/constant/BasicExportTypeEnum.java | 10 ++++++++++ .../sale/admin/constant/SocketMsgType.java | 2 ++ .../admin/socket/client/SocketMsgService.java | 9 +++++++++ .../socket/client/SpsWebSocketClient.java | 10 ++++++++-- .../socket/client/WebSocketComponent.java | 14 ++++++++++++- .../admin/socket/server/SpsSyncWebSocket.java | 20 ++++++++++++++++++- .../sale/admin/thread/HeartTaskService.java | 6 ++++++ 7 files changed, 67 insertions(+), 4 deletions(-) diff --git a/api-admin/src/main/java/com/glxp/sale/admin/constant/BasicExportTypeEnum.java b/api-admin/src/main/java/com/glxp/sale/admin/constant/BasicExportTypeEnum.java index cb58717..3322e62 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/constant/BasicExportTypeEnum.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/constant/BasicExportTypeEnum.java @@ -52,6 +52,16 @@ public enum BasicExportTypeEnum { */ IO_ORDER("io_order", "单据信息"), + /** + * + * 企业信息 + */ + + PRODUCE_BUSINESS_DATA("thr_manufacturer", "生产企业数据"), + DEVICE_INFO_DATA("device_info", "设备信息数据"), + DEVICE_CHECK_DATA("device_check", "巡检管理数据"), + DEVICE_REPAIR_DATA("device_repair_apply", "报修管理数据"), + DEVICE_UPKEEP_DATA("device__upkeep", "设备保养数据"), ; private String key; diff --git a/api-admin/src/main/java/com/glxp/sale/admin/constant/SocketMsgType.java b/api-admin/src/main/java/com/glxp/sale/admin/constant/SocketMsgType.java index 3a80463..8a18145 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/constant/SocketMsgType.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/constant/SocketMsgType.java @@ -10,4 +10,6 @@ public interface SocketMsgType { String BASIC_CORP_MAINTAIN_DELETE = "BASIC_CORP_MAINTAIN_DELETE"; //供应商字典 String BASIC_BUSINESS_TYPE_DELETE = "BASIC_BUSINESS_TYPE_DELETE"; //单据类型 + String STAT_DATA_REQUEST = "STAT_DATA_REQUEST"; //汇总日报 + String STAT_DATA = "STAT_DATA"; // } diff --git a/api-admin/src/main/java/com/glxp/sale/admin/socket/client/SocketMsgService.java b/api-admin/src/main/java/com/glxp/sale/admin/socket/client/SocketMsgService.java index 3956fae..4011b38 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/socket/client/SocketMsgService.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/socket/client/SocketMsgService.java @@ -1,6 +1,7 @@ package com.glxp.sale.admin.socket.client; import com.glxp.sale.admin.socket.server.SpsSyncWebSocket; +import org.jfree.util.Log; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -22,4 +23,12 @@ public class SocketMsgService { public void sendDeleteMsg(String message) { spsSyncWebSocket.sendMessage(message, "2:" + token); } + + + + + public void sendGetMsg(String message) { + Log.error("发送管理系统的信息{}"+message); + spsSyncWebSocket.sendMessage(message, "2:" + token); + } } diff --git a/api-admin/src/main/java/com/glxp/sale/admin/socket/client/SpsWebSocketClient.java b/api-admin/src/main/java/com/glxp/sale/admin/socket/client/SpsWebSocketClient.java index d720af4..a360abe 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/socket/client/SpsWebSocketClient.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/socket/client/SpsWebSocketClient.java @@ -1,13 +1,13 @@ package com.glxp.sale.admin.socket.client; -import com.alibaba.fastjson.JSONObject; -import com.glxp.sale.admin.constant.SocketMsgType; +import com.glxp.sale.admin.constant.SocketMsgType;; import org.java_websocket.WebSocket; import org.java_websocket.client.WebSocketClient; import org.java_websocket.framing.Framedata; import org.java_websocket.handshake.ServerHandshake; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.net.URI; @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.List; + public class SpsWebSocketClient extends WebSocketClient { private String excptMessage; @@ -26,6 +27,8 @@ public class SpsWebSocketClient extends WebSocketClient { @Resource SocketMsgService socketMsgService; + + public void setSocketMsgService(SocketMsgService socketMsgService) { this.socketMsgService = socketMsgService; } @@ -62,6 +65,9 @@ public class SpsWebSocketClient extends WebSocketClient { socketMsgService.sendDeleteMsg(s); } else if (s.contains(SocketMsgType.BASIC_BUSINESS_TYPE_DELETE)) { socketMsgService.sendDeleteMsg(s); + }else if (s.contains(SocketMsgType.STAT_DATA)) { + socketMsgService.sendGetMsg(s); + } else { //通知类消息则需转发 socketMsgService.sendNoticeMsg(s); diff --git a/api-admin/src/main/java/com/glxp/sale/admin/socket/client/WebSocketComponent.java b/api-admin/src/main/java/com/glxp/sale/admin/socket/client/WebSocketComponent.java index 53fc5cb..3d85409 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/socket/client/WebSocketComponent.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/socket/client/WebSocketComponent.java @@ -26,7 +26,7 @@ public class WebSocketComponent implements CommandLineRunner { HeartTaskService heartTaskService; @Resource SocketMsgService socketMsgService; - + private SpsWebSocketClient client; @Override public void run(String... args) throws Exception { @@ -66,6 +66,18 @@ public class WebSocketComponent implements CommandLineRunner { } + // 添加一个成员变量来保存 SpsWebSocketClient 实例 + + // 提供公共方法来访问 SpsWebSocketClient 实例 + public SpsWebSocketClient getClient() { + if (client == null) { + log.error("WebSocket client is not initialized"); + throw new IllegalStateException("WebSocket client is not initialized"); + } + return client; + } + + public void initConnect(SpsWebSocketClient client) { if (client == null && client.isOpen()) { log.info("WebSocket已连接,不需要重连"); diff --git a/api-admin/src/main/java/com/glxp/sale/admin/socket/server/SpsSyncWebSocket.java b/api-admin/src/main/java/com/glxp/sale/admin/socket/server/SpsSyncWebSocket.java index 9bb69f7..b0040aa 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/socket/server/SpsSyncWebSocket.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/socket/server/SpsSyncWebSocket.java @@ -2,15 +2,23 @@ package com.glxp.sale.admin.socket.server; import cn.hutool.json.JSONUtil; import com.glxp.sale.admin.entity.sync.SocketMsgEntity; +import com.glxp.sale.admin.service.param.SystemParamConfigService; +import com.glxp.sale.admin.socket.client.SocketMsgService; +import com.glxp.sale.admin.socket.client.SpsWebSocketClient; +import com.glxp.sale.admin.socket.client.WebSocketComponent; import com.glxp.sale.admin.util.ByteArraySplitter; +import com.glxp.sale.common.res.BaseResponse; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import javax.annotation.Resource; import javax.websocket.*; import javax.websocket.server.PathParam; import javax.websocket.server.ServerEndpoint; import java.io.IOException; +import java.net.URISyntaxException; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -33,6 +41,7 @@ public class SpsSyncWebSocket { private String key = ""; + /** * 建立连接 * @@ -58,11 +67,19 @@ public class SpsSyncWebSocket { log.info("online number:{}", getOnlineCount()); } + + @Autowired + WebSocketComponent webSocketComponent; @OnMessage public void onMessage(String message, Session session) { + //收到管理系统响应的信息 log.info("来自客户端的消息->>message:{};sessionId:{}", message, session.getId()); + //TODO 已经接受到消息 准备转发给spms 自助平台 + + } + @OnClose public void onClose() { log.info("onClose : {}" + key); @@ -85,7 +102,8 @@ public class SpsSyncWebSocket { * @param message 数据推送 * @param sessionId token */ - public synchronized void sendMessage(String message, String sessionId) { + public synchronized void + sendMessage(String message, String sessionId) { synchronized (this.getClass()) { for (Map.Entry stringMyWebSocketEntry : socketServersMap.entrySet()) { try { diff --git a/api-admin/src/main/java/com/glxp/sale/admin/thread/HeartTaskService.java b/api-admin/src/main/java/com/glxp/sale/admin/thread/HeartTaskService.java index 68ae99f..5812485 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/thread/HeartTaskService.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/thread/HeartTaskService.java @@ -115,4 +115,10 @@ public class HeartTaskService { logger.info("定时从上游下载全部据-----结束"); } + + + public void getData(String message){ + logger.error("jiehsou 要发送的数据"); + spsSyncWebSocket.sendMessage(SocketMsgEntity.builder().content(message).type(SocketMsgType.STAT_DATA).remark("我瞎说的数据").build(), "2:" + socketToken); + } }