Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -94,13 +94,19 @@ func GetProductPricingList(ctx context.Context, limit int, afterProductCode stri
|
|||||||
for _, item := range out {
|
for _, item := range out {
|
||||||
codes = append(codes, strings.TrimSpace(item.ProductCode))
|
codes = append(codes, strings.TrimSpace(item.ProductCode))
|
||||||
}
|
}
|
||||||
codesCSV := strings.Join(codes, ",")
|
valueRows := make([]string, 0, len(codes))
|
||||||
|
metricArgs := make([]any, 0, len(codes))
|
||||||
|
for i, code := range codes {
|
||||||
|
paramName := "@p" + strconv.Itoa(i+1)
|
||||||
|
valueRows = append(valueRows, "("+paramName+")")
|
||||||
|
metricArgs = append(metricArgs, code)
|
||||||
|
}
|
||||||
|
|
||||||
metricsQuery := `
|
metricsQuery := `
|
||||||
WITH req_codes AS (
|
WITH req_codes AS (
|
||||||
SELECT DISTINCT LTRIM(RTRIM(value)) AS ProductCode
|
SELECT DISTINCT LTRIM(RTRIM(v.ProductCode)) AS ProductCode
|
||||||
FROM STRING_SPLIT(@p1, ',')
|
FROM (VALUES ` + strings.Join(valueRows, ",") + `) v(ProductCode)
|
||||||
WHERE LEN(LTRIM(RTRIM(value))) > 0
|
WHERE LEN(LTRIM(RTRIM(v.ProductCode))) > 0
|
||||||
),
|
),
|
||||||
latest_base_price AS (
|
latest_base_price AS (
|
||||||
SELECT
|
SELECT
|
||||||
@@ -206,7 +212,7 @@ func GetProductPricingList(ctx context.Context, limit int, afterProductCode stri
|
|||||||
ON db.ItemCode = rc.ProductCode;
|
ON db.ItemCode = rc.ProductCode;
|
||||||
`
|
`
|
||||||
|
|
||||||
metricsRows, err := db.MssqlDB.QueryContext(ctx, metricsQuery, codesCSV)
|
metricsRows, err := db.MssqlDB.QueryContext(ctx, metricsQuery, metricArgs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("metrics query failed: %w", err)
|
return nil, fmt.Errorf("metrics query failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user