Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-06-04 18:08:18 +03:00
parent fea4938a9d
commit 5b8880693e
3 changed files with 92 additions and 13 deletions

View File

@@ -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 == "" {