Commit 3c3c9d97 by lcx

Demo

parent d0649f89
......@@ -12,7 +12,8 @@ public static class GraphQLExtension
{
public static void AddGraphQLSchemaAndTypes(this IServiceCollection services)
{
//services.AddScoped<ReportDataType>();
services.AddScoped<ChartDataType>();
services.AddScoped<ReportDataType>();
services.AddScoped<ReportPerformanceType>();
services.AddScoped<PerformanceQuery>();
services.AddScoped<ISchema, PerformanceSchema>();
......
......@@ -8,6 +8,25 @@ public class PerformanceQuery : ObjectGraphType
{
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",
arguments: new QueryArguments
(
......@@ -25,6 +44,30 @@ public PerformanceQuery(GraphQLService service)
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
{
public struct QueryParams
{
public const string pageSize = "pageSize";
public const string pageNumber = "pageNumber";
public const string hospitalId = "hospitalId";
public const string year = "year";
public const string month = "month";
public const string reportId = "reportID";
public const string category = "category";
}
}
using GraphQL.Types;
using Performance.DtoModels;
using Performance.Services;
namespace Performance.Api
{
public class ReportDataType : ObjectGraphType<ReportData>
{
public ReportDataType()
public ReportDataType(GraphQLService service)
{
Field(x => x.ReportID);
Field(x => x.ChartType, type: typeof(IdGraphType));
Field(x => x.ChartType);
Field(x => x.Sort);
Field(x => x.Title);
Field(x => x.XTitle);
......@@ -22,7 +23,10 @@ public ReportDataType()
Field(x => x.Formula);
Field(x => x.DataType);
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>
{
public ReportPerformanceType()
{
Field(x => x.Id);
Field(x => x.Id, type: typeof(IdGraphType));
Field(x => x.HospitalId);
Field(x => x.Year);
Field(x => x.Month);
......
......@@ -1503,14 +1503,14 @@
</summary>
</member>
<member name="P:Performance.DtoModels.ReportData.ChartType">
<summary>
<summary>
</summary>
</summary>
</member>
<member name="P:Performance.DtoModels.ReportData.Sort">
<summary>
<summary>
</summary>
</summary>
</member>
<member name="P:Performance.DtoModels.ReportData.Title">
<summary>
......
......@@ -10,8 +10,8 @@ public class ReportData
public ReportData(rep_report report)
{
ReportID = report.ID;
ChartType = report.ChartType;
Sort = report.Sort;
ChartType = report.ChartType ?? 0;
Sort = report.Sort ?? 0;
Title = report.Title;
XTitle = report.XTitle;
XUnit = report.XUnit;
......@@ -22,22 +22,22 @@ public ReportData(rep_report report)
NTitle = report.NTitle;
NUnit = report.NUnit;
Formula = report.Formula;
DataType = report.DataType;
FilterValue = report.FilterValue;
DataType = report.DataType ?? 0;
FilterValue = report.FilterValue ?? 0;
ChartData = new List<ChartData>();
}
public int ReportID { get; set; }
/// <summary>
///
///
/// </summary>
public Nullable<int> ChartType { get; set; }
public int ChartType { get; set; }
/// <summary>
///
///
/// </summary>
public Nullable<int> Sort { get; set; }
public int Sort { get; set; }
/// <summary>
/// 报表标题
......@@ -92,12 +92,12 @@ public ReportData(rep_report report)
/// <summary>
/// 1表示需要进行小于百分2的类型进行合并
/// </summary>
public Nullable<int> DataType { get; set; }
public int DataType { get; set; }
/// <summary>
/// 图标value过滤执值
/// </summary>
public Nullable<decimal> FilterValue { get; set; }
public decimal FilterValue { get; set; }
/// <summary>
/// 图表数据
......@@ -115,14 +115,17 @@ public class ChartData
/// X轴内容
/// </summary>
public string X { get; set; }
/// <summary>
/// Y轴内容
/// </summary>
public string Y { get; set; }
/// <summary>
/// 分类
/// </summary>
public string Name { get; set; }
/// <summary>
/// 值
/// </summary>
......@@ -131,7 +134,8 @@ public class ChartData
/// <summary>
/// 总量
/// </summary>
public Double? Total { get; set; }
public Double Total { get; set; }
/// <summary>
/// ChartData 类型标签
/// </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 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<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.Options" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
......
......@@ -6,8 +6,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;
using Performance.EntityModels;
using Performance.Infrastructure.Models;
using System.Linq.Dynamic.Core;
namespace Performance.Repository
{
......@@ -22,5 +25,15 @@ public PerforReportperformanceRepository(PerformanceDbContext context) : base(co
{
_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.EntityModels;
using Performance.Infrastructure.Models;
using Performance.Repository;
using System;
using System.Collections.Generic;
......@@ -23,19 +24,13 @@ PerforReportperformanceRepository reportperformanceRepository
this.reportperformanceRepository = reportperformanceRepository;
}
#region Demo
public ReportData Test(int hospitalId, int year, int month)
{
return new ReportData(new rep_report())
{
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 },
}
ChartData = new List<ChartData>()
};
}
......@@ -65,5 +60,48 @@ public List<report_performance> GetPerformances(int hospitalId, int year, int mo
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