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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
40 deletions
+70
-40
performance/Performance.Api/Controllers/TemplateController.cs
+6
-9
performance/Performance.Services/ExtractService.cs
+64
-31
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
))
{
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
);
return
new
ApiResponse
(
ResponseType
.
Fail
,
"医院无效"
);
var
user
=
claim
.
At
(
request
.
Token
);
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,45 +64,71 @@ 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
>();
var
allotList
=
perforPerallotRepository
.
GetEntities
(
t
=>
t
.
HospitalId
==
hospitalId
);
var
configList
=
perforHospitalconfigRepository
.
GetEntities
(
t
=>
t
.
HospitalId
==
hospitalId
);
var
firstList
=
perforPerfirstRepository
.
GetEntities
(
t
=>
t
.
HospitalId
==
hospitalId
);
var
scriptList
=
perforExtractRepository
.
GetEntities
(
t
=>
t
.
HospitalId
==
hospitalId
);
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
);
var
scriptList
=
perforExtractRepository
.
GetEntities
(
t
=>
t
.
HospitalId
==
hospitalId
);
if
(
configList
==
null
||
!
configList
.
Any
())
throw
new
PerformanceException
(
$"暂不支持自动提取绩效数据"
);
if
(
configList
==
null
||
!
configList
.
Any
())
throw
new
PerformanceException
(
$"暂不支持自动提取绩效数据"
);
if
(
scriptList
==
null
||
!
scriptList
.
Any
())
throw
new
PerformanceException
(
$"暂无该医院的配置信息和执行sql,无法进行数据提取"
);
if
(
scriptList
==
null
||
!
scriptList
.
Any
())
throw
new
PerformanceException
(
$"暂无该医院的配置信息和执行sql,无法进行数据提取"
);
var
hospitalConfig
=
configList
.
First
();
string
originalPath
=
""
;
//判断是否是首次
if
((
allotList
==
null
||
!
allotList
.
Any
())
&&
(
firstList
!=
null
||
!
firstList
.
Any
()))
{
var
first
=
firstList
.
OrderByDescending
(
t
=>
t
.
CreateDate
).
FirstOrDefault
();
//首次 从excel中获取人员信息,SHEET页信息,列头信息
sheetList
=
GetFileData
(
first
.
Path
);
originalPath
=
first
.
Path
;
var
hospitalConfig
=
configList
.
First
();
string
originalPath
=
""
;
//判断是否是首次
if
((
allotList
==
null
||
!
allotList
.
Any
())
&&
(
firstList
!=
null
||
!
firstList
.
Any
()))
{
var
first
=
firstList
.
OrderByDescending
(
t
=>
t
.
CreateDate
).
FirstOrDefault
();
//首次 从excel中获取人员信息,SHEET页信息,列头信息
sheetList
=
GetFileData
(
first
.
Path
);
originalPath
=
first
.
Path
;
}
else
{
//非首次 从数据库中获取人员信息,SHEET页信息,列头信息
var
allot
=
allotList
.
OrderByDescending
(
t
=>
t
.
Year
).
ThenByDescending
(
t
=>
t
.
Month
).
First
();
sheetList
=
GetRepositoryData
(
allot
.
ID
);
originalPath
=
allot
.
Path
;
}
var
dpath
=
Path
.
Combine
(
environment
.
ContentRootPath
,
"Files"
,
$"
{
hospitalId
}
"
,
"autoextract"
);
FileHelper
.
CreateDirectory
(
dpath
);
string
path
=
Path
.
Combine
(
dpath
,
$"绩效数据
{
DateTime
.
Now
.
ToString
(
"yyyyMMddHHmmssfff"
)}
.xlsx"
);
//根据SHEET页信息,列头信息,创建EXCEL文件
if
(
WriteExcel
(
path
,
originalPath
,
sheetList
,
hospitalConfig
,
hospitalId
,
out
string
filepath
))
SendEmail
(
mail
,
filepath
,
$"
{
hospital
.
HosName
}
HIS数据提取成功"
,
$"
{
hospital
.
HosName
}
在
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
成功提取。"
);
}
else
catch
(
Exception
ex
)
{
//非首次 从数据库中获取人员信息,SHEET页信息,列头信息
var
allot
=
allotList
.
OrderByDescending
(
t
=>
t
.
Year
).
ThenByDescending
(
t
=>
t
.
Month
).
First
();
sheetList
=
GetRepositoryData
(
allot
.
ID
);
originalPath
=
allot
.
Path
;
logger
.
LogError
(
ex
.
ToString
());
SendEmail
(
mail
,
""
,
$"
{
hospital
.
HosName
}
HIS数据提取失败"
,
$"
{
hospital
.
HosName
}
提取数据过程中出现异常情况,我们将尽快解决问题。给您带来的不便我们深感歉意!"
);
}
var
dpath
=
Path
.
Combine
(
environment
.
ContentRootPath
,
"Files"
,
$"
{
hospitalId
}
"
,
"autoextract"
);
FileHelper
.
CreateDirectory
(
dpath
);
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
(
"绩效数据提取失败"
);
}
/// <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