Commit 3c3c9d97 by lcx

Demo

parent d0649f89
...@@ -12,7 +12,8 @@ public static class GraphQLExtension ...@@ -12,7 +12,8 @@ public static class GraphQLExtension
{ {
public static void AddGraphQLSchemaAndTypes(this IServiceCollection services) public static void AddGraphQLSchemaAndTypes(this IServiceCollection services)
{ {
//services.AddScoped<ReportDataType>(); services.AddScoped<ChartDataType>();
services.AddScoped<ReportDataType>();
services.AddScoped<ReportPerformanceType>(); services.AddScoped<ReportPerformanceType>();
services.AddScoped<PerformanceQuery>(); services.AddScoped<PerformanceQuery>();
services.AddScoped<ISchema, PerformanceSchema>(); services.AddScoped<ISchema, PerformanceSchema>();
......
...@@ -8,6 +8,25 @@ public class PerformanceQuery : ObjectGraphType ...@@ -8,6 +8,25 @@ public class PerformanceQuery : ObjectGraphType
{ {
public PerformanceQuery(GraphQLService service) public PerformanceQuery(GraphQLService service)
{ {
Field<ReportDataType>("demo",
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 }
),
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);
}
);
Field<ListGraphType<ReportPerformanceType>>("performances", Field<ListGraphType<ReportPerformanceType>>("performances",
arguments: new QueryArguments arguments: new QueryArguments
( (
...@@ -25,6 +44,30 @@ public PerformanceQuery(GraphQLService service) ...@@ -25,6 +44,30 @@ public PerformanceQuery(GraphQLService service)
return service.GetPerformances(hospitalId, year, month, category); return service.GetPerformances(hospitalId, year, month, category);
} }
); );
Field<ListGraphType<ReportPerformanceType>>("paging",
arguments: new QueryArguments
(
new QueryArgument<IntGraphType>() { Name = QueryParams.pageSize },
new QueryArgument<IntGraphType>() { Name = QueryParams.pageNumber },
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 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;
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.GetPagingPerformances(hospitalId, year, month, category, pageNumber, pageSize);
}
);
} }
} }
} }
...@@ -7,12 +7,18 @@ namespace Performance.Api ...@@ -7,12 +7,18 @@ namespace Performance.Api
{ {
public struct QueryParams public struct QueryParams
{ {
public const string pageSize = "pageSize";
public const string pageNumber = "pageNumber";
public const string hospitalId = "hospitalId"; public const string hospitalId = "hospitalId";
public const string year = "year"; public const string year = "year";
public const string month = "month"; public const string month = "month";
public const string reportId = "reportID";
public const string category = "category"; public const string category = "category";
} }
} }
using GraphQL.Types; using GraphQL.Types;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.Services;
namespace Performance.Api namespace Performance.Api
{ {
public class ReportDataType : ObjectGraphType<ReportData> public class ReportDataType : ObjectGraphType<ReportData>
{ {
public ReportDataType() public ReportDataType(GraphQLService service)
{ {
Field(x => x.ReportID); Field(x => x.ReportID);
Field(x => x.ChartType, type: typeof(IdGraphType)); Field(x => x.ChartType);
Field(x => x.Sort); Field(x => x.Sort);
Field(x => x.Title); Field(x => x.Title);
Field(x => x.XTitle); Field(x => x.XTitle);
...@@ -22,7 +23,10 @@ public ReportDataType() ...@@ -22,7 +23,10 @@ public ReportDataType()
Field(x => x.Formula); Field(x => x.Formula);
Field(x => x.DataType); Field(x => x.DataType);
Field(x => x.FilterValue); Field(x => x.FilterValue);
Field<ListGraphType<ChartDataType>>("charData"); Field<ListGraphType<ChartDataType>>("charData", resolve: context =>
{
return service.GetChartData(context.Source.ReportID);
});
} }
} }
} }
...@@ -7,7 +7,7 @@ public class ReportPerformanceType : ObjectGraphType<report_performance> ...@@ -7,7 +7,7 @@ public class ReportPerformanceType : ObjectGraphType<report_performance>
{ {
public ReportPerformanceType() public ReportPerformanceType()
{ {
Field(x => x.Id); Field(x => x.Id, type: typeof(IdGraphType));
Field(x => x.HospitalId); Field(x => x.HospitalId);
Field(x => x.Year); Field(x => x.Year);
Field(x => x.Month); Field(x => x.Month);
......
...@@ -10,8 +10,8 @@ public class ReportData ...@@ -10,8 +10,8 @@ public class ReportData
public ReportData(rep_report report) public ReportData(rep_report report)
{ {
ReportID = report.ID; ReportID = report.ID;
ChartType = report.ChartType; ChartType = report.ChartType ?? 0;
Sort = report.Sort; Sort = report.Sort ?? 0;
Title = report.Title; Title = report.Title;
XTitle = report.XTitle; XTitle = report.XTitle;
XUnit = report.XUnit; XUnit = report.XUnit;
...@@ -22,8 +22,8 @@ public ReportData(rep_report report) ...@@ -22,8 +22,8 @@ public ReportData(rep_report report)
NTitle = report.NTitle; NTitle = report.NTitle;
NUnit = report.NUnit; NUnit = report.NUnit;
Formula = report.Formula; Formula = report.Formula;
DataType = report.DataType; DataType = report.DataType ?? 0;
FilterValue = report.FilterValue; FilterValue = report.FilterValue ?? 0;
ChartData = new List<ChartData>(); ChartData = new List<ChartData>();
} }
...@@ -32,12 +32,12 @@ public ReportData(rep_report report) ...@@ -32,12 +32,12 @@ public ReportData(rep_report report)
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public Nullable<int> ChartType { get; set; } public int ChartType { get; set; }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public Nullable<int> Sort { get; set; } public int Sort { get; set; }
/// <summary> /// <summary>
/// 报表标题 /// 报表标题
...@@ -92,12 +92,12 @@ public ReportData(rep_report report) ...@@ -92,12 +92,12 @@ public ReportData(rep_report report)
/// <summary> /// <summary>
/// 1表示需要进行小于百分2的类型进行合并 /// 1表示需要进行小于百分2的类型进行合并
/// </summary> /// </summary>
public Nullable<int> DataType { get; set; } public int DataType { get; set; }
/// <summary> /// <summary>
/// 图标value过滤执值 /// 图标value过滤执值
/// </summary> /// </summary>
public Nullable<decimal> FilterValue { get; set; } public decimal FilterValue { get; set; }
/// <summary> /// <summary>
/// 图表数据 /// 图表数据
...@@ -115,14 +115,17 @@ public class ChartData ...@@ -115,14 +115,17 @@ public class ChartData
/// X轴内容 /// X轴内容
/// </summary> /// </summary>
public string X { get; set; } public string X { get; set; }
/// <summary> /// <summary>
/// Y轴内容 /// Y轴内容
/// </summary> /// </summary>
public string Y { get; set; } public string Y { get; set; }
/// <summary> /// <summary>
/// 分类 /// 分类
/// </summary> /// </summary>
public string Name { get; set; } public string Name { get; set; }
/// <summary> /// <summary>
/// 值 /// 值
/// </summary> /// </summary>
...@@ -131,7 +134,8 @@ public class ChartData ...@@ -131,7 +134,8 @@ public class ChartData
/// <summary> /// <summary>
/// 总量 /// 总量
/// </summary> /// </summary>
public Double? Total { get; set; } public Double Total { get; set; }
/// <summary> /// <summary>
/// ChartData 类型标签 /// ChartData 类型标签
/// </summary> /// </summary>
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Performance.Infrastructure.Models
{
public class PageList<T> : List<T>
{
public int CurrentPage { get; private set; }
public int TotalPages { get; private set; }
public int PageSize { get; private set; }
public int TotalCount { get; private set; }
public bool HasPrevious => CurrentPage > 1;
public bool HasNext => CurrentPage < TotalPages;
public PageList(List<T> items, int totalCount, int pageNumber, int pageSize)
{
TotalCount = totalCount;
CurrentPage = pageNumber;
PageSize = pageSize;
TotalPages = (int)Math.Ceiling((double)totalCount / PageSize);
AddRange(items);
}
public static PageList<T> Create(IQueryable<T> source, int pageNumber, int pageSize)
{
var totalCount = source.Count();
var items = source.Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList();
var list = new PageList<T>(items, totalCount, pageNumber, pageSize);
return list;
}
}
}
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" /> <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.DynamicLinq" Version="2.2.5" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" /> <PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
......
...@@ -6,8 +6,11 @@ ...@@ -6,8 +6,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure.Models;
using System.Linq.Dynamic.Core;
namespace Performance.Repository namespace Performance.Repository
{ {
...@@ -22,5 +25,15 @@ public PerforReportperformanceRepository(PerformanceDbContext context) : base(co ...@@ -22,5 +25,15 @@ public PerforReportperformanceRepository(PerformanceDbContext context) : base(co
{ {
_db = context; _db = context;
} }
public PageList<report_performance> GetAllPaging(Expression<Func<report_performance, bool>> expression, int pageNumber, int pageSize, string orderby = null)
{
IQueryable<report_performance> queryableAuthors = _db.report_performance.AsNoTracking().Where(expression);
if (!string.IsNullOrEmpty(orderby))
queryableAuthors = queryableAuthors.OrderBy(orderby);
return PageList<report_performance>.Create(queryableAuthors, pageNumber, pageSize);
}
} }
} }
using Performance.DtoModels; using Performance.DtoModels;
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure.Models;
using Performance.Repository; using Performance.Repository;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -23,19 +24,13 @@ PerforReportperformanceRepository reportperformanceRepository ...@@ -23,19 +24,13 @@ PerforReportperformanceRepository reportperformanceRepository
this.reportperformanceRepository = reportperformanceRepository; this.reportperformanceRepository = reportperformanceRepository;
} }
#region Demo
public ReportData Test(int hospitalId, int year, int month) public ReportData Test(int hospitalId, int year, int month)
{ {
return new ReportData(new rep_report()) return new ReportData(new rep_report())
{ {
ChartData = new List<ChartData> ChartData = 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 },
}
}; };
} }
...@@ -65,5 +60,48 @@ public List<report_performance> GetPerformances(int hospitalId, int year, int mo ...@@ -65,5 +60,48 @@ public List<report_performance> GetPerformances(int hospitalId, int year, int mo
return reportperformanceRepository.GetEntities(exp); 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)
{
Expression<Func<report_performance, bool>> exp = (t) => true;
if (hospitalId != 0)
{
exp = exp.And(t => t.HospitalId == hospitalId);
}
if (year != 0)
{
exp = exp.And(t => t.Year == year);
}
if (month != 0)
{
exp = exp.And(t => t.Month == month);
}
if (!string.IsNullOrEmpty(category))
{
exp = exp.And(t => category.Split(',').Contains(t.Category));
}
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
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment