fix 时段码分页

This commit is contained in:
2024-07-31 14:57:03 +08:00
parent 26b1e56a20
commit 54cbd38b78
4 changed files with 32 additions and 10 deletions

View File

@@ -30,7 +30,7 @@ public class DeviceTimePeriodsController : ControllerBase
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet("page")] [HttpGet("page")]
public async Task<Pagination<DeviceTimePeriodResponse>> GetPageAsync([FromQuery] DeviceTimePeriodPageRequest request) public async Task<Pagination<DeviceTimePeriodPageResponse>> GetPageAsync([FromQuery] DeviceTimePeriodPageRequest request)
{ {
return await _deviceTimePeriodService.GetPageAsync(request); return await _deviceTimePeriodService.GetPageAsync(request);
} }

View File

@@ -0,0 +1,21 @@
using Dlhis.Entity.Device.Enums;
namespace Dlhis.Basic.Device.Response;
public class DeviceTimePeriodPageResponse
{
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 分配类型
/// </summary>
public DeviceTimePeriodAssignEnumType AssignType { get; set; }
/// <summary>
/// 分配值
/// </summary>
public Guid Value { get; set; }
}

View File

@@ -7,7 +7,7 @@ namespace Dlhis.Basic.Device.Services;
public interface IDeviceTimePeriodService : IScopeDependency public interface IDeviceTimePeriodService : IScopeDependency
{ {
Task<Pagination<DeviceTimePeriodResponse>> GetPageAsync(DeviceTimePeriodPageRequest request); Task<Pagination<DeviceTimePeriodPageResponse>> GetPageAsync(DeviceTimePeriodPageRequest request);
Task SaveAsync(DeviceTimePeriodSaveRequest request); Task SaveAsync(DeviceTimePeriodSaveRequest request);

View File

@@ -22,25 +22,26 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService
} }
/// <inheritdoc /> /// <inheritdoc />
public async Task<Pagination<DeviceTimePeriodResponse>> GetPageAsync(DeviceTimePeriodPageRequest request) public async Task<Pagination<DeviceTimePeriodPageResponse>> GetPageAsync(DeviceTimePeriodPageRequest request)
{ {
var pageOri = await _dbContext.Queryable<DeviceTimePeriodEntity>() var page = await _dbContext.Queryable<DeviceTimePeriodEntity>()
.Where(x => x.AssignType == request.AssignType) .Where(x => x.AssignType == request.AssignType)
.GroupBy(x => new { x.AssignType, x.Value })
.Select(x => new DeviceTimePeriodPageResponse
{
AssignType = x.AssignType,
Value = x.Value
})
.ToPageListAsync(request); .ToPageListAsync(request);
var page = pageOri.Adapt<Pagination<DeviceTimePeriodResponse>>();
var values = page.Data.Select(x => x.Value); var values = page.Data.Select(x => x.Value);
var data = request.AssignType == DeviceTimePeriodAssignEnumType.Device var data = request.AssignType == DeviceTimePeriodAssignEnumType.Device
? await _dbContext.Queryable<DeviceEntity>().Where(x => values.Contains(x.Code)).Select(x => new { x.Code, Name = x.DeployPlace }).ToListAsync() ? await _dbContext.Queryable<DeviceEntity>().Where(x => values.Contains(x.Code)).Select(x => new { x.Code, Name = x.DeployPlace }).ToListAsync()
: await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => values.Contains(x.Code)).Select(x => new { x.Code, x.Name }).ToListAsync(); : await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => values.Contains(x.Code)).Select(x => new { x.Code, x.Name }).ToListAsync();
var basicTypes = await _dbContext.Queryable<BasicTypeEntity>().Where(x => x.Type == "timeperiod").ToListAsync();
page.Data.ForEach(item => page.Data.ForEach(item =>
{ {
item.Name = data.FirstOrDefault(x => x.Code == item.Value)?.Name; item.Name = data.FirstOrDefault(x => x.Code == item.Value)?.Name;
item.CardTypeDesc = basicTypes.FirstOrDefault(x => x.Code == item.CardType.ToString())?.Display;
}); });
return page; return page;