37 Star 391 Fork 118

联犀/物联网iot模块

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
subscribeLogic.go 1.95 KB
一键复制 编辑 原始数据 按行查看 历史
杨磊 提交于 2024-10-10 22:13 . feat: 更新mod
package user
import (
"context"
"gitee.com/unitedrhino/share/ctxs"
"gitee.com/unitedrhino/share/def"
"gitee.com/unitedrhino/share/errors"
"gitee.com/unitedrhino/share/utils"
"gitee.com/unitedrhino/things/service/dmsvr/pb/dm"
"github.com/spf13/cast"
"gitee.com/unitedrhino/things/service/apisvr/internal/svc"
"gitee.com/unitedrhino/things/service/apisvr/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SubscribeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSubscribeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SubscribeLogic {
return &SubscribeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SubscribeLogic) Subscribe(req *types.SlotUserSubscribeReq) error {
l.Infof("userSubscribeSlot:%v", utils.Fmt(req))
switch req.Code {
case def.UserSubscribeDeviceConn:
case def.UserSubscribeDevicePropertyReport:
case def.UserSubscribeDeviceActionReport:
case def.UserSubscribeDeviceOtaReport:
default:
return errors.NotRealize
}
var productID = cast.ToString(req.Params["productID"])
var deviceName = cast.ToString(req.Params["deviceName"])
var projectID = cast.ToInt64(req.Params["projectID"])
var areaID = cast.ToInt64(req.Params["areaID"])
if productID != "" && deviceName != "" { //设备有权限查就能订阅
_, err := l.svcCtx.DeviceM.DeviceInfoRead(l.ctx, &dm.DeviceInfoReadReq{
ProductID: productID,
DeviceName: deviceName,
})
return err
}
var uc = ctxs.GetUserCtx(l.ctx)
if uc == nil {
return errors.Permissions.AddMsg("只有用户才能订阅")
}
if projectID == 0 {
return errors.Permissions
}
if uc.IsAdmin {
return nil
}
pa := uc.ProjectAuth[projectID]
if pa == nil {
return errors.Permissions
}
if pa.AuthType == def.AuthAdmin || pa.AuthType == def.AuthReadWrite {
return nil
}
if areaID == 0 {
return errors.Permissions
}
aa := pa.Area[areaID]
if aa == 0 {
return errors.Permissions
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/unitedrhino/things.git
git@gitee.com:unitedrhino/things.git
unitedrhino
things
物联网iot模块
v1.1.0

搜索帮助