|
|
@@ -4,10 +4,12 @@ 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;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
@@ -18,9 +20,11 @@ import com.fs.live.service.ILiveAutoTaskService;
|
|
|
import com.fs.live.service.ILiveGoodsService;
|
|
|
import com.fs.live.vo.LiveGoodsVo;
|
|
|
import com.fs.live.vo.LiveLotteryProductListVo;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
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;
|
|
|
|
|
|
@@ -179,6 +183,37 @@ public class LiveAutoTaskServiceImpl implements ILiveAutoTaskService {
|
|
|
baseMapper.insertLiveAutoTask(liveAutoTask);
|
|
|
|
|
|
}else if(liveAutoTask.getTaskType() == 7L){
|
|
|
+ // 查询最新序号
|
|
|
+ LiveAutoTask task = baseMapper.selectLastSignTaskByLiveId(liveAutoTask.getLiveId());
|
|
|
+ int nextSignNo = 1; // 默认第一次签到
|
|
|
+
|
|
|
+ if(task != null && StringUtils.isNotEmpty(task.getContent())){
|
|
|
+ try {
|
|
|
+ // 解析 content 获取 signNo
|
|
|
+ JSONObject contentObj = JSON.parseObject(task.getContent());
|
|
|
+ String currentSignNo = contentObj.getString("signNo");
|
|
|
+
|
|
|
+ if ("1".equals(currentSignNo)) {
|
|
|
+ nextSignNo = 2;
|
|
|
+ } else if ("2".equals(currentSignNo)) {
|
|
|
+ nextSignNo = 3;
|
|
|
+ } else if ("3".equals(currentSignNo)) {
|
|
|
+ return R.error("最多只能设置三次签到任务");
|
|
|
+ }else {
|
|
|
+ return R.error("签到任务配置错误");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("解析签到任务content失败", e);
|
|
|
+ return R.error("签到任务配置错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置新的签到序号
|
|
|
+ JSONObject content = new JSONObject();
|
|
|
+ content.put("signNo", nextSignNo);
|
|
|
+ liveAutoTask.setContent(content.toJSONString());
|
|
|
+
|
|
|
+
|
|
|
baseMapper.insertLiveAutoTask(liveAutoTask);
|
|
|
|
|
|
} else {
|
|
|
@@ -398,6 +433,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
|