diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index b60b2e42d..8677beb20 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -477,7 +477,6 @@ namespace IRaCIS.Application.Services return await userQueryable.ToPagedListAsync(param.PageIndex, param.PageSize, param.SortField == string.Empty ? "UserName" : param.SortField, param.Asc); - } /// diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/PersonalWorkstation.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/PersonalWorkstation.cs index d96ae367b..7b9bae7d9 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/PersonalWorkstation.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/PersonalWorkstation.cs @@ -192,8 +192,8 @@ namespace IRaCIS.Core.Application ToBeCheckedCount = t.SubjectVisitList.Where(u => u.CheckState == CheckStateEnum.ToCheck).Count(), - ToBeRepliedCount = t.SubjectVisitList.Where(u => u.CheckState == CheckStateEnum.ToCheck && - u.CheckChallengeDialogList.Any(t => t.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator)).Count(), + ToBeRepliedCount = t.SubjectVisitList.Where(u => u.CheckState == CheckStateEnum.CVIng && + u.CheckChallengeDialogList.OrderByDescending(t=>t.CreateTime).First().UserTypeEnum== UserTypeEnum.ClinicalResearchCoordinator).Count(), }); @@ -204,8 +204,8 @@ namespace IRaCIS.Core.Application .Where(u => u.CheckState == CheckStateEnum.ToCheck).CountAsync(); var totalToBeRepliedCount = await _subjectVisitRepository.Where(t => t.Trial.TrialUserList.Any(t => t.UserId == _userInfo.Id)) - .Where(u => u.CheckState == CheckStateEnum.ToCheck && - u.CheckChallengeDialogList.Any(t => t.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator)).CountAsync(); + .Where(u => u.CheckState == CheckStateEnum.CVIng && + u.CheckChallengeDialogList.OrderByDescending(t => t.CreateTime).First().UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator).CountAsync(); return ResponseOutput.Ok(result, new { TotalToBeCheckedCount = totalToBeCheckedCount, TotalToBeRepliedCount = totalToBeRepliedCount }); @@ -892,7 +892,7 @@ namespace IRaCIS.Core.Application [FromServices] IRepository _taskMedicalReviewRepository) { - var isPM = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager; + var isPM = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager|| _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM; var isCRC = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.ClinicalResearchCoordinator; var isIQC = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.IQC; var isMIM = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.MIM; @@ -917,9 +917,13 @@ namespace IRaCIS.Core.Application TrialStatusStr=t.TrialStatusStr, ExpetiedTaskCount= isPM ? t.VisitTaskList.Where(t=>t.IsUrgent).Count():0, + ReReadingApprovalCount= isPM? t.VisitTaskReReadingList.Where(t=>t.OriginalReReadingTask.ReReadingApplyState==ReReadingApplyState.DocotorHaveApplyed).Count():0, + PendingReconciliationCount=isPM? t.SubjectVisitList.Where(t=>t.CheckState==CheckStateEnum.ToCheck).Count():0, - + + PendingResponseCount=isPM? t.SubjectVisitList.Where(u => u.CheckState == CheckStateEnum.CVIng && + u.CheckChallengeDialogList.OrderByDescending(t => t.CreateTime).First().UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator).Count() : 0 @@ -934,6 +938,9 @@ namespace IRaCIS.Core.Application return ResponseOutput.Ok(result, new { TotalToBeReUploadCount = 0 }); } + + + #endregion } } diff --git a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs index d2328cc9b..b9fa19854 100644 --- a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs +++ b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs @@ -17,28 +17,32 @@ using Microsoft.EntityFrameworkCore.ValueGeneration; using UserTypeGroup = IRaCIS.Core.Domain.Models.UserTypeGroup; using IRaCIS.Core.Infra.EFCore.Common; using IRaCIS.Core.Infra.EFCore.Common.Dto; +using Microsoft.Identity.Client; +using EntityFramework.Exceptions.Common; +using System.Data; +using IRaCIS.Core.Infrastructure; namespace IRaCIS.Core.Infra.EFCore { public class IRaCISDBContext : DbContext { public readonly IUserInfo _userInfo; - //private readonly IAuditingData _auditingData; + public readonly ILogger _logger; // 在控制台 //public static readonly ILoggerFactory MyLoggerFactory = LoggerFactory.Create(builder => { builder.AddConsole(); }); // 调试窗口 public static readonly ILoggerFactory MyLoggerFactory = LoggerFactory.Create(builder => { builder.AddDebug(); }); - public IRaCISDBContext(DbContextOptions options, IUserInfo userInfo + public IRaCISDBContext(DbContextOptions options, IUserInfo userInfo, ILogger logger - //IAuditingData auditingData + //IAuditingData auditingData ) : base(options) { + _logger= logger; _userInfo = userInfo; - //this._auditingData = auditingData; - //_configuration = configuration; + } @@ -496,12 +500,69 @@ namespace IRaCIS.Core.Infra.EFCore return base.SaveChanges(); } + + #endregion + public override async Task SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken()) { // 采用触发器的方式 设置 CreateUserId CreateTime UpdateTime UpdateUserId 稽查实体里面没有这四个字段的值 因为先后顺序的原因 SetCommonEntityAuditInfo(); await AddAudit(); - return await base.SaveChangesAsync(cancellationToken); + + try + { + return await base.SaveChangesAsync(cancellationToken); + + } + catch (UniqueConstraintException ex) + { + _logger.LogError(ex.Message); + + throw new DBSaveFailedException("该唯一键已经存在于数据库中。"); + + } + catch (TimeoutException ex) + { + _logger.LogError(ex.Message); + + throw new DBSaveFailedException("数据库操作已经超时,请稍后重试。"); + + } + catch (CannotInsertNullException ex) + { + _logger.LogError(ex.Message); + + throw new DBSaveFailedException("无法在非空列上插入空值。"); + } + catch (MaxLengthExceededException ex) + { + _logger.LogError(ex.Message); + + throw new DBSaveFailedException("字符串超过了数据库列的最大长度。"); + } + catch (NumericOverflowException ex) + { + _logger.LogError(ex.Message); + + throw new DBSaveFailedException("数值超过了数据类型的范围。"); + } + catch (SyntaxErrorException ex) + { + _logger.LogError(ex.Message); + + throw new DBSaveFailedException("SQL 查询中存在语法错误。"); + } + catch (ReferenceConstraintException ex) + { + _logger.LogError(ex.Message); + throw new DBSaveFailedException("无法进行当前操作,当前数据不符合外键约束。"); + } + catch (DbUpdateConcurrencyException ex) + { + _logger.LogError(ex.Message); + + throw new DBSaveFailedException("SQL 事务失败,请检查环境。"); + } } @@ -670,7 +731,6 @@ namespace IRaCIS.Core.Infra.EFCore #endregion - #endregion public virtual DbSet TaskAllocationRule { get; set; } diff --git a/IRaCIS.Core.Infrastructure/_IRaCIS/Exception/CustomException.cs b/IRaCIS.Core.Infrastructure/_IRaCIS/Exception/BusinessValidationFailedException.cs similarity index 100% rename from IRaCIS.Core.Infrastructure/_IRaCIS/Exception/CustomException.cs rename to IRaCIS.Core.Infrastructure/_IRaCIS/Exception/BusinessValidationFailedException.cs diff --git a/IRaCIS.Core.Infrastructure/_IRaCIS/Exception/DBSaveFailedException.cs b/IRaCIS.Core.Infrastructure/_IRaCIS/Exception/DBSaveFailedException.cs new file mode 100644 index 000000000..2efed71b4 --- /dev/null +++ b/IRaCIS.Core.Infrastructure/_IRaCIS/Exception/DBSaveFailedException.cs @@ -0,0 +1,21 @@ +using System; + + +namespace IRaCIS.Core.Infrastructure + +{ + + + public class DBSaveFailedException : Exception + { + + public DBSaveFailedException() + { + + } + + public DBSaveFailedException(string message) : base(message) + { + } + } +}