From 59e73ad4283491cd407854874879e0ddc8dafaba Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期四, 07 八月 2025 14:08:20 +0800 Subject: [PATCH] feat:地区字典 --- FlexJobApi.User.Application/Menus/Commands/SaveMenuButtonCommandHandler.cs | 59 ++++++++++++++++++++++++++--------------------------------- 1 files changed, 26 insertions(+), 33 deletions(-) diff --git a/FlexJobApi.User.Application/Menus/Commands/SaveMenuButtonCommandHandler.cs b/FlexJobApi.User.Application/Menus/Commands/SaveMenuButtonCommandHandler.cs index 21d9a7e..87db6f8 100644 --- a/FlexJobApi.User.Application/Menus/Commands/SaveMenuButtonCommandHandler.cs +++ b/FlexJobApi.User.Application/Menus/Commands/SaveMenuButtonCommandHandler.cs @@ -24,39 +24,32 @@ /// <inheritdoc/> public async Task<Guid> Handle(SaveMenuButtonCommand request, CancellationToken cancellationToken) { - if (request.Id.HasValue) - { - var entity = await rep.FirstOrDefaultAsync(it => it.Id == it.Id); - if (entity.ParentId != request.ParentId) throw Oops.Oh(EnumErrorCodeType.s410, "涓婄骇Id"); - request.Adapt(entity); - if (await CheckExist(entity)) throw Oops.Oh(EnumErrorCodeType.s405, "鑿滃崟缂栧彿"); - await rep.UpdateAsync(entity); - return entity.Id; - } - else - { - var entity = new Menu(); - request.Adapt(entity); - if (await CheckExist(entity)) throw Oops.Oh(EnumErrorCodeType.s405, "鑿滃崟缂栧彿"); - await rep.InsertAsync(entity); - return entity.Id; - } - } - - /// <summary> - /// 鏍¢獙鑿滃崟鏄惁閲嶅 - /// </summary> - /// <param name="entity"></param> - /// <returns></returns> - private async Task<bool> CheckExist(Menu entity) - { - return await rep.AsQueryable().AsNoTracking() - .AnyAsync(it => - it.ParentId == entity.ParentId - && it.Group == entity.Group - && it.Location == entity.Location - && it.Code == entity.Code - && it.Id != entity.Id); + var parent = await rep.FirstOrDefaultAsync(it => it.Id == request.ParentId); + if (parent == null) throw Oops.Oh(EnumErrorCodeType.s404, "涓婄骇鑿滃崟"); + return await request.SaveData<Menu, SaveMenuButtonCommand>( + null, + it => + it.ParentId == request.ParentId + && it.Type == EnumMenuType.Button + && it.Group == request.Group + && it.Location == request.Location + && it.Code == request.Code + && it.Id != request.Id, + (entity) => + { + if (request.Id.HasValue) + { + if (entity.ParentId != request.ParentId) throw Oops.Oh(EnumErrorCodeType.s410, "涓婄骇Id"); + } + else + { + entity.Path = $"{parent.Path}{parent.Code}/"; + entity.Type = EnumMenuType.Button; + entity.VisitLevel = parent.VisitLevel; + } + request.Adapt(entity); + }, + cancellationToken); } } } -- Gitblit v1.9.1