37 Star 409 Fork 125

联犀/物联网iot模块

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
shadowIndexLogic.go 1.57 KB
一键复制 编辑 原始数据 按行查看 历史
杨磊 提交于 2024-10-10 22:13 . feat: 更新mod
package devicemsglogic
import (
"context"
"gitee.com/unitedrhino/share/def"
"gitee.com/unitedrhino/share/devices"
"gitee.com/unitedrhino/share/utils"
"gitee.com/unitedrhino/things/service/dmsvr/internal/domain/shadow"
"gitee.com/unitedrhino/things/service/dmsvr/internal/logic"
"gitee.com/unitedrhino/things/service/dmsvr/internal/repo/relationDB"
"gitee.com/unitedrhino/things/service/dmsvr/pb/dm"
"gitee.com/unitedrhino/things/service/dmsvr/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ShadowIndexLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewShadowIndexLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShadowIndexLogic {
return &ShadowIndexLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// 获取设备影子列表
func (l *ShadowIndexLogic) ShadowIndex(in *dm.PropertyLogLatestIndexReq) (*dm.ShadowIndexResp, error) {
_, err := logic.SchemaAccess(l.ctx, l.svcCtx, def.AuthRead, devices.Core{
ProductID: in.ProductID,
DeviceName: in.DeviceName,
}, nil)
if err != nil {
return nil, err
}
sr := relationDB.NewShadowRepo(l.ctx)
srs, err := sr.FindByFilter(l.ctx, shadow.Filter{
ProductID: in.ProductID,
DeviceName: in.DeviceName,
DataIDs: in.DataIDs,
})
if err != nil {
return nil, err
}
var index []*dm.ShadowIndex
for _, v := range srs {
index = append(index, &dm.ShadowIndex{
DataID: v.DataID,
Value: v.Value,
UpdatedDeviceTime: utils.ToInt64(v.UpdatedDeviceTime),
})
}
return &dm.ShadowIndexResp{List: index}, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/unitedrhino/things.git
git@gitee.com:unitedrhino/things.git
unitedrhino
things
物联网iot模块
v1.0.4

搜索帮助