提供下载文件接口
parent
3adba866ba
commit
1556a9f2b0
|
@ -151,6 +151,34 @@ namespace IRaCIS.Core.API.Controllers
|
||||||
return ResponseOutput.Ok();
|
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)
|
private void DealCommonStorePath(string fileType, string moduleType, string fileRealName, out string serverFilePath, out string relativePath)
|
||||||
{
|
{
|
||||||
var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\')).FullName;
|
var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\')).FullName;
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
.WhereIf(queryCommonDocument.FileTypeId != null, t => t.FileTypeId == queryCommonDocument.FileTypeId)
|
.WhereIf(queryCommonDocument.FileTypeId != null, t => t.FileTypeId == queryCommonDocument.FileTypeId)
|
||||||
.WhereIf( string.IsNullOrEmpty(queryCommonDocument.Code) , t => t.Code.Contains(queryCommonDocument.Code) )
|
.WhereIf( string.IsNullOrEmpty(queryCommonDocument.Code) , t => t.Code.Contains(queryCommonDocument.Code) )
|
||||||
.WhereIf(string.IsNullOrEmpty(queryCommonDocument.Name), t => t.Name.Contains(queryCommonDocument.Name))
|
.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();
|
return await commonDocumentQueryable.ToListAsync();
|
||||||
}
|
}
|
||||||
|
@ -57,5 +57,6 @@ namespace IRaCIS.Core.Application.Service
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ namespace IRaCIS.Core.Application.ViewModel
|
||||||
public string FileType { get; set; } = String.Empty;
|
public string FileType { get; set; } = String.Empty;
|
||||||
public string ModuleType { get; set; } = String.Empty;
|
public string ModuleType { get; set; } = String.Empty;
|
||||||
|
|
||||||
|
public string FullFilePath { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public DateTime? DeletedTime { get; set; }
|
public DateTime? DeletedTime { get; set; }
|
||||||
public DateTime CreateTime { get; set; }
|
public DateTime CreateTime { get; set; }
|
||||||
|
|
|
@ -42,10 +42,11 @@ namespace IRaCIS.Core.Application.Service
|
||||||
CreateMap<Dictionary, BasicDicSelect>()
|
CreateMap<Dictionary, BasicDicSelect>()
|
||||||
.ForMember(o => o.ParentCode, t => t.MapFrom(u => u.Parent.Code));
|
.ForMember(o => o.ParentCode, t => t.MapFrom(u => u.Parent.Code));
|
||||||
|
|
||||||
|
var token = "";
|
||||||
CreateMap<CommonDocument, CommonDocumentView>()
|
CreateMap<CommonDocument, CommonDocumentView>()
|
||||||
.ForMember(o => o.FileType, t => t.MapFrom(u => u.FileType.Value))
|
.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();
|
CreateMap<CommonDocument, CommonDocumentAddOrEdit>().ReverseMap();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue