|
@@ -18,6 +18,7 @@ import com.etotem.cfc.mapper.PointsLogMapper;
|
|
|
import com.etotem.cfc.mapper.TaskMapper;
|
|
import com.etotem.cfc.mapper.TaskMapper;
|
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
@@ -456,14 +457,25 @@ public class ActivityService extends ServiceImpl<ActivityMapper, Activity> {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void autoEndExpiredActivities() {
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 自动结束过期活动
|
|
|
|
|
+ * 逻辑:发布中且结束时间已过(endTime < now),将状态置为 ended。
|
|
|
|
|
+ * 备注:正式上线建议改为 Spring @Scheduled(cron = "0 0 2 * * ?") 每日 02:00 执行(见 TODOs),此处保留方法供 list/detail 触发兜底。
|
|
|
|
|
+ */
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 自动结束过期活动(P2-1 定时化)
|
|
|
|
|
+ * 每日 02:00 定时执行,结束阈值 = endTime < now()(去掉旧的 7 天延迟)。
|
|
|
|
|
+ * 同时保留在 list/detail 查询时轻量调用兜底(实时状态判断)。
|
|
|
|
|
+ */
|
|
|
|
|
+ @Scheduled(cron = "0 0 2 * * ?")
|
|
|
|
|
+ public void autoEndExpiredActivities() {
|
|
|
try {
|
|
try {
|
|
|
- Date threshold = new Date(System.currentTimeMillis() - 7L * 24 * 3600 * 1000);
|
|
|
|
|
|
|
+ Date now = new Date();
|
|
|
this.update(new LambdaUpdateWrapper<Activity>()
|
|
this.update(new LambdaUpdateWrapper<Activity>()
|
|
|
.eq(Activity::getStatus, "published")
|
|
.eq(Activity::getStatus, "published")
|
|
|
- .lt(Activity::getEndTime, threshold)
|
|
|
|
|
|
|
+ .lt(Activity::getEndTime, now)
|
|
|
.set(Activity::getStatus, "ended")
|
|
.set(Activity::getStatus, "ended")
|
|
|
- .set(Activity::getUpdatedAt, new Date()));
|
|
|
|
|
|
|
+ .set(Activity::getUpdatedAt, now));
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.warn("自动结束过期活动失败: {}", e.getMessage());
|
|
log.warn("自动结束过期活动失败: {}", e.getMessage());
|
|
|
}
|
|
}
|