Commit 2f5f9c7f authored by zengtianlai3's avatar zengtianlai3

Merge branch 'm33' into 'master'

统计sam业务开发

See merge request !13
parents dc3b192e cc8127aa
package iot.sixiang.license.event;
import iot.sixiang.license.device.DeviceProtocol;
import lombok.Data;
/**
* Created by m33 on 2022/6/9 21:38
*/
@Data
public class OperateSAMStatusEvent extends BaseEvent {
private String ip;
private DeviceProtocol protocol;
}
package iot.sixiang.license.event;
import com.alibaba.fastjson.JSON;
import iot.sixiang.license.device.DeviceProtocol;
import iot.sixiang.license.model.SamInfo;
import iot.sixiang.license.model.SamMonitor;
import iot.sixiang.license.model.msg.SamInfoMsg;
import iot.sixiang.license.operate.OperateManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* Created by m33 on 2022/6/9 21:39
*/
@Component
@Slf4j
public class OperateSAMStatusEventHandler {
@Autowired
public OperateManager operateManager;
public OperateSAMStatusEventHandler() {
}
@EventListener
public void handlerEvent(OperateSAMStatusEvent event) {
DeviceProtocol protocol = event.getProtocol();
String serverIp = event.getIp();
String jsonOperateStatus = new String(protocol.getContent(), 0, protocol.getContent().length);
SamInfoMsg samInfoMsg = JSON.parseObject(jsonOperateStatus, SamInfoMsg.class);
List<SamInfo> samInfoList = samInfoMsg.getList();
int samCount = samInfoList.size();
int onlineCount = 0;
for (SamInfo samInfo : samInfoList) {
if (samInfo.getStatus() == 0 || samInfo.getStatus() == 1 || samInfo.getStatus() == 2 || samInfo.getStatus() == 4) {
onlineCount++;
}
}
SamMonitor samMonitor = new SamMonitor();
samMonitor.setServerIp(serverIp);
samMonitor.setOnlineCount(onlineCount);
samMonitor.setSamCount(samCount);
operateManager.putSamMonitorMap(serverIp, samMonitor);
log.debug("OperateSAMStatusEventHandler");
}
}
......@@ -2,7 +2,6 @@ package iot.sixiang.license.event;
import io.netty.channel.socket.SocketChannel;
import iot.sixiang.license.device.DeviceProtocol;
import iot.sixiang.license.util.Util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
......
package iot.sixiang.license.model;
import lombok.Data;
/**
* Created by m33 on 2022/6/9 20:34
*/
@Data
public class SamInfo {
private int index;
private int samid;
private int status;
}
package iot.sixiang.license.model;
import lombok.Data;
/**
* Created by m33 on 2022/6/9 22:07
*/
@Data
public class SamMonitor {
private String serverIp;
private int samCount;
private int onlineCount;
}
package iot.sixiang.license.model.msg;
import iot.sixiang.license.model.SamInfo;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* Created by m33 on 2022/6/9 20:36
*/
@Data
public class SamInfoMsg {
List<SamInfo> list = new ArrayList<>();
}
......@@ -6,9 +6,7 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.SocketChannel;
import iot.sixiang.license.device.DeviceProtocol;
import iot.sixiang.license.event.EventPublisher;
import iot.sixiang.license.event.ForwardClientInactiveEvent;
import iot.sixiang.license.event.ForwardMessageResponseEvent;
import iot.sixiang.license.util.HexUtil;
import iot.sixiang.license.event.OperateSAMStatusEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -33,26 +31,14 @@ public class OperateClientHandler extends SimpleChannelInboundHandler<Object> {
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
// TODO Auto-generated method stub
// TODO 中转客户端收到消息后,将消息原封不动的发送给设备客户端
SocketChannel channel = (SocketChannel) ctx.channel();
InetSocketAddress socketAddr = (InetSocketAddress) ctx.channel().remoteAddress();
String serverIp = socketAddr.getHostString();
int serverPort = socketAddr.getPort();
log.debug("channelRead0...");
String remoteIp = socketAddr.getHostString();
DeviceProtocol protocol = (DeviceProtocol) msg;
log.info("桥接服务器响应1"+protocol.toString());
log.info("桥接服务器响应2:"+ HexUtil.bytes2hex(protocol.getContent()));
String channelId = channel.id().asLongText();
// ForwardMessageResponseEvent forwardMessageResponseEvent = new ForwardMessageResponseEvent();
// forwardMessageResponseEvent.setChannelId(channelId);
// forwardMessageResponseEvent.setChannel(channel);
// forwardMessageResponseEvent.setProtocol(protocol);
// eventPublisher.publishEvent(forwardMessageResponseEvent);
OperateSAMStatusEvent event = new OperateSAMStatusEvent();
event.setProtocol(protocol);
event.setIp(remoteIp);
eventPublisher.publishEvent(event);
}
......
package iot.sixiang.license.operate;
import iot.sixiang.license.entity.Server;
import iot.sixiang.license.model.SamMonitor;
import iot.sixiang.license.service.ServerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -21,9 +22,15 @@ public class OperateManager {
public OperateClient client;
private Map<String, Server> allServers = null;
private Map<String, SamMonitor> samMonitorMap = null;
public OperateManager() {
allServers = new HashMap<String, Server>();
samMonitorMap = new HashMap<>();
}
public synchronized void putSamMonitorMap(String serverIp, SamMonitor samMonitor) {
samMonitorMap.put(serverIp, samMonitor);
}
@PostConstruct
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment