From 0c763f9707a2f7ba8c5d6b6b6ddc7a3439110a87 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Mon, 6 Jul 2026 15:28:01 +0800 Subject: [PATCH] =?UTF-8?q?fix(channel):=20=E4=BF=AE=E5=A4=8D=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E6=A8=A1=E6=9D=BF=E9=87=8D=E5=A4=8D=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=20SQL=20=E8=AF=AD=E6=B3=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 避免 SqlSugar 翻译闭包 null 比较,改用分支与布尔标志构建查询条件。 --- .../Services/Channels/IssueTemplateService.cs | 18 ++++++++++++------ .../Channels/IssueTemplateRepository.cs | 17 ++++++++++++++--- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Oms.Application/Services/Channels/IssueTemplateService.cs b/src/Oms.Application/Services/Channels/IssueTemplateService.cs index 4cb2ed6..c59ccce 100644 --- a/src/Oms.Application/Services/Channels/IssueTemplateService.cs +++ b/src/Oms.Application/Services/Channels/IssueTemplateService.cs @@ -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)); diff --git a/src/Oms.SqlSugarCore/Channels/IssueTemplateRepository.cs b/src/Oms.SqlSugarCore/Channels/IssueTemplateRepository.cs index 2dfdd46..11a3daa 100644 --- a/src/Oms.SqlSugarCore/Channels/IssueTemplateRepository.cs +++ b/src/Oms.SqlSugarCore/Channels/IssueTemplateRepository.cs @@ -15,13 +15,24 @@ public class IssueTemplateRepository : OmsSqlSugarRepository, 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); } }