【改进】参数中心增加次数下载限制
This commit is contained in:
@@ -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<String> 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"));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -130,6 +130,7 @@ params.not.found=参数不存在
|
||||
params.no.permission=无权限操作该参数
|
||||
params.download.success=下载成功
|
||||
params.download.failed=下载失败
|
||||
params.download.exceed=超出次数下载
|
||||
|
||||
# ==================== 固件管理模块 ====================
|
||||
# 固件Controller
|
||||
|
||||
Reference in New Issue
Block a user