Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -672,6 +672,20 @@ func cleanProductPricingFilterValues(values []string) []string {
|
||||
return clean
|
||||
}
|
||||
|
||||
func isProductCodeOnlyPricingFilter(filters ProductPricingFilters) bool {
|
||||
return len(cleanProductPricingFilterValues(filters.ProductCode)) > 0 &&
|
||||
strings.TrimSpace(filters.Search) == "" &&
|
||||
len(cleanProductPricingFilterValues(filters.BrandGroup)) == 0 &&
|
||||
len(cleanProductPricingFilterValues(filters.AskiliYan)) == 0 &&
|
||||
len(cleanProductPricingFilterValues(filters.Kategori)) == 0 &&
|
||||
len(cleanProductPricingFilterValues(filters.UrunIlkGrubu)) == 0 &&
|
||||
len(cleanProductPricingFilterValues(filters.UrunAnaGrubu)) == 0 &&
|
||||
len(cleanProductPricingFilterValues(filters.UrunAltGrubu)) == 0 &&
|
||||
len(cleanProductPricingFilterValues(filters.Icerik)) == 0 &&
|
||||
len(cleanProductPricingFilterValues(filters.Karisim)) == 0 &&
|
||||
len(cleanProductPricingFilterValues(filters.Marka)) == 0
|
||||
}
|
||||
|
||||
func GetProductPricingPage(ctx context.Context, page int, limit int, filters ProductPricingFilters, includeTotal bool, sortBy string, descending bool) (ProductPricingPage, error) {
|
||||
result := ProductPricingPage{
|
||||
Rows: []models.ProductPricing{},
|
||||
@@ -751,8 +765,28 @@ func GetProductPricingPage(ctx context.Context, page int, limit int, filters Pro
|
||||
}, " OR ")+")")
|
||||
}
|
||||
whereSQL := strings.Join(whereParts, " AND ")
|
||||
cleanProductCodes := cleanProductPricingFilterValues(filters.ProductCode)
|
||||
productCodeOnlyFilter := isProductCodeOnlyPricingFilter(filters)
|
||||
|
||||
if includeTotal {
|
||||
if includeTotal && productCodeOnlyFilter {
|
||||
result.TotalCount = len(cleanProductCodes)
|
||||
if result.TotalCount == 0 {
|
||||
result.TotalPages = 0
|
||||
result.Page = 1
|
||||
return result, nil
|
||||
}
|
||||
totalPages := int(math.Ceil(float64(result.TotalCount) / float64(limit)))
|
||||
if totalPages <= 0 {
|
||||
totalPages = 1
|
||||
}
|
||||
if page > totalPages {
|
||||
page = totalPages
|
||||
offset = (page - 1) * limit
|
||||
}
|
||||
result.Page = page
|
||||
result.Limit = limit
|
||||
result.TotalPages = totalPages
|
||||
} else if includeTotal {
|
||||
countQuery := `
|
||||
SELECT COUNT(DISTINCT LTRIM(RTRIM(ProductCode)))
|
||||
FROM ProductFilterWithDescription('TR')
|
||||
@@ -789,7 +823,7 @@ func GetProductPricingPage(ctx context.Context, page int, limit int, filters Pro
|
||||
|
||||
// Stage 1: fetch only paged products first. Exact product-code filters do not
|
||||
// need the stock sort temp table here; detailed metrics are fetched below.
|
||||
productCodeFastPath := len(cleanProductPricingFilterValues(filters.ProductCode)) > 0
|
||||
productCodeFastPath := len(cleanProductCodes) > 0
|
||||
sortBy = strings.TrimSpace(sortBy)
|
||||
orderDir := "DESC"
|
||||
if !descending {
|
||||
@@ -876,7 +910,72 @@ func GetProductPricingPage(ctx context.Context, page int, limit int, filters Pro
|
||||
OFFSET ` + strconv.Itoa(offset) + ` ROWS
|
||||
FETCH NEXT ` + strconv.Itoa(limit) + ` ROWS ONLY;
|
||||
`
|
||||
if productCodeFastPath {
|
||||
if productCodeOnlyFilter {
|
||||
valueRows := make([]string, 0, len(cleanProductCodes))
|
||||
directArgs := make([]any, 0, len(cleanProductCodes))
|
||||
for i, code := range cleanProductCodes {
|
||||
paramName := "@p" + strconv.Itoa(i+1)
|
||||
valueRows = append(valueRows, "("+paramName+")")
|
||||
directArgs = append(directArgs, code)
|
||||
}
|
||||
args = directArgs
|
||||
productQuery = `
|
||||
WITH req_codes AS (
|
||||
SELECT DISTINCT LTRIM(RTRIM(v.ProductCode)) AS ProductCode
|
||||
FROM (VALUES ` + strings.Join(valueRows, ",") + `) v(ProductCode)
|
||||
WHERE LEN(LTRIM(RTRIM(v.ProductCode))) > 0
|
||||
),
|
||||
attr AS (
|
||||
SELECT
|
||||
LTRIM(RTRIM(a.ItemCode)) AS ProductCode,
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 45 THEN COALESCE(NULLIF(LTRIM(RTRIM(d.AttributeDescription)), ''), LTRIM(RTRIM(a.AttributeCode))) ELSE '' END) AS AskiliYan,
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 44 THEN COALESCE(NULLIF(LTRIM(RTRIM(d.AttributeDescription)), ''), LTRIM(RTRIM(a.AttributeCode))) ELSE '' END) AS Kategori,
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 42 THEN LTRIM(RTRIM(a.AttributeCode)) ELSE '' END) AS UrunIlkGrubuCode,
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 42 THEN COALESCE(NULLIF(LTRIM(RTRIM(d.AttributeDescription)), ''), LTRIM(RTRIM(a.AttributeCode))) ELSE '' END) AS UrunIlkGrubu,
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 1 THEN COALESCE(NULLIF(LTRIM(RTRIM(d.AttributeDescription)), ''), LTRIM(RTRIM(a.AttributeCode))) ELSE '' END) AS UrunAnaGrubu,
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 2 THEN COALESCE(NULLIF(LTRIM(RTRIM(d.AttributeDescription)), ''), LTRIM(RTRIM(a.AttributeCode))) ELSE '' END) AS UrunAltGrubu,
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 41 THEN COALESCE(NULLIF(LTRIM(RTRIM(d.AttributeDescription)), ''), LTRIM(RTRIM(a.AttributeCode))) ELSE '' END) AS Icerik,
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 29 THEN COALESCE(NULLIF(LTRIM(RTRIM(d.AttributeDescription)), ''), LTRIM(RTRIM(a.AttributeCode))) ELSE '' END) AS Karisim,
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 10 THEN COALESCE(NULLIF(LTRIM(RTRIM(d.AttributeDescription)), ''), LTRIM(RTRIM(a.AttributeCode))) ELSE '' END) AS Marka,
|
||||
MAX(CASE WHEN a.AttributeTypeCode = 10 THEN LTRIM(RTRIM(a.AttributeCode)) ELSE '' END) AS BrandCode
|
||||
FROM dbo.prItemAttribute a WITH(NOLOCK)
|
||||
INNER JOIN req_codes rc
|
||||
ON rc.ProductCode = LTRIM(RTRIM(a.ItemCode))
|
||||
LEFT JOIN dbo.cdItemAttributeDesc d WITH(NOLOCK)
|
||||
ON d.ItemTypeCode = a.ItemTypeCode
|
||||
AND d.AttributeTypeCode = a.AttributeTypeCode
|
||||
AND d.AttributeCode = a.AttributeCode
|
||||
AND d.LangCode = 'TR'
|
||||
WHERE a.ItemTypeCode = 1
|
||||
AND a.AttributeTypeCode IN (1,2,10,29,41,42,44,45)
|
||||
GROUP BY LTRIM(RTRIM(a.ItemCode))
|
||||
)
|
||||
SELECT
|
||||
rc.ProductCode,
|
||||
CAST('' AS NVARCHAR(100)) AS BrandGroupSec,
|
||||
COALESCE(attr.AskiliYan, '') AS AskiliYan,
|
||||
COALESCE(attr.Kategori, '') AS Kategori,
|
||||
COALESCE(attr.UrunIlkGrubu, '') AS UrunIlkGrubu,
|
||||
COALESCE(attr.UrunAnaGrubu, '') AS UrunAnaGrubu,
|
||||
COALESCE(attr.UrunAltGrubu, '') AS UrunAltGrubu,
|
||||
COALESCE(attr.Icerik, '') AS Icerik,
|
||||
COALESCE(attr.Karisim, '') AS Karisim,
|
||||
COALESCE(attr.Marka, '') AS Marka,
|
||||
COALESCE(attr.BrandCode, '') AS BrandCode
|
||||
FROM req_codes rc
|
||||
INNER JOIN dbo.cdItem ci WITH(NOLOCK)
|
||||
ON ci.ItemTypeCode = 1
|
||||
AND LTRIM(RTRIM(ci.ItemCode)) = rc.ProductCode
|
||||
LEFT JOIN attr
|
||||
ON attr.ProductCode = rc.ProductCode
|
||||
WHERE ISNULL(ci.IsBlocked, 0) = 0
|
||||
AND LEN(LTRIM(RTRIM(ci.ItemCode))) = 13
|
||||
AND COALESCE(attr.UrunIlkGrubuCode, '') IN ('SERI', 'AKSESUAR')
|
||||
ORDER BY rc.ProductCode ASC
|
||||
OFFSET ` + strconv.Itoa(offset) + ` ROWS
|
||||
FETCH NEXT ` + strconv.Itoa(limit) + ` ROWS ONLY;
|
||||
`
|
||||
} else if productCodeFastPath {
|
||||
productQuery = `
|
||||
IF OBJECT_ID('tempdb..#req_codes') IS NOT NULL DROP TABLE #req_codes;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user