Commit b47369b6 by lcx

Merge branch 'feature/人员字典分页' into develop

parents aaba54e6 f6539eae
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using FluentValidation.AspNetCore; using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure;
using Performance.Services; using Performance.Services;
namespace Performance.Api.Controllers namespace Performance.Api.Controllers
...@@ -27,13 +30,21 @@ public PersonController(PersonService personService, ClaimService claimService) ...@@ -27,13 +30,21 @@ public PersonController(PersonService personService, ClaimService claimService)
/// 获取所有员工记录 /// 获取所有员工记录
/// </summary> /// </summary>
/// <param name="allotId"></param> /// <param name="allotId"></param>
/// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
[Route("person/list/{allotId}")] [Route("person/list/{allotId}")]
[HttpPost] [HttpPost]
public ApiResponse GetPersons(int allotId) public ApiResponse GetPersons([FromRoute] int allotId, [FromBody] PersonParamsRequest request)
{ {
var list = personService.GetPersons(allotId, claimService.GetUserId()); var list = personService.GetPersons(allotId, claimService.GetUserId(), request);
return new ApiResponse(ResponseType.OK, list); return new ApiResponse(ResponseType.OK, new
{
list.CurrentPage,
list.TotalPages,
list.PageSize,
list.TotalCount,
list
});
} }
/// <summary> /// <summary>
...@@ -80,6 +91,30 @@ public ApiResponse DeletePerson(int employeeId) ...@@ -80,6 +91,30 @@ public ApiResponse DeletePerson(int employeeId)
} }
/// <summary> /// <summary>
/// 下载当前测算表
/// </summary>
/// <returns></returns>
[Route("person/list/download/{allotId}")]
[HttpPost]
public IActionResult DownloadCurrentCalculationTable([FromRoute] int allotId)
{
var filepath = personService.GetPersonDictFile(allotId, claimService.GetUserId());
if (!FileHelper.IsExistFile(filepath))
throw new PerformanceException("获取人员字典失败");
var memoryStream = new MemoryStream();
using (var stream = new FileStream(filepath, FileMode.Open))
{
stream.CopyToAsync(memoryStream).Wait();
}
memoryStream.Seek(0, SeekOrigin.Begin);
var provider = new FileExtensionContentTypeProvider();
FileInfo fileInfo = new FileInfo(filepath);
var memi = provider.Mappings[".xlsx"];
return File(memoryStream, memi, Path.GetFileName(fileInfo.Name));
}
/// <summary>
/// 获取所有科室记录 /// 获取所有科室记录
/// </summary> /// </summary>
/// <param name="hospitalId"></param> /// <param name="hospitalId"></param>
...@@ -206,7 +241,7 @@ public ApiResponse BathSavePerson(int allotId, int hospitalId, SaveCollectData r ...@@ -206,7 +241,7 @@ public ApiResponse BathSavePerson(int allotId, int hospitalId, SaveCollectData r
if (result) if (result)
return new ApiResponse(ResponseType.OK); return new ApiResponse(ResponseType.OK);
else else
return new ApiResponse(ResponseType.Error,"出勤天数或预留比例格式错误"); return new ApiResponse(ResponseType.Error, "出勤天数或预留比例格式错误");
} }
/// <summary> /// <summary>
......
...@@ -16,7 +16,7 @@ namespace Performance.Api ...@@ -16,7 +16,7 @@ namespace Performance.Api
{ {
public class RequestRateLimitingMiddleware public class RequestRateLimitingMiddleware
{ {
private readonly int Limit; private readonly int Limit = 1;
private readonly ILogger logger; private readonly ILogger logger;
private readonly RequestDelegate next; private readonly RequestDelegate next;
private readonly IMemoryCache requestStore; private readonly IMemoryCache requestStore;
...@@ -34,15 +34,14 @@ public class RequestRateLimitingMiddleware ...@@ -34,15 +34,14 @@ public class RequestRateLimitingMiddleware
this.next = next; this.next = next;
this.requestStore = requestStore; this.requestStore = requestStore;
this.httpContextAccessor = httpContextAccessor; this.httpContextAccessor = httpContextAccessor;
if (options == null)
throw new ArgumentNullException(nameof(options));
this.options = options.Value; this.options = options.Value;
Limit = options.Value.Limit; if (options != null)
Limit = options.Value.Limit;
} }
public async Task Invoke(HttpContext context) public async Task Invoke(HttpContext context)
{ {
if (options.Endpoints == null || !options.Endpoints.Any(t => context.Request.Path.ToString().StartsWith(t))) if (options == null || options.Endpoints == null || !options.Endpoints.Any(t => context.Request.Path.ToString().StartsWith(t)))
await next(context); await next(context);
var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(); var ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
...@@ -69,7 +68,7 @@ public class RequestRateLimitingMiddleware ...@@ -69,7 +68,7 @@ public class RequestRateLimitingMiddleware
else else
{ {
// X-RateLimit-RetryAfter:超出限制后能够再次正常访问的时间。 // X-RateLimit-RetryAfter:超出限制后能够再次正常访问的时间。
context.Response.Headers["X-RateLimit-RetryAfter"] = cacheOptions.AbsoluteExpiration?.ToString(); //context.Response.Headers["X-RateLimit-RetryAfter"] = cacheOptions.AbsoluteExpiration?.ToString();
context.Response.StatusCode = StatusCodes.Status200OK; context.Response.StatusCode = StatusCodes.Status200OK;
context.Response.ContentType = "application/json; charset=utf-8"; context.Response.ContentType = "application/json; charset=utf-8";
var response = new ApiResponse var response = new ApiResponse
...@@ -90,10 +89,10 @@ public class RequestRateLimitingMiddleware ...@@ -90,10 +89,10 @@ public class RequestRateLimitingMiddleware
{ {
hitCount++; hitCount++;
requestStore.Set(requestKey, hitCount, cacheOptions); requestStore.Set(requestKey, hitCount, cacheOptions);
// X-RateLimit-Limit:同一个时间段所允许的请求的最大数目 //// X-RateLimit-Limit:同一个时间段所允许的请求的最大数目
context.Response.Headers["X-RateLimit-Limit"] = Limit.ToString(); //context.Response.Headers["X-RateLimit-Limit"] = Limit.ToString();
// X-RateLimit-Remaining:在当前时间段内剩余的请求的数量。 //// X-RateLimit-Remaining:在当前时间段内剩余的请求的数量。
context.Response.Headers["X-RateLimit-Remaining"] = (Limit - hitCount).ToString(); //context.Response.Headers["X-RateLimit-Remaining"] = (Limit - hitCount).ToString();
await next(context); await next(context);
} }
} }
......
...@@ -101,15 +101,15 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) ...@@ -101,15 +101,15 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.UseStatusCodePagesWithReExecute("/error/{0}"); app.UseStatusCodePagesWithReExecute("/error/{0}");
} }
app.UseMiddleware<RequestRateLimitingMiddleware>();
app.UseCors("SignalrCore"); app.UseCors("SignalrCore");
app.UseSignalR(routes => routes.MapHub<AllotLogHub>("/performance/allotLogHub")); app.UseSignalR(routes => routes.MapHub<AllotLogHub>("/performance/allotLogHub"));
app.UseMvc();
app.UseSwaggerSetup(Configuration); app.UseSwaggerSetup(Configuration);
app.UseMiddleware<RequestRateLimitingMiddleware>();
app.UseMvc();
} }
private void JsonOptions(MvcJsonOptions json) private void JsonOptions(MvcJsonOptions json)
......
...@@ -1101,11 +1101,12 @@ ...@@ -1101,11 +1101,12 @@
</summary> </summary>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Performance.Api.Controllers.PersonController.GetPersons(System.Int32)"> <member name="M:Performance.Api.Controllers.PersonController.GetPersons(System.Int32,Performance.DtoModels.PersonParamsRequest)">
<summary> <summary>
获取所有员工记录 获取所有员工记录
</summary> </summary>
<param name="allotId"></param> <param name="allotId"></param>
<param name="request"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Performance.Api.Controllers.PersonController.CreatePerson(Performance.DtoModels.PerEmployeeResponse)"> <member name="M:Performance.Api.Controllers.PersonController.CreatePerson(Performance.DtoModels.PerEmployeeResponse)">
...@@ -1129,6 +1130,12 @@ ...@@ -1129,6 +1130,12 @@
<param name="employeeId"></param> <param name="employeeId"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Performance.Api.Controllers.PersonController.DownloadCurrentCalculationTable(System.Int32)">
<summary>
下载当前测算表
</summary>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.PersonController.GetDepartments(System.Int32)"> <member name="M:Performance.Api.Controllers.PersonController.GetDepartments(System.Int32)">
<summary> <summary>
获取所有科室记录 获取所有科室记录
......
...@@ -1851,7 +1851,7 @@ ...@@ -1851,7 +1851,7 @@
</member> </member>
<member name="P:Performance.DtoModels.AccoungingRequest.Type"> <member name="P:Performance.DtoModels.AccoungingRequest.Type">
<summary> <summary>
1 返回accounting列表 2 返回核算单元 3 返回核算单元类型 1 返回accounting列表 2 返回核算单元类型 3 返回核算单元
</summary> </summary>
</member> </member>
<member name="P:Performance.DtoModels.AccoungingRequest.UnitType"> <member name="P:Performance.DtoModels.AccoungingRequest.UnitType">
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.DtoModels
{
public class PersonParamsRequest
{
public const int MaxPageSize = 50;
public int PageNumber { get; set; } = 1;
private int _pageSize = 10;
public int PageSize
{
get { return _pageSize; }
set
{
_pageSize = value > MaxPageSize ? MaxPageSize : value;
}
}
public string SearchQuery { get; set; }
}
}
using System; using Newtonsoft.Json;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
namespace Performance.Infrastructure.Models namespace Performance.Infrastructure.Models
{ {
......
//-----------------------------------------------------------------------
// <copyright file=" per_employee.cs">
// * FileName: per_employee.cs
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Linq;
using System.Linq.Expressions;
using Performance.EntityModels;
using Performance.Infrastructure.Models;
namespace Performance.Repository
{
/// <summary>
/// per_employee Repository
/// </summary>
public partial class PerforPeremployeeRepository : PerforRepository<per_employee>
{
public new PageList<per_employee> GetEntitiesForPaging(int pageNumber, int pageSize, Expression<Func<per_employee, bool>> exp)
{
IQueryable<per_employee> queryableAuthors = context.Set<per_employee>().Where(exp);
return PageList<per_employee>.Create(queryableAuthors, pageNumber, pageSize);
}
}
}
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