【改进】参数中心增加次数下载限制

This commit is contained in:
MichaelWin
2026-02-09 12:32:23 +08:00
parent 71589ab13a
commit facff46bb6
3 changed files with 18 additions and 4 deletions

View File

@@ -9,13 +9,16 @@ import com.corewing.app.dto.UpdateParamRequest;
import com.corewing.app.entity.ParamsCenter; import com.corewing.app.entity.ParamsCenter;
import com.corewing.app.service.ParamsCenterService; import com.corewing.app.service.ParamsCenterService;
import com.corewing.app.util.I18nUtil; import com.corewing.app.util.I18nUtil;
import com.corewing.app.util.RedisUtil;
import com.corewing.app.vo.ParamsCenterVO; import com.corewing.app.vo.ParamsCenterVO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
/** /**
* 参数配置中心 Controller * 参数配置中心 Controller
@@ -25,11 +28,11 @@ import java.util.List;
@RequestMapping("/params") @RequestMapping("/params")
public class AppParamsCenterController { public class AppParamsCenterController {
private final ParamsCenterService paramsService; @Resource
private ParamsCenterService paramsService;
public AppParamsCenterController(ParamsCenterService paramsService) { @Resource
this.paramsService = paramsService; private RedisUtil redisUtil;
}
/** /**
* 创建参数配置 * 创建参数配置
@@ -225,6 +228,15 @@ public class AppParamsCenterController {
@PostMapping("/{id}/download") @PostMapping("/{id}/download")
public Result<String> incrementDownloadCount(@PathVariable Long id) { public Result<String> incrementDownloadCount(@PathVariable Long id) {
try { 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); ParamsCenter params = paramsService.getById(id);
if (params == null) { if (params == null) {
return Result.error(I18nUtil.getMessage("params.not.found")); return Result.error(I18nUtil.getMessage("params.not.found"));

View File

@@ -130,6 +130,7 @@ params.not.found=Parameter not found
params.no.permission=No permission to operate this parameter params.no.permission=No permission to operate this parameter
params.download.success=Download successful params.download.success=Download successful
params.download.failed=Download failed params.download.failed=Download failed
params.download.exceed=Exceeded the number of downloads
# ==================== Firmware Management Module ==================== # ==================== Firmware Management Module ====================
# Firmware Controller # Firmware Controller

View File

@@ -130,6 +130,7 @@ params.not.found=参数不存在
params.no.permission=无权限操作该参数 params.no.permission=无权限操作该参数
params.download.success=下载成功 params.download.success=下载成功
params.download.failed=下载失败 params.download.failed=下载失败
params.download.exceed=超出次数下载
# ==================== 固件管理模块 ==================== # ==================== 固件管理模块 ====================
# 固件Controller # 固件Controller