提供下载文件接口

Uat_Study
hang 2022-04-01 15:35:27 +08:00
parent 3adba866ba
commit 1556a9f2b0
4 changed files with 36 additions and 4 deletions

View File

@ -119,7 +119,7 @@ namespace IRaCIS.Core.API.Controllers
[HttpPost("CommonDocument/UploadCommonDoc/{fileType}/{moduleType}")]
[DisableRequestSizeLimit]
[DisableFormValueModelBinding]
public async Task<IResponseOutput> UploadCommonDoc(string fileType,string moduleType)
public async Task<IResponseOutput> 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<IActionResult> DownloadCommonFile(string code, [FromServices] IRepository<CommonDocument> _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;

View File

@ -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<CommonDocumentView>(_mapper.ConfigurationProvider);
.ProjectTo<CommonDocumentView>(_mapper.ConfigurationProvider,new { token = _userInfo.UserToken, userId = _userInfo.Id });
return await commonDocumentQueryable.ToListAsync();
}
@ -57,5 +57,6 @@ namespace IRaCIS.Core.Application.Service
}
}

View File

@ -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; }

View File

@ -42,10 +42,11 @@ namespace IRaCIS.Core.Application.Service
CreateMap<Dictionary, BasicDicSelect>()
.ForMember(o => o.ParentCode, t => t.MapFrom(u => u.Parent.Code));
var token = "";
CreateMap<CommonDocument, CommonDocumentView>()
.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<CommonDocument, CommonDocumentAddOrEdit>().ReverseMap();