From ca1f23ca4d36ffe68ab6ee751eb6798c60c621b0 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Fri, 20 May 2022 10:14:01 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=A9=E7=95=A5=E5=9B=BE=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CommonController.cs | 94 +++++++++++++++++++ IRaCIS.Core.Application/Helper/ImageResize.cs | 27 ++++++ .../IRaCIS.Core.Application.csproj | 4 + .../QC/DTO/NoneDicomStudyFileViewModel.cs | 2 + .../Service/QC/DTO/NoneDicomStudyViewModel.cs | 2 + .../Service/QC/NoneDicomStudyService.cs | 53 +++-------- .../Management/Notice/SystemNotice.cs | 4 +- 7 files changed, 144 insertions(+), 42 deletions(-) create mode 100644 IRaCIS.Core.API/Controllers/CommonController.cs create mode 100644 IRaCIS.Core.Application/Helper/ImageResize.cs diff --git a/IRaCIS.Core.API/Controllers/CommonController.cs b/IRaCIS.Core.API/Controllers/CommonController.cs new file mode 100644 index 000000000..723600c0e --- /dev/null +++ b/IRaCIS.Core.API/Controllers/CommonController.cs @@ -0,0 +1,94 @@ +using AutoMapper; +using IRaCIS.Core.Application.Helper; +using IRaCIS.Core.Domain.Share; +using IRaCIS.Core.Infrastructure.Extention; +using MediatR; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System.IO; +using System.Threading.Tasks; + +namespace IRaCIS.Core.API.Controllers +{ + [ApiExplorerSettings(GroupName = "Trial")] + [ApiController] + public class CommonController : ControllerBase + { + public IMapper _mapper { get; set; } + public IUserInfo _userInfo { get; set; } + + private readonly IWebHostEnvironment _hostEnvironment; + + + + public CommonController(IMapper mapper, IUserInfo userInfo, IMediator mediator, IWebHostEnvironment hostEnvironment) + { + _hostEnvironment = hostEnvironment; + _mapper = mapper; + _userInfo = userInfo; + } + + + [AllowAnonymous] + [HttpGet("Common/LocalFilePreview")] + public async Task LocalFilePreview(string relativePath) + { + var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\')).IfNullThrowException().FullName; + + var _fileStorePath = Path.Combine(rootPath, relativePath.Replace('/', '\\').Trim('\\')); + + + var storePreviewPath = _fileStorePath + ".preview.jpeg"; + + //if (!System.IO.File.Exists(storePreviewPath)) + //{ + ImageResizeHelper.ResizeSave(_fileStorePath, storePreviewPath); + //} + + return new FileContentResult(await System.IO.File.ReadAllBytesAsync(storePreviewPath), "image/jpeg"); + + //_logger.LogError(rootPath); + + //_logger.LogError(_fileStorePath); + + + //if (!File.Exists(storePreviewPath)) + //{ + + //Bitmap sourceImage = new Bitmap(File.OpenRead(_fileStorePath)); + + //System.Drawing.Image destinationImage = new Bitmap(500, 500); + //Graphics g = Graphics.FromImage(destinationImage); + + //g.DrawImage( + // sourceImage, + // new Rectangle(0, 0, 500, 500), + // new Rectangle(0, 0, sourceImage.Width, sourceImage.Height), + // GraphicsUnit.Pixel + //); + + //destinationImage.Save(storePreviewPath); + + //var image = SKBitmap.Decode(_fileStorePath); + ////设置图片新的size + //var newImg = image.Resize(new SKSizeI(50, 50), SKFilterQuality.Medium); + //using var fs = new FileStream(storePreviewPath, FileMode.Create); + //newImg.Encode(fs, SKEncodedImageFormat.Png, 100); + //fs.Flush(); + + + //var image = NetVips.Image.NewFromFile(_fileStorePath); + //var newImg = image.Resize(0.5); + //newImg.WriteToFile(storePreviewPath); + + + //var image = NetVips.Image.NewFromFile(_fileStorePath); + //var newImg = image.ThumbnailImage(500); + //newImg.WriteToFile(_fileStorePath); + + } + + } +} diff --git a/IRaCIS.Core.Application/Helper/ImageResize.cs b/IRaCIS.Core.Application/Helper/ImageResize.cs new file mode 100644 index 000000000..a864f0786 --- /dev/null +++ b/IRaCIS.Core.Application/Helper/ImageResize.cs @@ -0,0 +1,27 @@ + +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Processing; + +namespace IRaCIS.Core.Application.Helper; + +public static class ImageResizeHelper +{ + + + public static void ResizeSave(string filePath, string? fileStorePath) + { + + fileStorePath = fileStorePath ?? filePath + ".preview.jpeg"; + + using (var image = SixLabors.ImageSharp.Image.Load(filePath)) + { + + + image.Mutate(x => x.Resize(500, 500)); + + image.Save(fileStorePath); + + } + } +} + diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj index 1fe53bf75..f51005c76 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj @@ -82,14 +82,18 @@ + + + + diff --git a/IRaCIS.Core.Application/Service/QC/DTO/NoneDicomStudyFileViewModel.cs b/IRaCIS.Core.Application/Service/QC/DTO/NoneDicomStudyFileViewModel.cs index 474e18520..7600abdb9 100644 --- a/IRaCIS.Core.Application/Service/QC/DTO/NoneDicomStudyFileViewModel.cs +++ b/IRaCIS.Core.Application/Service/QC/DTO/NoneDicomStudyFileViewModel.cs @@ -20,6 +20,8 @@ namespace IRaCIS.Core.Application.Contracts public string FullFilePath { get; set; } = string.Empty; + public string PreviewPath => "/Common/LocalFilePreview?relativePath=" + Path; + } diff --git a/IRaCIS.Core.Application/Service/QC/DTO/NoneDicomStudyViewModel.cs b/IRaCIS.Core.Application/Service/QC/DTO/NoneDicomStudyViewModel.cs index aed1b7d87..b0c935404 100644 --- a/IRaCIS.Core.Application/Service/QC/DTO/NoneDicomStudyViewModel.cs +++ b/IRaCIS.Core.Application/Service/QC/DTO/NoneDicomStudyViewModel.cs @@ -17,6 +17,8 @@ namespace IRaCIS.Core.Application.Contracts public List NoneDicomStudyFileList { get; set; } = new List(); + public List NoneDicomStudyPreviewList=> NoneDicomStudyFileList.Select(t=> t.PreviewPath).ToList(); + } ///NoneDicomStudyQuery 列表查询参数模型 diff --git a/IRaCIS.Core.Application/Service/QC/NoneDicomStudyService.cs b/IRaCIS.Core.Application/Service/QC/NoneDicomStudyService.cs index 3f15de46b..3b958ebbb 100644 --- a/IRaCIS.Core.Application/Service/QC/NoneDicomStudyService.cs +++ b/IRaCIS.Core.Application/Service/QC/NoneDicomStudyService.cs @@ -14,10 +14,13 @@ using IRaCIS.Core.Application.Service.Inspection.DTO; using Nito.AsyncEx; using IRaCIS.Application.Interfaces; using IRaCIS.Core.Infrastructure; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp; + using Microsoft.Extensions.Logging; using Microsoft.AspNetCore.Authorization; +using System.Drawing; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp; +using IRaCIS.Core.Application.Helper; namespace IRaCIS.Core.Application.Contracts { @@ -44,10 +47,10 @@ namespace IRaCIS.Core.Application.Contracts IDictionaryService dictionaryService, IInspectionService inspectionService, IRepository studyMonitorRepository, - IRepository noneDicomStudyFileRepository,IRepository subjectVisitRepository, ILogger logger) + IRepository noneDicomStudyFileRepository, IRepository subjectVisitRepository, ILogger logger) { _noneDicomStudyRepository = noneDicomStudyRepository; - + this._httpContext = httpContext; this._dictionaryService = dictionaryService; this._inspectionService = inspectionService; @@ -87,7 +90,7 @@ namespace IRaCIS.Core.Application.Contracts [TypeFilter(typeof(TrialResourceFilter))] public async Task> AddOrUpdateNoneDicomStudy(NoneDicomStudyAddOrEdit addOrEditNoneDicomStudy) { - var visitList = await _subjectVisitRepository.Where(t => t.SubjectId == addOrEditNoneDicomStudy.SubjectId).Select(t => new { t.VisitNum, t.EarliestScanDate, t.LatestScanDate, t.Id }).ToListAsync(); + var visitList = await _subjectVisitRepository.Where(t => t.SubjectId == addOrEditNoneDicomStudy.SubjectId).Select(t => new { t.VisitNum, t.EarliestScanDate, t.LatestScanDate, t.Id }).ToListAsync(); var currentVisitNum = await _subjectVisitRepository.Where(t => t.Id == addOrEditNoneDicomStudy.SubjectVisitId).Select(t => t.VisitNum).FirstOrDefaultAsync(); @@ -155,7 +158,7 @@ namespace IRaCIS.Core.Application.Contracts [TypeFilter(typeof(TrialResourceFilter))] [HttpDelete("{trialId:guid}/{subjectVisitId:guid}/{noneDicomStudyId:guid}")] - public async Task DeleteNoneDicomStudy(Guid noneDicomStudyId,Guid subjectVisitId) + public async Task DeleteNoneDicomStudy(Guid noneDicomStudyId, Guid subjectVisitId) { //提交了 但是IQC同意的时候 是可以删除的 | 普通提交后也不能删除 if (await _subjectVisitRepository.AnyAsync(t => t.Id == subjectVisitId && t.SubmitState == SubmitStateEnum.Submitted && @@ -164,7 +167,7 @@ namespace IRaCIS.Core.Application.Contracts return ResponseOutput.NotOk("CRC Has Submited Image,can not delete"); } - await _noneDicomStudyRepository.DeleteFromQueryAsync( noneDicomStudyId); + await _noneDicomStudyRepository.DeleteFromQueryAsync(noneDicomStudyId); await _noneDicomStudyFileRepository.DeleteFromQueryAsync(t => t.NoneDicomStudyId == noneDicomStudyId); @@ -189,7 +192,7 @@ namespace IRaCIS.Core.Application.Contracts } //var subjectVisitId = await _noneDicomStudyFileRepository.Where(t => t.Id == noneDicomStudyFileId).Select(t => t.NoneDicomStudy.SubjectVisitId).FirstOrDefaultAsync(); - var success = await _noneDicomStudyFileRepository.DeleteFromQueryAsync(t => t.Id == noneDicomStudyFileId,true); + var success = await _noneDicomStudyFileRepository.DeleteFromQueryAsync(t => t.Id == noneDicomStudyFileId, true); return ResponseOutput.Ok(); } @@ -212,37 +215,7 @@ namespace IRaCIS.Core.Application.Contracts return await _repository.Where(t => t.NoneDicomStudy.SubjectVisitId == subjectVisitId).ProjectTo(_mapper.ConfigurationProvider, new { token = _userInfo.UserToken }).ToListAsync(); } - [AllowAnonymous] - [HttpGet] - public async Task NoneDicomFilePreview(string relativePath) - { - var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\')).IfNullThrowException().FullName; - var _fileStorePath = Path.Combine(rootPath, relativePath.Replace('/', '\\').Trim('\\')); - - //_logger.LogError(rootPath); - - //_logger.LogError(_fileStorePath); - - var storePreviewPath = _fileStorePath + ".preview.jpg"; - - //if (!File.Exists(storePreviewPath)) - //{ - - using (var image = SixLabors.ImageSharp.Image.Load(await File.ReadAllBytesAsync(_fileStorePath))) - { - image.Mutate(x => x - .Resize(1000, 1000) - ); - - await image.SaveAsJpegAsync(storePreviewPath); - - } - //} - - return new FileContentResult(await File.ReadAllBytesAsync(storePreviewPath), "image/jpg"); - - } /// /// 上传非Dicom 文件 支持压缩包 @@ -308,7 +281,7 @@ namespace IRaCIS.Core.Application.Contracts // 上传非Dicom 后 将状态改为待提交 分为普通上传 和QC后重传 普通上传时才改为待提交 await _subjectVisitRepository.UpdatePartialFromQueryAsync(t => t.Id == subjectVisitId && t.SubmitState == SubmitStateEnum.None, u => new SubjectVisit() { SubmitState = SubmitStateEnum.ToSubmit }); - var studyCode= await _noneDicomStudyRepository.Where(t=>t.Id== noneDicomStudyId).Select(t => t.StudyCode).FirstOrDefaultAsync(); + var studyCode = await _noneDicomStudyRepository.Where(t => t.Id == noneDicomStudyId).Select(t => t.StudyCode).FirstOrDefaultAsync(); await _studyMonitorRepository.AddAsync(new StudyMonitor() { @@ -317,7 +290,7 @@ namespace IRaCIS.Core.Application.Contracts IsDicom = false, IsDicomReUpload = false, StudyId = noneDicomStudyId, - StudyCode= studyCode, + StudyCode = studyCode, UploadStartTime = startTime, UploadFinishedTime = DateTime.Now, IP = _userInfo.IP, diff --git a/IRaCIS.Core.Domain/Management/Notice/SystemNotice.cs b/IRaCIS.Core.Domain/Management/Notice/SystemNotice.cs index 25a01713a..29d146fa4 100644 --- a/IRaCIS.Core.Domain/Management/Notice/SystemNotice.cs +++ b/IRaCIS.Core.Domain/Management/Notice/SystemNotice.cs @@ -19,9 +19,9 @@ namespace IRaCIS.Core.Domain.Models public class SystemNotice : Entity, IAuditUpdate, IAuditAdd { - public List NoticeUserTypeList { get; set; } + public List NoticeUserTypeList { get; set; }=new List(); - public List NoticeUserReadList { get; set; } + public List NoticeUserReadList { get; set; }=new List(); public User CreateUser { get; set; }