sunpengfei
2025-08-05 1ddd1094f635bdc69e1e236353aa77d5b400f007
FlexJobApi.User.Application/Menus/Commands/SaveMenuCommandHandler.cs
@@ -32,7 +32,7 @@
            if (request.Id.HasValue)
            {
                var entity = await rep.AsQueryable()
                    .Include(it => it.Childrens)
                    .Include(it => it.Children)
                    .FirstOrDefaultAsync(it => it.Id == request.Id, cancellationToken);
                if (entity == null) throw Oops.Oh(EnumErrorCodeType.s404, "菜单");
                if (entity.UserType != request.UserType) throw Oops.Oh(EnumErrorCodeType.s410, "用户类型");
@@ -71,7 +71,7 @@
            // 获取子集Id
            var childrenIds = GetRequestChildrenIds(request);
            // 删除子级
            entity.Childrens = entity.Childrens
            entity.Children = entity.Children
                .Where(it => 
                    it.Type == EnumMenuType.Menu 
                    || it.Type == EnumMenuType.Page 
@@ -89,7 +89,7 @@
                    // 遍历按钮 添加或更新
                    foreach (var button in buttonLocation.Buttons)
                    {
                        var buttonEntity = entity.Childrens.FirstOrDefault(it => it.Id == button.Id);
                        var buttonEntity = entity.Children.FirstOrDefault(it => it.Id == button.Id);
                        if (buttonEntity == null)
                        {
                            if (button.Id.HasValue) throw Oops.Oh(EnumErrorCodeType.s404, $"当前分组{group.Group}-位置{buttonLocation.Location}-按钮{button.Code}");
@@ -98,8 +98,9 @@
                                UserType = entity.UserType,
                                ClientType = entity.ClientType,
                                Type = EnumMenuType.Button,
                                VisitLevel = entity.VisitLevel,
                            };
                            entity.Childrens.Add(buttonEntity);
                            entity.Children.Add(buttonEntity);
                        }
                        else if (buttonEntity.Type != EnumMenuType.Button) throw Oops.Oh(EnumErrorCodeType.s400, $"当前分组{group.Group}-字段{button.Code}并非一个按钮");
                        buttonEntity.Path = $"{entity.Path}{entity.Code}/";
@@ -112,7 +113,7 @@
                // 遍历字段 添加或更新
                foreach (var field in group.Fields)
                {
                    var fieldEntity = entity.Childrens.FirstOrDefault(it => it.Id == field.Id);
                    var fieldEntity = entity.Children.FirstOrDefault(it => it.Id == field.Id);
                    if (fieldEntity == null)
                    {
                        if (field.Id.HasValue) throw Oops.Oh(EnumErrorCodeType.s404, $"当前分组{group.Group}-字段{field.Code}");
@@ -121,8 +122,9 @@
                            UserType = entity.UserType,
                            ClientType = entity.ClientType,
                            Type = EnumMenuType.Field,
                            VisitLevel = entity.VisitLevel,
                        };
                        entity.Childrens.Add(fieldEntity);
                        entity.Children.Add(fieldEntity);
                    }
                    else if (fieldEntity.Type != EnumMenuType.Field) throw Oops.Oh(EnumErrorCodeType.s400, $"当前分组{group.Group}-位置{fieldEntity.Location}-按钮{fieldEntity.Code}并非一个字段");
                    fieldEntity.Path = $"{entity.Path}{entity.Code}/";
@@ -139,7 +141,7 @@
        /// <param name="entity"></param>
        private void CheckRepeatChildrens(Menu entity)
        {
            var repeats = entity.Childrens
            var repeats = entity.Children
                .GroupBy(it =>
                {
                    return it.Type == EnumMenuType.Button