using IRaCIS.Application.Contracts; using IRaCIS.Application.Interfaces; using IRaCIS.Core.Domain.Share; using Microsoft.AspNetCore.Mvc; namespace IRaCIS.Core.Application.Service { [ApiExplorerSettings(GroupName = "Reviewer")] public class EducationService(IRepository _postgraduateRepository, IRepository _hospitalRepository, IRepository _educationRepository, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, IEducationService { /// /// 根据医生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, new { isEn_Us = _userInfo.IsEn_Us }).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.ReviewerDegree.Bachelor: doctorEducationInfo.ShowOrder = 1; break; case StaticData.ReviewerDegree.Master: doctorEducationInfo.ShowOrder = 2; break; case StaticData.ReviewerDegree.Doctorate: doctorEducationInfo.ShowOrder = 3; break; } await _educationRepository.AddAsync(doctorEducationInfo); var success = await _educationRepository.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 _educationRepository.SaveChangesAsync(); return ResponseOutput.Ok(success); } //_educationRepository.Update(needUpdate); } [HttpDelete, Route("{id:guid}")] public async Task DeleteEducationInfo(Guid id) { var success = await _educationRepository.BatchDeleteNoTrackingAsync(o => o.Id == id); return ResponseOutput.Result(success); } /// 添加/更新医生继续学习经历 [HttpPost] public async Task AddOrUpdatePostgraduateInfo(PostgraduateCommand inDto) { #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 _postgraduateRepository.InsertOrUpdateAsync(inDto, true); return ResponseOutput.Ok(entity.Id); } /// /// 删除医生继续学习经历 /// /// 医生Id /// [HttpDelete("{doctorId:guid}")] public async Task DeletePostgraduateInfo(Guid doctorId) { var success = await _postgraduateRepository.BatchDeleteNoTrackingAsync(o => o.Id == doctorId); return ResponseOutput.Result(success); } } }