filter less than 3 dimensions
This commit is contained in:
@ -14,12 +14,16 @@ type dimensionDispatcher struct {
|
||||
m *dimension.Matcher
|
||||
}
|
||||
|
||||
func (d dimensionDispatcher) isDimensionParam(value string) bool {
|
||||
return d.m.Match(value) != dimension.MatchResultMiss
|
||||
func pickFirst[T, V any](t T, v V) T {
|
||||
return t
|
||||
}
|
||||
|
||||
func (d dimensionDispatcher) dispatch(ctx context.Context, key, value string, in *entity.GoodsItemSize) (updated bool) {
|
||||
matchResult := d.m.Match(key)
|
||||
func (d dimensionDispatcher) isDimensionParam(value string) bool {
|
||||
return pickFirst(d.m.Match(value)) != dimension.MatchResultMiss
|
||||
}
|
||||
|
||||
func (d dimensionDispatcher) applyDimensionValue(ctx context.Context, key, value string, in *entity.GoodsItemSize) (updated bool) {
|
||||
matchResult, priority := d.m.Match(key)
|
||||
if matchResult == dimension.MatchResultMiss {
|
||||
return false
|
||||
}
|
||||
@ -29,7 +33,7 @@ func (d dimensionDispatcher) dispatch(ctx context.Context, key, value string, in
|
||||
if strings.Contains(value, "/") {
|
||||
dimensionValues := strings.Split(value, "/")
|
||||
for _, dv := range dimensionValues {
|
||||
updated = updated || d.dispatch(ctx, key, dv, in)
|
||||
updated = updated || d.applyDimensionValue(ctx, key, dv, in)
|
||||
}
|
||||
} else {
|
||||
out, err := entity.ParseDimention(value, entity.DimensionLocalRU)
|
||||
@ -42,10 +46,22 @@ func (d dimensionDispatcher) dispatch(ctx context.Context, key, value string, in
|
||||
|
||||
switch matchResult {
|
||||
case dimension.MatchResultHeight:
|
||||
if !priority && in.Height.Value != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
in.Height = out
|
||||
case dimension.MatchResultLength:
|
||||
if !priority && in.Length.Value != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
in.Length = out
|
||||
case dimension.MatchResultWidth:
|
||||
if !priority && in.Width.Value != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
in.Width = out
|
||||
case dimension.MatchResultDepth:
|
||||
in.UnmatchedDepth = out
|
||||
|
||||
Reference in New Issue
Block a user