|
@@ -109,7 +109,7 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
// 构建奖品记录
|
|
// 构建奖品记录
|
|
|
- FsUserRewards reward = buildAppUserReward(fsUserId, activityType, appRoleConfig,null);
|
|
|
|
|
|
|
+ FsUserRewards reward = buildAppUserReward(fsUserId, activityType, appRoleConfig,null,null);
|
|
|
try {
|
|
try {
|
|
|
// 插入奖品表
|
|
// 插入奖品表
|
|
|
int insertResult = rewardsMapper.insertFsUserRewards(reward);
|
|
int insertResult = rewardsMapper.insertFsUserRewards(reward);
|
|
@@ -139,6 +139,12 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void addUserWatchCourseRewards(Long fsUserId,Long videoId) {
|
|
public void addUserWatchCourseRewards(Long fsUserId,Long videoId) {
|
|
|
|
|
+ String watchCourseKey = APP_WATCH_COURSE_DAY_KEY + fsUserId;
|
|
|
|
|
+ Object cacheObject = redisCache.getCacheObject(watchCourseKey);
|
|
|
|
|
+ if (cacheObject == null) {
|
|
|
|
|
+ log.info("用户:{}今日无有效看课记录", fsUserId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
// 1. 生成锁的key:用户ID+视频ID
|
|
// 1. 生成锁的key:用户ID+视频ID
|
|
|
String lockKey = LOCK_WATCH_REWARD_KEY + fsUserId + ":" + videoId;
|
|
String lockKey = LOCK_WATCH_REWARD_KEY + fsUserId + ":" + videoId;
|
|
|
// 2. 创建分布式锁,设置10秒过期
|
|
// 2. 创建分布式锁,设置10秒过期
|
|
@@ -156,11 +162,12 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
|
|
|
log.info("获取分布式锁成功: userId={}, videoId={}, secret={}",
|
|
log.info("获取分布式锁成功: userId={}, videoId={}, secret={}",
|
|
|
fsUserId, videoId, lock.getLockSecretValue());
|
|
fsUserId, videoId, lock.getLockSecretValue());
|
|
|
|
|
|
|
|
|
|
+ String toDay=DateUtils.getDate();
|
|
|
// 4. 双重检查:再次确认是否已发放过奖励(防止锁内重复)
|
|
// 4. 双重检查:再次确认是否已发放过奖励(防止锁内重复)
|
|
|
- FsUserRewards existingReward = rewardsMapper.selectByUserIdAndVideoId(fsUserId, videoId);
|
|
|
|
|
|
|
+ FsUserRewards existingReward = rewardsMapper.selectByUserIdAndVideoId(fsUserId, videoId, toDay);
|
|
|
if (existingReward != null) {
|
|
if (existingReward != null) {
|
|
|
log.info("看课奖励已存在,不再重复发放: userId={}, videoId={}", fsUserId, videoId);
|
|
log.info("看课奖励已存在,不再重复发放: userId={}, videoId={}", fsUserId, videoId);
|
|
|
- return; // 已存在,直接返回
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 5. 原有的业务逻辑
|
|
// 5. 原有的业务逻辑
|
|
@@ -174,7 +181,7 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 构建奖品记录
|
|
// 构建奖品记录
|
|
|
- FsUserRewards reward = buildAppUserReward(fsUserId, activityType, appRoleConfig, videoId);
|
|
|
|
|
|
|
+ FsUserRewards reward = buildAppUserReward(fsUserId, activityType, appRoleConfig, videoId,toDay);
|
|
|
|
|
|
|
|
// 插入奖品表
|
|
// 插入奖品表
|
|
|
try {
|
|
try {
|
|
@@ -214,7 +221,7 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
|
|
|
* @param activityType 活动类型
|
|
* @param activityType 活动类型
|
|
|
* @param appRoleConfig 角色配置
|
|
* @param appRoleConfig 角色配置
|
|
|
*/
|
|
*/
|
|
|
- private FsUserRewards buildAppUserReward(Long fsUserId, String activityType, FsAppRole appRoleConfig,Long videoId) {
|
|
|
|
|
|
|
+ private FsUserRewards buildAppUserReward(Long fsUserId, String activityType, FsAppRole appRoleConfig,Long videoId,String toDay) {
|
|
|
FsUserRewards reward = new FsUserRewards();
|
|
FsUserRewards reward = new FsUserRewards();
|
|
|
reward.setFsUserId(fsUserId);
|
|
reward.setFsUserId(fsUserId);
|
|
|
reward.setActivityType(activityType);
|
|
reward.setActivityType(activityType);
|
|
@@ -244,6 +251,7 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
|
|
|
// 看课奖励
|
|
// 看课奖励
|
|
|
reward.setRewardType(appRoleConfig.getCourseRewardType());
|
|
reward.setRewardType(appRoleConfig.getCourseRewardType());
|
|
|
reward.setVideoId(videoId);
|
|
reward.setVideoId(videoId);
|
|
|
|
|
+ reward.setRewardDate(toDay);
|
|
|
// 获取当前用户的有效看课天数
|
|
// 获取当前用户的有效看课天数
|
|
|
FsUser fsUser = fsUserMapper.selectFsUserById(fsUserId);
|
|
FsUser fsUser = fsUserMapper.selectFsUserById(fsUserId);
|
|
|
if (fsUser == null) {
|
|
if (fsUser == null) {
|