代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。