|
|
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{
/// <summary>
/// 体检人员
/// </summary>
[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<IdentityUser, Guid> _userRepository; private readonly PatientRegisterManager _patientRegisterManager; private readonly PatientManager _manager; private readonly CacheService _cacheService; public PatientAppService( IRepository<Patient, Guid> repository, IRepository<IdentityUser, Guid> userRepository, PatientRegisterManager patientRegisterManager, PatientManager manager, CacheService cacheService) : base(repository) { _userRepository = userRepository; this._patientRegisterManager = patientRegisterManager; _manager = manager; _cacheService = cacheService; } /// <summary>
/// 获取通过主键
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public override async Task<PatientDto> GetAsync(Guid id) { return await base.GetAsync(id); } /// <summary>
/// 获取列表 体检人员
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[RemoteService(false)] public override async Task<PagedResultDto<PatientDto>> GetListAsync(PagedAndSortedResultRequestDto input) { return await base.GetListAsync(input); }
/// <summary>
/// 获取列表 体检人员 可以带名字或者身份证号码搜索
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/patient/getlistinfilter")] public async Task<List<PatientOrMedicalTimesDto>> 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;
} /// <summary>
/// 通过身份证号获取人员信息
/// </summary>
/// <param name="idNoInputDto"></param>
/// <returns></returns>
[HttpPost("api/app/patient/GetByIdNo")] public async Task<PatientDto> 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<Patient, PatientDto>(entitys.Last()); return dto;
} /// <summary>
/// 创建
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<PatientDto> CreateAsync(CreatePatientDto input) { var createEntity = ObjectMapper.Map<CreatePatientDto, Patient>(input); var entity = await _manager.CreateAsync(createEntity);
entity = await Repository.InsertAsync(entity); var dto = ObjectMapper.Map<Patient, PatientDto>(entity); return dto; }
/// <summary>
/// 更新
/// </summary>
/// <param name="id"></param>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<PatientDto> UpdateAsync(Guid id, UpdatePatientDto input) { var entity = await Repository.GetAsync(id); var sourceEntity = ObjectMapper.Map<UpdatePatientDto, Patient>(input); await _manager.UpdateAsync(sourceEntity, entity); entity = await Repository.UpdateAsync(entity); return ObjectMapper.Map<Patient, PatientDto>(entity); } /// <summary>
/// 删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public override async Task DeleteAsync(Guid id) { await _manager.CheckAndDeleteAsync(id); }
}}
|