This commit is contained in:
Mrx
2026-05-27 12:11:26 +08:00
parent 2a33369639
commit b7fb2a73c9
3 changed files with 144 additions and 0 deletions

View File

@@ -149,6 +149,28 @@ func (r *GormApiCallRepository) ListByUserIdWithFiltersAndProductName(ctx contex
// 应用筛选条件
if filters != nil {
// 产品ID筛选支持多个
if productIds, ok := filters["product_ids"].(string); ok && productIds != "" {
// 多个产品ID逗号分隔
productIdsList := strings.Split(productIds, ",")
// 去除空白字符
var cleanProductIds []string
for _, id := range productIdsList {
id = strings.TrimSpace(id)
if id != "" {
cleanProductIds = append(cleanProductIds, id)
}
}
if len(cleanProductIds) > 0 {
placeholders := strings.Repeat("?,", len(cleanProductIds))
placeholders = placeholders[:len(placeholders)-1] // 移除最后一个逗号
whereCondition += " AND ac.product_id IN (" + placeholders + ")"
for _, id := range cleanProductIds {
whereArgs = append(whereArgs, id)
}
}
}
// 时间范围筛选
if startTime, ok := filters["start_time"].(time.Time); ok {
whereCondition += " AND ac.created_at >= ?"
@@ -337,6 +359,28 @@ func (r *GormApiCallRepository) ListWithFiltersAndProductName(ctx context.Contex
whereArgs = append(whereArgs, userId)
}
// 产品ID筛选支持多个
if productIds, ok := filters["product_ids"].(string); ok && productIds != "" {
// 多个产品ID逗号分隔
productIdsList := strings.Split(productIds, ",")
// 去除空白字符
var cleanProductIds []string
for _, id := range productIdsList {
id = strings.TrimSpace(id)
if id != "" {
cleanProductIds = append(cleanProductIds, id)
}
}
if len(cleanProductIds) > 0 {
placeholders := strings.Repeat("?,", len(cleanProductIds))
placeholders = placeholders[:len(placeholders)-1] // 移除最后一个逗号
whereCondition += " AND ac.product_id IN (" + placeholders + ")"
for _, id := range cleanProductIds {
whereArgs = append(whereArgs, id)
}
}
}
// 时间范围筛选
if startTime, ok := filters["start_time"].(time.Time); ok {
whereCondition += " AND ac.created_at >= ?"