- improve jxutils.SplitStoreName

This commit is contained in:
gazebo
2019-03-18 15:04:42 +08:00
parent a4d8fd6230
commit 1e53e4edae
7 changed files with 67 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"math"
"reflect"
"regexp"
"strings"
"time"
@@ -11,6 +12,10 @@ import (
"git.rosy.net.cn/jx-callback/business/model"
)
var (
storeNamePat = regexp.MustCompile(`([^(\[(【)\])】\-\s]*)[(\[(【\-\s]+([^(\[(【)\])】\-]*)[)\])】]*`)
)
// 合并得到最终的门店状态
func MergeStoreStatus(status int, vendorStatus int) int {
if status < vendorStatus {
@@ -58,15 +63,26 @@ func SplitStoreName(fullName, separator, defaultPrefix string) (prefix, bareName
prefix = names[0]
bareName = names[1]
} else {
prefix = defaultPrefix
bareName = strings.Trim(strings.Trim(fullName, defaultPrefix), separator)
searchResult := storeNamePat.FindStringSubmatch(fullName)
if searchResult != nil {
prefix = searchResult[1]
bareName = strings.Trim(strings.Trim(searchResult[2], defaultPrefix), separator)
} else {
prefix = defaultPrefix
bareName = strings.Trim(strings.Trim(fullName, defaultPrefix), separator)
}
}
return TrimDecorationChar(defaultPrefix), TrimDecorationChar(bareName)
return TrimDecorationChar(prefix), TrimDecorationChar(bareName)
}
func ComposeStoreName(bareName, separator, prefix string) (fullName string) {
return prefix + separator + TrimDecorationChar(strings.Trim(bareName, separator))
func ComposeStoreName(bareName string, vendorID int) (fullName string) {
bareName = TrimDecorationChar(strings.Trim(bareName, "-"))
if vendorID == model.VendorIDJD {
fullName = "京西菜市-" + bareName
} else {
fullName = "京西菜市(" + bareName + ")"
}
return fullName
}
func StrTime2JxOperationTime(strTime string, defValue int16) int16 {