版本管理
continuous-integration/drone/push Build is running Details

Uat_IRC_Net8
he 2026-05-06 14:01:39 +08:00
parent 7bfb6d2c5f
commit 4b8d9bf7bf
3 changed files with 111 additions and 10 deletions

View File

@ -54,6 +54,11 @@ public class SegmentationAddOrEdit
public Guid VisitTaskId { get; set; } public Guid VisitTaskId { get; set; }
/// <summary>
/// 文件大小,单位字节
/// </summary>
public long FileSize { get; set; } = 0;
} }
public class SegmentationQuery:PageInput public class SegmentationQuery:PageInput
@ -77,7 +82,30 @@ public class SegmentationQuery:PageInput
public Guid? TrialId { get; set; } public Guid? TrialId { get; set; }
public Guid? VisitTaskId { 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; }
}

View File

@ -33,7 +33,8 @@ public class SegmentationService(IRepository<Segmentation> _segmentationReposito
IRepository<Segment> _segmentRepository, IRepository<Segment> _segmentRepository,
IRepository<ReadingQuestionTrial> _readingQuestionTrialRepository, IRepository<ReadingQuestionTrial> _readingQuestionTrialRepository,
IRepository<ReadingTableQuestionTrial> _readingTableQuestionTrialRepository, IRepository<ReadingTableQuestionTrial> _readingTableQuestionTrialRepository,
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer): BaseService, ISegmentationService IRepository<SegmentationVersion> _segmentationVersionRepository,
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer, IWebHostEnvironment _hostEnvironment): BaseService, ISegmentationService
{ {
@ -73,13 +74,83 @@ public class SegmentationService(IRepository<Segmentation> _segmentationReposito
{ {
if (addOrEditSegmentation.Id != null)
var entity = await _segmentationRepository.InsertOrUpdateAsync(addOrEditSegmentation, true); {
await SaveSegmentationVersionAsync(addOrEditSegmentation.Id.Value);
return ResponseOutput.Ok(entity.Id.ToString());
} }
var entity = await _segmentationRepository.InsertOrUpdateAsync(addOrEditSegmentation, true);
return ResponseOutput.Ok(entity.Id.ToString());
}
/// <summary>
/// 添加新版本
/// </summary>
/// <param name="segmentationId"></param>
/// <returns></returns>
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();
}
/// <summary>
/// 获取分割组历史版本
/// </summary>
/// <param name="inQuery"></param>
/// <returns></returns>
[HttpPost]
public async Task<PageOutput<SegmentationVersionView>> GetSegmentationVersionList(SegmentationVersionQuery inQuery)
{
var versionQueryable = _segmentationVersionRepository
.Where(x => x.SegmentationId == inQuery.SegmentationId)
.ProjectTo<SegmentationVersionView>(_mapper.ConfigurationProvider);
var defalutSortArray = new string[] { nameof(SegmentationVersion.Version) + " desc" };
var pageList = await versionQueryable.ToPagedListAsync(inQuery, defalutSortArray);
return pageList;
}
/// <summary>
/// 恢复分割组历史版本
/// </summary>
/// <param name="inDto"></param>
/// <returns></returns>
[HttpPost]
public async Task<IResponseOutput> 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();
}
/// <summary> /// <summary>
/// 删除分割组 /// 删除分割组

View File

@ -1,4 +1,4 @@
using AutoMapper; using AutoMapper;
using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Application.Contracts;
using IRaCIS.Core.Application.Service.Reading.Dto; using IRaCIS.Core.Application.Service.Reading.Dto;
using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Application.ViewModel;
@ -25,6 +25,8 @@ namespace IRaCIS.Core.Application.Service
CreateMap<Segmentation, SegmentationView>(); CreateMap<Segmentation, SegmentationView>();
CreateMap<Segmentation, SegmentationAddOrEdit>().ReverseMap(); CreateMap<Segmentation, SegmentationAddOrEdit>().ReverseMap();
CreateMap<SegmentationVersion, SegmentationVersionView>();
// 在此处拷贝automapper 映射 // 在此处拷贝automapper 映射
CreateMap<SegmentBinding, SegmentBindingView>() CreateMap<SegmentBinding, SegmentBindingView>()