修复店铺列表 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 nickname = input.StoreNickname?.Trim();
var filter = input.ExpirationFilter?.Trim().ToLowerInvariant();
var hasPlatformCode = !string.IsNullOrWhiteSpace(platformCode);
var hasNickname = !string.IsNullOrWhiteSpace(nickname);
var now = DateTime.Now;
var within7Days = now.AddDays(7);
return x =>
(!hasCustomerFilter || x.CustomerId == customerIdValue)
&& (string.IsNullOrWhiteSpace(platformCode) || x.PlatformCode == platformCode)
&& (string.IsNullOrWhiteSpace(nickname) || x.StoreNickname.Contains(nickname))
&& (string.IsNullOrWhiteSpace(filter) || filter == "normal"
? string.IsNullOrWhiteSpace(filter) || !x.TokenExpireTime.HasValue || x.TokenExpireTime > within7Days
: filter == "expired"
? x.TokenExpireTime.HasValue && x.TokenExpireTime < now
: filter == "within7days"
? x.TokenExpireTime.HasValue && x.TokenExpireTime >= now && x.TokenExpireTime <= within7Days
: true);
// 显式按过期筛选分支构造表达式,避免嵌套三元被 ORM 翻译成非法 IIF。
return filter switch
{
"expired" => x =>
(!hasCustomerFilter || x.CustomerId == customerIdValue)
&& (!hasPlatformCode || x.PlatformCode == platformCode)
&& (!hasNickname || x.StoreNickname.Contains(nickname!))
&& x.TokenExpireTime.HasValue
&& x.TokenExpireTime < now,
"within7days" => x =>
(!hasCustomerFilter || x.CustomerId == customerIdValue)
&& (!hasPlatformCode || x.PlatformCode == platformCode)
&& (!hasNickname || x.StoreNickname.Contains(nickname!))
&& 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) =>