fix 优化查询

This commit is contained in:
2025-02-26 12:13:47 +08:00
parent 1669dcbd11
commit 6232ba4683
6 changed files with 28 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
using Dlhis.Basic.WorkGrids.Request;
using Dlhis.Basic.WorkGrids.Response;
using Dlhis.Basic.WorkGrids.Services;
using Dlhis.Entity.Basic.Enums;
using Kurisu.AspNetCore.CustomClass;
using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
@@ -129,15 +130,16 @@ public class WorkGridsController : ControllerBase
}
/// <summary>
/// 获取人网格员排班列表
/// 获取网格员排班列表
/// </summary>
/// <param name="workGridCode">网格code</param>
/// <param name="date"></param>
/// <param name="periodType"></param>
/// <returns></returns>
[HttpGet("user/schedule/list")]
public async Task<List<WorkGridScheduleResponse>> GetListAsync([FromQuery] Guid workGridCode, [FromQuery] DateTime date)
public async Task<List<WorkGridScheduleResponse>> GetListAsync([FromQuery] Guid workGridCode, [FromQuery] DateTime date, [FromQuery] WorkGridTimePeriodEnumType? periodType)
{
return await _workGridScheduleService.GetListAsync(workGridCode, new DateOnly(date.Year, date.Month, date.Day));
return await _workGridScheduleService.GetListAsync(workGridCode, new DateOnly(date.Year, date.Month, date.Day), periodType);
}
/// <summary>

View File

@@ -4,5 +4,8 @@ namespace Dlhis.Basic.WorkGrids.Request;
public class WorkGridPageRequest : PageDto
{
/// <summary>
/// 网格code,不传则取我的网格
/// </summary>
public Guid? WorkGridCode { get; set; }
}

View File

@@ -9,4 +9,6 @@ public class WorkGridScheduleResponse
public WorkGridTimePeriodEnumType PeriodType { get; set; }
public string UserCode { get; set; }
public string UserName { get; set; }
}

View File

@@ -1,5 +1,6 @@
using Dlhis.Basic.WorkGrids.Request;
using Dlhis.Basic.WorkGrids.Response;
using Dlhis.Entity.Basic.Enums;
using Kurisu.AspNetCore.DataAccess.Dto;
namespace Dlhis.Basic.WorkGrids.Services;
@@ -11,7 +12,7 @@ public interface IWorkGridScheduleService : IScopeDependency
{
Task SaveAsync(WorkGridScheduleSaveRequest request);
Task<List<WorkGridScheduleResponse>> GetListAsync(Guid workGridCode, DateOnly date);
Task<List<WorkGridScheduleResponse>> GetListAsync(Guid workGridCode, DateOnly date, WorkGridTimePeriodEnumType? periodType);
Task<IEnumerable<WorkGridScheduleSummaryResponse>> GetListSummaryAsync(Guid workGridCode, DateOnly start, DateOnly end);

View File

@@ -1,6 +1,7 @@
using Dlhis.Basic.WorkGrids.Request;
using Dlhis.Basic.WorkGrids.Response;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Basic.Enums;
using Dlhis.Entity.Device.Entities;
using Dlhis.Jip.Api;
using Dlhis.Jip.Api.Requests;
@@ -17,7 +18,7 @@ public class WorkGridScheduleService : IWorkGridScheduleService
private readonly IDbContext _dbContext;
private readonly IJinkoJipApi _jinkoJipApi;
public WorkGridScheduleService(IDbContext dbContext ,IJinkoJipApi jinkoJipApi)
public WorkGridScheduleService(IDbContext dbContext, IJinkoJipApi jinkoJipApi)
{
_dbContext = dbContext;
_jinkoJipApi = jinkoJipApi;
@@ -53,15 +54,18 @@ public class WorkGridScheduleService : IWorkGridScheduleService
}
/// <inheritdoc />
public async Task<List<WorkGridScheduleResponse>> GetListAsync(Guid workGridCode, DateOnly date)
public async Task<List<WorkGridScheduleResponse>> GetListAsync(Guid workGridCode, DateOnly date, WorkGridTimePeriodEnumType? periodType)
{
return await _dbContext.Queryable<WorkGridScheduleEntity>()
.LeftJoin<GainfoEntity>((x, ga) => x.UserCode == ga.Code)
.Where(x => x.WorkGridCode == workGridCode && x.Date == date)
.Select(x => new WorkGridScheduleResponse
.WhereIF(periodType.HasValue, x => x.PeriodType == periodType)
.Select((x, ga) => new WorkGridScheduleResponse
{
Date = x.Date,
PeriodType = x.PeriodType,
UserCode = x.UserCode
UserCode = x.UserCode,
UserName = ga.Name
})
.ToListAsync();
}
@@ -92,7 +96,7 @@ public class WorkGridScheduleService : IWorkGridScheduleService
{
return await _dbContext.Queryable<DeviceUploadLogEntity>()
.LeftJoin<DeviceEntity>((log, d) => log.DeviceUniqueNo == d.UniqueNo)
.Where(log => log.UserUniqueNo == request.UserCode )
.Where(log => log.UserUniqueNo == request.UserCode)
.WhereIF(request.DateTimePeriod.HasValue(), log => log.RaiseDateTime >= request.DateTimePeriod.Start
&& log.RaiseDateTime <= request.DateTimePeriod.End)
.OrderBy(log => log.RaiseDateTime)

View File

@@ -74,6 +74,7 @@ public class WorkGridService : IWorkGridService
return await _dbContext.Queryable<WorkGridEntity>()
.LeftJoin<GainfoEntity>((x, ga) => x.LeaderUserCode == ga.Code)
.WhereIF(!isAll, x => x.LeaderUserCode == userCode)
.WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search) || x.LeaderUserCode == request.Search)
.Select((x, ga) => new WorkGridPageResponse
{
Id = x.Id,
@@ -105,7 +106,8 @@ public class WorkGridService : IWorkGridService
{
var currentUserCode = _currentUser.GetUserClaim("jinko-code");
var myWorkGrid = await _dbContext.Queryable<WorkGridEntity>()
.Where(x => x.LeaderUserCode == currentUserCode)
.WhereIF(request.WorkGridCode.HasValue == false, x => x.LeaderUserCode == currentUserCode)
.WhereIF(request.WorkGridCode.HasValue, x => x.Code == request.WorkGridCode)
.Select(x => new WorkGridUserPageResponse
{
Id = x.Id,
@@ -115,6 +117,7 @@ public class WorkGridService : IWorkGridService
UserInfos = SqlFunc.Subqueryable<WorkGridUserEntity>()
.LeftJoin<GainfoEntity>((p, ga) => p.UserCode == ga.Code)
.Where((p, ga) => p.WorkGridCode == x.Code)
.WhereIF(request.Search.IsPresent(), (p, ga) => p.UserCode == request.Search || ga.Name.Contains(request.Search))
.ToList((p, ga) => new WorkGridUserPageDetailResponse
{
Code = p.UserCode,