using AutoMapper.Internal.Mappers; using Microsoft.AspNetCore.Mvc; using Shentun.Peis.Patients; using Shentun.Peis.HelperDto; using Shentun.Peis.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; using Volo.Abp.Identity; using Shentun.Peis.PatientRegisters; using Microsoft.AspNetCore.Authorization; using Volo.Abp; using Microsoft.EntityFrameworkCore; using NUglify.Helpers; using Volo.Abp.ObjectMapping; namespace Shentun.Peis.Patients { /// /// 体检人员 /// [ApiExplorerSettings(GroupName = "Work")] [Authorize] public class PatientAppService : CrudAppService< Patient, //The Book entity PatientDto, //Used to show books Guid, //Primary key of the book entity PagedAndSortedResultRequestDto, //Used for paging/sorting CreatePatientDto, UpdatePatientDto> { private readonly IRepository _userRepository; private readonly PatientRegisterManager _patientRegisterManager; private readonly PatientManager _manager; private readonly CacheService _cacheService; public PatientAppService( IRepository repository, IRepository userRepository, PatientRegisterManager patientRegisterManager, PatientManager manager, CacheService cacheService) : base(repository) { _userRepository = userRepository; this._patientRegisterManager = patientRegisterManager; _manager = manager; _cacheService = cacheService; } /// /// 获取通过主键 /// /// /// public override async Task GetAsync(Guid id) { return await base.GetAsync(id); } /// /// 获取列表 体检人员 /// /// /// [RemoteService(false)] public override async Task> GetListAsync(PagedAndSortedResultRequestDto input) { return await base.GetListAsync(input); } /// /// 获取列表 体检人员 可以带名字或者身份证号码搜索 /// /// /// [HttpPost("api/app/patient/getlistinfilter")] public async Task> GetListInFilterAsync(GetListInFilterDto input) { var entlist = await Repository.GetQueryableAsync(); if (!string.IsNullOrEmpty(input.Filter)) { entlist = entlist.Where(m => m.DisplayName == input.Filter || m.IdNo == input.Filter); } var entdto = entlist.Select(s => new PatientOrMedicalTimesDto { CreationTime = s.CreationTime, CreatorId = s.CreatorId, DisplayName = s.DisplayName, Id = s.Id, LastModificationTime = s.LastModificationTime, LastModifierId = s.LastModifierId, MaritalStatusId = s.MaritalStatusId, Telephone = s.Telephone, SexId = s.SexId, PostalCode = s.PostalCode, Address = s.Address, BirthDate = DataHelper.ConversionDateToString(s.BirthDate), BirthPlaceId = s.BirthPlaceId, Email = s.Email, IdNo = s.IdNo, MobileTelephone = s.MobileTelephone, NationId = s.NationId, PatientNo = s.PatientNo, MedicalTimes = _patientRegisterManager.GetPatientCountNoAsync(s.Id), LastTime = _patientRegisterManager.GetPatientRegisterLastTime(s.Id), CreatorName = _cacheService.GetSurnameAsync(s.CreatorId).Result, LastModifierName = _cacheService.GetSurnameAsync(s.LastModifierId).Result }).OrderBy(m => m.Id).ToList(); return entdto; } /// /// 通过身份证号获取人员信息 /// /// /// [HttpPost("api/app/patient/GetByIdNo")] public async Task GetByIdNo(IdNoInputDto idNoInputDto) { if (string.IsNullOrWhiteSpace(idNoInputDto.IdNo)) { throw new UserFriendlyException("身份证号不能为空"); } var entitys = await Repository.GetListAsync(o => o.IdNo == idNoInputDto.IdNo.Trim()); if (entitys == null || !entitys.Any()) { return null; } var dto = ObjectMapper.Map(entitys.Last()); return dto; } /// /// 创建 /// /// /// public override async Task CreateAsync(CreatePatientDto input) { var createEntity = ObjectMapper.Map(input); var entity = await _manager.CreateAsync(createEntity); entity = await Repository.InsertAsync(entity); var dto = ObjectMapper.Map(entity); return dto; } /// /// 更新 /// /// /// /// public override async Task UpdateAsync(Guid id, UpdatePatientDto input) { var entity = await Repository.GetAsync(id); var sourceEntity = ObjectMapper.Map(input); await _manager.UpdateAsync(sourceEntity, entity); entity = await Repository.UpdateAsync(entity); return ObjectMapper.Map(entity); } /// /// 删除 /// /// /// public override async Task DeleteAsync(Guid id) { await _manager.CheckAndDeleteAsync(id); } } }