Skip to content

Commit

Permalink
[enhance] list api support search and sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnkwlp committed Nov 10, 2022
1 parent 41e20cc commit 44cea28
Show file tree
Hide file tree
Showing 4 changed files with 316 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public async Task<ListResultDto<WorkflowExecutionLogDto>> GetExecutionLogsAsync(

public async Task<PagedResultDto<WorkflowInstanceBasicDto>> GetListAsync(WorkflowInstanceListRequestDto input)
{
var count = await _workflowInstanceRepository.GetCountAsync(name: input.Name, definitionId: input.WorkflowDefinitionId, version: input.Version, status: input.WorkflowStatus, correlationId: input.CorrelationId);
var count = await _workflowInstanceRepository.LongCountAsync(name: input.Name, definitionId: input.WorkflowDefinitionId, version: input.Version, status: input.WorkflowStatus, correlationId: input.CorrelationId);
var list = await _workflowInstanceRepository.GetPagedListAsync(input.SkipCount, input.MaxResultCount, null, name: input.Name, definitionId: input.WorkflowDefinitionId, version: input.Version, status: input.WorkflowStatus, correlationId: input.CorrelationId);

return new PagedResultDto<WorkflowInstanceBasicDto>(count, ObjectMapper.Map<List<WorkflowInstance>, List<WorkflowInstanceBasicDto>>(list));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,62 @@ namespace Passingwind.Abp.ElsaModule.Common;

public interface IWorkflowInstanceRepository : IRepository<WorkflowInstance, Guid>
{
Task<long> GetCountAsync(string name = null, Guid? definitionId = null, Guid? definitionVersionId = null, int? version = null, WorkflowInstanceStatus? status = null, string correlationId = null, CancellationToken cancellationToken = default);
Task<long> LongCountAsync(
string name = null,
Guid? definitionId = null,
Guid? definitionVersionId = null,
int? version = null,
WorkflowInstanceStatus? status = null,
string correlationId = null,
DateTime[] creationTimes = null,
DateTime[] lastExecutedTimes = null,
DateTime[] finishedTimes = null,
DateTime[] cancelledTimes = null,
DateTime[] faultedTimes = null,
CancellationToken cancellationToken = default);

Task<List<WorkflowInstance>> GetListAsync(string name = null, Guid? definitionId = null, Guid? definitionVersionId = null, int? version = null, WorkflowInstanceStatus? status = null, string correlationId = null, bool includeDetails = false, CancellationToken cancellationToken = default);
Task<List<WorkflowInstance>> GetListAsync(
string name = null,
Guid? definitionId = null,
Guid? definitionVersionId = null,
int? version = null,
WorkflowInstanceStatus? status = null,
string correlationId = null,
DateTime[] creationTimes = null,
DateTime[] lastExecutedTimes = null,
DateTime[] finishedTimes = null,
DateTime[] cancelledTimes = null,
DateTime[] faultedTimes = null,
bool includeDetails = false,
CancellationToken cancellationToken = default);

Task<List<WorkflowInstance>> GetPagedListAsync(int skipCount, int maxResultCount, string sorting, string name = null, Guid? definitionId = null, Guid? definitionVersionId = null, int? version = null, WorkflowInstanceStatus? status = null, string correlationId = null, bool includeDetails = false, CancellationToken cancellationToken = default);
Task<List<WorkflowInstance>> GetPagedListAsync(
int skipCount,
int maxResultCount,
string sorting,
string name = null,
Guid? definitionId = null,
Guid? definitionVersionId = null,
int? version = null,
WorkflowInstanceStatus? status = null,
string correlationId = null,
DateTime[] creationTimes = null,
DateTime[] lastExecutedTimes = null,
DateTime[] finishedTimes = null,
DateTime[] cancelledTimes = null,
DateTime[] faultedTimes = null,
bool includeDetails = false,
CancellationToken cancellationToken = default);

Task<Dictionary<WorkflowInstanceStatus, int>> GetWorkflowStatusStatisticsAsync(
string name = null,
Guid? definitionId = null,
Guid? definitionVersionId = null,
int? version = null,
string correlationId = null,
DateTime[] creationTimes = null,
CancellationToken cancellationToken = default);

Task<Dictionary<DateTime, int>> GetStatusDateCountStatisticsAsync(WorkflowInstanceStatus WorkflowInstanceStatus, DateTime startDate, DateTime endDate, CancellationToken cancellationToken = default);

}

Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,148 @@
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;

namespace Passingwind.Abp.ElsaModule.EntityFrameworkCore.Repositories
namespace Passingwind.Abp.ElsaModule.EntityFrameworkCore.Repositories;

public class WorkflowInstanceRepository : EfCoreRepository<ElsaModuleDbContext, WorkflowInstance, Guid>, IWorkflowInstanceRepository
{
public class WorkflowInstanceRepository : EfCoreRepository<ElsaModuleDbContext, WorkflowInstance, Guid>, IWorkflowInstanceRepository
public WorkflowInstanceRepository(IDbContextProvider<ElsaModuleDbContext> dbContextProvider) : base(dbContextProvider)
{
public WorkflowInstanceRepository(IDbContextProvider<ElsaModuleDbContext> dbContextProvider) : base(dbContextProvider)
{
}
}

public async Task<long> GetCountAsync(string name = null, Guid? definitionId = null, Guid? definitionVersionId = null, int? version = null, WorkflowInstanceStatus? status = null, string correlationId = null, CancellationToken cancellationToken = default)
{
var dbset = await GetDbSetAsync();
return await dbset
.WhereIf(definitionId.HasValue, x => x.WorkflowDefinitionId == definitionId)
.WhereIf(definitionVersionId.HasValue, x => x.WorkflowDefinitionVersionId == definitionVersionId)
.WhereIf(version.HasValue, x => x.Version == version)
.WhereIf(status.HasValue, x => x.WorkflowStatus == status)
.WhereIf(!string.IsNullOrEmpty(correlationId), x => x.CorrelationId == correlationId)
.WhereIf(!string.IsNullOrEmpty(name), x => EF.Functions.Like(x.Name, $"%{name}%"))
.LongCountAsync(cancellationToken);
}
public async Task<long> LongCountAsync(
string name = null,
Guid? definitionId = null,
Guid? definitionVersionId = null,
int? version = null,
WorkflowInstanceStatus? status = null,
string correlationId = null,
DateTime[] creationTimes = null,
DateTime[] lastExecutedTimes = null,
DateTime[] finishedTimes = null,
DateTime[] cancelledTimes = null,
DateTime[] faultedTimes = null,
CancellationToken cancellationToken = default)
{
var dbset = await GetDbSetAsync();
return await dbset
.WhereIf(definitionId.HasValue, x => x.WorkflowDefinitionId == definitionId)
.WhereIf(definitionVersionId.HasValue, x => x.WorkflowDefinitionVersionId == definitionVersionId)
.WhereIf(version.HasValue, x => x.Version == version)
.WhereIf(status.HasValue, x => x.WorkflowStatus == status)
.WhereIf(!string.IsNullOrEmpty(correlationId), x => x.CorrelationId == correlationId)
.WhereIf(!string.IsNullOrEmpty(name), x => EF.Functions.Like(x.Name, $"%{name}%"))
.WhereIf(creationTimes?.Length == 2, x => x.CreationTime >= creationTimes[0] && x.CreationTime <= creationTimes[1])
.WhereIf(lastExecutedTimes?.Length == 2, x => x.LastExecutedTime.HasValue && x.LastExecutedTime >= lastExecutedTimes[0] && x.LastExecutedTime <= lastExecutedTimes[1])
.WhereIf(finishedTimes?.Length == 2, x => x.FinishedTime.HasValue && x.FinishedTime >= finishedTimes[0] && x.FinishedTime <= finishedTimes[1])
.WhereIf(cancelledTimes?.Length == 2, x => x.CancelledTime.HasValue && x.CancelledTime >= cancelledTimes[0] && x.CancelledTime <= cancelledTimes[1])
.WhereIf(faultedTimes?.Length == 2, x => x.FaultedTime.HasValue && x.FaultedTime >= faultedTimes[0] && x.FaultedTime <= faultedTimes[1])
.LongCountAsync(cancellationToken);
}

public async Task<List<WorkflowInstance>> GetListAsync(string name = null, Guid? definitionId = null, Guid? definitionVersionId = null, int? version = null, WorkflowInstanceStatus? status = null, string correlationId = null, bool includeDetails = false, CancellationToken cancellationToken = default)
{
var dbset = await GetDbSetAsync();
return await dbset
.WhereIf(definitionId.HasValue, x => x.WorkflowDefinitionId == definitionId)
.WhereIf(definitionVersionId.HasValue, x => x.WorkflowDefinitionVersionId == definitionVersionId)
.WhereIf(version.HasValue, x => x.Version == version)
.WhereIf(status.HasValue, x => x.WorkflowStatus == status)
.WhereIf(!string.IsNullOrEmpty(correlationId), x => x.CorrelationId == correlationId)
.WhereIf(!string.IsNullOrEmpty(name), x => EF.Functions.Like(x.Name, $"%{name}%"))
.ToListAsync(cancellationToken);
}
public async Task<List<WorkflowInstance>> GetListAsync(
string name = null,
Guid? definitionId = null,
Guid? definitionVersionId = null,
int? version = null,
WorkflowInstanceStatus? status = null,
string correlationId = null,
DateTime[] creationTimes = null,
DateTime[] lastExecutedTimes = null,
DateTime[] finishedTimes = null,
DateTime[] cancelledTimes = null,
DateTime[] faultedTimes = null,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
var dbset = await GetDbSetAsync();
return await dbset
.WhereIf(definitionId.HasValue, x => x.WorkflowDefinitionId == definitionId)
.WhereIf(definitionVersionId.HasValue, x => x.WorkflowDefinitionVersionId == definitionVersionId)
.WhereIf(version.HasValue, x => x.Version == version)
.WhereIf(status.HasValue, x => x.WorkflowStatus == status)
.WhereIf(!string.IsNullOrEmpty(correlationId), x => x.CorrelationId == correlationId)
.WhereIf(!string.IsNullOrEmpty(name), x => EF.Functions.Like(x.Name, $"%{name}%"))
.WhereIf(creationTimes?.Length == 2, x => x.CreationTime >= creationTimes[0] && x.CreationTime <= creationTimes[1])
.WhereIf(lastExecutedTimes?.Length == 2, x => x.LastExecutedTime.HasValue && x.LastExecutedTime >= lastExecutedTimes[0] && x.LastExecutedTime <= lastExecutedTimes[1])
.WhereIf(finishedTimes?.Length == 2, x => x.FinishedTime.HasValue && x.FinishedTime >= finishedTimes[0] && x.FinishedTime <= finishedTimes[1])
.WhereIf(cancelledTimes?.Length == 2, x => x.CancelledTime.HasValue && x.CancelledTime >= cancelledTimes[0] && x.CancelledTime <= cancelledTimes[1])
.WhereIf(faultedTimes?.Length == 2, x => x.FaultedTime.HasValue && x.FaultedTime >= faultedTimes[0] && x.FaultedTime <= faultedTimes[1])
.ToListAsync(cancellationToken);
}

public async Task<List<WorkflowInstance>> GetPagedListAsync(int skipCount, int maxResultCount, string sorting, string name = null, Guid? definitionId = null, Guid? definitionVersionId = null, int? version = null, WorkflowInstanceStatus? status = null, string correlationId = null, bool includeDetails = false, CancellationToken cancellationToken = default)
{
var dbset = await GetDbSetAsync();
return await dbset
.WhereIf(definitionId.HasValue, x => x.WorkflowDefinitionId == definitionId)
.WhereIf(definitionVersionId.HasValue, x => x.WorkflowDefinitionVersionId == definitionVersionId)
.WhereIf(version.HasValue, x => x.Version == version)
.WhereIf(status.HasValue, x => x.WorkflowStatus == status)
.WhereIf(!string.IsNullOrEmpty(correlationId), x => x.CorrelationId == correlationId)
.WhereIf(!string.IsNullOrEmpty(name), x => EF.Functions.Like(x.Name, $"%{name}%"))
.OrderBy(sorting ?? nameof(WorkflowInstance.CreationTime) + " desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync(cancellationToken);
}
public async Task<List<WorkflowInstance>> GetPagedListAsync(
int skipCount,
int maxResultCount,
string sorting,
string name = null,
Guid? definitionId = null,
Guid? definitionVersionId = null,
int? version = null,
WorkflowInstanceStatus? status = null,
string correlationId = null,
DateTime[] creationTimes = null,
DateTime[] lastExecutedTimes = null,
DateTime[] finishedTimes = null,
DateTime[] cancelledTimes = null,
DateTime[] faultedTimes = null,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
var dbset = await GetDbSetAsync();
return await dbset
.WhereIf(definitionId.HasValue, x => x.WorkflowDefinitionId == definitionId)
.WhereIf(definitionVersionId.HasValue, x => x.WorkflowDefinitionVersionId == definitionVersionId)
.WhereIf(version.HasValue, x => x.Version == version)
.WhereIf(status.HasValue, x => x.WorkflowStatus == status)
.WhereIf(!string.IsNullOrEmpty(correlationId), x => x.CorrelationId == correlationId)
.WhereIf(!string.IsNullOrEmpty(name), x => EF.Functions.Like(x.Name, $"%{name}%"))
.WhereIf(creationTimes?.Length == 2, x => x.CreationTime >= creationTimes[0] && x.CreationTime <= creationTimes[1])
.WhereIf(lastExecutedTimes?.Length == 2, x => x.LastExecutedTime.HasValue && x.LastExecutedTime >= lastExecutedTimes[0] && x.LastExecutedTime <= lastExecutedTimes[1])
.WhereIf(finishedTimes?.Length == 2, x => x.FinishedTime.HasValue && x.FinishedTime >= finishedTimes[0] && x.FinishedTime <= finishedTimes[1])
.WhereIf(cancelledTimes?.Length == 2, x => x.CancelledTime.HasValue && x.CancelledTime >= cancelledTimes[0] && x.CancelledTime <= cancelledTimes[1])
.WhereIf(faultedTimes?.Length == 2, x => x.FaultedTime.HasValue && x.FaultedTime >= faultedTimes[0] && x.FaultedTime <= faultedTimes[1])
.OrderBy(sorting ?? nameof(WorkflowInstance.CreationTime) + " desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync(cancellationToken);
}

public async Task<Dictionary<DateTime, int>> GetStatusDateCountStatisticsAsync(WorkflowInstanceStatus workflowStatus, DateTime startDate, DateTime endDate, CancellationToken cancellationToken = default)
{
var dbset = await GetDbSetAsync();

public async Task<Dictionary<DateTime, int>> GetStatusDateCountStatisticsAsync(WorkflowInstanceStatus workflowStatus, DateTime startDate, DateTime endDate, CancellationToken cancellationToken = default)
{
var dbset = await GetDbSetAsync();
var list = await dbset
.Where(x => x.WorkflowStatus == workflowStatus && x.CreationTime.Date >= startDate.Date && x.CreationTime.Date <= endDate.Date)
.Select(x => new { x.Id, x.CreationTime })
.ToListAsync(cancellationToken);

var list = await dbset
.Where(x => x.WorkflowStatus == workflowStatus && x.CreationTime.Date >= startDate.Date && x.CreationTime.Date <= endDate.Date)
.Select(x => new { x.Id, x.CreationTime })
.ToListAsync(cancellationToken);
return list
.GroupBy(x => x.CreationTime.Date)
.ToDictionary(x => x.Key.Date, x => x.Count());
}

public async Task<Dictionary<WorkflowInstanceStatus, int>> GetWorkflowStatusStatisticsAsync(
string name = null,
Guid? definitionId = null,
Guid? definitionVersionId = null,
int? version = null,
string correlationId = null,
DateTime[] creationTimes = null,
CancellationToken cancellationToken = default)
{
var dbset = await GetDbSetAsync();

return list
.GroupBy(x => x.CreationTime.Date)
.ToDictionary(x => x.Key.Date, x => x.Count());
}
var list = await dbset
.WhereIf(definitionId.HasValue, x => x.WorkflowDefinitionId == definitionId)
.WhereIf(definitionVersionId.HasValue, x => x.WorkflowDefinitionVersionId == definitionVersionId)
.WhereIf(version.HasValue, x => x.Version == version)
.WhereIf(!string.IsNullOrEmpty(correlationId), x => x.CorrelationId == correlationId)
.WhereIf(!string.IsNullOrEmpty(name), x => EF.Functions.Like(x.Name, $"%{name}%"))
.WhereIf(creationTimes?.Length == 2, x => x.CreationTime >= creationTimes[0] && x.CreationTime <= creationTimes[1])
.Select(x => new { x.Id, x.WorkflowStatus })
.ToListAsync(cancellationToken);

return list
.GroupBy(x => x.WorkflowStatus)
.ToDictionary(x => x.Key, x => x.Count());
}
}
Loading

0 comments on commit 44cea28

Please sign in to comment.