using BaseService.BaseData.DataDictionaryManagement.Dto; using BaseService.Permissions; using Microsoft.AspNetCore.Authorization; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; namespace BaseService.BaseData.DataDictionaryManagement { [Authorize(BaseServicePermissions.DataDictionary.Default)] public class DictionaryAppService : ApplicationService, IDictionaryAppService { private readonly IRepository _repository; public DictionaryAppService(IRepository repository) { _repository = repository; } [Authorize(BaseServicePermissions.DataDictionary.Create)] public async Task Create(CreateOrUpdateDictionaryDto input) { var exist = await _repository.FirstOrDefaultAsync(_ => _.Name == input.Name); if (exist != null) { throw new BusinessException("名称:" + input.Name + "字典已存在"); } var dic = new DataDictionary( GuidGenerator.Create(), input.Name, input.Description); var result = await _repository.InsertAsync(dic); return ObjectMapper.Map(result); } [Authorize(BaseServicePermissions.DataDictionary.Delete)] public async Task Delete(List ids) { foreach (var id in ids) { await _repository.DeleteAsync(id); } } public async Task Get(Guid id) { var result = await _repository.GetAsync(id); return ObjectMapper.Map(result); } public async Task> GetAll(GetDictionaryInputDto input) { var query = (await _repository.GetQueryableAsync()) .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), _ => _.Name.Contains(input.Filter) || _.Description.Contains(input.Filter)); var items = await query.OrderBy(input.Sorting ?? "Name") .Skip(input.SkipCount) .Take(input.MaxResultCount) .ToListAsync(); var totalCount = await query.CountAsync(); var dots = ObjectMapper.Map, List>(items); return new PagedResultDto(totalCount, dots); } [Authorize(BaseServicePermissions.DataDictionary.Update)] public async Task Update(Guid id, CreateOrUpdateDictionaryDto input) { var dic = await _repository.GetAsync(id); dic.Name = input.Name; dic.Description = input.Description; return ObjectMapper.Map(dic); } } }