package dept import ( "context" authHelper "perms-system-server/internal/logic/auth" "perms-system-server/internal/response" "perms-system-server/internal/svc" "perms-system-server/internal/types" "github.com/zeromicro/go-zero/core/logx" ) type DeleteDeptLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewDeleteDeptLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDeptLogic { return &DeleteDeptLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *DeleteDeptLogic) DeleteDept(req *types.DeleteDeptReq) error { if err := authHelper.RequireSuperAdmin(l.ctx); err != nil { return err } children, err := l.svcCtx.SysDeptModel.FindByParentId(l.ctx, req.Id) if err != nil { return err } if len(children) > 0 { return response.ErrBadRequest("该部门下存在子部门,无法删除") } userIds, _ := l.svcCtx.SysUserModel.FindIdsByDeptId(l.ctx, req.Id) if len(userIds) > 0 { return response.ErrBadRequest("该部门下仍有关联用户,无法删除") } return l.svcCtx.SysDeptModel.Delete(l.ctx, req.Id) }