config_service.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package config_service
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/cloudwego/hertz/pkg/app"
  6. "github.com/cloudwego/hertz/pkg/protocol/consts"
  7. "pji_desktop_http/biz/dal/mysql"
  8. "pji_desktop_http/common/entity"
  9. "strconv"
  10. )
  11. // QueryRescanReminderThreshold 查询续扫阈值
  12. // @router /config/query/rescanReminderThreshold [GET]
  13. func QueryRescanReminderThreshold(ctx context.Context, c *app.RequestContext) {
  14. systemConfig, err := mysql.QuerySystemConfig(ctx)
  15. if err != nil {
  16. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取系统配置失败"})
  17. return
  18. }
  19. c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "获取续扫阈值成功", Data: strconv.FormatFloat(float64(systemConfig.RescanReminderThreshold), 'f', 2, 32)})
  20. }
  21. // UpdateRescanReminderThreshold 更新续扫阈值
  22. // @router /config/update/rescanReminderThreshold [GET]
  23. func UpdateRescanReminderThreshold(ctx context.Context, c *app.RequestContext) {
  24. threshold := c.Query("threshold")
  25. fmt.Println("threshold", threshold)
  26. config, err := mysql.QuerySystemConfig(ctx)
  27. if err != nil {
  28. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取系统配置失败"})
  29. return
  30. }
  31. newVal, err := strconv.ParseFloat(threshold, 32)
  32. if err != nil {
  33. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "数据格式转换失败"})
  34. return
  35. }
  36. config.RescanReminderThreshold = float32(newVal)
  37. _, err = mysql.UpdateSystemConfig(ctx, config)
  38. if err != nil {
  39. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新续扫阈值失败"})
  40. return
  41. }
  42. c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "更新续扫阈值成功"})
  43. }