fix:修复规则主体重复校验逻辑错误

This commit is contained in:
hardstylewyl 2025-03-07 11:54:36 +08:00
parent b4d98a5d89
commit ef055943f6

View File

@ -14,15 +14,17 @@ public sealed class WarningRuleRepository : BasicRepository<WarningRuleEntity>,
public async Task<bool> CheckNameDuplicateAsync(int id, int subsystemId, int customId, string name)
{
var entity = await Context.Queryable<WarningRuleEntity>()
var list = await Context.Queryable<WarningRuleEntity>()
.Where(x => x.SubSystemId == subsystemId &&
x.CustomId == customId
&& string.Equals(x.Name, name))
.FirstAsync();
.ToListAsync();
// 如果是新增,则要求不能重复添加 subsystemId+customId+name三者都相同的
if (id == 0)
return entity != null;
var entity = list.First();
// 不重复
if (entity == null)
return false;
// 如果是修改,则要求查出来的和要修改的是同一个,否则视为重复
return entity.Id != id;