37 Star 401 Fork 123

联犀/物联网iot模块

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
groupInfoDeleteLogic.go 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
杨磊 提交于 2024-10-10 22:13 . feat: 更新mod
package devicegrouplogic
import (
"context"
"gitee.com/unitedrhino/share/def"
"gitee.com/unitedrhino/share/stores"
"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"
"gorm.io/gorm"
"github.com/zeromicro/go-zero/core/logx"
)
type GroupInfoDeleteLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
GiDB *relationDB.GroupInfoRepo
}
func NewGroupInfoDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GroupInfoDeleteLogic {
return &GroupInfoDeleteLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
GiDB: relationDB.NewGroupInfoRepo(ctx),
}
}
// 删除分组
func (l *GroupInfoDeleteLogic) GroupInfoDelete(in *dm.WithID) (*dm.Empty, error) {
po, err := relationDB.NewGroupInfoRepo(l.ctx).FindOne(l.ctx, in.Id)
if err != nil {
return nil, err
}
stores.GetTenantConn(l.ctx).Transaction(func(tx *gorm.DB) error {
if po.ParentID != 0 {
c, err := relationDB.NewGroupInfoRepo(tx).CountByFilter(l.ctx, relationDB.GroupInfoFilter{ParentID: po.ParentID})
if err != nil {
return err
}
if c == 0 { //下面没有子节点了
err = relationDB.NewGroupInfoRepo(tx).UpdateWithField(l.ctx,
relationDB.GroupInfoFilter{ID: po.ParentID}, map[string]any{"is_leaf": def.True})
if err != nil {
return err
}
}
}
err := relationDB.NewGroupInfoRepo(l.ctx).Delete(l.ctx, in.Id)
return err
})
logic.FillAreaGroupCount(l.ctx, l.svcCtx, int64(po.AreaID))
return &dm.Empty{}, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/unitedrhino/things.git
git@gitee.com:unitedrhino/things.git
unitedrhino
things
物联网iot模块
v1.0.3

搜索帮助