mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 23:20:26 +08:00
智能DNS中国家/地区线路下支持省/州的细分
This commit is contained in:
@@ -98,6 +98,14 @@ func (this *RegionCountryDAO) FindRegionCountryName(tx *dbs.Tx, id int64) (strin
|
|||||||
return name, nil
|
return name, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindRegionCountryRouteCode 查找国家|地区线路代号
|
||||||
|
func (this *RegionCountryDAO) FindRegionCountryRouteCode(tx *dbs.Tx, countryId int64) (string, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
Attr("valueId", countryId).
|
||||||
|
Result("routeCode").
|
||||||
|
FindStringCol("")
|
||||||
|
}
|
||||||
|
|
||||||
// FindCountryIdWithDataId 根据数据ID查找国家
|
// FindCountryIdWithDataId 根据数据ID查找国家
|
||||||
func (this *RegionCountryDAO) FindCountryIdWithDataId(tx *dbs.Tx, dataId string) (int64, error) {
|
func (this *RegionCountryDAO) FindCountryIdWithDataId(tx *dbs.Tx, dataId string) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
|
|||||||
@@ -77,6 +77,14 @@ func (this *RegionProvinceDAO) FindRegionProvinceName(tx *dbs.Tx, id int64) (str
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindRegionCountryId 获取省份对应的国家|地区
|
||||||
|
func (this *RegionProvinceDAO) FindRegionCountryId(tx *dbs.Tx, provinceId int64) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
Attr("valueId", provinceId).
|
||||||
|
Result("countryId").
|
||||||
|
FindInt64Col(0)
|
||||||
|
}
|
||||||
|
|
||||||
// FindProvinceIdWithDataId 根据数据ID查找省份
|
// FindProvinceIdWithDataId 根据数据ID查找省份
|
||||||
func (this *RegionProvinceDAO) FindProvinceIdWithDataId(tx *dbs.Tx, dataId string) (int64, error) {
|
func (this *RegionProvinceDAO) FindProvinceIdWithDataId(tx *dbs.Tx, dataId string) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
|
|||||||
@@ -88,9 +88,9 @@ func (this *RegionProvinceService) FindAllRegionProvincesWithRegionCountryId(ctx
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var result = []*pb.RegionProvince{}
|
var pbProvinces = []*pb.RegionProvince{}
|
||||||
for _, province := range provinces {
|
for _, province := range provinces {
|
||||||
result = append(result, &pb.RegionProvince{
|
pbProvinces = append(pbProvinces, &pb.RegionProvince{
|
||||||
Id: int64(province.ValueId),
|
Id: int64(province.ValueId),
|
||||||
Name: province.Name,
|
Name: province.Name,
|
||||||
Codes: province.DecodeCodes(),
|
Codes: province.DecodeCodes(),
|
||||||
@@ -101,7 +101,61 @@ func (this *RegionProvinceService) FindAllRegionProvincesWithRegionCountryId(ctx
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &pb.FindAllRegionProvincesWithRegionCountryIdResponse{
|
return &pb.FindAllRegionProvincesWithRegionCountryIdResponse{
|
||||||
RegionProvinces: result,
|
RegionProvinces: pbProvinces,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindAllRegionProvinces 查找所有国家|地区的所有省份
|
||||||
|
func (this *RegionProvinceService) FindAllRegionProvinces(ctx context.Context, req *pb.FindAllRegionProvincesRequest) (*pb.FindAllRegionProvincesResponse, error) {
|
||||||
|
_, _, err := this.ValidateAdminAndUser(ctx, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
provinces, err := regions.SharedRegionProvinceDAO.FindAllEnabledProvinces(tx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var pbProvinces = []*pb.RegionProvince{}
|
||||||
|
var countryRouteCodeCache = map[int64]string{} // countryId => routeCode
|
||||||
|
for _, province := range provinces {
|
||||||
|
// 国家|地区ID
|
||||||
|
var countryId = int64(province.CountryId)
|
||||||
|
if countryId <= 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 国家|地区线路
|
||||||
|
countryRouteCode, ok := countryRouteCodeCache[countryId]
|
||||||
|
if !ok {
|
||||||
|
countryRouteCode, err = regions.SharedRegionCountryDAO.FindRegionCountryRouteCode(tx, countryId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
countryRouteCodeCache[countryId] = countryRouteCode
|
||||||
|
}
|
||||||
|
if len(countryRouteCode) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
pbProvinces = append(pbProvinces, &pb.RegionProvince{
|
||||||
|
Id: int64(province.ValueId),
|
||||||
|
Name: province.Name,
|
||||||
|
Codes: province.DecodeCodes(),
|
||||||
|
CustomName: province.CustomName,
|
||||||
|
CustomCodes: province.DecodeCustomCodes(),
|
||||||
|
DisplayName: province.DisplayName(),
|
||||||
|
RegionCountryId: countryId,
|
||||||
|
RegionCountry: &pb.RegionCountry{
|
||||||
|
Id: countryId,
|
||||||
|
RouteCode: countryRouteCode,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &pb.FindAllRegionProvincesResponse{
|
||||||
|
RegionProvinces: pbProvinces,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user