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
4a871319
Commit
4a871319
authored
May 15, 2019
by
ruyun.zhang@suvalue.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
后台任务执行提取
parent
b53eca2a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
12 deletions
+42
-12
performance/Performance.Api/Controllers/TemplateController.cs
+5
-8
performance/Performance.Services/ExtractService.cs
+37
-4
No files found.
performance/Performance.Api/Controllers/TemplateController.cs
View file @
4a871319
using
FluentValidation.AspNetCore
;
using
Hangfire
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Http.Internal
;
...
...
@@ -103,15 +104,10 @@ public ApiResponse ExtractData([CustomizeValidator(RuleSet = "Delete"), FromBody
{
var
hospital
=
hospitalService
.
GetHopital
(
request
.
ID
);
if
(
hospital
==
null
)
return
new
ApiResponse
(
ResponseType
.
Fail
,
"hospitalid不存在"
);
var
filePath
=
extractService
.
ExtractData
(
request
.
ID
);
if
(!
string
.
IsNullOrEmpty
(
filePath
)
&&
FileHelper
.
IsExistFile
(
filePath
))
{
return
new
ApiResponse
(
ResponseType
.
Fail
,
"医院无效"
);
var
user
=
claim
.
At
(
request
.
Token
);
templateService
.
SendEmail
(
new
List
<
string
>
{
user
.
Mail
},
filePath
,
$"
{
hospital
.
HosName
}
提取数据"
,
$"
{
hospital
.
HosName
}
在
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
成功提取。"
);
}
return
new
ApiResponse
(
ResponseType
.
OK
,
"OK"
,
filePath
);
BackgroundJob
.
Enqueue
(()
=>
extractService
.
ExtractData
(
request
.
ID
,
user
.
Mail
,
hospital
));
return
new
ApiResponse
(
ResponseType
.
OK
,
"HIS绩效数据提取任务正在执行,稍后我们将以邮件的通知您!"
);
}
}
}
\ No newline at end of file
performance/Performance.Services/ExtractService.cs
View file @
4a871319
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Options
;
using
NPOI.HSSF.UserModel
;
using
NPOI.SS.UserModel
;
...
...
@@ -23,7 +24,9 @@ namespace Performance.Services
/// </summary>
public
class
ExtractService
:
IAutoInjection
{
private
readonly
ILogger
<
ExtractService
>
logger
;
private
readonly
IHostingEnvironment
environment
;
private
readonly
IEmailService
emailService
;
private
readonly
PerSheetService
perSheetService
;
private
readonly
PerHeaderService
perHeaderService
;
private
readonly
PerforPersheetRepository
perforPersheetRepository
;
...
...
@@ -34,7 +37,9 @@ public class ExtractService : IAutoInjection
private
readonly
PerforPerallotRepository
perforPerallotRepository
;
private
readonly
PerforHospitalconfigRepository
perforHospitalconfigRepository
;
public
ExtractService
(
IHostingEnvironment
environment
,
public
ExtractService
(
ILogger
<
ExtractService
>
logger
,
IHostingEnvironment
environment
,
IEmailService
emailService
,
PerSheetService
perSheetService
,
PerHeaderService
perHeaderService
,
PerforPersheetRepository
perforPersheetRepository
,
...
...
@@ -45,7 +50,9 @@ public class ExtractService : IAutoInjection
PerforPerallotRepository
perforPerallotRepository
,
PerforHospitalconfigRepository
perforHospitalconfigRepository
)
{
this
.
logger
=
logger
;
this
.
environment
=
environment
;
this
.
emailService
=
emailService
;
this
.
perSheetService
=
perSheetService
;
this
.
perHeaderService
=
perHeaderService
;
this
.
perforPersheetRepository
=
perforPersheetRepository
;
...
...
@@ -57,10 +64,12 @@ public class ExtractService : IAutoInjection
this
.
perforHospitalconfigRepository
=
perforHospitalconfigRepository
;
}
public
string
ExtractData
(
int
hospitalId
)
public
void
ExtractData
(
int
hospitalId
,
string
mail
,
sys_hospital
hospital
)
{
List
<
PerSheet
>
sheetList
=
new
List
<
PerSheet
>();
try
{
var
allotList
=
perforPerallotRepository
.
GetEntities
(
t
=>
t
.
HospitalId
==
hospitalId
);
var
configList
=
perforHospitalconfigRepository
.
GetEntities
(
t
=>
t
.
HospitalId
==
hospitalId
);
var
firstList
=
perforPerfirstRepository
.
GetEntities
(
t
=>
t
.
HospitalId
==
hospitalId
);
...
...
@@ -94,8 +103,32 @@ public string ExtractData(int hospitalId)
string
path
=
Path
.
Combine
(
dpath
,
$"绩效数据
{
DateTime
.
Now
.
ToString
(
"yyyyMMddHHmmssfff"
)}
.xlsx"
);
//根据SHEET页信息,列头信息,创建EXCEL文件
if
(
WriteExcel
(
path
,
originalPath
,
sheetList
,
hospitalConfig
,
hospitalId
,
out
string
filepath
))
return
filepath
;
throw
new
PerformanceException
(
"绩效数据提取失败"
);
SendEmail
(
mail
,
filepath
,
$"
{
hospital
.
HosName
}
HIS数据提取成功"
,
$"
{
hospital
.
HosName
}
在
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
成功提取。"
);
}
catch
(
Exception
ex
)
{
logger
.
LogError
(
ex
.
ToString
());
SendEmail
(
mail
,
""
,
$"
{
hospital
.
HosName
}
HIS数据提取失败"
,
$"
{
hospital
.
HosName
}
提取数据过程中出现异常情况,我们将尽快解决问题。给您带来的不便我们深感歉意!"
);
}
}
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="path"></param>
/// <param name="subject"></param>
/// <param name="body"></param>
private
void
SendEmail
(
string
mail
,
string
path
,
string
subject
,
string
body
)
{
var
message
=
new
EmailMessage
{
To
=
new
List
<
string
>
{
mail
},
Attachments
=
new
List
<
string
>
{
path
},
DisplayName
=
"溯直健康"
,
Subject
=
subject
,
Body
=
body
};
emailService
.
Send
(
message
);
}
/// <summary>
...
...
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