mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[优化]文件上传
This commit is contained in:
@@ -199,7 +199,7 @@ func GetEventFromTopic(reg, topic string) (identifier string) {
|
||||
}
|
||||
|
||||
// eventType 事件类型 info alarm
|
||||
func CreateEvent(msgType, eventType, content string, deviceAuth *model.DeviceAuth) *DeviceEventInfo {
|
||||
func CreateEventInfo(msgType, eventType, content string, deviceAuth *model.DeviceAuth) *DeviceEventInfo {
|
||||
ts := time.Now().Format("2006-01-02 15:04:05.000")
|
||||
ci := &tdengine.Events{
|
||||
DeviceId: deviceAuth.DeviceId,
|
||||
|
||||
@@ -88,7 +88,7 @@ func (s *HookGrpcService) OnClientConnected(ctx context.Context, in *exhook2.Cli
|
||||
}
|
||||
//添加连接ID
|
||||
mqttclient.Session.Store(etoken.DeviceId, in.Clientinfo.Clientid)
|
||||
data := netbase.CreateEvent(message.ConnectMes, "info", fmt.Sprintf("设备%s通过MQTT协议连接", etoken.Name), etoken)
|
||||
data := netbase.CreateEventInfo(message.ConnectMes, "info", fmt.Sprintf("设备%s通过MQTT协议连接", etoken.Name), etoken)
|
||||
go s.HookService.Queue.Queue(data)
|
||||
return &exhook2.EmptySuccess{}, nil
|
||||
}
|
||||
@@ -103,7 +103,7 @@ func (s *HookGrpcService) OnClientDisconnected(ctx context.Context, in *exhook2.
|
||||
}
|
||||
//删除连接ID
|
||||
mqttclient.Session.Delete(etoken.DeviceId)
|
||||
data := netbase.CreateEvent(message.DisConnectMes, "info", fmt.Sprintf("设备%s断开连接", etoken.Name), etoken)
|
||||
data := netbase.CreateEventInfo(message.DisConnectMes, "info", fmt.Sprintf("设备%s断开连接", etoken.Name), etoken)
|
||||
go s.HookService.Queue.Queue(data)
|
||||
return &exhook2.EmptySuccess{}, nil
|
||||
}
|
||||
@@ -243,10 +243,10 @@ func (s *HookGrpcService) OnMessagePublish(ctx context.Context, in *exhook2.Mess
|
||||
if in.Message.Topic == ConnectGatewayTopic {
|
||||
if val, ok := value.(string); ok {
|
||||
if val == "online" {
|
||||
data = netbase.CreateEvent(message.ConnectMes, "info", fmt.Sprintf("子设备%s通过网关连接", etoken.Name), auth)
|
||||
data = netbase.CreateEventInfo(message.ConnectMes, "info", fmt.Sprintf("子设备%s通过网关连接", etoken.Name), auth)
|
||||
}
|
||||
if val == "offline" {
|
||||
data = netbase.CreateEvent(message.ConnectMes, "info", fmt.Sprintf("子设备设备%s通过网关连接", etoken.Name), auth)
|
||||
data = netbase.CreateEventInfo(message.ConnectMes, "info", fmt.Sprintf("子设备设备%s通过网关连接", etoken.Name), auth)
|
||||
}
|
||||
// 子设备发送到队列里
|
||||
go s.HookService.Queue.Queue(data)
|
||||
|
||||
@@ -153,12 +153,12 @@ func (hhs *HookHttpService) hook(req *restful.Request, resp *restful.Response) {
|
||||
|
||||
func (cm *ConnectionManager) AddConnection(addr string, etoken *model.DeviceAuth, service *hook_message_work.HookService) {
|
||||
cm.activeConnections.Store(addr, etoken)
|
||||
data := netbase.CreateEvent(message.ConnectMes, "info", fmt.Sprintf("设备%s通过HTTP协议连接", etoken.Name), etoken)
|
||||
data := netbase.CreateEventInfo(message.ConnectMes, "info", fmt.Sprintf("设备%s通过HTTP协议连接", etoken.Name), etoken)
|
||||
go service.Queue.Queue(data)
|
||||
}
|
||||
|
||||
func (cm *ConnectionManager) RemoveConnection(addr string, etoken *model.DeviceAuth, service *hook_message_work.HookService) {
|
||||
data := netbase.CreateEvent(message.DisConnectMes, "info", fmt.Sprintf("设备%s断开连接", etoken.Name), etoken)
|
||||
data := netbase.CreateEventInfo(message.DisConnectMes, "info", fmt.Sprintf("设备%s断开连接", etoken.Name), etoken)
|
||||
cm.activeConnections.Delete(addr)
|
||||
go service.Queue.Queue(data)
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func handleConnection(conn *net.TCPConn, hs *hook_message_work.HookService) {
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
if isAuth {
|
||||
data := netbase.CreateEvent(message.DisConnectMes, "info", fmt.Sprintf("设备%s断开连接", etoken.Name), etoken)
|
||||
data := netbase.CreateEventInfo(message.DisConnectMes, "info", fmt.Sprintf("设备%s断开连接", etoken.Name), etoken)
|
||||
go hs.Queue.Queue(data)
|
||||
}
|
||||
tcpclient.TcpClient.Delete(etoken.DeviceId)
|
||||
@@ -67,7 +67,7 @@ func handleConnection(conn *net.TCPConn, hs *hook_message_work.HookService) {
|
||||
auth := netbase.Auth(token)
|
||||
if auth {
|
||||
global.Log.Infof("TCP协议 设备%s,认证成功", etoken.DeviceId)
|
||||
data := netbase.CreateEvent(message.ConnectMes, "info", fmt.Sprintf("设备%s通过TCP协议连接", etoken.Name), etoken)
|
||||
data := netbase.CreateEventInfo(message.ConnectMes, "info", fmt.Sprintf("设备%s通过TCP协议连接", etoken.Name), etoken)
|
||||
go hs.Queue.Queue(data)
|
||||
isAuth = true
|
||||
tcpclient.TcpClient.Store(etoken.DeviceId, conn)
|
||||
|
||||
@@ -44,7 +44,7 @@ func InitUdpHook(addr string, hs *hook_message_work.HookService) {
|
||||
_ = server.listener.Close()
|
||||
|
||||
if isAuth, ok := authMap[client.AddrPort().String()]; ok && isAuth {
|
||||
data := netbase.CreateEvent(message.DisConnectMes, "info", fmt.Sprintf("设备%s断开连接", etoken.Name), etoken)
|
||||
data := netbase.CreateEventInfo(message.DisConnectMes, "info", fmt.Sprintf("设备%s断开连接", etoken.Name), etoken)
|
||||
go hhs.HookService.Queue.Queue(data)
|
||||
}
|
||||
udpclient.UdpClient.Delete(etoken.DeviceId)
|
||||
@@ -72,7 +72,7 @@ func InitUdpHook(addr string, hs *hook_message_work.HookService) {
|
||||
|
||||
if auth {
|
||||
global.Log.Infof("UDP协议 设备%s,认证成功", etoken.DeviceId)
|
||||
data := netbase.CreateEvent(message.ConnectMes, "info", fmt.Sprintf("设备%s通过UDP协议连接", etoken.Name), etoken)
|
||||
data := netbase.CreateEventInfo(message.ConnectMes, "info", fmt.Sprintf("设备%s通过UDP协议连接", etoken.Name), etoken)
|
||||
go hhs.HookService.Queue.Queue(data)
|
||||
|
||||
authMap[client.AddrPort().String()] = true
|
||||
|
||||
Reference in New Issue
Block a user