Compare commits
23 Commits
Author | SHA1 | Date |
---|---|---|
|
e5c8c2aa44 | 4 days ago |
|
6b26bd24f5 | 4 days ago |
|
a137584591 | 6 days ago |
|
c050d6f73f | 1 week ago |
|
210186d002 | 2 weeks ago |
|
c75f0ebee8 | 2 weeks ago |
|
21c9c62cf4 | 2 months ago |
|
afd111fb68 | 2 months ago |
|
395ebd37e8 | 2 months ago |
|
1fcad6c88f | 2 months ago |
|
23ae9fabe8 | 5 months ago |
|
8084a9bde6 | 5 months ago |
|
cdf33c8990 | 6 months ago |
|
f8c948eee4 | 6 months ago |
|
e5cd13ff4f | 6 months ago |
|
a91d50021f | 6 months ago |
|
4d2ec8c834 | 8 months ago |
|
2336637294 | 10 months ago |
|
20d0da6075 | 2 years ago |
|
60887e6f46 | 2 years ago |
|
b4dbd61563 | 2 years ago |
|
e263c8febd | 2 years ago |
|
ff58a80153 | 2 years ago |
@ -0,0 +1,12 @@
|
|||||||
|
package com.glxp.sale.admin.config;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class WebSocketConfig {
|
||||||
|
@Bean
|
||||||
|
public ServerEndpointExporter serverEndpointExporter() {
|
||||||
|
return new ServerEndpointExporter();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.glxp.sale.admin.constant;
|
||||||
|
|
||||||
|
public interface SocketMsgType {
|
||||||
|
|
||||||
|
|
||||||
|
String DL_ALL_DATA = "DL_ALL_DATA";
|
||||||
|
String BASIC_DATA_DELETE = "BASIC_DATA_DELETE";
|
||||||
|
String BASIC_MANAGE_DELETE = "BASIC_MANAGE_DELETE";
|
||||||
|
|
||||||
|
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"; //
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
package com.glxp.sale.admin.entity.sync;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName(value = "code_rel")
|
||||||
|
public class CodeRel {
|
||||||
|
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
public Integer id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 器械最小销售产品标识
|
||||||
|
*/
|
||||||
|
@TableField(value = "diNameCode")
|
||||||
|
public String diNameCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阿里药品标识码
|
||||||
|
*/
|
||||||
|
@TableField(value = "drugCode")
|
||||||
|
public String drugCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 医保编码
|
||||||
|
*/
|
||||||
|
@TableField(value = "ybbm")
|
||||||
|
public String ybbm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阳光采购平台编码
|
||||||
|
*/
|
||||||
|
@TableField(value = "ycCode")
|
||||||
|
public String ycCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品条码
|
||||||
|
*/
|
||||||
|
@TableField(value = "sptm")
|
||||||
|
public String sptm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 药品本位码
|
||||||
|
*/
|
||||||
|
@TableField(value = "ypbwm")
|
||||||
|
public String ypbwm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一社会信用号
|
||||||
|
*/
|
||||||
|
@TableField(value = "tyshxyh")
|
||||||
|
public String tyshxyh;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 国家编码9码
|
||||||
|
*/
|
||||||
|
@TableField(value = "gjbm")
|
||||||
|
public String gjbm;
|
||||||
|
|
||||||
|
@TableField(value = "status")
|
||||||
|
public String status;
|
||||||
|
|
||||||
|
@TableField(value = "updateTime")
|
||||||
|
public Date updateTime;
|
||||||
|
|
||||||
|
@TableField(value = "createTime")
|
||||||
|
public Date createTime;
|
||||||
|
|
||||||
|
@TableField(value = "fromType")
|
||||||
|
public Integer fromType;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.glxp.sale.admin.entity.sync;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* websocket 消息体
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class SocketMsgEntity {
|
||||||
|
private String type;
|
||||||
|
private Object content;
|
||||||
|
private String remark;
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SocketMsgService {
|
||||||
|
|
||||||
|
@Value("${SPMS_WEBSOCKET_TOKEN}")
|
||||||
|
String token;
|
||||||
|
@Resource
|
||||||
|
SpsSyncWebSocket spsSyncWebSocket;
|
||||||
|
|
||||||
|
public void sendNoticeMsg(String message) {
|
||||||
|
spsSyncWebSocket.sendMessage(message, "2:" + token);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void sendDeleteMsg(String message) {
|
||||||
|
spsSyncWebSocket.sendMessage(message, "2:" + token);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void sendGetMsg(String message) {
|
||||||
|
Log.error("发送管理系统的信息{}"+message);
|
||||||
|
spsSyncWebSocket.sendMessage(message, "2:" + token);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,127 @@
|
|||||||
|
package com.glxp.sale.admin.socket.client;
|
||||||
|
|
||||||
|
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;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class SpsWebSocketClient extends WebSocketClient {
|
||||||
|
|
||||||
|
private String excptMessage;
|
||||||
|
|
||||||
|
Logger log = LoggerFactory.getLogger(SpsWebSocketClient.class);
|
||||||
|
|
||||||
|
private static List<SpsWebSocketClient> list = new ArrayList<>();
|
||||||
|
@Resource
|
||||||
|
SocketMsgService socketMsgService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setSocketMsgService(SocketMsgService socketMsgService) {
|
||||||
|
this.socketMsgService = socketMsgService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpsWebSocketClient(String serverUri) throws URISyntaxException {
|
||||||
|
super(new URI(serverUri));
|
||||||
|
this.setConnectionLostTimeout(0);
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (SpsWebSocketClient client : list) {
|
||||||
|
client.close();
|
||||||
|
}
|
||||||
|
list.clear();
|
||||||
|
list.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOpen(ServerHandshake serverHandshake) {
|
||||||
|
log.info("在线日志socket连接成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void onMessage(String s) {
|
||||||
|
log.info("收到消息:" + s);
|
||||||
|
//收到更新下载数据则赋值由外部处理,多个任务只处理一次避免重复处理
|
||||||
|
if (s.contains(SocketMsgType.DL_ALL_DATA)) {
|
||||||
|
this.excptMessage = s;
|
||||||
|
} else if (s.contains(SocketMsgType.BASIC_DATA_DELETE)) {
|
||||||
|
socketMsgService.sendDeleteMsg(s);
|
||||||
|
} else if (s.contains(SocketMsgType.BASIC_MANAGE_DELETE)) {
|
||||||
|
socketMsgService.sendDeleteMsg(s);
|
||||||
|
} else if (s.contains(SocketMsgType.BASIC_CORP_MAINTAIN_DELETE)) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClose(int i, String s, boolean b) {
|
||||||
|
log.info("在线日志socket断开");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWebsocketPing(WebSocket conn, Framedata f) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000 * 5);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
send("---pong---");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static void destroy() {
|
||||||
|
if (list.isEmpty())
|
||||||
|
return;
|
||||||
|
for (SpsWebSocketClient client : list) {
|
||||||
|
client.close();
|
||||||
|
}
|
||||||
|
list.clear();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//发送消息
|
||||||
|
public void sendMessage(String message) {
|
||||||
|
this.send(message);
|
||||||
|
System.out.println("已发送消息:" + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取接收到的信息
|
||||||
|
public String getExcptMessage() {
|
||||||
|
if (excptMessage != null) {
|
||||||
|
String message = new String(excptMessage);
|
||||||
|
excptMessage = null;
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.glxp.sale.admin.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import com.beust.jcommander.internal.Lists;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ByteArraySplitter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对String分片转换为List<byte[]>
|
||||||
|
*
|
||||||
|
* @param source 字符串
|
||||||
|
* @param size 分片的长度 单位字节
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<byte[]> split(String source, int size) {
|
||||||
|
// 存放最终结果
|
||||||
|
List<byte[]> result = Lists.newArrayList();
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(source)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] sourceBytes = source.getBytes();
|
||||||
|
if (size > sourceBytes.length) {
|
||||||
|
result.add(sourceBytes);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
// 开始进行split
|
||||||
|
int startIndex = 0;
|
||||||
|
int endIndex = sourceBytes.length - 1;
|
||||||
|
boolean isRunning = true;
|
||||||
|
while (isRunning) {
|
||||||
|
if ((endIndex + 1) - startIndex > size) {
|
||||||
|
result.add(ArrayUtil.sub(sourceBytes, startIndex, startIndex + size));
|
||||||
|
startIndex += size;
|
||||||
|
} else {
|
||||||
|
result.add(ArrayUtil.sub(sourceBytes, startIndex, endIndex + 1));
|
||||||
|
isRunning = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue