fix(channel): 修复问题模板重复校验 SQL 语法错误

避免 SqlSugar 翻译闭包 null 比较,改用分支与布尔标志构建查询条件。
This commit is contained in:
zzh 2026-07-06 15:28:01 +08:00
parent 4f5390ccb1
commit 0c763f9707
2 changed files with 26 additions and 9 deletions

View File

@ -101,12 +101,16 @@ public class IssueTemplateService : ApplicationService
{
var normalizedOrg = NormalizeOrganizationId(organizationId);
var normalizedType = issueType?.Trim();
var hasOrgFilter = normalizedOrg != null;
var hasTypeFilter = !string.IsNullOrWhiteSpace(normalizedType);
var orgValue = normalizedOrg ?? string.Empty;
var typeValue = normalizedType ?? string.Empty;
var entities = await IssueTemplateRepository.GetListAsync(x =>
x.Status == EnableStatus.Enabled
&& (string.IsNullOrWhiteSpace(normalizedType) || x.IssueType == normalizedType)
&& (normalizedOrg == null
|| x.OrganizationId == normalizedOrg
&& (!hasTypeFilter || x.IssueType == typeValue)
&& (!hasOrgFilter
|| x.OrganizationId == orgValue
|| x.OrganizationId == null
|| x.OrganizationId == string.Empty));
@ -136,12 +140,14 @@ public class IssueTemplateService : ApplicationService
var organizationId = NormalizeOrganizationId(input.OrganizationId);
var issueType = input.IssueType?.Trim();
var keyword = input.Keyword?.Trim();
var status = input.Status;
var hasOrganizationFilter = organizationId != null;
var hasStatusFilter = input.Status.HasValue;
var statusValue = input.Status.GetValueOrDefault();
return entity =>
(organizationId == null || entity.OrganizationId == organizationId)
(!hasOrganizationFilter || entity.OrganizationId == organizationId)
&& (string.IsNullOrWhiteSpace(issueType) || entity.IssueType == issueType)
&& (status == null || (byte)entity.Status == status.Value)
&& (!hasStatusFilter || (byte)entity.Status == statusValue)
&& (string.IsNullOrWhiteSpace(keyword)
|| entity.Title.Contains(keyword)
|| entity.Content.Contains(keyword));

View File

@ -15,13 +15,24 @@ public class IssueTemplateRepository : OmsSqlSugarRepository<IssueTemplate>, IIs
{
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
&& ((normalizedOrg == null && (x.OrganizationId == null || x.OrganizationId == string.Empty))
|| x.OrganizationId == normalizedOrg)
&& (!excludeId.HasValue || x.Id != excludeId.Value),
&& x.OrganizationId == normalizedOrg
&& (!hasExcludeId || x.Id != excludeIdValue),
cancellationToken);
}
}