代码拉取完成,页面将自动刷新
package devicegrouplogic
import (
"context"
"gitee.com/unitedrhino/share/ctxs"
"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 GroupDeviceMultiCreateLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
GdDB *relationDB.GroupDeviceRepo
}
func NewGroupDeviceMultiCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GroupDeviceMultiCreateLogic {
return &GroupDeviceMultiCreateLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
GdDB: relationDB.NewGroupDeviceRepo(ctx),
}
}
// 创建分组设备
func (l *GroupDeviceMultiCreateLogic) GroupDeviceMultiCreate(in *dm.GroupDeviceMultiSaveReq) (*dm.Empty, error) {
l.ctx = ctxs.WithDefaultAllProject(l.ctx)
t, err := relationDB.NewDeviceInfoRepo(l.ctx).CountByFilter(l.ctx, relationDB.DeviceFilter{Cores: logic.ToDeviceCores(in.List)})
if err != nil {
return nil, err
}
if int(t) != len(in.List) {
return nil, errors.Duplicate.AddMsg("有被删除的设备请重试")
}
gi, err := relationDB.NewGroupInfoRepo(l.ctx).FindOne(l.ctx, in.GroupID)
if err != nil {
return nil, err
}
list := make([]*relationDB.DmGroupDevice, 0, len(in.List))
for _, v := range in.List {
list = append(list, &relationDB.DmGroupDevice{
GroupID: in.GroupID,
ProductID: v.ProductID,
DeviceName: v.DeviceName,
AreaID: gi.AreaID,
})
}
err = l.GdDB.MultiInsert(l.ctx, list)
if err != nil {
return nil, errors.Database.AddDetail(err)
}
relationDB.NewGroupInfoRepo(l.ctx).UpdateGroupDeviceCount(l.ctx, in.GroupID)
return &dm.Empty{}, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。