From 4b8d9bf7bff733039e26514505600a09b3eb24fd Mon Sep 17 00:00:00 2001 From: he <109787524@qq.com> Date: Wed, 6 May 2026 14:01:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Reading/Dto/SegmentationViewModel.cs | 30 ++++++- .../Reading/Segment/SegmentationService.cs | 87 +++++++++++++++++-- .../Service/Reading/_MapConfig.cs | 4 +- 3 files changed, 111 insertions(+), 10 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Reading/Dto/SegmentationViewModel.cs b/IRaCIS.Core.Application/Service/Reading/Dto/SegmentationViewModel.cs index 4d8ff72f0..a2a5534a6 100644 --- a/IRaCIS.Core.Application/Service/Reading/Dto/SegmentationViewModel.cs +++ b/IRaCIS.Core.Application/Service/Reading/Dto/SegmentationViewModel.cs @@ -54,6 +54,11 @@ public class SegmentationAddOrEdit public Guid VisitTaskId { get; set; } + /// + /// 文件大小,单位字节 + /// + public long FileSize { get; set; } = 0; + } public class SegmentationQuery:PageInput @@ -77,7 +82,30 @@ public class SegmentationQuery:PageInput public Guid? TrialId { get; set; } public Guid? VisitTaskId { get; set; } - } +} + +public class SegmentationVersionView +{ + public Guid Id { get; set; } + public Guid SegmentationId { get; set; } + public int Version { get; set; } + public string SegmentationJson { get; set; } + public string SEGUrl { get; set; } + public long FileSize { get; set; } + public DateTime CreateTime { get; set; } + public string CreateUserName { get; set; } +} + +public class SegmentationVersionQuery : PageInput +{ + public Guid SegmentationId { get; set; } +} + +public class RestoreSegmentationVersionInDto +{ + public Guid SegmentationId { get; set; } + public Guid VersionId { get; set; } +} diff --git a/IRaCIS.Core.Application/Service/Reading/Segment/SegmentationService.cs b/IRaCIS.Core.Application/Service/Reading/Segment/SegmentationService.cs index ba580fcb5..e1a14fd42 100644 --- a/IRaCIS.Core.Application/Service/Reading/Segment/SegmentationService.cs +++ b/IRaCIS.Core.Application/Service/Reading/Segment/SegmentationService.cs @@ -33,7 +33,8 @@ public class SegmentationService(IRepository _segmentationReposito IRepository _segmentRepository, IRepository _readingQuestionTrialRepository, IRepository _readingTableQuestionTrialRepository, - IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer): BaseService, ISegmentationService + IRepository _segmentationVersionRepository, + IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer, IWebHostEnvironment _hostEnvironment): BaseService, ISegmentationService { @@ -69,17 +70,87 @@ public class SegmentationService(IRepository _segmentationReposito /// /// [HttpPost] - public async Task AddOrUpdateSegmentation(SegmentationAddOrEdit addOrEditSegmentation) - { - + public async Task AddOrUpdateSegmentation(SegmentationAddOrEdit addOrEditSegmentation) + { - var entity = await _segmentationRepository.InsertOrUpdateAsync(addOrEditSegmentation, true); - + if (addOrEditSegmentation.Id != null) + { + await SaveSegmentationVersionAsync(addOrEditSegmentation.Id.Value); + } + + var entity = await _segmentationRepository.InsertOrUpdateAsync(addOrEditSegmentation, true); return ResponseOutput.Ok(entity.Id.ToString()); - - } + } + /// + /// 添加新版本 + /// + /// + /// + private async Task SaveSegmentationVersionAsync(Guid segmentationId) + { + var data = await _segmentationRepository.FirstOrDefaultNoTrackingAsync(x => x.Id == segmentationId.Id.Value); + // 如果是新增或修改,记录一条版本信息 + var maxVersion = await _segmentationVersionRepository + .Where(x => x.SegmentationId == data.Id) + .OrderByDescending(x => x.Version) + .Select(x => x.Version) + .FirstOrDefaultAsync(); + + var newVersion = maxVersion + 1; + var versionEntity = new SegmentationVersion + { + SegmentationId = data.Id, + Version = newVersion, + SegmentationJson = data.SegmentationJson, + SEGUrl = data.SEGUrl, + FileSize = data.FileSize, + }; + + await _segmentationVersionRepository.AddAsync(versionEntity); + + await _segmentationRepository.SaveChangesAsync(); + } + + + /// + /// 获取分割组历史版本 + /// + /// + /// + [HttpPost] + public async Task> GetSegmentationVersionList(SegmentationVersionQuery inQuery) + { + var versionQueryable = _segmentationVersionRepository + .Where(x => x.SegmentationId == inQuery.SegmentationId) + .ProjectTo(_mapper.ConfigurationProvider); + var defalutSortArray = new string[] { nameof(SegmentationVersion.Version) + " desc" }; + var pageList = await versionQueryable.ToPagedListAsync(inQuery, defalutSortArray); + + return pageList; + } + + /// + /// 恢复分割组历史版本 + /// + /// + /// + [HttpPost] + public async Task RestoreSegmentationVersion(RestoreSegmentationVersionInDto inDto) + { + var version = await _segmentationVersionRepository.Where(x => x.Id == inDto.VersionId && x.SegmentationId == inDto.SegmentationId).FirstNotNullAsync(); + var segmentation = await _segmentationRepository.Where(x => x.Id == inDto.SegmentationId).FirstNotNullAsync(); + await _segmentationRepository.UpdatePartialFromQueryAsync(x => x.Id == inDto.SegmentationId, t => new Segmentation + { + SegmentationJson = version.SegmentationJson, + SEGUrl = version.SEGUrl, + FileSize = version.FileSize, + }); + await _segmentationRepository.SaveChangesAsync(); + + return ResponseOutput.Ok(); + } /// /// 删除分割组 diff --git a/IRaCIS.Core.Application/Service/Reading/_MapConfig.cs b/IRaCIS.Core.Application/Service/Reading/_MapConfig.cs index 13a79940d..80a789bf2 100644 --- a/IRaCIS.Core.Application/Service/Reading/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Reading/_MapConfig.cs @@ -1,4 +1,4 @@ -using AutoMapper; +using AutoMapper; using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Application.Service.Reading.Dto; using IRaCIS.Core.Application.ViewModel; @@ -25,6 +25,8 @@ namespace IRaCIS.Core.Application.Service CreateMap(); CreateMap().ReverseMap(); + CreateMap(); + // 在此处拷贝automapper 映射 CreateMap()