sunpengfei
2025-08-07 b4205c80b0fd6220632fa0ab7df4c75ba844afc4
feat:字典开发
3个文件已修改
33 ■■■■ 已修改文件
FlexJobApi.Application/Dictionaries/Commands/DictionaryDataCommandHandler.cs 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FlexJobApi.Application/Dictionaries/Queries/DictionaryDatasQueryHandler.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FlexJobApi.Core/Models/Main/Dictionaries/Queries/GetDictionaryDatasQuery.cs 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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;
            }
        }
    }
}
FlexJobApi.Application/Dictionaries/Queries/DictionaryDatasQueryHandler.cs
@@ -46,6 +46,10 @@
                    {
                        throw Oops.Oh(EnumErrorCodeType.s400, "请填写类别Id或编号");
                    }
                    if (request.ParentId.HasValue)
                    {
                        q = q.Where(it => it.ParentId == request.ParentId);
                    }
                    if (request.Keywords.IsNotNull())
                    {
                        q = q.Where(it =>
FlexJobApi.Core/Models/Main/Dictionaries/Queries/GetDictionaryDatasQuery.cs
@@ -26,6 +26,11 @@
        public string CategoryCode { get; set; }
        /// <summary>
        /// 上级Id
        /// </summary>
        public Guid? ParentId { get; set; }
        /// <summary>
        /// 关键字
        /// </summary>
        public string Keywords { get; set; }