37 Star 385 Fork 118

联犀/物联网模块

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
groupDeviceMultiCreateLogic.go 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
杨磊 提交于 2024-11-18 14:54 . feat: 升级批量更新导入功能
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
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/unitedrhino/things.git
git@gitee.com:unitedrhino/things.git
unitedrhino
things
物联网模块
v1.2.0

搜索帮助

0d507c66 1850385 C8b1a773 1850385