Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-06-18 12:28:05 +03:00
parent e14c1c176a
commit a3d143ad70
14 changed files with 5123 additions and 21 deletions

View File

@@ -548,6 +548,44 @@ func enrichAllProductPricingRows(ctx context.Context, out []models.ProductPricin
}
_ = pgRows.Close()
}
// Last pricing date should reflect the most recent price publish, not the Nebim base price date.
// E-commerce reads pg.sdprc; use its latest write timestamp as the authoritative "last pricing" signal.
dateRows, err := pg.QueryContext(ctx, `
SELECT
mmitem.code AS code,
to_char(MAX(sdprc.zlins_dttm), 'YYYY-MM-DD') AS last_pricing_date
FROM sdprc
JOIN mmitem ON mmitem.id = sdprc.mmitem_id
WHERE mmitem.code = ANY($1)
GROUP BY mmitem.code;
`, pq.Array(chunk))
if err == nil {
for dateRows.Next() {
var code, ymd string
if err := dateRows.Scan(&code, &ymd); err != nil {
_ = dateRows.Close()
return err
}
code = strings.TrimSpace(code)
ymd = strings.TrimSpace(ymd)
if code == "" || len(ymd) != 10 {
continue
}
if idx, ok := indexByCode[code]; ok {
cur := strings.TrimSpace(out[idx].LastPricingDate)
// both are YYYY-MM-DD, lexicographical compare is safe
if cur == "" || cur < ymd {
out[idx].LastPricingDate = ymd
}
}
}
if err := dateRows.Err(); err != nil {
_ = dateRows.Close()
return err
}
_ = dateRows.Close()
}
}
}