This commit is contained in:
tfl
2024-08-21 17:35:50 +08:00
parent 34ea7472b7
commit dd5b38b4e3
24 changed files with 328 additions and 133 deletions

View File

@@ -2,7 +2,6 @@ package netbase
import (
"encoding/json"
"fmt"
"pandax/apps/device/entity"
"pandax/apps/device/services"
exhook "pandax/iothub/server/emqxserver/protobuf"
@@ -182,6 +181,15 @@ func SplitLwm2mClientID(lwm2mClientID string, index int) string {
}
func GetRequestIdFromTopic(reg, topic string) (requestId string) {
re := regexp.MustCompile(reg)
res := re.FindStringSubmatch(topic)
if len(res) > 2 {
return res[2]
}
return ""
}
func GetEventFromTopic(reg, topic string) (identifier string) {
re := regexp.MustCompile(reg)
res := re.FindStringSubmatch(topic)
if len(res) > 1 {
@@ -190,13 +198,14 @@ func GetRequestIdFromTopic(reg, topic string) (requestId string) {
return ""
}
func CreateConnectionInfo(msgType, protocol, clientID, peerHost string, deviceAuth *model.DeviceAuth) *DeviceEventInfo {
// eventType 事件类型 info alarm
func CreateEvent(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,
Name: msgType,
Type: "info",
Content: fmt.Sprintf("设备%s, %s 事件", deviceAuth.Name, msgType),
Type: eventType,
Content: content,
Ts: ts,
}
v, err := json.Marshal(*ci)