chore: sync project snapshot for gitea/github upload
Some checks failed
CI / build_test_package (push) Has been cancelled
CI / auto_merge (push) Has been cancelled

This commit is contained in:
Your Name
2026-03-26 15:59:53 +08:00
parent e5b0f65156
commit 5f5597ef0f
121 changed files with 5841 additions and 1357 deletions

View File

@@ -2,6 +2,7 @@ package com.mosquito.project.job;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mosquito.project.config.AppConfig;
import com.mosquito.project.domain.Activity;
import com.mosquito.project.persistence.entity.ActivityEntity;
import com.mosquito.project.persistence.entity.RewardJobEntity;
@@ -15,6 +16,7 @@ import com.mosquito.project.service.CouponRewardService;
import com.mosquito.project.service.RewardService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@@ -32,6 +34,7 @@ import java.util.Map;
* 按活动规则计算奖励值
*/
@Component
@ConditionalOnProperty(value="app.reward-job.enabled", havingValue="true", matchIfMissing=true)
public class RewardJobProcessor {
private static final Logger log = LoggerFactory.getLogger(RewardJobProcessor.class);
@@ -44,6 +47,7 @@ public class RewardJobProcessor {
private final ObjectMapper objectMapper;
private final RewardDistributor rewardDistributor;
private final CouponRewardService couponRewardService;
private final AppConfig appConfig;
public RewardJobProcessor(RewardJobRepository rewardJobRepository,
ShortLinkRepository shortLinkRepository,
@@ -51,7 +55,8 @@ public class RewardJobProcessor {
ActivityRepository activityRepository,
ObjectMapper objectMapper,
RewardDistributor rewardDistributor,
CouponRewardService couponRewardService) {
CouponRewardService couponRewardService,
AppConfig appConfig) {
this.rewardJobRepository = rewardJobRepository;
this.shortLinkRepository = shortLinkRepository;
this.userRewardRepository = userRewardRepository;
@@ -59,11 +64,15 @@ public class RewardJobProcessor {
this.objectMapper = objectMapper;
this.rewardDistributor = rewardDistributor;
this.couponRewardService = couponRewardService;
this.appConfig = appConfig;
}
@Scheduled(fixedDelay = 5000) // 每5秒执行一次
@Transactional
public void processRewardJobs() {
if (!appConfig.getRewardJob().isEnabled()) {
return; // 测试环境禁用
}
OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC);
List<RewardJobEntity> pendingJobs = rewardJobRepository
.findTop10ByStatusAndNextRunAtLessThanEqualOrderByCreatedAtAsc("pending", now);