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
c9a93855
Commit
c9a93855
authored
Dec 31, 2021
by
lcx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加接口
parent
56d78a8f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
219 additions
and
0 deletions
+219
-0
performance/Performance.Api/Controllers/ExtractController.cs
+219
-0
No files found.
performance/Performance.Api/Controllers/ExtractController.cs
0 → 100644
View file @
c9a93855
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.StaticFiles
;
using
Microsoft.Extensions.DependencyInjection
;
using
Performance.DtoModels
;
using
Performance.EntityModels
;
using
Performance.Infrastructure
;
using
Performance.Services
;
using
Performance.Services.ExtractExcelService
;
using
Performance.Services.Queues
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Threading.Tasks
;
namespace
Performance.Api.Controllers
{
[
Route
(
"api/extract"
)]
[
ApiController
]
public
class
ExtractController
:
ControllerBase
{
private
readonly
ClaimService
_claim
;
private
readonly
AllotService
_allotService
;
private
readonly
CustomExtractService
_extractService
;
private
readonly
IServiceScopeFactory
_serviceScopeFactory
;
private
readonly
IBackgroundTaskQueue
_backgroundTaskQueue
;
private
readonly
IHubNotificationQueue
_notificationQueue
;
private
readonly
ExtractPreConfigService
_preConfigService
;
public
ExtractController
(
ClaimService
claim
,
AllotService
allotService
,
CustomExtractService
extractService
,
IServiceScopeFactory
serviceScopeFactory
,
IBackgroundTaskQueue
backgroundTaskQueue
,
IHubNotificationQueue
notificationQueue
,
ExtractPreConfigService
preConfigService
)
{
_claim
=
claim
;
_allotService
=
allotService
;
_extractService
=
extractService
;
_serviceScopeFactory
=
serviceScopeFactory
;
_backgroundTaskQueue
=
backgroundTaskQueue
;
_notificationQueue
=
notificationQueue
;
_preConfigService
=
preConfigService
;
}
#
region
自定义提取
/// <summary>
/// 自定义提取
/// </summary>
/// <param name="allotId"></param>
/// <returns></returns>
[
HttpPost
(
"custom/{allotId}"
)]
public
ApiResponse
CustomExtract
(
int
allotId
)
{
var
userId
=
_claim
.
GetUserId
();
if
(!
_extractService
.
CheckConfigScript
(
userId
,
allotId
))
return
new
ApiResponse
(
ResponseType
.
Fail
,
"未配置自定义抽取,请联系绩效管理人员。"
);
_backgroundTaskQueue
.
QueueBackgroundWorkItem
(
async
token
=>
{
using
(
var
scope
=
_serviceScopeFactory
.
CreateScope
())
{
var
scopedServices
=
scope
.
ServiceProvider
.
GetRequiredService
<
CustomExtractService
>();
var
scopedAllotService
=
scope
.
ServiceProvider
.
GetRequiredService
<
AllotService
>();
var
scopedQueue
=
scope
.
ServiceProvider
.
GetRequiredService
<
IHubNotificationQueue
>();
if
(
scopedServices
.
ExtractData
(
userId
,
allotId
,
out
string
resultFilePath
))
{
scopedAllotService
.
UpdateAllotCustomExtractPath
(
allotId
,
resultFilePath
);
scopedQueue
.
Send
(
new
Notification
(
allotId
,
"CustomDowoload"
,
new
CustomDownloadContent
(
"自定义数据提取数据成功,是否立即下载"
,
allotId
)));
}
else
{
scopedQueue
.
Send
(
new
Notification
(
allotId
,
"Notification"
,
new
TextContent
(
"自定义数据提取数据失败"
,
NotificationLevel
.
ERR
)));
}
await
Task
.
Delay
(
TimeSpan
.
FromSeconds
(
5
),
token
);
}
});
_notificationQueue
.
Send
(
new
Notification
(
allotId
,
"Notification"
,
new
TextContent
(
"自定义数据提取任务开始执行"
)));
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
);
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
));
}
#
endregion
#
region
医院数据库配置
[
HttpGet
(
"hospital/config/{hospitalId}"
)]
public
ApiResponse
<
List
<
sys_hospitalconfig
>>
GetHospitalConfig
([
FromRoute
]
int
hospitalId
)
{
if
(
hospitalId
==
0
)
return
new
ApiResponse
<
List
<
sys_hospitalconfig
>>(
ResponseType
.
ParameterError
,
"参数错误"
);
var
list
=
_preConfigService
.
GetHospitalConfig
(
hospitalId
);
return
new
ApiResponse
<
List
<
sys_hospitalconfig
>>(
ResponseType
.
OK
,
list
);
}
[
HttpPost
(
"hospital/config/create"
)]
public
ApiResponse
CreateHospitalConfig
([
FromBody
]
sys_hospitalconfig
hospitalconfig
)
{
if
(
hospitalconfig
==
null
)
return
new
ApiResponse
(
ResponseType
.
ParameterError
,
"参数错误"
);
var
flag
=
_preConfigService
.
CreateHospitalConfig
(
hospitalconfig
);
return
flag
?
new
ApiResponse
(
ResponseType
.
OK
,
"添加成功"
)
:
new
ApiResponse
(
ResponseType
.
Fail
,
"添加失败"
);
}
[
HttpPost
(
"hospital/config/update"
)]
public
ApiResponse
UpdateHospitalConfig
([
FromBody
]
sys_hospitalconfig
hospitalconfig
)
{
if
(
hospitalconfig
==
null
)
return
new
ApiResponse
(
ResponseType
.
ParameterError
,
"参数错误"
);
var
flag
=
_preConfigService
.
UpdateHospitalConfig
(
hospitalconfig
);
return
flag
?
new
ApiResponse
(
ResponseType
.
OK
,
"添加成功"
)
:
new
ApiResponse
(
ResponseType
.
Fail
,
"添加失败"
);
}
[
HttpPost
(
"hospital/config/{hospitalId}"
)]
public
ApiResponse
DeleteHospitalConfig
([
FromRoute
]
int
hospitalId
)
{
if
(
hospitalId
==
0
)
return
new
ApiResponse
(
ResponseType
.
ParameterError
,
"参数错误"
);
var
flag
=
_preConfigService
.
DeleteHospitalConfig
(
hospitalId
);
return
flag
?
new
ApiResponse
(
ResponseType
.
OK
,
"添加成功"
)
:
new
ApiResponse
(
ResponseType
.
Fail
,
"添加失败"
);
}
[
HttpPost
(
"hospital/connection/{hospitalId}"
)]
public
ApiResponse
TestConnectionCleared
([
FromRoute
]
int
hospitalId
)
{
if
(
hospitalId
==
0
)
return
new
ApiResponse
(
ResponseType
.
ParameterError
,
"参数错误"
);
var
flag
=
_preConfigService
.
TestConnectionCleared
(
hospitalId
);
return
flag
?
new
ApiResponse
(
ResponseType
.
OK
,
"连接成功"
)
:
new
ApiResponse
(
ResponseType
.
Fail
,
"连接成功"
);
}
#
endregion
#
region
提取
script
配置
[
HttpGet
(
"type"
)]
public
ApiResponse
GetExtractTypeAndScript
([
FromBody
]
ExTypeRequest
request
)
{
if
(
request
==
null
)
return
new
ApiResponse
(
ResponseType
.
ParameterError
,
"参数错误"
);
var
list
=
_preConfigService
.
GetExtractTypeAndScript
(
request
);
return
new
ApiResponse
(
ResponseType
.
OK
,
list
);
}
[
HttpGet
(
"type/{typeId}"
)]
public
ApiResponse
GetExtractTypeAndScriptById
([
FromRoute
]
int
typeId
)
{
if
(
typeId
==
0
)
return
new
ApiResponse
(
ResponseType
.
ParameterError
,
"参数错误"
);
var
data
=
_preConfigService
.
GetExtractTypeAndScriptById
(
typeId
);
return
new
ApiResponse
(
ResponseType
.
OK
,
data
);
}
[
HttpPost
(
"type/{typeId}"
)]
public
ApiResponse
DeleteExtractTypeAndScript
([
FromRoute
]
int
typeId
)
{
if
(
typeId
==
0
)
return
new
ApiResponse
(
ResponseType
.
ParameterError
,
"参数错误"
);
var
flag
=
_preConfigService
.
DeleteExtractTypeAndScript
(
typeId
);
return
flag
?
new
ApiResponse
(
ResponseType
.
OK
,
"删除成功"
)
:
new
ApiResponse
(
ResponseType
.
Fail
,
"删除失败"
);
}
[
HttpPost
(
"type/{typeId}/edit"
)]
public
ApiResponse
EditExtractTypeAndScript
([
FromRoute
]
int
typeId
,
[
FromBody
]
ExtractConfigResponse
request
)
{
if
(
typeId
==
0
)
return
new
ApiResponse
(
ResponseType
.
ParameterError
,
"参数错误"
);
var
flag
=
_preConfigService
.
EditExtractTypeAndScript
(
typeId
,
request
);
return
flag
?
new
ApiResponse
(
ResponseType
.
OK
,
"编辑成功"
)
:
new
ApiResponse
(
ResponseType
.
Fail
,
"编辑失败"
);
}
[
HttpPost
(
"type/{typeId}/querytime"
)]
public
ApiResponse
CheckExecsqlConsumeTime
([
FromBody
]
ConsumeTimeRequest
request
)
{
if
(
request
==
null
)
return
new
ApiResponse
(
ResponseType
.
ParameterError
,
"参数错误"
);
var
flag
=
_preConfigService
.
CheckExecsqlConsumeTime
(
request
);
return
new
ApiResponse
(
ResponseType
.
OK
,
flag
);
}
#
endregion
}
}
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