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
c614ea10
Commit
c614ea10
authored
Dec 13, 2021
by
纪旭 韦
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into 手工录入_
parents
6777d66a
d424bda0
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
88 additions
and
89 deletions
+88
-89
performance/Performance.Api/Controllers/TemplateController.cs
+21
-9
performance/Performance.Repository/Common/ConnectionBuilder.cs
+2
-2
performance/Performance.Repository/PerforPeremployeeRepository.cs
+6
-2
performance/Performance.Repository/Performance.Repository.csproj
+1
-1
performance/Performance.Services/ExConfigService.cs
+1
-1
performance/Performance.Services/ExtractExcelService/DictionaryService.cs
+10
-10
performance/Performance.Services/ExtractExcelService/ExtractService.cs
+30
-7
performance/Performance.Services/ExtractExcelService/QueryService.cs
+17
-57
No files found.
performance/Performance.Api/Controllers/TemplateController.cs
View file @
c614ea10
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
using
Performance.Infrastructure
;
using
Performance.Infrastructure
;
using
Performance.Services
;
using
Performance.Services
;
using
Performance.Services.ExtractExcelService
;
using
Performance.Services.ExtractExcelService
;
using
Performance.Services.Queues
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
...
@@ -37,6 +38,8 @@ public class TemplateController : Controller
...
@@ -37,6 +38,8 @@ public class TemplateController : Controller
private
readonly
AllotService
allotService
;
private
readonly
AllotService
allotService
;
private
readonly
LogManageService
logService
;
private
readonly
LogManageService
logService
;
private
readonly
IServiceScopeFactory
serviceScopeFactory
;
private
readonly
IServiceScopeFactory
serviceScopeFactory
;
private
readonly
IBackgroundTaskQueue
_backgroundTaskQueue
;
private
readonly
ExtractService
extractService
;
public
TemplateController
(
public
TemplateController
(
ILogger
<
ExceptionsFilter
>
logger
,
ILogger
<
ExceptionsFilter
>
logger
,
...
@@ -50,7 +53,9 @@ public class TemplateController : Controller
...
@@ -50,7 +53,9 @@ public class TemplateController : Controller
HospitalService
hospitalService
,
HospitalService
hospitalService
,
AllotService
allotService
,
AllotService
allotService
,
LogManageService
logService
,
LogManageService
logService
,
IServiceScopeFactory
serviceScopeFactory
)
IBackgroundTaskQueue
backgroundTaskQueue
,
IServiceScopeFactory
serviceScopeFactory
,
ExtractService
extractService
)
{
{
this
.
logger
=
logger
;
this
.
logger
=
logger
;
this
.
env
=
env
;
this
.
env
=
env
;
...
@@ -64,6 +69,8 @@ public class TemplateController : Controller
...
@@ -64,6 +69,8 @@ public class TemplateController : Controller
this
.
allotService
=
allotService
;
this
.
allotService
=
allotService
;
this
.
logService
=
logService
;
this
.
logService
=
logService
;
this
.
serviceScopeFactory
=
serviceScopeFactory
;
this
.
serviceScopeFactory
=
serviceScopeFactory
;
_backgroundTaskQueue
=
backgroundTaskQueue
;
this
.
extractService
=
extractService
;
}
}
/// <summary>
/// <summary>
...
@@ -226,22 +233,22 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody] ExtractRequest
...
@@ -226,22 +233,22 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody] ExtractRequest
allot
.
IsExtracting
=
1
;
allot
.
IsExtracting
=
1
;
allot
.
ExtractTime
=
DateTime
.
Now
;
allot
.
ExtractTime
=
DateTime
.
Now
;
allotService
.
Update
(
allot
);
allotService
.
Update
(
allot
);
string
email
=
claim
.
GetUserClaim
(
JwtClaimTypes
.
Mail
);
// string email = claim.GetUserClaim(JwtClaimTypes.Mail);
string
email
=
""
;
if
(
isSingle
)
if
(
isSingle
)
{
{
logger
.
LogInformation
(
"同一项目中进行提取"
);
logger
.
LogInformation
(
"同一项目中进行提取"
);
Task
.
Run
(()
=>
_backgroundTaskQueue
.
QueueBackgroundWorkItem
(
async
token
=>
{
{
using
(
var
scope
=
serviceScopeFactory
.
CreateScope
())
using
(
var
scope
=
serviceScopeFactory
.
CreateScope
())
{
{
var
scopedServices
=
scope
.
ServiceProvider
.
GetRequiredService
<
ExtractService
>();
var
scopedServices
=
scope
.
ServiceProvider
.
GetRequiredService
<
ExtractService
>();
logger
.
LogInformation
(
"提取绩效数据参数:"
+
JsonHelper
.
Serialize
(
new
{
allotId
=
allot
.
ID
,
hospitalId
=
allot
.
HospitalId
,
userId
=
claim
.
GetUserId
()
}));
logger
.
LogInformation
(
"提取绩效数据参数:"
+
JsonHelper
.
Serialize
(
new
{
allotId
=
allot
.
ID
,
hospitalId
=
allot
.
HospitalId
}));
string
extractFilePath
=
scopedServices
.
Main
(
allot
.
ID
,
allot
.
HospitalId
,
email
,
"User"
+
claim
.
GetUserId
(),
filePath
,
isSingle
);
string
extractFilePath
=
scopedServices
.
Main
(
allot
.
ID
,
allot
.
HospitalId
,
email
,
allot
.
ID
.
ToString
(),
filePath
,
isSingle
);
}
}
});
});
Thread
.
Sleep
(
1000
);
}
}
else
else
{
{
...
@@ -252,8 +259,7 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody] ExtractRequest
...
@@ -252,8 +259,7 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody] ExtractRequest
{
{
AllotId
=
request
.
AllotId
,
AllotId
=
request
.
AllotId
,
HospitalId
=
request
.
HospitalId
,
HospitalId
=
request
.
HospitalId
,
Email
=
email
,
Email
=
email
UserId
=
claim
.
GetUserId
()
};
};
string
json
=
JsonHelper
.
Serialize
(
obj
);
string
json
=
JsonHelper
.
Serialize
(
obj
);
...
@@ -284,6 +290,12 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody] ExtractRequest
...
@@ -284,6 +290,12 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody] ExtractRequest
// B 使用配置作为模板
// B 使用配置作为模板
}
}
[
HttpPost
(
"extract/allot/file"
)]
public
ApiResponse
ExtractAllotFile
(
ExtractRequest
request
)
{
extractService
.
Main
(
request
.
AllotId
,
request
.
HospitalId
,
request
.
Email
,
request
.
AllotId
.
ToString
(),
""
,
true
);
return
new
ApiResponse
(
ResponseType
.
OK
);
}
/// <summary>
/// <summary>
/// 提取日志
/// 提取日志
...
...
performance/Performance.Repository/Common/ConnectionBuilder.cs
View file @
c614ea10
using
Microsoft.Data.SqlClient
;
using
MySql.Data.MySqlClient
;
using
MySql.Data.MySqlClient
;
using
Oracle.ManagedDataAccess.Client
;
using
Oracle.ManagedDataAccess.Client
;
using
System
;
using
System
;
using
System.Data
;
using
System.Data
;
using
System.Data.SqlClient
;
namespace
Performance.Repository
namespace
Performance.Repository
{
{
...
...
performance/Performance.Repository/PerforPeremployeeRepository.cs
View file @
c614ea10
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
using
Performance.Repository
;
using
Performance.Repository
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Linq
;
using
System.Linq
;
using
System.Linq.Expressions
;
using
System.Linq.Expressions
;
...
@@ -117,7 +118,10 @@ public Comparison CheckAccountingUnitRealGiveFeeDiff(int allotId, string searchQ
...
@@ -117,7 +118,10 @@ public Comparison CheckAccountingUnitRealGiveFeeDiff(int allotId, string searchQ
TotalCount
=
DapperQuery
<
int
>(
queryCount
,
new
{
allotId
,
searchQuery
,
parm
=
$"%
{
searchQuery
}
%"
})?.
FirstOrDefault
()
??
0
,
TotalCount
=
DapperQuery
<
int
>(
queryCount
,
new
{
allotId
,
searchQuery
,
parm
=
$"%
{
searchQuery
}
%"
})?.
FirstOrDefault
()
??
0
,
};
};
}
}
}
public
IDbConnection
GetDbConnection
()
{
return
context
.
Database
.
GetDbConnection
();
}
}
}
}
performance/Performance.Repository/Performance.Repository.csproj
View file @
c614ea10
...
@@ -5,8 +5,8 @@
...
@@ -5,8 +5,8 @@
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.4" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.4" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
</ItemGroup>
</ItemGroup>
...
...
performance/Performance.Services/ExConfigService.cs
View file @
c614ea10
...
@@ -775,7 +775,7 @@ public string Judge(int allotId, int hospitalId, int useTemplate, ref bool isSin
...
@@ -775,7 +775,7 @@ public string Judge(int allotId, int hospitalId, int useTemplate, ref bool isSin
if
(
conf
==
null
)
if
(
conf
==
null
)
continue
;
continue
;
var
data
=
queryService
.
QueryData
(
conf
,
allot
,
scr
.
ExecScript
);
var
data
=
queryService
.
QueryData
<
ExtractDto
>(
conf
,
scr
.
ExecScript
,
allot
,
false
);
if
(
data
==
null
||
!
data
.
Any
())
continue
;
if
(
data
==
null
||
!
data
.
Any
())
continue
;
foreach
(
var
module
in
moduleSheet
.
Where
(
t
=>
t
.
CheckScriptId
==
scr
.
Id
))
foreach
(
var
module
in
moduleSheet
.
Where
(
t
=>
t
.
CheckScriptId
==
scr
.
Id
))
...
...
performance/Performance.Services/ExtractExcelService/DictionaryService.cs
View file @
c614ea10
...
@@ -71,7 +71,7 @@ public void Handler(int hospitalId, per_allot allot, string groupName, bool isSi
...
@@ -71,7 +71,7 @@ public void Handler(int hospitalId, per_allot allot, string groupName, bool isSi
var
typeIds
=
types
.
Where
(
t
=>
t
.
Source
==
(
int
)
SheetType
.
Employee
).
Select
(
t
=>
t
.
Id
);
var
typeIds
=
types
.
Where
(
t
=>
t
.
Source
==
(
int
)
SheetType
.
Employee
).
Select
(
t
=>
t
.
Id
);
var
script
=
scripts
.
Where
(
t
=>
typeIds
.
Contains
(
t
.
TypeId
));
var
script
=
scripts
.
Where
(
t
=>
typeIds
.
Contains
(
t
.
TypeId
));
if
(
script
!=
null
)
if
(
script
!=
null
)
Employee
(
allot
,
configs
,
scripts
);
Employee
(
allot
,
configs
,
scripts
,
isSingle
);
}
}
if
(
types
.
Any
(
t
=>
t
.
Source
==
(
int
)
SheetType
.
OnlyExtract
))
//不写入Excel的提取数据
if
(
types
.
Any
(
t
=>
t
.
Source
==
(
int
)
SheetType
.
OnlyExtract
))
//不写入Excel的提取数据
{
{
...
@@ -84,7 +84,7 @@ public void Handler(int hospitalId, per_allot allot, string groupName, bool isSi
...
@@ -84,7 +84,7 @@ public void Handler(int hospitalId, per_allot allot, string groupName, bool isSi
foreach
(
var
script
in
thisTypeScripts
)
foreach
(
var
script
in
thisTypeScripts
)
{
{
logger
.
LogInformation
(
$"提取sql:
{
script
.
ExecScript
}
"
);
logger
.
LogInformation
(
$"提取sql:
{
script
.
ExecScript
}
"
);
ExResult
(
allot
,
configs
.
FirstOrDefault
(
t
=>
t
.
Id
==
script
.
ConfigId
),
script
.
ExecScript
,
type
.
EName
);
ExResult
(
allot
,
configs
.
FirstOrDefault
(
t
=>
t
.
Id
==
script
.
ConfigId
),
script
.
ExecScript
,
type
.
EName
,
isSingle
);
}
}
}
}
}
}
...
@@ -96,7 +96,7 @@ public void Handler(int hospitalId, per_allot allot, string groupName, bool isSi
...
@@ -96,7 +96,7 @@ public void Handler(int hospitalId, per_allot allot, string groupName, bool isSi
foreach
(
var
item
in
hisScrips
)
foreach
(
var
item
in
hisScrips
)
{
{
logService
.
ReturnTheLog
(
allot
.
ID
,
groupName
,
2
,
"提取数据"
,
$"提取
{
item
.
SourceType
}
-
{
item
.
Category
}
数据"
,
isSingle
:
isSingle
);
logService
.
ReturnTheLog
(
allot
.
ID
,
groupName
,
2
,
"提取数据"
,
$"提取
{
item
.
SourceType
}
-
{
item
.
Category
}
数据"
,
isSingle
:
isSingle
);
HisData
(
allot
,
configs
.
FirstOrDefault
(
t
=>
t
.
Id
==
item
.
ConfigId
),
item
);
HisData
(
allot
,
configs
.
FirstOrDefault
(
t
=>
t
.
Id
==
item
.
ConfigId
),
item
,
isSingle
);
}
}
}
}
catch
(
Exception
)
catch
(
Exception
)
...
@@ -106,7 +106,7 @@ public void Handler(int hospitalId, per_allot allot, string groupName, bool isSi
...
@@ -106,7 +106,7 @@ public void Handler(int hospitalId, per_allot allot, string groupName, bool isSi
}
}
}
}
private
void
Employee
(
per_allot
allot
,
List
<
sys_hospitalconfig
>
configs
,
IEnumerable
<
ex_script
>
scripts
)
private
void
Employee
(
per_allot
allot
,
List
<
sys_hospitalconfig
>
configs
,
IEnumerable
<
ex_script
>
scripts
,
bool
isSingle
)
{
{
try
try
{
{
...
@@ -116,12 +116,12 @@ private void Employee(per_allot allot, List<sys_hospitalconfig> configs, IEnumer
...
@@ -116,12 +116,12 @@ private void Employee(per_allot allot, List<sys_hospitalconfig> configs, IEnumer
var
sql
=
script
.
ExecScript
;
var
sql
=
script
.
ExecScript
;
if
(
config
==
null
||
string
.
IsNullOrEmpty
(
sql
))
return
;
if
(
config
==
null
||
string
.
IsNullOrEmpty
(
sql
))
return
;
var
limitData
=
queryService
.
QueryData
<
dynamic
>(
config
,
allot
,
sql
);
var
limitData
=
queryService
.
QueryData
<
dynamic
>(
config
,
sql
,
allot
,
isSingle
);
if
(
limitData
==
null
||
!
limitData
.
Any
())
return
;
if
(
limitData
==
null
||
!
limitData
.
Any
())
return
;
var
columns
=
((
IDictionary
<
string
,
object
>)
limitData
.
ElementAt
(
0
)).
Select
(
t
=>
t
.
Key
.
ToLower
()).
ToList
();
var
columns
=
((
IDictionary
<
string
,
object
>)
limitData
.
ElementAt
(
0
)).
Select
(
t
=>
t
.
Key
.
ToLower
()).
ToList
();
var
data
=
queryService
.
QueryData
<
per_employee
>(
config
,
allot
,
sql
).
ToList
();
var
data
=
queryService
.
QueryData
<
per_employee
>(
config
,
sql
,
allot
,
isSingle
).
ToList
();
data
.
ForEach
(
t
=>
data
.
ForEach
(
t
=>
{
{
t
.
AllotId
=
allot
.
ID
;
t
.
AllotId
=
allot
.
ID
;
...
@@ -223,13 +223,13 @@ private void JudgeDataEqual(List<string> columns, List<per_employee> emps, List<
...
@@ -223,13 +223,13 @@ private void JudgeDataEqual(List<string> columns, List<per_employee> emps, List<
}
}
}
}
private
void
HisData
(
per_allot
allot
,
sys_hospitalconfig
config
,
his_script
script
)
private
void
HisData
(
per_allot
allot
,
sys_hospitalconfig
config
,
his_script
script
,
bool
isSingle
)
{
{
try
try
{
{
if
(
config
==
null
||
string
.
IsNullOrEmpty
(
script
.
ExecScript
))
return
;
if
(
config
==
null
||
string
.
IsNullOrEmpty
(
script
.
ExecScript
))
return
;
var
data
=
queryService
.
QueryData
<
HisData
>(
config
,
allot
,
script
.
ExecScript
);
var
data
=
queryService
.
QueryData
<
HisData
>(
config
,
script
.
ExecScript
,
allot
,
isSingle
);
if
(
data
==
null
||
!
data
.
Any
())
return
;
if
(
data
==
null
||
!
data
.
Any
())
return
;
var
hisdata
=
hisdataRepository
.
GetEntities
(
t
=>
t
.
AllotId
==
allot
.
ID
&&
t
.
SourceType
==
script
.
SourceType
&&
t
.
Category
==
script
.
Category
);
var
hisdata
=
hisdataRepository
.
GetEntities
(
t
=>
t
.
AllotId
==
allot
.
ID
&&
t
.
SourceType
==
script
.
SourceType
&&
t
.
Category
==
script
.
Category
);
...
@@ -265,13 +265,13 @@ private void Department()
...
@@ -265,13 +265,13 @@ private void Department()
{
{
}
}
private
void
ExResult
(
per_allot
allot
,
sys_hospitalconfig
config
,
string
sql
,
string
enmae
)
private
void
ExResult
(
per_allot
allot
,
sys_hospitalconfig
config
,
string
sql
,
string
enmae
,
bool
isSingle
)
{
{
try
try
{
{
if
(
config
==
null
||
string
.
IsNullOrEmpty
(
sql
))
return
;
if
(
config
==
null
||
string
.
IsNullOrEmpty
(
sql
))
return
;
var
data
=
queryService
.
QueryData
(
config
,
allot
,
sql
);
var
data
=
queryService
.
QueryData
<
ExtractDto
>(
config
,
sql
,
allot
,
isSingle
);
if
(
data
==
null
||
!
data
.
Any
())
return
;
if
(
data
==
null
||
!
data
.
Any
())
return
;
var
createTime
=
DateTime
.
Now
;
var
createTime
=
DateTime
.
Now
;
...
...
performance/Performance.Services/ExtractExcelService/ExtractService.cs
View file @
c614ea10
using
Microsoft.Extensions.Logging
;
using
Dapper
;
using
Microsoft.Extensions.Logging
;
using
NPOI.SS.UserModel
;
using
NPOI.SS.UserModel
;
using
Performance.DtoModels
;
using
Performance.DtoModels
;
using
Performance.EntityModels
;
using
Performance.EntityModels
;
...
@@ -7,6 +8,7 @@
...
@@ -7,6 +8,7 @@
using
Performance.Services.ExtractExcelService.SheetDataWrite
;
using
Performance.Services.ExtractExcelService.SheetDataWrite
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.IO
;
using
System.IO
;
using
System.Linq
;
using
System.Linq
;
...
@@ -73,9 +75,11 @@ PerforCofdrugtypefactorRepository drugtypefactorRepository
...
@@ -73,9 +75,11 @@ PerforCofdrugtypefactorRepository drugtypefactorRepository
/// <param name="isSingle">抽取是否在同一项目</param>
/// <param name="isSingle">抽取是否在同一项目</param>
public
string
Main
(
int
allotId
,
int
hospitalId
,
string
email
,
string
groupName
,
string
filePath
=
null
,
bool
isSingle
=
false
)
public
string
Main
(
int
allotId
,
int
hospitalId
,
string
email
,
string
groupName
,
string
filePath
=
null
,
bool
isSingle
=
false
)
{
{
groupName
=
allotId
.
ToString
();
string
extractFilePath
=
""
;
string
extractFilePath
=
""
;
per_allot
allot
=
null
;
per_allot
allot
=
null
;
IWorkbook
workbook
=
null
;
IWorkbook
workbook
=
null
;
IDbConnection
connection
=
peremployeeRepository
.
GetDbConnection
();
try
try
{
{
logService
.
ClearExtractLog
(
allotId
);
logService
.
ClearExtractLog
(
allotId
);
...
@@ -114,6 +118,11 @@ public string Main(int allotId, int hospitalId, string email, string groupName,
...
@@ -114,6 +118,11 @@ public string Main(int allotId, int hospitalId, string email, string groupName,
allot
.
ExtractPath
=
extractFilePath
;
allot
.
ExtractPath
=
extractFilePath
;
workbook
.
EvaluateAll
();
workbook
.
EvaluateAll
();
using
(
FileStream
file
=
new
FileStream
(
extractFilePath
,
FileMode
.
OpenOrCreate
))
{
workbook
.
Write
(
file
);
}
workbook
.
Close
();
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
...
@@ -124,12 +133,7 @@ public string Main(int allotId, int hospitalId, string email, string groupName,
...
@@ -124,12 +133,7 @@ public string Main(int allotId, int hospitalId, string email, string groupName,
finally
finally
{
{
logService
.
ReturnTheLog
(
allotId
,
groupName
,
3
,
""
,
100
,
5
,
isSingle
);
logService
.
ReturnTheLog
(
allotId
,
groupName
,
3
,
""
,
100
,
5
,
isSingle
);
using
(
FileStream
file
=
new
FileStream
(
extractFilePath
,
FileMode
.
OpenOrCreate
))
UpdateAllot
(
connection
,
allot
);
{
workbook
.
Write
(
file
);
}
workbook
.
Close
();
perallotRepository
.
Update
(
allot
);
}
}
return
extractFilePath
;
return
extractFilePath
;
}
}
...
@@ -333,6 +337,25 @@ private List<ExtractTransDto> StandDataFormat(int hospitalId, List<ex_result> re
...
@@ -333,6 +337,25 @@ private List<ExtractTransDto> StandDataFormat(int hospitalId, List<ex_result> re
return
groupdata
.
ToList
();
return
groupdata
.
ToList
();
}
}
private
void
UpdateAllot
(
IDbConnection
connection
,
per_allot
allot
)
{
try
{
string
sql
=
"update per_allot set isextracting = @isextracting, extractpath = @extractpath where id = @id"
;
if
(
connection
==
null
)
return
;
if
(
connection
.
State
==
ConnectionState
.
Closed
)
connection
.
Open
();
connection
.
Execute
(
sql
,
allot
);
}
catch
(
Exception
ex
)
{
logger
.
LogError
(
ex
.
Message
);
}
}
private
readonly
List
<
SheetType
>
OtherConfigSheet
=
new
List
<
SheetType
>
private
readonly
List
<
SheetType
>
OtherConfigSheet
=
new
List
<
SheetType
>
{
{
SheetType
.
AccountExtra
,
SheetType
.
AccountExtra
,
...
...
performance/Performance.Services/ExtractExcelService/QueryService.cs
View file @
c614ea10
...
@@ -59,6 +59,7 @@ PerforPerallotRepository perallotRepository
...
@@ -59,6 +59,7 @@ PerforPerallotRepository perallotRepository
}
}
private
readonly
DateTime
CreateTime
=
DateTime
.
Now
;
private
readonly
DateTime
CreateTime
=
DateTime
.
Now
;
private
static
Dictionary
<
int
,
IDbConnection
>
pools
=
new
Dictionary
<
int
,
IDbConnection
>();
/// <summary>
/// <summary>
/// 获取抽取数据
/// 获取抽取数据
...
@@ -194,8 +195,6 @@ private List<ex_result> ExtractModuleData(per_allot allot, string groupName, boo
...
@@ -194,8 +195,6 @@ private List<ex_result> ExtractModuleData(per_allot allot, string groupName, boo
logService
.
ReturnTheLog
(
allot
.
ID
,
groupName
,
3
,
""
,
ratio
>
20
?
20
:
ratio
,
1
,
isSingle
);
logService
.
ReturnTheLog
(
allot
.
ID
,
groupName
,
3
,
""
,
ratio
>
20
?
20
:
ratio
,
1
,
isSingle
);
logService
.
ReturnTheLog
(
allot
.
ID
,
groupName
,
2
,
"提取数据"
,
$"开始提取模块“
{
string
.
Join
(
"、"
,
thisModules
.
Select
(
t
=>
t
.
ModuleName
))}
”的数据"
,
1
,
isSingle
);
logService
.
ReturnTheLog
(
allot
.
ID
,
groupName
,
2
,
"提取数据"
,
$"开始提取模块“
{
string
.
Join
(
"、"
,
thisModules
.
Select
(
t
=>
t
.
ModuleName
))}
”的数据"
,
1
,
isSingle
);
Dictionary
<
int
,
IDbConnection
>
pools
=
new
Dictionary
<
int
,
IDbConnection
>();
foreach
(
var
script
in
scripts
.
Where
(
t
=>
t
.
TypeId
==
typeId
))
foreach
(
var
script
in
scripts
.
Where
(
t
=>
t
.
TypeId
==
typeId
))
{
{
var
config
=
configs
.
FirstOrDefault
(
t
=>
t
.
Id
==
script
.
ConfigId
);
var
config
=
configs
.
FirstOrDefault
(
t
=>
t
.
Id
==
script
.
ConfigId
);
...
@@ -203,20 +202,7 @@ private List<ex_result> ExtractModuleData(per_allot allot, string groupName, boo
...
@@ -203,20 +202,7 @@ private List<ex_result> ExtractModuleData(per_allot allot, string groupName, boo
try
try
{
{
try
var
querydata
=
QueryData
<
ExtractDto
>(
config
,
script
.
ExecScript
,
allot
,
isSingle
);
{
if
(!
pools
.
ContainsKey
(
config
.
Id
))
pools
.
Add
(
config
.
Id
,
ConnectionBuilder
.
Create
((
DatabaseType
)
config
.
DataBaseType
,
config
.
DbSource
,
config
.
DbName
,
config
.
DbUser
,
config
.
DbPassword
));
}
catch
{
logService
.
ReturnTheLog
(
allot
.
ID
,
groupName
,
2
,
"数据库连接"
,
$"数据库“
{
config
.
DbName
}
”连接失败"
,
3
,
isSingle
);
}
IDbConnection
connection
=
pools
[
config
.
Id
];
var
parameters
=
GetParameters
(
allot
);
var
querydata
=
QueryData
(
connection
,
parameters
,
script
.
ExecScript
);
if
(
querydata
!=
null
&&
querydata
.
Any
())
if
(
querydata
!=
null
&&
querydata
.
Any
())
{
{
...
@@ -287,7 +273,7 @@ private List<ex_result> ExtractItemData(per_allot allot, string groupName, bool
...
@@ -287,7 +273,7 @@ private List<ex_result> ExtractItemData(per_allot allot, string groupName, bool
var
config
=
configs
.
FirstOrDefault
(
t
=>
t
.
Id
==
script
.
ConfigId
);
var
config
=
configs
.
FirstOrDefault
(
t
=>
t
.
Id
==
script
.
ConfigId
);
if
(
config
==
null
)
continue
;
if
(
config
==
null
)
continue
;
var
querydata
=
QueryData
(
config
,
allot
,
script
.
ExecScript
);
var
querydata
=
QueryData
<
ExtractDto
>(
config
,
script
.
ExecScript
,
allot
,
isSingle
);
if
(
querydata
!=
null
&&
querydata
.
Any
())
if
(
querydata
!=
null
&&
querydata
.
Any
())
{
{
thisItems
.
ForEach
(
f
=>
thisItems
.
ForEach
(
f
=>
...
@@ -351,7 +337,7 @@ private List<ex_result> ExtractSpecialData(per_allot allot, string groupName, bo
...
@@ -351,7 +337,7 @@ private List<ex_result> ExtractSpecialData(per_allot allot, string groupName, bo
var
config
=
configs
.
FirstOrDefault
(
t
=>
t
.
Id
==
script
.
ConfigId
);
var
config
=
configs
.
FirstOrDefault
(
t
=>
t
.
Id
==
script
.
ConfigId
);
if
(
config
==
null
)
continue
;
if
(
config
==
null
)
continue
;
var
querydata
=
QueryData
(
config
,
allot
,
script
.
ExecScript
);
var
querydata
=
QueryData
<
ExtractDto
>(
config
,
script
.
ExecScript
,
allot
,
isSingle
);
if
(
querydata
!=
null
&&
querydata
.
Any
())
if
(
querydata
!=
null
&&
querydata
.
Any
())
{
{
thisSpecials
.
ForEach
(
f
=>
thisSpecials
.
ForEach
(
f
=>
...
@@ -396,54 +382,29 @@ private List<ex_result> ExtractSpecialData(per_allot allot, string groupName, bo
...
@@ -396,54 +382,29 @@ private List<ex_result> ExtractSpecialData(per_allot allot, string groupName, bo
/// <param name="source"></param>
/// <param name="source"></param>
/// <param name="category"></param>
/// <param name="category"></param>
/// <returns></returns>
/// <returns></returns>
public
IEnumerable
<
ExtractDto
>
QueryData
(
sys_hospitalconfig
config
,
per_allot
allot
,
string
execsql
)
public
IEnumerable
<
T
>
QueryData
<
T
>(
sys_hospitalconfig
config
,
string
execsql
,
per_allot
allot
,
bool
isSingle
)
{
{
var
parameters
=
GetParameters
(
allot
);
var
parameters
=
GetParameters
(
allot
);
using
(
var
connection
=
ConnectionBuilder
.
Create
((
DatabaseType
)
config
.
DataBaseType
,
config
.
DbSource
,
config
.
DbName
,
config
.
DbUser
,
config
.
DbPassword
))
{
return
QueryData
(
connection
,
parameters
,
execsql
);
}
}
/// <summary>
/// 查询数据
/// </summary>
/// <param name="config"></param>
/// <param name="allot"></param>
/// <param name="execsql"></param>
/// <param name="source"></param>
/// <param name="category"></param>
/// <returns></returns>
public
IEnumerable
<
ExtractDto
>
QueryData
(
IDbConnection
connection
,
Dictionary
<
string
,
string
>
parameters
,
string
execsql
)
{
foreach
(
var
item
in
parameters
)
foreach
(
var
item
in
parameters
)
{
{
execsql
=
Regex
.
Replace
(
execsql
,
item
.
Key
,
item
.
Value
,
RegexOptions
.
IgnoreCase
);
execsql
=
Regex
.
Replace
(
execsql
,
item
.
Key
,
item
.
Value
,
RegexOptions
.
IgnoreCase
);
}
}
logger
.
LogInformation
(
$"提取绩效数据SQL脚本
{
execsql
}
"
);
IDbConnection
connection
=
null
;
var
result
=
connection
.
Query
<
ExtractDto
>(
execsql
,
commandTimeout
:
20000
);
try
logger
.
LogInformation
(
$"提取绩效数据执行脚本获取数据
{
result
?.
Count
()
??
0
}
条记录"
);
{
if
(!
pools
.
ContainsKey
(
config
.
Id
))
pools
.
Add
(
config
.
Id
,
ConnectionBuilder
.
Create
((
DatabaseType
)
config
.
DataBaseType
,
config
.
DbSource
,
config
.
DbName
,
config
.
DbUser
,
config
.
DbPassword
));
connection
=
pools
[
config
.
Id
];
return
result
;
if
(
connection
==
null
)
return
Enumerable
.
Empty
<
T
>();
}
/// <summary>
if
(
connection
.
State
==
ConnectionState
.
Closed
)
/// 查询数据
connection
.
Open
();
/// </summary>
}
/// <param name="config"></param>
catch
/// <param name="allot"></param>
/// <param name="execsql"></param>
/// <param name="source"></param>
/// <param name="category"></param>
/// <returns></returns>
public
IEnumerable
<
T
>
QueryData
<
T
>(
sys_hospitalconfig
config
,
per_allot
allot
,
string
execsql
)
{
var
parameters
=
GetParameters
(
allot
);
using
(
var
connection
=
ConnectionBuilder
.
Create
((
DatabaseType
)
config
.
DataBaseType
,
config
.
DbSource
,
config
.
DbName
,
config
.
DbUser
,
config
.
DbPassword
))
{
foreach
(
var
item
in
parameters
)
{
{
execsql
=
Regex
.
Replace
(
execsql
,
item
.
Key
,
item
.
Value
,
RegexOptions
.
IgnoreCas
e
);
logService
.
ReturnTheLog
(
allot
.
ID
,
allot
.
ID
.
ToString
(),
2
,
"数据库连接"
,
$"数据库“
{
config
.
DbName
}
”连接失败"
,
3
,
isSingl
e
);
}
}
logger
.
LogInformation
(
$"提取绩效数据SQL脚本
{
execsql
}
"
);
logger
.
LogInformation
(
$"提取绩效数据SQL脚本
{
execsql
}
"
);
...
@@ -452,7 +413,6 @@ public IEnumerable<T> QueryData<T>(sys_hospitalconfig config, per_allot allot, s
...
@@ -452,7 +413,6 @@ public IEnumerable<T> QueryData<T>(sys_hospitalconfig config, per_allot allot, s
return
result
;
return
result
;
}
}
}
/// <summary>
/// <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