| | |
| | | using EFCore.BulkExtensions; |
| | | using Consul; |
| | | using EFCore.BulkExtensions; |
| | | using FlexJobApi.Core; |
| | | using Furion.DatabaseAccessor; |
| | | using Furion.DatabaseAccessor.Extensions; |
| | |
| | | { |
| | | 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(); |
| | |
| | | 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}/"; |
| | |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | | } |