自定义抽取对接调整

parent ec440f37
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Performance.DtoModels;
using Performance.Infrastructure;
using Performance.Services;
using Performance.Services.Queues;
using System;
using System.IO;
using System.Threading.Tasks;
namespace Performance.Api.Controllers
......@@ -13,17 +17,20 @@ namespace Performance.Api.Controllers
public class ModExtractController : Controller
{
private readonly ClaimService _claim;
private readonly AllotService _allotService;
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly IHubNotificationQueue _notificationQueue;
private readonly IBackgroundTaskQueue _backgroundTaskQueue;
public ModExtractController(
ClaimService claim,
AllotService allotService,
IServiceScopeFactory serviceScopeFactory,
IHubNotificationQueue notificationQueue,
IBackgroundTaskQueue backgroundTaskQueue)
{
_claim = claim;
_allotService = allotService;
_serviceScopeFactory = serviceScopeFactory;
_notificationQueue = notificationQueue;
_backgroundTaskQueue = backgroundTaskQueue;
......@@ -43,8 +50,8 @@ public ApiResponse CustomExtract(int allotId)
if (scopedServices.ExtractData(userId, allotId, out string resultFilePath))
{
scopedQueue.Send(new Notification(allotId, "Notification", new UrlContent("自定义数据提取数据成功", resultFilePath)));
scopedAllotService.UpdateAllotCustomExtractPath(allotId, resultFilePath);
scopedQueue.Send(new Notification(allotId, "CustomDowoload", new CustomDownloadContent("自定义数据提取数据成功,是否立即下载", allotId)));
}
else
{
......@@ -59,5 +66,33 @@ public ApiResponse CustomExtract(int allotId)
return new ApiResponse(ResponseType.OK);
}
/// <summary>
/// 从WebAPI下载文件
/// </summary>
/// <returns></returns>
[Route("down/{allotId}")]
[HttpGet]
[AllowAnonymous]
public IActionResult DownFile(int allotId)
{
var allot = _allotService.GetAllot(allotId);
allot.CustomExtractPath = @"E:\code_git\performance\performance\Performance.Api\bin\Debug\netcoreapp2.2\Files\2\autoextract\绩效提取数据20201126105808609.xls";
if (allot == null || string.IsNullOrWhiteSpace(allot.CustomExtractPath) || !FileHelper.IsExistFile(allot.CustomExtractPath))
{
return new ObjectResult(new ApiResponse(ResponseType.Fail, "文件不存在"));
}
var memoryStream = new MemoryStream();
using (var stream = new FileStream(allot.CustomExtractPath, FileMode.Open))
{
stream.CopyToAsync(memoryStream).Wait();
}
memoryStream.Seek(0, SeekOrigin.Begin);
string fileExt = Path.GetExtension(allot.CustomExtractPath);
var provider = new FileExtensionContentTypeProvider();
var memi = provider.Mappings[fileExt];
return File(memoryStream, memi, Path.GetFileName(allot.CustomExtractPath));
}
}
}
\ No newline at end of file
......@@ -27,6 +27,7 @@ public static void Main(string[] args)
config.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true, true);
env.ConfigureNLog("nlog.config");
})
.UseUrls("http://*:5001")
.UseStartup<Startup>();
}
}
......@@ -155,15 +155,15 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton<IBackgroundTaskQueue, BackgroundTaskQueue>();
services.AddSingleton<IHubNotificationQueue, HubNotificationQueue>();
// #region hangfire
//
// services.AddHangfire(config =>
// {
//#region hangfire
//services.AddHangfire(config =>
//{
// config.UseFilter(new AutomaticRetryAttribute { Attempts = 0 });
// config.UseStorage(new MySqlStorage(connection.Value.HangfireConnectionString));
// });
//
// #endregion hangfire
//});
//#endregion hangfire
services.AddSignalR();
services.AddCors(options =>
......@@ -245,12 +245,12 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
#endregion Swagger
// #region hangfire
//
// app.UseHangfireServer();
// app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new HangfireAuthorizationFilter() } });
//
// #endregion hangfire
//#region hangfire
//app.UseHangfireServer();
//app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new HangfireAuthorizationFilter() } });
//#endregion hangfire
app.UseCors("SignalrCore");
app.UseSignalR(routes => routes.MapHub<AllotLogHub>("/performance/allotLogHub"));
......
......@@ -937,6 +937,12 @@
</summary>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ModExtractController.DownFile(System.Int32)">
<summary>
从WebAPI下载文件
</summary>
<returns></returns>
</member>
<member name="T:Performance.Api.Controllers.OriginalController">
<summary>
原始数据修改
......
......@@ -118,4 +118,15 @@ public UrlContent(string subject, string url, NotificationLevel level = Notifica
public string Content { get; set; }
public override string Type => "Url";
}
public class CustomDownloadContent : Notification.PushContent
{
public CustomDownloadContent(string subject,object @object ,NotificationLevel level = NotificationLevel.INF)
: base(subject, level)
{
Arguments = @object;
}
public override string Type => "CustomDownload";
public object Arguments { get; set; }
}
}
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