From 12a0812bcdac6d2ce84f94c5733490b3fb7df651 Mon Sep 17 00:00:00 2001 From: he <10978375@qq.com> Date: Tue, 17 May 2022 13:14:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TrialSiteUser/DTO/TrialSiteViewModel.cs | 2 +- .../Service/TrialSiteUser/TrialSiteService.cs | 8 +-- .../Common/AuditingData.cs | 72 ++++++++++++++++++- .../Context/IRaCISDBContext.cs | 2 + .../Repository/Repository.cs | 2 +- 5 files changed, 77 insertions(+), 9 deletions(-) diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialSiteViewModel.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialSiteViewModel.cs index 2fe3a9b7e..1148bd3ff 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialSiteViewModel.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialSiteViewModel.cs @@ -67,7 +67,7 @@ namespace IRaCIS.Core.Application.Contracts.DTO public Guid TrialId { get; set; } public Guid SiteId { get; set; } public Guid UserId { get; set; } - + public DateTime? CreateTime { get; set; } = DateTime.Now; public string UserRealName { get; set; } = String.Empty; } diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs index 6d5b24619..7d362bef5 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs @@ -288,9 +288,9 @@ namespace IRaCIS.Core.Application.Services { var addArray = _mapper.Map>(trialSiteCRCList); - await _repository.AddRangeAsync(addArray); + await _trialSiteUserRepository.AddRangeAsync(addArray); - return ResponseOutput.Result(await _repository.SaveChangesAsync()); + return ResponseOutput.Result(await _trialSiteUserRepository.SaveChangesAsync()); } /// 删除CRC人员 @@ -300,8 +300,8 @@ namespace IRaCIS.Core.Application.Services { - var isSuccess = await _trialSiteUserRepository.BatchUpdateNoTrackingAsync(u => u.Id == id, u => new TrialSiteUser() - { IsDeleted = isDelete, DeletedTime = isDelete ? DateTime.Now : null }); + var isSuccess = await _trialSiteUserRepository.UpdatePartialFromQueryAsync(id, u => new TrialSiteUser() + { IsDeleted = isDelete, DeletedTime = isDelete ? DateTime.Now : null },true); return ResponseOutput.Ok(isSuccess); } diff --git a/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs b/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs index a1f631afe..3125567d3 100644 --- a/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs +++ b/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs @@ -24,7 +24,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common { /// - /// 数据库对象 + /// 数据库对象o /// public IRaCISDBContext _dbContext { get; set; } @@ -79,8 +79,10 @@ namespace IRaCIS.Core.Infra.EFCore.Common { return new List() { - typeof(TrialUser) - }; + typeof(TrialUser), + typeof(TrialSiteUser), + typeof(TrialSite) + }; } } @@ -180,12 +182,71 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 项目中心 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialSite))) { + var entity = item.Entity as TrialSite; + if (entity.Site == null) + { + entity.Site =await _dbContext.Site.Where(x => x.Id == entity.SiteId).FirstOrDefaultAsync(); + } await InsertInspection(item, type, x => new DataInspection() { GeneralId = x.Id, + + },new + { + TrialSiteCode = entity.TrialSiteCode, + SiteName= entity.Site.SiteName, + SiteAliasName= entity.TrialSiteAliasName, + City= entity.Site.City, + Country= entity.Site.Country, + Status= entity.IsDeleted?"禁用":"启用", }); } + // 项目中心人员 + foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialSiteUser))) + { + var entity = item.Entity as TrialSiteUser; + if (entity.TrialSite == null) + { + entity.TrialSite= await _dbContext.TrialSite.Where(x => x.TrialId == entity.TrialId&&x.SiteId== entity.SiteId).FirstOrDefaultAsync(); + } + + if (entity.Site == null) + { + entity.Site = await _dbContext.Site.Where(x => x.Id == entity.SiteId).FirstOrDefaultAsync(); + } + + if (entity.User == null) + { + entity.User = await _dbContext.User.Where(x => x.Id == entity.UserId).FirstOrDefaultAsync(); + } + + if (entity.UserTypeRole == null) + { + entity.UserTypeRole = await _dbContext.UserType.Where(x => x.Id == entity.User.UserTypeId).FirstOrDefaultAsync(); + } + + await InsertInspection(item, type, x => new DataInspection() + { + GeneralId = x.Id, + + }, new + { + TrialSiteCode = entity.TrialSite.TrialSiteCode, + SiteName = entity.Site.SiteName, + SiteAliasName = entity.TrialSite.TrialSiteAliasName, + City = entity.Site.City, + Country = entity.Site.Country, + Status = entity.IsDeleted ? "禁用" : "启用", + UserName = entity.User.UserName, + UserRealName = entity.User.FullName, + UserType= entity.UserTypeRole.UserTypeShortName, + Phone= entity.User.Phone, + Email= entity.User.EMail, + Organization= entity.User.OrganizationName, + + }); + } // 项目人员 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialUser))) @@ -206,6 +267,11 @@ namespace IRaCIS.Core.Infra.EFCore.Common State=entity.IsDeleted?"退出":"加入", }); } + + + + + // 受试者 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(Subject))) { diff --git a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs index dbab9e024..8495a1034 100644 --- a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs +++ b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs @@ -234,6 +234,8 @@ namespace IRaCIS.Core.Infra.EFCore public virtual DbSet Site { get; set; } + public virtual DbSet User { get; set; } + public virtual DbSet TrialSiteUserSurvey { get; set; } public virtual DbSet TrialSiteEquipmentSurvey { get; set; } public virtual DbSet TrialSiteSurvey { get; set; } diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 6503421dd..b2bf0162b 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -244,7 +244,7 @@ namespace IRaCIS.Core.Infra.EFCore var query = ignoreQueryFilter ? _dbSet.AsNoTracking().IgnoreQueryFilters() : _dbSet.AsNoTracking(); //不跟踪 查询出来的实体就是Detached - var searchEntity = await query.FirstOrDefaultAsync(t => t.Id == id); + var searchEntity = await query.IgnoreQueryFilters().FirstOrDefaultAsync(t => t.Id == id); if (searchEntity == null) {