provider_threshold.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package provider
  2. import (
  3. "context"
  4. "gd_management/apis"
  5. "gd_management/errors"
  6. "fmt"
  7. "github.com/astaxie/beego/orm"
  8. "strconv"
  9. )
  10. func parseFloat(data float64) float64 {
  11. s := fmt.Sprintf("%.2f", data)
  12. ret, _ := strconv.ParseFloat(s, 32)
  13. return ret
  14. }
  15. func ManagementSetProviderThreshold(ctx context.Context, req *apis.ManagementSetProviderThresholdReq, reply *apis.ManagementSetProviderThresholdReply) (err error) {
  16. if req.ThresholdFailRate > 1 ||
  17. req.ThresholdFailRate < 0 ||
  18. req.ThresholdNorecordRate > 1 ||
  19. req.ThresholdNorecordRate < 0 ||
  20. req.ThresholdTimeout < 0 {
  21. return errors.ArgsError
  22. }
  23. o := orm.NewOrm()
  24. sql := "update t_gd_provider_api set warning_enable=?"
  25. if req.ThresholdFailRate > 0 {
  26. sql = fmt.Sprintf("%s, threshold_fail_rate=%f", sql, req.ThresholdFailRate)
  27. }
  28. if req.ThresholdNorecordRate > 0 {
  29. sql = fmt.Sprintf("%s, threshold_norecord_rate=%f", sql, req.ThresholdNorecordRate)
  30. }
  31. if req.ThresholdTimeout > 0 {
  32. sql = fmt.Sprintf("%s, threshold_timeout=%d", sql, req.ThresholdTimeout)
  33. }
  34. sql = fmt.Sprintf("%s where id=?", sql)
  35. _, err = o.Raw(sql, req.WarningEnable, req.ProviderApiId).Exec()
  36. if err != nil {
  37. return errors.DataBaseError
  38. }
  39. return nil
  40. }