Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
Tankaikai 2024-12-26 13:57:38 +08:00
commit 16b158e5e1
4 changed files with 152 additions and 8 deletions

View File

@ -0,0 +1,142 @@
package com.sqx.common.utils;
import cn.hutool.core.date.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* 数据出现次数
*/
@Component
public class DataLimitUtil {
private static final String ACCESS_COUNT_KEY_PREFIX = "sys:data:";
private static RedisUtils redisUtils;
private static final int DEFAULT_ACCESS_COUNT = 5;
private static final String DATE_TIME_FORMAT = "month";
@Autowired
public void setRedisUtils(RedisUtils redisUtils) {
DataLimitUtil.redisUtils = redisUtils;
}
/**
* 默认 当月5次
* @param key 名称 sys:data:名称
* @return
*/
public static boolean isAccessAllowed(String key) {
String redisKey = generateRedisKey(key);
Object countObj = redisUtils.get(redisKey);
if (countObj == null) {
// 根据不同时间周期设置过期时间并初始化访问次数为1
long expireAt = calculateExpireAt(DATE_TIME_FORMAT);
redisUtils.set(redisKey, 1, expireAt);
return true;
}
if ((int) countObj < DEFAULT_ACCESS_COUNT) {
// 访问次数未达上限次数加1
redisUtils.incr(redisKey);
return true;
}
return false;
}
/**
* 默认月 month//自然月
* @param key 名称 sys:data:名称
* @param count 次数限制
* @return
*/
public static boolean isAccessAllowed(String key, Integer count) {
String redisKey = generateRedisKey(key);
Object countObj = redisUtils.get(redisKey);
if (countObj == null) {
// 根据不同时间周期设置过期时间并初始化访问次数为1
long expireAt = calculateExpireAt(DATE_TIME_FORMAT);
redisUtils.set(redisKey, 1, expireAt);
return true;
}
if ((int) countObj < count) {
// 访问次数未达上限次数加1
redisUtils.incr(redisKey);
return true;
}
return false;
}
/**
* 默认 5次
* @param key 名称 sys:data:名称
* @param timeFormat day//自然天 week//本周日 month//自然月 year//自然年
* @return
*/
public static boolean isAccessAllowed(String key, String timeFormat) {
String redisKey = generateRedisKey(key);
Object countObj = redisUtils.get(redisKey);
if (countObj == null) {
// 根据不同时间周期设置过期时间并初始化访问次数为1
long expireAt = calculateExpireAt(timeFormat);
redisUtils.set(redisKey, 1, expireAt);
return true;
}
if ((int) countObj < DEFAULT_ACCESS_COUNT) {
// 访问次数未达上限次数加1
redisUtils.incr(redisKey);
return true;
}
return false;
}
/**
* @param key 名称 sys:data:名称
* @param count 次数限制
* @param timeFormat day//自然天 week//本周日 month//自然月 year//自然年
* @return
*/
public static boolean isAccessAllowed(String key, Integer count, String timeFormat) {
String redisKey = generateRedisKey(key);
Object countObj = redisUtils.get(redisKey);
if (countObj == null) {
// 根据不同时间周期设置过期时间并初始化访问次数为1
long expireAt = calculateExpireAt(timeFormat);
redisUtils.set(redisKey, 1, expireAt);
return true;
}
if (Integer.parseInt(countObj.toString()) < count) {
// 访问次数未达上限次数加1
redisUtils.incr(redisKey);
return true;
}
return false;
}
private static String generateRedisKey(String key) {
return ACCESS_COUNT_KEY_PREFIX + key;
}
private static long calculateExpireAt(String timePeriod) {
Date now = DateUtil.beginOfDay(DateUtil.date());
Date expireDate = null;
if ("day".equals(timePeriod)) {
expireDate = DateUtil.endOfDay(now);
} else if ("week".equals(timePeriod)) {
expireDate = DateUtil.endOfWeek(now);
} else if ("month".equals(timePeriod)) {
expireDate = DateUtil.endOfMonth(now);
} else if ("year".equals(timePeriod)) {
expireDate = DateUtil.endOfYear(now);
}
long endTimeStamp = DateUtil.endOfDay(expireDate).getTime() / 1000L;
long currentTimeStamp = DateUtil.currentSeconds();
return endTimeStamp - currentTimeStamp;
}
}

View File

@ -4,7 +4,9 @@ package com.sqx.modules.app.controller.app;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sqx.common.annotation.Debounce;
import com.sqx.common.utils.ApiAccessLimitUtil;
import com.sqx.common.utils.DataLimitUtil;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.app.annotation.LoginUser;
@ -73,10 +75,14 @@ public class AppController {
@RequestMapping(value = "/updateUser", method = RequestMethod.POST)
@ApiOperation("用户修改个人信息")
@ResponseBody
@Debounce(interval = 3000, value = "#userId")
public Result updateUserImageUrl(@RequestAttribute("userId") Long userId, String zhiFuBao, String zhiFuBaoName) {
if(StrUtil.isEmpty(zhiFuBao) || StrUtil.isEmpty(zhiFuBaoName)){
if (StrUtil.isEmpty(zhiFuBao) || StrUtil.isEmpty(zhiFuBaoName)) {
return Result.error("支付宝账户及姓名不能为空!");
}
if (!DataLimitUtil.isAccessAllowed(zhiFuBao+zhiFuBaoName, 1, "month")) {
return Result.error("修改失败,相同支付宝账号每月仅可绑定一次");
}
int count = userService.count(new QueryWrapper<UserEntity>()
.ne("user_id", userId)
.eq("zhi_fu_bao_name", zhiFuBaoName)

View File

@ -159,11 +159,7 @@ public class InviteServiceImpl extends ServiceImpl<InviteDao, Invite> implements
// 金币
int money = Integer.parseInt(commonInfoService.findOne(911).getValue());
if (money > 0) {
UpdateWrapper<UserMoney> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("user_id", userEntity.getUserId())
.setSql("money = money + " + money);
userMoneyService.update(updateWrapper);
userMoneyService.updateMoney(1, userEntity.getUserId(), money);
UserMoneyDetails userMoneyDetails = new UserMoneyDetails();
userMoneyDetails.setUserId(userEntity.getUserId());
userMoneyDetails.setType(1);
@ -316,7 +312,7 @@ public class InviteServiceImpl extends ServiceImpl<InviteDao, Invite> implements
BigDecimal rateMoney = sysUserEntity.getQdRate();
BigDecimal sumMoney = rateMoney.subtract(oneMoney);
sumMoney = sumMoney.subtract(twoMoney);
if (sumMoney.compareTo(BigDecimal.ZERO)<=0) {
if (sumMoney.compareTo(BigDecimal.ZERO) <= 0) {
return result;
}
userMoneyService.updateSysAmount(1, sysUserEntity.getUserId(), sumMoney.doubleValue());

View File

@ -11,7 +11,7 @@ server:
connection-timeout: 5000ms
port: 8100
servlet:
context-path: /sqx_fast
context-path: /czg
spring:
main: