6/21 同步优化增加枚举以及汇总日报

dev
wangwei 10 months ago
parent 20d0da6075
commit 2336637294

@ -52,6 +52,16 @@ public enum BasicExportTypeEnum {
*/ */
IO_ORDER("io_order", "单据信息"), 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; private String key;

@ -10,4 +10,6 @@ public interface SocketMsgType {
String BASIC_CORP_MAINTAIN_DELETE = "BASIC_CORP_MAINTAIN_DELETE"; //供应商字典 String BASIC_CORP_MAINTAIN_DELETE = "BASIC_CORP_MAINTAIN_DELETE"; //供应商字典
String BASIC_BUSINESS_TYPE_DELETE = "BASIC_BUSINESS_TYPE_DELETE"; //单据类型 String BASIC_BUSINESS_TYPE_DELETE = "BASIC_BUSINESS_TYPE_DELETE"; //单据类型
String STAT_DATA_REQUEST = "STAT_DATA_REQUEST"; //汇总日报
String STAT_DATA = "STAT_DATA"; //
} }

@ -1,6 +1,7 @@
package com.glxp.sale.admin.socket.client; package com.glxp.sale.admin.socket.client;
import com.glxp.sale.admin.socket.server.SpsSyncWebSocket; import com.glxp.sale.admin.socket.server.SpsSyncWebSocket;
import org.jfree.util.Log;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -22,4 +23,12 @@ public class SocketMsgService {
public void sendDeleteMsg(String message) { public void sendDeleteMsg(String message) {
spsSyncWebSocket.sendMessage(message, "2:" + token); spsSyncWebSocket.sendMessage(message, "2:" + token);
} }
public void sendGetMsg(String message) {
Log.error("发送管理系统的信息{}"+message);
spsSyncWebSocket.sendMessage(message, "2:" + token);
}
} }

@ -1,13 +1,13 @@
package com.glxp.sale.admin.socket.client; 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.WebSocket;
import org.java_websocket.client.WebSocketClient; import org.java_websocket.client.WebSocketClient;
import org.java_websocket.framing.Framedata; import org.java_websocket.framing.Framedata;
import org.java_websocket.handshake.ServerHandshake; import org.java_websocket.handshake.ServerHandshake;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.net.URI; import java.net.URI;
@ -16,6 +16,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class SpsWebSocketClient extends WebSocketClient { public class SpsWebSocketClient extends WebSocketClient {
private String excptMessage; private String excptMessage;
@ -26,6 +27,8 @@ public class SpsWebSocketClient extends WebSocketClient {
@Resource @Resource
SocketMsgService socketMsgService; SocketMsgService socketMsgService;
public void setSocketMsgService(SocketMsgService socketMsgService) { public void setSocketMsgService(SocketMsgService socketMsgService) {
this.socketMsgService = socketMsgService; this.socketMsgService = socketMsgService;
} }
@ -62,6 +65,9 @@ public class SpsWebSocketClient extends WebSocketClient {
socketMsgService.sendDeleteMsg(s); socketMsgService.sendDeleteMsg(s);
} else if (s.contains(SocketMsgType.BASIC_BUSINESS_TYPE_DELETE)) { } else if (s.contains(SocketMsgType.BASIC_BUSINESS_TYPE_DELETE)) {
socketMsgService.sendDeleteMsg(s); socketMsgService.sendDeleteMsg(s);
}else if (s.contains(SocketMsgType.STAT_DATA)) {
socketMsgService.sendGetMsg(s);
} else { } else {
//通知类消息则需转发 //通知类消息则需转发
socketMsgService.sendNoticeMsg(s); socketMsgService.sendNoticeMsg(s);

@ -26,7 +26,7 @@ public class WebSocketComponent implements CommandLineRunner {
HeartTaskService heartTaskService; HeartTaskService heartTaskService;
@Resource @Resource
SocketMsgService socketMsgService; SocketMsgService socketMsgService;
private SpsWebSocketClient client;
@Override @Override
public void run(String... args) throws Exception { 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) { public void initConnect(SpsWebSocketClient client) {
if (client == null && client.isOpen()) { if (client == null && client.isOpen()) {
log.info("WebSocket已连接不需要重连"); log.info("WebSocket已连接不需要重连");

@ -2,15 +2,23 @@ package com.glxp.sale.admin.socket.server;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.glxp.sale.admin.entity.sync.SocketMsgEntity; 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.admin.util.ByteArraySplitter;
import com.glxp.sale.common.res.BaseResponse;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.websocket.*; import javax.websocket.*;
import javax.websocket.server.PathParam; import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint; import javax.websocket.server.ServerEndpoint;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -33,6 +41,7 @@ public class SpsSyncWebSocket {
private String key = ""; private String key = "";
/** /**
* *
* *
@ -58,11 +67,19 @@ public class SpsSyncWebSocket {
log.info("online number:{}", getOnlineCount()); log.info("online number:{}", getOnlineCount());
} }
@Autowired
WebSocketComponent webSocketComponent;
@OnMessage @OnMessage
public void onMessage(String message, Session session) { public void onMessage(String message, Session session) {
//收到管理系统响应的信息
log.info("来自客户端的消息->>message:{};sessionId:{}", message, session.getId()); log.info("来自客户端的消息->>message:{};sessionId:{}", message, session.getId());
//TODO 已经接受到消息 准备转发给spms 自助平台
} }
@OnClose @OnClose
public void onClose() { public void onClose() {
log.info("onClose : {}" + key); log.info("onClose : {}" + key);
@ -85,7 +102,8 @@ public class SpsSyncWebSocket {
* @param message * @param message
* @param sessionId token * @param sessionId token
*/ */
public synchronized void sendMessage(String message, String sessionId) { public synchronized void
sendMessage(String message, String sessionId) {
synchronized (this.getClass()) { synchronized (this.getClass()) {
for (Map.Entry<String, SpsSyncWebSocket> stringMyWebSocketEntry : socketServersMap.entrySet()) { for (Map.Entry<String, SpsSyncWebSocket> stringMyWebSocketEntry : socketServersMap.entrySet()) {
try { try {

@ -115,4 +115,10 @@ public class HeartTaskService {
logger.info("定时从上游下载全部据-----结束"); logger.info("定时从上游下载全部据-----结束");
} }
public void getData(String message){
logger.error("jiehsou 要发送的数据");
spsSyncWebSocket.sendMessage(SocketMsgEntity.builder().content(message).type(SocketMsgType.STAT_DATA).remark("我瞎说的数据").build(), "2:" + socketToken);
}
} }

Loading…
Cancel
Save