Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"bssapp-backend/auth"
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func BuildMSSQLPiyasaFilter(
|
||||
@@ -27,37 +26,5 @@ func BuildMSSQLPiyasaFilter(
|
||||
|
||||
func BuildMSSQLPiyasaFilterWithCodes(column string, codes []string) string {
|
||||
normalizedCol := fmt.Sprintf("UPPER(LTRIM(RTRIM(%s)))", column)
|
||||
|
||||
exact := BuildINClause(normalizedCol, codes)
|
||||
prefixCodes := first3Codes(codes)
|
||||
if len(prefixCodes) == 0 {
|
||||
return exact
|
||||
}
|
||||
|
||||
prefix := BuildINClause(
|
||||
fmt.Sprintf("LEFT(%s, 3)", normalizedCol),
|
||||
prefixCodes,
|
||||
)
|
||||
|
||||
return fmt.Sprintf("(%s OR %s)", exact, prefix)
|
||||
}
|
||||
|
||||
func first3Codes(codes []string) []string {
|
||||
seen := make(map[string]struct{}, len(codes))
|
||||
out := make([]string, 0, len(codes))
|
||||
|
||||
for _, c := range codes {
|
||||
n := strings.ToUpper(strings.TrimSpace(c))
|
||||
if len(n) < 3 {
|
||||
continue
|
||||
}
|
||||
n = n[:3]
|
||||
if _, ok := seen[n]; ok {
|
||||
continue
|
||||
}
|
||||
seen[n] = struct{}{}
|
||||
out = append(out, n)
|
||||
}
|
||||
|
||||
return out
|
||||
return BuildINClause(normalizedCol, codes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user