Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-06-04 17:43:21 +03:00
parent 6aea7f4012
commit fea4938a9d
4 changed files with 268 additions and 26 deletions

View File

@@ -31,6 +31,23 @@ type pricingParameterRow struct {
BrandGroupSec string
}
func PricingParameterRowForImport(
askiliYan, kategori, urunIlkGrubu, urunAnaGrubu, urunAltGrubu,
icerik, marka, brandCode, brandGroupSec string,
) pricingParameterRow {
return pricingParameterRow{
AskiliYan: askiliYan,
Kategori: kategori,
UrunIlkGrubu: urunIlkGrubu,
UrunAnaGrubu: urunAnaGrubu,
UrunAltGrubu: urunAltGrubu,
Icerik: icerik,
Marka: marka,
BrandCode: brandCode,
BrandGroupSec: brandGroupSec,
}
}
type PricingParameterRuleRow struct {
PricingParameterID int64 `json:"pricing_parameter_id"`
ScopeKey string `json:"scope_key"`
@@ -238,6 +255,77 @@ func pricingParameterScopeValue(value string) []string {
return []string{value}
}
func EnsureActivePricingParameterByScope(ctx context.Context, tx *sql.Tx, row pricingParameterRow) (int64, bool, 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 existingID int64
var isActive bool
err := tx.QueryRowContext(ctx, `
SELECT id, is_active
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
ORDER BY is_active DESC, 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(&existingID, &isActive)
if err == nil {
if isActive {
return existingID, false, nil
}
} else if err != sql.ErrNoRows {
return 0, false, err
}
var newID int64
if err := tx.QueryRowContext(ctx, `
INSERT INTO mk_urunpricingprmtr (
askili_yan, kategori, urun_ilk_grubu, urun_ana_grubu, urun_alt_grubu,
icerik, marka, brand_code, brand_group_sec,
is_active, first_seen_at, last_seen_at
)
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,TRUE,now(),now())
RETURNING id
`,
row.AskiliYan,
row.Kategori,
row.UrunIlkGrubu,
row.UrunAnaGrubu,
row.UrunAltGrubu,
row.Icerik,
row.Marka,
row.BrandCode,
row.BrandGroupSec,
).Scan(&newID); err != nil {
return 0, false, err
}
return newID, true, nil
}
func SyncPricingParametersFromMSSQL(ctx context.Context, mssql *sql.DB, pg *sql.DB) (PricingParameterSyncResult, error) {
out := PricingParameterSyncResult{}
startedAt := time.Now()