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
934df22c
Commit
934df22c
authored
Jan 20, 2021
by
lcx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
后端http请求统一使用restsharp
parent
46d49c12
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
300 additions
and
188 deletions
+300
-188
performance/Performance.Api/Controllers/ExConfigController.cs
+22
-12
performance/Performance.Api/Controllers/TemplateController.cs
+57
-39
performance/Performance.Api/wwwroot/Performance.Api.xml
+3
-10
performance/Performance.Api/wwwroot/Performance.DtoModels.xml
+15
-0
performance/Performance.DtoModels/Request/ExtractRequest.cs
+8
-1
performance/Performance.DtoModels/Request/SignalrLogRequest.cs
+19
-0
performance/Performance.Extract.Api/Controllers/ExtractController.cs
+59
-124
performance/Performance.Infrastructure/Helper/RestSharpHelper.cs
+101
-0
performance/Performance.Services/LogManageService.cs
+16
-2
No files found.
performance/Performance.Api/Controllers/ExConfigController.cs
View file @
934df22c
...
...
@@ -17,17 +17,18 @@ namespace Performance.Api.Controllers
[
ApiController
]
public
class
ExConfigController
:
Controller
{
private
readonly
ILogger
<
ExConfigController
>
logger
;
private
ILogger
logger
;
private
WebapiUrl
options
;
private
ExConfigService
configService
;
private
WebapiUrl
url
;
public
ExConfigController
(
ILogger
<
ExConfigController
>
logger
,
ExConfigService
configService
,
IOptions
<
WebapiUrl
>
url
)
IOptions
<
WebapiUrl
>
options
,
ExConfigService
configService
)
{
this
.
logger
=
logger
;
this
.
options
=
options
.
Value
;
this
.
configService
=
configService
;
this
.
url
=
url
.
Value
;
}
/// <summary>
...
...
@@ -70,8 +71,11 @@ public ApiResponse FeeSource([FromBody] ModModuleRequest request)
if
(
request
.
HospitalId
==
null
||
request
.
HospitalId
.
Value
==
0
)
return
new
ApiResponse
(
ResponseType
.
ParameterError
,
"HospitalId 参数错误!"
);
string
retJson
=
HttpHelper
.
HttpPost
(
url
.
HttpPost
+
"/modextract/source"
,
JsonHelper
.
Serialize
(
request
),
true
);
var
ret
=
JsonHelper
.
Deserialize
<
ApiResponse
>(
retJson
);
var
http
=
new
RestSharpHelper
();
var
url
=
http
.
SetUrl
(
options
.
HttpPost
,
"/modextract/source"
);
var
req
=
http
.
CreatePostRequest
(
JsonHelper
.
Serialize
(
request
));
var
res
=
http
.
GetResponse
(
url
,
req
);
var
ret
=
http
.
GetContent
<
ApiResponse
>(
res
);
return
new
ApiResponse
(
ResponseType
.
OK
,
ret
.
Data
);
}
...
...
@@ -166,8 +170,14 @@ public ApiResponse Items([FromBody] ModItemRequest request)
if
(
sheetType
==
(
int
)
SheetType
.
Income
)
{
logger
.
LogInformation
(
$"绩效收入模板配置项列表 : 请求地址
{
url
.
HttpPost
}
/modextract/items"
);
HttpHelper
.
HttpPost
(
url
.
HttpPost
+
"/modextract/items"
,
JsonHelper
.
Serialize
(
request
),
true
);
logger
.
LogInformation
(
$"绩效收入模板配置项列表 : 请求地址
{
options
.
HttpPost
}
/modextract/items"
);
var
http
=
new
RestSharpHelper
();
var
url
=
http
.
SetUrl
(
options
.
HttpPost
,
"/modextract/items"
);
var
req
=
http
.
CreatePostRequest
(
JsonHelper
.
Serialize
(
request
));
var
res
=
http
.
GetResponse
(
url
,
req
);
var
ret
=
http
.
GetContent
<
ApiResponse
>(
res
);
logger
.
LogInformation
(
$"绩效收入模板配置项列表在
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd hh:mm:ss完成请求"
)}
"
);
}
var
list
=
configService
.
QueryItems
(
request
.
ModuleId
.
Value
);
...
...
@@ -204,8 +214,8 @@ public ApiResponse DelItem([FromBody] ModItemRequest request)
return
new
ApiResponse
(
ResponseType
.
OK
,
"删除成功!"
);
}
#
region
特殊科室模板
/// <summary>
/// 特殊科室模板配置项新增
/// </summary>
...
...
@@ -266,7 +276,6 @@ public ApiResponse DelSpecial([FromBody] ModSpecialRequest request)
return
new
ApiResponse
(
ResponseType
.
OK
,
"删除成功!"
);
}
/// <summary>
/// 特殊科室人均
/// </summary>
...
...
@@ -278,7 +287,8 @@ public ApiResponse PerforType()
var
list
=
configService
.
PerforType
();
return
new
ApiResponse
(
ResponseType
.
OK
,
list
);
}
#
endregion
#
endregion
特殊科室模板
/// <summary>
/// 数据配置项
...
...
performance/Performance.Api/Controllers/TemplateController.cs
View file @
934df22c
...
...
@@ -18,6 +18,7 @@
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
Performance.Api.Controllers
{
...
...
@@ -79,15 +80,19 @@ public IActionResult DownFile(int type = 1)
case
1
:
path
=
Path
.
Combine
(
env
.
ContentRootPath
,
"Template"
,
"医院绩效模板.xls"
);
break
;
case
2
:
path
=
Path
.
Combine
(
env
.
ContentRootPath
,
"Template"
,
"医院二次分配绩效模板.xlsx"
);
break
;
case
3
:
path
=
Path
.
Combine
(
env
.
ContentRootPath
,
"Template"
,
"医院绩效模板(无执行科室).xlsx"
);
break
;
case
4
:
path
=
Path
.
Combine
(
env
.
ContentRootPath
,
"Template"
,
"医院人员绩效模板.xls"
);
break
;
case
5
:
path
=
Path
.
Combine
(
env
.
ContentRootPath
,
"Template"
,
"工作量数据导入模板.xls"
);
break
;
...
...
@@ -158,6 +163,7 @@ public ApiResponse Import([FromForm] IFormCollection form)
}
#
region
老版提取
///// <summary>
///// 提取绩效数据
///// </summary>
...
...
@@ -218,9 +224,11 @@ public ApiResponse Import([FromForm] IFormCollection form)
// throw ex;
// }
//}
#
endregion
#
endregion
老版提取
#
region
新版提取
/// <summary>
/// 提取绩效数据
/// </summary>
...
...
@@ -254,11 +262,22 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody] ExtractRequest
}
else
{
logger
.
LogInformation
(
"提取绩效数据请求路径:"
+
url
.
HttpPost
+
"/extract/extract"
);
if
(
string
.
IsNullOrEmpty
(
filePath
))
HttpHelper
.
HttpPostNoRequest
(
url
.
HttpPost
+
$"/extract/extract?allotId=
{
request
.
AllotId
}
&hospitalId=
{
request
.
HospitalId
}
&email=
{
email
}
&userId=
{
claim
.
GetUserId
()}
"
,
""
);
else
HttpHelper
.
HttpClient
(
url
.
HttpPost
+
$"/extract/extract?allotId=
{
request
.
AllotId
}
&hospitalId=
{
request
.
HospitalId
}
&email=
{
email
}
&userId=
{
claim
.
GetUserId
()}
"
,
filePath
,
true
);
var
http
=
new
RestSharpHelper
();
string
endpoint
=
"/extract/extract"
;
var
extractUrl
=
http
.
SetUrl
(
url
.
HttpPost
,
endpoint
);
var
obj
=
new
{
allotId
=
request
.
AllotId
,
hospitalId
=
request
.
HospitalId
,
email
=
email
,
userId
=
claim
.
GetUserId
()
};
string
json
=
JsonHelper
.
Serialize
(
obj
);
var
parameter
=
JsonHelper
.
Deserialize
<
Dictionary
<
string
,
object
>>(
json
);
var
restRequest
=
string
.
IsNullOrEmpty
(
filePath
)
?
http
.
CreatePostRequest
(
json
)
:
http
.
CreateFileRequest
(
new
string
[]
{
filePath
},
parameter
);
Task
.
Run
(()
=>
http
.
GetResponse
(
extractUrl
,
restRequest
));
}
return
new
ApiResponse
(
ResponseType
.
OK
,
"HIS绩效数据提取任务正在执行,稍后我们将以邮件的通知您!"
,
new
{
IsExtracting
=
false
});
...
...
@@ -281,8 +300,8 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody] ExtractRequest
// B 使用配置作为模板
}
#
endregion
#
endregion
新版提取
/// <summary>
/// 从WebAPI下载文件
...
...
@@ -314,26 +333,31 @@ public IActionResult DownFile([FromQuery] AllotRequest request)
/// <summary>
/// 保存提取文件
/// </summary>
/// <param name="form"></param>
/// <param name="allotId"></param>
/// <param name="hospitalId"></param>
/// <returns></returns>
[
Route
(
"savefile"
)]
[
HttpPost
]
[
AllowAnonymous
]
public
ApiResponse
SaveFile
(
[
FromForm
]
IFormCollection
form
,
int
allotId
,
int
hospitalId
)
public
ApiResponse
SaveFile
()
{
logger
.
LogInformation
(
$"保存提取文件请求参数:allotId:
{
allotId
}
hospitalId:
{
hospitalId
}
"
);
try
Dictionary
<
string
,
object
>
dict
=
new
Dictionary
<
string
,
object
>(
);
foreach
(
var
key
in
Request
.
Form
.
Keys
)
{
var
file
=
((
FormFileCollection
)
form
.
Files
).
FirstOrDefault
();
if
(
file
==
null
)
dict
.
Add
(
key
,
Request
.
Form
[
key
]);
}
string
json
=
JsonHelper
.
Serialize
(
dict
);
var
request
=
JsonHelper
.
Deserialize
<
ExtractRequest
>(
json
);
if
(
Request
.
Form
.
Files
==
null
||
!
Request
.
Form
.
Files
.
Any
())
{
logger
.
LogError
(
$"返回文件为空!"
);
return
new
ApiResponse
(
ResponseType
.
Error
,
"上传文件无效"
);
}
var
dpath
=
Path
.
Combine
(
env
.
ContentRootPath
,
"Files"
,
$"
{
hospitalId
}
"
,
"autoextract"
);
logger
.
LogInformation
(
"保存提取文件请求参数:"
+
json
);
try
{
var
file
=
Request
.
Form
.
Files
[
0
];
var
dpath
=
Path
.
Combine
(
env
.
ContentRootPath
,
"Files"
,
$"
{
request
.
HospitalId
}
"
,
"autoextract"
);
FileHelper
.
CreateDirectory
(
dpath
);
var
path
=
Path
.
Combine
(
dpath
,
FileHelper
.
GetFileName
(
file
.
FileName
));
...
...
@@ -349,24 +373,22 @@ public ApiResponse SaveFile([FromForm] IFormCollection form, int allotId, int ho
return
new
ApiResponse
(
ResponseType
.
Error
,
"保存失败"
);
}
}
var
allot
=
allotService
.
GetAllot
(
a
llotId
);
var
allot
=
allotService
.
GetAllot
(
request
.
A
llotId
);
allot
.
ExtractPath
=
path
;
allot
.
IsExtracting
=
2
;
if
(
string
.
IsNullOrEmpty
(
path
)
||
!
FileHelper
.
IsExistFile
(
path
))
{
logger
.
LogInformation
(
$"保存提取文件文件未保存成功,保存文件不存在!"
);
return
new
ApiResponse
(
ResponseType
.
Fail
,
"上传成功!"
);
}
if
(!
allotService
.
Update
(
allot
))
{
logger
.
LogInformation
(
$"保存提取文件更新文件路径失败!"
);
return
new
ApiResponse
(
ResponseType
.
Fail
,
"上传成功!"
);
}
return
new
ApiResponse
(
ResponseType
.
OK
,
"上传成功!"
);
string
success
=
"上传成功!"
;
string
message
=
(
string
.
IsNullOrEmpty
(
path
)
||
!
FileHelper
.
IsExistFile
(
path
))
?
"保存提取文件文件未保存成功,保存文件不存在!"
:
(!
allotService
.
Update
(
allot
))
?
"保存提取文件更新文件路径失败!"
:
success
;
if
(
message
==
success
)
return
new
ApiResponse
(
ResponseType
.
OK
,
message
);
else
return
new
ApiResponse
(
ResponseType
.
Fail
,
message
);
}
catch
(
Exception
ex
)
{
logger
.
LogInformation
(
$"保存提取文件异常
{
ex
.
ToString
()}
"
);
logger
.
LogError
(
$"保存提取文件保存失败:"
+
ex
.
ToString
());
return
new
ApiResponse
(
ResponseType
.
Error
,
ex
.
Message
);
}
...
...
@@ -375,24 +397,20 @@ public ApiResponse SaveFile([FromForm] IFormCollection form, int allotId, int ho
/// <summary>
/// 返回日志
/// </summary>
/// <param name="type">1 进度条 2 信息</param>
/// <param name="tag"></param>
/// <param name="message"></param>
/// <param name="level"></param>
/// <param name="groupName"></param>
/// <param name="request"></param>
[
Route
(
"returnlog"
)]
[
HttpPost
]
[
AllowAnonymous
]
public
void
ReturnLog
(
int
type
,
string
tag
,
string
message
,
int
level
,
string
groupName
)
public
void
ReturnLog
(
[
FromBody
]
SignalrLogRequest
request
)
{
logger
.
LogInformation
(
"返回日志:"
+
JsonHelper
.
Serialize
(
new
{
type
,
tag
,
message
,
level
,
groupName
}
));
if
(
t
ype
==
3
)
logger
.
LogInformation
(
"返回日志:"
+
JsonHelper
.
Serialize
(
request
));
if
(
request
.
T
ype
==
3
)
{
logService
.
Schedule
(
groupName
,
ConvertHelper
.
To
<
decimal
>(
message
),
l
evel
);
logService
.
Schedule
(
request
.
GroupName
,
ConvertHelper
.
To
<
decimal
>(
request
.
Message
),
request
.
L
evel
);
}
else
{
logService
.
ExtractLog
(
groupName
,
tag
,
message
,
l
evel
);
logService
.
ExtractLog
(
request
.
GroupName
,
request
.
Tag
,
request
.
Message
,
request
.
L
evel
);
}
}
...
...
performance/Performance.Api/wwwroot/Performance.Api.xml
View file @
934df22c
...
...
@@ -1310,24 +1310,17 @@
</summary>
<returns></returns>
</member>
<member
name=
"M:Performance.Api.Controllers.TemplateController.SaveFile
(Microsoft.AspNetCore.Http.IFormCollection,System.Int32,System.Int32)
"
>
<member
name=
"M:Performance.Api.Controllers.TemplateController.SaveFile"
>
<summary>
保存提取文件
</summary>
<param
name=
"form"
></param>
<param
name=
"allotId"
></param>
<param
name=
"hospitalId"
></param>
<returns></returns>
</member>
<member
name=
"M:Performance.Api.Controllers.TemplateController.ReturnLog(
System.Int32,System.String,System.String,System.Int32,System.String
)"
>
<member
name=
"M:Performance.Api.Controllers.TemplateController.ReturnLog(
Performance.DtoModels.SignalrLogRequest
)"
>
<summary>
返回日志
</summary>
<param
name=
"type"
>
1 进度条 2 信息
</param>
<param
name=
"tag"
></param>
<param
name=
"message"
></param>
<param
name=
"level"
></param>
<param
name=
"groupName"
></param>
<param
name=
"request"
></param>
</member>
<member
name=
"M:Performance.Api.Controllers.TemplateController.ReturnLog(Performance.EntityModels.log_dbug)"
>
<summary>
...
...
performance/Performance.Api/wwwroot/Performance.DtoModels.xml
View file @
934df22c
...
...
@@ -1970,6 +1970,16 @@
邮箱
</summary>
</member>
<member
name=
"P:Performance.DtoModels.ExtractRequest.GroupName"
>
<summary>
Signalr分组名称
</summary>
</member>
<member
name=
"P:Performance.DtoModels.ExtractRequest.UserId"
>
<summary>
用户Id
</summary>
</member>
<member
name=
"P:Performance.DtoModels.GuaranteeRequest.Id"
>
<summary>
</summary>
</member>
...
...
@@ -3011,6 +3021,11 @@
保底来源科室
</summary>
</member>
<member
name=
"P:Performance.DtoModels.HospitalResponse.IsOpenCMIPercent"
>
<summary>
是否开启科室CMI占比 1 启用 2 禁用
</summary>
</member>
<member
name=
"P:Performance.DtoModels.HospitalResponse.IsOpenNursingDeptAudit"
>
<summary>
是否开启护理部审核 1 启用 2 禁用
...
...
performance/Performance.DtoModels/Request/ExtractRequest.cs
View file @
934df22c
...
...
@@ -27,9 +27,16 @@ public class ExtractRequest
/// </summary>
public
string
Email
{
get
;
set
;
}
/// <summary>
/// Signalr分组名称
/// </summary>
public
string
GroupName
{
get
;
set
;
}
}
/// <summary>
/// 用户Id
/// </summary>
public
int
UserId
{
get
;
set
;
}
}
public
class
ExtractRequestValidator
:
AbstractValidator
<
ExtractRequest
>
{
...
...
performance/Performance.DtoModels/Request/SignalrLogRequest.cs
0 → 100644
View file @
934df22c
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Performance.DtoModels
{
public
class
SignalrLogRequest
{
public
int
Type
{
get
;
set
;
}
public
string
Tag
{
get
;
set
;
}
public
string
Message
{
get
;
set
;
}
public
int
Level
{
get
;
set
;
}
public
string
GroupName
{
get
;
set
;
}
}
}
performance/Performance.Extract.Api/Controllers/ExtractController.cs
View file @
934df22c
using
FluentValidation.AspNetCore
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Http.Internal
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.StaticFiles
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Options
;
using
Performance.DtoModels
;
using
Performance.DtoModels.AppSettings
;
using
Performance.Infrastructure
;
using
Performance.Services
;
using
Performance.Services.ExtractExcelService
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
Performance.Extract.Api.Controllers
{
[
Route
(
"api/[controller]"
)]
public
class
ExtractController
:
Controller
{
private
readonly
DFExtractService
extractService
;
private
readonly
HospitalService
hospitalService
;
private
readonly
ExtractService
extractService1
;
private
readonly
WebapiUrl
url
;
private
readonly
ILogger
<
ExtractController
>
logger
;
private
readonly
IHostingEnvironment
evn
;
private
readonly
ILogger
logger
;
private
readonly
WebapiUrl
options
;
private
readonly
ExtractService
extractService1
;
public
ExtractController
(
DFExtractService
extractService
,
HospitalService
hospitalService
,
ExtractService
extractService1
,
IOptions
<
WebapiUrl
>
url
,
public
ExtractController
(
IHostingEnvironment
evn
,
ILogger
<
ExtractController
>
logger
,
IHostingEnvironment
evn
)
IOptions
<
WebapiUrl
>
options
,
ExtractService
extractService1
)
{
this
.
extractService
=
extractService
;
this
.
hospitalService
=
hospitalService
;
this
.
extractService1
=
extractService1
;
this
.
url
=
url
.
Value
;
this
.
logger
=
logger
;
this
.
evn
=
evn
;
this
.
logger
=
logger
;
this
.
options
=
options
.
Value
;
this
.
extractService1
=
extractService1
;
}
/// <summary>
/// 保存首次文件
/// </summary>
/// <param name="form"></param>
/// <param name="type">1、历史绩效文件 2、首次模板文件</param>
/// <param name="hospitalId"></param>
/// <returns></returns>
[
Route
(
"import"
)]
[
HttpPost
]
public
ApiResponse
Import
([
FromForm
]
IFormCollection
form
,
int
type
,
int
hospitalId
,
int
year
,
int
month
)
{
var
file
=
((
FormFileCollection
)
form
.
Files
).
FirstOrDefault
();
if
(
file
==
null
)
return
new
ApiResponse
(
ResponseType
.
Error
,
"上传文件无效"
);
var
dpath
=
Path
.
Combine
(
evn
.
ContentRootPath
,
"Files"
,
$"
{
hospitalId
}
"
,
"first"
);
if
(
type
==
1
)
dpath
=
Path
.
Combine
(
evn
.
ContentRootPath
,
"Files"
,
$"
{
hospitalId
}
"
,
$"
{
year
}{
month
.
ToString
().
PadLeft
(
2
,
'0'
)}
"
);
FileHelper
.
CreateDirectory
(
dpath
);
var
path
=
Path
.
Combine
(
dpath
,
FileHelper
.
GetFileName
(
file
.
FileName
));
using
(
var
stream
=
file
.
OpenReadStream
())
{
byte
[]
bytes
=
new
byte
[
stream
.
Length
];
stream
.
Read
(
bytes
,
0
,
bytes
.
Length
);
if
(!
FileHelper
.
CreateFile
(
path
,
bytes
))
return
new
ApiResponse
(
ResponseType
.
Error
,
"保存失败"
);
}
if
(!
string
.
IsNullOrEmpty
(
path
)
&&
FileHelper
.
IsExistFile
(
path
))
return
new
ApiResponse
(
ResponseType
.
OK
,
path
);
else
return
new
ApiResponse
(
ResponseType
.
Error
,
"获取首次文件失败!"
);
}
///// <summary>
///// 提取数据
///// </summary>
///// <param name="request"></param>
//[HttpPost]
//[Route("index")]
//public void Index([FromBody]AllotRequest request)
//{
// var token = Guid.NewGuid().ToString("N");
// logger.LogInformation(token + ",开始提取数据,请求参数:" + JsonHelper.Serialize(request));
// var hospital = hospitalService.GetHopital(request.HospitalId.Value);
// var filepath = extractService.ExtractData(request.ID, request.Mail, hospital, request.Path);
// if (!string.IsNullOrEmpty(filepath) && FileHelper.IsExistFile(filepath))
// {
// int i = 1;
// while (i <= 5)
// {
// string retJson = HttpHelper.HttpClient(url.ImportFile + $"?allotId={request.ID}&hospitalId={hospital.ID}", filepath);
// logger.LogInformation(retJson);
// var ret = JsonHelper.Deserialize<ApiResponse>(retJson);
// if ((int)ret.State == 1)
// break;
// i++;
// }
// }
// logger.LogInformation(token + ",提取结束,请求参数:" + JsonHelper.Serialize(request));
//}
#
region
新版提取
/// <summary>
...
...
@@ -117,25 +42,47 @@ public ApiResponse Import([FromForm] IFormCollection form, int type, int hospita
/// <returns></returns>
[
Route
(
"extract"
)]
[
HttpPost
]
public
void
ExtractData
(
[
FromForm
]
IFormCollection
form
,
int
allotId
,
int
hospitalId
,
string
email
,
string
userId
)
public
void
ExtractData
()
{
logger
.
LogInformation
(
"提取绩效数据请求参数:"
+
JsonHelper
.
Serialize
(
new
{
allotId
,
hospitalId
,
email
,
userId
}));
if
(
allotId
==
0
||
hospitalId
==
0
)
Dictionary
<
string
,
object
>
dict
=
new
Dictionary
<
string
,
object
>();
foreach
(
var
key
in
Request
.
Form
.
Keys
)
{
dict
.
Add
(
key
,
Request
.
Form
[
key
]);
}
string
json
=
JsonHelper
.
Serialize
(
dict
);
var
request
=
JsonHelper
.
Deserialize
<
ExtractRequest
>(
json
);
logger
.
LogInformation
(
"提取绩效数据请求参数:"
+
json
);
if
(
request
==
null
||
request
.
AllotId
==
0
||
request
.
HospitalId
==
0
)
return
;
var
path
=
string
.
Empty
;
if
(
Request
.
Form
.
Files
==
null
||
!
Request
.
Form
.
Files
.
Any
())
logger
.
LogInformation
(
$"文件为空,以模板文件进行数据提取!"
);
else
path
=
SaveFileAsTemplate
(
Request
.
Form
.
Files
[
0
],
request
.
HospitalId
);
#
region
保存历史绩效文件
string
filePath
=
extractService1
.
Main
(
request
.
AllotId
,
request
.
HospitalId
,
request
.
Email
,
"User"
+
request
.
UserId
,
path
);
logger
.
LogInformation
(
$"抽取的文件地址:
{
filePath
}
"
);
if
(
form
.
Files
==
null
||
!
form
.
Files
.
Any
()
||
((
FormFileCollection
)
form
.
Files
).
FirstOrDefault
()
==
null
)
logger
.
LogInformation
(
$"文件为空!"
);
if
(
!
string
.
IsNullOrEmpty
(
filePath
)
&&
FileHelper
.
IsExistFile
(
filePath
)
)
ImportFileAsAllotExtractFile
(
request
.
AllotId
,
request
.
HospitalId
,
filePath
);
else
logger
.
LogInformation
(
$"保存提取文件提取文件不存在!"
);
}
#
endregion
新版提取
#
region
保存历史绩效文件
private
string
SaveFileAsTemplate
(
IFormFile
file
,
int
hospitalId
)
{
var
file
=
((
FormFileCollection
)
form
.
Files
)?.
FirstOrDefault
();
var
dpath
=
Path
.
Combine
(
evn
.
ContentRootPath
,
"Files"
,
"HospitalAllot"
,
$"
{
hospitalId
}
"
);
FileHelper
.
CreateDirectory
(
dpath
);
path
=
Path
.
Combine
(
dpath
,
FileHelper
.
GetFileName
(
file
.
FileName
));
string
path
=
Path
.
Combine
(
dpath
,
FileHelper
.
GetFileName
(
file
.
FileName
));
logger
.
LogInformation
(
$"保存历史绩效文件保存路径:"
+
path
);
if
(!
string
.
IsNullOrEmpty
(
path
)
&&
FileHelper
.
IsExistFile
(
path
))
FileHelper
.
DeleteFile
(
path
);
...
...
@@ -148,57 +95,45 @@ public void ExtractData([FromForm] IFormCollection form, int allotId, int hospit
byte
[]
bytes
=
new
byte
[
stream
.
Length
];
stream
.
Read
(
bytes
,
0
,
bytes
.
Length
);
if
(!
FileHelper
.
CreateFile
(
path
,
bytes
))
{
logger
.
LogInformation
(
$"保存历史绩效文件保存失败"
);
else
return
""
;
}
}
return
path
;
}
#
endregion
保存历史绩效文件
//string filePath = newExtractService.ExtractData(allotId, request.Email, hospitalId);
//string filePath = extractService.ExtractData(allotId, email, hospitalId, "User" + userId, path); //抽取
string
filePath
=
extractService1
.
Main
(
allotId
,
hospitalId
,
email
,
"User"
+
userId
,
path
);
logger
.
LogInformation
(
$"抽取文件地址:
{
filePath
}
"
);
#
region
保存文件到网站下
if
(!
string
.
IsNullOrEmpty
(
filePath
)
&&
FileHelper
.
IsExistFile
(
filePath
)
)
private
void
ImportFileAsAllotExtractFile
(
int
allotId
,
int
hospitalId
,
string
filePath
)
{
string
http
=
url
.
ImportFile
+
$"/template/savefile?allotId=
{
allotId
}
&hospitalId=
{
hospitalId
}
"
;
logger
.
LogInformation
(
"请求路径:"
+
http
+
",请求参数"
+
JsonHelper
.
Serialize
(
new
{
allotId
,
hospitalId
}));
var
http
=
new
RestSharpHelper
();
string
endpoint
=
"/template/savefile"
;
var
importUrl
=
http
.
SetUrl
(
options
.
ImportFile
,
endpoint
);
var
obj
=
new
{
allotId
,
hospitalId
};
string
json
=
JsonHelper
.
Serialize
(
obj
);
var
parameter
=
JsonHelper
.
Deserialize
<
Dictionary
<
string
,
object
>>(
json
);
var
request
=
http
.
CreateFileRequest
(
new
string
[]
{
filePath
},
parameter
);
int
i
=
1
;
while
(
i
<=
5
)
{
if
(
i
==
5
)
logger
.
LogInformation
(
$"保存文件失败,已尝试执行五次,请联系开发人员!"
);
else
logger
.
LogInformation
(
$"正在尝试第
{
i
}
次保存!"
);
//保存文件
var
files
=
new
Dictionary
<
string
,
string
>
{
{
"file"
,
filePath
}
};
string
retJson
=
HttpHelper
.
HttpPost
(
http
,
files
:
files
);
logger
.
LogInformation
(
"保存提取文件返回结果:"
+
JsonHelper
.
Serialize
(
retJson
));
logger
.
LogInformation
(
retJson
);
var
ret
=
JsonHelper
.
Deserialize
<
ApiResponse
>(
retJson
);
if
(
ret
!=
null
&&
(
int
)
ret
.
State
==
1
)
var
response
=
http
.
GetResponse
(
importUrl
,
request
);
var
result
=
http
.
GetContent
<
ApiResponse
>(
response
);
if
(
result
!=
null
&&
(
int
)
result
.
State
==
1
)
{
logger
.
LogInformation
(
"保存提取文件保存成功!"
);
break
;
return
;
}
i
++;
}
logger
.
LogInformation
(
$"保存文件失败,已尝试执行五次,请联系开发人员!"
);
}
else
logger
.
LogInformation
(
$"保存提取文件提取文件不存在!"
);
#
endregion
保存文件到网站下
}
#
endregion
新版提取
}
}
performance/Performance.Infrastructure/Helper/RestSharpHelper.cs
0 → 100644
View file @
934df22c
using
RestSharp
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Performance.Infrastructure
{
public
class
RestSharpHelper
{
public
const
string
tokenHeader
=
"Authorization"
;
public
RestClient
SetUrl
(
string
baseUrl
,
string
endpoint
)
{
var
url
=
Path
.
Combine
(
baseUrl
,
endpoint
);
var
restClient
=
new
RestClient
(
url
);
return
restClient
;
}
public
RestRequest
CreateGetRequest
(
string
tokenHeader
=
tokenHeader
,
string
token
=
null
,
int
timeout
=
-
1
)
{
var
restRequest
=
new
RestRequest
(
Method
.
GET
);
restRequest
.
AddHeader
(
tokenHeader
,
token
);
restRequest
.
AddHeader
(
"Accept"
,
"application/json"
);
restRequest
.
Timeout
=
timeout
;
return
restRequest
;
}
public
RestRequest
CreatePostRequest
(
string
payload
,
string
tokenHeader
=
tokenHeader
,
string
token
=
null
,
int
timeout
=
-
1
)
{
var
restRequest
=
new
RestRequest
(
Method
.
POST
);
restRequest
.
AddHeader
(
tokenHeader
,
token
);
restRequest
.
AddHeader
(
"Accept"
,
"application/json"
);
restRequest
.
AddParameter
(
"application/json"
,
payload
,
ParameterType
.
RequestBody
);
restRequest
.
Timeout
=
timeout
;
return
restRequest
;
}
public
RestRequest
CreateFileRequest
(
string
[]
files
,
Dictionary
<
string
,
object
>
parameter
=
null
,
string
tokenHeader
=
tokenHeader
,
string
token
=
null
,
int
timeout
=
-
1
)
{
var
restRequest
=
new
RestRequest
(
Method
.
POST
);
restRequest
.
AddHeader
(
tokenHeader
,
token
);
if
(
files
!=
null
&&
files
.
Any
(
t
=>
!
string
.
IsNullOrEmpty
(
t
)))
{
int
i
=
1
;
foreach
(
var
file
in
files
.
Where
(
t
=>
!
string
.
IsNullOrEmpty
(
t
)))
{
restRequest
.
AddFile
(
i
.
ToString
(),
file
);
i
++;
}
}
if
(
parameter
!=
null
)
{
foreach
(
var
item
in
parameter
)
{
restRequest
.
AddParameter
(
item
.
Key
,
item
.
Value
);
}
}
restRequest
.
Timeout
=
timeout
;
return
restRequest
;
}
public
RestRequest
CreatePutRequest
(
string
payload
,
string
tokenHeader
=
tokenHeader
,
string
token
=
null
,
int
timeout
=
-
1
)
{
var
restRequest
=
new
RestRequest
(
Method
.
PUT
);
restRequest
.
AddHeader
(
tokenHeader
,
token
);
restRequest
.
AddHeader
(
"Accept"
,
"application/json"
);
restRequest
.
AddParameter
(
"application/json"
,
payload
,
ParameterType
.
RequestBody
);
restRequest
.
Timeout
=
timeout
;
return
restRequest
;
}
public
RestRequest
CreateDeleteRequest
(
string
tokenHeader
=
tokenHeader
,
string
token
=
null
,
int
timeout
=
-
1
)
{
var
restRequest
=
new
RestRequest
(
Method
.
DELETE
);
restRequest
.
AddHeader
(
tokenHeader
,
token
);
restRequest
.
AddHeader
(
"Accept"
,
"application/json"
);
restRequest
.
Timeout
=
timeout
;
return
restRequest
;
}
public
IRestResponse
GetResponse
(
RestClient
client
,
RestRequest
request
)
{
return
client
.
Execute
(
request
);
}
public
async
Task
<
IRestResponse
>
GetResponseAsync
(
RestClient
client
,
RestRequest
request
)
{
return
await
client
.
ExecuteAsync
(
request
);
}
public
DTO
GetContent
<
DTO
>(
IRestResponse
response
)
{
var
content
=
response
.
Content
;
DTO
dtoObject
=
JsonHelper
.
Deserialize
<
DTO
>(
content
);
return
dtoObject
;
}
}
}
performance/Performance.Services/LogManageService.cs
View file @
934df22c
using
Microsoft.AspNetCore.SignalR
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Options
;
using
Performance.DtoModels
;
using
Performance.DtoModels.AppSettings
;
using
Performance.Infrastructure
;
using
Performance.Repository
;
using
System
;
using
System.Threading.Tasks
;
namespace
Performance.Services
{
...
...
@@ -102,8 +104,20 @@ public void ReturnTheLog(int allotId, string groupName, int type, string tag, ob
logdbug
.
Add
(
allotId
,
tag
,
content
,
level
,
type
);
if
(!
isSingle
)
{
var
http
=
url
.
ImportFile
+
$"/template/returnlog?type=
{
type
}
&tag=
{
tag
}
&message=
{
content
}
&level=
{
level
}
&groupName=
{
groupName
}
"
;
HttpHelper
.
HttpPost
(
http
);
var
http
=
new
RestSharpHelper
();
var
importUrl
=
http
.
SetUrl
(
url
.
ImportFile
,
"/template/returnlog"
);
var
info
=
new
SignalrLogRequest
()
{
Type
=
type
,
Tag
=
tag
,
Message
=
content
,
Level
=
level
,
GroupName
=
groupName
};
string
json
=
JsonHelper
.
Serialize
(
info
);
var
request
=
http
.
CreatePostRequest
(
json
);
Task
.
Run
(()
=>
http
.
GetResponse
(
importUrl
,
request
));
}
}
catch
(
Exception
ex
)
...
...
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