mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-10 04:00:24 +08:00
新版IP库管理阶段性提交(未完成)
This commit is contained in:
@@ -187,7 +187,7 @@ func (this *AdminService) FindEnabledAdmin(ctx context.Context, req *pb.FindEnab
|
||||
IsSuper: admin.IsSuper,
|
||||
Modules: pbModules,
|
||||
OtpLogin: pbOtpAuth,
|
||||
CanLogin: admin.CanLogin == 1,
|
||||
CanLogin: admin.CanLogin,
|
||||
}
|
||||
return &pb.FindEnabledAdminResponse{Admin: result}, nil
|
||||
}
|
||||
@@ -407,7 +407,7 @@ func (this *AdminService) ListEnabledAdmins(ctx context.Context, req *pb.ListEna
|
||||
IsSuper: admin.IsSuper,
|
||||
CreatedAt: int64(admin.CreatedAt),
|
||||
OtpLogin: pbOtpAuth,
|
||||
CanLogin: admin.CanLogin == 1,
|
||||
CanLogin: admin.CanLogin,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
495
internal/rpc/services/service_ip_library_file.go
Normal file
495
internal/rpc/services/service_ip_library_file.go
Normal file
@@ -0,0 +1,495 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/regions"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
// IPLibraryFileService IP库文件管理
|
||||
type IPLibraryFileService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// FindAllUnfinishedIPLibraryFiles 查找所有未完成的IP库文件
|
||||
func (this *IPLibraryFileService) FindAllUnfinishedIPLibraryFiles(ctx context.Context, req *pb.FindAllUnfinishedIPLibraryFilesRequest) (*pb.FindAllUnfinishedIPLibraryFilesResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
libraryFiles, err := models.SharedIPLibraryFileDAO.FindAllUnfinishedLibraryFiles(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var pbLibraryFiles = []*pb.IPLibraryFile{}
|
||||
for _, libraryFile := range libraryFiles {
|
||||
var pbCountryNames = libraryFile.DecodeCountries()
|
||||
var pbProviderNames = libraryFile.DecodeProviders()
|
||||
|
||||
var pbProvinces = []*pb.IPLibraryFile_Province{}
|
||||
for _, province := range libraryFile.DecodeProvinces() {
|
||||
pbProvinces = append(pbProvinces, &pb.IPLibraryFile_Province{
|
||||
CountryName: province[0],
|
||||
ProvinceName: province[1],
|
||||
})
|
||||
}
|
||||
|
||||
var pbCities = []*pb.IPLibraryFile_City{}
|
||||
for _, city := range libraryFile.DecodeCities() {
|
||||
pbCities = append(pbCities, &pb.IPLibraryFile_City{
|
||||
CountryName: city[0],
|
||||
ProvinceName: city[1],
|
||||
CityName: city[2],
|
||||
})
|
||||
}
|
||||
|
||||
var pbTowns = []*pb.IPLibraryFile_Town{}
|
||||
for _, town := range libraryFile.DecodeTowns() {
|
||||
pbTowns = append(pbTowns, &pb.IPLibraryFile_Town{
|
||||
CountryName: town[0],
|
||||
ProvinceName: town[1],
|
||||
CityName: town[2],
|
||||
TownName: town[3],
|
||||
})
|
||||
}
|
||||
|
||||
pbLibraryFiles = append(pbLibraryFiles, &pb.IPLibraryFile{
|
||||
Id: int64(libraryFile.Id),
|
||||
FileId: int64(libraryFile.FileId),
|
||||
IsFinished: libraryFile.IsFinished,
|
||||
CreatedAt: int64(libraryFile.CreatedAt),
|
||||
CountryNames: pbCountryNames,
|
||||
Provinces: pbProvinces,
|
||||
Cities: pbCities,
|
||||
Towns: pbTowns,
|
||||
ProviderNames: pbProviderNames,
|
||||
})
|
||||
}
|
||||
|
||||
return &pb.FindAllUnfinishedIPLibraryFilesResponse{
|
||||
IpLibraryFiles: pbLibraryFiles,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FindIPLibraryFile 查找单个IP库文件
|
||||
func (this *IPLibraryFileService) FindIPLibraryFile(ctx context.Context, req *pb.FindIPLibraryFileRequest) (*pb.FindIPLibraryFileResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
libraryFile, err := models.SharedIPLibraryFileDAO.FindEnabledIPLibraryFile(tx, req.IpLibraryFileId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if libraryFile == nil {
|
||||
return &pb.FindIPLibraryFileResponse{
|
||||
IpLibraryFile: nil,
|
||||
}, nil
|
||||
}
|
||||
|
||||
var pbCountryNames = libraryFile.DecodeCountries()
|
||||
var pbProviderNames = libraryFile.DecodeProviders()
|
||||
|
||||
var pbProvinces = []*pb.IPLibraryFile_Province{}
|
||||
for _, province := range libraryFile.DecodeProvinces() {
|
||||
pbProvinces = append(pbProvinces, &pb.IPLibraryFile_Province{
|
||||
CountryName: province[0],
|
||||
ProvinceName: province[1],
|
||||
})
|
||||
}
|
||||
|
||||
var pbCities = []*pb.IPLibraryFile_City{}
|
||||
for _, city := range libraryFile.DecodeCities() {
|
||||
pbCities = append(pbCities, &pb.IPLibraryFile_City{
|
||||
CountryName: city[0],
|
||||
ProvinceName: city[1],
|
||||
CityName: city[2],
|
||||
})
|
||||
}
|
||||
|
||||
var pbTowns = []*pb.IPLibraryFile_Town{}
|
||||
for _, town := range libraryFile.DecodeTowns() {
|
||||
pbTowns = append(pbTowns, &pb.IPLibraryFile_Town{
|
||||
CountryName: town[0],
|
||||
ProvinceName: town[1],
|
||||
CityName: town[2],
|
||||
TownName: town[3],
|
||||
})
|
||||
}
|
||||
|
||||
return &pb.FindIPLibraryFileResponse{IpLibraryFile: &pb.IPLibraryFile{
|
||||
Id: int64(libraryFile.Id),
|
||||
FileId: int64(libraryFile.FileId),
|
||||
IsFinished: libraryFile.IsFinished,
|
||||
CreatedAt: int64(libraryFile.CreatedAt),
|
||||
CountryNames: pbCountryNames,
|
||||
Provinces: pbProvinces,
|
||||
Cities: pbCities,
|
||||
Towns: pbTowns,
|
||||
ProviderNames: pbProviderNames,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
// CreateIPLibraryFile 创建IP库文件
|
||||
func (this *IPLibraryFileService) CreateIPLibraryFile(ctx context.Context, req *pb.CreateIPLibraryFileRequest) (*pb.CreateIPLibraryFileResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var countries = []string{}
|
||||
var provinces = [][2]string{}
|
||||
var cities = [][3]string{}
|
||||
var towns = [][4]string{}
|
||||
var providers = []string{}
|
||||
|
||||
err = json.Unmarshal(req.CountriesJSON, &countries)
|
||||
if err != nil {
|
||||
return nil, errors.New("decode countries failed: " + err.Error())
|
||||
}
|
||||
|
||||
err = json.Unmarshal(req.ProvincesJSON, &provinces)
|
||||
if err != nil {
|
||||
return nil, errors.New("decode provinces failed: " + err.Error())
|
||||
}
|
||||
|
||||
err = json.Unmarshal(req.CitiesJSON, &cities)
|
||||
if err != nil {
|
||||
return nil, errors.New("decode cities failed: " + err.Error())
|
||||
}
|
||||
|
||||
err = json.Unmarshal(req.TownsJSON, &towns)
|
||||
if err != nil {
|
||||
return nil, errors.New("decode towns failed: " + err.Error())
|
||||
}
|
||||
|
||||
err = json.Unmarshal(req.ProvidersJSON, &providers)
|
||||
if err != nil {
|
||||
return nil, errors.New("decode providers failed: " + err.Error())
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
libraryFileId, err := models.SharedIPLibraryFileDAO.CreateLibraryFile(tx, req.Template, req.EmptyValues, req.FileId, countries, provinces, cities, towns, providers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CreateIPLibraryFileResponse{
|
||||
IpLibraryFileId: libraryFileId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CheckCountriesWithIPLibraryFileId 检查国家/地区
|
||||
func (this *IPLibraryFileService) CheckCountriesWithIPLibraryFileId(ctx context.Context, req *pb.CheckCountriesWithIPLibraryFileIdRequest) (*pb.CheckCountriesWithIPLibraryFileIdResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
allCountries, err := regions.SharedRegionCountryDAO.FindAllCountries(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
countryNames, err := models.SharedIPLibraryFileDAO.FindLibraryFileCountries(tx, req.IpLibraryFileId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var pbMissingCountries = []*pb.CheckCountriesWithIPLibraryFileIdResponse_MissingCountry{}
|
||||
for _, countryName := range countryNames {
|
||||
if len(countryName) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
countryId, err := regions.SharedRegionCountryDAO.FindCountryIdWithName(tx, countryName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if countryId > 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
var pbMissingCountry = &pb.CheckCountriesWithIPLibraryFileIdResponse_MissingCountry{
|
||||
CountryName: countryName,
|
||||
SimilarCountries: nil,
|
||||
}
|
||||
|
||||
// 查找相似
|
||||
var similarCountries = regions.SharedRegionCountryDAO.FindSimilarCountries(allCountries, countryName, 5)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, similarCountry := range similarCountries {
|
||||
pbMissingCountry.SimilarCountries = append(pbMissingCountry.SimilarCountries, &pb.RegionCountry{
|
||||
Id: int64(similarCountry.Id),
|
||||
Name: similarCountry.Name,
|
||||
DisplayName: similarCountry.DisplayName(),
|
||||
})
|
||||
}
|
||||
|
||||
pbMissingCountries = append(pbMissingCountries, pbMissingCountry)
|
||||
}
|
||||
|
||||
return &pb.CheckCountriesWithIPLibraryFileIdResponse{
|
||||
MissingCountries: pbMissingCountries,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CheckProvincesWithIPLibraryFileId 检查省份/州
|
||||
func (this *IPLibraryFileService) CheckProvincesWithIPLibraryFileId(ctx context.Context, req *pb.CheckProvincesWithIPLibraryFileIdRequest) (*pb.CheckProvincesWithIPLibraryFileIdResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
provinces, err := models.SharedIPLibraryFileDAO.FindLibraryFileProvinces(tx, req.IpLibraryFileId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var countryMap = map[string]int64{} // countryName => countryId
|
||||
var provinceNamesMap = map[int64][][2]string{} // countryId => [][2]{countryName, provinceName}
|
||||
var countryIds = []int64{}
|
||||
for _, province := range provinces {
|
||||
var countryName = province[0]
|
||||
var provinceName = province[1]
|
||||
|
||||
countryId, ok := countryMap[countryName]
|
||||
if ok {
|
||||
provinceNamesMap[countryId] = append(provinceNamesMap[countryId], [2]string{countryName, provinceName})
|
||||
continue
|
||||
}
|
||||
|
||||
countryId, err := regions.SharedRegionCountryDAO.FindCountryIdWithName(tx, countryName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
countryMap[countryName] = countryId
|
||||
|
||||
provinceNamesMap[countryId] = append(provinceNamesMap[countryId], [2]string{countryName, provinceName})
|
||||
|
||||
if countryId > 0 && !lists.ContainsInt64(countryIds, countryId) {
|
||||
countryIds = append(countryIds, countryId)
|
||||
}
|
||||
}
|
||||
|
||||
var pbMissingProvinces = []*pb.CheckProvincesWithIPLibraryFileIdResponse_MissingProvince{}
|
||||
for _, countryId := range countryIds {
|
||||
allProvinces, err := regions.SharedRegionProvinceDAO.FindAllEnabledProvincesWithCountryId(tx, countryId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, province := range provinceNamesMap[countryId] {
|
||||
var countryName = province[0]
|
||||
var provinceName = province[1]
|
||||
provinceId, err := regions.SharedRegionProvinceDAO.FindProvinceIdWithName(tx, countryId, provinceName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if provinceId > 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
var similarProvinces = regions.SharedRegionProvinceDAO.FindSimilarProvinces(allProvinces, provinceName, 5)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var pbMissingProvince = &pb.CheckProvincesWithIPLibraryFileIdResponse_MissingProvince{}
|
||||
pbMissingProvince.CountryName = countryName
|
||||
pbMissingProvince.ProvinceName = provinceName
|
||||
|
||||
for _, similarProvince := range similarProvinces {
|
||||
pbMissingProvince.SimilarProvinces = append(pbMissingProvince.SimilarProvinces, &pb.RegionProvince{
|
||||
Id: int64(similarProvince.Id),
|
||||
Name: similarProvince.Name,
|
||||
DisplayName: similarProvince.DisplayName(),
|
||||
})
|
||||
}
|
||||
pbMissingProvinces = append(pbMissingProvinces, pbMissingProvince)
|
||||
}
|
||||
}
|
||||
|
||||
return &pb.CheckProvincesWithIPLibraryFileIdResponse{MissingProvinces: pbMissingProvinces}, nil
|
||||
}
|
||||
|
||||
// CheckCitiesWithIPLibraryFileId 检查城市/市
|
||||
func (this *IPLibraryFileService) CheckCitiesWithIPLibraryFileId(ctx context.Context, req *pb.CheckCitiesWithIPLibraryFileIdRequest) (*pb.CheckCitiesWithIPLibraryFileIdResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
cities, err := models.SharedIPLibraryFileDAO.FindLibraryFileCities(tx, req.IpLibraryFileId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var countryMap = map[string]int64{} // countryName => countryId
|
||||
var provinceMap = map[string]int64{} // countryId_provinceName => provinceId
|
||||
var provinceNamesMap = map[int64][][3]string{} // provinceId => [][3]{countryName, provinceName, cityName}
|
||||
var provinceIds = []int64{}
|
||||
for _, city := range cities {
|
||||
var countryName = city[0]
|
||||
var provinceName = city[1]
|
||||
var cityName = city[2]
|
||||
|
||||
countryId, ok := countryMap[countryName]
|
||||
if !ok {
|
||||
countryId, err = regions.SharedRegionCountryDAO.FindCountryIdWithName(tx, countryName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
countryMap[countryName] = countryId
|
||||
|
||||
var key = types.String(countryId) + "_" + provinceName
|
||||
provinceId, ok := provinceMap[key]
|
||||
if ok {
|
||||
provinceNamesMap[provinceId] = append(provinceNamesMap[provinceId], [3]string{countryName, provinceName, cityName})
|
||||
} else {
|
||||
provinceId, err := regions.SharedRegionProvinceDAO.FindProvinceIdWithName(tx, countryId, provinceName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
provinceMap[key] = provinceId
|
||||
provinceNamesMap[provinceId] = append(provinceNamesMap[provinceId], [3]string{countryName, provinceName, cityName})
|
||||
if provinceId > 0 {
|
||||
provinceIds = append(provinceIds, provinceId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var pbMissingCities = []*pb.CheckCitiesWithIPLibraryFileIdResponse_MissingCity{}
|
||||
for _, provinceId := range provinceIds {
|
||||
allCities, err := regions.SharedRegionCityDAO.FindAllEnabledCitiesWithProvinceId(tx, provinceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, city := range provinceNamesMap[provinceId] {
|
||||
var countryName = city[0]
|
||||
var provinceName = city[1]
|
||||
var cityName = city[2]
|
||||
cityId, err := regions.SharedRegionCityDAO.FindCityIdWithName(tx, provinceId, cityName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cityId > 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
var similarCities = regions.SharedRegionCityDAO.FindSimilarCities(allCities, cityName, 5)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var pbMissingCity = &pb.CheckCitiesWithIPLibraryFileIdResponse_MissingCity{}
|
||||
pbMissingCity.CountryName = countryName
|
||||
pbMissingCity.ProvinceName = provinceName
|
||||
pbMissingCity.CityName = cityName
|
||||
|
||||
for _, similarCity := range similarCities {
|
||||
pbMissingCity.SimilarCities = append(pbMissingCity.SimilarCities, &pb.RegionCity{
|
||||
Id: int64(similarCity.Id),
|
||||
Name: similarCity.Name,
|
||||
DisplayName: similarCity.DisplayName(),
|
||||
})
|
||||
}
|
||||
pbMissingCities = append(pbMissingCities, pbMissingCity)
|
||||
}
|
||||
}
|
||||
|
||||
return &pb.CheckCitiesWithIPLibraryFileIdResponse{MissingCities: pbMissingCities}, nil
|
||||
}
|
||||
|
||||
// CheckProvidersWithIPLibraryFileId 检查ISP运营商
|
||||
func (this *IPLibraryFileService) CheckProvidersWithIPLibraryFileId(ctx context.Context, req *pb.CheckProvidersWithIPLibraryFileIdRequest) (*pb.CheckProvidersWithIPLibraryFileIdResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
allProviders, err := regions.SharedRegionProviderDAO.FindAllEnabledProviders(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
providerNames, err := models.SharedIPLibraryFileDAO.FindLibraryFileProviders(tx, req.IpLibraryFileId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var pbMissingProviders = []*pb.CheckProvidersWithIPLibraryFileIdResponse_MissingProvider{}
|
||||
for _, providerName := range providerNames {
|
||||
if len(providerName) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
providerId, err := regions.SharedRegionProviderDAO.FindProviderIdWithName(tx, providerName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if providerId > 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
var pbMissingProvider = &pb.CheckProvidersWithIPLibraryFileIdResponse_MissingProvider{
|
||||
ProviderName: providerName,
|
||||
SimilarProviders: nil,
|
||||
}
|
||||
|
||||
// 查找相似
|
||||
var similarProviders = regions.SharedRegionProviderDAO.FindSimilarProviders(allProviders, providerName, 5)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, similarProvider := range similarProviders {
|
||||
pbMissingProvider.SimilarProviders = append(pbMissingProvider.SimilarProviders, &pb.RegionProvider{
|
||||
Id: int64(similarProvider.Id),
|
||||
Name: similarProvider.Name,
|
||||
DisplayName: similarProvider.DisplayName(),
|
||||
})
|
||||
}
|
||||
|
||||
pbMissingProviders = append(pbMissingProviders, pbMissingProvider)
|
||||
}
|
||||
|
||||
return &pb.CheckProvidersWithIPLibraryFileIdResponse{
|
||||
MissingProviders: pbMissingProviders,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GenerateIPLibraryFile 生成IP库文件
|
||||
func (this *IPLibraryFileService) GenerateIPLibraryFile(ctx context.Context, req *pb.GenerateIPLibraryFileRequest) (*pb.RPCSuccess, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
err = models.SharedIPLibraryFileDAO.GenerateIPLibrary(tx, req.IpLibraryFileId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
@@ -14,6 +14,7 @@ type RegionCityService struct {
|
||||
}
|
||||
|
||||
// FindAllEnabledRegionCities 查找所有城市
|
||||
// Deprecated
|
||||
func (this *RegionCityService) FindAllEnabledRegionCities(ctx context.Context, req *pb.FindAllEnabledRegionCitiesRequest) (*pb.FindAllEnabledRegionCitiesResponse, error) {
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
if err != nil {
|
||||
@@ -48,9 +49,10 @@ func (this *RegionCityService) FindAllEnabledRegionCities(ctx context.Context, r
|
||||
}
|
||||
|
||||
pbProvince = &pb.RegionProvince{
|
||||
Id: int64(province.Id),
|
||||
Name: province.Name,
|
||||
Codes: province.DecodeCodes(),
|
||||
Id: int64(province.Id),
|
||||
Name: province.Name,
|
||||
Codes: province.DecodeCodes(),
|
||||
DisplayName: province.DisplayName(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +62,9 @@ func (this *RegionCityService) FindAllEnabledRegionCities(ctx context.Context, r
|
||||
Codes: city.DecodeCodes(),
|
||||
RegionProvinceId: int64(city.ProvinceId),
|
||||
RegionProvince: pbProvince,
|
||||
CustomName: city.CustomName,
|
||||
CustomCodes: city.DecodeCustomCodes(),
|
||||
DisplayName: city.DisplayName(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -68,7 +73,106 @@ func (this *RegionCityService) FindAllEnabledRegionCities(ctx context.Context, r
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FindAllRegionCities 查找所有城市
|
||||
func (this *RegionCityService) FindAllRegionCities(ctx context.Context, req *pb.FindAllRegionCitiesRequest) (*pb.FindAllRegionCitiesResponse, error) {
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
cities, err := regions.SharedRegionCityDAO.FindAllEnabledCities(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var pbCities = []*pb.RegionCity{}
|
||||
|
||||
var provincesMap = map[int64]*regions.RegionProvince{} // provinceId => RegionProvince
|
||||
|
||||
for _, city := range cities {
|
||||
var provinceId = int64(city.ProvinceId)
|
||||
|
||||
var pbProvince = &pb.RegionProvince{Id: provinceId}
|
||||
if req.IncludeRegionProvince {
|
||||
province, ok := provincesMap[provinceId]
|
||||
if !ok {
|
||||
province, err = regions.SharedRegionProvinceDAO.FindEnabledRegionProvince(tx, provinceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if province == nil {
|
||||
continue
|
||||
}
|
||||
provincesMap[provinceId] = province
|
||||
}
|
||||
|
||||
pbProvince = &pb.RegionProvince{
|
||||
Id: int64(province.Id),
|
||||
Name: province.Name,
|
||||
Codes: province.DecodeCodes(),
|
||||
CustomName: province.CustomName,
|
||||
CustomCodes: province.DecodeCustomCodes(),
|
||||
DisplayName: province.DisplayName(),
|
||||
}
|
||||
}
|
||||
|
||||
pbCities = append(pbCities, &pb.RegionCity{
|
||||
Id: int64(city.Id),
|
||||
Name: city.Name,
|
||||
Codes: city.DecodeCodes(),
|
||||
RegionProvinceId: int64(city.ProvinceId),
|
||||
RegionProvince: pbProvince,
|
||||
CustomName: city.CustomName,
|
||||
CustomCodes: city.DecodeCustomCodes(),
|
||||
DisplayName: city.DisplayName(),
|
||||
})
|
||||
}
|
||||
|
||||
return &pb.FindAllRegionCitiesResponse{
|
||||
RegionCities: pbCities,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FindAllRegionCitiesWithRegionProvinceId 查找某个省份的所有城市
|
||||
func (this *RegionCityService) FindAllRegionCitiesWithRegionProvinceId(ctx context.Context, req *pb.FindAllRegionCitiesWithRegionProvinceIdRequest) (*pb.FindAllRegionCitiesWithRegionProvinceIdResponse, error) {
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
cities, err := regions.SharedRegionCityDAO.FindAllEnabledCitiesWithProvinceId(tx, req.RegionProvinceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var pbCities = []*pb.RegionCity{}
|
||||
|
||||
for _, city := range cities {
|
||||
var provinceId = int64(city.ProvinceId)
|
||||
|
||||
var pbProvince = &pb.RegionProvince{Id: provinceId}
|
||||
|
||||
pbCities = append(pbCities, &pb.RegionCity{
|
||||
Id: int64(city.Id),
|
||||
Name: city.Name,
|
||||
Codes: city.DecodeCodes(),
|
||||
RegionProvinceId: int64(city.ProvinceId),
|
||||
RegionProvince: pbProvince,
|
||||
CustomName: city.CustomName,
|
||||
CustomCodes: city.DecodeCustomCodes(),
|
||||
DisplayName: city.DisplayName(),
|
||||
})
|
||||
}
|
||||
|
||||
return &pb.FindAllRegionCitiesWithRegionProvinceIdResponse{
|
||||
RegionCities: pbCities,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FindEnabledRegionCity 查找单个城市信息
|
||||
// Deprecated
|
||||
func (this *RegionCityService) FindEnabledRegionCity(ctx context.Context, req *pb.FindEnabledRegionCityRequest) (*pb.FindEnabledRegionCityResponse, error) {
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
if err != nil {
|
||||
@@ -92,6 +196,55 @@ func (this *RegionCityService) FindEnabledRegionCity(ctx context.Context, req *p
|
||||
Name: city.Name,
|
||||
Codes: city.DecodeCodes(),
|
||||
RegionProvinceId: int64(city.ProvinceId),
|
||||
CustomName: city.CustomName,
|
||||
CustomCodes: city.DecodeCustomCodes(),
|
||||
DisplayName: city.DisplayName(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FindRegionCity 查找单个城市信息
|
||||
func (this *RegionCityService) FindRegionCity(ctx context.Context, req *pb.FindRegionCityRequest) (*pb.FindRegionCityResponse, error) {
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
city, err := regions.SharedRegionCityDAO.FindEnabledRegionCity(tx, req.RegionCityId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if city == nil {
|
||||
return &pb.FindRegionCityResponse{
|
||||
RegionCity: nil,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &pb.FindRegionCityResponse{
|
||||
RegionCity: &pb.RegionCity{
|
||||
Id: int64(city.Id),
|
||||
Name: city.Name,
|
||||
Codes: city.DecodeCodes(),
|
||||
RegionProvinceId: int64(city.ProvinceId),
|
||||
CustomName: city.CustomName,
|
||||
CustomCodes: city.DecodeCustomCodes(),
|
||||
DisplayName: city.DisplayName(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateRegionCityCustom 修改城市定制信息
|
||||
func (this *RegionCityService) UpdateRegionCityCustom(ctx context.Context, req *pb.UpdateRegionCityCustomRequest) (*pb.RPCSuccess, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
err = regions.SharedRegionCityDAO.UpdateCityCustom(tx, req.RegionCityId, req.CustomName, req.CustomCodes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ type RegionCountryService struct {
|
||||
}
|
||||
|
||||
// FindAllEnabledRegionCountries 查找所有的国家列表
|
||||
// Deprecated
|
||||
func (this *RegionCountryService) FindAllEnabledRegionCountries(ctx context.Context, req *pb.FindAllEnabledRegionCountriesRequest) (*pb.FindAllEnabledRegionCountriesResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
@@ -39,10 +40,13 @@ func (this *RegionCountryService) FindAllEnabledRegionCountries(ctx context.Cont
|
||||
}
|
||||
|
||||
result = append(result, &pb.RegionCountry{
|
||||
Id: int64(country.Id),
|
||||
Name: country.Name,
|
||||
Codes: country.DecodeCodes(),
|
||||
Pinyin: pinyinStrings,
|
||||
Id: int64(country.Id),
|
||||
Name: country.Name,
|
||||
Codes: country.DecodeCodes(),
|
||||
Pinyin: pinyinStrings,
|
||||
CustomName: country.CustomName,
|
||||
CustomCodes: country.DecodeCustomCodes(),
|
||||
DisplayName: country.DisplayName(),
|
||||
})
|
||||
}
|
||||
return &pb.FindAllEnabledRegionCountriesResponse{
|
||||
@@ -51,6 +55,7 @@ func (this *RegionCountryService) FindAllEnabledRegionCountries(ctx context.Cont
|
||||
}
|
||||
|
||||
// FindEnabledRegionCountry 查找单个国家信息
|
||||
// Deprecated
|
||||
func (this *RegionCountryService) FindEnabledRegionCountry(ctx context.Context, req *pb.FindEnabledRegionCountryRequest) (*pb.FindEnabledRegionCountryResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
@@ -69,8 +74,95 @@ func (this *RegionCountryService) FindEnabledRegionCountry(ctx context.Context,
|
||||
}
|
||||
|
||||
return &pb.FindEnabledRegionCountryResponse{RegionCountry: &pb.RegionCountry{
|
||||
Id: int64(country.Id),
|
||||
Name: country.Name,
|
||||
Codes: country.DecodeCodes(),
|
||||
Id: int64(country.Id),
|
||||
Name: country.Name,
|
||||
Codes: country.DecodeCodes(),
|
||||
CustomName: country.CustomName,
|
||||
CustomCodes: country.DecodeCustomCodes(),
|
||||
DisplayName: country.DisplayName(),
|
||||
}}, nil
|
||||
}
|
||||
|
||||
// FindAllRegionCountries 查找所有的国家列表
|
||||
func (this *RegionCountryService) FindAllRegionCountries(ctx context.Context, req *pb.FindAllRegionCountriesRequest) (*pb.FindAllRegionCountriesResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
countries, err := regions.SharedRegionCountryDAO.FindAllEnabledCountriesOrderByPinyin(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result = []*pb.RegionCountry{}
|
||||
for _, country := range countries {
|
||||
pinyinStrings := []string{}
|
||||
err = json.Unmarshal(country.Pinyin, &pinyinStrings)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(pinyinStrings) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, &pb.RegionCountry{
|
||||
Id: int64(country.Id),
|
||||
Name: country.Name,
|
||||
Codes: country.DecodeCodes(),
|
||||
Pinyin: pinyinStrings,
|
||||
CustomName: country.CustomName,
|
||||
CustomCodes: country.DecodeCustomCodes(),
|
||||
DisplayName: country.DisplayName(),
|
||||
})
|
||||
}
|
||||
return &pb.FindAllRegionCountriesResponse{
|
||||
RegionCountries: result,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FindRegionCountry 查找单个国家信息
|
||||
func (this *RegionCountryService) FindRegionCountry(ctx context.Context, req *pb.FindRegionCountryRequest) (*pb.FindRegionCountryResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
country, err := regions.SharedRegionCountryDAO.FindEnabledRegionCountry(tx, req.RegionCountryId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if country == nil {
|
||||
return &pb.FindRegionCountryResponse{RegionCountry: nil}, nil
|
||||
}
|
||||
|
||||
return &pb.FindRegionCountryResponse{RegionCountry: &pb.RegionCountry{
|
||||
Id: int64(country.Id),
|
||||
Name: country.Name,
|
||||
Codes: country.DecodeCodes(),
|
||||
CustomName: country.CustomName,
|
||||
CustomCodes: country.DecodeCustomCodes(),
|
||||
DisplayName: country.DisplayName(),
|
||||
}}, nil
|
||||
}
|
||||
|
||||
// UpdateRegionCountryCustom 修改城市定制信息
|
||||
func (this *RegionCountryService) UpdateRegionCountryCustom(ctx context.Context, req *pb.UpdateRegionCountryCustomRequest) (*pb.RPCSuccess, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
err = regions.SharedRegionCountryDAO.UpdateCountryCustom(tx, req.RegionCountryId, req.CustomName, req.CustomCodes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ type RegionProviderService struct {
|
||||
}
|
||||
|
||||
// FindAllEnabledRegionProviders 查找所有ISP
|
||||
// Deprecated
|
||||
func (this *RegionProviderService) FindAllEnabledRegionProviders(ctx context.Context, req *pb.FindAllEnabledRegionProvidersRequest) (*pb.FindAllEnabledRegionProvidersResponse, error) {
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
if err != nil {
|
||||
@@ -29,9 +30,12 @@ func (this *RegionProviderService) FindAllEnabledRegionProviders(ctx context.Con
|
||||
var pbProviders = []*pb.RegionProvider{}
|
||||
for _, provider := range providers {
|
||||
pbProviders = append(pbProviders, &pb.RegionProvider{
|
||||
Id: int64(provider.Id),
|
||||
Name: provider.Name,
|
||||
Codes: provider.DecodeCodes(),
|
||||
Id: int64(provider.Id),
|
||||
Name: provider.Name,
|
||||
Codes: provider.DecodeCodes(),
|
||||
CustomName: provider.CustomName,
|
||||
CustomCodes: provider.DecodeCustomCodes(),
|
||||
DisplayName: provider.DisplayName(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -41,6 +45,7 @@ func (this *RegionProviderService) FindAllEnabledRegionProviders(ctx context.Con
|
||||
}
|
||||
|
||||
// FindEnabledRegionProvider 查找单个ISP信息
|
||||
// Deprecated
|
||||
func (this *RegionProviderService) FindEnabledRegionProvider(ctx context.Context, req *pb.FindEnabledRegionProviderRequest) (*pb.FindEnabledRegionProviderResponse, error) {
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
if err != nil {
|
||||
@@ -60,9 +65,87 @@ func (this *RegionProviderService) FindEnabledRegionProvider(ctx context.Context
|
||||
|
||||
return &pb.FindEnabledRegionProviderResponse{
|
||||
RegionProvider: &pb.RegionProvider{
|
||||
Id: int64(provider.Id),
|
||||
Name: provider.Name,
|
||||
Codes: provider.DecodeCodes(),
|
||||
Id: int64(provider.Id),
|
||||
Name: provider.Name,
|
||||
Codes: provider.DecodeCodes(),
|
||||
CustomName: provider.CustomName,
|
||||
CustomCodes: provider.DecodeCustomCodes(),
|
||||
DisplayName: provider.DisplayName(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FindAllRegionProviders 查找所有ISP
|
||||
func (this *RegionProviderService) FindAllRegionProviders(ctx context.Context, req *pb.FindAllRegionProvidersRequest) (*pb.FindAllRegionProvidersResponse, error) {
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
providers, err := regions.SharedRegionProviderDAO.FindAllEnabledProviders(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var pbProviders = []*pb.RegionProvider{}
|
||||
for _, provider := range providers {
|
||||
pbProviders = append(pbProviders, &pb.RegionProvider{
|
||||
Id: int64(provider.Id),
|
||||
Name: provider.Name,
|
||||
Codes: provider.DecodeCodes(),
|
||||
CustomName: provider.CustomName,
|
||||
CustomCodes: provider.DecodeCustomCodes(),
|
||||
DisplayName: provider.DisplayName(),
|
||||
})
|
||||
}
|
||||
|
||||
return &pb.FindAllRegionProvidersResponse{
|
||||
RegionProviders: pbProviders,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FindRegionProvider 查找单个ISP信息
|
||||
func (this *RegionProviderService) FindRegionProvider(ctx context.Context, req *pb.FindRegionProviderRequest) (*pb.FindRegionProviderResponse, error) {
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
provider, err := regions.SharedRegionProviderDAO.FindEnabledRegionProvider(tx, req.RegionProviderId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if provider == nil {
|
||||
return &pb.FindRegionProviderResponse{
|
||||
RegionProvider: nil,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &pb.FindRegionProviderResponse{
|
||||
RegionProvider: &pb.RegionProvider{
|
||||
Id: int64(provider.Id),
|
||||
Name: provider.Name,
|
||||
Codes: provider.DecodeCodes(),
|
||||
CustomName: provider.CustomName,
|
||||
CustomCodes: provider.DecodeCustomCodes(),
|
||||
DisplayName: provider.DisplayName(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateRegionProviderCustom 修改城市定制信息
|
||||
func (this *RegionProviderService) UpdateRegionProviderCustom(ctx context.Context, req *pb.UpdateRegionProviderCustomRequest) (*pb.RPCSuccess, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
err = regions.SharedRegionProviderDAO.UpdateProviderCustom(tx, req.RegionProviderId, req.CustomName, req.CustomCodes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ type RegionProvinceService struct {
|
||||
}
|
||||
|
||||
// FindAllEnabledRegionProvincesWithCountryId 查找所有省份
|
||||
// Deprecated
|
||||
func (this *RegionProvinceService) FindAllEnabledRegionProvincesWithCountryId(ctx context.Context, req *pb.FindAllEnabledRegionProvincesWithCountryIdRequest) (*pb.FindAllEnabledRegionProvincesWithCountryIdResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
@@ -28,9 +29,12 @@ func (this *RegionProvinceService) FindAllEnabledRegionProvincesWithCountryId(ct
|
||||
result := []*pb.RegionProvince{}
|
||||
for _, province := range provinces {
|
||||
result = append(result, &pb.RegionProvince{
|
||||
Id: int64(province.Id),
|
||||
Name: province.Name,
|
||||
Codes: province.DecodeCodes(),
|
||||
Id: int64(province.Id),
|
||||
Name: province.Name,
|
||||
Codes: province.DecodeCodes(),
|
||||
CustomName: province.CustomName,
|
||||
CustomCodes: province.DecodeCustomCodes(),
|
||||
DisplayName: province.DisplayName(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -40,6 +44,7 @@ func (this *RegionProvinceService) FindAllEnabledRegionProvincesWithCountryId(ct
|
||||
}
|
||||
|
||||
// FindEnabledRegionProvince 查找单个省份信息
|
||||
// Deprecated
|
||||
func (this *RegionProvinceService) FindEnabledRegionProvince(ctx context.Context, req *pb.FindEnabledRegionProvinceRequest) (*pb.FindEnabledRegionProvinceResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
@@ -59,9 +64,88 @@ func (this *RegionProvinceService) FindEnabledRegionProvince(ctx context.Context
|
||||
|
||||
return &pb.FindEnabledRegionProvinceResponse{
|
||||
RegionProvince: &pb.RegionProvince{
|
||||
Id: int64(province.Id),
|
||||
Name: province.Name,
|
||||
Codes: province.DecodeCodes(),
|
||||
Id: int64(province.Id),
|
||||
Name: province.Name,
|
||||
Codes: province.DecodeCodes(),
|
||||
CustomName: province.CustomName,
|
||||
CustomCodes: province.DecodeCustomCodes(),
|
||||
DisplayName: province.DisplayName(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FindAllRegionProvincesWithRegionCountryId 查找所有省份
|
||||
func (this *RegionProvinceService) FindAllRegionProvincesWithRegionCountryId(ctx context.Context, req *pb.FindAllRegionProvincesWithRegionCountryIdRequest) (*pb.FindAllRegionProvincesWithRegionCountryIdResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
provinces, err := regions.SharedRegionProvinceDAO.FindAllEnabledProvincesWithCountryId(tx, req.RegionCountryId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := []*pb.RegionProvince{}
|
||||
for _, province := range provinces {
|
||||
result = append(result, &pb.RegionProvince{
|
||||
Id: int64(province.Id),
|
||||
Name: province.Name,
|
||||
Codes: province.DecodeCodes(),
|
||||
CustomName: province.CustomName,
|
||||
CustomCodes: province.DecodeCustomCodes(),
|
||||
DisplayName: province.DisplayName(),
|
||||
})
|
||||
}
|
||||
|
||||
return &pb.FindAllRegionProvincesWithRegionCountryIdResponse{
|
||||
RegionProvinces: result,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FindRegionProvince 查找单个省份信息
|
||||
func (this *RegionProvinceService) FindRegionProvince(ctx context.Context, req *pb.FindRegionProvinceRequest) (*pb.FindRegionProvinceResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := this.ValidateNodeId(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
province, err := regions.SharedRegionProvinceDAO.FindEnabledRegionProvince(tx, req.RegionProvinceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if province == nil {
|
||||
return &pb.FindRegionProvinceResponse{RegionProvince: nil}, nil
|
||||
}
|
||||
|
||||
return &pb.FindRegionProvinceResponse{
|
||||
RegionProvince: &pb.RegionProvince{
|
||||
Id: int64(province.Id),
|
||||
Name: province.Name,
|
||||
Codes: province.DecodeCodes(),
|
||||
CustomName: province.CustomName,
|
||||
CustomCodes: province.DecodeCustomCodes(),
|
||||
DisplayName: province.DisplayName(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateRegionProvinceCustom 修改城市定制信息
|
||||
func (this *RegionProvinceService) UpdateRegionProvinceCustom(ctx context.Context, req *pb.UpdateRegionProvinceCustomRequest) (*pb.RPCSuccess, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
err = regions.SharedRegionProvinceDAO.UpdateProvinceCustom(tx, req.RegionProvinceId, req.CustomName, req.CustomCodes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user