|
|
@@ -4,6 +4,7 @@ import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
@@ -21,6 +22,7 @@ import com.fs.live.vo.LiveLotteryProductListVo;
|
|
|
import org.checkerframework.checker.units.qual.A;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -393,6 +395,44 @@ public class LiveAutoTaskServiceImpl implements ILiveAutoTaskService {
|
|
|
if (!updateList.isEmpty()) {
|
|
|
baseMapper.batchUpdateLiveAutoTask(updateList);
|
|
|
}
|
|
|
+
|
|
|
+ // 重新计算后,需要清理并重建Redis缓存
|
|
|
+ // 因为任务的触发时间(score)已经改变,旧的缓存已失效
|
|
|
+ try {
|
|
|
+ String cacheKey = "live:auto_task:" + live.getLiveId();
|
|
|
+
|
|
|
+ // 1. 删除旧的缓存
|
|
|
+ redisCache.deleteObject(cacheKey);
|
|
|
+
|
|
|
+ // 2. 如果直播间正在直播,重新构建缓存
|
|
|
+ if (live.getStatus() != null && live.getStatus() == 2) {
|
|
|
+ for (LiveAutoTask task : liveAutoTasks) {
|
|
|
+ // 只缓存状态为启用且未完成的任务
|
|
|
+ if (task.getStatus() != null && task.getStatus() == 1L
|
|
|
+ && task.getFinishStatus() != null && task.getFinishStatus() == 0L) {
|
|
|
+ LiveAutoTask cacheTask = new LiveAutoTask();
|
|
|
+ BeanUtils.copyProperties(task, cacheTask);
|
|
|
+ cacheTask.setCreateTime(null);
|
|
|
+ cacheTask.setUpdateTime(null);
|
|
|
+
|
|
|
+ redisCache.zSetAdd(cacheKey, JSON.toJSONString(cacheTask), task.getAbsValue().getTime());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置过期时间
|
|
|
+ if (!liveAutoTasks.isEmpty()) {
|
|
|
+ redisCache.expire(cacheKey, 1, TimeUnit.DAYS);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("直播间开始时间变化,已重新构建自动化任务缓存: liveId={}, 任务数={}",
|
|
|
+ live.getLiveId(), liveAutoTasks.size());
|
|
|
+ } else {
|
|
|
+ log.info("直播间未开播,已清理自动化任务缓存: liveId={}", live.getLiveId());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("重新构建自动化任务缓存失败: liveId={}, error={}",
|
|
|
+ live.getLiveId(), e.getMessage(), e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|