perf:索引优化

- 预警规则主体添加联合索引(CustomId,SubSystemId)
 - 运输预警明细生成任务索引调整
 IDX_IsClosed_PlanExecutionTime=>IDX_PlanExecutionTime_IsClosed

 refactor:运输时效场景中因素输入月份排序
This commit is contained in:
hardstylewyl 2025-03-20 09:54:54 +08:00
parent 554236af30
commit 653880fb37
5 changed files with 15 additions and 7 deletions

View File

@ -296,6 +296,12 @@ public class TransportWarningService : ApplicationService
var oldScene = await _warningRuleRepository.GetTransportSceneAsync(input.WarningId, input.Id);
var oldBo = oldScene != null ? TransportWarningSceneBO.From(oldScene) : null;
// 如果有月份则排序之后在写入
if (!string.IsNullOrWhiteSpace(postBo.Months))
{
var sorted = postBo.Months.Split('/').Select(int.Parse).OrderBy(x => x).ToList();
postBo.Months = string.Join('/', sorted);
}
// 更新或者新增
var id = await _warningRuleRepository.UpsertTransportSceneReturnIdAsync(postBo.ToEntity());

View File

@ -1,7 +1,7 @@
namespace SJZY.Track.Domain.Aggregates.WarningAggregate.Transport;
[SugarTable("t_warning_transport_generate_task", TableDescription = "运输时效预警明细生成任务")]
[SugarIndex("IDX_IsClosed_PlanExecutionTime", nameof(IsClosed), OrderByType.Desc, nameof(PlanExecutionTime), OrderByType.Asc)]
[SugarIndex("IDX_PlanExecutionTime_IsClosed", nameof(PlanExecutionTime), OrderByType.Asc, nameof(IsClosed), OrderByType.Asc)]
public sealed class TransportWarningDetailsGenerateTaskEntity : IFullAuditedBasicEntitys, IEntity
{
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
@ -39,4 +39,4 @@ public sealed class TransportWarningDetailsGenerateTaskEntity : IFullAuditedBasi
[SugarColumn(ColumnName = "IsClosed", ColumnDescription = "是否关闭")]
public bool IsClosed { get; set; } //是否关闭,执行完成被关闭/手动关闭
}
}

View File

@ -4,6 +4,7 @@ namespace SJZY.Track.Domain.Aggregates.WarningAggregate;
// 预警规则主体
[SugarTable("t_warning_0", TableDescription = "预警规则主体(用于将来替换t_warning)")]
[SugarIndex("IDX_CustomId_SubSystemId", nameof(CustomId), OrderByType.Asc, nameof(SubSystemId), OrderByType.Asc)]
public sealed class WarningRuleEntity : IFullAuditedBasicEntitys, IAggregateRoot
{
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]

View File

@ -89,10 +89,11 @@ public class WarningRuleRepository : BasicRepository<WarningRuleEntity>, IWarnin
public async Task<WarningRuleEntity?> GetWarningRuleForEnabledAsync(int subSystemId, int customId, WarningRuleType warningType)
{
var warningRules = await Context.Queryable<WarningRuleEntity>()
.Where(x => x.IsEnabled)
.Where(x => x.SubSystemId == subSystemId)
.Where(x => x.CustomId == customId)
.Where(x => x.WarningType == (int) warningType)
.Where(x => x.CustomId == customId
&& x.SubSystemId == subSystemId
&& x.WarningType == (int) warningType
&& x.IsEnabled
)
.ToListAsync();
return warningRules.FirstOrDefault();

View File

@ -113,7 +113,7 @@ public sealed class WarningTaskRepository : BasicRepository<WarningNotifyTaskEnt
public Task<List<TransportWarningDetailsGenerateTaskEntity>> ScanTransportWarningDetailsGenerateTaskAsync()
{
return Context.Queryable<TransportWarningDetailsGenerateTaskEntity>()
.Where(x => x.IsClosed == false && DateTime.Now >= x.PlanExecutionTime)
.Where(x => DateTime.Now >= x.PlanExecutionTime && x.IsClosed == false)
.ToListAsync();
}