Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -433,6 +433,16 @@ func buildNebimVariantDisplayCode(colorCode string, dim3Code string) string {
|
||||
return dim3Code
|
||||
}
|
||||
|
||||
func chooseDisplayDimToken(raw string, resolvedID int64, reverse map[int64]string) string {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if resolvedID > 0 {
|
||||
if tok := strings.TrimSpace(reverse[resolvedID]); tok != "" {
|
||||
return tok
|
||||
}
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
||||
type wholesaleCampaignHistoryRow struct {
|
||||
ID int64 `json:"id"`
|
||||
CampaignID *int64 `json:"campaign_id"`
|
||||
@@ -874,6 +884,33 @@ ORDER BY dim_id, updated_at DESC;
|
||||
}
|
||||
tmpMap[k] = v
|
||||
}
|
||||
canonicalToken := func(id int64) string {
|
||||
if id <= 0 {
|
||||
return ""
|
||||
}
|
||||
if tok := strings.TrimSpace(idToToken[id]); tok != "" {
|
||||
return tok
|
||||
}
|
||||
var tok string
|
||||
if err := pg.QueryRowContext(ctx, `
|
||||
SELECT token
|
||||
FROM mk_dim_token_map
|
||||
WHERE dim_column = 'dimval1'
|
||||
AND dim_id = $1
|
||||
ORDER BY
|
||||
CASE WHEN token ~ '^[0-9]{3}$' THEN 0 ELSE 1 END,
|
||||
length(token),
|
||||
updated_at DESC
|
||||
LIMIT 1
|
||||
`, id).Scan(&tok); err == nil {
|
||||
tok = strings.TrimSpace(tok)
|
||||
if tok != "" {
|
||||
idToToken[id] = tok
|
||||
return tok
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// MSSQL: stock list for selected products; map to (mmitem_id, dim1, dim3_key) via token->id mapping.
|
||||
joined := strings.Join(codes, ",")
|
||||
@@ -974,7 +1011,9 @@ WHERE NOT EXISTS (
|
||||
q = qty.Float64
|
||||
}
|
||||
prev.StockQty += q
|
||||
prev.VariantCode = buildNebimVariantDisplayCode(colorCode, dim3Code)
|
||||
displayColor := chooseDisplayDimToken(colorCode, d1, map[int64]string{d1: canonicalToken(d1)})
|
||||
displayDim3 := chooseDisplayDimToken(dim3Code, d3k, map[int64]string{d3k: canonicalToken(d3k)})
|
||||
prev.VariantCode = buildNebimVariantDisplayCode(displayColor, displayDim3)
|
||||
prev.HasMSSQL = true
|
||||
tmpMap[key] = prev
|
||||
_ = colorCode // display-only
|
||||
|
||||
Reference in New Issue
Block a user