Skip to content

Commit

Permalink
feat: 闪烁上下线类型不推送出去
Browse files Browse the repository at this point in the history
  • Loading branch information
godLei6 committed Dec 20, 2024
1 parent ac9adeb commit 807c374
Showing 1 changed file with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func HandleOnlineFix(ctx context.Context, svcCtx *svc.ServiceContext, insertList
ProductID: ld.ProductID,
DeviceName: ld.DeviceName,
}
var needPush bool
di, err := svcCtx.DeviceCache.GetData(ctx, dev)
if err != nil {
log.Error(err)
Expand All @@ -126,7 +127,9 @@ func HandleOnlineFix(ctx context.Context, svcCtx *svc.ServiceContext, insertList
if err != nil {
log.Error(err)
}

if di.IsOnline != def.True {
needPush = true
}
err = svcCtx.PubApp.DeviceStatusConnected(ctx, appMsg)
if err != nil {
log.Errorf("%s.pubApp productID:%v deviceName:%v err:%v",
Expand All @@ -148,10 +151,8 @@ func HandleOnlineFix(ctx context.Context, svcCtx *svc.ServiceContext, insertList
}
}
OffLineDevices = append(OffLineDevices, &dev)
err = svcCtx.PubApp.DeviceStatusDisConnected(ctx, appMsg)
if err != nil {
log.Errorf("%s.pubApp productID:%v deviceName:%v err:%v",
utils.FuncName(), ld.ProductID, ld.DeviceName, err)
if di.IsOnline == def.True {
needPush = true
}
protocol.DeleteDeviceActivity(ctx, dev)
}
Expand All @@ -166,18 +167,26 @@ func HandleOnlineFix(ctx context.Context, svcCtx *svc.ServiceContext, insertList
log.Errorf("%s.HubLogRepo.insert productID:%v deviceName:%v err:%v",
utils.FuncName(), ld.ProductID, ld.DeviceName, err)
}
err = svcCtx.UserSubscribe.Publish(ctx, def.UserSubscribeDeviceConn, appMsg, map[string]any{
"productID": ld.ProductID,
"deviceName": ld.DeviceName,
}, map[string]any{
"projectID": di.ProjectID,
}, map[string]any{
"projectID": cast.ToString(di.ProjectID),
"areaID": cast.ToString(di.AreaID),
})
if err != nil {
log.Error(err)
if needPush {
err = svcCtx.PubApp.DeviceStatusDisConnected(ctx, appMsg)
if err != nil {
log.Errorf("%s.pubApp productID:%v deviceName:%v err:%v",
utils.FuncName(), ld.ProductID, ld.DeviceName, err)
}
err = svcCtx.UserSubscribe.Publish(ctx, def.UserSubscribeDeviceConn, appMsg, map[string]any{
"productID": ld.ProductID,
"deviceName": ld.DeviceName,
}, map[string]any{
"projectID": di.ProjectID,
}, map[string]any{
"projectID": cast.ToString(di.ProjectID),
"areaID": cast.ToString(di.AreaID),
})
if err != nil {
log.Error(err)
}
}

}
for _, msg := range insertList {
handleMsg(msg)
Expand Down

0 comments on commit 807c374

Please sign in to comment.