Commit 4461671b authored by 黄奎's avatar 黄奎

文件下载修改

parent d622af05
...@@ -2146,10 +2146,8 @@ namespace Mall.WebApi.Controllers.TradePavilion ...@@ -2146,10 +2146,8 @@ namespace Mall.WebApi.Controllers.TradePavilion
demodel.MallBaseId = RequestParm.MallBaseId; demodel.MallBaseId = RequestParm.MallBaseId;
demodel.TenantId = RequestParm.TenantId; demodel.TenantId = RequestParm.TenantId;
List<int> ExcelEnumIds = JsonConvert.DeserializeObject<List<int>>(parms.GetStringValue("ExcelEnumIds")); List<int> ExcelEnumIds = JsonConvert.DeserializeObject<List<int>>(parms.GetStringValue("ExcelEnumIds"));
string hashKey = Common.Config.GetHash(Common.Plugin.JsonHelper.Serialize(demodel)); string hashKey = Common.Config.GetHash(Common.Plugin.JsonHelper.Serialize(demodel) + parms.GetStringValue("ExcelEnumIds"));
string fileName = hashKey + ".xls"; string fileName = "品牌信息" + ".xls";
string filePath = Path.Combine(Directory.GetCurrentDirectory(), "upfile/temporary"); string filePath = Path.Combine(Directory.GetCurrentDirectory(), "upfile/temporary");
if (System.IO.Directory.Exists(filePath) == false)//如果不存在就创建file文件夹 if (System.IO.Directory.Exists(filePath) == false)//如果不存在就创建file文件夹
{ {
...@@ -2169,8 +2167,11 @@ namespace Mall.WebApi.Controllers.TradePavilion ...@@ -2169,8 +2167,11 @@ namespace Mall.WebApi.Controllers.TradePavilion
redisValue = redisHelper.StringGet(key); redisValue = redisHelper.StringGet(key);
if (string.IsNullOrEmpty(redisValue)) if (string.IsNullOrEmpty(redisValue))
{ {
redisHelper.StringSet(key, fileName, TimeSpan.FromMinutes(30)); redisHelper.StringSet(key, fileName, TimeSpan.FromMinutes(10));
GetBrandListToExcel(demodel, ExcelEnumIds, tempPath, fileUrl); Task.Run(() =>
{
GetBrandListToExcel(demodel, ExcelEnumIds, tempPath, fileUrl);
});
} }
} }
return await Task.Run<ApiResult>(() => return await Task.Run<ApiResult>(() =>
...@@ -2227,16 +2228,15 @@ namespace Mall.WebApi.Controllers.TradePavilion ...@@ -2227,16 +2228,15 @@ namespace Mall.WebApi.Controllers.TradePavilion
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public FileContentResult GetFile() public async Task<FileContentResult> GetFile()
{ {
string ExcelName = "品牌列表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
JObject parms = JObject.Parse(RequestParm.msg.ToString()); JObject parms = JObject.Parse(RequestParm.msg.ToString());
string fileUrl = parms.GetStringValue("fileUrl"); string fileUrl = parms.GetStringValue("fileUrl");
string newPath = Directory.GetCurrentDirectory() + fileUrl; string newPath = Directory.GetCurrentDirectory() + fileUrl;
if (System.IO.File.Exists(newPath)) if (System.IO.File.Exists(newPath))
{ {
byte[] fileBytes = System.IO.File.ReadAllBytes(newPath); var fileBytes = await System.IO.File.ReadAllBytesAsync(newPath);
return File(fileBytes, "application/octet-stream", ExcelName); return File(fileBytes, "application/octet-stream");
} }
else else
{ {
...@@ -2248,7 +2248,7 @@ namespace Mall.WebApi.Controllers.TradePavilion ...@@ -2248,7 +2248,7 @@ namespace Mall.WebApi.Controllers.TradePavilion
/// 品牌下载 /// 品牌下载
/// </summary> /// </summary>
private void GetBrandListToExcel(RB_Brand_Extend demodel, List<int> ExcelEnumIds,string filePath, string excelFileUrl) private async void GetBrandListToExcel(RB_Brand_Extend demodel, List<int> ExcelEnumIds,string filePath, string excelFileUrl)
{ {
try try
{ {
......
...@@ -24,10 +24,11 @@ namespace Mall.WebApi ...@@ -24,10 +24,11 @@ namespace Mall.WebApi
webBuilder.ConfigureKestrel((context, options) => webBuilder.ConfigureKestrel((context, options) =>
{ {
options.AllowSynchronousIO = true; options.AllowSynchronousIO = true;
//设置应用服务器Kestrel请求体最大为50MB //设置应用服务器Kestrel请求体最大为100MB
options.Limits.MaxRequestBodySize = 52428800; options.Limits.MaxRequestBodySize = 104857600;
//解决并发异常 //解决并发异常
options.Limits.MinRequestBodyDataRate = null; options.Limits.MinRequestBodyDataRate = null;
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2);
}); });
webBuilder.UseStartup<Startup>().UseIIS(); webBuilder.UseStartup<Startup>().UseIIS();
}); });
......
...@@ -41,8 +41,13 @@ namespace Mall.WebApi ...@@ -41,8 +41,13 @@ namespace Mall.WebApi
/// <param name="services"></param> /// <param name="services"></param>
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(x => x.AllowSynchronousIO = true) services.Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(x =>
.Configure<IISServerOptions>(x => x.AllowSynchronousIO = true); {
x.AllowSynchronousIO = true;
x.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2);
})
.Configure<IISServerOptions>(x => { x.AllowSynchronousIO = true; })
;
services.AddControllers(); services.AddControllers();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); //注入http上下文 services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); //注入http上下文
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment