临时添加混拨配置创建功能
This commit is contained in:
@@ -33,3 +33,16 @@ func UpdateConfigs(tx *gorm.DB, configs []model.ConfigUpdate) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateConfigs(tx *gorm.DB, configs []model.ConfigCreate) error {
|
||||
if len(configs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := tx.CreateInBatches(&configs, 500).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
55
actions/gen.go
Normal file
55
actions/gen.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"zzman/model"
|
||||
|
||||
u "zzman/util"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func GenConfig(tx *gorm.DB) error {
|
||||
|
||||
gateways, err := FindGateways(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cities, err := FindCitiesWithEdgesCount(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
configs := make([]model.ConfigCreate, len(gateways)*30)
|
||||
for iGateway := range gateways {
|
||||
for j := range 30 {
|
||||
n := iGateway*30 + j
|
||||
iCity := (iGateway*30 + j) % len(cities)
|
||||
gateway := gateways[iGateway]
|
||||
city := cities[iCity]
|
||||
|
||||
configs[n] = model.ConfigCreate{
|
||||
Table: u.P(strconv.Itoa(j + 221)),
|
||||
Cityhash: &city.Hash,
|
||||
CityLabel: &city.Label,
|
||||
Network: u.P(fmt.Sprintf("172.30.168.%d", j+222)),
|
||||
GatewayMac: &gateway.Macaddr,
|
||||
User: u.P(fmt.Sprintf("jdzz%ddt%d", iGateway+1, j+221)),
|
||||
InnerIp: u.P(fmt.Sprintf("%s%d", gateway.ProxyIp, j+222)),
|
||||
EdgeMac: u.P(""),
|
||||
IsChange: u.P(1),
|
||||
IsOnline: u.P(0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println(fmt.Sprintf("生成配置:%d 条", len(configs)))
|
||||
err = CreateConfigs(tx, configs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user