chore: sync project snapshot for gitea/github upload
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user