增加国家/地区封禁管理

This commit is contained in:
刘祥超
2020-11-06 11:02:53 +08:00
parent 62ae07484d
commit c5b0f5f3a2
15 changed files with 3843 additions and 11 deletions

View File

@@ -136,6 +136,22 @@ func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicyInboundAndOutbound(policy
return err
}
// 修改策略的Inbound
func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicyInbound(policyId int64, inboundJSON []byte) error {
if policyId <= 0 {
return errors.New("invalid policyId")
}
op := NewHTTPFirewallPolicyOperator()
op.Id = policyId
if len(inboundJSON) > 0 {
op.Inbound = inboundJSON
} else {
op.Inbound = "null"
}
_, err := this.Save(op)
return err
}
// 修改策略
func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicy(policyId int64, isOn bool, name string, description string, inboundJSON []byte, outboundJSON []byte) error {
if policyId <= 0 {

View File

@@ -1,9 +1,11 @@
package models
import (
"encoding/json"
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/types"
)
const (
@@ -69,3 +71,32 @@ func (this *RegionCityDAO) FindRegionCityName(id uint32) (string, error) {
Result("name").
FindStringCol("")
}
// 根据数据ID查找城市
func (this *RegionCityDAO) FindCityWithDataId(dataId string) (int64, error) {
return this.Query().
Attr("dataId", dataId).
ResultPk().
FindInt64Col(0)
}
// 创建城市
func (this *RegionCityDAO) CreateCity(provinceId int64, name string, dataId string) (int64, error) {
op := NewRegionCityOperator()
op.ProvinceId = provinceId
op.Name = name
op.DataId = dataId
op.State = RegionCityStateEnabled
codes := []string{name}
codesJSON, err := json.Marshal(codes)
if err != nil {
return 0, err
}
op.Codes = codesJSON
_, err = this.Save(op)
if err != nil {
return 0, err
}
return types.Int64(op.Id), nil
}

View File

@@ -7,6 +7,7 @@ type RegionCity struct {
Name string `field:"name"` // 名称
Codes string `field:"codes"` // 代号
State uint8 `field:"state"` // 状态
DataId string `field:"dataId"` // 原始数据ID
}
type RegionCityOperator struct {
@@ -15,6 +16,7 @@ type RegionCityOperator struct {
Name interface{} // 名称
Codes interface{} // 代号
State interface{} // 状态
DataId interface{} // 原始数据ID
}
func NewRegionCityOperator() *RegionCityOperator {

View File

@@ -1,9 +1,13 @@
package models
import (
"encoding/json"
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/types"
"github.com/mozillazg/go-pinyin"
"strings"
)
const (
@@ -42,7 +46,7 @@ func (this *RegionCountryDAO) EnableRegionCountry(id uint32) error {
}
// 禁用条目
func (this *RegionCountryDAO) DisableRegionCountry(id uint32) error {
func (this *RegionCountryDAO) DisableRegionCountry(id int64) error {
_, err := this.Query().
Pk(id).
Set("state", RegionCountryStateDisabled).
@@ -51,7 +55,7 @@ func (this *RegionCountryDAO) DisableRegionCountry(id uint32) error {
}
// 查找启用中的条目
func (this *RegionCountryDAO) FindEnabledRegionCountry(id uint32) (*RegionCountry, error) {
func (this *RegionCountryDAO) FindEnabledRegionCountry(id int64) (*RegionCountry, error) {
result, err := this.Query().
Pk(id).
Attr("state", RegionCountryStateEnabled).
@@ -63,9 +67,56 @@ func (this *RegionCountryDAO) FindEnabledRegionCountry(id uint32) (*RegionCountr
}
// 根据主键查找名称
func (this *RegionCountryDAO) FindRegionCountryName(id uint32) (string, error) {
func (this *RegionCountryDAO) FindRegionCountryName(id int64) (string, error) {
return this.Query().
Pk(id).
Result("name").
FindStringCol("")
}
// 根据数据ID查找国家
func (this *RegionCountryDAO) FindCountryIdWithDataId(dataId string) (int64, error) {
return this.Query().
Attr("dataId", dataId).
ResultPk().
FindInt64Col(0)
}
// 根据数据ID创建国家
func (this *RegionCountryDAO) CreateCountry(name string, dataId string) (int64, error) {
op := NewRegionCountryOperator()
op.Name = name
pinyinPieces := pinyin.Pinyin(name, pinyin.NewArgs())
pinyinResult := []string{}
for _, piece := range pinyinPieces {
pinyinResult = append(pinyinResult, strings.Join(piece, " "))
}
pinyinJSON, err := json.Marshal([]string{strings.Join(pinyinResult, " ")})
op.Pinyin = pinyinJSON
codes := []string{name}
codesJSON, err := json.Marshal(codes)
if err != nil {
return 0, err
}
op.Codes = codesJSON
op.DataId = dataId
op.State = RegionCountryStateEnabled
_, err = this.Save(op)
if err != nil {
return 0, err
}
return types.Int64(op.Id), nil
}
// 查找所有可用的国家
func (this *RegionCountryDAO) FindAllEnabledCountriesOrderByPinyin() (result []*RegionCountry, err error) {
_, err = this.Query().
State(RegionCountryStateEnabled).
Slice(&result).
Asc("pinyin").
FindAll()
return
}

View File

@@ -2,17 +2,21 @@ package models
//
type RegionCountry struct {
Id uint32 `field:"id"` // ID
Name string `field:"name"` // 名称
Codes string `field:"codes"` // 代号
State uint8 `field:"state"` // 状态
Id uint32 `field:"id"` // ID
Name string `field:"name"` // 名称
Codes string `field:"codes"` // 代号
State uint8 `field:"state"` // 状态
DataId string `field:"dataId"` // 原始数据ID
Pinyin string `field:"pinyin"` // 拼音
}
type RegionCountryOperator struct {
Id interface{} // ID
Name interface{} // 名称
Codes interface{} // 代号
State interface{} // 状态
Id interface{} // ID
Name interface{} // 名称
Codes interface{} // 代号
State interface{} // 状态
DataId interface{} // 原始数据ID
Pinyin interface{} // 拼音
}
func NewRegionCountryOperator() *RegionCountryOperator {

View File

@@ -1,9 +1,11 @@
package models
import (
"encoding/json"
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/types"
)
const (
@@ -69,3 +71,43 @@ func (this *RegionProvinceDAO) FindRegionProvinceName(id uint32) (string, error)
Result("name").
FindStringCol("")
}
// 根据数据ID查找省份
func (this *RegionProvinceDAO) FindProvinceIdWithDataId(dataId string) (int64, error) {
return this.Query().
Attr("dataId", dataId).
ResultPk().
FindInt64Col(0)
}
// 创建省份
func (this *RegionProvinceDAO) CreateProvince(countryId int64, name string, dataId string) (int64, error) {
op := NewRegionProvinceOperator()
op.CountryId = countryId
op.Name = name
op.DataId = dataId
op.State = RegionProvinceStateEnabled
codes := []string{name}
codesJSON, err := json.Marshal(codes)
if err != nil {
return 0, err
}
op.Codes = codesJSON
_, err = this.Save(op)
if err != nil {
return 0, err
}
return types.Int64(op.Id), nil
}
// 查找所有省份
func (this *RegionProvinceDAO) FindAllEnabledProvincesWithCountryId(countryId int64) (result []*RegionProvince, err error) {
_, err = this.Query().
State(RegionProvinceStateEnabled).
Attr("countryId", countryId).
Asc("name").
Slice(&result).
FindAll()
return
}

View File

@@ -7,6 +7,7 @@ type RegionProvince struct {
Name string `field:"name"` // 名称
Codes string `field:"codes"` // 代号
State uint8 `field:"state"` // 状态
DataId string `field:"dataId"` // 原始数据ID
}
type RegionProvinceOperator struct {
@@ -15,6 +16,7 @@ type RegionProvinceOperator struct {
Name interface{} // 名称
Codes interface{} // 代号
State interface{} // 状态
DataId interface{} // 原始数据ID
}
func NewRegionProvinceOperator() *RegionProvinceOperator {