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
e430cd4d
Commit
e430cd4d
authored
Feb 22, 2021
by
lcx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
大屏数据导入工作量效率优化
parent
95faf43c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
4 deletions
+48
-4
performance/Performance.Repository/BaseRepository.cs
+44
-1
performance/Performance.Repository/Performance.Repository.csproj
+1
-0
performance/Performance.Services/ReportGlobalService.cs
+3
-3
No files found.
performance/Performance.Repository/BaseRepository.cs
View file @
e430cd4d
...
@@ -4,8 +4,8 @@
...
@@ -4,8 +4,8 @@
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq
;
using
System.Linq.Expressions
;
using
System.Linq.Expressions
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Z.EntityFramework.Extensions
;
namespace
Performance.Repository
namespace
Performance.Repository
{
{
...
@@ -23,18 +23,22 @@ public TEntity DapperQueryFirst(string sql, object param)
...
@@ -23,18 +23,22 @@ public TEntity DapperQueryFirst(string sql, object param)
{
{
return
context
.
Database
.
GetDbConnection
().
QueryFirst
<
TEntity
>(
sql
,
param
);
return
context
.
Database
.
GetDbConnection
().
QueryFirst
<
TEntity
>(
sql
,
param
);
}
}
public
IEnumerable
<
TEntity
>
DapperQuery
(
string
sql
,
object
param
)
public
IEnumerable
<
TEntity
>
DapperQuery
(
string
sql
,
object
param
)
{
{
return
context
.
Database
.
GetDbConnection
().
Query
<
TEntity
>(
sql
,
param
);
return
context
.
Database
.
GetDbConnection
().
Query
<
TEntity
>(
sql
,
param
);
}
}
public
IEnumerable
<
TEntity
>
DapperQuery
(
string
sql
,
object
param
,
int
?
commandTimeout
=
null
)
public
IEnumerable
<
TEntity
>
DapperQuery
(
string
sql
,
object
param
,
int
?
commandTimeout
=
null
)
{
{
return
context
.
Database
.
GetDbConnection
().
Query
<
TEntity
>(
sql
,
param
,
commandTimeout
:
commandTimeout
);
return
context
.
Database
.
GetDbConnection
().
Query
<
TEntity
>(
sql
,
param
,
commandTimeout
:
commandTimeout
);
}
}
public
IEnumerable
<
T
>
DapperQuery
<
T
>(
string
sql
,
object
param
)
where
T
:
class
,
new
()
public
IEnumerable
<
T
>
DapperQuery
<
T
>(
string
sql
,
object
param
)
where
T
:
class
,
new
()
{
{
return
context
.
Database
.
GetDbConnection
().
Query
<
T
>(
sql
,
param
);
return
context
.
Database
.
GetDbConnection
().
Query
<
T
>(
sql
,
param
);
}
}
public
T
DapperQueryFirstOrDefault
<
T
>(
string
sql
,
object
param
)
public
T
DapperQueryFirstOrDefault
<
T
>(
string
sql
,
object
param
)
{
{
return
context
.
Database
.
GetDbConnection
().
QueryFirstOrDefault
<
T
>(
sql
,
param
);
return
context
.
Database
.
GetDbConnection
().
QueryFirstOrDefault
<
T
>(
sql
,
param
);
...
@@ -79,11 +83,13 @@ public bool Remove(TEntity entity)
...
@@ -79,11 +83,13 @@ public bool Remove(TEntity entity)
context
.
Set
<
TEntity
>().
Remove
(
entity
);
context
.
Set
<
TEntity
>().
Remove
(
entity
);
return
context
.
SaveChanges
()
>
0
;
return
context
.
SaveChanges
()
>
0
;
}
}
public
bool
RemoveRange
(
params
TEntity
[]
entities
)
public
bool
RemoveRange
(
params
TEntity
[]
entities
)
{
{
context
.
Set
<
TEntity
>().
RemoveRange
(
entities
);
context
.
Set
<
TEntity
>().
RemoveRange
(
entities
);
return
context
.
SaveChanges
()
>
0
;
return
context
.
SaveChanges
()
>
0
;
}
}
public
bool
RemoveRange
(
Expression
<
Func
<
TEntity
,
bool
>>
exp
)
public
bool
RemoveRange
(
Expression
<
Func
<
TEntity
,
bool
>>
exp
)
{
{
var
query
=
CompileQuery
(
exp
);
var
query
=
CompileQuery
(
exp
);
...
@@ -144,5 +150,42 @@ private TEntity CompileQuerySingle(Expression<Func<TEntity, bool>> exp)
...
@@ -144,5 +150,42 @@ private TEntity CompileQuerySingle(Expression<Func<TEntity, bool>> exp)
var
func
=
EF
.
CompileQuery
((
DbContext
context
,
Expression
<
Func
<
TEntity
,
bool
>>
exps
)
=>
context
.
Set
<
TEntity
>().
FirstOrDefault
(
exp
));
var
func
=
EF
.
CompileQuery
((
DbContext
context
,
Expression
<
Func
<
TEntity
,
bool
>>
exps
)
=>
context
.
Set
<
TEntity
>().
FirstOrDefault
(
exp
));
return
func
(
context
,
exp
);
return
func
(
context
,
exp
);
}
}
#
region
Bulk
public
void
BulkInsert
(
IEnumerable
<
TEntity
>
entities
)
{
EntityFrameworkManager
.
ContextFactory
=
factory
=>
context
;
context
.
Set
<
TEntity
>().
BulkInsert
(
entities
);
context
.
BulkSaveChanges
();
}
public
async
Task
BulkInsertAsync
(
IEnumerable
<
TEntity
>
entities
)
{
EntityFrameworkManager
.
ContextFactory
=
factory
=>
context
;
await
context
.
Set
<
TEntity
>().
BulkInsertAsync
(
entities
);
await
context
.
BulkSaveChangesAsync
();
}
public
int
DeleteFromQuery
(
Expression
<
Func
<
TEntity
,
bool
>>
exp
)
{
return
context
.
Set
<
TEntity
>().
Where
(
exp
).
DeleteFromQuery
();
}
public
void
BulkDelete
(
IEnumerable
<
TEntity
>
entities
)
{
EntityFrameworkManager
.
ContextFactory
=
factory
=>
context
;
context
.
Set
<
TEntity
>().
BulkDelete
(
entities
);
context
.
BulkSaveChanges
();
}
public
async
Task
BulkDeleteAsync
(
IEnumerable
<
TEntity
>
entities
)
{
EntityFrameworkManager
.
ContextFactory
=
factory
=>
context
;
await
context
.
Set
<
TEntity
>().
BulkDeleteAsync
(
entities
);
await
context
.
BulkSaveChangesAsync
();
}
#
endregion
Bulk
}
}
}
}
performance/Performance.Repository/Performance.Repository.csproj
View file @
e430cd4d
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
<PackageReference Include="MySql.Data" Version="8.0.15" />
<PackageReference Include="MySql.Data" Version="8.0.15" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.15" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.15" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.19.60" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.19.60" />
<PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="2.8.20" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
...
...
performance/Performance.Services/ReportGlobalService.cs
View file @
e430cd4d
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
using
Performance.Services.ExtractExcelService
;
using
Performance.Services.ExtractExcelService
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Linq
;
using
System.Text
;
using
System.Text
;
...
@@ -204,10 +205,9 @@ public void ImportAllotData(int hospitalId, string filePath)
...
@@ -204,10 +205,9 @@ public void ImportAllotData(int hospitalId, string filePath)
var
years
=
data
.
Select
(
t
=>
t
.
Year
).
Distinct
();
var
years
=
data
.
Select
(
t
=>
t
.
Year
).
Distinct
();
var
months
=
data
.
Select
(
t
=>
t
.
Month
).
Distinct
();
var
months
=
data
.
Select
(
t
=>
t
.
Month
).
Distinct
();
var
historyData
=
hisimportdataRepository
.
GetEntities
(
t
=>
t
.
HospitalId
==
hospitalId
&&
years
.
Contains
(
t
.
Year
)
&&
months
.
Contains
(
t
.
Month
)
&&
t
.
Category
==
sheetName
);
if
(
historyData
!=
null
&&
historyData
.
Any
())
hisimportdataRepository
.
RemoveRange
(
historyData
.
ToArray
());
hisimportdataRepository
.
AddRange
(
data
.
Where
(
t
=>
t
.
Year
!=
0
&&
t
.
Month
!=
0
).
ToArray
());
hisimportdataRepository
.
DeleteFromQuery
(
t
=>
t
.
HospitalId
==
hospitalId
&&
years
.
Contains
(
t
.
Year
)
&&
months
.
Contains
(
t
.
Month
)
&&
t
.
Category
==
sheetName
);
hisimportdataRepository
.
BulkInsert
(
data
.
Where
(
t
=>
t
.
Year
!=
0
&&
t
.
Month
!=
0
));
}
}
}
}
catch
(
Exception
ex
)
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