每日下载次数限制,重置密码接口调整

pull/1121/head
梁宇奇 2025-10-13 17:21:32 +08:00
parent eb80dd4784
commit b26feec4ea
3 changed files with 21 additions and 1 deletions

View File

@ -300,6 +300,10 @@ public class CacheConstants {
* *
*/ */
public static final String PIC_PACK_USER_REQ_COUNT_CACHE = "pic_pack_user_req_count_cache:"; public static final String PIC_PACK_USER_REQ_COUNT_CACHE = "pic_pack_user_req_count_cache:";
/**
*
*/
public static final String PIC_PACK_USER_DAILY_REQ_COUNT_CACHE = "pic_pack_user_daily_req_count_cache:";
/** /**
* *
*/ */

View File

@ -179,9 +179,12 @@ public class SysUserServiceImpl implements ISysUserService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public String resetPassword(Long userId, String password) { public String resetPassword(Long userId, String password) {
if (userId == null || StrUtil.isEmpty(password)) { if (userId == null) {
return null; return null;
} }
if (StrUtil.isEmpty(password)) {
password = configService.selectConfigByKey("sys.user.initPassword");
}
SysUser user = userMapper.selectById(userId); SysUser user = userMapper.selectById(userId);
user.setPassword(SecurityUtils.encryptPassword(password)); user.setPassword(SecurityUtils.encryptPassword(password));
updateUserBase(user, true); updateUserBase(user, true);

View File

@ -67,6 +67,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -640,7 +641,13 @@ public class StoreProductServiceImpl implements IStoreProductService {
public PicPackInfoDTO getPicPackDownloadUrl(PicPackReqDTO picPackReqDTO) { public PicPackInfoDTO getPicPackDownloadUrl(PicPackReqDTO picPackReqDTO) {
Assert.notNull(picPackReqDTO.getUserId()); Assert.notNull(picPackReqDTO.getUserId());
String reqCacheKey = CacheConstants.PIC_PACK_USER_REQ_COUNT_CACHE + picPackReqDTO.getUserId(); String reqCacheKey = CacheConstants.PIC_PACK_USER_REQ_COUNT_CACHE + picPackReqDTO.getUserId();
String dailyReqCacheKey = CacheConstants.PIC_PACK_USER_DAILY_REQ_COUNT_CACHE + picPackReqDTO.getUserId();
int reqCount = Optional.ofNullable((Integer) redisCache.getCacheObject(reqCacheKey)).orElse(0); int reqCount = Optional.ofNullable((Integer) redisCache.getCacheObject(reqCacheKey)).orElse(0);
int dailyReqCount = Optional.ofNullable((Integer) redisCache.getCacheObject(dailyReqCacheKey)).orElse(0);
//每日下载次数限制50次
if (dailyReqCount > 49) {
throw new ServiceException("您今日的免费下载限额(50款/日)已用完,请明日再来!如需扩大下载限额,请联系平台客服");
}
//5次请求后需要输入验证码 //5次请求后需要输入验证码
if (reqCount > 4) { if (reqCount > 4) {
//需验证验证码 //需验证验证码
@ -669,6 +676,12 @@ public class StoreProductServiceImpl implements IStoreProductService {
} }
//请求次数+1 //请求次数+1
redisCache.setCacheObject(reqCacheKey, reqCount + 1); redisCache.setCacheObject(reqCacheKey, reqCount + 1);
redisCache.setCacheObject(dailyReqCacheKey, dailyReqCount + 1);
if (0 == dailyReqCount) {
//每日首次下载
long expire = DateUtil.endOfDay(new Date()).getTime() - System.currentTimeMillis();
redisCache.expire(dailyReqCacheKey, expire, TimeUnit.MILLISECONDS);
}
return new PicPackInfoDTO(file.getId(), file.getFileName(), file.getFileUrl(), file.getFileSize(), downloadUrl, false); return new PicPackInfoDTO(file.getId(), file.getFileName(), file.getFileUrl(), file.getFileSize(), downloadUrl, false);
} }