From e395e105cb4965bebf7b96b4b50be290a532907c Mon Sep 17 00:00:00 2001 From: he <10978375@qq.com> Date: Tue, 26 Apr 2022 15:28:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9Dicom=E5=BD=B1=E5=83=8F?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/StudyController.cs | 75 +++++++++-------- .../Service/ImageAndDoc/StudyService.cs | 18 +---- IRaCIS.Core.Infra.EFCore/Common/EFSqlQuery.cs | 80 +++++++++++++++++++ .../Repository/Repository.cs | 64 +++++++++++++++ 4 files changed, 187 insertions(+), 50 deletions(-) create mode 100644 IRaCIS.Core.Infra.EFCore/Common/EFSqlQuery.cs diff --git a/IRaCIS.Core.API/Controllers/StudyController.cs b/IRaCIS.Core.API/Controllers/StudyController.cs index 225648667..abe758c64 100644 --- a/IRaCIS.Core.API/Controllers/StudyController.cs +++ b/IRaCIS.Core.API/Controllers/StudyController.cs @@ -188,46 +188,55 @@ namespace IRaCIS.Api.Controllers section = await reader.ReadNextSectionAsync(); } - if (archivedStudyIds.Count > 0) // 上传成功,处理逻辑 + try { - - - // 同一个访视 多个线程上传处理 批量保存 可能造成死锁 https://www.cnblogs.com/johnblogs/p/9945767.html - - await _dicomArchiveService.DicomDBDataSaveChange(); - - //sw.Stop(); - _studyService.UploadOrReUploadNeedTodo(archiveStudyCommand, archivedStudyIds, ref archiveResult, new StudyMonitor() + if (archivedStudyIds.Count > 0) // 上传成功,处理逻辑 { - TrialId = savedInfo.TrialId, - SiteId = savedInfo.SiteId, - SubjectId = savedInfo.SubjectId, - SubjectVisitId = savedInfo.SubjectVisitId, - StudyId = archivedStudyIds[0], - UploadStartTime = startTime, - UploadFinishedTime = DateTime.Now, - //TotalMillisecondsInterval = (DateTime.Now- startTime).TotalMilliseconds, - FileSize = (decimal)HttpContext.Request.ContentLength, - FileCount = archiveResult.ReceivedFileCount, - IsDicom = true, - IsDicomReUpload = archiveStudyCommand.AbandonStudyId!=null, - IP =_userInfo.IP - }); - _provider.Remove("StudyUid_" + archiveStudyCommand.StudyInstanceUid); + // 同一个访视 多个线程上传处理 批量保存 可能造成死锁 https://www.cnblogs.com/johnblogs/p/9945767.html + + await _dicomArchiveService.DicomDBDataSaveChange(); + + //sw.Stop(); + _studyService.UploadOrReUploadNeedTodo(archiveStudyCommand, archivedStudyIds, ref archiveResult, new StudyMonitor() + { + TrialId = savedInfo.TrialId, + SiteId = savedInfo.SiteId, + SubjectId = savedInfo.SubjectId, + SubjectVisitId = savedInfo.SubjectVisitId, + StudyId = archivedStudyIds[0], + UploadStartTime = startTime, + UploadFinishedTime = DateTime.Now, + //TotalMillisecondsInterval = (DateTime.Now- startTime).TotalMilliseconds, + FileSize = (decimal)HttpContext.Request.ContentLength, + FileCount = archiveResult.ReceivedFileCount, + IsDicom = true, + IsDicomReUpload = archiveStudyCommand.AbandonStudyId != null, + IP = _userInfo.IP + }); + + _provider.Remove("StudyUid_" + archiveStudyCommand.StudyInstanceUid); + + } + else + { + return ResponseOutput.NotOk("未完成该检查的归档", archiveResult); + } + + + data.GeneralId = archivedStudyIds[0]; + Dictionary keyValuePairs = new Dictionary(); + keyValuePairs.Add("StyudCode", studycode); + data.JsonDetail = _inspectionService.AddJsonItem(data.JsonDetail, keyValuePairs); + await _inspectionService.AddInspectionRecordAsync(data); } - else + catch (Exception) { - return ResponseOutput.NotOk("未完成该检查的归档", archiveResult); + + section = await reader.ReadNextSectionAsync(); } - - - data.GeneralId = archivedStudyIds[0]; - Dictionary keyValuePairs = new Dictionary(); - keyValuePairs.Add("StyudCode", studycode); - data.JsonDetail = _inspectionService.AddJsonItem(data.JsonDetail, keyValuePairs); - await _inspectionService.AddInspectionRecordAsync(data); + diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs index e29b54bf8..312acfa3d 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs @@ -152,23 +152,7 @@ namespace IRaCIS.Application.Services _ = _dicomStudyMonitorRepository.AddAsync(monitor).Result; _ = _studyRepository.SaveChangesAsync().Result; - // 这里上传dicom影像之后修改之后修改访视的状态 - _inspectionService.AddInspectionRecordAsync(new DataInspectionAddDTO() - { - SiteId = subjectVisit.SiteId, - SubjectId = subjectVisit.SubjectId, - IsSign = false, - VisitStageId = subjectVisit.VisitStageId, - SubjectVisitName = subjectVisit.VisitName, - BlindName = subjectVisit.BlindName, - SubjectVisitId = subjectVisit.Id, - Identification = "Edit|Visit|Status|Visit-Image Upload", - JsonDetail= JsonConvert.SerializeObject(new { - SubmitState= subjectVisit.SubmitState, - - }) - - }).Wait(); + diff --git a/IRaCIS.Core.Infra.EFCore/Common/EFSqlQuery.cs b/IRaCIS.Core.Infra.EFCore/Common/EFSqlQuery.cs new file mode 100644 index 000000000..58b9c353d --- /dev/null +++ b/IRaCIS.Core.Infra.EFCore/Common/EFSqlQuery.cs @@ -0,0 +1,80 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Common; +using System.Data.SqlClient; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace IRaCIS.Core.Infra.EFCore +{ + public static class EFSqlQuery + { + public static IEnumerable SqlQuery(this DatabaseFacade facade, string sql, params object[] parameters) where T : class, new() + { + DataTable dt = SqlQuery(facade, sql, parameters); + return dt.ToEnumerable(); + } + + public static IEnumerable ToEnumerable(this DataTable dt) where T : class, new() + { + PropertyInfo[] propertyInfos = typeof(T).GetProperties(); + T[] ts = new T[dt.Rows.Count]; + int i = 0; + foreach (DataRow row in dt.Rows) + { + T t = new T(); + foreach (PropertyInfo p in propertyInfos) + { + if (dt.Columns.IndexOf(p.Name) != -1 && row[p.Name] != DBNull.Value) + p.SetValue(t, row[p.Name], null); + } + ts[i] = t; + i++; + } + return ts; + } + + public static DataTable SqlQuery(this DatabaseFacade facade, string sql, params object[] parameters) + { + DbCommand cmd = CreateCommand(facade, sql, out DbConnection conn, parameters); + DbDataReader reader = cmd.ExecuteReader(); + DataTable dt = new DataTable(); + dt.Load(reader); + reader.Close(); + conn.Close(); + return dt; + } + + private static DbCommand CreateCommand(DatabaseFacade facade, string sql, out DbConnection dbConn, params object[] parameters) + { + DbConnection conn = facade.GetDbConnection(); + dbConn = conn; + conn.Open(); + DbCommand cmd = conn.CreateCommand(); + if (facade.IsSqlServer()) + { + cmd.CommandText = sql; + CombineParams(ref cmd, parameters); + } + return cmd; + } + + private static void CombineParams(ref DbCommand command, params object[] parameters) + { + if (parameters != null) + { + foreach (SqlParameter parameter in parameters) + { + if (!parameter.ParameterName.Contains("@")) + parameter.ParameterName = $"@{parameter.ParameterName}"; + command.Parameters.Add(parameter); + } + } + } + } +} diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index b7b02fae3..b2f2b90d5 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -545,6 +545,70 @@ namespace IRaCIS.Core.Infra.EFCore #region 稽查 + ///// + ///// + ///// + ///// + ///// + ///// + //public async Task SetDictionaryValue(string Identification, string json) + //{ + + + //} + + + ///// + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public async Task GetDictionaryValue(string Table,string ForeignKeyValue,string ForeignKeyText,string value) + //{ + // string para = string.Empty; + // string sql = string.Empty; + // string item = JsonConvert.SerializeObject(new { + // item = value + // }); + // var JsonData = JsonConvert.DeserializeObject>(item); + // if (JsonData["item"].GetType() == typeof(JArray)) + // { + // foreach (var v in JsonData["item"] as JArray) + // { + // para += para == string.Empty ? $"'{v}'" : $",'{v}'"; + // } + + + // } + // else + // { + + // } + + + + // //Type type = typeof(TFrom); + + // ////以下是不要ID这个字段的 比如自增列ID 就不能像上名那样写 + // //var properties = type.GetProperties().Where(t => t.Name != "Id"); + + + // //string strSqlName = string.Join(",", properties.Select(p => $"[{p.Name}]").ToArray()); + + // //string strSqlValue = string.Join(",", properties.Select(P => $"@{P.Name}").ToArray()); + + // //string strSql = $"insert into {nameof(Dictionary)} ( " + strSqlName + " ) values (" + strSqlValue + ")"; + + // ////para Sql是参数 + // //SqlParameter[] para = properties.Select(p => new SqlParameter($"@{p.Name}", p.GetValue(from, null))).ToArray(); + + // _dbContext.Database.SqlQuery<> + // //_dbContext.Database.ExecuteSqlRaw(strSql, para); + //} + /// /// 获取枚举