package provider import ( "context" "gd_management/apis" "gd_management/errors" "fmt" "github.com/astaxie/beego/orm" "strconv" ) func parseFloat(data float64) float64 { s := fmt.Sprintf("%.2f", data) ret, _ := strconv.ParseFloat(s, 32) return ret } func ManagementSetProviderThreshold(ctx context.Context, req *apis.ManagementSetProviderThresholdReq, reply *apis.ManagementSetProviderThresholdReply) (err error) { if req.ThresholdFailRate > 1 || req.ThresholdFailRate < 0 || req.ThresholdNorecordRate > 1 || req.ThresholdNorecordRate < 0 || req.ThresholdTimeout < 0 { return errors.ArgsError } o := orm.NewOrm() sql := "update t_gd_provider_api set warning_enable=?" if req.ThresholdFailRate > 0 { sql = fmt.Sprintf("%s, threshold_fail_rate=%f", sql, req.ThresholdFailRate) } if req.ThresholdNorecordRate > 0 { sql = fmt.Sprintf("%s, threshold_norecord_rate=%f", sql, req.ThresholdNorecordRate) } if req.ThresholdTimeout > 0 { sql = fmt.Sprintf("%s, threshold_timeout=%d", sql, req.ThresholdTimeout) } sql = fmt.Sprintf("%s where id=?", sql) _, err = o.Raw(sql, req.WarningEnable, req.ProviderApiId).Exec() if err != nil { return errors.DataBaseError } return nil }