mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-28 00:06:36 +08:00
增加城市/ISP查询接口
This commit is contained in:
@@ -38,7 +38,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
// 启用条目
|
||||
// EnableRegionCity 启用条目
|
||||
func (this *RegionCityDAO) EnableRegionCity(tx *dbs.Tx, id uint32) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -47,7 +47,7 @@ func (this *RegionCityDAO) EnableRegionCity(tx *dbs.Tx, id uint32) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 禁用条目
|
||||
// DisableRegionCity 禁用条目
|
||||
func (this *RegionCityDAO) DisableRegionCity(tx *dbs.Tx, id uint32) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -56,7 +56,7 @@ func (this *RegionCityDAO) DisableRegionCity(tx *dbs.Tx, id uint32) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
// FindEnabledRegionCity 查找启用中的条目
|
||||
func (this *RegionCityDAO) FindEnabledRegionCity(tx *dbs.Tx, id int64) (*RegionCity, error) {
|
||||
result, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -68,7 +68,7 @@ func (this *RegionCityDAO) FindEnabledRegionCity(tx *dbs.Tx, id int64) (*RegionC
|
||||
return result.(*RegionCity), err
|
||||
}
|
||||
|
||||
// 根据主键查找名称
|
||||
// FindRegionCityName 根据主键查找名称
|
||||
func (this *RegionCityDAO) FindRegionCityName(tx *dbs.Tx, id uint32) (string, error) {
|
||||
return this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -76,7 +76,7 @@ func (this *RegionCityDAO) FindRegionCityName(tx *dbs.Tx, id uint32) (string, er
|
||||
FindStringCol("")
|
||||
}
|
||||
|
||||
// 根据数据ID查找城市
|
||||
// FindCityWithDataId 根据数据ID查找城市
|
||||
func (this *RegionCityDAO) FindCityWithDataId(tx *dbs.Tx, dataId string) (int64, error) {
|
||||
return this.Query(tx).
|
||||
Attr("dataId", dataId).
|
||||
@@ -84,7 +84,7 @@ func (this *RegionCityDAO) FindCityWithDataId(tx *dbs.Tx, dataId string) (int64,
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// 创建城市
|
||||
// CreateCity 创建城市
|
||||
func (this *RegionCityDAO) CreateCity(tx *dbs.Tx, provinceId int64, name string, dataId string) (int64, error) {
|
||||
op := NewRegionCityOperator()
|
||||
op.ProvinceId = provinceId
|
||||
@@ -105,7 +105,7 @@ func (this *RegionCityDAO) CreateCity(tx *dbs.Tx, provinceId int64, name string,
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
// 根据城市名查找城市ID
|
||||
// FindCityIdWithNameCacheable 根据城市名查找城市ID
|
||||
func (this *RegionCityDAO) FindCityIdWithNameCacheable(tx *dbs.Tx, provinceId int64, cityName string) (int64, error) {
|
||||
key := cityName + "@" + numberutils.FormatInt64(provinceId)
|
||||
|
||||
@@ -132,3 +132,12 @@ func (this *RegionCityDAO) FindCityIdWithNameCacheable(tx *dbs.Tx, provinceId in
|
||||
|
||||
return cityId, nil
|
||||
}
|
||||
|
||||
// FindAllEnabledCities 获取所有城市信息
|
||||
func (this *RegionCityDAO) FindAllEnabledCities(tx *dbs.Tx) (result []*RegionCity, err error) {
|
||||
_, err = this.Query(tx).
|
||||
State(RegionCityStateEnabled).
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1 +1,18 @@
|
||||
package regions
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
)
|
||||
|
||||
func (this *RegionCity) DecodeCodes() []string {
|
||||
if len(this.Codes) == 0 {
|
||||
return []string{}
|
||||
}
|
||||
result := []string{}
|
||||
err := json.Unmarshal([]byte(this.Codes), &result)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
// 启用条目
|
||||
// EnableRegionProvider 启用条目
|
||||
func (this *RegionProviderDAO) EnableRegionProvider(tx *dbs.Tx, id uint32) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -45,7 +45,7 @@ func (this *RegionProviderDAO) EnableRegionProvider(tx *dbs.Tx, id uint32) error
|
||||
return err
|
||||
}
|
||||
|
||||
// 禁用条目
|
||||
// DisableRegionProvider 禁用条目
|
||||
func (this *RegionProviderDAO) DisableRegionProvider(tx *dbs.Tx, id uint32) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -54,8 +54,8 @@ func (this *RegionProviderDAO) DisableRegionProvider(tx *dbs.Tx, id uint32) erro
|
||||
return err
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
func (this *RegionProviderDAO) FindEnabledRegionProvider(tx *dbs.Tx, id uint32) (*RegionProvider, error) {
|
||||
// FindEnabledRegionProvider 查找启用中的条目
|
||||
func (this *RegionProviderDAO) FindEnabledRegionProvider(tx *dbs.Tx, id int64) (*RegionProvider, error) {
|
||||
result, err := this.Query(tx).
|
||||
Pk(id).
|
||||
Attr("state", RegionProviderStateEnabled).
|
||||
@@ -66,7 +66,7 @@ func (this *RegionProviderDAO) FindEnabledRegionProvider(tx *dbs.Tx, id uint32)
|
||||
return result.(*RegionProvider), err
|
||||
}
|
||||
|
||||
// 根据主键查找名称
|
||||
// FindRegionProviderName 根据主键查找名称
|
||||
func (this *RegionProviderDAO) FindRegionProviderName(tx *dbs.Tx, id uint32) (string, error) {
|
||||
return this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -74,7 +74,7 @@ func (this *RegionProviderDAO) FindRegionProviderName(tx *dbs.Tx, id uint32) (st
|
||||
FindStringCol("")
|
||||
}
|
||||
|
||||
// 根据服务商名称查找服务商ID
|
||||
// FindProviderIdWithNameCacheable 根据服务商名称查找服务商ID
|
||||
func (this *RegionProviderDAO) FindProviderIdWithNameCacheable(tx *dbs.Tx, providerName string) (int64, error) {
|
||||
SharedCacheLocker.RLock()
|
||||
providerId, ok := regionProviderNameAndIdCacheMap[providerName]
|
||||
@@ -100,7 +100,7 @@ func (this *RegionProviderDAO) FindProviderIdWithNameCacheable(tx *dbs.Tx, provi
|
||||
return providerId, nil
|
||||
}
|
||||
|
||||
// 创建Provider
|
||||
// CreateProvider 创建Provider
|
||||
func (this *RegionProviderDAO) CreateProvider(tx *dbs.Tx, name string) (int64, error) {
|
||||
op := NewRegionProviderOperator()
|
||||
op.Name = name
|
||||
@@ -112,3 +112,12 @@ func (this *RegionProviderDAO) CreateProvider(tx *dbs.Tx, name string) (int64, e
|
||||
op.Codes = codesJSON
|
||||
return this.SaveInt64(tx, op)
|
||||
}
|
||||
|
||||
// FindAllEnabledProviders 查找所有服务商
|
||||
func (this *RegionProviderDAO) FindAllEnabledProviders(tx *dbs.Tx) (result []*RegionProvider, err error) {
|
||||
_, err = this.Query(tx).
|
||||
State(RegionProviderStateEnabled).
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1 +1,18 @@
|
||||
package regions
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
)
|
||||
|
||||
func (this *RegionProvider) DecodeCodes() []string {
|
||||
if len(this.Codes) == 0 {
|
||||
return []string{}
|
||||
}
|
||||
result := []string{}
|
||||
err := json.Unmarshal([]byte(this.Codes), &result)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user