admin/src/Oms.SqlSugarCore/Channels/IssueTemplateRepository.cs
zzh 0c763f9707 fix(channel): 修复问题模板重复校验 SQL 语法错误
避免 SqlSugar 翻译闭包 null 比较,改用分支与布尔标志构建查询条件。
2026-07-06 15:28:01 +08:00

39 lines
1.3 KiB
C#

using Fake.DependencyInjection;
using Oms.Domain.ChannelsAggregate.Entities;
using Oms.Domain.ChannelsAggregate.Repositories;
using Oms.SqlSugarCore.Repositories;
namespace Oms.SqlSugarCore.Channels;
public class IssueTemplateRepository : OmsSqlSugarRepository<IssueTemplate>, IIssueTemplateRepository, IScopedDependency
{
public async Task<bool> ExistsDuplicateAsync(
string? organizationId,
string issueType,
int? excludeId = null,
CancellationToken cancellationToken = default)
{
var normalizedOrg = string.IsNullOrWhiteSpace(organizationId) ? null : organizationId.Trim();
var normalizedType = issueType.Trim();
var hasExcludeId = excludeId.HasValue;
var excludeIdValue = excludeId.GetValueOrDefault();
if (normalizedOrg == null)
{
return await AnyAsync(
x =>
x.IssueType == normalizedType
&& (x.OrganizationId == null || x.OrganizationId == string.Empty)
&& (!hasExcludeId || x.Id != excludeIdValue),
cancellationToken);
}
return await AnyAsync(
x =>
x.IssueType == normalizedType
&& x.OrganizationId == normalizedOrg
&& (!hasExcludeId || x.Id != excludeIdValue),
cancellationToken);
}
}