From 1556a9f2b0b03f8b4506d3f14bbf0435acc003db Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Fri, 1 Apr 2022 15:35:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BE=9B=E4=B8=8B=E8=BD=BD=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/UploadController.cs | 30 ++++++++++++++++++- .../Service/Common/CommonDocumentService.cs | 3 +- .../Common/DTO/CommonDocumentViewModel.cs | 2 ++ .../Service/Common/_MapConfig.cs | 5 ++-- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/IRaCIS.Core.API/Controllers/UploadController.cs b/IRaCIS.Core.API/Controllers/UploadController.cs index f1ea5b068..8ecbf0f92 100644 --- a/IRaCIS.Core.API/Controllers/UploadController.cs +++ b/IRaCIS.Core.API/Controllers/UploadController.cs @@ -119,7 +119,7 @@ namespace IRaCIS.Core.API.Controllers [HttpPost("CommonDocument/UploadCommonDoc/{fileType}/{moduleType}")] [DisableRequestSizeLimit] [DisableFormValueModelBinding] - public async Task UploadCommonDoc(string fileType,string moduleType) + public async Task UploadCommonDoc(string fileType, string moduleType) { var boundary = HeaderUtilities.RemoveQuotes(MediaTypeHeaderValue.Parse(Request.ContentType).Boundary).Value; @@ -151,6 +151,34 @@ namespace IRaCIS.Core.API.Controllers return ResponseOutput.Ok(); } + + + [HttpGet("CommonDocument/DownloadCommonDoc")] + public async Task DownloadCommonFile(string code, [FromServices] IRepository _commonDocumentRepository) + { + var doc = _commonDocumentRepository.AsQueryable(true).FirstOrDefault(t => t.Code == code); + + if (doc==null) + { + throw new Exception("当前code 没要找到对应的文件"); + } + + var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\')).FullName; + + var filePath = Path.Combine(rootPath, doc.Path); + + if (!System.IO.File.Exists(filePath)) + { + throw new Exception("服务器本地不存在该路径文件"); + } + + + var stream = System.IO.File.OpenRead(filePath); + return File(stream, "application/octet-stream", Path.GetFileName(doc.Name)); + + } + + private void DealCommonStorePath(string fileType, string moduleType, string fileRealName, out string serverFilePath, out string relativePath) { var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\')).FullName; diff --git a/IRaCIS.Core.Application/Service/Common/CommonDocumentService.cs b/IRaCIS.Core.Application/Service/Common/CommonDocumentService.cs index 947957c6d..65d1fc3fb 100644 --- a/IRaCIS.Core.Application/Service/Common/CommonDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Common/CommonDocumentService.cs @@ -33,7 +33,7 @@ namespace IRaCIS.Core.Application.Service .WhereIf(queryCommonDocument.FileTypeId != null, t => t.FileTypeId == queryCommonDocument.FileTypeId) .WhereIf( string.IsNullOrEmpty(queryCommonDocument.Code) , t => t.Code.Contains(queryCommonDocument.Code) ) .WhereIf(string.IsNullOrEmpty(queryCommonDocument.Name), t => t.Name.Contains(queryCommonDocument.Name)) - .ProjectTo(_mapper.ConfigurationProvider); + .ProjectTo(_mapper.ConfigurationProvider,new { token = _userInfo.UserToken, userId = _userInfo.Id }); return await commonDocumentQueryable.ToListAsync(); } @@ -57,5 +57,6 @@ namespace IRaCIS.Core.Application.Service + } } diff --git a/IRaCIS.Core.Application/Service/Common/DTO/CommonDocumentViewModel.cs b/IRaCIS.Core.Application/Service/Common/DTO/CommonDocumentViewModel.cs index 38f4ee9be..fa29a9ae7 100644 --- a/IRaCIS.Core.Application/Service/Common/DTO/CommonDocumentViewModel.cs +++ b/IRaCIS.Core.Application/Service/Common/DTO/CommonDocumentViewModel.cs @@ -15,6 +15,8 @@ namespace IRaCIS.Core.Application.ViewModel public string FileType { get; set; } = String.Empty; public string ModuleType { get; set; } = String.Empty; + public string FullFilePath { get; set; } + public DateTime? DeletedTime { get; set; } public DateTime CreateTime { get; set; } diff --git a/IRaCIS.Core.Application/Service/Common/_MapConfig.cs b/IRaCIS.Core.Application/Service/Common/_MapConfig.cs index e4b5dccf4..b597eb064 100644 --- a/IRaCIS.Core.Application/Service/Common/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Common/_MapConfig.cs @@ -42,10 +42,11 @@ namespace IRaCIS.Core.Application.Service CreateMap() .ForMember(o => o.ParentCode, t => t.MapFrom(u => u.Parent.Code)); - + var token = ""; CreateMap() .ForMember(o => o.FileType, t => t.MapFrom(u => u.FileType.Value)) - .ForMember(o => o.ModuleType, t => t.MapFrom(u => u.ModuleType.Value)); + .ForMember(o => o.ModuleType, t => t.MapFrom(u => u.ModuleType.Value)) + .ForMember(d => d.FullFilePath, u => u.MapFrom(s => s.Path + "?access_token=" + token)); CreateMap().ReverseMap();