diff --git a/IRaCIS.Core.Application/Service/Doctor/AttachmentService.cs b/IRaCIS.Core.Application/Service/Doctor/AttachmentService.cs index 0655e322b..f227d8324 100644 --- a/IRaCIS.Core.Application/Service/Doctor/AttachmentService.cs +++ b/IRaCIS.Core.Application/Service/Doctor/AttachmentService.cs @@ -1,5 +1,7 @@ using IRaCIS.Application.Contracts; using IRaCIS.Application.Interfaces; +using IRaCIS.Core.Application.ViewModel; +using IRaCIS.Core.Infrastructure.Extention; using Microsoft.AspNetCore.Mvc; using Panda.DynamicWebApi.Attributes; @@ -9,7 +11,9 @@ namespace IRaCIS.Core.Application.Service /// 医生文档关联关系维护 /// [ApiExplorerSettings(GroupName = "Reviewer")] - public class AttachmentService(IRepository _attachmentrepository, IRepository _doctorrepository, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, IAttachmentService + public class AttachmentService(IRepository _attachmentrepository, + IRepository _enrollRepository, + IRepository _doctorrepository, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, IAttachmentService { @@ -90,7 +94,71 @@ namespace IRaCIS.Core.Application.Service } - //public async Task<> + /// + /// 获取项目医生附件 + /// + /// + /// + [HttpPost] + public async Task> GetTrialAttachments(GetTrialAttachmentsInDto inDto) + { + var doctorIds =await _enrollRepository.Where(x => x.TrialId == inDto.TrialId && x.EnrollStatus >= EnrollStatus.InviteIntoGroup).Select(x => x.DoctorId).ToListAsync(); + + var ids = doctorIds.Select(x=>(Guid?)x).ToList(); + + var attachmentList = await _attachmentrepository + .WhereIf(inDto.DoctorId!=null,x=>x.DoctorId==inDto.DoctorId) + .WhereIf(inDto.IsAuthorizedView != null, x => x.IsAuthorizedView == inDto.IsAuthorizedView) + .WhereIf(inDto.Type.IsNotNullOrEmpty(), x => x.Type == inDto.Type) + .WhereIf(inDto.FileName.IsNotNullOrEmpty(), x => inDto.FileName.Contains(x.FileName)) + + .Where(a => ids.Contains(a.DoctorId)||a.TrialId==inDto.TrialId ).ProjectTo(_mapper.ConfigurationProvider).ToPagedListAsync(inDto); + + + return attachmentList; + + } + + /// + /// 修改稽查状态 + /// + /// + /// + [HttpPost] + public async Task SetAuthorizedView(SetAttachmentAuthorizedView inDto) + { + await _attachmentrepository.UpdatePartialFromQueryAsync(x => x.Id == inDto.Id, x => new Attachment() { IsAuthorizedView = inDto.IsAuthorizedView }, true); + return ResponseOutput.Ok(); + } + + + /// + /// 上传项目医生 + /// + /// + /// + [HttpPost] + public async Task> SaveTrialAttachments(IEnumerable attachmentList) + { + foreach (var item in attachmentList) + { + if (item.DoctorId != null) + { + await _attachmentrepository.BatchDeleteNoTrackingAsync(a => a.DoctorId == item.DoctorId && a.Type == item.Type); + } + } + + var attachments = _mapper.Map>(attachmentList).ToList(); + var newAttachment = attachments.Where(t => t.Id == Guid.Empty); + await _attachmentrepository.AddRangeAsync(newAttachment); + await _attachmentrepository.SaveChangesAsync(); + + var list = _mapper.Map>(attachments).ToList(); + + list.ForEach(t => t.FullPath = t.Path + "?access_token=" + _userInfo.UserToken); + + return list; + } [NonDynamicMethod] diff --git a/IRaCIS.Core.Application/Service/Doctor/DTO/AttachmentModel.cs b/IRaCIS.Core.Application/Service/Doctor/DTO/AttachmentModel.cs index d9e6caae0..466dfaf6c 100644 --- a/IRaCIS.Core.Application/Service/Doctor/DTO/AttachmentModel.cs +++ b/IRaCIS.Core.Application/Service/Doctor/DTO/AttachmentModel.cs @@ -3,7 +3,7 @@ public class AttachmentDTO { public Guid Id { get; set; } - public Guid DoctorId { get; set; } + public Guid? DoctorId { get; set; } public bool IsOfficial { get; set; } public string Type { get; set; } = string.Empty; public string Path { get; set; } = string.Empty; @@ -13,8 +13,30 @@ public int Language { get; set; } public bool ReUpload { get; set; } = false; + + public Guid? TrialId { get; set; } } + public class SetAttachmentAuthorizedView + { + public Guid Id { get; set; } + + public bool IsAuthorizedView { get; set; } + } + + + public class GetTrialAttachmentsInDto:PageInput + { + public Guid TrialId { get; set; } + + public string? Type { get; set; } + + public Guid? DoctorId { get; set; } + + public string? FileName { get; set; } + + public bool? IsAuthorizedView { get; set; } + } public class ReviewerAckDTO { public Guid Id { get; set; } diff --git a/IRaCIS.Core.Domain/Dcotor/Attachment.cs b/IRaCIS.Core.Domain/Dcotor/Attachment.cs index eb79579a8..5c7613d17 100644 --- a/IRaCIS.Core.Domain/Dcotor/Attachment.cs +++ b/IRaCIS.Core.Domain/Dcotor/Attachment.cs @@ -12,7 +12,7 @@ public class Attachment : BaseAddAuditEntity [Comment("编码")] public string Code { get; set; } = null!; - public Guid DoctorId { get; set; } + public Guid? DoctorId { get; set; } [Comment("过期时间")] public DateTime? ExpiryDate { get; set; } @@ -30,4 +30,16 @@ public class Attachment : BaseAddAuditEntity [Comment("文件类型名")] public string Type { get; set; } = null!; + + /// + /// 项目Id + /// + public Guid? TrialId { get; set; } + + + /// + /// 是否授权 + /// + + public bool IsAuthorizedView { get; set; } = false; }