using Admin.Core.Common.Input; using Admin.Core.Common.Output; using Admin.Core.Model.Personnel; using Admin.Core.Repository.Personnel; using Admin.Core.Service.Personnel.Organization.Input; using Admin.Core.Service.Personnel.Organization.Output; using System.Threading.Tasks; namespace Admin.Core.Service.Personnel.Organization { public class OrganizationService : BaseService, IOrganizationService { private readonly IOrganizationRepository _organizationRepository; public OrganizationService(IOrganizationRepository organizationRepository) { _organizationRepository = organizationRepository; } public async Task GetAsync(long id) { var result = await _organizationRepository.GetAsync(id); return ResponseOutput.Ok(result); } public async Task PageAsync(PageInput input) { var key = input.Filter?.Name; var list = await _organizationRepository.Select .WhereIf(key.NotNull(), a => a.Name.Contains(key) || a.Code.Contains(key)) .Count(out var total) .OrderByDescending(true, c => c.Id) .Page(input.CurrentPage, input.PageSize) .ToListAsync(); var data = new PageOutput() { List = list, Total = total }; return ResponseOutput.Ok(data); } public async Task AddAsync(OrganizationAddInput input) { var dictionary = Mapper.Map(input); var id = (await _organizationRepository.InsertAsync(dictionary)).Id; return ResponseOutput.Result(id > 0); } public async Task UpdateAsync(OrganizationUpdateInput input) { if (!(input?.Id > 0)) { return ResponseOutput.NotOk(); } var entity = await _organizationRepository.GetAsync(input.Id); if (!(entity?.Id > 0)) { return ResponseOutput.NotOk("数据字典不存在!"); } Mapper.Map(input, entity); await _organizationRepository.UpdateAsync(entity); return ResponseOutput.Ok(); } public async Task DeleteAsync(long id) { var result = false; if (id > 0) { result = (await _organizationRepository.DeleteAsync(m => m.Id == id)) > 0; } return ResponseOutput.Result(result); } public async Task SoftDeleteAsync(long id) { var result = await _organizationRepository.SoftDeleteAsync(id); return ResponseOutput.Result(result); } } }