From facff46bb6b0b4ebc1a22b2883bfb104ccde6372 Mon Sep 17 00:00:00 2001 From: MichaelWin Date: Mon, 9 Feb 2026 12:32:23 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=94=B9=E8=BF=9B=E3=80=91=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=B8=AD=E5=BF=83=E5=A2=9E=E5=8A=A0=E6=AC=A1=E6=95=B0?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/AppParamsCenterController.java | 20 +++++++++++++++---- .../resources/i18n/messages_en_US.properties | 1 + .../resources/i18n/messages_zh_CN.properties | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/corewing/app/modules/app/AppParamsCenterController.java b/src/main/java/com/corewing/app/modules/app/AppParamsCenterController.java index 76e6bfa..72709e5 100644 --- a/src/main/java/com/corewing/app/modules/app/AppParamsCenterController.java +++ b/src/main/java/com/corewing/app/modules/app/AppParamsCenterController.java @@ -9,13 +9,16 @@ import com.corewing.app.dto.UpdateParamRequest; import com.corewing.app.entity.ParamsCenter; import com.corewing.app.service.ParamsCenterService; import com.corewing.app.util.I18nUtil; +import com.corewing.app.util.RedisUtil; import com.corewing.app.vo.ParamsCenterVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import javax.validation.Valid; import java.util.List; +import java.util.concurrent.TimeUnit; /** * 参数配置中心 Controller @@ -25,11 +28,11 @@ import java.util.List; @RequestMapping("/params") public class AppParamsCenterController { - private final ParamsCenterService paramsService; + @Resource + private ParamsCenterService paramsService; - public AppParamsCenterController(ParamsCenterService paramsService) { - this.paramsService = paramsService; - } + @Resource + private RedisUtil redisUtil; /** * 创建参数配置 @@ -225,6 +228,15 @@ public class AppParamsCenterController { @PostMapping("/{id}/download") public Result incrementDownloadCount(@PathVariable Long id) { try { + + Object loginId = StpUtil.getLoginId(); + boolean isNew = redisUtil.setIfAbsent("paramCenter_" + loginId, 1, 1, TimeUnit.DAYS); + // 如果键已存在,递增计数器 + long sendCount = isNew ? 1 : redisUtil.incr("paramCenter_" + loginId, 1); + if(sendCount > 3) { + return Result.error(I18nUtil.getMessage("params.download.exceed")); + } + ParamsCenter params = paramsService.getById(id); if (params == null) { return Result.error(I18nUtil.getMessage("params.not.found")); diff --git a/src/main/resources/i18n/messages_en_US.properties b/src/main/resources/i18n/messages_en_US.properties index 68a0814..7e7ff3d 100644 --- a/src/main/resources/i18n/messages_en_US.properties +++ b/src/main/resources/i18n/messages_en_US.properties @@ -130,6 +130,7 @@ params.not.found=Parameter not found params.no.permission=No permission to operate this parameter params.download.success=Download successful params.download.failed=Download failed +params.download.exceed=Exceeded the number of downloads # ==================== Firmware Management Module ==================== # Firmware Controller diff --git a/src/main/resources/i18n/messages_zh_CN.properties b/src/main/resources/i18n/messages_zh_CN.properties index f1ce2f3..eedf7cf 100644 --- a/src/main/resources/i18n/messages_zh_CN.properties +++ b/src/main/resources/i18n/messages_zh_CN.properties @@ -130,6 +130,7 @@ params.not.found=参数不存在 params.no.permission=无权限操作该参数 params.download.success=下载成功 params.download.failed=下载失败 +params.download.exceed=超出次数下载 # ==================== 固件管理模块 ==================== # 固件Controller