Commit c757d6ba authored by 王亚雷's avatar 王亚雷

Merge remote-tracking branch 'origin/v2.3.1' into dev

parents ad29851a e245a591
package com.tanpu.community.manager; package com.tanpu.community.manager;
import com.tanpu.common.redis.RedisHelper;
import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.service.*; import com.tanpu.community.service.*;
import com.tanpu.community.service.quartz.TopicReportService; import com.tanpu.community.service.quartz.TopicReportService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.Duration;
@Slf4j @Slf4j
@Service @Service
@Configuration @Configuration
...@@ -31,6 +37,12 @@ public class ConJobManager { ...@@ -31,6 +37,12 @@ public class ConJobManager {
@Autowired @Autowired
private TopicReportService topicReportService; private TopicReportService topicReportService;
@Resource
private RedisHelper redisHelper;
@Resource
private UuidGenHelper uuidGenHelper;
/** /**
* 定时统计 话题 访问数据,并刷到redis * 定时统计 话题 访问数据,并刷到redis
*/ */
...@@ -72,16 +84,46 @@ public class ConJobManager { ...@@ -72,16 +84,46 @@ public class ConJobManager {
*/ */
@Scheduled(cron = "0 30 9 ? * *") @Scheduled(cron = "0 30 9 ? * *")
public void reportTopicWeekday() { public void reportTopicWeekday() {
String key = "community:lock:reportTopicWeekday";
String uuid = uuidGenHelper.getUuidStr();
Boolean locked = null;
try {
locked = redisHelper.setIfAbsent(key, uuid, Duration.ofSeconds(60));
if (locked) {
log.info("reportTopicWeekday start"); log.info("reportTopicWeekday start");
topicReportService.reportTopicWeekday(); topicReportService.reportTopicWeekday();
} }
} finally {
if (Boolean.TRUE.equals(locked)) {
String value = redisHelper.get(key);
if (StringUtils.equals(uuid, value)) {
redisHelper.delete(key);
}
}
}
}
/** /**
* 每周六早上09:00汇报 topic数据 * 每周六早上09:00汇报 topic数据
*/ */
@Scheduled(cron = "0 0 9 ? * SAT") @Scheduled(cron = "0 0 9 ? * SAT")
public void reportTopicSaturday() { public void reportTopicSaturday() {
String key = "community:lock:reportTopicSaturday";
String uuid = uuidGenHelper.getUuidStr();
Boolean locked = null;
try {
locked = redisHelper.setIfAbsent(key, uuid, Duration.ofSeconds(60));
if (locked) {
log.info("reportTopicSaturday start"); log.info("reportTopicSaturday start");
topicReportService.reportTopicSaturday(); topicReportService.reportTopicSaturday();
} }
} finally {
if (Boolean.TRUE.equals(locked)) {
String value = redisHelper.get(key);
if (StringUtils.equals(uuid, value)) {
redisHelper.delete(key);
}
}
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment