不同地区提取合并自动配置
This commit is contained in:
@@ -308,6 +308,16 @@ func (s *channelService) CreateChannel(
|
||||
// 更新套餐使用记录
|
||||
step = time.Now()
|
||||
|
||||
toUpdate := models.ResourcePss{
|
||||
Used: resource.Used + int32(count),
|
||||
DailyLast: now,
|
||||
}
|
||||
last := resource.DailyLast
|
||||
if now.Year() != last.Year() || now.Month() != last.Month() || now.Day() != last.Day() {
|
||||
toUpdate.DailyUsed = int32(count)
|
||||
} else {
|
||||
toUpdate.DailyUsed = resource.DailyUsed + int32(count)
|
||||
}
|
||||
_, err = q.ResourcePss.
|
||||
Where(q.ResourcePss.ResourceID.Eq(resourceId)).
|
||||
Select(
|
||||
@@ -315,11 +325,7 @@ func (s *channelService) CreateChannel(
|
||||
q.ResourcePss.DailyUsed,
|
||||
q.ResourcePss.DailyLast,
|
||||
).
|
||||
Updates(models.ResourcePss{
|
||||
Used: resource.Used + int32(count),
|
||||
DailyUsed: resource.DailyUsed + int32(count),
|
||||
DailyLast: now,
|
||||
})
|
||||
Updates(toUpdate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -468,15 +474,33 @@ func assignEdge(count int, filter NodeFilterConfig) (*AssignEdgeResult, error) {
|
||||
step = time.Now()
|
||||
|
||||
slog.Debug("新增新节点", "proxy", info.proxy.Name, "used", info.used, "count", info.count)
|
||||
|
||||
rConfigs := rProxyConfigs[info.proxy.Name]
|
||||
|
||||
var newConfig = remote.AutoConfig{
|
||||
Province: filter.Prov,
|
||||
City: filter.City,
|
||||
Isp: filter.Isp,
|
||||
Count: int(math.Ceil(float64(info.used) * 11 / 10)),
|
||||
}
|
||||
var newConfigs []remote.AutoConfig
|
||||
var update = false
|
||||
for _, rConfig := range rConfigs {
|
||||
if rConfig.Isp == filter.Isp && rConfig.City == filter.City && rConfig.Province == filter.Prov {
|
||||
newConfigs = append(newConfigs, newConfig)
|
||||
update = true
|
||||
} else {
|
||||
newConfigs = append(newConfigs, rConfig)
|
||||
}
|
||||
}
|
||||
if !update {
|
||||
newConfigs = append(newConfigs, newConfig)
|
||||
}
|
||||
|
||||
err := remote.Cloud.CloudConnect(remote.CloudConnectReq{
|
||||
Uuid: info.proxy.Name,
|
||||
Edge: nil,
|
||||
AutoConfig: []remote.AutoConfig{{
|
||||
Province: filter.Prov,
|
||||
City: filter.City,
|
||||
Isp: filter.Isp,
|
||||
Count: int(math.Ceil(float64(info.used) * 11 / 10)),
|
||||
}},
|
||||
Uuid: info.proxy.Name,
|
||||
Edge: nil,
|
||||
AutoConfig: newConfigs,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -475,6 +475,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
wantErr: true,
|
||||
wantErrContains: "端口数量不足",
|
||||
},
|
||||
// todo 跨天用量更新
|
||||
// todo 多地区混杂条件提取
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -510,14 +512,6 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
// 检查返回地址格式
|
||||
for _, addr := range got {
|
||||
protocol := string(tt.args.protocol)
|
||||
if !strings.HasPrefix(addr, protocol+"://") {
|
||||
t.Errorf("CreateChannel() 地址 %v 不是有效的 %s 地址", addr, protocol)
|
||||
}
|
||||
}
|
||||
|
||||
// 查询创建的通道
|
||||
var channels []models.Channel
|
||||
db.Where(
|
||||
|
||||
Reference in New Issue
Block a user