| | |
| | | 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, "用户类型"); |
| | |
| | | // 获取子集Id |
| | | var childrenIds = GetRequestChildrenIds(request); |
| | | // 删除子级 |
| | | entity.Childrens = entity.Childrens.Where(it => |
| | | it.Type == EnumMenuType.Menu |
| | | || it.Type == EnumMenuType.Page |
| | | || it.Type == EnumMenuType.Modal |
| | | || childrenIds.Contains(it.Id)).ToList(); |
| | | entity.Children = entity.Children |
| | | .Where(it => |
| | | it.Type == EnumMenuType.Menu |
| | | || it.Type == EnumMenuType.Page |
| | | || it.Type == EnumMenuType.Modal |
| | | || childrenIds.Contains(it.Id)) |
| | | .ToList(); |
| | | |
| | | // 遍历分组 |
| | | |
| | |
| | | // 遍历按钮 添加或更新 |
| | | 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}"); |
| | |
| | | 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}/"; |
| | |
| | | // 遍历字段 添加或更新 |
| | | 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}"); |
| | |
| | | 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}/"; |
| | |
| | | /// <param name="entity"></param> |
| | | private void CheckRepeatChildrens(Menu entity) |
| | | { |
| | | var repeats = entity.Childrens |
| | | var repeats = entity.Children |
| | | .GroupBy(it => |
| | | { |
| | | return it.Type == EnumMenuType.Button |