package config_service import ( "context" "fmt" "github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/protocol/consts" "pji_desktop_http/biz/dal/mysql" "pji_desktop_http/common/entity" "strconv" ) // QueryRescanReminderThreshold 查询续扫阈值 // @router /config/query/rescanReminderThreshold [GET] func QueryRescanReminderThreshold(ctx context.Context, c *app.RequestContext) { systemConfig, err := mysql.QuerySystemConfig(ctx) if err != nil { c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取系统配置失败"}) return } c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "获取续扫阈值成功", Data: strconv.FormatFloat(float64(systemConfig.RescanReminderThreshold), 'f', 2, 32)}) } // UpdateRescanReminderThreshold 更新续扫阈值 // @router /config/update/rescanReminderThreshold [GET] func UpdateRescanReminderThreshold(ctx context.Context, c *app.RequestContext) { threshold := c.Query("threshold") fmt.Println("threshold", threshold) config, err := mysql.QuerySystemConfig(ctx) if err != nil { c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取系统配置失败"}) return } newVal, err := strconv.ParseFloat(threshold, 32) if err != nil { c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "数据格式转换失败"}) return } config.RescanReminderThreshold = float32(newVal) _, err = mysql.UpdateSystemConfig(ctx, config) if err != nil { c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新续扫阈值失败"}) return } c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "更新续扫阈值成功"}) }