feat(卡列表): 新增 has_active_package 查询条件筛选生效中套餐
- DTO ListStandaloneIotCardRequest 增加 HasActivePackage *bool 字段, query/json 名 has_active_package,description 中文 - Service ListStandalone 将 HasActivePackage 映射为 filters["has_active_package"] - Store applyStandaloneFilters 新增 EXISTS/NOT EXISTS 子查询, 使用 constants.PackageUsageStatusActive,限制 master_usage_id IS NULL 且 deleted_at IS NULL,所有查询路径(默认/两阶段/并行)均复用此函数 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -895,6 +895,16 @@ func (s *IotCardStore) applyStandaloneFilters(ctx context.Context, query *gorm.D
|
||||
if carrierName, ok := filters["carrier_name"].(string); ok && carrierName != "" {
|
||||
query = query.Where("carrier_name LIKE ?", "%"+carrierName+"%")
|
||||
}
|
||||
// has_active_package 过滤:是否存在生效中的主套餐记录
|
||||
if hasActivePackage, ok := filters["has_active_package"].(bool); ok {
|
||||
subQuery := s.db.WithContext(ctx).Table("tb_package_usage pu").Select("1").
|
||||
Where("pu.iot_card_id = tb_iot_card.id AND pu.status = ? AND pu.master_usage_id IS NULL AND pu.deleted_at IS NULL", constants.PackageUsageStatusActive)
|
||||
if hasActivePackage {
|
||||
query = query.Where("EXISTS (?)", subQuery)
|
||||
} else {
|
||||
query = query.Where("NOT EXISTS (?)", subQuery)
|
||||
}
|
||||
}
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user