Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -5,17 +5,22 @@ import (
|
||||
"bssapp-backend/models"
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetProductPricingList(ctx context.Context, limit int, offset int) ([]models.ProductPricing, error) {
|
||||
func GetProductPricingList(ctx context.Context, limit int, afterProductCode string) ([]models.ProductPricing, error) {
|
||||
if limit <= 0 {
|
||||
limit = 500
|
||||
}
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
afterProductCode = strings.TrimSpace(afterProductCode)
|
||||
|
||||
cursorFilter := ""
|
||||
args := make([]any, 0, 1)
|
||||
if afterProductCode != "" {
|
||||
cursorFilter = "WHERE bp.ProductCode > @p1"
|
||||
args = append(args, afterProductCode)
|
||||
}
|
||||
|
||||
query := `
|
||||
@@ -36,11 +41,11 @@ func GetProductPricingList(ctx context.Context, limit int, offset int) ([]models
|
||||
AND LEN(LTRIM(RTRIM(ProductCode))) = 13
|
||||
),
|
||||
paged_products AS (
|
||||
SELECT
|
||||
SELECT TOP (` + strconv.Itoa(limit) + `)
|
||||
bp.ProductCode
|
||||
FROM base_products bp
|
||||
` + cursorFilter + `
|
||||
ORDER BY bp.ProductCode
|
||||
OFFSET %d ROWS FETCH NEXT %d ROWS ONLY
|
||||
),
|
||||
latest_base_price AS (
|
||||
SELECT
|
||||
@@ -182,7 +187,6 @@ func GetProductPricingList(ctx context.Context, limit int, offset int) ([]models
|
||||
ON st.ItemCode = bp.ProductCode
|
||||
ORDER BY bp.ProductCode;
|
||||
`
|
||||
query = fmt.Sprintf(query, offset, limit)
|
||||
|
||||
var (
|
||||
rows *sql.Rows
|
||||
@@ -190,7 +194,7 @@ func GetProductPricingList(ctx context.Context, limit int, offset int) ([]models
|
||||
)
|
||||
for attempt := 1; attempt <= 3; attempt++ {
|
||||
var err error
|
||||
rows, err = db.MssqlDB.QueryContext(ctx, query)
|
||||
rows, err = db.MssqlDB.QueryContext(ctx, query, args...)
|
||||
if err == nil {
|
||||
rowsErr = nil
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user