修复店铺列表 ExpirationFilter 嵌套三元导致 SqlSugar IIF 翻译失败。

按 expired/within7days/normal 分支构造独立 predicate,与充值等模块写法对齐。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zzh 2026-07-11 17:10:31 +08:00
parent fb61fbb072
commit c2d7b5c854

View File

@ -170,20 +170,37 @@ public class PlatformStoreService : ApplicationService
var platformCode = input.PlatformCode?.Trim(); var platformCode = input.PlatformCode?.Trim();
var nickname = input.StoreNickname?.Trim(); var nickname = input.StoreNickname?.Trim();
var filter = input.ExpirationFilter?.Trim().ToLowerInvariant(); var filter = input.ExpirationFilter?.Trim().ToLowerInvariant();
var hasPlatformCode = !string.IsNullOrWhiteSpace(platformCode);
var hasNickname = !string.IsNullOrWhiteSpace(nickname);
var now = DateTime.Now; var now = DateTime.Now;
var within7Days = now.AddDays(7); var within7Days = now.AddDays(7);
return x => // 显式按过期筛选分支构造表达式,避免嵌套三元被 ORM 翻译成非法 IIF。
return filter switch
{
"expired" => x =>
(!hasCustomerFilter || x.CustomerId == customerIdValue) (!hasCustomerFilter || x.CustomerId == customerIdValue)
&& (string.IsNullOrWhiteSpace(platformCode) || x.PlatformCode == platformCode) && (!hasPlatformCode || x.PlatformCode == platformCode)
&& (string.IsNullOrWhiteSpace(nickname) || x.StoreNickname.Contains(nickname)) && (!hasNickname || x.StoreNickname.Contains(nickname!))
&& (string.IsNullOrWhiteSpace(filter) || filter == "normal" && x.TokenExpireTime.HasValue
? string.IsNullOrWhiteSpace(filter) || !x.TokenExpireTime.HasValue || x.TokenExpireTime > within7Days && x.TokenExpireTime < now,
: filter == "expired" "within7days" => x =>
? x.TokenExpireTime.HasValue && x.TokenExpireTime < now (!hasCustomerFilter || x.CustomerId == customerIdValue)
: filter == "within7days" && (!hasPlatformCode || x.PlatformCode == platformCode)
? x.TokenExpireTime.HasValue && x.TokenExpireTime >= now && x.TokenExpireTime <= within7Days && (!hasNickname || x.StoreNickname.Contains(nickname!))
: true); && x.TokenExpireTime.HasValue
&& x.TokenExpireTime >= now
&& x.TokenExpireTime <= within7Days,
"normal" => x =>
(!hasCustomerFilter || x.CustomerId == customerIdValue)
&& (!hasPlatformCode || x.PlatformCode == platformCode)
&& (!hasNickname || x.StoreNickname.Contains(nickname!))
&& (!x.TokenExpireTime.HasValue || x.TokenExpireTime > within7Days),
_ => x =>
(!hasCustomerFilter || x.CustomerId == customerIdValue)
&& (!hasPlatformCode || x.PlatformCode == platformCode)
&& (!hasNickname || x.StoreNickname.Contains(nickname!))
};
} }
private static PlatformStoreOutput MapOutput(SalesStore entity) => private static PlatformStoreOutput MapOutput(SalesStore entity) =>