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

This commit is contained in:
Tankaikai 2025-01-07 13:15:29 +08:00
commit 0084d6be0f
9 changed files with 105 additions and 119 deletions

View File

@ -34,8 +34,9 @@ public class ApiAccessLimitUtil {
/**
* 默认 当月5次
* @param id 唯一值
* @param key 接口名称 sys:limit:接口名称
*
* @param id 唯一值
* @param key 接口名称 sys:limit:接口名称
* @return
*/
public static boolean isAccessAllowed(String id, String key) {
@ -58,9 +59,10 @@ public class ApiAccessLimitUtil {
/**
* 默认月 month//自然月
* @param id 唯一值
* @param key 接口名称 sys:limit:接口名称
* @param count 次数限制
*
* @param id 唯一值
* @param key 接口名称 sys:limit:接口名称
* @param count 次数限制
* @return
*/
public static boolean isAccessAllowed(String id, String key, Integer count) {
@ -82,9 +84,10 @@ public class ApiAccessLimitUtil {
/**
* 默认 5次
*
* @param id 唯一值
* @param key 接口名称 sys:limit:接口名称
* @param timeFormat day//自然天 week//本周日 month//自然月 year//自然年
* @param timeFormat day//自然天 week//本周日 month//自然月 year//自然年
* @return
*/
public static boolean isAccessAllowed(String id, String key, String timeFormat) {
@ -108,7 +111,7 @@ public class ApiAccessLimitUtil {
* @param id 唯一值
* @param key 接口名称 sys:limit:接口名称
* @param count 次数限制
* @param timeFormat day//自然天 week//本周日 month//自然月 year//自然年
* @param timeFormat day//自然天 week//本周日 month//自然月 year//自然年
* @return
*/
public static boolean isAccessAllowed(String id, String key, Integer count, String timeFormat) {
@ -118,7 +121,7 @@ public class ApiAccessLimitUtil {
long expireAt;
if (StrUtil.isBlank(timeFormat)) {
expireAt = count;
}else {
} else {
// 根据不同时间周期设置过期时间并初始化访问次数为1
expireAt = calculateExpireAt(timeFormat);
}
@ -133,14 +136,40 @@ public class ApiAccessLimitUtil {
return false;
}
public static boolean getCertAuthIsAccessAllowed(String id, String key, Integer count) {
String redisKey = generateRedisKey(key, id);
Object countObj = redisUtils.get(redisKey);
if (countObj == null) {
return true;
}
return Integer.parseInt(countObj.toString()) < count;
}
public static void setCertAuthIsAccessAllowed(String id, String key, Integer count, String timeFormat) {
String redisKey = generateRedisKey(key, id);
Object countObj = redisUtils.get(redisKey);
if (countObj == null) {
long expireAt;
if (StrUtil.isBlank(timeFormat)) {
expireAt = count;
} else {
// 根据不同时间周期设置过期时间并初始化访问次数为1
expireAt = calculateExpireAt(timeFormat);
}
redisUtils.set(redisKey, 1, expireAt);
} else {
redisUtils.incr(redisKey);
}
}
public static void removeKey(String id, String key) {
String redisKey = generateRedisKey(key, id);
redisUtils.delete(redisKey);
}
public static<T> T runFunAndCheckKey(Supplier<T> supplier, String lockKey, Integer seconds) {
try{
public static <T> T runFunAndCheckKey(Supplier<T> supplier, String lockKey, Integer seconds) {
try {
// 创建线程id, 用作判断
String clientId = UUID.randomUUID().toString();
// 设置分布式锁
@ -154,12 +183,12 @@ public class ApiAccessLimitUtil {
lock = Boolean.TRUE.equals(redisUtils.setIfAbsent(lockKey, clientId, seconds));
}
return supplier.get();
} catch (RuntimeException e){
} catch (RuntimeException e) {
log.error("执行出错", e);
throw e;
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally{
} finally {
redisUtils.delete(lockKey);
}
}
@ -189,7 +218,7 @@ public class ApiAccessLimitUtil {
Date now = DateUtil.beginOfDay(DateUtil.date());
Date expireDate = null;
if ("day".equals(timePeriod)) {
expireDate = DateUtil.endOfDay(now);
expireDate = DateUtil.endOfDay(now);
} else if ("week".equals(timePeriod)) {
expireDate = DateUtil.endOfWeek(now);
} else if ("month".equals(timePeriod)) {

View File

@ -37,9 +37,6 @@ import java.util.*;
@ConfigurationProperties(prefix = "spring.shardingsphere")
public class ShardingConfig {
@Value("${spring.profiles.active}")
private String activeProfile;
/**
* 读取数据源信息
*/

View File

@ -9,7 +9,6 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sqx.common.annotation.Debounce;
import com.sqx.common.exception.SqxException;
import com.sqx.common.utils.ApiAccessLimitUtil;
import com.sqx.common.utils.DataLimitUtil;
import com.sqx.common.utils.Result;
@ -33,6 +32,7 @@ import java.util.Map;
/**
* APP登录授权
* @author mac
*/
@RestController
@RequestMapping("/app/user")
@ -104,83 +104,75 @@ public class AppController {
UserInfo userInfo = userInfoService.getByUserId(userId);
UserEntity userEntity = userService.getById(userId);
String errMsg = null;
if (StrUtil.isNotBlank(zhiFuBao) && !zhiFuBao.equals(userEntity.getZhiFuBao())) {
if (StrUtil.isNotBlank(zhiFuBao) && (!zhiFuBao.equals(userEntity.getZhiFuBao())) || !certName.equals(userEntity.getZhiFuBaoName())) {
int count = userService.count(new QueryWrapper<UserEntity>()
.ne("user_id", userId)
.eq("zhi_fu_bao_name", certName)
.eq("zhi_fu_bao", zhiFuBao));
if (count > 0) {
errMsg = "支付宝信息修改失败: 一个支付宝账号仅可绑定一个用户";
return Result.error("支付宝信息修改失败: 此支付宝账号已被绑定");
}
if (errMsg == null && StrUtil.isNotBlank(userInfo.getCertName()) && !certName.equals(userInfo.getCertName())) {
errMsg = "支付宝信息修改失败: 姓名与实名认证信息不相符";
if (StrUtil.isNotBlank(userInfo.getCertName()) && !certName.equals(userInfo.getCertName())) {
return Result.error("支付宝信息修改失败: 姓名与实名认证信息不相符");
}
if (errMsg == null && !DataLimitUtil.isAccessAllowed(zhiFuBao+certName, Integer.parseInt(commonRepository.findOne(924).getValue()), "month")) {
errMsg = "支付宝信息修改失败: 相同支付宝账号每月可绑定次数已用完";
if (!DataLimitUtil.isAccessAllowed(zhiFuBao + certName, Integer.parseInt(commonRepository.findOne(924).getValue()), "month")) {
return Result.error("支付宝信息修改失败: 相同支付宝账号每月可绑定次数已用完");
}
if (errMsg == null && !ApiAccessLimitUtil.isAccessAllowed(userId.toString(), "updateZFB", Integer.parseInt(commonRepository.findOne(925).getValue()), "month")) {
errMsg = "支付宝信息修改失败: 每月可修改次数已用完,请联系管理员";
if (!ApiAccessLimitUtil.isAccessAllowed(userId.toString(), "updateZFB", Integer.parseInt(commonRepository.findOne(925).getValue()), "month")) {
return Result.error("支付宝信息修改失败: 每月可修改次数已用完,请联系管理员");
}
if (errMsg == null) {
userEntity.setZhiFuBao(zhiFuBao);
userEntity.setZhiFuBaoName(certName);
userService.update(userEntity, new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getUserId, userId));
}
userEntity.setZhiFuBao(zhiFuBao);
userEntity.setZhiFuBaoName(certName);
userService.update(userEntity, new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getUserId, userId));
}
if (StrUtil.isBlank(certNum)) {
return Result.success();
}
String authErrMsg = null;
if (StrUtil.isNotBlank(certNum) && !certNum.equals(userInfo.getCertNo())) {
if (!certNum.equals(userInfo.getCertNo()) || !certName.equals(userInfo.getCertName())) {
if (StrUtil.isNotBlank(userEntity.getZhiFuBaoName()) && !certName.equals(userEntity.getZhiFuBaoName())) {
authErrMsg = "实名修改失败: 姓名与绑定支付宝信息不相符";
return Result.error("实名修改失败: 姓名与绑定支付宝信息不相符");
}
if (authErrMsg == null && !IdcardUtil.isValidCard(certNum)) {
authErrMsg = "实名修改失败: 身份证号码有误";
if (!IdcardUtil.isValidCard(certNum)) {
return Result.error("实名修改失败: 身份证号码有误");
}
if (authErrMsg == null) {
Integer idCount = userInfoService.countCertCount(certName, certNum);
if (idCount > 1) {
authErrMsg = "实名修改失败: 此实名信息已存在";
}
}
if (authErrMsg == null && !ApiAccessLimitUtil.isAccessAllowed(String.valueOf(userId), "updateAuthCertInfo", 1, "month")) {
authErrMsg = "实名修改失败: 账号每月可修改次数已用完,请联系管理员";
}
if (authErrMsg == null && !ApiAccessLimitUtil.isAccessAllowed(certNum, "updateAuthCertInfoByIdCard", 1, "month")) {
authErrMsg = "实名修改失败: 此身份证信息次月已绑定过,请联系管理员";
}
if (authErrMsg == null) {
try {
aliService.authCertNo(certName, certNum);
userInfo.setCertName(certName);
userInfo.setCertNo(certNum);
userInfo.setUpdateTime(DateUtil.date());
userInfoService.update(userInfo, new LambdaQueryWrapper<UserInfo>().eq(UserInfo::getUserId, userId));
}catch (Exception e) {
ApiAccessLimitUtil.removeKey(String.valueOf(userId), "updateAuthCertInfo");
ApiAccessLimitUtil.removeKey(certNum, "updateAuthCertInfoByIdCard");
authErrMsg = "实名修改失败: 身份证信息不匹配";
Integer idCount = userInfoService.countCertCount(certName, certNum);
if (idCount >= 1) {
return Result.error("实名修改失败: 此身份证信息已绑定过");
}
if (!ApiAccessLimitUtil.getCertAuthIsAccessAllowed(String.valueOf(userId), "updateAuthCertInfo", 1)) {
return Result.error("实名修改失败: 每月可修改次数已用完,请联系管理员");
}
if (!ApiAccessLimitUtil.getCertAuthIsAccessAllowed(certNum, "updateAuthCertInfoByIdCard", 1)) {
return Result.error("实名修改失败: 每月可修改次数已用完,请联系管理员");
}
try {
aliService.authCertNo(certName, certNum);
userInfo.setCertName(certName);
userInfo.setCertNo(certNum);
userInfo.setUpdateTime(DateUtil.date());
boolean update = userInfoService.update(userInfo, new LambdaQueryWrapper<UserInfo>().eq(UserInfo::getUserId, userId).eq(UserInfo::getId, userInfo.getId()));
if (!update) {
return Result.error("实名修改失败: 请稍后重试");
}
ApiAccessLimitUtil.setCertAuthIsAccessAllowed(String.valueOf(userId), "updateAuthCertInfo", 1, "month");
ApiAccessLimitUtil.setCertAuthIsAccessAllowed(certNum, "updateAuthCertInfoByIdCard", 1, "month");
return Result.success();
} catch (Exception e) {
return Result.error("实名修改失败: 身份证信息不匹配");
}
}
if (errMsg != null || authErrMsg != null) {
authErrMsg = authErrMsg == null ? "" : authErrMsg;
return Result.error(errMsg == null ? authErrMsg : errMsg + " " + authErrMsg);
}
return Result.success();
// 去除首绑支付宝奖励
// if (bool && isFirstBind) {
// userService.firstBindAwardsMoney(old);
// }
}
@ -194,22 +186,6 @@ public class AppController {
return Result.success();
}
/*@Login
@RequestMapping(value = "/updateUsers", method = RequestMethod.POST)
@ApiOperation("用户修改个人信息")
@ResponseBody
public Result updateUsers(@RequestAttribute("userId") Long userId,String userName,String avatar,String phone) {
UserEntity userEntity=new UserEntity();
userEntity.setUserId(userId);
userEntity.setUserName(userName);
userEntity.setAvatar(avatar);
userEntity.setPhone(phone);
userService.updateById(userEntity);
return Result.success();
}*/
@Login
@RequestMapping(value = "/updateUserImageUrl", method = RequestMethod.POST)
@ApiOperation("用户修改头像")

View File

@ -167,16 +167,6 @@ public class AppLoginController {
return userService.sendMsg(phone, state,null);
}
@Login
@Debounce(value = "#authCertNoDTO.idNum")
@PostMapping("/authCertNo")
public Result authCertNo(@RequestBody @Validated AuthCertNoDTO authCertNoDTO, @RequestAttribute("userId") long userId) {
if (!ApiAccessLimitUtil.isAccessAllowed(String.valueOf(userId), "updateAuthCertInfo", 1, "month")) {
return Result.error("每月可修改次数已用完,请联系管理员");
}
return Result.success().put("data", userService.authCertNo(userId, authCertNoDTO));
}
@ApiOperation("解密手机号")
@RequestMapping(value = "/selectPhone",method = RequestMethod.POST)
public Result getPhoneNumberBeanS5(@RequestBody WxPhone wxPhone) {

View File

@ -96,9 +96,9 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
throw new CzgException("ip跳动过于频繁请联系管理员解封");
}
ThreadUtil.execAsync(() -> {
redisService.recordUrlVisitCountWithIp(userId, request.getRequestURI(), ip);
});
// ThreadUtil.execAsync(() -> {
// redisService.recordUrlVisitCountWithIp(userId, request.getRequestURI(), ip);
// });
// 设置 userId request 后续根据 userId 获取用户信息
UserEntity user = userService.selectUserById(userId);

View File

@ -126,8 +126,6 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
private final UserVipDao userVipDao;
private final InviteAchievementService inviteAchievementService;
@Value("${spring.profiles.active}")
private String profiles;
private ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock(true);

View File

@ -226,6 +226,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, Course> implements
map.put("dyEpisodeId", "");
map.put("wxCourseDetailsId", "");
map.putAll(countMap);
map.put("courseId", courseId + "");
}
PageUtils pageUtils = PageUtils.page(pageInfo);
// setCache(cacheKey, JSONUtil.toJsonStr(pageUtils));
@ -1299,10 +1300,10 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, Course> implements
if ("start".equals(type)) {
//开始播放
courseDetailsDao.updateViewCount(details.getCourseId(),details.getCourseDetailsId(), 1);
courseDetailsDao.updateViewCount(details.getCourseId(), details.getCourseDetailsId(), 1);
} else if ("end".equals(type)) {
//播放完成
courseDetailsDao.updateViewCount(details.getCourseId(),details.getCourseDetailsId(), 2);
courseDetailsDao.updateViewCount(details.getCourseId(), details.getCourseDetailsId(), 2);
}
return Result.success();

View File

@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@ -20,6 +21,7 @@ import java.util.List;
@Component
@EnableScheduling
@Profile({"prod"})
public class SpinningTask3 {
@Resource
@ -27,16 +29,11 @@ public class SpinningTask3 {
@Resource
private DiscSpinningRecordService recordService;
@Value("${spring.profiles.active}")
private String profiles;
private Logger logger = LoggerFactory.getLogger(getClass());
@Scheduled(cron = "0 0/5 * * * ? ")
@Scheduled(cron = "0 0/1 * * * ? ")
public void record() {
if (!"prod".equals(profiles)) {
return;
}
record("1");
}

View File

@ -115,25 +115,23 @@ public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> impleme
}
@Override
public PageUtils selectCashOutList(Integer page, Integer limit, CashOut cashOut,@Param("isApp") boolean isApp) {
public PageUtils selectCashOutList(Integer page, Integer limit, CashOut cashOut, @Param("isApp") boolean isApp) {
LambdaQueryWrapper<CashOut> queryWrapper = new LambdaQueryWrapper<>();
if (isApp) {
queryWrapper.eq(CashOut::getUserId, cashOut.getUserId())
.eq(CashOut::getUserType, 1);
}else {
if (cashOut.getSysUserId() != null) {
} else {
if (cashOut.getSysUserId() == null) {
return PageUtils.page(new PageInfo<>());
}else {
queryWrapper.eq(CashOut::getUserId, cashOut.getSysUserId())
.eq(CashOut::getUserType, 2);
}
}
if (!isApp && cashOut.getUserId() != null) {
queryWrapper.eq(CashOut::getUserId, cashOut.getUserId());
}
PageHelper.startPage(page, limit);
List<CashOut> cashOutList = list(queryWrapper.eq(CashOut::getUserType, 1).orderByDesc(CashOut::getCreateAt));
List<CashOut> cashOutList = list(queryWrapper.orderByDesc(CashOut::getCreateAt));
if (!isApp) {
ArrayList<Long> userIdList = new ArrayList<>();
@ -662,9 +660,9 @@ public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> impleme
if (StrUtil.isNotBlank(cashOut.getStartTime()) && StrUtil.isNotBlank(cashOut.getEndTime())) {
queryWrapper.between(CashOut::getCreateAt, cashOut.getStartTime(), cashOut.getEndTime());
}else if (StrUtil.isNotBlank(cashOut.getStartTime())) {
} else if (StrUtil.isNotBlank(cashOut.getStartTime())) {
queryWrapper.ge(CashOut::getCreateAt, cashOut.getStartTime());
}else if (StrUtil.isNotBlank(cashOut.getEndTime())) {
} else if (StrUtil.isNotBlank(cashOut.getEndTime())) {
queryWrapper.le(CashOut::getCreateAt, cashOut.getEndTime());
}