Fix product performance grouped JSON build
This commit is contained in:
@@ -3239,16 +3239,16 @@ SELECT (
|
||||
'image_product_code', image_product_code,
|
||||
'image_color_code', image_color_code,
|
||||
'image_yaka_kodu', image_yaka_kodu,
|
||||
'product_code', CASE WHEN $%d = 'product_code' THEN group_value ELSE product_code END,
|
||||
'color_code', CASE WHEN $%d = 'color_code' THEN group_value ELSE color_code END,
|
||||
'yaka_kodu', CASE WHEN $%d = 'yaka_kodu' THEN group_value ELSE yaka_kodu END,
|
||||
'item_description', item_description,
|
||||
'kategori', CASE WHEN $%d = 'kategori' THEN group_value ELSE kategori END,
|
||||
'askili_yan', CASE WHEN $%d = 'askili_yan' THEN group_value ELSE askili_yan END,
|
||||
'urun_ilk_grubu', CASE WHEN $%d = 'urun_ilk_grubu' THEN group_value ELSE urun_ilk_grubu END,
|
||||
'urun_ana_grubu', CASE WHEN $%d = 'urun_ana_grubu' THEN group_value ELSE urun_ana_grubu END,
|
||||
'urun_alt_grubu', CASE WHEN $%d = 'urun_alt_grubu' THEN group_value ELSE urun_alt_grubu END,
|
||||
'market_key', CASE WHEN $%d = 'market_key' THEN group_value ELSE market_key END
|
||||
'product_code', CASE WHEN $%d = 'product_code' THEN group_value ELSE '' END,
|
||||
'color_code', CASE WHEN $%d = 'color_code' THEN group_value ELSE '' END,
|
||||
'yaka_kodu', CASE WHEN $%d = 'yaka_kodu' THEN group_value ELSE '' END,
|
||||
'item_description', CASE WHEN $%d = 'item_description' THEN group_value ELSE '' END,
|
||||
'kategori', CASE WHEN $%d = 'kategori' THEN group_value ELSE '' END,
|
||||
'askili_yan', CASE WHEN $%d = 'askili_yan' THEN group_value ELSE '' END,
|
||||
'urun_ilk_grubu', CASE WHEN $%d = 'urun_ilk_grubu' THEN group_value ELSE '' END,
|
||||
'urun_ana_grubu', CASE WHEN $%d = 'urun_ana_grubu' THEN group_value ELSE '' END,
|
||||
'urun_alt_grubu', CASE WHEN $%d = 'urun_alt_grubu' THEN group_value ELSE '' END,
|
||||
'market_key', CASE WHEN $%d = 'market_key' THEN group_value ELSE '' END
|
||||
)
|
||||
|| jsonb_build_object(
|
||||
'stock_qty', stock_qty,
|
||||
@@ -3377,7 +3377,7 @@ FROM (
|
||||
GROUP BY COALESCE(%s, '')
|
||||
) g
|
||||
ORDER BY group_value
|
||||
`, len(args)+1, len(args)+1, len(args)+1, len(args)+1, len(args)+1, len(args)+1, len(args)+1, len(args)+1, len(args)+1, groupExpr, groupExpr, whereSQL, groupExpr)
|
||||
`, len(args)+1, len(args)+1, len(args)+1, len(args)+1, len(args)+1, len(args)+1, len(args)+1, len(args)+1, len(args)+1, len(args)+1, groupExpr, groupExpr, whereSQL, groupExpr)
|
||||
args = append(args, field)
|
||||
return queryProductPerformanceJSONRows(ctx, pg, query, args...)
|
||||
}
|
||||
@@ -3678,6 +3678,7 @@ func appendProductPerformanceGroupedRows(out *[]map[string]any, sourceRows []map
|
||||
|
||||
func makeProductPerformanceGroupedRow(key string, level int, field, value string, rows []map[string]any) map[string]any {
|
||||
row := aggregateProductPerformanceRows(rows, field)
|
||||
clearProductPerformanceGroupDimensions(row, field, value)
|
||||
row["__group"] = true
|
||||
row["row_key"] = "group|" + key
|
||||
row["key"] = key
|
||||
@@ -3686,7 +3687,6 @@ func makeProductPerformanceGroupedRow(key string, level int, field, value string
|
||||
row["group_value"] = value
|
||||
row["label"] = value
|
||||
row["count"] = len(rows)
|
||||
row[field] = value
|
||||
row["recommendation"] = fmt.Sprintf("%d satır", len(rows))
|
||||
|
||||
image := firstProductPerformanceImageSource(rows)
|
||||
@@ -3696,6 +3696,33 @@ func makeProductPerformanceGroupedRow(key string, level int, field, value string
|
||||
return row
|
||||
}
|
||||
|
||||
var productPerformanceGroupDimensionFields = map[string]bool{
|
||||
"product_code": true,
|
||||
"color_yaka": true,
|
||||
"color_code": true,
|
||||
"yaka_kodu": true,
|
||||
"item_description": true,
|
||||
"kategori": true,
|
||||
"askili_yan": true,
|
||||
"urun_ilk_grubu": true,
|
||||
"urun_ana_grubu": true,
|
||||
"urun_alt_grubu": true,
|
||||
"market_key": true,
|
||||
"country": true,
|
||||
"customer_segment": true,
|
||||
"customer_code": true,
|
||||
"customer_name": true,
|
||||
}
|
||||
|
||||
func clearProductPerformanceGroupDimensions(row map[string]any, groupField, groupValue string) {
|
||||
for field := range productPerformanceGroupDimensionFields {
|
||||
row[field] = ""
|
||||
}
|
||||
if productPerformanceGroupDimensionFields[groupField] {
|
||||
row[groupField] = groupValue
|
||||
}
|
||||
}
|
||||
|
||||
func aggregateProductPerformanceRows(rows []map[string]any, groupField string) map[string]any {
|
||||
out := map[string]any{}
|
||||
for _, row := range rows {
|
||||
|
||||
Reference in New Issue
Block a user