Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
performance
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zry
performance
Commits
3c68762c
Commit
3c68762c
authored
Nov 26, 2020
by
ruyun.zhang@suvalue.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
自定义抽取对接调整
parent
ec440f37
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
17 deletions
+71
-17
performance/Performance.Api/Controllers/ModExtractController.cs
+38
-2
performance/Performance.Api/Program.cs
+1
-0
performance/Performance.Api/Startup.cs
+15
-15
performance/Performance.Api/wwwroot/Performance.Api.xml
+6
-0
performance/Performance.Services/Queues/IHubNotificationQueue.cs
+11
-0
No files found.
performance/Performance.Api/Controllers/ModExtractController.cs
View file @
3c68762c
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
performance/Performance.Api/Program.cs
View file @
3c68762c
...
...
@@ -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
>();
}
}
performance/Performance.Api/Startup.cs
View file @
3c68762c
...
...
@@ -155,15 +155,15 @@ public void ConfigureServices(IServiceCollection services)
services
.
AddSingleton
<
IBackgroundTaskQueue
,
BackgroundTaskQueue
>();
services
.
AddSingleton
<
IHubNotificationQueue
,
HubNotificationQueue
>();
//
#region hangfire
//
//
services.AddHangfire(config =>
//
{
//
config.UseFilter(new AutomaticRetryAttribute { Attempts = 0 });
//
config.UseStorage(new MySqlStorage(connection.Value.HangfireConnectionString));
//
});
//
//
#endregion hangfire
//#region hangfire
//services.AddHangfire(config =>
//{
// config.UseFilter(new AutomaticRetryAttribute { Attempts = 0 });
// config.UseStorage(new MySqlStorage(connection.Value.HangfireConnectionString));
//});
//#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"
));
...
...
performance/Performance.Api/wwwroot/Performance.Api.xml
View file @
3c68762c
...
...
@@ -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>
原始数据修改
...
...
performance/Performance.Services/Queues/IHubNotificationQueue.cs
View file @
3c68762c
...
...
@@ -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
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment