From 59e73ad4283491cd407854874879e0ddc8dafaba Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期四, 07 八月 2025 14:08:20 +0800 Subject: [PATCH] feat:地区字典 --- FlexJobApi.Application/Dictionaries/Commands/DictionaryDataCommandHandler.cs | 63 +++++++++++++++++++++++++++---- 1 files changed, 55 insertions(+), 8 deletions(-) diff --git a/FlexJobApi.Application/Dictionaries/Commands/DictionaryDataCommandHandler.cs b/FlexJobApi.Application/Dictionaries/Commands/DictionaryDataCommandHandler.cs index a480570..7df5b54 100644 --- a/FlexJobApi.Application/Dictionaries/Commands/DictionaryDataCommandHandler.cs +++ b/FlexJobApi.Application/Dictionaries/Commands/DictionaryDataCommandHandler.cs @@ -1,7 +1,12 @@ 锘縰sing FlexJobApi.Core; +using Furion.DatabaseAccessor; +using Furion.FriendlyException; +using Mapster; using MediatR; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,25 +16,57 @@ /// <summary> /// 鏁版嵁瀛楀吀鍛戒护澶勭悊鍣� /// </summary> - public class DictionaryDataCommandHandler : + public class DictionaryDataCommandHandler( + IRepository<DictionaryData> rep, + IRepository<DictionaryCategory> repDictionaryCategory + ) : IRequestHandler<SaveDictionaryDataCommand, Guid>, - IRequestHandler<SetDictionaryDataIsDisabledCommand, int> + IRequestHandler<SetDictionaryDataIsDisabledCommand, int>, + IRequestHandler<SyncHumanResourcesAreaDictionaryDataCommand, int> { + private readonly IRepository<DictionaryData> rep = rep; + private readonly IRepository<DictionaryCategory> repDictionaryCategory = repDictionaryCategory; + /// <summary> /// 淇濆瓨鏁版嵁瀛楀吀 /// </summary> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> - public Task<Guid> Handle(SaveDictionaryDataCommand request, CancellationToken cancellationToken) + public async Task<Guid> Handle(SaveDictionaryDataCommand request, CancellationToken cancellationToken) { - return request.SaveData<DictionaryData, SaveDictionaryDataCommand>( - (q, e, r) => q.Any(it => + var category = await repDictionaryCategory + .Where(it => it.Id == request.CategoryId || it.Code == request.CategoryCode) + .Select(it => new + { + it.Id, + it.Code + }) + .FirstOrDefaultAsync(); + if (category == null) throw Oops.Oh(EnumErrorCodeType.s404, "鏁版嵁瀛楀吀绫诲埆"); + request.CategoryId = category.Id; + if (!request.Code.StartsWith($"{category.Code}-")) throw Oops.Oh(EnumErrorCodeType.s400, "缂栧彿寮�澶撮渶瑕佸寘鍚被鍒紪鍙�-"); + return await request.SaveData<DictionaryData, SaveDictionaryDataCommand>( + null, + it => it.CategoryId == request.CategoryId - && it.ParentId == request.ParentId && it.Code == request.Code - && it.Content == request.Content), cancellationToken); + && it.Id != request.Id, + (entity) => + { + entity.Path = DbUtils.GetTreeDataPath<DictionaryData>(request.ParentId, cancellationToken).Result; + if (request.Id.HasValue) + { + if (entity.Code != request.Code) throw Oops.Oh(EnumErrorCodeType.s400, "缂栧彿涓嶅彲淇敼"); + DbUtils.UpdateTreeDataChildrenPath<DictionaryData>( + $"{entity.Path}/{entity.Code}/", + $"{entity.Path}/{request.Code}/", + cancellationToken).Wait(); + } + request.Adapt(entity); + }, + cancellationToken); } /// <summary> @@ -40,7 +77,17 @@ /// <returns></returns> public Task<int> Handle(SetDictionaryDataIsDisabledCommand request, CancellationToken cancellationToken) { - return request.SetIsDisable<DictionaryData>(cancellationToken: cancellationToken); + return request.SetIsDisabled<DictionaryData>(cancellationToken: cancellationToken); + } + + public async Task<int> Handle(SyncHumanResourcesAreaDictionaryDataCommand request, CancellationToken cancellationToken) + { + var rep = Db.GetRepository<BaseArea, HumanResourcesDbContextLocator>(); + var areas = await rep.AsQueryable().AsNoTracking() + .Take(10) + .ToListAsync(); + Console.WriteLine(); + return 1; } } } -- Gitblit v1.9.1