sunpengfei
2025-08-07 b4205c80b0fd6220632fa0ab7df4c75ba844afc4
FlexJobApi.Application/Dictionaries/Commands/DictionaryDataCommandHandler.cs
@@ -1,4 +1,5 @@
using EFCore.BulkExtensions;
using Consul;
using EFCore.BulkExtensions;
using FlexJobApi.Core;
using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
@@ -94,6 +95,16 @@
            {
                CategoryId = categoryId
            });
            var parentAreas = areas.Where(it => it.ParentId == 0).ToList();
            LoopAdd(categoryId, entities, areas, parentAreas);
            await rep.Context.BulkInsertAsync(entities);
            return entities.Count;
        }
        public void LoopAdd(Guid categoryId, List<DictionaryData> entities, List<BaseArea> all, List<BaseArea> areas)
        {
            if (areas.IsNotNull())
            {
            foreach (var area in areas)
            {
                var entity = new DictionaryData();
@@ -107,12 +118,9 @@
                        var parentArea = areas.FirstOrDefault(it => it.AreaCode == area.ParentId);
                        if (parentArea != null)
                        {
                            throw Oops.Oh(EnumErrorCodeType.s404, "未找到上级地区");
                                throw Oops.Oh(EnumErrorCodeType.s404, "上级地区");
                        }
                        else
                        {
                            continue;
                        }
                    }
                    entity.ParentId = parent.Id;
                    entity.Path = $"{parent.Path}{parent.Code}/";
@@ -130,9 +138,11 @@
                entity.Field5 = area.Description;
                entity.Sort = area.Sort ?? 0;
                entities.Add(entity);
                    var children = all.Where(it => it.ParentId == area.AreaCode).ToList();
                    LoopAdd(categoryId, entities, all, children);
            }
            await rep.Context.BulkInsertAsync(entities);
            return entities.Count;
            }
        }
    }
}