using IRaCIS.Application.Interfaces; using IRaCIS.Application.Contracts; using IRaCIS.Core.Infra.EFCore; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Application.Filter; using IRaCIS.Core.Infrastructure.Extention; using Microsoft.AspNetCore.Mvc; namespace IRaCIS.Application.Services { [ApiExplorerSettings(GroupName = "Reviewer")] public class EducationService : BaseService, IEducationService { private readonly IRepository _postgraduateRepository; private readonly IRepository _educationRepository; public EducationService(IRepository doctorNormalEducationRepository, IRepository doctorContinueLearningRepository) { _educationRepository = doctorNormalEducationRepository; _postgraduateRepository = doctorContinueLearningRepository; } /// /// 根据医生Id获取医生教育经历和继续学习经历列表 /// [HttpGet("{doctorId:Guid}")] public async Task GetEducation(Guid doctorId) { var educationList = await _educationRepository.Where(o => o.DoctorId == doctorId) .OrderBy(t => t.CreateTime).ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); var postgraduateList = await _postgraduateRepository.Where(o => o.DoctorId == doctorId) .OrderBy(t => t.CreateTime).ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); return new DoctorEducationExperienceDTO() { EducationList = educationList, PostgraduateList = postgraduateList }; } /// /// 新增医生教育经历 /// /// /// [HttpPost] public async Task AddOrUpdateEducationInfo(EducationCommand educationInfoViewModel) { if (educationInfoViewModel.Id == Guid.Empty || educationInfoViewModel.Id == null) { var doctorEducationInfo = _mapper.Map(educationInfoViewModel); switch (educationInfoViewModel.Degree) { case StaticData.Bachelor: doctorEducationInfo.ShowOrder = 1; break; case StaticData.Master: doctorEducationInfo.ShowOrder = 2; break; case StaticData.Doctorate: doctorEducationInfo.ShowOrder = 3; break; } await _educationRepository.AddAsync(doctorEducationInfo); var success = await _repository.SaveChangesAsync(); return ResponseOutput.Result(success, doctorEducationInfo.Id.ToString()); } else { var needUpdate = await _educationRepository.FirstOrDefaultAsync(t => t.Id == educationInfoViewModel.Id); if (needUpdate == null) return Null404NotFound(needUpdate); _mapper.Map(educationInfoViewModel, needUpdate); var success = await _repository.SaveChangesAsync(); return ResponseOutput.Ok(success); } //_educationRepository.Update(needUpdate); } [HttpDelete, Route("{doctorId:guid}")] public async Task DeleteEducationInfo(Guid id) { var success = await _educationRepository.BatchDeleteAsync(o => o.Id == id); return ResponseOutput.Result(success); } /// 添加/更新医生继续学习经历 [HttpPost] public async Task AddOrUpdatePostgraduateInfo(PostgraduateCommand postgraduateViewModel) { #region 封装前 //if (postgraduateViewModel.Id == Guid.Empty || postgraduateViewModel.Id == null) //{ // var doctorContinueLearning = _mapper.Map(postgraduateViewModel); // _postgraduateRepository.Add(doctorContinueLearning); // var success = _postgraduateRepository.SaveChanges(); // return ResponseOutput.Result(success, doctorContinueLearning.Id.ToString()); //} //else //{ // _postgraduateRepository.Update(_mapper.Map(postgraduateViewModel)); // var success = _postgraduateRepository.SaveChanges(); // return ResponseOutput.Result(success); //} #endregion var entity = await _repository.InsertOrUpdateAsync(postgraduateViewModel, true); return ResponseOutput.Ok(entity.Id); } /// /// 删除医生继续学习经历 /// /// 医生Id /// [HttpDelete("{doctorId:guid}")] public async Task DeletePostgraduateInfo(Guid doctorId) { var success = await _repository.BatchDeleteAsync(o => o.Id == doctorId); return ResponseOutput.Result(success); } } }