fix:修复预警明细的排序逻辑

fix:修复预警主体重复性判断增加预警类型
This commit is contained in:
hardstylewyl 2025-03-24 16:23:25 +08:00
parent d9751ecb34
commit a4c5ad619c
6 changed files with 20 additions and 30 deletions

View File

@ -193,13 +193,10 @@ public class CompleteWarningService : ApplicationService
};
});
var sorted = map.OrderBy(x =>
{
// 待处理置顶
if (x.Status == 1) return x.Status;
// 其他按创建时间从早到晚
return DateTimeHelper.ConvertToUnixTimestamp(x.CreateTime);
});
// 按状态组+组内时间降序,分割状态组 g1:(待处理) g2:(已处理/已关闭) 确保g1总是在g2之前
var sorted = map
.OrderBy(x => x.Status == (int) CompleteWarningStatus.待处理 ? 1 : 2)
.ThenByDescending(x => x.CreateTime); //同状态组按时间降序;
return new UnifyPageResultDto<CompleteWarningDetailsDto>(
sorted.ToList(),

View File

@ -158,13 +158,10 @@ public class ReturnWarningService : ApplicationService
CreateTime = x.CreateTime,
});
var sorted = map.OrderBy(x =>
{
// 人工介入置顶
if (x.Status == 1) return x.Status;
// 其他按创建时间从早到晚
return DateTimeHelper.ConvertToUnixTimestamp(x.CreateTime);
});
// 按状态组+组内时间降序,分割状态组 g1:(人工介入) g2:(重试中/推送完成/已关闭) 确保g1总是在g2之前
var sorted = map
.OrderBy(x => x.Status == (int) ReturnWarningStatus.人工介入 ? 1 : 2)
.ThenByDescending(x => x.CreateTime); //同状态组按时间降序;
return new UnifyPageResultDto<ReturnWarningDetailsDto>(
sorted.ToList(),

View File

@ -253,16 +253,10 @@ public class TransportWarningService : ApplicationService
// 计算后的状态过滤
var filtered = map.WhereIf(input.Status > 0, x => x.Status == input.Status);
// 按状态+时间排序
// 按状态组+组内时间降序,分割状态组 g1:(即将超时/已超时) g2:(已完成/超时完成/已关闭) 确保g1总是在g2之前
var sorted = filtered
.OrderBy(x =>
{
// 即将超时,已超时置顶
if (x.Status is 1 or 2) return x.Status;
// 其他按创建时间从早到晚
return DateTimeHelper.ConvertToUnixTimestamp(x.CreateTime);
})
.ThenByDescending(x => x.CreateTime) //同状态(即将超时/已超时)按创建时间从晚到早
.OrderBy(x => x.Status is (int) TransportWarningStatus.即将超时 or (int) TransportWarningStatus.已超时 ? 1 : 2)
.ThenByDescending(x => x.CreateTime) //同状态组按时间降序
.ToList();
return new UnifyPageResultDto<TransportWarningDetailsDto>(

View File

@ -130,10 +130,11 @@ public class WarningService : ApplicationService
throw new BusinessException(message: $"WarningId=[{input.Id}],WarningType=[{input.WarningType}]预警规则主体不存在,不允许修改");
}
// 要求 SubSystemId+CustomId+Name 联合不能重复
if (await _warningRuleRepository.CheckNameDuplicateAsync(input.Id, input.SubSystemId, input.CustomId, input.Name))
// 要求 SubSystemId+CustomId+Name+WarningType 联合不能重复
if (await _warningRuleRepository.CheckNameDuplicateAsync(input.Id, input.SubSystemId, input.CustomId, input.Name, (WarningRuleType) input.WarningType))
{
throw new BusinessException(message: $"SubSystemId:[{input.SubSystemId}],CustomId:[{input.CustomId}],已存在名称为[{input.Name}]规则,不允许重复创建/修改");
throw new BusinessException(message: $"SubSystemId:[{input.SubSystemId}],CustomId:[{input.CustomId}]," +
$"WarningType:[{input.WarningType.ToString()}]已存在名称为[{input.Name}]规则,不允许重复创建/修改");
}
// 如果创建/修改的主体为启用状态,则要求通过检查

View File

@ -13,7 +13,7 @@ public interface IWarningRuleRepository : IBasicRepository<WarningRuleEntity>
#region 规则主体
// 检查名称是否重复
Task<bool> CheckNameDuplicateAsync(int id, int subsystemId, int customId, string name);
Task<bool> CheckNameDuplicateAsync(int id, int subsystemId, int customId, string name, WarningRuleType warningType);
// 检查是同一【子系统+客户+类型】是否有多个启用的预警规则主体
Task<bool> CheckEnableDuplicateAsync(int warningId, int subsystemId, int customId, WarningRuleType warningType);

View File

@ -13,11 +13,12 @@ public class WarningRuleRepository : BasicRepository<WarningRuleEntity>, IWarnin
{
#region 规则主体
public async Task<bool> CheckNameDuplicateAsync(int id, int subsystemId, int customId, string name)
public async Task<bool> CheckNameDuplicateAsync(int id, int subsystemId, int customId, string name, WarningRuleType warningType)
{
var entity = await Context.Queryable<WarningRuleEntity>()
.Where(x => x.SubSystemId == subsystemId &&
x.CustomId == customId
.Where(x => x.SubSystemId == subsystemId
&& x.CustomId == customId
&& x.WarningType == (int) warningType
&& string.Equals(x.Name, name))
.FirstAsync();