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