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
4ad7fbc0
Commit
4ad7fbc0
authored
Sep 09, 2021
by
lcx
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/绩效汇报表' into develop
parents
f9e57df7
b8c28b86
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
710 additions
and
12 deletions
+710
-12
performance/Performance.Api/Controllers/ReportController.cs
+35
-3
performance/Performance.Api/wwwroot/Performance.Api.xml
+10
-2
performance/Performance.DtoModels/Request/ConditionRequest.cs
+93
-0
performance/Performance.Services/ReportService.cs
+572
-7
No files found.
performance/Performance.Api/Controllers/ReportController.cs
View file @
4ad7fbc0
...
@@ -219,20 +219,51 @@ public ApiResponse MenuReport([CustomizeValidator(RuleSet = "Menu"), FromBody] R
...
@@ -219,20 +219,51 @@ public ApiResponse MenuReport([CustomizeValidator(RuleSet = "Menu"), FromBody] R
return
new
ApiResponse
(
ResponseType
.
OK
,
""
,
list
);
return
new
ApiResponse
(
ResponseType
.
OK
,
""
,
list
);
}
}
/// <summary>
/// 菜单报表
/// 菜单报表
/// </summary>
/// </summary>
/// <param name="request"></param>
/// <param name="request"></param>
/// <returns></returns>
/// <returns></returns>
[
Route
(
"operation"
)]
[
Route
(
"operation"
)]
[
HttpPost
]
[
HttpPost
]
public
ApiResponse
Operation
([
FromBody
]
ReportRequest
request
)
public
ApiResponse
Operation
([
FromBody
]
ReportRequest
request
)
{
{
if
(
request
==
null
)
if
(
request
==
null
)
return
new
ApiResponse
(
ResponseType
.
Fail
,
"参数错误!"
);
return
new
ApiResponse
(
ResponseType
.
Fail
,
"参数错误!"
);
var
list
=
reportService
.
Operation
(
request
);
var
list
=
reportService
.
Operation
(
request
);
return
new
ApiResponse
(
ResponseType
.
OK
,
""
,
list
);
return
new
ApiResponse
(
ResponseType
.
OK
,
""
,
list
);
}
}
/// <summary>
/// 绩效汇报表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[
Route
(
"table/normal"
)]
[
HttpPost
]
public
ApiResponse
TableNormal
([
FromBody
]
ConditionRequest
request
)
{
if
(
request
==
null
)
return
new
ApiResponse
(
ResponseType
.
OK
,
""
,
new
TableData
());
var
list
=
reportService
.
TableNormal
(
request
);
return
new
ApiResponse
(
ResponseType
.
OK
,
""
,
list
);
}
/// <summary>
/// 科室绩效对比
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[
Route
(
"table/special"
)]
[
HttpPost
]
public
ApiResponse
TableSpecial
([
FromBody
]
ConditionRequest
request
)
{
if
(
request
==
null
)
return
new
ApiResponse
(
ResponseType
.
OK
,
""
,
new
TableData
());
var
list
=
reportService
.
TableSpecial
(
request
);
return
new
ApiResponse
(
ResponseType
.
OK
,
""
,
list
);
}
}
}
}
}
\ No newline at end of file
performance/Performance.Api/wwwroot/Performance.Api.xml
View file @
4ad7fbc0
...
@@ -1455,9 +1455,17 @@
...
@@ -1455,9 +1455,17 @@
<param
name=
"request"
></param>
<param
name=
"request"
></param>
<returns></returns>
<returns></returns>
</member>
</member>
<member
name=
"M:Performance.Api.Controllers.ReportController.Operation(Performance.DtoModels.ReportRequest)"
>
<!-- Badly formed XML comment ignored for member "M:Performance.Api.Controllers.ReportController.Operation(Performance.DtoModels.ReportRequest)" -->
<member
name=
"M:Performance.Api.Controllers.ReportController.TableNormal(Performance.DtoModels.ConditionRequest)"
>
<summary>
<summary>
菜单报表
绩效汇报表
</summary>
<param
name=
"request"
></param>
<returns></returns>
</member>
<member
name=
"M:Performance.Api.Controllers.ReportController.TableSpecial(Performance.DtoModels.ConditionRequest)"
>
<summary>
科室绩效对比
</summary>
</summary>
<param
name=
"request"
></param>
<param
name=
"request"
></param>
<returns></returns>
<returns></returns>
...
...
performance/Performance.DtoModels/Request/ConditionRequest.cs
0 → 100644
View file @
4ad7fbc0
using
Newtonsoft.Json.Linq
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Performance.DtoModels
{
public
class
ConditionRequest
{
public
int
HospitalId
{
get
;
set
;
}
public
int
ReportId
{
get
;
set
;
}
public
int
[]
Year
{
get
;
set
;
}
public
int
[]
Month
{
get
;
set
;
}
public
string
[]
AccountingUnit
{
get
;
set
;
}
public
string
[]
UnitType
{
get
;
set
;
}
}
public
class
Condition
{
public
int
Year
{
get
;
set
;
}
public
int
Month
{
get
;
set
;
}
public
string
AccountingUnit
{
get
;
set
;
}
public
string
UnitType
{
get
;
set
;
}
}
public
class
TableData
{
public
List
<
Column
>
Columns
{
get
;
set
;
}
public
JArray
Data
{
get
;
set
;
}
}
public
class
Column
{
public
string
Label
{
get
;
set
;
}
public
string
Prop
{
get
;
set
;
}
public
List
<
Column
>
Children
{
get
;
set
;
}
}
public
class
QueryData
{
public
int
HospitalId
{
get
;
set
;
}
public
int
Year
{
get
;
set
;
}
public
int
Month
{
get
;
set
;
}
public
string
AccountingUnit
{
get
;
set
;
}
public
string
UnitType
{
get
;
set
;
}
public
string
SourceType
{
get
;
set
;
}
public
string
Category
{
get
;
set
;
}
public
string
ItemName
{
get
;
set
;
}
public
decimal
?
Value
{
get
;
set
;
}
public
List
<
QueryData
>
Children
{
get
;
set
;
}
}
public
class
QueryResult
{
public
string
Fixed1
{
get
;
set
;
}
public
string
Fixed2
{
get
;
set
;
}
public
string
Fixed3
{
get
;
set
;
}
public
string
Fixed4
{
get
;
set
;
}
public
string
Fixed5
{
get
;
set
;
}
public
string
Column1
{
get
;
set
;
}
public
string
Column2
{
get
;
set
;
}
public
string
Column3
{
get
;
set
;
}
public
decimal
?
Value
{
get
;
set
;
}
}
}
performance/Performance.Services/ReportService.cs
View file @
4ad7fbc0
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Logging
;
using
Newtonsoft.Json.Linq
;
using
Performance.DtoModels
;
using
Performance.DtoModels
;
using
Performance.DtoModels.Request
;
using
Performance.EntityModels
;
using
Performance.EntityModels
;
using
Performance.Infrastructure
;
using
Performance.Infrastructure
;
using
Performance.Repository
;
using
Performance.Repository
;
using
Performance.Services.ExtractExcelService
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq
;
using
System.Linq.Expressions
;
namespace
Performance.Services
namespace
Performance.Services
{
{
public
class
ReportService
:
IAutoInjection
public
class
ReportService
:
IAutoInjection
{
{
private
readonly
ILogger
<
ReportService
>
logger
;
private
readonly
ILogger
<
ReportService
>
logger
;
private
PerforReportRepository
perforReportRepository
;
private
readonly
PerforReportRepository
perforReportRepository
;
private
PerforPerallotRepository
perforPerallotRepository
;
private
readonly
PerforPerallotRepository
perforPerallotRepository
;
private
PerforResbaiscnormRepository
perforResbaiscnormRepository
;
private
readonly
PerforResbaiscnormRepository
perforResbaiscnormRepository
;
private
PerforHospersonfeeRepository
perforHospersonfeeRepository
;
private
readonly
PerforHospersonfeeRepository
perforHospersonfeeRepository
;
private
PerforResaccountRepository
perforResaccountRepository
;
private
readonly
PerforResaccountRepository
perforResaccountRepository
;
private
PerforRepimportconfigRepository
repimportconfigRepository
;
private
readonly
PerforRepimportconfigRepository
repimportconfigRepository
;
private
readonly
PerforRepreportRepository
repreportRepository
;
public
ReportService
(
public
ReportService
(
ILogger
<
ReportService
>
logger
,
ILogger
<
ReportService
>
logger
,
...
@@ -26,7 +31,8 @@ public class ReportService : IAutoInjection
...
@@ -26,7 +31,8 @@ public class ReportService : IAutoInjection
PerforResbaiscnormRepository
perforResbaiscnormRepository
,
PerforResbaiscnormRepository
perforResbaiscnormRepository
,
PerforHospersonfeeRepository
perforHospersonfeeRepository
,
PerforHospersonfeeRepository
perforHospersonfeeRepository
,
PerforRepimportconfigRepository
repimportconfigRepository
,
PerforRepimportconfigRepository
repimportconfigRepository
,
PerforResaccountRepository
perforResaccountRepository
)
PerforResaccountRepository
perforResaccountRepository
,
PerforRepreportRepository
repreportRepository
)
{
{
this
.
logger
=
logger
;
this
.
logger
=
logger
;
this
.
perforReportRepository
=
perforReportRepository
;
this
.
perforReportRepository
=
perforReportRepository
;
...
@@ -35,6 +41,7 @@ public class ReportService : IAutoInjection
...
@@ -35,6 +41,7 @@ public class ReportService : IAutoInjection
this
.
perforHospersonfeeRepository
=
perforHospersonfeeRepository
;
this
.
perforHospersonfeeRepository
=
perforHospersonfeeRepository
;
this
.
perforResaccountRepository
=
perforResaccountRepository
;
this
.
perforResaccountRepository
=
perforResaccountRepository
;
this
.
repimportconfigRepository
=
repimportconfigRepository
;
this
.
repimportconfigRepository
=
repimportconfigRepository
;
this
.
repreportRepository
=
repreportRepository
;
}
}
/// <summary>
/// <summary>
...
@@ -580,5 +587,563 @@ public SheetExportResponse Operation(ReportRequest request)
...
@@ -580,5 +587,563 @@ public SheetExportResponse Operation(ReportRequest request)
return
sheet
;
return
sheet
;
}
}
#
region
normal
public
TableData
TableNormal
(
ConditionRequest
request
)
{
TableData
tableData
=
new
TableData
();
try
{
var
report
=
repreportRepository
.
GetEntity
(
t
=>
t
.
ID
==
request
.
ReportId
);
if
(
report
==
null
)
return
tableData
;
List
<
QueryResult
>
results
=
perforReportRepository
.
DapperQuery
<
QueryResult
>(
report
.
Content
,
new
{
request
.
HospitalId
,
Year
=
request
.
Year
?.
FirstOrDefault
()
??
DateTime
.
Now
.
Year
,
Month
=
request
.
Month
?.
FirstOrDefault
()
??
DateTime
.
Now
.
Month
})?.
ToList
();
if
(
results
==
null
||
!
results
.
Any
())
return
tableData
;
(
int
rowNum
,
int
columnNum
)
=
GetRowAndColumnLevel
(
results
);
List
<
Column
>
columns
=
new
List
<
Column
>();
Dictionary
<
string
,
Expression
<
Func
<
QueryResult
,
bool
>>>
colConditions
=
new
Dictionary
<
string
,
Expression
<
Func
<
QueryResult
,
bool
>>>();
var
fixedDict
=
JsonHelper
.
Deserialize
<
Dictionary
<
string
,
string
>>(
report
.
QueryArguments
)
??
new
Dictionary
<
string
,
string
>();
switch
(
columnNum
)
{
case
1
:
columns
=
GetLevel1Columns
(
results
,
rowNum
,
colConditions
,
fixedDict
);
break
;
case
2
:
columns
=
GetLevel2Columns
(
results
,
rowNum
,
colConditions
,
fixedDict
);
break
;
case
3
:
columns
=
GetLevel3Columns
(
results
,
rowNum
,
colConditions
,
fixedDict
);
break
;
}
tableData
.
Columns
=
columns
;
tableData
.
Data
=
GetFixedData
(
results
,
colConditions
,
rowNum
);
}
catch
(
Exception
ex
)
{
logger
.
LogError
(
ex
.
Message
);
}
return
tableData
;
}
private
(
int
rowNum
,
int
columnNum
)
GetRowAndColumnLevel
(
List
<
QueryResult
>
results
)
{
List
<
Func
<
QueryResult
,
bool
>>
rows
=
new
List
<
Func
<
QueryResult
,
bool
>>
{
t
=>
!
string
.
IsNullOrEmpty
(
t
.
Fixed1
),
t
=>
!
string
.
IsNullOrEmpty
(
t
.
Fixed2
),
t
=>
!
string
.
IsNullOrEmpty
(
t
.
Fixed3
),
t
=>
!
string
.
IsNullOrEmpty
(
t
.
Fixed4
),
t
=>
!
string
.
IsNullOrEmpty
(
t
.
Fixed5
),
};
int
rowIndex
=
0
;
foreach
(
var
item
in
rows
)
{
if
(!
results
.
Any
(
item
))
break
;
rowIndex
++;
}
List
<
Func
<
QueryResult
,
bool
>>
columns
=
new
List
<
Func
<
QueryResult
,
bool
>>
{
t
=>
!
string
.
IsNullOrEmpty
(
t
.
Column1
),
t
=>
!
string
.
IsNullOrEmpty
(
t
.
Column2
),
t
=>
!
string
.
IsNullOrEmpty
(
t
.
Column3
),
};
int
columnIndex
=
0
;
foreach
(
var
item
in
columns
)
{
if
(!
results
.
Any
(
item
))
break
;
columnIndex
++;
}
return
(
rowIndex
,
columnIndex
);
}
private
List
<
Column
>
GetLevel1Columns
(
List
<
QueryResult
>
results
,
int
rowNum
,
Dictionary
<
string
,
Expression
<
Func
<
QueryResult
,
bool
>>>
colConditions
,
Dictionary
<
string
,
string
>
fixedDict
)
{
List
<
Column
>
columns
=
new
List
<
Column
>();
for
(
int
i
=
0
;
i
<
rowNum
;
i
++)
{
string
key
=
$"fixed_
{
i
+
1
}
"
;
columns
.
Add
(
new
Column
{
Label
=
fixedDict
.
ContainsKey
(
key
)
?
fixedDict
[
key
]
:
""
,
Prop
=
key
});
}
var
level1
=
results
.
Where
(
t
=>
!
string
.
IsNullOrEmpty
(
t
.
Column1
)).
Select
(
t
=>
t
.
Column1
).
Distinct
();
columns
.
AddRange
(
level1
.
Select
(
t
=>
{
var
col
=
new
Column
{
Label
=
t
,
Prop
=
$"field_
{
t
}
"
};
colConditions
.
Add
(
col
.
Prop
,
exp
=>
exp
.
Column1
==
t
);
return
col
;
}));
return
columns
;
}
private
List
<
Column
>
GetLevel2Columns
(
List
<
QueryResult
>
results
,
int
rowNum
,
Dictionary
<
string
,
Expression
<
Func
<
QueryResult
,
bool
>>>
colConditions
,
Dictionary
<
string
,
string
>
fixedDict
)
{
List
<
Column
>
columns
=
new
List
<
Column
>();
for
(
int
i
=
0
;
i
<
rowNum
;
i
++)
{
string
key
=
$"fixed_
{
i
+
1
}
"
;
columns
.
Add
(
new
Column
{
Label
=
fixedDict
.
ContainsKey
(
key
)
?
fixedDict
[
key
]
:
""
,
Prop
=
key
});
}
var
columnData
=
results
.
Select
(
t
=>
new
{
Column1
=
t
.
Column1
.
NoBlank
(),
Column2
=
t
.
Column2
.
NoBlank
()
}).
Distinct
();
var
level1
=
columnData
.
Where
(
t
=>
!
string
.
IsNullOrEmpty
(
t
.
Column1
))?.
Select
(
t
=>
t
.
Column1
).
Distinct
();
if
(
level1
==
null
||
!
level1
.
Any
())
return
columns
;
foreach
(
var
item
in
level1
)
{
var
column
=
new
Column
{
Label
=
item
,
Prop
=
$"field_
{
item
}
"
};
var
level2
=
columnData
.
Where
(
t
=>
t
.
Column1
==
item
&&
!
string
.
IsNullOrEmpty
(
t
.
Column2
))?.
Select
(
t
=>
t
.
Column2
).
Distinct
();
if
(
level2
==
null
||
!
level2
.
Any
())
continue
;
column
.
Children
=
level2
.
Select
(
item2
=>
{
var
col
=
new
Column
{
Label
=
item2
,
Prop
=
$"field_
{
item
}
_
{
item2
}
"
};
colConditions
.
Add
(
col
.
Prop
,
exp
=>
exp
.
Column1
==
item
&&
exp
.
Column2
==
item2
);
return
col
;
}).
ToList
();
columns
.
Add
(
column
);
}
return
columns
;
}
private
List
<
Column
>
GetLevel3Columns
(
List
<
QueryResult
>
results
,
int
rowNum
,
Dictionary
<
string
,
Expression
<
Func
<
QueryResult
,
bool
>>>
colConditions
,
Dictionary
<
string
,
string
>
fixedDict
)
{
List
<
Column
>
columns
=
new
List
<
Column
>();
for
(
int
i
=
0
;
i
<
rowNum
;
i
++)
{
string
key
=
$"fixed_
{
i
+
1
}
"
;
columns
.
Add
(
new
Column
{
Label
=
fixedDict
.
ContainsKey
(
key
)
?
fixedDict
[
key
]
:
""
,
Prop
=
key
});
}
var
columnData
=
results
.
Select
(
t
=>
new
{
Column1
=
t
.
Column1
.
NoBlank
(),
Column2
=
t
.
Column2
.
NoBlank
(),
Column3
=
t
.
Column3
.
NoBlank
()
}).
Distinct
();
var
level1
=
columnData
.
Where
(
t
=>
!
string
.
IsNullOrEmpty
(
t
.
Column1
))?.
Select
(
t
=>
t
.
Column1
).
Distinct
();
if
(
level1
==
null
||
!
level1
.
Any
())
return
columns
;
foreach
(
var
item1
in
level1
)
{
var
column1
=
new
Column
{
Label
=
item1
,
Prop
=
$"field_
{
item1
}
"
,
Children
=
new
List
<
Column
>()
};
var
level2
=
columnData
.
Where
(
t
=>
t
.
Column1
==
item1
&&
!
string
.
IsNullOrEmpty
(
t
.
Column2
))?.
Select
(
t
=>
t
.
Column2
).
Distinct
();
if
(
level2
==
null
||
!
level2
.
Any
())
continue
;
foreach
(
var
item2
in
level2
)
{
var
column2
=
new
Column
{
Label
=
item1
,
Prop
=
$"field_
{
item1
}
_
{
item2
}
"
};
var
level3
=
columnData
.
Where
(
t
=>
t
.
Column1
==
item1
&&
t
.
Column2
==
item2
&&
!
string
.
IsNullOrEmpty
(
t
.
Column3
))?.
Select
(
t
=>
t
.
Column3
).
Distinct
();
if
(
level3
==
null
||
!
level3
.
Any
())
continue
;
column2
.
Children
=
level3
.
Select
(
item3
=>
{
var
col
=
new
Column
{
Label
=
item2
,
Prop
=
$"field_
{
item1
}
_
{
item2
}
_
{
item3
}
"
};
colConditions
.
Add
(
col
.
Prop
,
exp
=>
exp
.
Column1
==
item1
&&
exp
.
Column2
==
item2
&&
exp
.
Column3
==
item3
);
return
col
;
}).
ToList
();
column1
.
Children
.
Add
(
column2
);
}
columns
.
Add
(
column1
);
}
return
columns
;
}
private
JArray
GetFixedData
(
List
<
QueryResult
>
results
,
Dictionary
<
string
,
Expression
<
Func
<
QueryResult
,
bool
>>>
expressions
,
int
rowNum
)
{
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>
fixedexpressions
=
new
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>();
switch
(
rowNum
)
{
case
1
:
fixedexpressions
=
GetFixed1Data
(
results
);
break
;
case
2
:
fixedexpressions
=
GetFixed2Data
(
results
);
break
;
case
3
:
fixedexpressions
=
GetFixed3Data
(
results
);
break
;
case
4
:
fixedexpressions
=
GetFixed4Data
(
results
);
break
;
case
5
:
fixedexpressions
=
GetFixed5Data
(
results
);
break
;
}
if
(
fixedexpressions
==
null
||
!
fixedexpressions
.
Any
())
return
new
JArray
();
JArray
jArray
=
new
JArray
();
foreach
(
var
item
in
fixedexpressions
)
{
JObject
jobj
=
item
.
Value
;
foreach
(
var
expdic
in
expressions
)
{
var
exp
=
item
.
Key
.
And
(
expdic
.
Value
);
var
value
=
results
.
Where
(
exp
.
Compile
())?.
Sum
(
t
=>
t
.
Value
);
jobj
[
expdic
.
Key
]
=
value
==
0
?
null
:
value
;
}
jArray
.
Add
(
jobj
);
}
return
jArray
;
}
private
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>
GetFixed1Data
(
List
<
QueryResult
>
results
)
{
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>
fixedexpressions
=
new
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>();
var
fixedData
=
results
.
Select
(
t
=>
t
.
Fixed1
.
NoBlank
()).
Distinct
();
if
(
fixedData
!=
null
&&
fixedData
.
Any
())
{
int
index
=
1
;
foreach
(
var
item
in
fixedData
)
{
Expression
<
Func
<
QueryResult
,
bool
>>
exp
=
(
f
)
=>
f
.
Fixed1
==
item
;
JObject
jobj
=
new
JObject
{
[
"rownumber"
]
=
index
,
[
"fixed_1"
]
=
item
};
fixedexpressions
.
Add
(
exp
,
jobj
);
index
++;
}
}
return
fixedexpressions
;
}
private
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>
GetFixed2Data
(
List
<
QueryResult
>
results
)
{
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>
fixedexpressions
=
new
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>();
var
fixedData
=
results
.
Select
(
t
=>
new
{
Fixed1
=
t
.
Fixed1
.
NoBlank
(),
Fixed2
=
t
.
Fixed2
.
NoBlank
()
}).
Distinct
();
if
(
fixedData
!=
null
&&
fixedData
.
Any
())
{
int
index
=
1
;
foreach
(
var
item
in
fixedData
)
{
Expression
<
Func
<
QueryResult
,
bool
>>
exp
=
(
f
)
=>
f
.
Fixed1
==
item
.
Fixed1
&&
f
.
Fixed2
==
item
.
Fixed2
;
JObject
jobj
=
new
JObject
{
[
"rownumber"
]
=
index
,
[
"fixed_1"
]
=
item
.
Fixed1
,
[
"fixed_2"
]
=
item
.
Fixed2
,
};
fixedexpressions
.
Add
(
exp
,
jobj
);
index
++;
}
}
return
fixedexpressions
;
}
private
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>
GetFixed3Data
(
List
<
QueryResult
>
results
)
{
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>
fixedexpressions
=
new
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>();
var
fixedData
=
results
.
Select
(
t
=>
new
{
Fixed1
=
t
.
Fixed1
.
NoBlank
(),
Fixed2
=
t
.
Fixed2
.
NoBlank
(),
Fixed3
=
t
.
Fixed3
.
NoBlank
()
}).
Distinct
();
if
(
fixedData
!=
null
&&
fixedData
.
Any
())
{
int
index
=
1
;
foreach
(
var
item
in
fixedData
)
{
Expression
<
Func
<
QueryResult
,
bool
>>
exp
=
(
f
)
=>
f
.
Fixed1
==
item
.
Fixed1
&&
f
.
Fixed2
==
item
.
Fixed2
&&
f
.
Fixed3
==
item
.
Fixed3
;
JObject
jobj
=
new
JObject
{
[
"rownumber"
]
=
index
,
[
"fixed_1"
]
=
item
.
Fixed1
,
[
"fixed_2"
]
=
item
.
Fixed2
,
[
"fixed_3"
]
=
item
.
Fixed3
,
};
fixedexpressions
.
Add
(
exp
,
jobj
);
index
++;
}
}
return
fixedexpressions
;
}
private
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>
GetFixed4Data
(
List
<
QueryResult
>
results
)
{
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>
fixedexpressions
=
new
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>();
var
fixedData
=
results
.
Select
(
t
=>
new
{
Fixed1
=
t
.
Fixed1
.
NoBlank
(),
Fixed2
=
t
.
Fixed2
.
NoBlank
(),
Fixed3
=
t
.
Fixed3
.
NoBlank
(),
Fixed4
=
t
.
Fixed4
.
NoBlank
()
}).
Distinct
();
if
(
fixedData
!=
null
&&
fixedData
.
Any
())
{
int
index
=
1
;
foreach
(
var
item
in
fixedData
)
{
Expression
<
Func
<
QueryResult
,
bool
>>
exp
=
(
f
)
=>
f
.
Fixed1
==
item
.
Fixed1
&&
f
.
Fixed2
==
item
.
Fixed2
&&
f
.
Fixed3
==
item
.
Fixed3
&&
f
.
Fixed4
==
item
.
Fixed4
;
JObject
jobj
=
new
JObject
{
[
"rownumber"
]
=
index
,
[
"fixed_1"
]
=
item
.
Fixed1
,
[
"fixed_2"
]
=
item
.
Fixed2
,
[
"fixed_3"
]
=
item
.
Fixed3
,
[
"fixed_4"
]
=
item
.
Fixed4
,
};
fixedexpressions
.
Add
(
exp
,
jobj
);
index
++;
}
}
return
fixedexpressions
;
}
private
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>
GetFixed5Data
(
List
<
QueryResult
>
results
)
{
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>
fixedexpressions
=
new
Dictionary
<
Expression
<
Func
<
QueryResult
,
bool
>>,
JObject
>();
var
fixedData
=
results
.
Select
(
t
=>
new
{
Fixed1
=
t
.
Fixed1
.
NoBlank
(),
Fixed2
=
t
.
Fixed2
.
NoBlank
(),
Fixed3
=
t
.
Fixed3
.
NoBlank
(),
Fixed4
=
t
.
Fixed4
.
NoBlank
(),
Fixed5
=
t
.
Fixed5
.
NoBlank
()
}).
Distinct
();
if
(
fixedData
!=
null
&&
fixedData
.
Any
())
{
int
index
=
1
;
foreach
(
var
item
in
fixedData
)
{
Expression
<
Func
<
QueryResult
,
bool
>>
exp
=
(
f
)
=>
f
.
Fixed1
==
item
.
Fixed1
&&
f
.
Fixed2
==
item
.
Fixed2
&&
f
.
Fixed3
==
item
.
Fixed3
&&
f
.
Fixed4
==
item
.
Fixed4
&&
f
.
Fixed5
==
item
.
Fixed5
;
JObject
jobj
=
new
JObject
{
[
"rownumber"
]
=
index
,
[
"fixed_1"
]
=
item
.
Fixed1
,
[
"fixed_2"
]
=
item
.
Fixed2
,
[
"fixed_3"
]
=
item
.
Fixed3
,
[
"fixed_4"
]
=
item
.
Fixed4
,
[
"fixed_5"
]
=
item
.
Fixed5
,
};
fixedexpressions
.
Add
(
exp
,
jobj
);
index
++;
}
}
return
fixedexpressions
;
}
#
endregion
#
region
special
public
TableData
TableSpecial
(
ConditionRequest
request
)
{
TableData
tableData
=
new
TableData
();
var
conditions
=
GetConditions
(
request
);
if
(
conditions
==
null
||
!
conditions
.
Any
())
return
tableData
;
try
{
#
region
columns
List
<
Column
>
columns
=
new
List
<
Column
>
{
new
Column
{
Label
=
"月份"
,
Children
=
new
List
<
Column
>
{
new
Column
{
Label
=
"核算单元"
,
Children
=
new
List
<
Column
>
{
new
Column
{
Label
=
"核算组别"
,
Prop
=
"itemname"
}
}
}
}
}
};
foreach
(
var
condition
in
conditions
)
{
string
key
=
$"field_
{
condition
.
Year
}
_
{
condition
.
Month
}
_
{
condition
.
AccountingUnit
}
_
{
condition
.
UnitType
}
"
;
columns
.
Add
(
new
Column
{
Label
=
$"
{
condition
.
Year
}
年
{
condition
.
Month
}
月"
,
Children
=
new
List
<
Column
>
{
new
Column
{
Label
=
condition
.
AccountingUnit
,
Children
=
new
List
<
Column
>
{
new
Column
{
Label
=
condition
.
UnitType
,
Prop
=
key
}
}
}
}
});
}
tableData
.
Columns
=
columns
;
#
endregion
var
report
=
repreportRepository
.
GetEntity
(
t
=>
t
.
ID
==
request
.
ReportId
);
if
(
report
==
null
)
return
tableData
;
var
data
=
perforReportRepository
.
DapperQuery
<
QueryData
>(
report
.
Content
,
request
);
if
(
data
==
null
||
!
data
.
Any
())
return
tableData
;
var
type
=
data
.
Select
(
t
=>
new
{
SourceType
=
t
.
SourceType
.
NoBlank
(),
Category
=
t
.
Category
.
NoBlank
(),
ItemName
=
t
.
ItemName
.
NoBlank
()
}).
Distinct
();
#
region
data
JArray
jarray
=
new
JArray
();
int
index
=
1
;
foreach
(
var
sourcetype
in
type
.
Where
(
t
=>
!
string
.
IsNullOrEmpty
(
t
.
SourceType
))?.
Select
(
t
=>
t
.
SourceType
).
Distinct
())
{
var
conditionData
=
data
.
Where
(
t
=>
t
.
SourceType
==
sourcetype
);
if
(
conditionData
==
null
||
!
conditionData
.
Any
())
continue
;
JObject
level1
=
new
JObject
{
[
"rownumber"
]
=
index
,
[
"itemname"
]
=
sourcetype
};
index
++;
WriteDataToJObject
(
level1
,
conditionData
,
conditions
);
JArray
level1Arr
=
new
JArray
();
jarray
.
Add
(
level1
);
var
categories
=
type
.
Where
(
t
=>
t
.
SourceType
==
sourcetype
);
if
(
categories
==
null
||
!
categories
.
Any
(
t
=>
!
string
.
IsNullOrEmpty
(
t
.
Category
)))
continue
;
foreach
(
var
category
in
categories
.
Select
(
t
=>
t
.
Category
).
Distinct
())
{
conditionData
=
data
.
Where
(
t
=>
t
.
SourceType
==
sourcetype
&&
t
.
Category
==
category
);
if
(
conditionData
==
null
||
!
conditionData
.
Any
())
continue
;
JObject
level2
=
new
JObject
{
[
"rownumber"
]
=
index
,
[
"itemname"
]
=
category
};
index
++;
WriteDataToJObject
(
level2
,
conditionData
,
conditions
);
JArray
level2Arr
=
new
JArray
();
level1Arr
.
Add
(
level2
);
var
itemnames
=
categories
.
Where
(
t
=>
t
.
Category
==
category
);
if
(
itemnames
==
null
||
!
itemnames
.
Any
(
t
=>
!
string
.
IsNullOrEmpty
(
t
.
ItemName
)))
continue
;
foreach
(
var
itemname
in
itemnames
.
Select
(
t
=>
t
.
ItemName
).
Distinct
())
{
conditionData
=
data
.
Where
(
t
=>
t
.
SourceType
==
sourcetype
&&
t
.
Category
==
category
&&
t
.
ItemName
==
itemname
);
if
(
conditionData
==
null
||
!
conditionData
.
Any
())
continue
;
JObject
level3
=
new
JObject
{
[
"rownumber"
]
=
index
,
[
"itemname"
]
=
itemname
};
index
++;
WriteDataToJObject
(
level3
,
conditionData
,
conditions
);
level2Arr
.
Add
(
level3
);
}
if
(
level2Arr
!=
null
&&
level2Arr
.
Any
())
level2
[
"children"
]
=
level2Arr
;
}
if
(
level1Arr
!=
null
&&
level1Arr
.
Any
())
level1
[
"children"
]
=
level1Arr
;
}
tableData
.
Data
=
jarray
;
#
endregion
}
catch
(
Exception
ex
)
{
logger
.
LogError
(
$"Table Error:
{
ex
}
"
);
}
return
tableData
;
}
private
List
<
Condition
>
GetConditions
(
ConditionRequest
request
)
{
List
<
Condition
>
conditions
=
new
List
<
Condition
>();
if
(
request
.
AccountingUnit
==
null
||
!
request
.
AccountingUnit
.
Any
())
throw
new
PerformanceException
(
"请选择核算单元"
);
if
(
request
.
UnitType
==
null
||
!
request
.
UnitType
.
Any
())
throw
new
PerformanceException
(
"请选择核算组别"
);
if
(
request
.
Year
==
null
||
!
request
.
Year
.
Any
())
request
.
Year
=
new
int
[]
{
DateTime
.
Now
.
Year
};
if
(
request
.
Month
==
null
||
!
request
.
Month
.
Any
())
request
.
Month
=
new
int
[]
{
DateTime
.
Now
.
Month
};
var
departmentInfos
=
request
.
AccountingUnit
.
Join
(
request
.
UnitType
,
account
=>
true
,
unit
=>
true
,
(
account
,
unit
)
=>
new
{
account
,
unit
});
var
dateInfo
=
request
.
Year
.
Join
(
request
.
Month
,
year
=>
true
,
month
=>
true
,
(
year
,
month
)
=>
new
{
year
,
month
});
conditions
=
departmentInfos
.
Join
(
dateInfo
,
outer
=>
true
,
innner
=>
true
,
(
outer
,
innner
)
=>
new
{
outer
,
innner
})
.
Select
(
t
=>
new
Condition
{
AccountingUnit
=
t
.
outer
.
account
,
UnitType
=
t
.
outer
.
unit
,
Year
=
t
.
innner
.
year
,
Month
=
t
.
innner
.
month
}).
OrderBy
(
t
=>
t
.
Year
).
ThenBy
(
t
=>
t
.
Month
).
ThenBy
(
t
=>
t
.
AccountingUnit
).
ThenBy
(
t
=>
t
.
UnitType
).
ToList
();
return
conditions
;
}
public
void
WriteDataToJObject
(
JObject
jobj
,
IEnumerable
<
QueryData
>
data
,
List
<
Condition
>
conditions
)
{
try
{
foreach
(
var
item
in
conditions
)
{
string
key
=
$"field_
{
item
.
Year
}
_
{
item
.
Month
}
_
{
item
.
AccountingUnit
}
_
{
item
.
UnitType
}
"
;
var
value
=
data
?.
Where
(
t
=>
t
.
Year
==
item
.
Year
&&
t
.
Month
==
item
.
Month
&&
t
.
AccountingUnit
==
item
.
AccountingUnit
&&
t
.
UnitType
==
item
.
UnitType
)?.
Sum
(
t
=>
t
.
Value
);
jobj
[
key
]
=
value
==
0
?
null
:
value
;
}
}
catch
(
Exception
ex
)
{
logger
.
LogError
(
$"WriteDataToJObject:
{
ex
}
"
);
}
}
#
endregion
}
}
}
}
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