|
@@ -2,10 +2,9 @@ package com.fs.his.service.impl;
|
|
|
|
|
|
|
|
import com.fs.app.domain.FsAppRole;
|
|
import com.fs.app.domain.FsAppRole;
|
|
|
import com.fs.app.mapper.FsAppRoleMapper;
|
|
import com.fs.app.mapper.FsAppRoleMapper;
|
|
|
|
|
+import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.exception.CustomException;
|
|
import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.DateUtils;
|
|
|
-import com.fs.course.domain.FsCourseWatchLog;
|
|
|
|
|
-import com.fs.course.mapper.FsCourseWatchLogMapper;
|
|
|
|
|
import com.fs.his.domain.FsUser;
|
|
import com.fs.his.domain.FsUser;
|
|
|
import com.fs.his.domain.FsUserRewards;
|
|
import com.fs.his.domain.FsUserRewards;
|
|
|
import com.fs.his.dto.ClaimRewardsAddDTO;
|
|
import com.fs.his.dto.ClaimRewardsAddDTO;
|
|
@@ -27,7 +26,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
|
|
+import java.time.Duration;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
@@ -42,15 +44,16 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private FsAppRoleMapper appRoleMapper;
|
|
private FsAppRoleMapper appRoleMapper;
|
|
|
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private FsCourseWatchLogMapper watchLogMapper;
|
|
|
|
|
-
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ObjectMapper objectMapper;
|
|
private ObjectMapper objectMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RewardStrategyFactory strategyFactory;
|
|
private RewardStrategyFactory strategyFactory;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RedisCache redisCache;
|
|
|
|
|
+
|
|
|
|
|
+ private static final String APP_WATCH_COURSE_DAY_KEY ="app:watch:course:day:";
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void claimRewards(ClaimRewardsAddDTO claimRewardsAddDTO) {
|
|
public void claimRewards(ClaimRewardsAddDTO claimRewardsAddDTO) {
|
|
@@ -75,7 +78,7 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
|
|
|
RewardStrategy strategy = strategyFactory.getStrategy(reward.getActivityType(), reward.getRewardType());
|
|
RewardStrategy strategy = strategyFactory.getStrategy(reward.getActivityType(), reward.getRewardType());
|
|
|
RewardResult result = strategy.process(reward);
|
|
RewardResult result = strategy.process(reward);
|
|
|
//RewardResult result = new RewardResult();
|
|
//RewardResult result = new RewardResult();
|
|
|
- result.setSuccess(true);
|
|
|
|
|
|
|
+ //result.setSuccess(true);
|
|
|
if (result.isSuccess()) {
|
|
if (result.isSuccess()) {
|
|
|
// 更新奖品状态
|
|
// 更新奖品状态
|
|
|
rewardsMapper.updateStatus(rewardsId, 1, result.getOrderCode(), DateUtils.getNowDate());
|
|
rewardsMapper.updateStatus(rewardsId, 1, result.getOrderCode(), DateUtils.getNowDate());
|
|
@@ -323,6 +326,7 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public FsAppRole showWatchCourseRewardWindows(Long fsUserId) {
|
|
public FsAppRole showWatchCourseRewardWindows(Long fsUserId) {
|
|
|
|
|
+ String watchCourseKey = APP_WATCH_COURSE_DAY_KEY + fsUserId;
|
|
|
FsAppRole noShowWindow = new FsAppRole();
|
|
FsAppRole noShowWindow = new FsAppRole();
|
|
|
|
|
|
|
|
// 获取用户和配置
|
|
// 获取用户和配置
|
|
@@ -351,9 +355,9 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 积分/红包逻辑
|
|
// 积分/红包逻辑
|
|
|
- List<FsCourseWatchLog> finishedLogs = watchLogMapper.selectTodayFinishedLogsByUserId(fsUserId);
|
|
|
|
|
// 今日没有完课 → 不展示
|
|
// 今日没有完课 → 不展示
|
|
|
- if (CollectionUtils.isEmpty(finishedLogs)) {
|
|
|
|
|
|
|
+ Object cacheObject = redisCache.getCacheObject(watchCourseKey);
|
|
|
|
|
+ if (cacheObject == null) {
|
|
|
return noShowWindow;
|
|
return noShowWindow;
|
|
|
}
|
|
}
|
|
|
// 今天已领过 → 不展示
|
|
// 今天已领过 → 不展示
|
|
@@ -364,6 +368,44 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
|
|
|
return defaultConfig;
|
|
return defaultConfig;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void recordUserWatchCourseDays(Long fsUserId) {
|
|
|
|
|
+ String watchCourseKey = APP_WATCH_COURSE_DAY_KEY + fsUserId;
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 检查Redis中是否有今日已记录的标记
|
|
|
|
|
+ Object cacheObject = redisCache.getCacheObject(watchCourseKey);
|
|
|
|
|
+ if (cacheObject != null) {
|
|
|
|
|
+ log.info("用户今日有效看课天数已记录, userId: {}", fsUserId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 计算到今晚23:59:59的剩余秒数
|
|
|
|
|
+ long secondsUntilEndOfDay = getSecondsUntilEndOfDay();
|
|
|
|
|
+
|
|
|
|
|
+ // 3. Redis记录今日已看课标记(过期时间为今晚23:59:59)
|
|
|
|
|
+ redisCache.setCacheObject(watchCourseKey, fsUserId, (int) secondsUntilEndOfDay, TimeUnit.SECONDS);
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 更新数据库中的累计看课天数
|
|
|
|
|
+ FsUser fsUser = fsUserMapper.selectFsUserById(fsUserId);
|
|
|
|
|
+ if (fsUser != null) {
|
|
|
|
|
+ // 获取当前累计天数,如果为null则默认为0
|
|
|
|
|
+ Integer currentDays = fsUser.getAppRewardsViewedDays();
|
|
|
|
|
+ if (currentDays == null) {
|
|
|
|
|
+ currentDays = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 更新累计天数
|
|
|
|
|
+ FsUser updateUser = new FsUser();
|
|
|
|
|
+ updateUser.setUserId(fsUserId);
|
|
|
|
|
+ updateUser.setAppRewardsViewedDays(currentDays + 1);
|
|
|
|
|
+ fsUserMapper.updateFsUser(updateUser);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("用户累计看课天数更新成功, userId: {}, 当前天数: {}", fsUserId, currentDays + 1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.error("用户不存在, userId: {}", fsUserId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//根据用户id、角色id获取配置的奖品信息(实物商品包含商品名称和图片)
|
|
//根据用户id、角色id获取配置的奖品信息(实物商品包含商品名称和图片)
|
|
|
private FsAppRole getAppRoleConfig(Long fsUserId){
|
|
private FsAppRole getAppRoleConfig(Long fsUserId){
|
|
|
//获取当前用户最高权重角色, "false"表示查询等级数字最小的权重角色
|
|
//获取当前用户最高权重角色, "false"表示查询等级数字最小的权重角色
|
|
@@ -376,7 +418,20 @@ public class AppUserRewardServiceImpl implements IAppUserRewardService {
|
|
|
return fsAppRole;
|
|
return fsAppRole;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取到今晚23:59:59的剩余秒数
|
|
|
|
|
+ */
|
|
|
|
|
+ private long getSecondsUntilEndOfDay() {
|
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
+ LocalDateTime endOfDay = now.toLocalDate().atTime(23, 59, 59);
|
|
|
|
|
+
|
|
|
|
|
+ // 如果当前时间已经超过23:59:59,用明天
|
|
|
|
|
+ if (now.isAfter(endOfDay)) {
|
|
|
|
|
+ endOfDay = endOfDay.plusDays(1);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ return Duration.between(now, endOfDay).getSeconds();
|
|
|
|
|
+ }
|
|
|
/**
|
|
/**
|
|
|
* 积分、商品是否过期的判断方法(红包需要另外方法计算)
|
|
* 积分、商品是否过期的判断方法(红包需要另外方法计算)
|
|
|
* @param reward: 奖品
|
|
* @param reward: 奖品
|