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
064e84b5
Commit
064e84b5
authored
May 16, 2022
by
ruyun.zhang@suvalue.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
报表查询方法修改
parent
8a1844e5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
290 additions
and
185 deletions
+290
-185
performance/Performance.Api/wwwroot/Performance.DtoModels.xml
+15
-0
performance/Performance.Api/wwwroot/Performance.EntityModels.xml
+0
-10
performance/Performance.DtoModels/ReportStatistics/ReportStatisticsInfoDto.cs
+14
-2
performance/Performance.EntityModels/Entity/report_statistics.cs
+9
-8
performance/Performance.Services/StatisticsService.cs
+252
-165
No files found.
performance/Performance.Api/wwwroot/Performance.DtoModels.xml
View file @
064e84b5
...
@@ -1786,6 +1786,21 @@
...
@@ -1786,6 +1786,21 @@
结果返回用途 首次查询 0 用于比对 1 用于对比
结果返回用途 首次查询 0 用于比对 1 用于对比
</summary>
</summary>
</member>
</member>
<member
name=
"P:Performance.DtoModels.StatisticsColumn.ColumnName"
>
<summary>
显示名
</summary>
</member>
<member
name=
"P:Performance.DtoModels.StatisticsColumn.OrgColumnName"
>
<summary>
原始名,对应到数据列
</summary>
</member>
<member
name=
"P:Performance.DtoModels.StatisticsColumn.Fixed"
>
<summary>
固定
</summary>
</member>
<member
name=
"P:Performance.DtoModels.ReportTable.PersonnelName"
>
<member
name=
"P:Performance.DtoModels.ReportTable.PersonnelName"
>
<summary>
<summary>
人员信息
人员信息
...
...
performance/Performance.Api/wwwroot/Performance.EntityModels.xml
View file @
064e84b5
...
@@ -7405,16 +7405,6 @@
...
@@ -7405,16 +7405,6 @@
汇总数值SQL
汇总数值SQL
</summary>
</summary>
</member>
</member>
<member
name=
"P:Performance.EntityModels.report_statistics.ProportionScript"
>
<summary>
占比SQL
</summary>
</member>
<member
name=
"P:Performance.EntityModels.report_statistics.WeightScript"
>
<summary>
权重SQL
</summary>
</member>
<member
name=
"T:Performance.EntityModels.report_statistics_selection"
>
<member
name=
"T:Performance.EntityModels.report_statistics_selection"
>
<summary>
<summary>
...
...
performance/Performance.DtoModels/ReportStatistics/ReportStatisticsInfoDto.cs
View file @
064e84b5
...
@@ -58,7 +58,7 @@ public class StatisticsSelectionDto
...
@@ -58,7 +58,7 @@ public class StatisticsSelectionDto
public
List
<
TitleValue
>
Options
{
get
;
set
;
}
public
List
<
TitleValue
>
Options
{
get
;
set
;
}
}
}
public
class
StatisticsQuery
public
class
StatisticsQuery
...
@@ -86,10 +86,22 @@ public class StatisticsColumn
...
@@ -86,10 +86,22 @@ public class StatisticsColumn
{
{
public
StatisticsColumn
()
public
StatisticsColumn
()
{
{
ColumnName
=
""
;
OrgColumnName
=
""
;
Fixed
=
""
;
ChildColumns
=
new
List
<
StatisticsColumn
>();
ChildColumns
=
new
List
<
StatisticsColumn
>();
}
}
/// <summary>
/// 显示名
/// </summary>
public
string
ColumnName
{
get
;
set
;
}
public
string
ColumnName
{
get
;
set
;
}
/// <summary>
/// 原始名,对应到数据列
/// </summary>
public
string
OrgColumnName
{
get
;
set
;
}
/// <summary>
/// 固定
/// </summary>
public
string
Fixed
{
get
;
set
;
}
public
string
Fixed
{
get
;
set
;
}
public
List
<
StatisticsColumn
>
ChildColumns
{
get
;
set
;
}
public
List
<
StatisticsColumn
>
ChildColumns
{
get
;
set
;
}
}
}
...
...
performance/Performance.EntityModels/Entity/report_statistics.cs
View file @
064e84b5
...
@@ -35,14 +35,14 @@ public class report_statistics
...
@@ -35,14 +35,14 @@ public class report_statistics
/// </summary>
/// </summary>
public
string
TotalScript
{
get
;
set
;
}
public
string
TotalScript
{
get
;
set
;
}
/// <summary>
///
//
<summary>
/// 占比SQL
///
//
占比SQL
/// </summary>
///
//
</summary>
public
string
ProportionScript
{
get
;
set
;
}
//
public string ProportionScript { get; set; }
/// <summary>
///
//
<summary>
/// 权重SQL
///
//
权重SQL
/// </summary>
///
//
</summary>
public
string
WeightScript
{
get
;
set
;
}
//
public string WeightScript { get; set; }
}
}
}
}
\ No newline at end of file
performance/Performance.Services/StatisticsService.cs
View file @
064e84b5
...
@@ -11,66 +11,98 @@
...
@@ -11,66 +11,98 @@
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Data
;
using
System.Linq
;
using
System.Linq
;
using
System.Text.RegularExpressions
;
namespace
Performance.Services
namespace
Performance.Services
{
{
public
class
StatisticsService
:
IAutoInjection
public
class
StatisticsService
:
IAutoInjection
{
{
private
readonly
ILogger
<
StatisticsService
>
logger
;
private
readonly
ILogger
<
StatisticsService
>
_
logger
;
private
readonly
IOptions
<
AppConnection
>
options
;
private
readonly
IOptions
<
AppConnection
>
_
options
;
private
readonly
PerforReportStatisticsRepository
R
eportStatisticsRepository
;
private
readonly
PerforReportStatisticsRepository
_r
eportStatisticsRepository
;
private
readonly
PerforReportStatisticsSelectionRepository
R
eportStatisticsSelectionRepository
;
private
readonly
PerforReportStatisticsSelectionRepository
_r
eportStatisticsSelectionRepository
;
private
readonly
PerforReportStatisticsSelectionRecordRepository
R
eportStatisticsSelectionRecordRepository
;
private
readonly
PerforReportStatisticsSelectionRecordRepository
_r
eportStatisticsSelectionRecordRepository
;
private
readonly
PerforReportStatisticsStoreRepository
R
eportStatisticsStoreRepository
;
private
readonly
PerforReportStatisticsStoreRepository
_r
eportStatisticsStoreRepository
;
private
readonly
PerforReportStatisticsTreeRepository
R
eportStatisticsTreeRepository
;
private
readonly
PerforReportStatisticsTreeRepository
_r
eportStatisticsTreeRepository
;
public
StatisticsService
(
public
StatisticsService
(
ILogger
<
StatisticsService
>
logger
,
ILogger
<
StatisticsService
>
logger
,
IOptions
<
AppConnection
>
options
,
IOptions
<
AppConnection
>
options
,
PerforReportStatisticsRepository
ReportStatisticsRepository
,
PerforReportStatisticsRepository
ReportStatisticsRepository
,
PerforReportStatisticsSelectionRepository
ReportStatisticsSelectionRepository
,
PerforReportStatisticsSelectionRepository
ReportStatisticsSelectionRepository
,
PerforReportStatisticsSelectionRecordRepository
ReportStatisticsSelectionRecordRepository
,
PerforReportStatisticsSelectionRecordRepository
ReportStatisticsSelectionRecordRepository
,
PerforReportStatisticsStoreRepository
ReportStatisticsStoreRepository
,
PerforReportStatisticsStoreRepository
ReportStatisticsStoreRepository
,
PerforReportStatisticsTreeRepository
ReportStatisticsTreeRepository
PerforReportStatisticsTreeRepository
ReportStatisticsTreeRepository
)
)
{
{
this
.
logger
=
logger
;
_
logger
=
logger
;
this
.
options
=
options
;
_
options
=
options
;
this
.
R
eportStatisticsRepository
=
ReportStatisticsRepository
;
_r
eportStatisticsRepository
=
ReportStatisticsRepository
;
this
.
R
eportStatisticsSelectionRepository
=
ReportStatisticsSelectionRepository
;
_r
eportStatisticsSelectionRepository
=
ReportStatisticsSelectionRepository
;
this
.
R
eportStatisticsSelectionRecordRepository
=
ReportStatisticsSelectionRecordRepository
;
_r
eportStatisticsSelectionRecordRepository
=
ReportStatisticsSelectionRecordRepository
;
this
.
R
eportStatisticsStoreRepository
=
ReportStatisticsStoreRepository
;
_r
eportStatisticsStoreRepository
=
ReportStatisticsStoreRepository
;
this
.
R
eportStatisticsTreeRepository
=
ReportStatisticsTreeRepository
;
_r
eportStatisticsTreeRepository
=
ReportStatisticsTreeRepository
;
}
}
p
ublic
StatisticsInfoDto
GetInfo
(
int
hospitalID
,
int
statisticsId
)
p
rivate
(
string
sql
,
DynamicParameters
param
)
GetSqlQuery
(
string
sql
,
Dictionary
<
string
,
object
>
pairs
)
{
{
//var json = JsonHelper.Serialize(ReportStatisticsStore);
List
<
string
>
plist
=
new
List
<
string
>();
//var dic = JsonHelper.Deserialize<Dictionary<string, string>>(json);
foreach
(
var
item
in
pairs
)
{
if
(!
Regex
.
IsMatch
(
sql
,
$"@
{
item
.
Key
}
"
,
RegexOptions
.
IgnoreCase
|
RegexOptions
.
Multiline
))
{
var
key
=
item
.
Key
.
StartsWith
(
"@"
)
?
item
.
Key
.
Substring
(
1
,
item
.
Key
.
Length
-
1
)
:
item
.
Key
;
if
(
item
.
Value
.
GetType
().
GetInterfaces
().
Any
(
iface
=>
iface
.
IsGenericType
&&
iface
.
GetGenericTypeDefinition
()
==
typeof
(
ICollection
<>)))
plist
.
Add
(
$"
{
key
}
IN @
{
key
}
"
);
else
plist
.
Add
(
$"
{
key
}
= @
{
key
}
"
);
}
}
string
@wh
=
string
.
Join
(
" AND "
,
plist
.
ToArray
());
// 多种占位方式
string
[]
ws
=
new
string
[]
{
"@wh"
,
"@w"
,
"{w}"
,
"{wh}"
};
foreach
(
var
item
in
ws
)
{
if
(
Regex
.
IsMatch
(
sql
,
item
,
RegexOptions
.
IgnoreCase
|
RegexOptions
.
Multiline
))
sql
=
Regex
.
Replace
(
sql
,
item
,
@wh
,
RegexOptions
.
IgnoreCase
|
RegexOptions
.
Multiline
);
}
DynamicParameters
param
=
new
DynamicParameters
();
foreach
(
var
item
in
pairs
)
{
var
key
=
item
.
Key
.
StartsWith
(
"@"
)
?
item
.
Key
:
$"@
{
item
.
Key
}
"
;
param
.
Add
(
key
,
item
.
Value
);
}
var
ReportStatistics
=
ReportStatisticsRepository
.
GetEntity
(
t
=>
t
.
ID
==
statisticsId
&&
t
.
HospitalId
==
hospitalID
);
return
(
sql
,
param
);
if
(
ReportStatistics
==
null
)
}
public
StatisticsInfoDto
GetInfo
(
int
hospitalID
,
int
statisticsId
)
{
var
reportStatistics
=
_reportStatisticsRepository
.
GetEntity
(
t
=>
t
.
ID
==
statisticsId
&&
t
.
HospitalId
==
hospitalID
);
if
(
reportStatistics
==
null
)
return
new
StatisticsInfoDto
();
return
new
StatisticsInfoDto
();
var
ReportStatisticsSelection
=
ReportStatisticsSelectionRepository
.
GetEntities
(
t
=>
t
.
StatisticsID
==
R
eportStatistics
.
ID
);
var
reportStatisticsSelection
=
_reportStatisticsSelectionRepository
.
GetEntities
(
t
=>
t
.
StatisticsID
==
r
eportStatistics
.
ID
);
if
(
R
eportStatisticsSelection
.
Count
==
0
)
if
(
r
eportStatisticsSelection
.
Count
==
0
)
return
new
StatisticsInfoDto
();
return
new
StatisticsInfoDto
();
var
result
=
new
StatisticsInfoDto
()
var
result
=
new
StatisticsInfoDto
()
{
{
StatisticsID
=
statisticsId
,
StatisticsID
=
statisticsId
,
HospitalId
=
(
int
)
R
eportStatistics
.
HospitalId
,
HospitalId
=
(
int
)
r
eportStatistics
.
HospitalId
,
Name
=
R
eportStatistics
.
Name
,
Name
=
r
eportStatistics
.
Name
,
IsComparison
=
(
int
)
R
eportStatistics
.
IsComparison
,
IsComparison
=
(
int
)
r
eportStatistics
.
IsComparison
,
Selections
=
new
List
<
StatisticsSelectionDto
>
{
}
Selections
=
new
List
<
StatisticsSelectionDto
>
{
}
};
};
Dictionary
<
string
,
object
>
pairs
=
new
Dictionary
<
string
,
object
>
foreach
(
var
item
in
ReportStatisticsSelection
)
{
{
string
sql
=
$"SELECT
{
item
.
InputName
}
Title,
{
item
.
InputName
}
Value FROM report_statistics_store Where HospitalID =
{
hospitalID
}
GROUP BY
{
item
.
InputName
}
ORDER BY
{
item
.
InputName
}
"
;
{
"@hospitalId"
,
hospitalID
},
};
var
ReportStatisticsStore
=
ReportStatisticsStoreRepository
.
DapperQuery
<
TitleValue
>(
sql
,
null
).
ToList
();
foreach
(
var
item
in
reportStatisticsSelection
)
{
var
(
sql
,
param
)
=
GetSqlQuery
(
item
.
Content
,
pairs
);
var
reportStatisticsStore
=
_reportStatisticsStoreRepository
.
DapperQuery
<
TitleValue
>(
sql
,
param
).
ToList
();
R
eportStatisticsStore
.
ForEach
(
t
=>
t
.
State
=
(
int
)
item
.
State
);
r
eportStatisticsStore
.
ForEach
(
t
=>
t
.
State
=
(
int
)
item
.
State
);
StatisticsSelectionDto
statisticsSelectionDto
=
new
StatisticsSelectionDto
()
StatisticsSelectionDto
statisticsSelectionDto
=
new
StatisticsSelectionDto
()
{
{
...
@@ -81,7 +113,7 @@ public StatisticsInfoDto GetInfo(int hospitalID, int statisticsId)
...
@@ -81,7 +113,7 @@ public StatisticsInfoDto GetInfo(int hospitalID, int statisticsId)
Required
=
item
.
Required
,
Required
=
item
.
Required
,
Sort
=
item
.
Sort
,
Sort
=
item
.
Sort
,
Title
=
item
.
Title
,
Title
=
item
.
Title
,
Options
=
R
eportStatisticsStore
Options
=
r
eportStatisticsStore
};
};
result
.
Selections
.
Add
(
statisticsSelectionDto
);
result
.
Selections
.
Add
(
statisticsSelectionDto
);
}
}
...
@@ -90,7 +122,7 @@ public StatisticsInfoDto GetInfo(int hospitalID, int statisticsId)
...
@@ -90,7 +122,7 @@ public StatisticsInfoDto GetInfo(int hospitalID, int statisticsId)
public
List
<
report_statistics_selection_record
>
GetSelectionRecord
(
int
hospitalID
,
int
statisticsId
)
public
List
<
report_statistics_selection_record
>
GetSelectionRecord
(
int
hospitalID
,
int
statisticsId
)
{
{
var
result
=
R
eportStatisticsSelectionRecordRepository
.
GetEntities
(
t
=>
t
.
HospitalId
==
hospitalID
&&
t
.
StatisticsID
==
statisticsId
).
OrderByDescending
(
t
=>
t
.
UpdateDate
).
ToList
();
var
result
=
_r
eportStatisticsSelectionRecordRepository
.
GetEntities
(
t
=>
t
.
HospitalId
==
hospitalID
&&
t
.
StatisticsID
==
statisticsId
).
OrderByDescending
(
t
=>
t
.
UpdateDate
).
ToList
();
return
result
;
return
result
;
}
}
...
@@ -98,178 +130,233 @@ public ApiResponse SaveSelectionRecord(report_statistics_selection_record record
...
@@ -98,178 +130,233 @@ public ApiResponse SaveSelectionRecord(report_statistics_selection_record record
{
{
record
.
Content
=
JsonHelper
.
Serialize
(
record
.
Content
);
record
.
Content
=
JsonHelper
.
Serialize
(
record
.
Content
);
var
result
=
R
eportStatisticsSelectionRecordRepository
.
GetEntity
(
t
=>
t
.
ID
==
record
.
ID
);
var
result
=
_r
eportStatisticsSelectionRecordRepository
.
GetEntity
(
t
=>
t
.
ID
==
record
.
ID
);
bool
ok
;
bool
ok
;
if
(
result
!=
null
)
if
(
result
!=
null
)
{
{
result
.
UpdateDate
=
DateTime
.
Now
;
result
.
UpdateDate
=
DateTime
.
Now
;
ok
=
R
eportStatisticsSelectionRecordRepository
.
Update
(
record
);
ok
=
_r
eportStatisticsSelectionRecordRepository
.
Update
(
record
);
}
}
else
else
{
{
record
.
CreateDate
=
DateTime
.
Now
;
record
.
CreateDate
=
DateTime
.
Now
;
ok
=
R
eportStatisticsSelectionRecordRepository
.
Add
(
record
);
ok
=
_r
eportStatisticsSelectionRecordRepository
.
Add
(
record
);
}
}
if
(
ok
)
return
new
ApiResponse
(
ResponseType
.
OK
);
if
(
ok
)
return
new
ApiResponse
(
ResponseType
.
OK
);
else
return
new
ApiResponse
(
ResponseType
.
Fail
);
else
return
new
ApiResponse
(
ResponseType
.
Fail
);
}
}
public
StatisticsQueryResultDto
Search
(
StatisticsQuery
query
)
public
StatisticsQueryResultDto
Search
(
StatisticsQuery
query
)
{
{
var
ReportStatistics
=
R
eportStatisticsRepository
.
GetEntity
(
t
=>
t
.
ID
==
query
.
StatisticsID
&&
t
.
HospitalId
==
query
.
HospitalID
);
var
reportStatistics
=
_r
eportStatisticsRepository
.
GetEntity
(
t
=>
t
.
ID
==
query
.
StatisticsID
&&
t
.
HospitalId
==
query
.
HospitalID
);
if
(
R
eportStatistics
==
null
)
if
(
r
eportStatistics
==
null
)
return
new
StatisticsQueryResultDto
();
return
new
StatisticsQueryResultDto
();
var
ReportStatisticsTree
=
ReportStatisticsTreeRepository
.
GetEntities
(
t
=>
t
.
StatisticsID
==
query
.
StatisticsID
)
;
Dictionary
<
string
,
object
>
pairs
=
new
Dictionary
<
string
,
object
>
{
}
;
var
reportStatisticsTree
=
_reportStatisticsTreeRepository
.
GetEntities
(
t
=>
t
.
StatisticsID
==
query
.
StatisticsID
);
var
isTree
=
(
reportStatisticsTree
!=
null
&&
reportStatisticsTree
.
Count
>
0
);
StatisticsQueryResultDto
dto
=
new
StatisticsQueryResultDto
/*
* 报表分三种
* 1.绩效情况六--各科室医护绩效对比 这是特殊的,直接查询视图,对列头特殊处理
* 2.没有层级 通过1条SQL查询全部数据展示
* 3.配置层级 通过层级查询固定SQL
*/
if
(
query
.
StatisticsID
==
7
)
return
StatisticsQuery7
(
query
,
reportStatistics
);
else
if
(!
isTree
)
return
StatisticsQuery
(
query
,
reportStatistics
);
else
return
StatisticsTreeQuery
(
query
,
reportStatisticsTree
);
}
/// <summary>
/// 绩效情况六--各科室医护绩效对比 这是特殊的,直接查询视图,对列头特殊处理
/// </summary>
/// <param name="query"></param>
/// <param name="statistics"></param>
/// <returns></returns>
private
StatisticsQueryResultDto
StatisticsQuery7
(
StatisticsQuery
query
,
report_statistics
statistics
)
{
Dictionary
<
string
,
object
>
pairs
=
new
Dictionary
<
string
,
object
>
{
{
IsComparison
=
ReportStatistics
.
IsComparison
,
{
"HospitalID"
,
query
.
HospitalID
},
Columns
=
new
List
<
StatisticsColumn
>
{
new
StatisticsColumn
{
ColumnName
=
"项目"
,
Fixed
=
"left"
,
},
},
Datas
=
new
List
<
Dictionary
<
string
,
string
>>()
{
}
};
};
foreach
(
var
item
in
query
.
Values
)
{
pairs
.
Add
(
item
.
Title
,
item
.
Values
);
}
var
table
=
new
List
<
Dictionary
<
string
,
string
>>();
using
(
IDbConnection
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
if
(!
string
.
IsNullOrEmpty
(
statistics
.
TotalScript
))
{
var
(
sql
,
param
)
=
GetSqlQuery
(
statistics
.
TotalScript
,
pairs
);
var
data
=
connection
.
Query
(
sql
,
param
);
table
=
JsonHelper
.
Deserialize
<
List
<
Dictionary
<
string
,
string
>>>(
JsonHelper
.
Serialize
(
data
));
}
}
var
columns
=
new
List
<
StatisticsColumn
>();
using
(
IDbConnection
connection
=
new
MySqlConnection
(
options
.
Value
.
PerformanceConnectionString
)
)
if
(
table
!=
null
&&
table
.
Count
>
0
)
{
{
if
(
ReportStatisticsTree
!=
null
&&
ReportStatisticsTree
.
Count
()
>
0
)
foreach
(
var
item
in
table
.
First
().
Keys
)
{
{
foreach
(
var
item
in
ReportStatisticsTree
)
/*
* 对列头特殊处理
* 按"_"拆分,并合并父子列头
*/
if
(!
item
.
Contains
(
"_"
))
{
{
List
<
string
>
where
=
new
List
<
string
>();
columns
.
Add
(
new
StatisticsColumn
{
ColumnName
=
item
,
OrgColumnName
=
item
,
Fixed
=
"left"
});
}
else
{
var
cols
=
item
.
SplitRemoveEmpty
(
"_"
);
foreach
(
var
queryValues
in
query
.
Values
)
var
col
=
columns
.
FirstOrDefault
(
w
=>
w
.
ColumnName
==
cols
.
First
());
if
(
col
==
null
)
{
{
StatisticsColumn
statisticsColumn
=
new
StatisticsColumn
col
=
new
StatisticsColumn
{
ColumnName
=
cols
.
First
(),
OrgColumnName
=
item
,
};
{
columns
.
Add
(
col
);
ColumnName
=
string
.
Join
(
"/"
,
queryValues
.
Values
),
Fixed
=
""
,
ChildColumns
=
new
List
<
StatisticsColumn
>()
{
new
StatisticsColumn
{
ColumnName
=
"数额"
,
Fixed
=
""
,
},
}
};
if
(!
dto
.
Columns
.
Select
(
t
=>
t
.
ColumnName
).
Contains
(
statisticsColumn
.
ColumnName
))
dto
.
Columns
.
Add
(
statisticsColumn
);
where
.
Add
(
$"
{
queryValues
.
Title
}
in ('
{
string
.
Join
(
"','"
,
queryValues
.
Values
)}
')"
);
}
}
string
sql
=
item
.
TotalScript
?.
Replace
(
"@wh"
,
string
.
Join
(
" and "
,
where
));
if
(!
col
.
ChildColumns
.
Any
(
w
=>
w
.
ColumnName
==
cols
.
Last
()))
col
.
ChildColumns
.
Add
(
new
StatisticsColumn
{
ColumnName
=
cols
.
Last
(),
OrgColumnName
=
item
,
});
var
data
=
new
Dictionary
<
string
,
string
>
{
{
"项目"
,
item
.
Name
},
{
"数额"
,
sql
==
null
?
""
:
connection
.
Query
<
string
>(
sql
).
FirstOrDefault
()},
{
"汇总公式"
,
item
.
TotalFormula
},
{
"占比公式"
,
item
.
ProportionFormula
},
{
"权重公式"
,
item
.
WeightFormula
},
};
dto
.
Datas
.
Add
(
data
);
}
}
var
ProportionFormula
=
ReportStatisticsTree
.
Any
(
t
=>
!
string
.
IsNullOrEmpty
(
t
.
ProportionFormula
));
}
var
WeightFormula
=
ReportStatisticsTree
.
Any
(
t
=>
!
string
.
IsNullOrEmpty
(
t
.
WeightFormula
));
}
return
new
StatisticsQueryResultDto
dto
.
Columns
.
ForEach
(
t
=>
{
{
IsComparison
=
query
.
IsComparison
,
if
(
t
.
ColumnName
!=
"项目"
)
Columns
=
columns
,
{
Datas
=
table
,
if
(
ProportionFormula
)
};
t
.
ChildColumns
.
Add
(
new
StatisticsColumn
()
{
ColumnName
=
"占比"
,
Fixed
=
""
});
}
if
(
WeightFormula
)
t
.
ChildColumns
.
Add
(
new
StatisticsColumn
()
{
ColumnName
=
"权重"
,
Fixed
=
""
});
if
(
ReportStatistics
.
IsComparison
==
1
&&
query
.
IsComparison
==
1
)
t
.
ChildColumns
.
Add
(
new
StatisticsColumn
()
{
ColumnName
=
"增降幅"
,
Fixed
=
""
});
}
});
/// <summary>
dto
.
Datas
.
ForEach
(
t
=>
/// 没有层级 通过1条SQL查询全部数据展示
{
/// </summary>
if
(
ProportionFormula
)
/// <param name="query"></param>
t
.
Add
(
"占比"
,
""
);
/// <param name="statistics"></param>
if
(
WeightFormula
)
/// <returns></returns>
t
.
Add
(
"权重"
,
""
);
private
StatisticsQueryResultDto
StatisticsQuery
(
StatisticsQuery
query
,
report_statistics
statistics
)
if
(
ReportStatistics
.
IsComparison
==
1
&&
query
.
IsComparison
==
1
)
{
t
.
Add
(
"增降幅"
,
""
);
Dictionary
<
string
,
object
>
pairs
=
new
Dictionary
<
string
,
object
>
});
{
{
"HospitalID"
,
query
.
HospitalID
},
};
foreach
(
var
item
in
query
.
Values
)
{
pairs
.
Add
(
item
.
Title
,
item
.
Values
);
}
var
table
=
new
List
<
Dictionary
<
string
,
string
>>();
using
(
IDbConnection
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
if
(!
string
.
IsNullOrEmpty
(
statistics
.
TotalScript
))
{
var
(
sql
,
param
)
=
GetSqlQuery
(
statistics
.
TotalScript
,
pairs
);
var
data
=
connection
.
Query
(
sql
,
param
);
table
=
JsonHelper
.
Deserialize
<
List
<
Dictionary
<
string
,
string
>>>(
JsonHelper
.
Serialize
(
data
));
}
}
else
}
var
columns
=
new
List
<
StatisticsColumn
>();
string
[]
cols
=
new
string
[]
{
"数值"
,
"金额"
,
"占比"
,
"权重"
};
if
(
table
!=
null
&&
table
.
Count
>
0
)
{
foreach
(
var
item
in
table
.
First
().
Keys
)
{
{
List
<
string
>
where
=
new
List
<
string
>();
columns
.
Add
(
new
StatisticsColumn
{
ColumnName
=
item
,
OrgColumnName
=
item
,
Fixed
=
cols
.
Contains
(
item
)
?
""
:
"left"
});
}
}
return
new
StatisticsQueryResultDto
{
IsComparison
=
query
.
IsComparison
,
Columns
=
columns
,
Datas
=
table
,
};
}
/// <summary>
/// 配置层级 通过层级查询固定SQL
/// </summary>
/// <param name="query"></param>
/// <param name="reportStatisticsTree"></param>
/// <returns></returns>
private
StatisticsQueryResultDto
StatisticsTreeQuery
(
StatisticsQuery
query
,
List
<
report_statistics_tree
>
reportStatisticsTree
)
{
var
columns
=
new
List
<
StatisticsColumn
>();
columns
.
Add
(
new
StatisticsColumn
{
ColumnName
=
"项目"
,
OrgColumnName
=
"项目"
,
Fixed
=
"left"
,
});
if
(
reportStatisticsTree
.
Any
(
w
=>
!
string
.
IsNullOrEmpty
(
w
.
TotalScript
)
||
!
string
.
IsNullOrEmpty
(
w
.
TotalFormula
)))
{
columns
.
Add
(
new
StatisticsColumn
{
ColumnName
=
"数值"
,
OrgColumnName
=
"数值"
,
});
columns
.
Add
(
new
StatisticsColumn
{
ColumnName
=
"数值公式"
,
OrgColumnName
=
"数值公式"
,
});
}
foreach
(
var
queryValues
in
query
.
Values
)
if
(
reportStatisticsTree
.
Any
(
w
=>
!
string
.
IsNullOrEmpty
(
w
.
ProportionFormula
)))
{
{
StatisticsColumn
statisticsColumn
=
new
StatisticsColumn
columns
.
Add
(
new
StatisticsColumn
{
ColumnName
=
"占比"
,
OrgColumnName
=
"占比"
,
});
{
columns
.
Add
(
new
StatisticsColumn
{
ColumnName
=
"占比公式"
,
OrgColumnName
=
"占比公式"
,
});
ColumnName
=
string
.
Join
(
"/"
,
queryValues
.
Values
),
}
Fixed
=
""
,
if
(
reportStatisticsTree
.
Any
(
w
=>
!
string
.
IsNullOrEmpty
(
w
.
WeightFormula
)))
ChildColumns
=
new
List
<
StatisticsColumn
>()
{
{
columns
.
Add
(
new
StatisticsColumn
{
ColumnName
=
"权重"
,
OrgColumnName
=
"权重"
,
});
new
StatisticsColumn
{
ColumnName
=
"数额"
,
Fixed
=
""
,
},
columns
.
Add
(
new
StatisticsColumn
{
ColumnName
=
"权重公式"
,
OrgColumnName
=
"权重公式"
,
});
}
}
};
Dictionary
<
string
,
object
>
pairs
=
new
Dictionary
<
string
,
object
>
if
(!
dto
.
Columns
.
Select
(
t
=>
t
.
ColumnName
).
Contains
(
statisticsColumn
.
ColumnName
))
{
dto
.
Columns
.
Add
(
statisticsColumn
);
{
"HospitalID"
,
query
.
HospitalID
},
};
foreach
(
var
item
in
query
.
Values
)
{
pairs
.
Add
(
item
.
Title
,
item
.
Values
);
}
where
.
Add
(
$"
{
queryValues
.
Title
}
in ('
{
string
.
Join
(
"','"
,
queryValues
.
Values
)}
')"
);
var
table
=
new
List
<
Dictionary
<
string
,
string
>>();
}
// 层级有几层,则数据就有几层
foreach
(
var
item
in
reportStatisticsTree
)
{
var
row
=
new
Dictionary
<
string
,
string
>();
row
.
Add
(
"项目"
,
item
.
Name
);
if
(
reportStatisticsTree
.
Any
(
w
=>
!
string
.
IsNullOrEmpty
(
w
.
TotalScript
)
||
!
string
.
IsNullOrEmpty
(
w
.
TotalFormula
)))
{
row
.
Add
(
"数值"
,
""
);
row
.
Add
(
"数值公式"
,
item
.
TotalFormula
??
""
);
}
if
(
reportStatisticsTree
.
Any
(
w
=>
!
string
.
IsNullOrEmpty
(
w
.
ProportionFormula
)))
{
row
.
Add
(
"占比"
,
""
);
row
.
Add
(
"占比公式"
,
item
.
ProportionFormula
??
""
);
}
if
(
reportStatisticsTree
.
Any
(
w
=>
!
string
.
IsNullOrEmpty
(
w
.
WeightFormula
)))
{
row
.
Add
(
"权重"
,
""
);
row
.
Add
(
"权重公式"
,
item
.
WeightFormula
??
""
);
}
dto
.
Columns
.
ForEach
(
t
=>
using
(
IDbConnection
connection
=
new
MySqlConnection
(
_options
.
Value
.
PerformanceConnectionString
))
{
if
(!
string
.
IsNullOrEmpty
(
item
.
TotalScript
))
{
{
if
(
t
.
ColumnName
!=
"项目"
)
// 通过层级查询固定SQL
{
var
(
sql
,
param
)
=
GetSqlQuery
(
item
.
TotalScript
,
pairs
);
if
(!
string
.
IsNullOrEmpty
(
ReportStatistics
.
ProportionScript
))
var
data
=
connection
.
QueryFirstOrDefault
<
decimal
?>(
sql
,
param
);
t
.
ChildColumns
.
Add
(
new
StatisticsColumn
()
{
ColumnName
=
"占比"
,
Fixed
=
""
});
if
(!
string
.
IsNullOrEmpty
(
ReportStatistics
.
WeightScript
))
t
.
ChildColumns
.
Add
(
new
StatisticsColumn
()
{
ColumnName
=
"权重"
,
Fixed
=
""
});
if
(
ReportStatistics
.
IsComparison
==
1
&&
query
.
IsComparison
==
1
)
t
.
ChildColumns
.
Add
(
new
StatisticsColumn
()
{
ColumnName
=
"增降幅"
,
Fixed
=
""
});
}
});
var
data
=
new
Dictionary
<
string
,
string
>
if
(
row
.
ContainsKey
(
"数值"
))
{
row
[
"数值"
]
=
data
?.
ToString
()
??
""
;
{
"项目"
,
ReportStatistics
.
Name
},
else
{
"汇总公式"
,
""
},
row
.
Add
(
"数值"
,
data
?.
ToString
()
??
""
);
{
"占比公式"
,
""
},
{
"权重公式"
,
""
},
};
if
(!
string
.
IsNullOrEmpty
(
ReportStatistics
.
TotalScript
))
{
var
json
=
connection
.
Query
(
ReportStatistics
.
TotalScript
?.
Replace
(
"@wh"
,
string
.
Join
(
" and "
,
where
))).
FirstOrDefault
();
var
dic
=
JsonHelper
.
Deserialize
(
json
);
data
.
Add
(
"数额"
,
dic
[
"数额"
].
ToString
());
}
if
(!
string
.
IsNullOrEmpty
(
ReportStatistics
.
ProportionScript
))
{
var
json
=
connection
.
Query
(
ReportStatistics
.
ProportionScript
?.
Replace
(
"@wh"
,
string
.
Join
(
" and "
,
where
))).
FirstOrDefault
();
var
dic
=
JsonHelper
.
Deserialize
(
json
);
data
.
Add
(
"占比"
,
dic
[
"占比"
].
ToString
());
}
}
if
(!
string
.
IsNullOrEmpty
(
ReportStatistics
.
WeightScript
))
{
var
json
=
connection
.
Query
(
ReportStatistics
.
WeightScript
?.
Replace
(
"@wh"
,
string
.
Join
(
" and "
,
where
))).
FirstOrDefault
();
var
dic
=
JsonHelper
.
Deserialize
(
json
);
data
.
Add
(
"权重"
,
dic
[
"权重"
].
ToString
());
}
if
(
ReportStatistics
.
IsComparison
==
1
&&
query
.
IsComparison
==
1
)
data
.
Add
(
"增降幅"
,
""
);
dto
.
Datas
.
Add
(
data
);
}
}
table
.
Add
(
row
);
}
}
return
new
StatisticsQueryResultDto
{
IsComparison
=
query
.
IsComparison
,
return
dto
;
Columns
=
columns
,
Datas
=
table
,
};
}
}
}
}
}
}
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