| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- 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("该部门下存在子部门,无法删除")
- }
- return l.svcCtx.SysDeptModel.Delete(l.ctx, req.Id)
- }
|