Skip to content

Commit

Permalink
feat: 修复action推送不正确的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
godLei6 committed Sep 19, 2023
1 parent e3fab8c commit ee76588
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/disvr/internal/event/deviceMsgEvent/thing.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ func (l *ThingLogic) HandleAction(msg *deviceMsg.PublishMsg) (respMsg *deviceMsg
if err != nil {
return nil, err
}
utils.GoNewCtx(l.ctx, func(ctx context.Context) {
l.Infof("DeviceThingActionReport.Action device:%v,reqType:%v,req:%v", core, reqType, l.dreq)
//应用事件通知-设备物模型事件上报通知 ↓↓↓
err := l.svcCtx.PubApp.DeviceThingActionReport(ctx, application.ActionReport{
Device: core, Timestamp: timeStamp.UnixMilli(), ReqType: reqType, ClientToken: l.dreq.ClientToken,
ActionID: l.dreq.ActionID, Params: l.dreq.Params, Dir: schema.ActionDirUp, Code: l.dreq.Code, Status: l.dreq.Status,
})
if err != nil {
logx.WithContext(ctx).Errorf("%s.DeviceThingActionReport.Action req:%v,err:%v", utils.FuncName(), utils.Fmt(l.dreq), err)
}
})
case deviceMsg.ActionReply: //云端请求设备的回复
reqType = deviceMsg.RespMsg
var resp msgThing.Resp
Expand All @@ -312,18 +323,20 @@ func (l *ThingLogic) HandleAction(msg *deviceMsg.PublishMsg) (respMsg *deviceMsg
if err != nil {
return nil, err
}
}
utils.GoNewCtx(l.ctx, func(ctx context.Context) {
l.Infof("DeviceThingActionReport device:%v,reqType:%v,req:%v", core, reqType, l.dreq)
//应用事件通知-设备物模型事件上报通知 ↓↓↓
err := l.svcCtx.PubApp.DeviceThingActionReport(ctx, application.ActionReport{
Device: core, Timestamp: timeStamp.UnixMilli(), ReqType: reqType, ClientToken: l.dreq.ClientToken,
ActionID: l.dreq.ActionID, Params: l.dreq.Params, Dir: schema.ActionDirUp, Code: l.dreq.Code, Status: l.dreq.Status,
utils.GoNewCtx(l.ctx, func(ctx context.Context) {
l.Infof("DeviceThingActionReport.ActionReply device:%v,reqType:%v,req:%v", core, reqType, l.dreq)
param := resp.Data.(map[string]any)
//应用事件通知-设备物模型事件上报通知 ↓↓↓
err := l.svcCtx.PubApp.DeviceThingActionReport(ctx, application.ActionReport{
Device: core, Timestamp: timeStamp.UnixMilli(), ReqType: reqType, ClientToken: resp.ClientToken,
ActionID: resp.ActionID, Params: param, Dir: schema.ActionDirUp, Code: resp.Code, Status: resp.Status,
})
if err != nil {
logx.WithContext(ctx).Errorf("%s.DeviceThingActionReport req:%v,err:%v", utils.FuncName(), utils.Fmt(l.dreq), err)
}
})
if err != nil {
logx.WithContext(ctx).Errorf("%s.DeviceThingActionReport req:%v,err:%v", utils.FuncName(), utils.Fmt(l.dreq), err)
}
})
}

return nil, nil
}

Expand Down

0 comments on commit ee76588

Please sign in to comment.