完善自我更新逻辑

This commit is contained in:
BBIT-Kai
2025-12-30 17:54:33 +08:00
parent ec29d883bd
commit 62e8ecb7d6
12 changed files with 248 additions and 112 deletions
+4 -4
View File
@@ -6,7 +6,7 @@ import (
)
type MqttTopic struct {
Project string
DeptId string
Domain string
DeviceType string
DeviceID string
@@ -21,7 +21,7 @@ func FromStringToMqttTopic(topic string) *MqttTopic {
parts = append(parts, "")
}
return &MqttTopic{
Project: parts[0],
DeptId: parts[0],
Domain: parts[1],
DeviceType: parts[2],
DeviceID: parts[3],
@@ -38,7 +38,7 @@ func (m *MqttTopic) ToString() string {
return s
}
return strings.Join([]string{
toVal(m.Project),
toVal(m.DeptId),
toVal(m.Domain),
toVal(m.DeviceType),
toVal(m.DeviceID),
@@ -48,7 +48,7 @@ func (m *MqttTopic) ToString() string {
// 严格生成 topic,不允许 "+" 或空
func (m *MqttTopic) Build() (string, error) {
parts := []string{m.Project, m.Domain, m.DeviceType, m.DeviceID, m.Resource}
parts := []string{m.DeptId, m.Domain, m.DeviceType, m.DeviceID, m.Resource}
for _, p := range parts {
if p == "" || p == "+" {
return "", errors.New("cannot build strict topic, wildcard exists")