feat:2、刷新绑定信息,操作加一个刷新绑定状态的按钮,3、绑定错误有提示,手动上报异常,拿到包ID做链接跳转(定位)
This commit is contained in:
@@ -55,12 +55,23 @@ type RockDashboardResult struct {
|
||||
CostUpdated bool `json:"cost_updated"`
|
||||
}
|
||||
|
||||
// RockConfigValidationError 表示 Rock 配置参数不合法,handler 会转成 400。
|
||||
type RockConfigValidationError struct {
|
||||
Message string
|
||||
}
|
||||
|
||||
func (e *RockConfigValidationError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
type UpdateRockConfigReq struct {
|
||||
AutoDeliveryEnabled *bool `json:"auto_delivery_enabled"`
|
||||
BaseURL *string `json:"base_url"`
|
||||
BearerToken *string `json:"bearer_token"`
|
||||
MinPointsWarning *float64 `json:"min_points_warning"`
|
||||
TokenWarningStock *int `json:"token_warning_stock"`
|
||||
UsingWarnDays *int `json:"using_warn_days"`
|
||||
UsingDangerDays *int `json:"using_danger_days"`
|
||||
AutoPurchaseEnabled *bool `json:"auto_purchase_enabled"`
|
||||
AutoPurchaseCount *int `json:"auto_purchase_count"`
|
||||
PurchaseCooldownMinutes *int `json:"purchase_cooldown_minutes"`
|
||||
@@ -79,6 +90,8 @@ func (s *RockService) GetConfig(ctx context.Context) (*model.RockConfig, error)
|
||||
MinPointsWarning: 1050.00,
|
||||
BlackTokenCost: 20.00,
|
||||
TokenWarningStock: 10,
|
||||
UsingWarnDays: 3,
|
||||
UsingDangerDays: 5,
|
||||
AutoPurchaseEnabled: false,
|
||||
AutoPurchaseCount: 50,
|
||||
PurchaseCooldownMinutes: 10,
|
||||
@@ -142,6 +155,27 @@ func (s *RockService) UpdateConfig(ctx context.Context, req UpdateRockConfigReq)
|
||||
updates["purchase_cooldown_minutes"] = *req.PurchaseCooldownMinutes
|
||||
}
|
||||
|
||||
// 使用中超时预警阈值:橙色必须小于红色,否则前端无法区分两级。
|
||||
warnDays := cfg.UsingWarnDays
|
||||
if req.UsingWarnDays != nil {
|
||||
warnDays = *req.UsingWarnDays
|
||||
updates["using_warn_days"] = warnDays
|
||||
}
|
||||
dangerDays := cfg.UsingDangerDays
|
||||
if req.UsingDangerDays != nil {
|
||||
dangerDays = *req.UsingDangerDays
|
||||
updates["using_danger_days"] = dangerDays
|
||||
}
|
||||
if warnDays < 1 || warnDays > 365 {
|
||||
return nil, &RockConfigValidationError{Message: "使用中橙色预警天数必须在 1-365 之间"}
|
||||
}
|
||||
if dangerDays < 1 || dangerDays > 365 {
|
||||
return nil, &RockConfigValidationError{Message: "使用中红色预警天数必须在 1-365 之间"}
|
||||
}
|
||||
if dangerDays <= warnDays {
|
||||
return nil, &RockConfigValidationError{Message: "使用中红色预警天数必须大于橙色预警天数"}
|
||||
}
|
||||
|
||||
if len(updates) > 0 {
|
||||
updates["updated_at"] = time.Now()
|
||||
if err := s.db.WithContext(ctx).Model(&model.RockConfig{}).Where("id = ?", cfg.ID).Updates(updates).Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user