查找省份对应ID时,自动尝试省略省、区之类的后缀

This commit is contained in:
刘祥超
2024-03-15 15:08:05 +08:00
parent e90424f80a
commit 7f63dc4565
3 changed files with 62 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/iwind/TeaGo/types"
"io"
"os"
"strings"
"time"
)
@@ -449,6 +450,14 @@ func (this *IPLibraryFileDAO) GenerateIPLibrary(tx *dbs.Tx, libraryFileId int64)
for _, province := range dbProvinces {
for _, code := range province.AllCodes() {
provinceMap[types.String(province.CountryId)+"_"+code] = int64(province.ValueId)
for _, suffix := range regions.RegionProvinceSuffixes {
if strings.HasSuffix(code, suffix) {
provinceMap[types.String(province.CountryId)+"_"+strings.TrimSuffix(code, suffix)] = int64(province.ValueId)
} else {
provinceMap[types.String(province.CountryId)+"_"+(code+suffix)] = int64(province.ValueId)
}
}
}
}