| | |
| | | using FlexJobApi.Core; |
| | | using Furion.DatabaseAccessor; |
| | | using Furion.FriendlyException; |
| | | using Mapster; |
| | | using MediatR; |
| | | using Microsoft.EntityFrameworkCore; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | |
| | | /// <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>( |
| | | 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 |
| | | && 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}/", |
| | |
| | | { |
| | | 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; |
| | | } |
| | | } |
| | | } |