From b52e2de6e50acb20a45bc371b1b992829911e250 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Fri, 27 May 2022 13:11:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=AD=BE=E5=90=8D=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRaCIS.Core.API/Startup.cs | 2 + .../Authorization/JWTAuthSetup.cs | 102 ++++++++++-------- .../IRaCIS.Core.Application.xml | 7 -- .../Service/Document/TrialDocumentService.cs | 68 ++++-------- .../Service/QC/QCOperationService.cs | 36 +++++-- 5 files changed, 101 insertions(+), 114 deletions(-) diff --git a/IRaCIS.Core.API/Startup.cs b/IRaCIS.Core.API/Startup.cs index 44bf00bad..7c8db9ca1 100644 --- a/IRaCIS.Core.API/Startup.cs +++ b/IRaCIS.Core.API/Startup.cs @@ -20,6 +20,7 @@ using Localization; using Magicodes.ExporterAndImporter.Core.Filters; using IRaCIS.Core.Application.MediatR.CommandAndQueries; using IRaCIS.Core.Infra.EFCore.Common; +using Invio.Extensions.Authentication.JwtBearer; namespace IRaCIS.Core.API { @@ -198,6 +199,7 @@ namespace IRaCIS.Core.API app.UseRouting(); app.UseAuthentication(); + //app.UseJwtBearerQueryString(); app.UseAuthorization(); //文件伺服 必须带Token 访问 diff --git a/IRaCIS.Core.API/_ServiceExtensions/Authorization/JWTAuthSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/Authorization/JWTAuthSetup.cs index ff0a92b7e..29dec3bb8 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/Authorization/JWTAuthSetup.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/Authorization/JWTAuthSetup.cs @@ -20,72 +20,82 @@ namespace IRaCIS.Core.API configuration.Bind("JwtSetting", jwtSetting); services - .AddAuthentication(o=> { + .AddAuthentication(o => + { o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; o.DefaultChallengeScheme = nameof(ApiResponseHandler); o.DefaultForbidScheme = nameof(ApiResponseHandler); }) .AddJwtBearer(options => { - options.TokenValidationParameters = new TokenValidationParameters - { - ValidIssuer = jwtSetting.Issuer, - ValidAudience = jwtSetting.Audience, - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSetting.SecurityKey)), - // 榛樿 300s - ClockSkew = TimeSpan.Zero - }; + options.TokenValidationParameters = new TokenValidationParameters + { + ValidIssuer = jwtSetting.Issuer, + ValidAudience = jwtSetting.Audience, + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSetting.SecurityKey)), + // 榛樿 300s + ClockSkew = TimeSpan.Zero + }; - // OPTION 1: use `Invio.Extensions.Authentication.JwtBearer` + // OPTION 1: use `Invio.Extensions.Authentication.JwtBearer` - options.AddQueryStringAuthentication(); + options.AddQueryStringAuthentication(); - // OPTION 2: do it manually - #region - //options.Events = new JwtBearerEvents - //{ - // OnMessageReceived = (context) => { - // if (!context.Request.Query.TryGetValue("access_token", out StringValues values)) - // { - // return Task.CompletedTask; - // } + //).AddJwtBearerQueryStringAuthentication( + // (JwtBearerQueryStringOptions options) => + // { + // options.QueryStringParameterName = "access_token"; + // options.QueryStringBehavior = QueryStringBehaviors.Redact; + // }; - // if (values.Count > 1) - // { - // context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; - // context.Fail( - // "Only one 'access_token' query string parameter can be defined. " + - // $"However, {values.Count:N0} were included in the request." - // ); + // OPTION 2: do it manually - // return Task.CompletedTask; - // } + #region + //options.Events = new JwtBearerEvents + //{ + // OnMessageReceived = (context) => { - // var token = values.Single(); + // if (!context.Request.Query.TryGetValue("access_token", out StringValues values)) + // { + // return Task.CompletedTask; + // } - // if (String.IsNullOrWhiteSpace(token)) - // { - // context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; - // context.Fail( - // "The 'access_token' query string parameter was defined, " + - // "but a value to represent the token was not included." - // ); + // if (values.Count > 1) + // { + // context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; + // context.Fail( + // "Only one 'access_token' query string parameter can be defined. " + + // $"However, {values.Count:N0} were included in the request." + // ); - // return Task.CompletedTask; - // } + // return Task.CompletedTask; + // } - // context.Token = token; + // var token = values.Single(); - // return Task.CompletedTask; - // } - //}; - #endregion + // if (String.IsNullOrWhiteSpace(token)) + // { + // context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; + // context.Fail( + // "The 'access_token' query string parameter was defined, " + + // "but a value to represent the token was not included." + // ); - }) + // return Task.CompletedTask; + // } + + // context.Token = token; + + // return Task.CompletedTask; + // } + //}; + #endregion + + }) .AddScheme(nameof(ApiResponseHandler), o => { }); } - } +} } diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 2cd9f0c5a..1df0c3722 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -1179,13 +1179,6 @@ - - - 鑾峰彇鐢ㄦ埛鏄惁鏈夋枃妗f湭绛剧讲 - - - - 鑾峰彇纭鍒楄〃鎯呭喌 椤圭洰鏂囨。+绯荤粺鏂囨。+鍏蜂綋鐨勪汉 diff --git a/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs b/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs index 7f64e0776..0d087c261 100644 --- a/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Document/TrialDocumentService.cs @@ -197,56 +197,24 @@ namespace IRaCIS.Core.Application.Services .WhereIf(querySystemDocument.IsSign == true, t => t.ConfirmUserId != null) .WhereIf(querySystemDocument.IsSign == false, t => t.ConfirmUserId == null); - return await unionQuery.ToPagedListAsync(querySystemDocument.PageIndex, querySystemDocument.PageSize, querySystemDocument.SortField, querySystemDocument.Asc); + var result = await unionQuery.ToPagedListAsync(querySystemDocument.PageIndex, querySystemDocument.PageSize, querySystemDocument.SortField, querySystemDocument.Asc); + + var needSignTrialDocCount = await _trialDocumentRepository.AsQueryable(true) + .Where(t => t.Trial.TrialUserList.Any(t => t.UserId == _userInfo.Id)) + .Where(t => t.IsDeleted == false && !t.TrialDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id) && t.NeedConfirmedUserTypeList.Any(u => u.NeedConfirmUserTypeId == _userInfo.UserTypeId)) + .CountAsync(); + + + var needSignSystemDocCount = await _systemDocumentRepository + .Where(t => t.IsDeleted == false && !t.SystemDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id) && t.NeedConfirmedUserTypeList.Any(u => u.NeedConfirmUserTypeId == _userInfo.UserTypeId)) + .CountAsync(); + + result.OtherData = new { NeedSignCount= needSignTrialDocCount + needSignSystemDocCount , NeedSignTrialDocCount= needSignTrialDocCount, NeedSignSystemDocCount = needSignSystemDocCount } ; + + return result; } - /// - /// 鑾峰彇鐢ㄦ埛鏄惁鏈夋枃妗f湭绛剧讲 - /// - /// - /// - [HttpGet("{trialId:guid}")] - public async Task GetUserIsHaveDocumentNeedSign(Guid trialId) - { - var trialFininshedTime = await _repository.Where(t => t.Id == trialId).Select(t => t.TrialFinishedTime).FirstOrDefaultAsync(); - - //绯荤粺鏂囨。鏌ヨ - var systemDocumentQueryable = from needConfirmedUserType in _repository.Where(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId) - //.Where(u => u.UserTypeRole.UserList.SelectMany(cc => cc.UserTrials.Where(t => t.TrialId == querySystemDocument.TrialId)).Any(e => e.Trial.TrialFinishedTime < u.SystemDocument.CreateTime)) - .WhereIf(trialFininshedTime != null, u => u.SystemDocument.CreateTime < trialFininshedTime) - .WhereIf(!_userInfo.IsAdmin, t => t.SystemDocument.IsDeleted == false || (t.SystemDocument.IsDeleted == true && t.SystemDocument.SystemDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id))) - - join trialUser in _repository.Where(t => t.TrialId == trialId && t.UserId == _userInfo.Id) - on needConfirmedUserType.NeedConfirmUserTypeId equals trialUser.User.UserTypeId - join confirm in _repository.GetQueryable() on new { ConfirmUserId = trialUser.UserId, SystemDocumentId = needConfirmedUserType.SystemDocumentId } equals new { confirm.ConfirmUserId, confirm.SystemDocumentId } into cc - from confirm in cc.DefaultIfEmpty() - select new - { - //ConfirmUserId = confirm.ConfirmUserId, - ConfirmTime = confirm.ConfirmTime, - }; - - //椤圭洰鏂囨。鏌ヨ - var trialDocQueryable = from trialDoc in _trialDocumentRepository.Where(t => t.TrialId == trialId) - .WhereIf(!_userInfo.IsAdmin, t => t.NeedConfirmedUserTypeList.Any(t => t.NeedConfirmUserTypeId == _userInfo.UserTypeId)) - .WhereIf(!_userInfo.IsAdmin, t => t.IsDeleted == false || (t.IsDeleted == true && t.TrialDocConfirmedUserList.Any(t => t.ConfirmUserId == _userInfo.Id))) - - join trialUser in _repository.Where(t => t.TrialId == trialId && t.UserId == _userInfo.Id) on trialDoc.TrialId equals trialUser.TrialId - join confirm in _repository.Where(t => t.TrialDocument.TrialId == trialId) on - new { trialUser.UserId, TrialDocumentId = trialDoc.Id } equals new { UserId = confirm.ConfirmUserId, confirm.TrialDocumentId } into cc - from confirm in cc.DefaultIfEmpty() - select new - { - //ConfirmUserId = confirm.ConfirmUserId, - ConfirmTime = confirm.ConfirmTime, - }; - - var unionQuery = systemDocumentQueryable.Union(trialDocQueryable); - - return await unionQuery.AnyAsync(t => t.ConfirmTime == null); - } - /// @@ -533,7 +501,7 @@ namespace IRaCIS.Core.Application.Services /// public async Task UserConfirm(UserConfirmCommand userConfirmCommand) { - + if (userConfirmCommand.isSystemDoc) { if (await _repository.AnyAsync(t => t.SystemDocumentId == userConfirmCommand.DocumentId && t.ConfirmUserId == _userInfo.Id)) @@ -545,7 +513,7 @@ namespace IRaCIS.Core.Application.Services return ResponseOutput.NotOk("鏂囦欢宸插垹闄ゆ垨鑰呭簾闄,绛剧讲澶辫触锛"); } - await _systemDocConfirmedUserRepository.AddAsync(new SystemDocConfirmedUser() { ConfirmTime = DateTime.Now, ConfirmUserId = _userInfo.Id, IsDeleted=false, SystemDocumentId = userConfirmCommand.DocumentId },true); + await _systemDocConfirmedUserRepository.AddAsync(new SystemDocConfirmedUser() { ConfirmTime = DateTime.Now, ConfirmUserId = _userInfo.Id, IsDeleted = false, SystemDocumentId = userConfirmCommand.DocumentId }, true); } else { @@ -559,7 +527,7 @@ namespace IRaCIS.Core.Application.Services return ResponseOutput.NotOk("鏂囦欢宸插垹闄ゆ垨鑰呭簾闄,绛剧讲澶辫触锛"); } - await _trialDocUserTypeConfirmedUserRepository.AddAsync(new TrialDocUserTypeConfirmedUser() { ConfirmTime = DateTime.Now, ConfirmUserId = _userInfo.Id,IsDeleted=false, TrialDocumentId = userConfirmCommand.DocumentId },true); + await _trialDocUserTypeConfirmedUserRepository.AddAsync(new TrialDocUserTypeConfirmedUser() { ConfirmTime = DateTime.Now, ConfirmUserId = _userInfo.Id, IsDeleted = false, TrialDocumentId = userConfirmCommand.DocumentId }, true); } await _repository.SaveChangesAsync(); diff --git a/IRaCIS.Core.Application/Service/QC/QCOperationService.cs b/IRaCIS.Core.Application/Service/QC/QCOperationService.cs index 4eb6fef6a..19390e0cc 100644 --- a/IRaCIS.Core.Application/Service/QC/QCOperationService.cs +++ b/IRaCIS.Core.Application/Service/QC/QCOperationService.cs @@ -313,7 +313,7 @@ namespace IRaCIS.Core.Application.Image.QA var sv = (await _subjectVisitRepository.FirstOrDefaultAsync(t => t.Id == input.subjectVisitId)).IfNullThrowException(); - if ( sv.RequestBackState == RequestBackStateEnum.CRC_RequestBack) + if (sv.RequestBackState == RequestBackStateEnum.CRC_RequestBack) { ResponseOutput.NotOk("褰撳墠璁胯澶勪簬鐢宠鍥為鐘舵侊紝 涓嶅厑璁稿叧闂川鐤戙"); } @@ -341,7 +341,7 @@ namespace IRaCIS.Core.Application.Image.QA /// [HttpPut("{trialId:guid}")] [TypeFilter(typeof(TrialResourceFilter))] - [Authorize(Policy = IRaCISPolicy.PM_APM )] + [Authorize(Policy = IRaCISPolicy.PM_APM)] public async Task SetCheckPass(SetCheckPassDt data) { //if (_userInfo.UserTypeEnumInt != (int)UserTypeEnum.ProjectManager && _userInfo.UserTypeEnumInt != (int)UserTypeEnum.APM) @@ -407,7 +407,7 @@ namespace IRaCIS.Core.Application.Image.QA { sv.RequestBackState = RequestBackStateEnum.CRC_RequestBack; - await _subjectVisitRepository.SaveChangesAsync(); + await _subjectVisitRepository.SaveChangesAsync(); } else { @@ -1301,7 +1301,19 @@ namespace IRaCIS.Core.Application.Image.QA return ResponseOutput.NotOk("鏈夎瑙嗘湭涓婁紶浠讳綍Dicom/闈濪icom褰卞儚鏁版嵁锛屼笉鍏佽鎻愪氦"); } + //鍗曚釜鎻愪氦鎻愮ず淇℃伅 + if (dbSubjectVisitList.Count() == 1 && dbSubjectVisitList.First().SubmitState == SubmitStateEnum.Submitted) + { + return ResponseOutput.NotOk("褰撳墠璁胯鐨勫奖鍍忔暟鎹紝宸茬粡鐢卞叾浠朇RC鎻愪氦銆", 3, ApiResponseCodeEnum.NeedTips); + } + else if(dbSubjectVisitList.Any(t => t.SubmitState == SubmitStateEnum.Submitted)) + { + return ResponseOutput.NotOk("褰撳墠鎵归噺鎻愪氦璁胯鐨勫奖鍍忔暟鎹紝鍏朵腑閮ㄥ垎宸茬敱鍏朵粬CRC鎻愪氦銆", 3, ApiResponseCodeEnum.NeedTips); + } + + + // 鍒汉鏈彁浜ょ殑 foreach (var dbSubjectVisit in dbSubjectVisitList) { @@ -1369,10 +1381,6 @@ namespace IRaCIS.Core.Application.Image.QA dbSubjectVisit.SubmitTime = DateTime.Now; } - else - { - return ResponseOutput.NotOk("褰撳墠璁胯鐨勫奖鍍忔暟鎹紝宸茬粡鐢卞叾浠朇RC鎻愪氦銆",3,ApiResponseCodeEnum.NeedTips); - } //涓嶅 鐩存帴QC閫氳繃 鍙兘涓鑷存ф牳鏌 涔熷彲鑳戒笉涓鑷存ф牳鏌 if (trialConfig.QCProcessEnum == TrialQCProcess.NotAudit) { @@ -1394,12 +1402,18 @@ namespace IRaCIS.Core.Application.Image.QA } + } + var success = await _repository.SaveChangesAsync(); - return ResponseOutput.Result(success); + + + + + return ResponseOutput.Ok(success); @@ -1685,7 +1699,7 @@ namespace IRaCIS.Core.Application.Image.QA if (trialConfig.QCProcessEnum == TrialQCProcess.DoubleAudit && await _repository.AnyAsync(t => t.Id == qcChallengeId && t.SubjectVisit.AuditState == AuditStateEnum.InSecondaryQC)) { - + // //涓鑷存ф牳鏌ヨ川鐤戠姸鎬 // sv.CheckChallengeState = CheckChanllengeTypeEnum.None; @@ -1734,7 +1748,7 @@ namespace IRaCIS.Core.Application.Image.QA [Authorize(Policy = IRaCISPolicy.CRC)] public async Task SetReuploadFinished(CRCReuploadFinishedCommand cRCReuploadFinishedCommand) { - + var qcChallenge = (await _qcChallengeRepository.FirstOrDefaultAsync(t => t.Id == cRCReuploadFinishedCommand.QCChallengeId)).IfNullThrowException(); if (qcChallenge.ReuploadEnum != QCChanllengeReuploadEnum.QCAgreeUpload) @@ -1876,7 +1890,7 @@ namespace IRaCIS.Core.Application.Image.QA if (command.SubjectFirstGiveMedicineTime != null) { - await _subjectRepository.UpdatePartialFromQueryAsync(command.SubjectId, u => new Subject() { FirstGiveMedicineTime = command.SubjectFirstGiveMedicineTime, },true); + await _subjectRepository.UpdatePartialFromQueryAsync(command.SubjectId, u => new Subject() { FirstGiveMedicineTime = command.SubjectFirstGiveMedicineTime, }, true); } await _subjectVisitRepository.SaveChangesAsync();