37 Star 391 Fork 118

联犀/物联网iot模块

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
deviceInfoReadLogic.go 2.19 KB
一键复制 编辑 原始数据 按行查看 历史
杨磊 提交于 2024-10-10 22:13 . feat: 更新mod
package devicemanagelogic
import (
"context"
"gitee.com/unitedrhino/share/ctxs"
"gitee.com/unitedrhino/share/def"
"gitee.com/unitedrhino/share/devices"
"gitee.com/unitedrhino/share/errors"
"gitee.com/unitedrhino/things/service/dmsvr/internal/logic"
"gitee.com/unitedrhino/things/service/dmsvr/internal/repo/relationDB"
"gitee.com/unitedrhino/things/service/dmsvr/internal/svc"
"gitee.com/unitedrhino/things/service/dmsvr/pb/dm"
"github.com/zeromicro/go-zero/core/logx"
)
type DeviceInfoReadLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
DiDB *relationDB.DeviceInfoRepo
}
func NewDeviceInfoReadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeviceInfoReadLogic {
return &DeviceInfoReadLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
DiDB: relationDB.NewDeviceInfoRepo(ctx),
}
}
// 获取设备信息详情
func (l *DeviceInfoReadLogic) DeviceInfoRead(in *dm.DeviceInfoReadReq) (*dm.DeviceInfo, error) {
if ctxs.GetUserCtx(l.ctx).IsAdmin {
l.ctx = ctxs.WithAllProject(l.ctx)
}
di, err := l.DiDB.FindOneByFilter(l.ctx,
relationDB.DeviceFilter{ProductID: in.ProductID, DeviceNames: []string{in.DeviceName},
SharedType: def.SelectTypeAll})
if err != nil && !errors.Cmp(err, errors.NotFind) {
l.Error(err)
return nil, err
}
if di == nil {
di, err = l.DiDB.FindOneByFilter(l.ctx,
relationDB.DeviceFilter{DeviceNames: []string{in.DeviceName},
SharedType: def.SelectTypeAll})
if err != nil {
l.Error(err)
return nil, err
}
}
pb := logic.ToDeviceInfo(l.ctx, l.svcCtx, di)
if in.WithGateway && pb.DeviceType == def.DeviceTypeSubset {
gd, err := relationDB.NewGatewayDeviceRepo(l.ctx).FindOneByFilter(l.ctx, relationDB.GatewayDeviceFilter{SubDevice: &devices.Core{
ProductID: di.ProductID,
DeviceName: di.DeviceName,
}})
if err != nil && !errors.Cmp(err, errors.NotFind) {
return nil, err
}
if gd != nil {
ddi, err := l.svcCtx.DeviceCache.GetData(l.ctx, devices.Core{
ProductID: gd.GatewayProductID,
DeviceName: gd.GatewayDeviceName,
})
if err != nil && !errors.Cmp(err, errors.NotFind) {
return nil, err
}
if ddi != nil {
pb.Gateway = ddi
}
}
}
return pb, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/unitedrhino/things.git
git@gitee.com:unitedrhino/things.git
unitedrhino
things
物联网iot模块
v1.0.4

搜索帮助