From 5b8880693ee8f58479184a1739b7a3e2afabb439 Mon Sep 17 00:00:00 2001 From: M_Kececi Date: Thu, 4 Jun 2026 18:08:18 +0300 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- svc/queries/pricing_parameters.go | 44 +++++++++++++++++++++++++++++++ svc/routes/pricing_rules.go | 29 +++++++++++++++----- ui/src/pages/PricingRules.vue | 32 +++++++++++++++++----- 3 files changed, 92 insertions(+), 13 deletions(-) diff --git a/svc/queries/pricing_parameters.go b/svc/queries/pricing_parameters.go index 0f50083..1057b17 100644 --- a/svc/queries/pricing_parameters.go +++ b/svc/queries/pricing_parameters.go @@ -326,6 +326,50 @@ RETURNING id return newID, true, nil } +func FindActivePricingParameterByScope(ctx context.Context, tx *sql.Tx, row pricingParameterRow) (int64, error) { + row.AskiliYan = strings.TrimSpace(row.AskiliYan) + row.Kategori = strings.TrimSpace(row.Kategori) + row.UrunIlkGrubu = strings.TrimSpace(row.UrunIlkGrubu) + row.UrunAnaGrubu = strings.TrimSpace(row.UrunAnaGrubu) + row.UrunAltGrubu = strings.TrimSpace(row.UrunAltGrubu) + row.Icerik = strings.TrimSpace(row.Icerik) + row.Marka = strings.TrimSpace(row.Marka) + row.BrandCode = strings.TrimSpace(row.BrandCode) + row.BrandGroupSec = strings.TrimSpace(row.BrandGroupSec) + + var id int64 + err := tx.QueryRowContext(ctx, ` +SELECT id +FROM mk_urunpricingprmtr +WHERE askili_yan=$1 + AND kategori=$2 + AND urun_ilk_grubu=$3 + AND urun_ana_grubu=$4 + AND urun_alt_grubu=$5 + AND icerik=$6 + AND marka=$7 + AND brand_code=$8 + AND brand_group_sec=$9 + AND is_active=TRUE +ORDER BY last_seen_at DESC, id DESC +LIMIT 1 +`, + row.AskiliYan, + row.Kategori, + row.UrunIlkGrubu, + row.UrunAnaGrubu, + row.UrunAltGrubu, + row.Icerik, + row.Marka, + row.BrandCode, + row.BrandGroupSec, + ).Scan(&id) + if err != nil { + return 0, err + } + return id, nil +} + func SyncPricingParametersFromMSSQL(ctx context.Context, mssql *sql.DB, pg *sql.DB) (PricingParameterSyncResult, error) { out := PricingParameterSyncResult{} startedAt := time.Now() diff --git a/svc/routes/pricing_rules.go b/svc/routes/pricing_rules.go index edff335..12f9f05 100644 --- a/svc/routes/pricing_rules.go +++ b/svc/routes/pricing_rules.go @@ -70,6 +70,8 @@ type PricingRuleImportPayload struct { type PricingRuleImportResult struct { Success bool `json:"success"` Processed int `json:"processed"` + Matched int `json:"matched"` + Skipped int `json:"skipped"` Updated int `json:"updated"` ActivatedScopeCount int `json:"activated_scope_count"` ErrorCount int `json:"error_count"` @@ -162,14 +164,15 @@ func ImportPricingRulesHandler(pg *sql.DB) http.HandlerFunc { defer tx.Rollback() updated := 0 - activatedScopeCount := 0 + matched := 0 + skipped := 0 for _, raw := range payload.Items { if raw.TryWholesaleStep < 0 || raw.TryRetailStep < 0 || raw.UsdWholesaleStep < 0 || raw.UsdRetailStep < 0 || raw.EurWholesaleStep < 0 || raw.EurRetailStep < 0 { http.Error(w, "invalid rounding step", http.StatusBadRequest) return } - pricingParameterID, activated, err := queries.EnsureActivePricingParameterByScope(ctx, tx, queries.PricingParameterRowForImport( + pricingParameterID, err := queries.FindActivePricingParameterByScope(ctx, tx, queries.PricingParameterRowForImport( raw.AskiliYan, raw.Kategori, raw.UrunIlkGrubu, @@ -180,13 +183,15 @@ func ImportPricingRulesHandler(pg *sql.DB) http.HandlerFunc { raw.BrandCode, raw.BrandGroupSec, )) + if err == sql.ErrNoRows { + skipped++ + continue + } if err != nil { http.Error(w, "pricing parameter resolve error", http.StatusInternalServerError) return } - if activated { - activatedScopeCount++ - } + matched++ _, err = queries.UpsertPricingRule(ctx, tx, queries.PricingRuleSaveItem{ PricingParameterID: pricingParameterID, @@ -233,8 +238,10 @@ func ImportPricingRulesHandler(pg *sql.DB) http.HandlerFunc { _ = json.NewEncoder(w).Encode(PricingRuleImportResult{ Success: true, Processed: len(payload.Items), + Matched: matched, + Skipped: skipped, Updated: updated, - ActivatedScopeCount: activatedScopeCount, + ActivatedScopeCount: 0, ErrorCount: 0, }) } @@ -545,7 +552,7 @@ func buildPricingRuleCSV(rows []queries.PricingParameterRuleRow) string { row.UrunAltGrubu, row.Icerik, row.Marka, - row.BrandCode, + csvExcelTextValue(row.BrandCode), row.BrandGroupSec, fmt.Sprintf("%.2f", pricingRuleNumericValue(row, "try_wholesale_step")), fmt.Sprintf("%.2f", pricingRuleNumericValue(row, "try_retail_step")), @@ -595,6 +602,14 @@ func csvEscapeValue(value string) string { return text } +func csvExcelTextValue(value string) string { + text := strings.TrimSpace(value) + if text == "" { + return "" + } + return `="` + strings.ReplaceAll(text, `"`, `""`) + `"` +} + func splitCSV(raw string) []string { raw = strings.TrimSpace(raw) if raw == "" { diff --git a/ui/src/pages/PricingRules.vue b/ui/src/pages/PricingRules.vue index 83ff355..1d0bfba 100644 --- a/ui/src/pages/PricingRules.vue +++ b/ui/src/pages/PricingRules.vue @@ -10,7 +10,7 @@ icon="refresh" label="Yenile" :loading="loading" - @click="loadRows" + @click="refreshRows" /> @@ -291,7 +291,7 @@