diff --git a/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs b/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs index 70e4e83cb..9e394116b 100644 --- a/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs +++ b/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs @@ -407,6 +407,12 @@ namespace IRaCIS.Core.API.Controllers //IR 上传的时候跟任务绑定 public Guid? VisitTaskId { get; set; } + public string RecordPath { get; set; } + + public int FailedFileCount { get; set; } + + public long FileSize { get; set; } + public List UploadedFileList { get; set; } = new List(); @@ -420,6 +426,14 @@ namespace IRaCIS.Core.API.Controllers public string FileType { get; set; } } } + + /// + /// 非dicom 上传预上传接口 + /// + /// + /// + /// + /// [HttpPost, Route("Study/PreArchiveStudy")] [TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })] public async Task PreArchiveStudy(PreArchiveStudyCommand preArchiveStudyCommand, @@ -437,6 +451,7 @@ namespace IRaCIS.Core.API.Controllers IsSuccess = false, UploadStartTime = DateTime.Now, + FileCount=preArchiveStudyCommand.FileCount, IsDicom = preArchiveStudyCommand.IsDicom, IP = _userInfo.IP }; @@ -500,7 +515,9 @@ namespace IRaCIS.Core.API.Controllers noneDicomStudy.FileCount = noneDicomStudy.FileCount + (incommand.VisitTaskId != null ? 0 : incommand.UploadedFileList.Count); - studyMonitor.FileCount = incommand.UploadedFileList.Count; + studyMonitor.RecordPath = incommand.RecordPath; + studyMonitor.FailedFileCount = incommand.FailedFileCount; + studyMonitor.IsSuccess = incommand.FailedFileCount == 0; studyMonitor.FileSize = incommand.UploadedFileList.Sum(t => t.FileFize); studyMonitor.IsDicom = false; studyMonitor.IsDicomReUpload = false; @@ -508,7 +525,6 @@ namespace IRaCIS.Core.API.Controllers studyMonitor.StudyCode = noneDicomStudy.StudyCode; studyMonitor.ArchiveFinishedTime = DateTime.Now; studyMonitor.IP = _userInfo.IP; - studyMonitor.IsSuccess = true; await _noneDicomStudyRepository.SaveChangesAsync(); diff --git a/IRaCIS.Core.API/IRaCIS.Core.API.xml b/IRaCIS.Core.API/IRaCIS.Core.API.xml index 78ee17b23..6573bf84a 100644 --- a/IRaCIS.Core.API/IRaCIS.Core.API.xml +++ b/IRaCIS.Core.API/IRaCIS.Core.API.xml @@ -281,6 +281,15 @@ Dicom 归档 + + + 非dicom 上传预上传接口 + + + + + + 上传非Dicom 文件 支持压缩包 多文件上传 diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index e8ac5c764..000d081aa 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -4263,7 +4263,7 @@ 临床答案 - + 临床答案 diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs index 496d13735..ef8f3fdf4 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs @@ -207,9 +207,6 @@ namespace IRaCIS.Core.Application.Contracts [NotDefault] public Guid SubjectVisitId { get; set; } - - public long FileSize { get; set; } - public bool IsDicomReUpload { get; set; } @@ -390,7 +387,7 @@ namespace IRaCIS.Core.Application.Contracts public string HtmlPath { get; set; } = string.Empty; - public decimal FileFize { get; set; } + public long FileSize { get; set; } } public class CRCUploadTaskQuery @@ -582,6 +579,8 @@ namespace IRaCIS.Core.Application.Contracts public string IP { get; set; } + public UserTypeEnum UserTypeEnum { get; set; } + } public class TrialIamgeDownQuery:PageInput diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs index 412809334..ea22cafaf 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs @@ -90,7 +90,6 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc IP = _userInfo.IP, IsDicomReUpload = preArchiveStudyCommand.IsDicomReUpload, - FileSize = preArchiveStudyCommand.FileSize, FileCount = preArchiveStudyCommand.FileCount, }; @@ -165,6 +164,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc studyMonitor.FailedFileCount = incommand.FailedFileCount; studyMonitor.IsSuccess = incommand.FailedFileCount == 0; studyMonitor.RecordPath = incommand.RecordPath; + studyMonitor.FileSize = incommand.Study.SeriesList.SelectMany(t=>t.InstanceList).Sum(t => t.FileSize); var studyId = IdentifierHelper.CreateGuid(incommand.Study.StudyInstanceUid, incommand.TrialId.ToString()); var findStudy = await _dicomstudyRepository.FirstOrDefaultAsync(t => t.Id == studyId); diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/_MapConfig.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/_MapConfig.cs index 6b0cf422a..5ba39efb7 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/_MapConfig.cs @@ -145,6 +145,7 @@ namespace IRaCIS.Core.Application.Service CreateMap() .ForMember(d => d.UserFullName, u => u.MapFrom(s => s.CreateUser.FullName)) + .ForMember(d => d.UserTypeEnum, u => u.MapFrom(s => s.CreateUser.UserTypeEnum)) .ForMember(d => d.UserName, u => u.MapFrom(s => s.CreateUser.UserName)); } diff --git a/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalAnswerService.cs b/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalAnswerService.cs index 4dc4fb8d2..a05ec4760 100644 --- a/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalAnswerService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalAnswerService.cs @@ -25,8 +25,6 @@ namespace IRaCIS.Core.Application.Service [ApiExplorerSettings(GroupName = "Reading")] public class ClinicalAnswerService( IRepository _trialClinicalQuestionRepository, - IRepository _systemClinicalQuestionRepository, - IRepository _systemClinicalTableQuestionRepository, IRepository _trialClinicalTableQuestionRepository, IRepository _clinicalDataTrialSetRepository, IRepository _clinicalFormRepository, diff --git a/IRaCIS.Core.Application/Service/Reading/_MapConfig.cs b/IRaCIS.Core.Application/Service/Reading/_MapConfig.cs index 33a9ad6e5..f471c4bb5 100644 --- a/IRaCIS.Core.Application/Service/Reading/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Reading/_MapConfig.cs @@ -15,13 +15,13 @@ namespace IRaCIS.Core.Application.Service //是否英文环境 - var isEn_Us=false; + var isEn_Us = false; //标准Id List CriterionIds = new List(); - #region 临床问题 - CreateMap() + #region 临床问题 + CreateMap() .ForMember(d => d.GroupName, opt => opt.MapFrom(src => src.GroupQuestin.QuestionName)) .ForMember(d => d.GroupEnName, opt => opt.MapFrom(src => src.GroupQuestin.QuestionEnName)); @@ -42,20 +42,23 @@ namespace IRaCIS.Core.Application.Service .ForMember(d => d.SystemClinicalQuestionId, opt => opt.MapFrom(src => src.Id)); CreateMap() + .ForMember(d => d.CreateUser, opt => opt.Ignore()) .ForMember(d => d.SystemClinicalQuestionId, opt => opt.MapFrom(src => src.Id)); CreateMap() .ForMember(d => d.SystemTableQuestionId, u => u.MapFrom(s => s.Id)); + CreateMap() - .ForMember(d => d.SystemTableQuestionId, opt => opt.MapFrom(src => src.Id)); + .ForMember(d => d.SystemTableQuestionId, opt => opt.MapFrom(src => src.Id)) + .ForMember(d => d.CreateUser, opt => opt.Ignore()); // 预览 CreateMap(); CreateMap(); - + CreateMap(); CreateMap(); #endregion @@ -69,38 +72,38 @@ namespace IRaCIS.Core.Application.Service CreateMap(); CreateMap(); - CreateMap().ReverseMap(); + CreateMap().ReverseMap(); - CreateMap(); - CreateMap().ReverseMap(); - CreateMap() - .ForMember(d => d.QuestionMark, u => u.MapFrom(s => s.ReadingTableQuestionTrial == null ? null : s.ReadingTableQuestionTrial.QuestionMark)); + CreateMap(); + CreateMap().ReverseMap(); + CreateMap() + .ForMember(d => d.QuestionMark, u => u.MapFrom(s => s.ReadingTableQuestionTrial == null ? null : s.ReadingTableQuestionTrial.QuestionMark)); - CreateMap(); + CreateMap(); CreateMap() - .ForMember(d => d.SubjectVisitName, u => u.MapFrom(s => s.VisitStage==null?string.Empty: s.VisitStage.VisitName)) + .ForMember(d => d.SubjectVisitName, u => u.MapFrom(s => s.VisitStage == null ? string.Empty : s.VisitStage.VisitName)) .ForMember(d => d.SiteIds, u => u.MapFrom(s => s.ReadingPeriodSites.Select(x => x.TrialSiteId))) .ForMember(d => d.SiteCodes, u => u.MapFrom(s => s.ReadingPeriodSites.Select(x => x.TrialSite.TrialSiteCode))) .ForMember(d => d.PlanCount, u => u.MapFrom(s => s.ReadingPeriodPlanList.Count)); CreateMap() .ForMember(d => d.ChildGroup, u => u.MapFrom(s => s.Dictionary.ChildGroup)) - .ForMember(d => d.Code, u => u.MapFrom(s => s.Dictionary.Code)) + .ForMember(d => d.Code, u => u.MapFrom(s => s.Dictionary.Code)) .ForMember(d => d.Description, u => u.MapFrom(s => s.Dictionary.Description)) .ForMember(d => d.ShowOrder, u => u.MapFrom(s => s.Dictionary.ShowOrder)) .ForMember(d => d.ParentCode, u => u.MapFrom(s => s.Dictionary.Parent.Code)) .ForMember(d => d.Value, u => u.MapFrom(s => s.Dictionary.Value)) .ForMember(d => d.ValueCN, u => u.MapFrom(s => s.Dictionary.ValueCN)); - CreateMap() - .ForMember(d => d.ChildGroup, u => u.MapFrom(s => s.Dictionary.ChildGroup)) - .ForMember(d => d.Code, u => u.MapFrom(s => s.Dictionary.Code)) - .ForMember(d => d.Description, u => u.MapFrom(s => s.Dictionary.Description)) - .ForMember(d => d.ShowOrder, u => u.MapFrom(s => s.Dictionary.ShowOrder)) - .ForMember(d => d.ParentCode, u => u.MapFrom(s => s.Dictionary.Parent.Code)) - .ForMember(d => d.Value, u => u.MapFrom(s => s.Dictionary.Value)) - .ForMember(d => d.ValueCN, u => u.MapFrom(s => s.Dictionary.ValueCN)); + CreateMap() + .ForMember(d => d.ChildGroup, u => u.MapFrom(s => s.Dictionary.ChildGroup)) + .ForMember(d => d.Code, u => u.MapFrom(s => s.Dictionary.Code)) + .ForMember(d => d.Description, u => u.MapFrom(s => s.Dictionary.Description)) + .ForMember(d => d.ShowOrder, u => u.MapFrom(s => s.Dictionary.ShowOrder)) + .ForMember(d => d.ParentCode, u => u.MapFrom(s => s.Dictionary.Parent.Code)) + .ForMember(d => d.Value, u => u.MapFrom(s => s.Dictionary.Value)) + .ForMember(d => d.ValueCN, u => u.MapFrom(s => s.Dictionary.ValueCN)); CreateMap() .ForMember(d => d.FristAddTaskId, u => u.MapFrom(s => s.FirstAddTaskId!.Value)); @@ -127,14 +130,14 @@ namespace IRaCIS.Core.Application.Service CreateMap().ReverseMap(); CreateMap() - .ForMember(t => t.TrialCriterionNameList, u => u.MapFrom(c => c.TrialClinicalDataSetCriteriaList.Where(x=> - CriterionIds.Contains(x.TrialReadingCriterionId) ).Select(t => t.TrialReadingCriterion.CriterionName))) + .ForMember(t => t.TrialCriterionNameList, u => u.MapFrom(c => c.TrialClinicalDataSetCriteriaList.Where(x => + CriterionIds.Contains(x.TrialReadingCriterionId)).Select(t => t.TrialReadingCriterion.CriterionName))) .ForMember(t => t.TrialCriterionIdList, u => u.MapFrom(c => c.TrialClinicalDataSetCriteriaList.Select(t => t.TrialReadingCriterion.Id))) - .ForMember(d => d.IsUsed, u => u.MapFrom(s => s.ReadingClinicalDataList.Count()>0)); + .ForMember(d => d.IsUsed, u => u.MapFrom(s => s.ReadingClinicalDataList.Count() > 0)); CreateMap(); - //.ForMember(t=>t.SystemCriterionNameList,u=>u.MapFrom(c=>c.SystemClinicalDataCriterionList.Select(t=>t.SystemReadingCriterion.CriterionName))) - //.ForMember(t => t.SystemCriterionIdList, u => u.MapFrom(c => c.SystemClinicalDataCriterionList.Select(t => t.SystemReadingCriterion.Id))); + //.ForMember(t=>t.SystemCriterionNameList,u=>u.MapFrom(c=>c.SystemClinicalDataCriterionList.Select(t=>t.SystemReadingCriterion.CriterionName))) + //.ForMember(t => t.SystemCriterionIdList, u => u.MapFrom(c => c.SystemClinicalDataCriterionList.Select(t => t.SystemReadingCriterion.Id))); CreateMap().ReverseMap(); @@ -149,15 +152,15 @@ namespace IRaCIS.Core.Application.Service CreateMap() .ForMember(d => d.OriginalId, u => u.MapFrom(s => s.Id)); - //.ForMember(dest => dest.Instance, opt => opt.Ignore()) - //.ForMember(dest => dest.ReadingQuestionTrial, opt => opt.Ignore()); + //.ForMember(dest => dest.Instance, opt => opt.Ignore()) + //.ForMember(dest => dest.ReadingQuestionTrial, opt => opt.Ignore()); #region 阅片问题 - + // 忽略列 CreateMap() - .ForMember(d => d.QuestionName, u => u.MapFrom(s => isEn_Us?s.QuestionEnName:s.QuestionName)) + .ForMember(d => d.QuestionName, u => u.MapFrom(s => isEn_Us ? s.QuestionEnName : s.QuestionName)) .ForMember(d => d.GroupName, u => u.MapFrom(s => isEn_Us ? s.GroupEnName : s.GroupName)) .ForMember(dest => dest.ReadingCriterionPage, opt => opt.Ignore()) .ForMember(dest => dest.ParentReadingQuestionTrial, opt => opt.Ignore()) @@ -207,7 +210,8 @@ namespace IRaCIS.Core.Application.Service CreateMap(); - CreateMap(); + CreateMap() + .ForMember(d => d.CreateUser, u => u.Ignore()); CreateMap(); @@ -218,12 +222,13 @@ namespace IRaCIS.Core.Application.Service .ForMember(d => d.OriginalId, u => u.MapFrom(s => s.Id)); CreateMap() - .ForMember(d => d.ReadingQuestionSystemId, u => u.MapFrom(s => s.Id)); + .ForMember(d => d.CreateUser, u => u.Ignore()) + .ForMember(d => d.ReadingQuestionSystemId, u => u.MapFrom(s => s.Id)); CreateMap() .ForMember(d => d.MergeName, u => u.MapFrom(s => s.MergeRow == null ? string.Empty : s.MergeRow.ReadingQuestionTrial.OrderMark + s.MergeRow.RowIndex.GetLesionMark())) .ForMember(d => d.SplitName, u => u.MapFrom(s => s.SplitRow == null ? string.Empty : s.SplitRow.ReadingQuestionTrial.OrderMark + s.SplitRow.RowIndex.GetLesionMark())) - .ForMember(d => d.LesionType, u => u.MapFrom(s => s.ReadingQuestionTrial == null ?null : s.ReadingQuestionTrial.LesionType)); + .ForMember(d => d.LesionType, u => u.MapFrom(s => s.ReadingQuestionTrial == null ? null : s.ReadingQuestionTrial.LesionType)); CreateMap() @@ -237,10 +242,11 @@ namespace IRaCIS.Core.Application.Service CreateMap(); - CreateMap() + CreateMap() .ForMember(dest => dest.ReadingQuestionTrialList, opt => opt.Ignore()) - .ForMember(d => d.ReadingQuestionCriterionSystemId, u => u.MapFrom(s => s.Id)); ; - + .ForMember(dest => dest.CreateUser, opt => opt.Ignore()) + .ForMember(d => d.ReadingQuestionCriterionSystemId, u => u.MapFrom(s => s.Id)); + CreateMap(); CreateMap() @@ -251,19 +257,19 @@ namespace IRaCIS.Core.Application.Service CreateMap(); CreateMap(); CreateMap() - .ForMember(d => d.GroupName, u => u.MapFrom(s => s.GroupInfo==null?s.GroupName:s.GroupInfo.GroupName)) - .ForMember(d => d.ParentQuestionName, u => u.MapFrom(s => s.ParentReadingQuestionSystem==null?string.Empty: s.ParentReadingQuestionSystem.QuestionName)) + .ForMember(d => d.GroupName, u => u.MapFrom(s => s.GroupInfo == null ? s.GroupName : s.GroupInfo.GroupName)) + .ForMember(d => d.ParentQuestionName, u => u.MapFrom(s => s.ParentReadingQuestionSystem == null ? string.Empty : s.ParentReadingQuestionSystem.QuestionName)) .ForMember(d => d.ParentQuestionShowOrder, u => u.MapFrom(s => s.ParentReadingQuestionSystem.ShowOrder)) .ForMember(d => d.ParentDictionaryCode, u => u.MapFrom(s => s.ParentReadingQuestionSystem.DictionaryCode)) .ForMember(d => d.ParentQuestionGenre, u => u.MapFrom(s => s.ParentReadingQuestionSystem.QuestionGenre)) .ForMember(d => d.RelevanceShowOrder, u => u.MapFrom(s => s.RelevanceReadingQuestionSystem.ShowOrder)) .ForMember(d => d.RelevanceDictionaryCode, u => u.MapFrom(s => s.RelevanceReadingQuestionSystem.DictionaryCode)) .ForMember(d => d.RelevanceQuestionGenre, u => u.MapFrom(s => s.RelevanceReadingQuestionSystem.QuestionGenre)); - + CreateMap(); CreateMap() - .ForMember(d => d.QuestionCount, u => u.MapFrom(s => s.ReadingQuestionTrialList.Count())); + .ForMember(d => d.QuestionCount, u => u.MapFrom(s => s.ReadingQuestionTrialList.Count())); CreateMap(); @@ -282,7 +288,7 @@ namespace IRaCIS.Core.Application.Service #region IR阅片 CreateMap() .ForMember(d => d.QuestionName, u => u.MapFrom(s => isEn_Us ? s.QuestionEnName : s.QuestionName)) - .ForMember(x=>x.Id, y=>y.MapFrom(z=>z.Id)); + .ForMember(x => x.Id, y => y.MapFrom(z => z.Id)); //CreateMap() // .ForMember(x => x.VisitTaskId, y => y.MapFrom(z => z.Id)) @@ -299,7 +305,7 @@ namespace IRaCIS.Core.Application.Service CreateMap(); CreateMap() - .ForMember(x=>x.ParentShowOrder,y=>y.MapFrom(n=>n.ParentQuestion.ShowOrder)); + .ForMember(x => x.ParentShowOrder, y => y.MapFrom(n => n.ParentQuestion.ShowOrder)); CreateMap(); @@ -311,12 +317,12 @@ namespace IRaCIS.Core.Application.Service //.ForMember(x => x.FileList, y => y.MapFrom(n => n.FileList)) .ForMember(x => x.CreateUserName, y => y.MapFrom(n => n.CreateUser.UserName)); - #endregion + #endregion - #region 阅片部位 + #region 阅片部位 - CreateMap(); - CreateMap(); + CreateMap(); + CreateMap(); CreateMap().ReverseMap(); CreateMap(); @@ -329,13 +335,13 @@ namespace IRaCIS.Core.Application.Service // .ForMember(d => d.SubjectCode, u => u.MapFrom(s => s.subject.Code)) // .ForMember(d => d.SubjectStatus, u => u.MapFrom(s => s.subject.Status)); - - CreateMap().ReverseMap(); + + CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); - + CreateMap() .ForMember(o => o.UploadedTime, t => t.MapFrom(u => u.CreateTime)) .ForMember(o => o.Uploader, t => t.MapFrom(u => u.CreateUser.LastName + " / " + u.CreateUser.FirstName)) @@ -347,5 +353,5 @@ namespace IRaCIS.Core.Application.Service #endregion } } - + } diff --git a/IRaCIS.Core.Application/Service/Visit/DTO/VisitPointViewModel.cs b/IRaCIS.Core.Application/Service/Visit/DTO/VisitPointViewModel.cs index af0413301..5655cf27c 100644 --- a/IRaCIS.Core.Application/Service/Visit/DTO/VisitPointViewModel.cs +++ b/IRaCIS.Core.Application/Service/Visit/DTO/VisitPointViewModel.cs @@ -281,6 +281,8 @@ namespace IRaCIS.Core.Application.Contracts public bool IsDicom { get; set; } + public int FileCount { get; set; } + } diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index 3123ebec9..07b667ab0 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -110,27 +110,25 @@ namespace IRaCIS.Application.Services { public Guid TestId { get; set; } - public string TestName { get; set; } + public string TestName { get; set; } } - public IResponseOutput TestJson() + public async Task TestJson() { - var trial=new Trial(); - trial.ExperimentName = null; - - _trialRepository.AddAsync(trial,true); + await _trialBodyPartRepository.FirstOrDefaultAsync(); + await _trialBodyPartRepository.Where(t=>t.Trial.Id==Guid.Empty).FirstOrDefaultAsync(); return ResponseOutput.Ok(new TestModel(), IRCEmailPasswordHelper.GenerateRandomPassword(10)); } - public string TestHoliday(DateTime startdate,DateTime endDate) + public string TestHoliday(DateTime startdate, DateTime endDate) { - var timeSpan= HolidayHelper.GetChinaWorkTimeSpan(startdate, endDate); + var timeSpan = HolidayHelper.GetChinaWorkTimeSpan(startdate, endDate); _userRepository.Where(t => t.Id == _userInfo.Id).Select(t => t.FullName).FirstOrDefault(); diff --git a/IRaCIS.Core.Domain/BaseModel/Entity.cs b/IRaCIS.Core.Domain/BaseModel/Entity.cs index 854414413..ce7dfc8c8 100644 --- a/IRaCIS.Core.Domain/BaseModel/Entity.cs +++ b/IRaCIS.Core.Domain/BaseModel/Entity.cs @@ -71,7 +71,7 @@ namespace IRaCIS.Core.Domain.Models [ForeignKey("CreateUserId")] [JsonIgnore] - public User CreateUser { get; set; } + public virtual User CreateUser { get; set; } } public abstract class BaseAddDeleteAuditEntity : Entity, IAuditAdd, ISoftDelete diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/MigrationRemoveForeignKeysSqlGenerator .cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/MigrationRemoveForeignKeysSqlGenerator .cs deleted file mode 100644 index dae427d53..000000000 --- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/MigrationRemoveForeignKeysSqlGenerator .cs +++ /dev/null @@ -1,30 +0,0 @@ -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Migrations.Operations; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Convention -{ - public class MigrationRemoveForeignKeysSqlGenerator : MigrationsSqlGenerator - { - public MigrationRemoveForeignKeysSqlGenerator(MigrationsSqlGeneratorDependencies dependencies, IMigrationsAnnotationProvider migrationsAnnotations) : base(dependencies) - { - } - - protected override void Generate(Microsoft.EntityFrameworkCore.Migrations.Operations.CreateTableOperation operation, IModel? model, MigrationCommandListBuilder builder, bool terminate = true) - { - operation.ForeignKeys.Clear(); - base.Generate(operation, model, builder, terminate); - } - - protected override void Generate(AddForeignKeyOperation operation, IModel? model, MigrationCommandListBuilder builder, - bool terminate = true) - { - return; - } - } -} diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/NoForeignKeyConvention.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/NoForeignKeyConvention.cs new file mode 100644 index 000000000..6fc9727d6 --- /dev/null +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/NoForeignKeyConvention.cs @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore.Metadata.Conventions; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore; +namespace IRaCIS.Core.Test +{ + /// + /// 这种方式不行 + /// + public class NoForeignKeyConvention : IModelFinalizingConvention + { + public void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext context) + { + foreach (var entityType in modelBuilder.Metadata.GetEntityTypes()) + { + foreach (var foreignKey in entityType.GetForeignKeys()) + { + // 设置删除行为为 NoAction,避免生成外键约束 + foreignKey.Builder.OnDelete(DeleteBehavior.NoAction); + } + } + } + } +} + + diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/NoForeignKeyMigrationsSqlGenerator.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/NoForeignKeyMigrationsSqlGenerator.cs new file mode 100644 index 000000000..0b42a15d9 --- /dev/null +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/NoForeignKeyMigrationsSqlGenerator.cs @@ -0,0 +1,30 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations.Operations; +using Microsoft.EntityFrameworkCore.Metadata; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations.Internal; +using Microsoft.EntityFrameworkCore.Storage; + +namespace IRaCIS.Core.Test +{ + public class NoForeignKeyMigrationsSqlGenerator : MigrationsSqlGenerator + { + public NoForeignKeyMigrationsSqlGenerator( + MigrationsSqlGeneratorDependencies dependencies) : base(dependencies) + { + } + + protected override void Generate(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder) + { + if (operation is AddForeignKeyOperation || operation is DropForeignKeyOperation) + { + // 跳过外键的生成 + return; + } + + base.Generate(operation, model, builder); + } + } + +} diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs index 64f2c1298..6f7889277 100644 --- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using IRaCIS.Core.Test.CodeFirstTest.MSSQL; -using IRaCIS.Core.Test.CodeFirstTest.MSSQL.Convention; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.Extensions.Options; @@ -42,8 +41,9 @@ public partial class IRCContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - //移除外键约束 - optionsBuilder.ReplaceService(); + + // 替换默认的 MigrationsSqlGenerator + optionsBuilder.ReplaceService(); optionsBuilder.UseSqlServer("Server=106.14.89.110,1433;Database=IRC_Code;User ID=sa;Password=mssql_KnTs2a;TrustServerCertificate=true"); @@ -59,12 +59,14 @@ public partial class IRCContext : DbContext modelBuilder.ApplyConfiguration(configurationInstance); } - + OnModelCreatingPartial(modelBuilder); } protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) { + + //针对字符串使用默认的长度配置 configurationBuilder.Conventions.Add(_ => new MaxStringLengthConvention()); } diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912012757_RemoveForeignKey.Designer.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912054434_RemoveForeignKey.Designer.cs similarity index 99% rename from IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912012757_RemoveForeignKey.Designer.cs rename to IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912054434_RemoveForeignKey.Designer.cs index 5604139f2..7cbf95b93 100644 --- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912012757_RemoveForeignKey.Designer.cs +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912054434_RemoveForeignKey.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations { [DbContext(typeof(IRCContext))] - [Migration("20240912012757_RemoveForeignKey")] + [Migration("20240912054434_RemoveForeignKey")] partial class RemoveForeignKey { /// diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912012757_RemoveForeignKey.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912054434_RemoveForeignKey.cs similarity index 100% rename from IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912012757_RemoveForeignKey.cs rename to IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912054434_RemoveForeignKey.cs diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs index 6410bc381..6451992e6 100644 --- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs @@ -151,16 +151,21 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL #region 测试生成迁移移除外键约束 #endregion + + #region 测试迁移不生成外键约束,ef知道外键关系,但是数据库不保存外键 public class Project : BaseFullAuditEntity { } - public class ProjectUser: BaseFullAuditEntity + public class ProjectUser : BaseFullAuditEntity { //外键 public Guid ProjectId { get; set; } public Project Project { get; set; } } + #endregion + + }