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
006e5edd
Commit
006e5edd
authored
Dec 22, 2020
by
lcx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
确定graphql参数内容
parent
3c3c9d97
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
102 deletions
+94
-102
performance/Performance.Api/GraphQLSchema/PerformanceQuery.cs
+62
-37
performance/Performance.Api/GraphQLSchema/ReportDataType.cs
+1
-4
performance/Performance.Services/GraphQLService.cs
+31
-61
No files found.
performance/Performance.Api/GraphQLSchema/PerformanceQuery.cs
View file @
006e5edd
using
GraphQL.Types
;
using
Dapper
;
using
GraphQL.Types
;
using
Performance.DtoModels
;
using
Performance.Infrastructure
;
using
Performance.Services
;
using
System.Collections.Generic
;
using
System.Linq
;
namespace
Performance.Api
{
...
...
@@ -8,66 +12,87 @@ public class PerformanceQuery : ObjectGraphType
{
public
PerformanceQuery
(
GraphQLService
service
)
{
Field
<
ReportDataType
>(
"demo"
,
Field
<
ListGraphType
<
ReportDataType
>>(
"info"
,
resolve
:
context
=>
{
return
service
.
GetReportsInfo
();
}
);
Field
<
ReportDataType
>(
"report"
,
arguments
:
new
QueryArguments
(
new
QueryArgument
<
IntGraphType
>()
{
Name
=
QueryParams
.
reportId
},
new
QueryArgument
<
IntGraphType
>()
{
Name
=
QueryParams
.
hospitalId
},
new
QueryArgument
<
IntGraphType
>()
{
Name
=
QueryParams
.
year
},
new
QueryArgument
<
IntGraphType
>()
{
Name
=
QueryParams
.
month
},
new
QueryArgument
<
StringGraphType
>()
{
Name
=
QueryParams
.
category
}
new
QueryArgument
<
IntGraphType
>()
{
Name
=
QueryParams
.
reportId
}
),
resolve
:
context
=>
{
int
hospitalId
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
hospitalId
)
?
ConvertHelper
.
TryInt
(
context
.
Arguments
[
QueryParams
.
hospitalId
].
ToString
())
:
default
;
int
year
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
year
)
?
ConvertHelper
.
TryInt
(
context
.
Arguments
[
QueryParams
.
year
].
ToString
())
:
default
;
int
month
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
month
)
?
ConvertHelper
.
TryInt
(
context
.
Arguments
[
QueryParams
.
month
].
ToString
())
:
default
;
string
category
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
category
)
?
context
.
Arguments
[
QueryParams
.
category
].
ToString
()
:
string
.
Empty
;
return
service
.
Test
(
hospitalId
,
year
,
month
);
int
reportId
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
reportId
)
?
ConvertHelper
.
To
<
int
>(
context
.
Arguments
[
QueryParams
.
reportId
])
:
0
;
return
service
.
GetReport
(
reportId
);
}
);
Field
<
ListGraphType
<
ChartDataType
>>(
"chardata"
,
arguments
:
Arguments
(),
resolve
:
context
=>
{
int
reportId
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
reportId
)
?
ConvertHelper
.
To
<
int
>(
context
.
Arguments
[
QueryParams
.
reportId
])
:
0
;
var
parameters
=
GetDynamicParameters
(
context
.
Arguments
,
QueryParams
.
hospitalId
,
QueryParams
.
year
,
QueryParams
.
month
);
return
service
.
GetChartData
(
reportId
,
parameters
);
}
);
Field
<
ListGraphType
<
ReportPerformanceType
>>(
"performances"
,
arguments
:
new
QueryArguments
(
new
QueryArgument
<
IntGraphType
>()
{
Name
=
QueryParams
.
hospitalId
},
new
QueryArgument
<
IntGraphType
>()
{
Name
=
QueryParams
.
year
},
new
QueryArgument
<
IntGraphType
>()
{
Name
=
QueryParams
.
month
},
new
QueryArgument
<
StringGraphType
>()
{
Name
=
QueryParams
.
category
}
),
resolve
:
context
=>
{
int
hospitalId
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
hospitalId
)
?
ConvertHelper
.
TryInt
(
context
.
Arguments
[
QueryParams
.
hospitalId
].
ToString
())
:
default
;
int
year
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
year
)
?
ConvertHelper
.
TryInt
(
context
.
Arguments
[
QueryParams
.
year
].
ToString
())
:
default
;
int
month
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
month
)
?
ConvertHelper
.
TryInt
(
context
.
Arguments
[
QueryParams
.
month
].
ToString
())
:
default
;
string
category
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
category
)
?
context
.
Arguments
[
QueryParams
.
category
].
ToString
()
:
string
.
Empty
;
return
service
.
GetPerformances
(
hospitalId
,
year
,
month
,
category
);
return
new
List
<
EntityModels
.
report_performance
>();
}
);
}
Field
<
ListGraphType
<
ReportPerformanceType
>>(
"paging"
,
arguments
:
new
QueryArguments
(
new
QueryArgument
<
IntGraphType
>()
{
Name
=
QueryParams
.
pageSize
},
new
QueryArgument
<
IntGraphType
>()
{
Name
=
QueryParams
.
pageNumber
},
public
static
QueryArguments
Arguments
(
params
QueryArgument
[]
args
)
{
var
basic
=
new
QueryArguments
{
new
QueryArgument
<
IntGraphType
>()
{
Name
=
QueryParams
.
reportId
},
new
QueryArgument
<
IntGraphType
>()
{
Name
=
QueryParams
.
hospitalId
},
new
QueryArgument
<
IntGraphType
>()
{
Name
=
QueryParams
.
year
},
new
QueryArgument
<
IntGraphType
>()
{
Name
=
QueryParams
.
month
},
new
QueryArgument
<
StringGraphType
>()
{
Name
=
QueryParams
.
category
}
),
resolve
:
context
=>
new
QueryArgument
<
IntGraphType
>()
{
Name
=
QueryParams
.
month
}
};
if
(
args
!=
null
&&
args
.
Any
())
{
int
pageSize
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
pageSize
)
?
ConvertHelper
.
TryInt
(
context
.
Arguments
[
QueryParams
.
pageSize
].
ToString
())
:
10
;
int
pageNumber
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
pageNumber
)
?
ConvertHelper
.
TryInt
(
context
.
Arguments
[
QueryParams
.
pageNumber
].
ToString
())
:
1
;
foreach
(
var
item
in
args
)
{
basic
.
Add
(
item
);
}
}
int
hospitalId
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
hospitalId
)
?
ConvertHelper
.
TryInt
(
context
.
Arguments
[
QueryParams
.
hospitalId
].
ToString
())
:
default
;
int
year
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
year
)
?
ConvertHelper
.
TryInt
(
context
.
Arguments
[
QueryParams
.
year
].
ToString
())
:
default
;
int
month
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
month
)
?
ConvertHelper
.
TryInt
(
context
.
Arguments
[
QueryParams
.
month
].
ToString
())
:
default
;
return
basic
;
}
string
category
=
context
.
Arguments
.
ContainsKey
(
QueryParams
.
category
)
?
context
.
Arguments
[
QueryParams
.
category
].
ToString
()
:
string
.
Empty
;
return
service
.
GetPagingPerformances
(
hospitalId
,
year
,
month
,
category
,
pageNumber
,
pageSize
);
public
DynamicParameters
GetDynamicParameters
(
Dictionary
<
string
,
object
>
arguments
,
params
string
[]
fields
)
{
DynamicParameters
parameters
=
new
DynamicParameters
();
if
(
arguments
==
null
||
!
arguments
.
Any
())
return
parameters
;
if
(
fields
!=
null
&&
fields
.
Any
())
{
foreach
(
var
item
in
fields
)
{
if
(
arguments
.
ContainsKey
(
item
))
{
parameters
.
Add
(
item
.
ToLower
(),
arguments
[
item
]);
}
);
}
}
return
parameters
;
}
}
}
performance/Performance.Api/GraphQLSchema/ReportDataType.cs
View file @
006e5edd
using
GraphQL.Types
;
using
Performance.DtoModels
;
using
Performance.Infrastructure
;
using
Performance.Services
;
namespace
Performance.Api
...
...
@@ -23,10 +24,6 @@ public ReportDataType(GraphQLService service)
Field
(
x
=>
x
.
Formula
);
Field
(
x
=>
x
.
DataType
);
Field
(
x
=>
x
.
FilterValue
);
Field
<
ListGraphType
<
ChartDataType
>>(
"charData"
,
resolve
:
context
=>
{
return
service
.
GetChartData
(
context
.
Source
.
ReportID
);
});
}
}
}
performance/Performance.Services/GraphQLService.cs
View file @
006e5edd
using
Performance.DtoModels
;
using
Dapper
;
using
Microsoft.Extensions.Logging
;
using
Performance.DtoModels
;
using
Performance.EntityModels
;
using
Performance.Infrastructure.Models
;
using
Performance.Repository
;
...
...
@@ -12,96 +14,64 @@ namespace Performance.Services
{
public
class
GraphQLService
:
IAutoInjection
{
private
readonly
ILogger
logger
;
private
readonly
PerforPeremployeeRepository
peremployeeRepository
;
private
readonly
PerforRepreportRepository
repreportRepository
;
private
readonly
PerforReportperformanceRepository
reportperformanceRepository
;
public
GraphQLService
(
ILogger
<
GraphQLService
>
logger
,
PerforPeremployeeRepository
peremployeeRepository
,
PerforRepreportRepository
repreportRepository
,
PerforReportperformanceRepository
reportperformanceRepository
)
{
this
.
logger
=
logger
;
this
.
peremployeeRepository
=
peremployeeRepository
;
this
.
repreportRepository
=
repreportRepository
;
this
.
reportperformanceRepository
=
reportperformanceRepository
;
}
#
region
Demo
public
ReportData
Test
(
int
hospitalId
,
int
year
,
int
month
)
{
return
new
ReportData
(
new
rep_report
())
{
ChartData
=
new
List
<
ChartData
>()
};
}
public
List
<
report_performance
>
GetPerformances
(
int
hospitalId
,
int
year
,
int
month
,
string
category
)
public
List
<
ReportData
>
GetReportsInfo
()
{
Expression
<
Func
<
report_performance
,
bool
>>
exp
=
(
t
)
=>
true
;
var
reports
=
repreportRepository
.
GetEntities
();
if
(
reports
==
null
||
!
reports
.
Any
())
return
new
List
<
ReportData
>();
if
(
hospitalId
!=
0
)
var
result
=
new
List
<
ReportData
>();
foreach
(
var
item
in
reports
)
{
exp
=
exp
.
And
(
t
=>
t
.
HospitalId
==
hospitalId
);
result
.
Add
(
new
ReportData
(
item
)
);
}
if
(
year
!=
0
)
{
exp
=
exp
.
And
(
t
=>
t
.
Year
==
year
);
return
result
;
}
if
(
month
!=
0
)
public
ReportData
GetReport
(
int
reportId
)
{
exp
=
exp
.
And
(
t
=>
t
.
Month
==
month
);
if
(
reportId
==
0
)
return
new
ReportData
(
new
rep_report
());
var
report
=
repreportRepository
.
GetEntity
(
t
=>
t
.
ID
==
reportId
)
??
new
rep_report
();
return
new
ReportData
(
report
);
}
if
(!
string
.
IsNullOrEmpty
(
category
)
)
public
List
<
ChartData
>
GetChartData
(
int
reportId
,
DynamicParameters
parameters
)
{
exp
=
exp
.
And
(
t
=>
category
.
Split
(
','
).
Contains
(
t
.
Category
));
}
if
(
reportId
==
0
)
return
new
List
<
ChartData
>();
return
reportperformanceRepository
.
GetEntities
(
exp
);
}
public
PageList
<
report_performance
>
GetPagingPerformances
(
int
hospitalId
,
int
year
,
int
month
,
string
category
,
int
pageNumber
=
1
,
int
pageSize
=
10
,
string
orderby
=
null
)
try
{
Expression
<
Func
<
report_performance
,
bool
>>
exp
=
(
t
)
=>
true
;
var
report
=
repreportRepository
.
GetEntity
(
t
=>
t
.
ID
==
reportId
);
if
(
report
==
null
||
string
.
IsNullOrEmpty
(
report
.
Content
))
return
new
List
<
ChartData
>();
if
(
hospitalId
!=
0
)
{
exp
=
exp
.
And
(
t
=>
t
.
HospitalId
==
hospitalId
);
}
var
sql
=
report
.
Content
.
ToLower
();
if
(
year
!=
0
)
{
exp
=
exp
.
And
(
t
=>
t
.
Year
==
year
);
}
var
chartData
=
repreportRepository
.
DapperQuery
<
ChartData
>(
sql
,
parameters
);
if
(
month
!=
0
)
{
exp
=
exp
.
And
(
t
=>
t
.
Month
==
month
);
return
chartData
!=
null
&&
chartData
.
Any
()
?
chartData
.
ToList
()
:
new
List
<
ChartData
>();
}
if
(!
string
.
IsNullOrEmpty
(
category
))
catch
(
Exception
ex
)
{
exp
=
exp
.
And
(
t
=>
category
.
Split
(
','
).
Contains
(
t
.
Category
));
logger
.
LogError
(
"获取报表数据异常: "
+
ex
.
ToString
());
return
new
List
<
ChartData
>();
}
PageList
<
report_performance
>
data
=
reportperformanceRepository
.
GetAllPaging
(
exp
,
pageNumber
,
pageSize
,
orderby
);
return
data
;
}
public
List
<
ChartData
>
GetChartData
(
int
reportId
)
{
return
new
List
<
ChartData
>
{
new
ChartData
{
X
=
"张三"
,
Y
=
"语文"
,
Value
=
89
},
new
ChartData
{
X
=
"张三"
,
Y
=
"数学"
,
Value
=
99
},
new
ChartData
{
X
=
"张三"
,
Y
=
"英语"
,
Value
=
72
},
new
ChartData
{
X
=
"李四"
,
Y
=
"语文"
,
Value
=
92
},
new
ChartData
{
X
=
"李四"
,
Y
=
"数学"
,
Value
=
93
},
new
ChartData
{
X
=
"李四"
,
Y
=
"英语"
,
Value
=
80
},
};
}
#
endregion
Demo
}
}
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