初始化
This commit is contained in:
40
accompany-scheduler/accompany-scheduler-service/pom.xml
Normal file
40
accompany-scheduler/accompany-scheduler-service/pom.xml
Normal file
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>accompany-scheduler</artifactId>
|
||||
<groupId>com.accompany</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>accompany-scheduler-service</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.accompany</groupId>
|
||||
<artifactId>accompany-business-service</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.1.20</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shardingsphere</groupId>
|
||||
<artifactId>sharding-jdbc-core</artifactId>
|
||||
<version>4.0.0-RC2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson-spring-data-20</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -0,0 +1,15 @@
|
||||
package com.accompany.scheduler.base;
|
||||
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.google.gson.Gson;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class BaseTask {
|
||||
|
||||
@Autowired
|
||||
protected JedisService jedisService;
|
||||
|
||||
protected Gson gson = new Gson();
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package com.accompany.scheduler.config;
|
||||
|
||||
import com.accompany.common.support.InjectBeanSelfBeanPostProcessor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @Author yubin
|
||||
* @Description //TODO
|
||||
* @Date 2019-05-05 19:20
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
public class BeanConfig {
|
||||
|
||||
|
||||
@Bean
|
||||
public InjectBeanSelfBeanPostProcessor initBean() {
|
||||
return new InjectBeanSelfBeanPostProcessor();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,477 @@
|
||||
package com.accompany.scheduler.config;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.apache.activemq.command.ActiveMQTopic;
|
||||
import org.apache.activemq.pool.PooledConnectionFactory;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.DeliveryMode;
|
||||
import javax.jms.Queue;
|
||||
import javax.jms.Topic;
|
||||
|
||||
/**
|
||||
* @Author yubin
|
||||
* @Description //TODO
|
||||
* @Date 2019-04-10 16:29
|
||||
*/
|
||||
|
||||
@Component
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "activemq")
|
||||
public class JmsConfig {
|
||||
|
||||
|
||||
private String brokerUrl;
|
||||
|
||||
private String user;
|
||||
|
||||
private String password;
|
||||
|
||||
private int maxConnections;
|
||||
|
||||
private int idleTimeout;
|
||||
|
||||
|
||||
|
||||
|
||||
public final static String MY_QUEUE = "spring-queue";
|
||||
public final static String GIFT_QUEUE = "gift-queue";
|
||||
|
||||
public final static String OPENBOX_QUEUE = "openbox-queue";
|
||||
|
||||
|
||||
|
||||
//用户退出清除已点歌曲的延迟队列
|
||||
public final static String CLEAN_MUSIC_QUEUE = "clean-music-queue";
|
||||
//活动礼包队列
|
||||
public final static String ACTIVITY_PACK_QUEUE = "activity-pack-queue";
|
||||
|
||||
public final static String GIFT_TOPIC = "erban-gift-topic";
|
||||
|
||||
public final static String PAY_FINISH_QUEUE = "pay-finish-queue";
|
||||
|
||||
public final static String LINEARLY_POOL_DEFAULT_QUEUE = "linearly-pool-draw-queue";
|
||||
|
||||
/**
|
||||
* 许愿星杯每日首登队列
|
||||
*/
|
||||
public final static String WISH_STAR_CUP_USER_LOGIN_MSG_QUEUE = "wish_star_cup_user_login_msg_queue";
|
||||
|
||||
/**
|
||||
* 定义点对点队列
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Queue myQueue() {
|
||||
return new ActiveMQQueue(MY_QUEUE);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue giftQueue() {
|
||||
return new ActiveMQQueue(GIFT_QUEUE);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue openBoxQueue() {
|
||||
return new ActiveMQQueue(OPENBOX_QUEUE);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public Queue cleanMusicQueue() {
|
||||
return new ActiveMQQueue(CLEAN_MUSIC_QUEUE);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue activityPackQueue() {
|
||||
return new ActiveMQQueue(ACTIVITY_PACK_QUEUE);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue payFinishQueue() {
|
||||
return new ActiveMQQueue(PAY_FINISH_QUEUE);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue wishStarCupUserLoginMsgQueue() { return new ActiveMQQueue(WISH_STAR_CUP_USER_LOGIN_MSG_QUEUE); }
|
||||
|
||||
@Bean
|
||||
public Queue linearlyPoolDefaultQueue() {
|
||||
return new ActiveMQQueue(LINEARLY_POOL_DEFAULT_QUEUE);
|
||||
}
|
||||
|
||||
|
||||
@Primary
|
||||
@Bean("myConnectionFactory")
|
||||
public ConnectionFactory connectionFactory() {
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(user,password,brokerUrl);
|
||||
factory.setTrustAllPackages(true);
|
||||
|
||||
PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(factory);
|
||||
pooledConnectionFactory.setMaxConnections(maxConnections);
|
||||
pooledConnectionFactory.setIdleTimeout(idleTimeout);
|
||||
|
||||
return pooledConnectionFactory;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 定义一个主题
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Topic giftTopic() {
|
||||
return new ActiveMQTopic(GIFT_TOPIC);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 配置队列生产者的JmsTemplate
|
||||
* @param activeMQConnectionFactory
|
||||
* @return
|
||||
*/
|
||||
@Bean("jmsTemplate")
|
||||
public JmsTemplate jmsTemplate(@Qualifier("myConnectionFactory") ConnectionFactory activeMQConnectionFactory) {
|
||||
JmsTemplate template = new JmsTemplate(activeMQConnectionFactory);
|
||||
template.setExplicitQosEnabled(true);
|
||||
template.setDeliveryMode(DeliveryMode.PERSISTENT);
|
||||
template.setDefaultDestination(myQueue());
|
||||
template.setSessionTransacted(true);
|
||||
return template;
|
||||
}
|
||||
|
||||
@Bean("giftJmsTemplate")
|
||||
public JmsTemplate giftJmsTemplate(@Qualifier("myConnectionFactory")ConnectionFactory activeMQConnectionFactory) {
|
||||
JmsTemplate template = new JmsTemplate(activeMQConnectionFactory);
|
||||
template.setDefaultDestination(giftQueue());
|
||||
template.setSessionTransacted(true);
|
||||
return template;
|
||||
}
|
||||
|
||||
@Bean("giftTopicJmsTemplate")
|
||||
public JmsTemplate giftTopicJmsTemplate(@Qualifier("myConnectionFactory")ConnectionFactory activeMQConnectionFactory) {
|
||||
JmsTemplate template = new JmsTemplate(activeMQConnectionFactory);
|
||||
template.setExplicitQosEnabled(true);
|
||||
template.setDeliveryMode(DeliveryMode.PERSISTENT);
|
||||
template.setDefaultDestination(giftTopic());
|
||||
template.setSessionTransacted(true);
|
||||
return template;
|
||||
}
|
||||
|
||||
|
||||
@Bean("openBoxJmsTemplate")
|
||||
public JmsTemplate openBoxJmsTemplate(@Qualifier("myConnectionFactory")ConnectionFactory activeMQConnectionFactory) {
|
||||
JmsTemplate template = new JmsTemplate(activeMQConnectionFactory);
|
||||
template.setDefaultDestination(openBoxQueue());
|
||||
return template;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Bean("cleanMusicJmsTemplate")
|
||||
public JmsTemplate cleanMusicJmsTemplate(@Qualifier("myConnectionFactory")ConnectionFactory activeMQConnectionFactory) {
|
||||
JmsTemplate template = new JmsTemplate(activeMQConnectionFactory);
|
||||
template.setDefaultDestination(cleanMusicQueue());
|
||||
return template;
|
||||
}
|
||||
|
||||
@Bean("activityPackJmsTemplate")
|
||||
public JmsTemplate activityPackJmsTemplate(@Qualifier("myConnectionFactory")ConnectionFactory activeMQConnectionFactory) {
|
||||
JmsTemplate template = new JmsTemplate(activeMQConnectionFactory);
|
||||
template.setDefaultDestination(activityPackQueue());
|
||||
return template;
|
||||
}
|
||||
|
||||
@Bean("payFinishJmsTemplate")
|
||||
public JmsTemplate payFinishJmsTemplate(@Qualifier("myConnectionFactory")ConnectionFactory activeMQConnectionFactory) {
|
||||
JmsTemplate template = new JmsTemplate(activeMQConnectionFactory);
|
||||
template.setDefaultDestination(payFinishQueue());
|
||||
return template;
|
||||
}
|
||||
|
||||
@Bean("linearlyPoolJmsTemplate")
|
||||
public JmsTemplate linearlyPoolJmsTemplate(@Qualifier("myConnectionFactory")ConnectionFactory activeMQConnectionFactory) {
|
||||
JmsTemplate template = new JmsTemplate(activeMQConnectionFactory);
|
||||
template.setDefaultDestination(linearlyPoolDefaultQueue());
|
||||
return template;
|
||||
}
|
||||
|
||||
|
||||
@Bean("jmsContainer")
|
||||
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
|
||||
DefaultJmsListenerContainerFactory factory
|
||||
= new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setConcurrency("4-8");
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean("jmsContainer2")
|
||||
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory2() {
|
||||
DefaultJmsListenerContainerFactory factory
|
||||
= new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setConcurrency("4-8");
|
||||
|
||||
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean("jmsContainer3")
|
||||
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory3() {
|
||||
DefaultJmsListenerContainerFactory factory
|
||||
= new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setConcurrency("4-8");
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean("giftMagicJmsContainer")
|
||||
public DefaultJmsListenerContainerFactory giftMagicJmsContainer() {
|
||||
DefaultJmsListenerContainerFactory factory
|
||||
= new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setConcurrency("4-8");
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Bean("boxPrizeContainer")
|
||||
public DefaultJmsListenerContainerFactory boxPrizeContainer() {
|
||||
DefaultJmsListenerContainerFactory factory
|
||||
= new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setConcurrency("4-8");
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean("jmsContainer4")
|
||||
public DefaultJmsListenerContainerFactory jmsContainer4() {
|
||||
DefaultJmsListenerContainerFactory factory
|
||||
= new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setSubscriptionDurable(false);
|
||||
factory.setPubSubDomain(true);
|
||||
factory.setConcurrency("4-8");
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
@Bean("newyearJmsContainer")
|
||||
public DefaultJmsListenerContainerFactory newyearJmsContainer() {
|
||||
DefaultJmsListenerContainerFactory factory
|
||||
= new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setSubscriptionDurable(false);
|
||||
factory.setPubSubDomain(true);
|
||||
factory.setConcurrency("4-8");
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Bean("cleanMusicContainer")
|
||||
public DefaultJmsListenerContainerFactory cleanMusicContainer() {
|
||||
DefaultJmsListenerContainerFactory factory
|
||||
= new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setConcurrency("4-8");
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean("activityPackContainer")
|
||||
public DefaultJmsListenerContainerFactory activityPackContainer() {
|
||||
DefaultJmsListenerContainerFactory factory
|
||||
= new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setConcurrency("4-8");
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean("signDrawGoldContainer")
|
||||
public DefaultJmsListenerContainerFactory signDrawGoldContainer() {
|
||||
DefaultJmsListenerContainerFactory factory
|
||||
= new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setConcurrency("4-8");
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
@Bean("signContainer")
|
||||
public DefaultJmsListenerContainerFactory signContainer() {
|
||||
DefaultJmsListenerContainerFactory factory
|
||||
= new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setConcurrency("4-8");
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean("radishGiftContainer")
|
||||
public DefaultJmsListenerContainerFactory radishGiftContainer() {
|
||||
DefaultJmsListenerContainerFactory factory
|
||||
= new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setConcurrency("4-8");
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean("payFinishContainer")
|
||||
public DefaultJmsListenerContainerFactory payFinishContainer() {
|
||||
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setConcurrency("4-8");
|
||||
return factory;
|
||||
}
|
||||
|
||||
public final static String AD_PLATFORM_USER_LOGIN_MSG_QUEUE = "ad_platform_user_login_msg_queue";
|
||||
|
||||
@Bean
|
||||
public Queue adPlatfromUserLoginMsgQueue() { return new ActiveMQQueue(AD_PLATFORM_USER_LOGIN_MSG_QUEUE); }
|
||||
|
||||
@Bean("adPlatformLoginMsgJmsTemplate")
|
||||
public JmsTemplate adPlatformLoginMsgJmsTemplate(@Qualifier("myConnectionFactory")ConnectionFactory activeMQConnectionFactory) {
|
||||
JmsTemplate template = new JmsTemplate(activeMQConnectionFactory);
|
||||
template.setDefaultDestination(adPlatfromUserLoginMsgQueue());
|
||||
return template;
|
||||
}
|
||||
|
||||
|
||||
@Bean("adPlatformUserLoginMsgContainer")
|
||||
public DefaultJmsListenerContainerFactory adPlatformUserLoginMsgContainer() {
|
||||
DefaultJmsListenerContainerFactory factory
|
||||
= new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setConcurrency("4-8");
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean("wishStarCupLoginMsgJmsTemplate")
|
||||
public JmsTemplate wishStarCupLoginMsgJmsTemplate(@Qualifier("myConnectionFactory")ConnectionFactory activeMQConnectionFactory) {
|
||||
JmsTemplate template = new JmsTemplate(activeMQConnectionFactory);
|
||||
template.setDefaultDestination(wishStarCupUserLoginMsgQueue());
|
||||
return template;
|
||||
}
|
||||
|
||||
|
||||
@Bean("wishStarCupUserLoginMsgContainer")
|
||||
public DefaultJmsListenerContainerFactory wishStarCupUserLoginMsgContainer() {
|
||||
DefaultJmsListenerContainerFactory factory
|
||||
= new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setConcurrency("4-8");
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
public final static String WISHSTARCUP_QUEUE = "wishstarcup-queue";
|
||||
|
||||
|
||||
@Bean
|
||||
public Queue wishStarCupQueue() {
|
||||
return new ActiveMQQueue(WISHSTARCUP_QUEUE);
|
||||
}
|
||||
|
||||
@Bean("wishStarCupJmsTemplate")
|
||||
public JmsTemplate wishStarCupJmsTemplate(@Qualifier("myConnectionFactory")ConnectionFactory activeMQConnectionFactory) {
|
||||
JmsTemplate template = new JmsTemplate(activeMQConnectionFactory);
|
||||
template.setDefaultDestination(wishStarCupQueue());
|
||||
return template;
|
||||
}
|
||||
|
||||
@Bean("wishStarCupContainer")
|
||||
public DefaultJmsListenerContainerFactory wishStarCupContainer() {
|
||||
DefaultJmsListenerContainerFactory factory
|
||||
= new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory());
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setSessionAcknowledgeMode(4);
|
||||
factory.setConcurrency("4-8");
|
||||
return factory;
|
||||
}
|
||||
|
||||
public String getBrokerUrl() {
|
||||
return brokerUrl;
|
||||
}
|
||||
|
||||
public void setBrokerUrl(String brokerUrl) {
|
||||
this.brokerUrl = brokerUrl;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public int getMaxConnections() {
|
||||
return maxConnections;
|
||||
}
|
||||
|
||||
public void setMaxConnections(int maxConnections) {
|
||||
this.maxConnections = maxConnections;
|
||||
}
|
||||
|
||||
public int getIdleTimeout() {
|
||||
return idleTimeout;
|
||||
}
|
||||
|
||||
public void setIdleTimeout(int idleTimeout) {
|
||||
this.idleTimeout = idleTimeout;
|
||||
}
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
package com.accompany.scheduler.config;
|
||||
|
||||
import com.accompany.common.constant.Constant;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* @Author yubin
|
||||
* @Description 线程池配置
|
||||
* @Date 2019-01-30 10:31
|
||||
*/
|
||||
|
||||
|
||||
@Configuration
|
||||
public class ScheduleConfig implements SchedulingConfigurer {
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(30) {
|
||||
// 重写schedule方法,每次定时执行时,都设置一个新的traceid
|
||||
public ScheduledFuture<?> schedule(Runnable command,
|
||||
long delay,
|
||||
TimeUnit unit) {
|
||||
return super.schedule(() -> {
|
||||
MDC.put(Constant.LOG_TRACE_ID_NAME, UUID.randomUUID().toString());
|
||||
command.run();
|
||||
}, delay, unit);
|
||||
}
|
||||
|
||||
public <V> ScheduledFuture<V> schedule(Callable<V> callable,
|
||||
long delay,
|
||||
TimeUnit unit) {
|
||||
return super.schedule(new Callable<V>() {
|
||||
@Override
|
||||
public V call() throws Exception {
|
||||
MDC.put(Constant.LOG_TRACE_ID_NAME, UUID.randomUUID().toString());
|
||||
return callable.call();
|
||||
}
|
||||
}, delay, unit);
|
||||
}
|
||||
|
||||
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
|
||||
long initialDelay,
|
||||
long period,
|
||||
TimeUnit unit) {
|
||||
return super.scheduleAtFixedRate(() -> {
|
||||
MDC.put(Constant.LOG_TRACE_ID_NAME, UUID.randomUUID().toString());
|
||||
command.run();
|
||||
}, initialDelay, period, unit);
|
||||
}
|
||||
|
||||
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command,
|
||||
long initialDelay,
|
||||
long delay,
|
||||
TimeUnit unit) {
|
||||
return super.scheduleWithFixedDelay(() -> {
|
||||
MDC.put(Constant.LOG_TRACE_ID_NAME, UUID.randomUUID().toString());
|
||||
command.run();
|
||||
}, initialDelay, delay, unit);
|
||||
}
|
||||
public void execute(Runnable command) {
|
||||
super.execute(() -> {
|
||||
MDC.put(Constant.LOG_TRACE_ID_NAME, UUID.randomUUID().toString());
|
||||
command.run();
|
||||
});
|
||||
}
|
||||
|
||||
public Future<?> submit(Runnable task) {
|
||||
return super.submit(() -> {
|
||||
MDC.put(Constant.LOG_TRACE_ID_NAME, UUID.randomUUID().toString());
|
||||
task.run();
|
||||
});
|
||||
}
|
||||
|
||||
public <T> Future<T> submit(Runnable task, T result) {
|
||||
return super.submit(() -> {
|
||||
MDC.put(Constant.LOG_TRACE_ID_NAME, UUID.randomUUID().toString());
|
||||
task.run();
|
||||
}, result);
|
||||
}
|
||||
|
||||
public <T> Future<T> submit(Callable<T> task) {
|
||||
return super.submit(new Callable<T>() {
|
||||
@Override
|
||||
public T call() throws Exception {
|
||||
MDC.put(Constant.LOG_TRACE_ID_NAME, UUID.randomUUID().toString());
|
||||
return task.call();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
taskRegistrar.setScheduler(executor);
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package com.accompany.scheduler.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 定时任务配置信息
|
||||
*/
|
||||
|
||||
@Data
|
||||
@RefreshScope
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "task")
|
||||
public class TaskPropertyConfig {
|
||||
|
||||
|
||||
private String checkUserTime;
|
||||
|
||||
private int beforeDay;
|
||||
|
||||
private int size;
|
||||
|
||||
private String startTime;
|
||||
|
||||
private String updatePrizeTime;
|
||||
|
||||
private int prizeSize;
|
||||
|
||||
private String updateHotValueTime;
|
||||
|
||||
private int updateLimit;
|
||||
|
||||
private String updateAuditCount;
|
||||
|
||||
private String sumPurseTime;
|
||||
|
||||
private String financeTime;
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package com.accompany.scheduler.constant;
|
||||
|
||||
/**
|
||||
* @author PaperCut
|
||||
* Created by PaperCut on 2018/8/1.
|
||||
* Quartz任务类型
|
||||
*/
|
||||
public enum QuartzJobType {
|
||||
JavaJobClass(1, "JavaJobClass"), SqlJob(2, "SqlJob"), HttpGetJob(3, "HttpGetJob");
|
||||
public final int value;
|
||||
|
||||
private final String desc;
|
||||
|
||||
QuartzJobType(int value, String desc) {
|
||||
this.value = value;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public static String getDesc(int type) {
|
||||
for (QuartzJobType enumType : QuartzJobType.values()) {
|
||||
if (enumType.value == type) {
|
||||
return enumType.getDesc();
|
||||
}
|
||||
}
|
||||
return "" + type;
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package com.accompany.scheduler.exception;
|
||||
|
||||
public class JobException extends RuntimeException {
|
||||
public JobException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public JobException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JobException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public JobException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
protected JobException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package com.accompany.scheduler.init;
|
||||
|
||||
import com.accompany.business.sensitvienew.SensitiveFilterUtil;
|
||||
import com.accompany.business.sensitvienew.SensitiveNewService;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SensitiveInitRunner implements CommandLineRunner, ApplicationContextAware {
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
SensitiveFilterUtil.setSensitiveService(applicationContext.getBean(SensitiveNewService.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
}
|
@@ -0,0 +1,330 @@
|
||||
package com.accompany.scheduler.job;
|
||||
|
||||
import com.accompany.business.service.ErBanNetEaseService;
|
||||
import com.accompany.business.service.user.UsersService;
|
||||
import com.accompany.business.vo.RunningRoomVo;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.accompany.core.service.user.UsersBaseService;
|
||||
import com.accompany.core.util.StringUtils;
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 随机加减机器人任务
|
||||
*
|
||||
* @author yanghaoyu
|
||||
*/
|
||||
public class AddRobotToRoomJob implements Job {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AddRobotToRoomJob.class);
|
||||
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
|
||||
@Autowired
|
||||
private ErBanNetEaseService erBanNetEaseService;
|
||||
|
||||
@Autowired
|
||||
private UsersService usersService;
|
||||
|
||||
@Autowired
|
||||
private UsersBaseService usersBaseService;
|
||||
|
||||
private Gson gson = new Gson();
|
||||
|
||||
private static boolean flags = false;
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext arg0) throws JobExecutionException {
|
||||
logger.info("正在执行随机加减机器人至房间定时任务.");
|
||||
//获取所有正在运行的房间
|
||||
Type type = new TypeToken<List<String>>() {
|
||||
}.getType();
|
||||
List<Long> notAddIds = Constant.IOSAuditAccount.auditAccountList;
|
||||
List<String> removeIds = Lists.newArrayList();
|
||||
List<String> addIds = Lists.newArrayList();
|
||||
Map<String, String> map = jedisService.hgetAllBykey(RedisKey.room_running.getKey());
|
||||
//判断上次添加机器人的房间是否有关闭的,如果有则找出来并把添加的机器人还原到not_running_robot中
|
||||
if (map != null && map.size() > 0) {
|
||||
flags = false;
|
||||
Map<String, String> map2 = jedisService.hgetAllBykey(RedisKey.running_robot.getKey());
|
||||
if (map2 != null && map2.size() > 0) {
|
||||
for (Map.Entry<String, String> entry : map2.entrySet()) {
|
||||
boolean flag = false;
|
||||
String roomUid = null;
|
||||
for (Map.Entry<String, String> stringEntry : map.entrySet()) {
|
||||
if (entry.getKey().equals(stringEntry.getKey())) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
if (!flag) {
|
||||
roomUid = entry.getKey();
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
//当前房间为关闭房间,将该房间的机器人id从running_robot中移动到not_running_robot.
|
||||
jedisService.hdelete(RedisKey.running_robot.getKey(), roomUid, null);
|
||||
removeIds.add(roomUid.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String removeId : removeIds) {
|
||||
map2.remove(removeId);
|
||||
}
|
||||
//加机器人操作
|
||||
//获得未被使用的机器人ids
|
||||
String idsNotRunStr = jedisService.read(RedisKey.not_running_robot.getKey());
|
||||
if (StringUtils.isEmpty(idsNotRunStr)) {
|
||||
idsNotRunStr = getRobotList();
|
||||
}
|
||||
List<String> ids = gson.fromJson(idsNotRunStr, type);
|
||||
//打乱机器人顺序
|
||||
Collections.shuffle(ids);
|
||||
//获取已存在机器人的房间
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
//获得当前房间
|
||||
if (notAddIds.contains(Long.parseLong(entry.getKey()))) {
|
||||
continue;
|
||||
}
|
||||
RunningRoomVo runningRoomVo = gson.fromJson(entry.getValue(), RunningRoomVo.class);
|
||||
//判断当前房间是否有机器人
|
||||
String robotStr = null;
|
||||
for (Map.Entry<String, String> entrys : map2.entrySet()) {
|
||||
if (entrys.getKey().equals(entry.getKey())) {
|
||||
robotStr = entrys.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
List<String> idList = Lists.newArrayList();
|
||||
if (!StringUtils.isEmpty(robotStr)) {
|
||||
idList = gson.fromJson(robotStr, type);
|
||||
}
|
||||
//判断当前房间机器人数量是不是大于20
|
||||
if (idList.size() < 20) {
|
||||
//获取要添加的机器人
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
idsNotRunStr = getRobotList();
|
||||
ids = gson.fromJson(idsNotRunStr, type);
|
||||
}
|
||||
String id = ids.remove(ids.size() - 1);
|
||||
idList.add(id);
|
||||
String idListStr = gson.toJson(idList);
|
||||
try {
|
||||
//将机器人添加到房间
|
||||
List<String> array = Lists.newArrayList();
|
||||
addIds.add(id);
|
||||
array.add(id);
|
||||
String accids = gson.toJson(array);
|
||||
erBanNetEaseService.addRobotToRoom(runningRoomVo.getRoomId(), accids);
|
||||
//将添加的机器人添加到running_robot缓存中
|
||||
map2.put(runningRoomVo.getUid().toString(), idListStr);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
//减机器人操作
|
||||
Random random = new Random();
|
||||
if (map.size() <= 2) {
|
||||
int randomNum = random.nextInt(map.size());
|
||||
int num = 0;
|
||||
//房间数小于2
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
if (randomNum != num) {
|
||||
num++;
|
||||
continue;
|
||||
}
|
||||
//随机选取一个房间删除机器人
|
||||
RunningRoomVo runningRoomVo = gson.fromJson(entry.getValue(), RunningRoomVo.class);
|
||||
//获取当前房间的机器人列表
|
||||
String idListStr = null;
|
||||
for (Map.Entry<String, String> entrys : map2.entrySet()) {
|
||||
if (entrys.getKey().equals(runningRoomVo.getUid().toString())) {
|
||||
idListStr = entrys.getValue();
|
||||
}
|
||||
}
|
||||
if (StringUtils.isEmpty(idListStr)) {
|
||||
continue;
|
||||
}
|
||||
List<String> list = gson.fromJson(idListStr, type);
|
||||
if (list.size() < 5) {
|
||||
continue;
|
||||
}
|
||||
Collections.shuffle(list);
|
||||
//得到删除的机器人id,并将其添加到not_running_robot缓存中
|
||||
String id = null;
|
||||
if (addIds.contains(list.get(list.size() - 1))) {
|
||||
if (list.size() < 2) {
|
||||
continue;
|
||||
}
|
||||
id = list.remove(list.size() - 2);
|
||||
} else {
|
||||
id = list.remove(list.size() - 1);
|
||||
}
|
||||
ids.add(id);
|
||||
try {
|
||||
//删除当前房间机器人
|
||||
List<String> array = Lists.newArrayList();
|
||||
array.add(id);
|
||||
String accids = gson.toJson(array);
|
||||
erBanNetEaseService.deleteRobotToRoom(runningRoomVo.getRoomId(), accids);
|
||||
//将删除的机器人从running_robot中删除
|
||||
idListStr = gson.toJson(list);
|
||||
map2.put(runningRoomVo.getUid().toString(), idListStr);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
List<Integer> lists = Lists.newArrayList();
|
||||
int roomSize = 0;
|
||||
while (roomSize < 2) {
|
||||
int randomNum = random.nextInt(map.size());
|
||||
int num = 0;
|
||||
if (lists.contains(randomNum)) {
|
||||
continue;
|
||||
}
|
||||
lists.add(randomNum);
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
if (randomNum != num) {
|
||||
num++;
|
||||
continue;
|
||||
}
|
||||
//随机选取一个房间删除机器人
|
||||
RunningRoomVo runningRoomVo = gson.fromJson(entry.getValue(), RunningRoomVo.class);
|
||||
//获取当前房间的机器人列表
|
||||
String idListStr = null;
|
||||
for (Map.Entry<String, String> entrys : map2.entrySet()) {
|
||||
if (entry.getKey().equals(entrys.getKey())) {
|
||||
idListStr = entrys.getValue();
|
||||
}
|
||||
}
|
||||
if (StringUtils.isEmpty(idListStr)) {
|
||||
continue;
|
||||
}
|
||||
List<String> list = gson.fromJson(idListStr, type);
|
||||
Collections.shuffle(list);
|
||||
//得到删除的机器人id,并将其添加到not_running_robot缓存中
|
||||
String id = null;
|
||||
if (addIds.contains(list.get(list.size() - 1))) {
|
||||
if (list.size() < 2) {
|
||||
continue;
|
||||
}
|
||||
id = list.remove(list.size() - 2);
|
||||
} else {
|
||||
id = list.remove(list.size() - 1);
|
||||
}
|
||||
ids.add(id);
|
||||
roomSize++;
|
||||
try {
|
||||
List<String> array = Lists.newArrayList();
|
||||
array.add(id);
|
||||
String accids = gson.toJson(array);
|
||||
//删除当前房间机器人
|
||||
erBanNetEaseService.deleteRobotToRoom(runningRoomVo.getRoomId(), accids);
|
||||
//将删除的机器人从running_robot中删除
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
idListStr = gson.toJson(list);
|
||||
map2.put(runningRoomVo.getUid().toString(), idListStr);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
jedisService.hwrite(RedisKey.running_robot.getKey(), map2);
|
||||
idsNotRunStr = gson.toJson(ids);
|
||||
jedisService.set(RedisKey.not_running_robot.getKey(), idsNotRunStr);
|
||||
} else {
|
||||
if (!flags) {
|
||||
logger.info("无人开房,删除已使用的机器人");
|
||||
jedisService.hdeleteKey(RedisKey.running_robot.getKey());
|
||||
flags = true;
|
||||
} else {
|
||||
logger.info("无人开房,无正在使用的机器人");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//获得100男性机器人,50女性机器人
|
||||
public String getRobotList() {
|
||||
Map<String, String> woManRobotMap = jedisService.hgetAll(RedisKey.add_woman.getKey());
|
||||
List<String> ids = Lists.newArrayList();
|
||||
List<String> ids2 = Lists.newArrayList();
|
||||
if (woManRobotMap != null && woManRobotMap.size() > 0) {
|
||||
for (Map.Entry<String, String> entry : woManRobotMap.entrySet()) {
|
||||
Type type = new TypeToken<List<String>>() {
|
||||
}.getType();
|
||||
ids = gson.fromJson(entry.getValue(), type);
|
||||
jedisService.hdelete(RedisKey.add_woman.getKey(), entry.getKey(), null);
|
||||
Integer i = Integer.parseInt(entry.getKey()) + 50;
|
||||
if (i > ids.size() - 1) {
|
||||
jedisService.hwrite(RedisKey.add_woman.getKey(), 50 + "", entry.getValue());
|
||||
ids = ids.subList(0, 50);
|
||||
} else {
|
||||
jedisService.hwrite(RedisKey.add_woman.getKey(), i.toString(), entry.getValue());
|
||||
ids = ids.subList(Integer.parseInt(entry.getKey()), i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<Users> list = usersBaseService.getUsersByRobot((byte) 2);
|
||||
List<String> arrays = Lists.newArrayList();
|
||||
for (Users user : list) {
|
||||
arrays.add(user.getUid().toString());
|
||||
}
|
||||
String listStr = gson.toJson(arrays);
|
||||
jedisService.hwrite(RedisKey.add_woman.getKey(), 0 + "", listStr);
|
||||
ids.addAll(arrays);
|
||||
}
|
||||
Map<String, String> manRobotMap = jedisService.hgetAll(RedisKey.add_man.getKey());
|
||||
if (manRobotMap != null && manRobotMap.size() > 0) {
|
||||
for (Map.Entry<String, String> manEntry : manRobotMap.entrySet()) {
|
||||
Type type = new TypeToken<List<String>>() {
|
||||
}.getType();
|
||||
ids2 = gson.fromJson(manEntry.getValue(), type);
|
||||
jedisService.hdelete(RedisKey.add_man.getKey(), manEntry.getKey(), null);
|
||||
Integer i = Integer.parseInt(manEntry.getKey()) + 100;
|
||||
if (i > ids2.size() - 1) {
|
||||
jedisService.hwrite(RedisKey.add_man.getKey(), 100 + "", manEntry.getValue());
|
||||
ids2 = ids2.subList(0, 100);
|
||||
} else {
|
||||
jedisService.hwrite(RedisKey.add_man.getKey(), i.toString(), manEntry.getValue());
|
||||
ids2 = ids2.subList(Integer.parseInt(manEntry.getKey()), i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<Users> list = usersBaseService.getUsersByRobot((byte) 1);
|
||||
List<String> arrays = Lists.newArrayList();
|
||||
for (Users user : list) {
|
||||
arrays.add(user.getUid().toString());
|
||||
}
|
||||
String listStr = gson.toJson(arrays);
|
||||
jedisService.hwrite(RedisKey.add_man.getKey(), 0 + "", listStr);
|
||||
ids2.addAll(arrays);
|
||||
}
|
||||
ids.addAll(ids2);
|
||||
String idsNotRunStr = gson.toJson(ids);
|
||||
jedisService.set(RedisKey.not_running_robot.getKey(), idsNotRunStr);
|
||||
return idsNotRunStr;
|
||||
}
|
||||
}
|
@@ -0,0 +1,464 @@
|
||||
package com.accompany.scheduler.job;
|
||||
|
||||
|
||||
import com.accompany.business.service.ErBanNetEaseService;
|
||||
import com.accompany.business.vo.RunningRoomVo;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.core.model.UsersExample;
|
||||
import com.accompany.core.mybatismapper.UsersMapper;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class AddRobotToRoomJob2 implements Job {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AddRobotToRoomJob2.class);
|
||||
private Type type = new TypeToken<List<String>>() {
|
||||
}.getType();
|
||||
//机器人最大数
|
||||
private static final Integer MAX_ROBOT_NUM = 20;
|
||||
//上一次房间数据
|
||||
private static Map<String, String> preRoom = null;
|
||||
private static Map<String, String> currentRoom = null;
|
||||
private static Map<String, String> runRobot = null;
|
||||
private static List<String> notRunRobot = null;
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
@Autowired
|
||||
private UsersMapper usersMapper;
|
||||
@Autowired
|
||||
private ErBanNetEaseService erBanNetEaseService;
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
/*
|
||||
1. 房间关闭问题
|
||||
*/
|
||||
updateCurrentInfo();
|
||||
try {
|
||||
//当前没有在线房间
|
||||
if (CollectionUtils.isEmpty(currentRoom)) {
|
||||
LOGGER.info("----------当前没有在线房间----------");
|
||||
//清除所有机器人
|
||||
clearAllRobotInPreRoom();
|
||||
preRoom = null;
|
||||
return;
|
||||
} else {//当前有在线房间
|
||||
clearRobotInClosedRoom();
|
||||
}
|
||||
/*
|
||||
2. 机器人添加问题
|
||||
(1)随机获取一个房间
|
||||
(2)机器人操作
|
||||
① 移除机器人
|
||||
② 增加机器人
|
||||
*/
|
||||
for (Map.Entry<String, String> currentEntry : currentRoom.entrySet()) {
|
||||
|
||||
addRobotInRoom(currentEntry.getKey());
|
||||
|
||||
}
|
||||
// String roomKey = getRoomIdWithRandom ( );
|
||||
// LOGGER.info ( "随机选择的房间是: " + roomKey );
|
||||
//对房间进行操作
|
||||
// addRobotInRoom ( roomKey );
|
||||
/*
|
||||
3. 将数据写入缓存
|
||||
*/
|
||||
saveCurrentInfo();
|
||||
preRoom = clone(currentRoom);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加机器人操作
|
||||
* (先把旧的机器从run_robot找出来,在从not_run_robot中随机抽取一定数量的机器人填入,在最后再把旧的机器人插入到not_run_robot
|
||||
* 中(防止旧的机器人和新的机器人重叠))
|
||||
* 每次往房间里增加一个机器人,当数量达到了设定值MAX_ROBOT_NUM,每次移除一个机器人,同时增加一个机器人,保持数量在MAX_ROBOT_NUM
|
||||
*
|
||||
* @param roomKey
|
||||
*/
|
||||
private void addRobotInRoom(String roomKey) {
|
||||
|
||||
Integer preRobotNum = 0;
|
||||
boolean overRobot = false;
|
||||
//判断房间是否存在机器人
|
||||
//如果有,移除
|
||||
List<String> oldRobotList = getRobotListInRoom(roomKey);
|
||||
if (!CollectionUtils.isEmpty(oldRobotList)) {
|
||||
//存在机器人
|
||||
preRobotNum = oldRobotList.size();
|
||||
//移除机器人
|
||||
}
|
||||
//房间机器人数量超过设定值,
|
||||
if (preRobotNum >= MAX_ROBOT_NUM) {
|
||||
overRobot = true;
|
||||
}
|
||||
//获取notRobot数量
|
||||
Integer notRobotNum = notRunRobot.size();
|
||||
//往房间里增加一定数量(大于或等于上一次的数量)机器人
|
||||
Random random = new Random();
|
||||
Integer addNum = 1;//random.nextInt ( MAX_ROBOT_NUM + 1 - preRobotNum ) + preRobotNum;
|
||||
if (notRobotNum==0) {
|
||||
//添加机器人的数量比空闲机器人的数量总数还要大
|
||||
notRunRobot=Lists.newArrayList();
|
||||
LOGGER.info("机器人库不足!!!" + "剩余:" + notRobotNum);
|
||||
return;
|
||||
}
|
||||
LOGGER.info("往房间增加:" + addNum + "个机器人");
|
||||
//随机从房间里删除一定数量的机器人
|
||||
List<String> deleteRobotList = new ArrayList<>();
|
||||
//产生addNum个数量的随机机器人
|
||||
List<String> robotList = new ArrayList<>();
|
||||
for (int i = 0; i < addNum; i++) {
|
||||
//添加addNum个机器人
|
||||
robotList.add(notRunRobot.get(random.nextInt(notRobotNum)));
|
||||
//随机删除addNum个机器人
|
||||
if (overRobot) {
|
||||
deleteRobotList.add(oldRobotList.get(random.nextInt(oldRobotList.size())));
|
||||
}
|
||||
}
|
||||
//TODO 云信操作
|
||||
String accidsDel = new Gson().toJson(deleteRobotList);
|
||||
String accidsAdd = new Gson().toJson(robotList);
|
||||
RunningRoomVo runningRoomVo = null;
|
||||
for (Map.Entry<String, String> currentEntry : currentRoom.entrySet()) {
|
||||
if (currentEntry.getKey().equals(roomKey)) {
|
||||
String value = currentEntry.getValue();
|
||||
runningRoomVo = new Gson().fromJson(value, RunningRoomVo.class);
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (!CollectionUtils.isEmpty(deleteRobotList)) {
|
||||
erBanNetEaseService.deleteRobotToRoom(runningRoomVo.getRoomId(), accidsDel);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
erBanNetEaseService.addRobotToRoom(runningRoomVo.getRoomId(), accidsAdd);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (CollectionUtils.isEmpty(oldRobotList)) {
|
||||
oldRobotList = new ArrayList<>();
|
||||
}
|
||||
for (int i = 0; i < robotList.size(); i++) {
|
||||
oldRobotList.add(robotList.get(i));
|
||||
}
|
||||
for (int i = 0; i < deleteRobotList.size(); i++) {
|
||||
oldRobotList.remove(deleteRobotList.get(i));
|
||||
}
|
||||
insertRobotInCache(roomKey, oldRobotList, deleteRobotList);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机获取一个房间Id
|
||||
*
|
||||
* @return 房间ID
|
||||
*/
|
||||
private String getRoomIdWithRandom() {
|
||||
|
||||
Random random = new Random();
|
||||
Integer roomNum = currentRoom.size();
|
||||
List<String> roomKeyList = new ArrayList<>();
|
||||
//rand.nextInt(MAX - MIN + 1) + MIN; // randNumber 将被赋值为一个 MIN 和 MAX 范围内的随机数
|
||||
Integer randNum = random.nextInt(roomNum) + 0;
|
||||
for (Map.Entry<String, String> roomEntry : currentRoom.entrySet()) {
|
||||
roomKeyList.add(roomEntry.getKey());
|
||||
}
|
||||
return roomKeyList.get(randNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除上一次房间中的所有机器人
|
||||
*/
|
||||
private void clearAllRobotInPreRoom() throws Exception {
|
||||
|
||||
List<String> roomList = new ArrayList<>();
|
||||
if (!CollectionUtils.isEmpty(preRoom)) {
|
||||
for (Map.Entry<String, String> preEntry : preRoom.entrySet()) {
|
||||
roomList.add(preEntry.getKey());
|
||||
}
|
||||
//TODO 清除上一次房间中的所有机器人
|
||||
clearRobotInClosedRoom(roomList);
|
||||
}
|
||||
//两次都没有在线的房间
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 从Redis中读取当前房间信息,机器人在房间的情况,机器人不在房间的情况
|
||||
*/
|
||||
private void updateCurrentInfo() {
|
||||
|
||||
//获取当前房间状态,在房间的机器人,不在房间的机器人
|
||||
currentRoom = jedisService.hgetAllBykey(RedisKey.room_running.getKey());
|
||||
runRobot = jedisService.hgetAllBykey(RedisKey.running_robot.getKey());
|
||||
notRunRobot = getNotRunRobot();
|
||||
}
|
||||
|
||||
private void saveCurrentInfo() {
|
||||
jedisService.hwrite(RedisKey.running_robot.getKey(), runRobot);
|
||||
String notRunRobotStr = new Gson().toJson(notRunRobot);
|
||||
jedisService.set(RedisKey.not_running_robot.getKey(), notRunRobotStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前有在线的房间
|
||||
* 1.查找是否存在关闭的房间?
|
||||
* 2.(清除残余机器人)
|
||||
*/
|
||||
private void clearRobotInClosedRoom() throws Exception {
|
||||
|
||||
List<String> closeRommList = new ArrayList<>();
|
||||
boolean hasClosedRoom = true;
|
||||
//没有上一次房间信息,说明属于都是新开的房(不存在关闭的房间(残留机器人))
|
||||
if (preRoom == null) {
|
||||
LOGGER.info("----------上一次没有开房记录----------");
|
||||
preRoom = clone(currentRoom);
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* 找出关闭房(上一次记录存在,当前记录不存在的房间)
|
||||
* 遍历上次信息,查看当前房是否存在,存在:房间未关闭;不存在:反之
|
||||
*/
|
||||
//比较两次房间信息(uid是否相等)
|
||||
for (Map.Entry<String, String> preEntry : preRoom.entrySet()) {
|
||||
for (Map.Entry<String, String> entry : currentRoom.entrySet()) {
|
||||
//uid相等,两次房间相同
|
||||
if (entry.getKey().equals(preEntry.getKey())) {
|
||||
LOGGER.info("前后两次有相同的房间:" + preEntry.getKey());
|
||||
hasClosedRoom = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasClosedRoom) {
|
||||
LOGGER.info("存在关闭房:" + preEntry.getKey());
|
||||
closeRommList.add(preEntry.getKey());
|
||||
}
|
||||
hasClosedRoom = true;
|
||||
}
|
||||
//TODO 清理关闭房间中机器人处理
|
||||
clearRobotInClosedRoom(closeRommList);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 清除关闭房间中的机器人
|
||||
*
|
||||
* @param roomList 关闭房间列表()
|
||||
*/
|
||||
private void clearRobotInClosedRoom(List<String> roomList) throws Exception {
|
||||
|
||||
for (int i = 0; i < roomList.size(); i++) {
|
||||
|
||||
/*
|
||||
更新缓存中的机器人的信息
|
||||
(这里先不对redis直接操作,先对runRobot,和notRunRobot操作,最后再写进去)
|
||||
(一个房间可能存在很多机器人,所以先获取机器人列表)
|
||||
*/
|
||||
//获取机器人列表
|
||||
List<String> robotList = getRobotListInRoom(roomList.get(i));
|
||||
//1.running_robot(删除正在房间的机器人)
|
||||
//2.not_running_robot(增加到不在房间的机器人列表中)(通过机器人的uid)
|
||||
deleteRobotInCache(roomList.get(i), robotList);
|
||||
//TODO 删除云信中机器人
|
||||
//删除当前房间机器人
|
||||
List<String> array = Lists.newArrayList();
|
||||
for (int j = 0; j < robotList.size(); j++) {
|
||||
array.add(robotList.get(j));
|
||||
}
|
||||
String accids = new Gson().toJson(array);
|
||||
RunningRoomVo runningRoomVo = null;
|
||||
for (Map.Entry<String, String> preEntry : preRoom.entrySet()) {
|
||||
if (preEntry.getKey().equals(roomList.get(i))) {
|
||||
String value = preEntry.getValue();
|
||||
runningRoomVo = new Gson().fromJson(value, RunningRoomVo.class);
|
||||
}
|
||||
}
|
||||
erBanNetEaseService.deleteRobotToRoom(runningRoomVo.getRoomId(), accids);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 把机器人从运行状态切换到空闲状态
|
||||
* (在房间 == 》 不在房间)
|
||||
*
|
||||
* @param roomKey 房间ID
|
||||
* @param robotList 机器人列表
|
||||
*/
|
||||
private void deleteRobotInCache(String roomKey, List<String> robotList) {
|
||||
//删除run_robot
|
||||
runRobot.remove(roomKey);
|
||||
//遍历删除notRunRobot
|
||||
if (!CollectionUtils.isEmpty(robotList)) {
|
||||
for (int i = 0; i < robotList.size(); i++) {
|
||||
notRunRobot.add(robotList.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 把机器人从空闲状态切换到运行状态
|
||||
* (不在房间 == 》在房间)
|
||||
* 移除机器人:从run_robot更新机器人列表,从not_run_robot移除并增加
|
||||
*
|
||||
* @param roomKey 房间ID
|
||||
* @param robotList 机器人列表
|
||||
* @param oldRobotList 旧的机器人
|
||||
*/
|
||||
private void insertRobotInCache(String roomKey, List<String> robotList, List<String> oldRobotList) {
|
||||
|
||||
//1.把房间里的机器人删除run_robot
|
||||
runRobot.remove(roomKey);
|
||||
//2.把机器人插入到房间run_robot
|
||||
String robotListStr = new Gson().toJson(robotList);
|
||||
runRobot.put(roomKey, robotListStr);
|
||||
//3.更新不在房间机器人列表not_run_robot
|
||||
if (!CollectionUtils.isEmpty(robotList)) {
|
||||
for (int i = 0; i < robotList.size(); i++) {
|
||||
//移除
|
||||
notRunRobot.remove(robotList.get(i));
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < oldRobotList.size(); i++) {
|
||||
notRunRobot.add(oldRobotList.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取某个房间的机器人列表
|
||||
*
|
||||
* @param roomKey 房间ID
|
||||
* @return
|
||||
*/
|
||||
private List<String> getRobotListInRoom(String roomKey) {
|
||||
|
||||
|
||||
List<String> robotList = new ArrayList<>();
|
||||
String robotListStr = "";
|
||||
//遍历running_robot,查找对应房间的机器人
|
||||
if (!CollectionUtils.isEmpty(runRobot)) {
|
||||
for (Map.Entry<String, String> runRobotEntry : runRobot.entrySet()) {
|
||||
if (runRobotEntry.getKey().equals(roomKey)) {
|
||||
robotListStr = runRobotEntry.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
robotList = new Gson().fromJson(robotListStr, type);
|
||||
return robotList;
|
||||
|
||||
}
|
||||
|
||||
//Map克隆方法:
|
||||
public <T extends Serializable> T clone(Map<String, String> obj) {
|
||||
T cloneObj = null;
|
||||
try {
|
||||
// 写入字节流
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ObjectOutputStream obs = new ObjectOutputStream(out);
|
||||
obs.writeObject(obj);
|
||||
obs.close();
|
||||
|
||||
// 分配内存,写入原始对象,生成新对象
|
||||
ByteArrayInputStream ios = new ByteArrayInputStream(out.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(ios);
|
||||
// 返回生成的新对象
|
||||
cloneObj = (T) ois.readObject();
|
||||
ois.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return cloneObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取没有在房间(空闲)的机器人
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private List<String> getNotRunRobot() {
|
||||
|
||||
List<String> notRunRobot = null;
|
||||
notRunRobot = getNotRunRobotCache();
|
||||
//从缓存中获取
|
||||
if (CollectionUtils.isEmpty(notRunRobot)) {
|
||||
//从数据库中获取
|
||||
notRunRobot = getNotRunRobotDB();
|
||||
if (CollectionUtils.isEmpty(notRunRobot)) {
|
||||
return null;
|
||||
} else {
|
||||
saveNotRunRobotCache(notRunRobot);
|
||||
}
|
||||
}
|
||||
return notRunRobot;
|
||||
}
|
||||
|
||||
private void saveNotRunRobotCache(List<String> list) {
|
||||
|
||||
String string = new Gson().toJson(list);
|
||||
jedisService.set(RedisKey.not_running_robot.getKey(), string);
|
||||
|
||||
}
|
||||
|
||||
private List<String> getNotRunRobotCache() {
|
||||
|
||||
String notRunRobotStr = jedisService.read(RedisKey.not_running_robot.getKey());
|
||||
if (notRunRobotStr == null) {
|
||||
return null;
|
||||
}
|
||||
List<String> list = new Gson().fromJson(notRunRobotStr, type);
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<String> getNotRunRobotDB() {
|
||||
LOGGER.info("==========从数据库中获取空闲机器人列表==========");
|
||||
List<String> list = new ArrayList<>();
|
||||
UsersExample usersExample = new UsersExample();
|
||||
usersExample.createCriteria().andDefUserEqualTo((byte) 3);
|
||||
List<Users> usersList = usersMapper.selectByExample(usersExample);
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < usersList.size(); i++) {
|
||||
list.add(String.valueOf(usersList.get(i).getUid()));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void business(String[] args) {
|
||||
Random rand = new Random();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
//int randNumber = rand.nextInt(MAX - MIN + 1) + MIN; // randNumber 将被赋值为一个 MIN 和 MAX 范围内的随机数
|
||||
System.out.println(rand.nextInt(0) + 0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,136 @@
|
||||
package com.accompany.scheduler.job;
|
||||
|
||||
import com.accompany.core.model.Room;
|
||||
import com.accompany.business.service.ErBanNetEaseService;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.accompany.business.service.room.RoomHotService;
|
||||
import com.accompany.business.service.room.RoomService;
|
||||
import com.accompany.business.vo.RoomVo;
|
||||
import com.google.gson.Gson;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.netease.neteaseacc.result.RoomUserListRet;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* 定时检查房间是否异常关闭任务
|
||||
*
|
||||
* @author yanghaoyu
|
||||
*/
|
||||
public class CheckRoomExceptionJob implements Job {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CheckRoomExceptionJob.class);
|
||||
@Autowired
|
||||
private RoomService roomService;
|
||||
|
||||
@Autowired
|
||||
private ErBanNetEaseService erBanNetEaseService;
|
||||
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
|
||||
@Autowired
|
||||
private RoomHotService roomHotService;
|
||||
|
||||
private Gson gson = new Gson();
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext arg0) throws JobExecutionException {
|
||||
try {
|
||||
logger.info("正在执行定时任务:查询异常退出房间数据");
|
||||
/* 从缓存中查询正在开播的房间id */
|
||||
List<Long> keepAliveRoomUids = roomHotService.getVipRoomListByCheckRoom();
|
||||
Map<String, String> map = jedisService.hgetAll(RedisKey.room_running.getKey());
|
||||
List<RoomVo> roomList = new ArrayList<>();
|
||||
if (map != null && map.size() > 0) {
|
||||
Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<String, String> entry = it.next();
|
||||
String key = entry.getKey();
|
||||
if (StringUtils.isNotEmpty(key)) {
|
||||
String roomVoStr = jedisService.hget(RedisKey.room.getKey(), key.toString());
|
||||
RoomVo roomVo = gson.fromJson(roomVoStr, RoomVo.class);
|
||||
roomList.add(roomVo);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
roomList = roomService.getHomeRunningRoomList();
|
||||
}
|
||||
for (RoomVo roomVo : roomList) {
|
||||
/* 是否是开播状态 */
|
||||
if (roomVo!=null && roomVo.getValid()!= null && roomVo.getValid()) {
|
||||
/* 是否是断开连接状态 */
|
||||
/* 查询房间信息 */
|
||||
if (!CollectionUtils.isEmpty(keepAliveRoomUids)) {
|
||||
boolean flag = keepAliveRoomUids.contains(roomVo.getUid());
|
||||
if (flag) {
|
||||
logger.info("当前房间是vip房间,不进行异常关闭检查.uid=" + roomVo.getUid());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (roomVo.getIsExceptionClose()) {
|
||||
/* 断开连接时间是否超过5分钟 */
|
||||
if ((System.currentTimeMillis() - roomVo.getExceptionCloseTime().getTime()) > 60000*10) {
|
||||
logger.info("当前房间已经断开连接超过10分钟,判断是否重连:uid=" + roomVo.getUid());
|
||||
/* 判断是否重连 */
|
||||
/* 查询房间所有成员信息 */
|
||||
Room room = new Room();
|
||||
room.setUid(roomVo.getUid());
|
||||
//查询云信中当前房间的状态
|
||||
RoomUserListRet roomUserListRet = erBanNetEaseService
|
||||
.getRoomMemberListInfo(roomVo.getRoomId(), roomVo.getUid());
|
||||
//房间没没有在线人员 关闭房间
|
||||
if (roomUserListRet == null) {
|
||||
roomService.closeRoom(roomVo.getUid());
|
||||
continue;
|
||||
}
|
||||
//或者房间类型为陪伴房的时候 关闭房间
|
||||
if (roomUserListRet != null) {
|
||||
if (null != roomVo.getType()) {
|
||||
if (roomVo.getType().equals(Constant.RoomType.companion)) {
|
||||
roomService.closeRoom(roomVo.getUid());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Entry<String, List<Map<String, Object>>> entry : roomUserListRet.getDesc()
|
||||
.entrySet()) {
|
||||
for (Entry<String, Object> entry2 : entry.getValue().get(0).entrySet()) {
|
||||
if ("onlineStat".equals(entry2.getKey())) {
|
||||
boolean onlineStat = (boolean) entry2.getValue();
|
||||
/* 是否在线,在线为true */
|
||||
if (onlineStat) {
|
||||
logger.info("当前房间已经重连,uid:" + roomVo.getUid());
|
||||
/* 重新连接上 ,将异常信息改为false */
|
||||
room.setIsExceptionClose(false);
|
||||
} else {
|
||||
logger.info("当前房间未重连,正在关闭房间。uid:" + roomVo.getUid());
|
||||
/* 未重新链接,关闭房间 */
|
||||
roomService.closeRoom(roomVo.getUid());
|
||||
room.setValid(false);
|
||||
room.setIsExceptionClose(false);
|
||||
}
|
||||
roomService.updateRunningRoom(room);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("定时任务:查询异常房间失败。", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package com.accompany.scheduler.job;
|
||||
|
||||
import com.accompany.scheduler.model.QuartzJob;
|
||||
import com.accompany.scheduler.util.HttpUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobExecutionContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by PaperCut on 2018/6/11.
|
||||
* Http请求任务实体
|
||||
*/
|
||||
@Slf4j
|
||||
public class HttpGetJobDetail implements Job {
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) {
|
||||
JobDataMap dataMap = jobExecutionContext.getMergedJobDataMap();
|
||||
QuartzJob job = (QuartzJob) dataMap.get("jobBean");
|
||||
String url = job.getJobData();
|
||||
log.info("Invoking http GET: {}", url);
|
||||
try {
|
||||
String resp = HttpUtils.get(null, url);
|
||||
if (resp == null) {
|
||||
log.error("Failed to request http get: {}, result is null", url);
|
||||
} else {
|
||||
log.info("Successful http get: {}", url);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to invoke http GET: {}, msg: {}", url, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package com.accompany.scheduler.job;
|
||||
|
||||
import org.quartz.spi.TriggerFiredBundle;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.scheduling.quartz.AdaptableJobFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author yanghaoyu 将quartz中的job注入到spring容器中,交给他管理。
|
||||
*/
|
||||
@Service("jobFactory")
|
||||
public class JobFactory extends AdaptableJobFactory {
|
||||
|
||||
@Autowired
|
||||
private AutowireCapableBeanFactory capableBeanFactory;
|
||||
|
||||
@Override
|
||||
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
|
||||
Object jobInstance = super.createJobInstance(bundle);
|
||||
/* 进行注入 */
|
||||
capableBeanFactory.autowireBean(jobInstance);
|
||||
return jobInstance;
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package com.accompany.scheduler.job;
|
||||
|
||||
import com.accompany.business.mybatismapper.StatWeekListsMapper;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.google.gson.Gson;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@Slf4j
|
||||
public class RefreshGiftWeekListJob implements Job {
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
@Autowired
|
||||
private StatWeekListsMapper statWeekListMapper;
|
||||
|
||||
private Gson gson = new Gson();
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
log.info("正在执行清除周贡献榜数据任务。");
|
||||
jedisService.hdeleteKey(RedisKey.send_gift_weeklist.getKey());
|
||||
log.info("清除周榜数据成功");
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.accompany.scheduler.job;
|
||||
|
||||
|
||||
import com.accompany.business.service.RobotService;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
|
||||
public class RefreshRobotJob implements Job {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RefreshRobotJob.class);
|
||||
|
||||
@Autowired
|
||||
private RobotService robotService;
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
|
||||
try {
|
||||
robotService.addRobotToPermitRoom();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("RefreshRobotJob error...",e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package com.accompany.scheduler.job;
|
||||
|
||||
import com.accompany.business.mybatismapper.StatWeekListsMapper;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.google.gson.Gson;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@Slf4j
|
||||
public class RefreshWeekListJob implements Job {
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
@Autowired
|
||||
private StatWeekListsMapper statWeekListMapper;
|
||||
|
||||
private Gson gson = new Gson();
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
log.info("正在执行清除周榜数据任务。");
|
||||
jedisService.hdeleteKey(RedisKey.week_list.getKey());
|
||||
log.info("清楚周榜数据成功");
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
package com.accompany.scheduler.job;
|
||||
|
||||
import com.accompany.business.util.SpringContextHolder;
|
||||
import com.accompany.scheduler.model.QuartzJob;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
/** Created by PaperCut on 2018/6/11. Sql任务实体 */
|
||||
@Slf4j
|
||||
public class SqlJobDetail implements Job {
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) {
|
||||
long start = System.currentTimeMillis();
|
||||
JobDataMap dataMap = jobExecutionContext.getMergedJobDataMap();
|
||||
QuartzJob job = (QuartzJob) dataMap.get("jobBean");
|
||||
log.info("获取 jdbcTemplate");
|
||||
JdbcTemplate template = SpringContextHolder.getBean("jdbcTemplate");
|
||||
template.execute(job.getJobData());
|
||||
log.info(job.getJobName() + " executed in {} ms", System.currentTimeMillis() - start);
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
package com.accompany.scheduler.job;
|
||||
|
||||
import com.accompany.business.model.RoomOpenHist;
|
||||
import com.accompany.business.model.StatBasicRoom;
|
||||
import com.accompany.business.mybatismapper.RoomOpenHistMapper;
|
||||
import com.accompany.business.service.statis.StatBasicRoomService;
|
||||
import com.accompany.business.service.user.UsersService;
|
||||
import com.accompany.common.utils.GetTimeUtils;
|
||||
import com.accompany.business.model.RoomOpenHistExample;
|
||||
import com.accompany.core.model.Users;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class StatRoomLiveDataJob implements Job {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(StatRoomLiveDataJob.class);
|
||||
|
||||
@Autowired
|
||||
private RoomOpenHistMapper roomOpenHistMapper;
|
||||
@Autowired
|
||||
private StatBasicRoomService statBasicRoomService;
|
||||
@Autowired
|
||||
private UsersService usersService;
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
logger.info("定时任务:将今日开房时长数据写入到数据库中");
|
||||
Date date = new Date(System.currentTimeMillis() - 87400000);
|
||||
RoomOpenHistExample example = new RoomOpenHistExample();
|
||||
example.createCriteria().andCloseTimeBetween(GetTimeUtils.getTimesnights(date, 0), GetTimeUtils.getTimesnight(0));
|
||||
List<RoomOpenHist> openHists = roomOpenHistMapper.selectByExample(example);
|
||||
Map<Long, Double> map = new HashMap<>();
|
||||
for (RoomOpenHist openHist : openHists) {
|
||||
Double dura = map.put(openHist.getRoomId(), openHist.getDura());
|
||||
if (dura != null) {
|
||||
map.put(openHist.getRoomId(), dura + openHist.getDura());
|
||||
dura = null;
|
||||
}
|
||||
}
|
||||
for (Map.Entry<Long, Double> entry : map.entrySet()) {
|
||||
StatBasicRoom statBasicRoom = new StatBasicRoom();
|
||||
statBasicRoom.setRoomUid(entry.getKey());
|
||||
statBasicRoom.setSumLiveTime(entry.getValue().longValue());
|
||||
statBasicRoom.setCreateTime(new Date());
|
||||
Users users = usersService.getUsersByUid(entry.getKey());
|
||||
if (users == null) {
|
||||
logger.info("当前开播房主uid:" + entry.getKey());
|
||||
} else {
|
||||
statBasicRoom.setNick(users.getNick());
|
||||
statBasicRoom.setErbanNo(users.getErbanNo());
|
||||
}
|
||||
logger.info("更新房间开播时长到数据库,roomUid:" + entry.getKey());
|
||||
statBasicRoomService.insertBasicRoom(statBasicRoom);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,86 @@
|
||||
package com.accompany.scheduler.job;
|
||||
|
||||
import com.accompany.business.model.StatBasicUsers;
|
||||
import com.accompany.business.model.StatBasicUsersExample;
|
||||
import com.accompany.business.model.StatUserStandTime;
|
||||
import com.accompany.business.mybatismapper.StatBasicUsersMapper;
|
||||
import com.accompany.business.service.statis.StatBasicRoomService;
|
||||
import com.accompany.business.service.statis.StatBasicUsersService;
|
||||
import com.accompany.business.service.statis.StatUserStandTimeService;
|
||||
import com.accompany.common.utils.GetTimeUtils;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class StatUserStandTimeJob implements Job {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(StatUserStandTimeJob.class);
|
||||
@Autowired
|
||||
private StatBasicUsersService statBasicUsersService;
|
||||
@Autowired
|
||||
private StatBasicUsersMapper statBasicUsersMapper;
|
||||
@Autowired
|
||||
private StatBasicRoomService statBasicRoomService;
|
||||
@Autowired
|
||||
private StatUserStandTimeService statUserStandTimeService;
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
logger.info("执行定时任务:写入用户每个房间停留时间.");
|
||||
Date date = new Date(System.currentTimeMillis() - 87400000);
|
||||
StatBasicUsersExample example = new StatBasicUsersExample();
|
||||
Map<Long, Map<Long, Integer>> map = new HashMap<>();
|
||||
example.createCriteria().andCreateTimeBetween(GetTimeUtils.getTimesnights(date, 0), GetTimeUtils.getTimesnight(0));
|
||||
List<StatBasicUsers> statBasicUsersList = statBasicUsersMapper.selectByExample(example);
|
||||
for (StatBasicUsers statBasicUsers : statBasicUsersList) {
|
||||
if (map.size() == 0) {
|
||||
Map<Long, Integer> map2 = new HashMap<>();
|
||||
map2.put(statBasicUsers.getRoomUid(), 1);
|
||||
map.put(statBasicUsers.getUid(), map2);
|
||||
} else {
|
||||
boolean flag = true;
|
||||
lop:for (Map.Entry<Long, Map<Long, Integer>> mapEntry : map.entrySet()) {
|
||||
if (mapEntry.getKey().equals(statBasicUsers.getUid())) {
|
||||
Map<Long, Integer> value = mapEntry.getValue();
|
||||
for (Map.Entry<Long, Integer> map2Entry : value.entrySet()) {
|
||||
if (map2Entry.getKey().equals(statBasicUsers.getRoomUid())) {
|
||||
//同一个人同一个房间
|
||||
value.put(map2Entry.getKey(), map2Entry.getValue() + 1);
|
||||
map.put(statBasicUsers.getUid(), value);
|
||||
flag = false;
|
||||
break lop;
|
||||
} else {
|
||||
//同一个人不同房间
|
||||
value.put(statBasicUsers.getRoomUid(), 1);
|
||||
map.put(statBasicUsers.getUid(), value);
|
||||
flag = false;
|
||||
break lop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
Map<Long, Integer> map2 = new HashMap<>();
|
||||
map2.put(statBasicUsers.getRoomUid(), 1);
|
||||
map.put(statBasicUsers.getUid(), map2);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Map.Entry<Long, Map<Long, Integer>> mapEntry : map.entrySet()) {
|
||||
StatUserStandTime statUserStandTime = new StatUserStandTime();
|
||||
statUserStandTime.setUid(mapEntry.getKey());
|
||||
for (Map.Entry<Long, Integer> map2Entry : mapEntry.getValue().entrySet()) {
|
||||
statUserStandTime.setRoomUid(map2Entry.getKey());
|
||||
statUserStandTime.setStandTime((long) map2Entry.getValue());
|
||||
statUserStandTime.setCreateTime(new Date());
|
||||
statUserStandTimeService.insertStatStandTime(statUserStandTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
package com.accompany.scheduler.job;
|
||||
|
||||
import com.accompany.business.model.StatBasicRoom;
|
||||
import com.accompany.business.model.StatSumRoom;
|
||||
import com.accompany.business.mybatismapper.StatSumRoomMapper;
|
||||
import com.accompany.business.service.statis.StatBasicRoomService;
|
||||
import com.accompany.business.service.statis.StatBasicUsersService;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class StaticRoomDataJob implements Job {
|
||||
private static final Logger logger = LoggerFactory.getLogger(StaticRoomDataJob.class);
|
||||
|
||||
@Autowired
|
||||
private StatBasicRoomService statBasicRoomService;
|
||||
@Autowired
|
||||
private StatBasicUsersService statBasicUsersService;
|
||||
@Autowired
|
||||
private StatSumRoomMapper statSumRoomMapper;
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
logger.info("定时任务:将每天的人气数据统计到房间数据中.");
|
||||
List<StatBasicRoom> basicRoomList = statBasicUsersService.queryBasicUsers();
|
||||
basicRoomList = statBasicRoomService.updateRooms(basicRoomList);
|
||||
for (StatBasicRoom statBasicRoom : basicRoomList) {
|
||||
logger.info("当前房间一天的详细统计数据,roomUid" + statBasicRoom.getRoomUid() + ",Moods:" + statBasicRoom.getMoods() +
|
||||
",IntoPeoples:" + statBasicRoom.getRoomIntoPeoples() + ",sumLive:" + statBasicRoom.getSumLiveTime());
|
||||
StatSumRoom statSumRoom = statSumRoomMapper.selectByPrimaryKey(statBasicRoom.getRoomUid());
|
||||
if (statSumRoom == null) {
|
||||
statSumRoom = new StatSumRoom();
|
||||
statSumRoom.setMoods(statBasicRoom.getMoods());
|
||||
statSumRoom.setRoomIntoPeoples(statBasicRoom.getRoomIntoPeoples());
|
||||
statSumRoom.setRoomUid(statBasicRoom.getRoomUid());
|
||||
statSumRoom.setSumLiveTime(statBasicRoom.getSumLiveTime());
|
||||
statSumRoomMapper.insertSelective(statSumRoom);
|
||||
} else {
|
||||
Long intoPeoples = statSumRoom.getRoomIntoPeoples();
|
||||
if (intoPeoples == null) {
|
||||
statSumRoom.setRoomIntoPeoples(statBasicRoom.getRoomIntoPeoples());
|
||||
} else {
|
||||
Long intoPeople = statBasicRoom.getRoomIntoPeoples();
|
||||
if (intoPeople != null) {
|
||||
statSumRoom.setRoomIntoPeoples(intoPeople + statSumRoom.getRoomIntoPeoples());
|
||||
}
|
||||
}
|
||||
Long moods = statSumRoom.getMoods();
|
||||
if (moods == null) {
|
||||
statSumRoom.setMoods(statBasicRoom.getMoods());
|
||||
} else {
|
||||
Long mood = statBasicRoom.getMoods();
|
||||
if (mood != null) {
|
||||
statSumRoom.setMoods(mood + statSumRoom.getMoods());
|
||||
}
|
||||
}
|
||||
statSumRoom.setSumLiveTime(statBasicRoom.getSumLiveTime() + statSumRoom.getSumLiveTime());
|
||||
statSumRoomMapper.updateByPrimaryKey(statSumRoom);
|
||||
}
|
||||
logger.info("统计房间数据总和成功。");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package com.accompany.scheduler.mapper;
|
||||
|
||||
import com.accompany.scheduler.model.QuartzJob;
|
||||
import com.accompany.scheduler.model.QuartzJobExample;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface QuartzJobMapper {
|
||||
int countByExample(QuartzJobExample example);
|
||||
|
||||
int deleteByExample(QuartzJobExample example);
|
||||
|
||||
int deleteByPrimaryKey(Long id);
|
||||
|
||||
int insert(QuartzJob record);
|
||||
|
||||
int insertSelective(QuartzJob record);
|
||||
|
||||
List<QuartzJob> selectByExample(QuartzJobExample example);
|
||||
|
||||
QuartzJob selectByPrimaryKey(Long id);
|
||||
|
||||
int updateByExampleSelective(@Param("record") QuartzJob record, @Param("example") QuartzJobExample example);
|
||||
|
||||
int updateByExample(@Param("record") QuartzJob record, @Param("example") QuartzJobExample example);
|
||||
|
||||
int updateByPrimaryKeySelective(QuartzJob record);
|
||||
|
||||
int updateByPrimaryKey(QuartzJob record);
|
||||
|
||||
QuartzJob getPeriodic(String name);
|
||||
|
||||
QuartzJob getOneTime(String name);
|
||||
|
||||
String getJobNameById(Long id);
|
||||
|
||||
int deleteByName(String name);
|
||||
|
||||
QuartzJob getByName(String name);
|
||||
|
||||
int countPeriodic();
|
||||
|
||||
int countOneTime();
|
||||
|
||||
List<QuartzJob> selectPeriodicByPage(@Param("start") int start, @Param("count") int count);
|
||||
|
||||
List<QuartzJob> selectOneTimeByPage(@Param("start") int start, @Param("count") int count);
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
package com.accompany.scheduler.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class QuartzJob implements Serializable {
|
||||
private Long id;
|
||||
|
||||
private String expression;
|
||||
|
||||
private String description;
|
||||
|
||||
private String jobName;
|
||||
|
||||
private String jobClassName;
|
||||
|
||||
private Integer jobType;
|
||||
|
||||
private String jobData;
|
||||
|
||||
private Boolean isOneTime;
|
||||
|
||||
private Date nextFireTime;
|
||||
|
||||
private Date prevFireTime;
|
||||
|
||||
private String triggerState;
|
||||
|
||||
private String triggerType;
|
||||
|
||||
private Date startTime;
|
||||
|
||||
private Date endTime;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private Date updateTime;
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,73 @@
|
||||
package com.accompany.scheduler.repository;
|
||||
|
||||
import com.accompany.scheduler.mapper.QuartzJobMapper;
|
||||
import com.accompany.scheduler.model.QuartzJob;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by PaperCut on 2018/6/11.
|
||||
*/
|
||||
@Component
|
||||
public class JdbcQuartzJobRepository implements QuartzJobRepository {
|
||||
@Autowired
|
||||
QuartzJobMapper quartzJobMapper;
|
||||
|
||||
@Override
|
||||
public void add(QuartzJob job) {
|
||||
quartzJobMapper.insert(job);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(QuartzJob job) {
|
||||
quartzJobMapper.updateByPrimaryKey(job);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(QuartzJob job) {
|
||||
quartzJobMapper.deleteByPrimaryKey(job.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuartzJob get(Long id) {
|
||||
return quartzJobMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuartzJob getByName(String name) {
|
||||
return quartzJobMapper.getByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuartzJob getPeriod(String name) {
|
||||
return quartzJobMapper.getPeriodic(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuartzJob getOneTime(String name) {
|
||||
return quartzJobMapper.getOneTime(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuartzJob> findPeriodByPage(Integer page, Integer pageSize) {
|
||||
return quartzJobMapper.selectPeriodicByPage((page - 1) * pageSize, pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer countPeriod() {
|
||||
return quartzJobMapper.countPeriodic();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuartzJob> findOneTimeByPage(Integer page, Integer pageSize) {
|
||||
return quartzJobMapper.selectOneTimeByPage((page - 1) * pageSize, pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer countOneTime() {
|
||||
return quartzJobMapper.countOneTime();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.accompany.scheduler.repository;
|
||||
|
||||
import com.accompany.scheduler.model.QuartzJob;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface QuartzJobRepository {
|
||||
void add(QuartzJob job);
|
||||
|
||||
void update(QuartzJob job);
|
||||
|
||||
void delete(QuartzJob job);
|
||||
|
||||
QuartzJob get(Long id);
|
||||
|
||||
QuartzJob getByName(String name);
|
||||
|
||||
QuartzJob getPeriod(String name);
|
||||
|
||||
QuartzJob getOneTime(String name);
|
||||
|
||||
List<QuartzJob> findPeriodByPage(Integer page, Integer pageSize);
|
||||
|
||||
Integer countPeriod();
|
||||
|
||||
List<QuartzJob> findOneTimeByPage(Integer page, Integer pageSize);
|
||||
|
||||
Integer countOneTime();
|
||||
}
|
@@ -0,0 +1,134 @@
|
||||
package com.accompany.scheduler.service;
|
||||
|
||||
import com.accompany.scheduler.constant.QuartzJobType;
|
||||
import com.accompany.scheduler.exception.JobException;
|
||||
import com.accompany.scheduler.model.QuartzJob;
|
||||
import com.accompany.scheduler.repository.QuartzJobRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author PaperCut
|
||||
* Created by PaperCut on 2018/12/14.
|
||||
* 抽象任务处理类
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class AbstractQuartzJobService implements QuartzJobService {
|
||||
protected QuartzJobRepository quartzJobRepository;
|
||||
protected Scheduler quartzScheduler;
|
||||
|
||||
@Autowired
|
||||
public AbstractQuartzJobService(QuartzJobRepository quartzJobRepository, Scheduler quartzScheduler) {
|
||||
this.quartzJobRepository = quartzJobRepository;
|
||||
this.quartzScheduler = quartzScheduler;
|
||||
|
||||
// 执行初始化
|
||||
init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
try {
|
||||
quartzScheduler.getListenerManager().addTriggerListener(new SimpleTriggerListener());
|
||||
} catch (SchedulerException e) {
|
||||
log.error("Failed to initialize QuartJobService.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuartzJob add(QuartzJob job) throws Exception {
|
||||
boolean isExists = exists(job.getJobName());
|
||||
if (isExists) {
|
||||
throw new JobException("该任务名已存在");
|
||||
}
|
||||
job.setCreateTime(new Date());
|
||||
quartzJobRepository.add(job);
|
||||
schedule(job);
|
||||
|
||||
return job;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuartzJob update(QuartzJob job) throws Exception {
|
||||
Trigger.TriggerState state = quartzScheduler.getTriggerState(getTriggerKey(job.getJobName()));
|
||||
quartzScheduler.deleteJob(getJobKey(job.getJobName()));
|
||||
|
||||
schedule(job);
|
||||
if (state == Trigger.TriggerState.PAUSED) {
|
||||
quartzScheduler.pauseJob(getJobKey(job.getJobName()));
|
||||
}
|
||||
job.setUpdateTime(new Date());
|
||||
quartzJobRepository.update(job);
|
||||
|
||||
return job;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) throws Exception {
|
||||
QuartzJob job = quartzJobRepository.get(id);
|
||||
if (job == null) {
|
||||
throw new JobException("未找到该任务");
|
||||
}
|
||||
quartzJobRepository.delete(job);
|
||||
quartzScheduler.deleteJob(getJobKey(job.getJobName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByName(String name) throws Exception {
|
||||
QuartzJob job = quartzJobRepository.getByName(name);
|
||||
if (job == null) {
|
||||
throw new JobException("未找到该任务");
|
||||
}
|
||||
quartzJobRepository.delete(job);
|
||||
quartzScheduler.deleteJob(getJobKey(job.getJobName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(String name) throws Exception {
|
||||
return quartzScheduler.checkExists(getJobKey(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume(String name) throws JobException, SchedulerException {
|
||||
JobDetail jobDetail = quartzScheduler.getJobDetail(getJobKey(name));
|
||||
TriggerKey triggerKey = getTriggerKey(name);
|
||||
Trigger trigger = quartzScheduler.getTrigger(triggerKey);
|
||||
if (trigger != null) {
|
||||
QuartzJob jobEntity = quartzJobRepository.getPeriod(name);
|
||||
CronTrigger newTrigger = TriggerBuilder.newTrigger()
|
||||
.withIdentity(getTriggerKey(name))
|
||||
.forJob(jobDetail)
|
||||
.withSchedule(CronScheduleBuilder.cronSchedule(jobEntity.getExpression()))
|
||||
.build();
|
||||
quartzScheduler.rescheduleJob(triggerKey, newTrigger);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause(String name) throws Exception {
|
||||
quartzScheduler.pauseJob(getJobKey(name));
|
||||
}
|
||||
|
||||
protected JobFactory getFactory(QuartzJob job) {
|
||||
Integer jobType = job.getJobType();
|
||||
if (jobType == QuartzJobType.SqlJob.value) {
|
||||
return new SqlJobFactory();
|
||||
} else if (jobType == QuartzJobType.JavaJobClass.value) {
|
||||
return new JavaJobFactory();
|
||||
} else if (jobType == QuartzJobType.HttpGetJob.value) {
|
||||
return new HttpGetJobFactory();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not found this job type for job factory.");
|
||||
}
|
||||
}
|
||||
|
||||
abstract void schedule(QuartzJob job) throws Exception;
|
||||
|
||||
abstract String getGroup();
|
||||
|
||||
abstract JobKey getJobKey(String name);
|
||||
|
||||
abstract TriggerKey getTriggerKey(String name);
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package com.accompany.scheduler.service;
|
||||
|
||||
import com.accompany.scheduler.job.HttpGetJobDetail;
|
||||
import com.accompany.scheduler.model.QuartzJob;
|
||||
import org.quartz.JobBuilder;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobDetail;
|
||||
|
||||
/**
|
||||
* Created by PaperCut on 2018/6/11.
|
||||
* http请求类型任务
|
||||
*/
|
||||
public class HttpGetJobFactory implements JobFactory {
|
||||
@Override
|
||||
public JobDetail create(QuartzJob job) throws ClassNotFoundException {
|
||||
JobDataMap jobDataMap = new JobDataMap();
|
||||
jobDataMap.put("jobBean", job);
|
||||
JobDetail jobDetail = JobBuilder.newJob(HttpGetJobDetail.class)
|
||||
.withIdentity(job.getJobName())
|
||||
.withDescription(job.getDescription())
|
||||
.usingJobData(jobDataMap)
|
||||
.build();
|
||||
return jobDetail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobDetail create(String group, QuartzJob job) {
|
||||
JobDataMap jobDataMap = new JobDataMap();
|
||||
jobDataMap.put("jobBean", job);
|
||||
JobDetail jobDetail = JobBuilder.newJob(HttpGetJobDetail.class)
|
||||
.withIdentity(job.getJobName(), group)
|
||||
.withDescription(job.getDescription())
|
||||
.usingJobData(jobDataMap)
|
||||
.build();
|
||||
return jobDetail;
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
package com.accompany.scheduler.service;
|
||||
|
||||
import com.accompany.scheduler.model.QuartzJob;
|
||||
import org.quartz.JobBuilder;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobDetail;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Created by PaperCut on 2018/6/11.
|
||||
* Java类型任务
|
||||
*/
|
||||
public class JavaJobFactory implements JobFactory {
|
||||
private final Map<String, Class> clazzCache = new ConcurrentHashMap<>();
|
||||
|
||||
private Class findClass(String className) throws ClassNotFoundException {
|
||||
Class instance = null;
|
||||
if ((instance = clazzCache.get(className)) == null) {
|
||||
Class clazz = Class.forName(className);
|
||||
clazzCache.put(className, clazz);
|
||||
instance = clazzCache.get(className);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobDetail create(QuartzJob job) throws ClassNotFoundException {
|
||||
JobDataMap jobDataMap = new JobDataMap();
|
||||
jobDataMap.put("jobBean", job);
|
||||
JobDetail jobDetail = JobBuilder.newJob(findClass(job.getJobClassName()))
|
||||
.withIdentity(job.getJobName())
|
||||
.withDescription(job.getDescription())
|
||||
.usingJobData(jobDataMap)
|
||||
.build();
|
||||
return jobDetail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobDetail create(String group, QuartzJob job) throws ClassNotFoundException {
|
||||
JobDataMap jobDataMap = new JobDataMap();
|
||||
jobDataMap.put("jobBean", job);
|
||||
JobDetail jobDetail = JobBuilder.newJob(findClass(job.getJobClassName()))
|
||||
.withIdentity(job.getJobName(), group)
|
||||
.withDescription(job.getDescription())
|
||||
.usingJobData(jobDataMap)
|
||||
.build();
|
||||
return jobDetail;
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package com.accompany.scheduler.service;
|
||||
|
||||
import com.accompany.scheduler.model.QuartzJob;
|
||||
import org.quartz.JobDetail;
|
||||
|
||||
/**
|
||||
* Created by PaperCut on 2018/12/14.
|
||||
* Job工厂接口
|
||||
*/
|
||||
public interface JobFactory {
|
||||
JobDetail create(QuartzJob job) throws ClassNotFoundException;
|
||||
|
||||
JobDetail create(String group, QuartzJob job) throws ClassNotFoundException;
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
package com.accompany.scheduler.service;
|
||||
|
||||
import com.accompany.scheduler.model.QuartzJob;
|
||||
import com.accompany.scheduler.repository.QuartzJobRepository;
|
||||
import org.quartz.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author PaperaCut
|
||||
* Created by PaperCut on 2018/12/14.
|
||||
* 持久任务服务类
|
||||
*/
|
||||
@Service
|
||||
public class PeriodQuartzJobService extends AbstractQuartzJobService {
|
||||
@Autowired
|
||||
public PeriodQuartzJobService(QuartzJobRepository quartzJobRepository, Scheduler quartzScheduler) {
|
||||
super(quartzJobRepository, quartzScheduler);
|
||||
}
|
||||
|
||||
@Override
|
||||
String getGroup() {
|
||||
return "CRON";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobKey getJobKey(String name) {
|
||||
return new JobKey(name, getGroup());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TriggerKey getTriggerKey(String name) {
|
||||
return new TriggerKey(name + "_trigger", getGroup());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void schedule(QuartzJob job) throws Exception {
|
||||
JobDetail jobDetail = getFactory(job).create(getGroup(), job);
|
||||
CronTrigger trigger = TriggerBuilder.newTrigger()
|
||||
.withIdentity(getTriggerKey(job.getJobName()))
|
||||
.withSchedule(CronScheduleBuilder.cronSchedule(job.getExpression()))
|
||||
.build();
|
||||
quartzScheduler.scheduleJob(jobDetail, trigger);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取周期性任务
|
||||
*
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
public List<QuartzJob> findPeriodByPage(Integer page, Integer pageSize) {
|
||||
return quartzJobRepository.findPeriodByPage(page, pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计获取周期性任务数量
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Integer countPeriod() {
|
||||
return quartzJobRepository.countPeriod();
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package com.accompany.scheduler.service;
|
||||
|
||||
import com.accompany.scheduler.model.QuartzJob;
|
||||
import org.quartz.SchedulerException;
|
||||
|
||||
/**
|
||||
* Created by PaperCut on 2018/12/14.
|
||||
* 任务管理接口
|
||||
*/
|
||||
public interface QuartzJobService {
|
||||
QuartzJob add(QuartzJob job) throws Exception;
|
||||
|
||||
QuartzJob update(QuartzJob job) throws Exception;
|
||||
|
||||
void delete(Long id) throws Exception;
|
||||
|
||||
void deleteByName(String name) throws Exception;
|
||||
|
||||
boolean exists(String name) throws Exception;
|
||||
|
||||
void resume(String name) throws SchedulerException;
|
||||
|
||||
void pause(String name) throws Exception;
|
||||
}
|
@@ -0,0 +1,163 @@
|
||||
package com.accompany.scheduler.service;
|
||||
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.scheduler.constant.QuartzJobType;
|
||||
import com.accompany.scheduler.job.SqlJobDetail;
|
||||
import com.accompany.scheduler.mapper.QuartzJobMapper;
|
||||
import com.accompany.scheduler.model.QuartzJob;
|
||||
import org.apache.commons.lang3.time.FastDateFormat;
|
||||
import org.quartz.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
public class QuartzPeriodJobService {
|
||||
private static final String GROUP_CRON = "CRON";
|
||||
private static final String GROUP_ONE_TIME = "ONE_TIME";
|
||||
|
||||
@Autowired
|
||||
Scheduler quartzScheduler;
|
||||
|
||||
@Autowired
|
||||
QuartzJobMapper quartzJobMapper;
|
||||
|
||||
public void add(QuartzJob job) throws SchedulerException, ClassNotFoundException {
|
||||
boolean isExists = exists(job.getJobName());
|
||||
if (isExists) {
|
||||
throw new SchedulerException("该任务名已存在");
|
||||
}
|
||||
Date curDate = new Date();
|
||||
job.setCreateTime(curDate);
|
||||
job.setUpdateTime(curDate);
|
||||
schedulePeriodic(job);
|
||||
}
|
||||
|
||||
public void addOneTime(QuartzJob job) throws SchedulerException, ParseException, ClassNotFoundException {
|
||||
boolean isExists = exists(job.getJobName());
|
||||
if (isExists) {
|
||||
throw new SchedulerException("该任务名已存在");
|
||||
}
|
||||
job.setIsOneTime(true);
|
||||
job.setCreateTime(new Date());
|
||||
quartzJobMapper.insert(job);
|
||||
|
||||
scheduleOneTime(job);
|
||||
}
|
||||
|
||||
private void scheduleOneTime(QuartzJob job) throws ClassNotFoundException, ParseException, SchedulerException {
|
||||
JobDetail jobDetail = null;
|
||||
JobDataMap dataMap = new JobDataMap();
|
||||
dataMap.put("jobBean", job);
|
||||
|
||||
if (job.getJobType() == QuartzJobType.JavaJobClass.value) {
|
||||
jobDetail = JobBuilder.newJob((Class<Job>) Class.forName(job.getJobClassName()))
|
||||
.withIdentity(job.getJobName(), GROUP_CRON)
|
||||
.withDescription(job.getDescription()).usingJobData(dataMap)
|
||||
.build();
|
||||
} else if (job.getJobType() == QuartzJobType.SqlJob.value) {
|
||||
jobDetail = JobBuilder.newJob(SqlJobDetail.class)
|
||||
.withIdentity(job.getJobName(), GROUP_ONE_TIME)
|
||||
.withDescription(job.getDescription()).usingJobData(dataMap)
|
||||
.build();
|
||||
}
|
||||
Date date = FastDateFormat.getInstance(DateTimeUtil.DEFAULT_DATE_PATTERN).parse(job.getExpression());
|
||||
SimpleTrigger trigger = (SimpleTrigger) TriggerBuilder.newTrigger()
|
||||
.withIdentity(job.getJobName() + "_trigger", GROUP_ONE_TIME)
|
||||
.startAt(date) // some Date
|
||||
.forJob(jobDetail)
|
||||
.build();
|
||||
|
||||
quartzScheduler.scheduleJob(jobDetail, trigger);
|
||||
}
|
||||
|
||||
private void schedulePeriodic(QuartzJob job) throws ClassNotFoundException, SchedulerException {
|
||||
JobDetail jobDetail = null;
|
||||
JobDataMap dataMap = new JobDataMap();
|
||||
dataMap.put("jobBean", job);
|
||||
if (job.getJobType() == QuartzJobType.JavaJobClass.value) {
|
||||
jobDetail = JobBuilder.newJob((Class<Job>) Class.forName(job.getJobClassName()))
|
||||
.withIdentity(job.getJobName(), GROUP_CRON)
|
||||
.withDescription(job.getDescription()).usingJobData(dataMap)
|
||||
.build();
|
||||
} else if (job.getJobType() == QuartzJobType.SqlJob.value) {
|
||||
jobDetail = JobBuilder.newJob(SqlJobDetail.class)
|
||||
.withIdentity(job.getJobName(), GROUP_CRON)
|
||||
.withDescription(job.getDescription()).usingJobData(dataMap)
|
||||
.build();
|
||||
}
|
||||
CronTrigger trigger = TriggerBuilder.newTrigger()
|
||||
.withIdentity(job.getJobName() + "_trigger", GROUP_CRON)
|
||||
.forJob(jobDetail)
|
||||
.withSchedule(CronScheduleBuilder.cronSchedule(job.getExpression()))
|
||||
.build();
|
||||
|
||||
quartzScheduler.scheduleJob(jobDetail, trigger);
|
||||
}
|
||||
|
||||
public void resume(String name) throws SchedulerException {
|
||||
TriggerKey triggerKey = new TriggerKey(name + "_trigger", GROUP_CRON);
|
||||
JobDetail jobDetail = quartzScheduler.getJobDetail(new JobKey(name, GROUP_CRON));
|
||||
Trigger oldTrigger = quartzScheduler.getTrigger(triggerKey);
|
||||
if (oldTrigger != null) {
|
||||
QuartzJob job = quartzJobMapper.getPeriodic(name);
|
||||
CronTrigger newTrigger = TriggerBuilder.newTrigger()
|
||||
.withIdentity(triggerKey)
|
||||
.forJob(jobDetail)
|
||||
.withSchedule(CronScheduleBuilder.cronSchedule(job.getExpression()))
|
||||
.build();
|
||||
quartzScheduler.rescheduleJob(triggerKey, newTrigger);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(QuartzJob job) throws SchedulerException, ClassNotFoundException {
|
||||
Trigger.TriggerState state = quartzScheduler.getTriggerState(new TriggerKey(job.getJobName() + "_trigger", GROUP_CRON));
|
||||
quartzScheduler.deleteJob(new JobKey(job.getJobName(), GROUP_CRON));
|
||||
|
||||
schedulePeriodic(job);
|
||||
if (state == Trigger.TriggerState.PAUSED) {
|
||||
quartzScheduler.pauseJob(new JobKey(job.getJobName(), GROUP_CRON));
|
||||
}
|
||||
job.setUpdateTime(new Date());
|
||||
|
||||
quartzJobMapper.updateByPrimaryKey(job);
|
||||
}
|
||||
|
||||
public void pause(String name) throws SchedulerException {
|
||||
quartzScheduler.pauseJob(new JobKey(name, GROUP_CRON));
|
||||
}
|
||||
|
||||
public void runOnce(String name, boolean periodic) throws SchedulerException {
|
||||
quartzScheduler.triggerJob(new JobKey(name, periodic ? GROUP_CRON : GROUP_ONE_TIME));
|
||||
}
|
||||
|
||||
public boolean exists(String name) throws SchedulerException {
|
||||
return quartzScheduler.checkExists(new JobKey(name, GROUP_CRON));
|
||||
}
|
||||
|
||||
public void delete(Long id) throws SchedulerException {
|
||||
String jobName = quartzJobMapper.getJobNameById(id);
|
||||
quartzScheduler.deleteJob(new JobKey(jobName, GROUP_CRON));
|
||||
quartzJobMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public void deleteByOneTime(Long id) throws SchedulerException {
|
||||
String jobName = quartzJobMapper.getJobNameById(id);
|
||||
quartzScheduler.deleteJob(new JobKey(jobName, GROUP_ONE_TIME));
|
||||
quartzJobMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
|
||||
public void deleteByName(String name) throws SchedulerException {
|
||||
quartzScheduler.deleteJob(new JobKey(name, GROUP_CRON));
|
||||
quartzJobMapper.deleteByName(name);
|
||||
}
|
||||
|
||||
public void deleteByNameForOneTime(String name) throws SchedulerException {
|
||||
quartzScheduler.deleteJob(new JobKey(name, GROUP_ONE_TIME));
|
||||
quartzJobMapper.deleteByName(name);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,73 @@
|
||||
package com.accompany.scheduler.service;
|
||||
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.scheduler.model.QuartzJob;
|
||||
import com.accompany.scheduler.repository.QuartzJobRepository;
|
||||
import org.apache.commons.lang3.time.FastDateFormat;
|
||||
import org.quartz.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author PaperCut
|
||||
* @since 2020-03-20
|
||||
* 简单定时任务
|
||||
*/
|
||||
@Service
|
||||
public class SimpleQuartzJobService extends AbstractQuartzJobService {
|
||||
|
||||
@Autowired
|
||||
public SimpleQuartzJobService(QuartzJobRepository quartzJobRepository, Scheduler quartzScheduler) {
|
||||
super(quartzJobRepository, quartzScheduler);
|
||||
}
|
||||
|
||||
@Override
|
||||
String getGroup() {
|
||||
return "ONE_TIME";
|
||||
}
|
||||
|
||||
@Override
|
||||
JobKey getJobKey(String name) {
|
||||
return new JobKey(name, getGroup());
|
||||
}
|
||||
|
||||
@Override
|
||||
TriggerKey getTriggerKey(String name) {
|
||||
return new TriggerKey(name + "_trigger", getGroup());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void schedule(QuartzJob job) throws Exception {
|
||||
Date date = FastDateFormat.getInstance(DateTimeUtil.DEFAULT_DATE_PATTERN).parse(job.getExpression());
|
||||
JobDetail jobDetail = getFactory(job).create(getGroup(), job);
|
||||
SimpleTrigger trigger = (SimpleTrigger) TriggerBuilder.newTrigger()
|
||||
.withIdentity(getTriggerKey(job.getJobName()))
|
||||
.startAt(date)
|
||||
.forJob(jobDetail)
|
||||
.build();
|
||||
quartzScheduler.scheduleJob(jobDetail, trigger);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取一次性任务
|
||||
*
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
public List<QuartzJob> findOneTimeByPage(Integer page, Integer pageSize) {
|
||||
return quartzJobRepository.findOneTimeByPage(page, pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计一次性任务数量
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Integer countOneTime() {
|
||||
return quartzJobRepository.countOneTime();
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package com.accompany.scheduler.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.Trigger;
|
||||
import org.quartz.listeners.TriggerListenerSupport;
|
||||
|
||||
/**
|
||||
* Created by PaperCut on 2018/6/12.
|
||||
* 一次性任务触发器
|
||||
*/
|
||||
@Slf4j
|
||||
public class SimpleTriggerListener extends TriggerListenerSupport {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "SimpleTriggerListener";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void triggerComplete(Trigger trigger, JobExecutionContext context, Trigger.CompletedExecutionInstruction triggerInstructionCode) {
|
||||
log.info("Completed trigger...");
|
||||
super.triggerComplete(trigger, context, triggerInstructionCode);
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package com.accompany.scheduler.service;
|
||||
|
||||
import com.accompany.scheduler.job.SqlJobDetail;
|
||||
import com.accompany.scheduler.model.QuartzJob;
|
||||
import org.quartz.JobBuilder;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobDetail;
|
||||
|
||||
/**
|
||||
* Created by PaperCut on 2018/12/14.
|
||||
* Sql类型任务
|
||||
*/
|
||||
public class SqlJobFactory implements JobFactory {
|
||||
@Override
|
||||
public JobDetail create(QuartzJob job) {
|
||||
JobDataMap dataMap = new JobDataMap();
|
||||
dataMap.put("jobBean", job);
|
||||
JobDetail jobDetail = JobBuilder.newJob(SqlJobDetail.class)
|
||||
.withIdentity(job.getJobName())
|
||||
.withDescription(job.getDescription())
|
||||
.usingJobData(dataMap)
|
||||
.build();
|
||||
return jobDetail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobDetail create(String group, QuartzJob job) {
|
||||
JobDataMap dataMap = new JobDataMap();
|
||||
dataMap.put("jobBean", job);
|
||||
JobDetail jobDetail = JobBuilder.newJob(SqlJobDetail.class)
|
||||
.withIdentity(job.getJobName(), group)
|
||||
.withDescription(job.getDescription())
|
||||
.usingJobData(dataMap)
|
||||
.build();
|
||||
return jobDetail;
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.account.AccountBlockService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 定时更新封禁时间到期的用户-将封禁状态改为封禁结束
|
||||
* Created by liuyang on 2019/6/17.
|
||||
*/
|
||||
@Component
|
||||
public class AccountBlockTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AccountBlockTask.class);
|
||||
|
||||
@Autowired
|
||||
private AccountBlockService accountBlockService;
|
||||
|
||||
/**
|
||||
* 每十分钟执行一次
|
||||
*/
|
||||
@Scheduled(cron = "0 */10 * * * ?")
|
||||
public void updateBlockStatus() throws Exception{
|
||||
logger.info("updateBlockStatus start ===============");
|
||||
accountBlockService.deleteAccountBlock();
|
||||
logger.info("updateBlockStatus finish ===============");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,113 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.activity.ActRedPacketRemindService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
/**
|
||||
* Created by yanpengcheng on 2019/1/8
|
||||
* 暂时关掉,要指定2月才运行
|
||||
*/
|
||||
//@Component
|
||||
public class ActRedPacketRemindTask extends BaseTask implements ApplicationContextAware {
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Autowired
|
||||
ActRedPacketRemindService actRedPacketRemindService;
|
||||
|
||||
//正式环境
|
||||
static final String BASE_CRON_1 = " 3,4 2 ?";
|
||||
static final String BASE_CRON_2 = " 5 2 ?";
|
||||
static final String BASE_CRON_3 = " 5-7 2 ?";
|
||||
static final String BASE_CRON_4 = " 7 2 ?";
|
||||
|
||||
|
||||
static final String CRON_TO_BEGIN = "0 0 12,19" + BASE_CRON_1;//2月,3-4号预热期间,每天12、19点,0分发送小秘书
|
||||
static final String CRON_SESSION_1 = "0 21 0" + BASE_CRON_2;//2月5号,0点的21分发送小秘书(除夕场结束)
|
||||
static final String CRON_SESSION_2 = "0 9 18" + BASE_CRON_3;//2月5-7号,18点的9分发送小秘书(白天场结束)
|
||||
static final String CRON_SESSION_3 = "0 39 23" + BASE_CRON_3;//2月5-7号,23点的39分发送小秘书(晚上场结束)
|
||||
static final String CRON_TIEMS_1 = "0 1,5,9 9-18" + BASE_CRON_3;//2月5-7号,9-23点的1、5、9分发送小秘书(每次红包雨结束提醒)
|
||||
static final String CRON_TIEMS_2 = "0 1,5,9,31,35,39 19-23" + BASE_CRON_3;//2月5-7号,9-23点的31、35、39分发送小秘书(每次红包雨结束提醒)
|
||||
static final String CRON_END = "0 39 23" + BASE_CRON_4;//全部红包雨活动结束提醒
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
}
|
||||
|
||||
/**
|
||||
* 预热提醒
|
||||
*/
|
||||
@Scheduled(cron = CRON_TO_BEGIN)
|
||||
public void yearRedPacketBeginRemind() {
|
||||
logger.info("yearRedPacketRemind() start ========");
|
||||
actRedPacketRemindService.beginRemind(null);
|
||||
logger.info("yearRedPacketRemind() finish ========");
|
||||
}
|
||||
|
||||
/**
|
||||
* 每一场结束后(除夕场)
|
||||
*/
|
||||
@Scheduled(cron = CRON_SESSION_1)
|
||||
public void yearRedPacketSessionRemind1() {
|
||||
logger.info("yearRedPacketSessionRemind1() start ========");
|
||||
actRedPacketRemindService.sessionRemind(null);
|
||||
logger.info("yearRedPacketSessionRemind1() finish ========");
|
||||
}
|
||||
|
||||
/**
|
||||
* 每一场结束后(白天场)
|
||||
*/
|
||||
@Scheduled(cron = CRON_SESSION_2)
|
||||
public void yearRedPacketSessionRemind2() {
|
||||
logger.info("yearRedPacketSessionRemind2() start ========");
|
||||
actRedPacketRemindService.sessionRemind(null);
|
||||
logger.info("yearRedPacketSessionRemind2() finish ========");
|
||||
}
|
||||
|
||||
/**
|
||||
* 每一场结束后(晚上场)
|
||||
*/
|
||||
@Scheduled(cron = CRON_SESSION_3)
|
||||
public void yearRedPacketSessionRemind3() {
|
||||
logger.info("yearRedPacketSessionRemind3() start ========");
|
||||
actRedPacketRemindService.sessionRemind(null);
|
||||
logger.info("yearRedPacketSessionRemind3() finish ========");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 每一次结束(白天场)
|
||||
*/
|
||||
@Scheduled(cron = CRON_TIEMS_1)
|
||||
public void yearRedPacketTimesRemind() {
|
||||
logger.info("yearRedPacketRoundRemind() start ========");
|
||||
actRedPacketRemindService.sendBatchMsg(null, actRedPacketRemindService.REMIND_TIMES_BEGIN_FORMAT);
|
||||
logger.info("yearRedPacketRoundRemind() finish ========");
|
||||
}
|
||||
|
||||
/**
|
||||
* 每一次结束(晚上场)
|
||||
*/
|
||||
@Scheduled(cron = CRON_TIEMS_2)
|
||||
public void yearRedPacketTimesRemind1() {
|
||||
logger.info("yearRedPacketRoundRemind1() start ========");
|
||||
actRedPacketRemindService.sendBatchMsg(null, actRedPacketRemindService.REMIND_TIMES_BEGIN_FORMAT);
|
||||
logger.info("yearRedPacketRoundRemind1() finish ========");
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束
|
||||
*/
|
||||
@Scheduled(cron = CRON_END)
|
||||
public void yearRedPacketEndRemind() {
|
||||
logger.info("yearRedPacketRoundRemind1() start ========");
|
||||
actRedPacketRemindService.sendBatchMsg(null, actRedPacketRemindService.REMIND_END_FORMAT);
|
||||
logger.info("yearRedPacketRoundRemind1() finish ========");
|
||||
}
|
||||
}
|
@@ -0,0 +1,112 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.activity.ActYearCeremonyService;
|
||||
import com.accompany.business.vo.activity.*;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ActYearCeremonyTask extends BaseTask {
|
||||
|
||||
// 固化状态
|
||||
private static final String FIXATION = "fixation";
|
||||
|
||||
@Autowired
|
||||
private ActYearCeremonyService actYearCeremonyService;
|
||||
|
||||
/**
|
||||
* 神豪王座数据
|
||||
*/
|
||||
@Scheduled(cron = "45 00 * * * ?")
|
||||
public void createRankKing() {
|
||||
log.info("ActYearCeremonyTask.createRankKing 初始化神豪王座数据");
|
||||
actYearCeremonyService.createRankKingInit(new Date());
|
||||
log.info("ActYearCeremonyTask.createRankKing 结束");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 固化土豪榜并发放奖励
|
||||
*/
|
||||
@Scheduled(cron = "0 04 00,12 * * ? ")
|
||||
public void saveTycoonRank() {
|
||||
ActYearCeremonyConfig config = actYearCeremonyService.getActYearCeremonyConf();
|
||||
Date date = new Date();
|
||||
log.info("ActYearCeremonyTask.saveExpertRank 开始固化达人榜单时间:{}", date);
|
||||
if(date.getTime() < config.getStartTime().getTime()){
|
||||
return ;
|
||||
}
|
||||
// 获取前一天的数据进行固化
|
||||
Date days = DateTimeUtil.addDays(date, -1);
|
||||
String dayTime = DateTimeUtil.convertDate(days, DateTimeUtil.DEFAULT_DATE_PATTERN);
|
||||
|
||||
Byte tycoonByte = Constant.YearCeremonyConstant.TYCOON;
|
||||
String awardKey = RedisKey.act_year_ceremony_award.getKey();
|
||||
|
||||
// 判断日榜数据是否已固化
|
||||
String fixationStr = jedisService.hget(RedisKey.act_year_ceremony_tycoon.getKey(FIXATION), dayTime);
|
||||
if(! Boolean.valueOf(fixationStr)){
|
||||
actYearCeremonyService.sendTycoonDayRankAward(days, dayTime, awardKey, tycoonByte);
|
||||
}
|
||||
|
||||
if(date.getTime() > config.getEndTime().getTime() && ! actYearCeremonyService.checkAwardStatus(awardKey, tycoonByte.toString())){
|
||||
// 发放总榜奖励
|
||||
actYearCeremonyService.sendTycoonRankAward(days, awardKey, tycoonByte);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 固化达人榜
|
||||
*/
|
||||
@Scheduled(cron = "${scheduler.year-ceremony.fixation-rank-cron}")
|
||||
public void saveExpertRank() {
|
||||
Date date = new Date();
|
||||
log.info("ActYearCeremonyTask.saveExpertRank 开始固化达人榜单时间:{}", date);
|
||||
// 获取达人榜单所有时间
|
||||
ActYearCeremonyConfig expertConf = actYearCeremonyService.getActYearExpertConf();
|
||||
ActYearCeremonyTimeVo expertTime = expertConf.getExpertTime();
|
||||
if(date.getTime() < expertTime.getVoteStartTime().getTime()){
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
// 固化榜单
|
||||
String rankKey = RedisKey.act_year_ceremony_expert.getKey();
|
||||
actYearCeremonyService.fixationRankType(expertTime, date,rankKey, Constant.YearCeremonyConstant.EXPERT);
|
||||
log.info("ActYearCeremonyTask.saveExpertRank 固化成功达人榜单时间", date);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 固化房间榜
|
||||
*/
|
||||
@Scheduled(cron = "${scheduler.year-ceremony.fixation-rank-cron}")
|
||||
public void saveRoomRank() {
|
||||
Date date = new Date();
|
||||
log.info("ActYearCeremonyTask.saveRoomRank 开始固化房间榜单时间:{}", date);
|
||||
// 获取达人榜单所有时间
|
||||
ActYearCeremonyConfig roomConf = actYearCeremonyService.getActYearRoomConf();
|
||||
ActYearCeremonyTimeVo roomTime = roomConf.getRoomTime();
|
||||
|
||||
if(date.getTime() < roomTime.getVoteStartTime().getTime()){
|
||||
return ;
|
||||
}
|
||||
|
||||
// 固化榜单
|
||||
String rankKey = RedisKey.act_year_ceremony_room.getKey();
|
||||
actYearCeremonyService.fixationRankType(roomTime, date,rankKey, Constant.YearCeremonyConstant.ROOM);
|
||||
log.info("ActYearCeremonyTask.saveRoomRank 固化成功房间榜单时间:{}", date);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.activity.ActivityFortuneService;
|
||||
import com.accompany.business.vo.activity.ActivityFortuneConfig;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ActivityFortuneTask extends BaseTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ActivityFortuneTask.class);
|
||||
|
||||
@Autowired
|
||||
private ActivityFortuneService activityFortuneService;
|
||||
|
||||
@Scheduled(cron = "0 0/20 * * * ? ")
|
||||
public void caveUpRedPacket() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
logger.info("开始执行许愿集福气,当前时间为:" + currentTime);
|
||||
ActivityFortuneConfig config = activityFortuneService.getFortuneConfig();
|
||||
long collectEndTime = DateTimeUtil.convertStrToDate(config.getCollectEndTime(), DateTimeUtil.DEFAULT_DATETIME_PATTERN).getTime();
|
||||
long drawStartTime = DateTimeUtil.convertStrToDate(config.getDrawStartTime(), DateTimeUtil.DEFAULT_DATETIME_PATTERN).getTime();
|
||||
long drawEndTime = DateTimeUtil.convertStrToDate(config.getDrawEndTime(), DateTimeUtil.DEFAULT_DATETIME_PATTERN).getTime();
|
||||
Long listNum = jedisService.llen(RedisKey.activity_fortune_red_packet.getKey());
|
||||
if(currentTime > collectEndTime && currentTime < drawStartTime){
|
||||
activityFortuneService.redPacket(listNum,config.getCaveUpGold());
|
||||
}else if(currentTime > drawEndTime){
|
||||
activityFortuneService.caveUpRemainingGold(listNum);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,105 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.activities.ActivitiesCoupleService;
|
||||
import com.accompany.business.service.activity.*;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Created By LeeNana on 2020/3/11.
|
||||
* 活动定时器
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ActivityTask extends BaseTask {
|
||||
|
||||
@Autowired
|
||||
private ActivitiesCoupleService activitiesCoupleService;
|
||||
@Autowired
|
||||
private ActivityYearBeastService activityYearBeastService;
|
||||
@Autowired
|
||||
private ActivityLoveWallService activityLoveWallService;
|
||||
@Autowired
|
||||
private ActivityLoveRankService activityLoveRankService;
|
||||
@Autowired
|
||||
private ActivityOneYearService activityOneYearService;
|
||||
@Autowired
|
||||
private ActivityOneYearSweetCakeService activityOneYearSweetCakeService;
|
||||
@Autowired
|
||||
private ActMagicSchoolService actMagicSchoolService;
|
||||
|
||||
/**
|
||||
* 三日情侣活动
|
||||
*/
|
||||
// @Scheduled(cron = "0 0 0 18 3 ?")
|
||||
public void sendMsgToUser(){
|
||||
log.info("sendMsgToUser() start..........");
|
||||
try {
|
||||
activitiesCoupleService.sendMsgToUser();
|
||||
log.info("sendMsgToUser() end..........");
|
||||
}catch (Exception e){
|
||||
log.error("sendMsgToUser() failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 年兽活动奖励
|
||||
*/
|
||||
// @Scheduled(cron = "0 02 00,12 * * ? ")
|
||||
public void sendYearBeastAward(){
|
||||
log.info("ActivityTask.sendYearBeastAward 开始发放年兽活动奖励");
|
||||
activityYearBeastService.sendActYearBeastAward();
|
||||
log.info("ActivityTask.sendYearBeastAward 发放年兽活动奖励结束");
|
||||
}
|
||||
|
||||
/**
|
||||
* 2022情人节活动奖励
|
||||
*/
|
||||
// @Scheduled(cron = "0 02 00,12 * * ? ")
|
||||
public void sendLoveWallAward(){
|
||||
try {
|
||||
log.info("ActivityTask.sendLoveWallAward 发放情人节表白墙奖励开始");
|
||||
activityLoveWallService.sendLoveWallAward();
|
||||
log.info("ActivityTask.sendLoveWallAward 发放情人节表白墙奖励结束");
|
||||
}catch (Exception e){
|
||||
log.error("ActivityTask.sendLoveWallAward() failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
// @Scheduled(cron = "0 02 00,12 * * ?")
|
||||
public void sednActLoveRankAward(){
|
||||
try {
|
||||
log.info("ActivityTask.sednActLoveRankAward 开始发放 520榜单活动奖励");
|
||||
activityLoveRankService.sednActLoveRankAward();
|
||||
log.info("ActivityTask.sednActLoveRankAward 520榜单活动奖励发放结束");
|
||||
}catch (Exception e){
|
||||
log.error("ActivityTask.sendLoveWallAward() failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
// @Scheduled(cron = "0 02 00,12 * * ?")
|
||||
public void sednActOneYearAward(){
|
||||
try {
|
||||
log.info("ActivityTask.sednActOneYearAward 开始发放 一周年奖励");
|
||||
activityOneYearService.sednActOneYearAward();
|
||||
log.info("ActivityTask.sednActOneYearAward 一周年奖励发放结束");
|
||||
activityOneYearSweetCakeService.sendCompoundCakeAward();
|
||||
}catch (Exception e){
|
||||
log.error("ActivityTask.sednActOneYearAward() failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 02 00,12 * * ?")
|
||||
public void sednActMagicSchoolRankAward(){
|
||||
try {
|
||||
log.info("ActivityTask.sendActRankAward 开始发放 魔法学院榜单");
|
||||
actMagicSchoolService.sendActRankAward();
|
||||
log.info("ActivityTask.sendActRankAward 魔法学院榜单");
|
||||
}catch (Exception e){
|
||||
log.error("ActivityTask.sednActOneYearAward() failed", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.anchor.AnchorFansTeamService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 每天12点发送粉丝专属礼物
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AnchorFansDesignGiftTask extends BaseTask {
|
||||
|
||||
@Autowired
|
||||
private AnchorFansTeamService anchorFansTeamService;
|
||||
|
||||
@Scheduled(cron = "0 2 0 * * ?")
|
||||
public void createRankKing() {
|
||||
log.info("赠送粉丝每日专属礼物和初始化粉丝铭牌状态开始....");
|
||||
anchorFansTeamService.sendDesignGiftAndNameplateStatus();
|
||||
log.info("赠送粉丝每日专属礼物和初始化粉丝铭牌结束....");
|
||||
}
|
||||
}
|
@@ -0,0 +1,183 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.model.AuditAudioRoom;
|
||||
import com.accompany.core.model.Room;
|
||||
import com.accompany.business.mybatismapper.AuditAudioRoomMapper;
|
||||
import com.accompany.business.service.auditaudio.AuditAudioRoomService;
|
||||
import com.accompany.business.service.room.RoomService;
|
||||
import com.accompany.business.vo.RunningRoomVo;
|
||||
import com.accompany.business.vo.auditaudio.AuditAudioBaseRetVo;
|
||||
import com.accompany.business.vo.auditaudio.AuditAudioListRetVo;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import com.accompany.common.constant.RoomMonitorTypeEnum;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.StringUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 2 * @Author: zhuct
|
||||
* 3 * @Date: 2019/8/28 14:30
|
||||
* 4
|
||||
*/
|
||||
//@Component
|
||||
public class AuditAudioRoomTask extends BaseTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AuditAudioRoomTask.class);
|
||||
@Autowired
|
||||
private AuditAudioRoomService auditAudioRoomService;
|
||||
@Autowired
|
||||
private RoomService roomService;
|
||||
@Autowired
|
||||
private AuditAudioRoomMapper auditAudioRoomMapper;
|
||||
|
||||
@Resource(name = "bizExecutor")
|
||||
private TaskExecutor bizExecutor;
|
||||
|
||||
/**
|
||||
* 将需要监控的房间,向数美查询是否停止监控,若已经停止则重新发起请求
|
||||
*/
|
||||
@Scheduled(cron = "0 */2 * * * ?")
|
||||
public void checkRestartAuditAudioRoom() {
|
||||
logger.info("checkRestartAuditAudioRoom start ================");
|
||||
Integer monitorType = auditAudioRoomService.getRoomMonitorType();
|
||||
if (monitorType == null) {
|
||||
return;
|
||||
}
|
||||
if (monitorType == RoomMonitorTypeEnum.GIVEN_ROOM.getValue()) {
|
||||
sendAuditRoom(this.getAllGivenRoom(), RoomMonitorTypeEnum.GIVEN_ROOM.getValue());
|
||||
|
||||
} else if (monitorType == RoomMonitorTypeEnum.ALL_ROOM.getValue()) {
|
||||
sendAuditRoom(this.getAllOnlineRoom(), RoomMonitorTypeEnum.ALL_ROOM.getValue());
|
||||
}
|
||||
|
||||
Map<String, String> map = jedisService.hgetAll(RedisKey.audit_audio_room.getKey());
|
||||
if (map == null || map.size() == 0) {
|
||||
return;
|
||||
}
|
||||
List<String> requestIds = this.getAuditingRequestIds();
|
||||
for (String key : map.keySet()) {
|
||||
Long roomUid = Long.valueOf(key);
|
||||
AuditAudioRoom audioRoom = gson.fromJson(map.get(key), AuditAudioRoom.class);
|
||||
String runningRoomStr = jedisService.hget(RedisKey.room_running.getKey(), roomUid.toString());
|
||||
RunningRoomVo runningRoomVo = gson.fromJson(runningRoomStr, RunningRoomVo.class);
|
||||
//如果房间在线人数不为0,并且数美已经没有在监控,则重新发起监控请求
|
||||
if (runningRoomVo != null && runningRoomVo.getOnlineNum() != 0 && !requestIds.contains(audioRoom.getRequestId())) {
|
||||
logger.info("need to restart audit room,roomUid={}", roomUid);
|
||||
this.restartAuditAudioRoom(roomUid, audioRoom);
|
||||
}
|
||||
}
|
||||
logger.info("checkRestartAuditAudioRoom end =================");
|
||||
}
|
||||
|
||||
private void sendAuditRoom(List<String> roomUids, Byte monitorType) {
|
||||
for (String roomUid : roomUids) {
|
||||
Boolean hexists = jedisService.hexists(RedisKey.audit_audio_room.getKey(), roomUid);
|
||||
if (!hexists) {//如果需要送审的房间不在audit_audio_room缓存中,则送审
|
||||
logger.info("send audit room,roomUid={}", roomUid);
|
||||
Room room = roomService.getRoomByUid(Long.valueOf(roomUid));
|
||||
auditAudioRoomService.sendAuditRoom(room, monitorType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有指定房间,在线并且有人房间列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private List<String> getAllGivenRoom() {
|
||||
List<String> roomUids = new ArrayList<>();
|
||||
Set<String> smembers = jedisService.smembers(RedisKey.given_audit_audio_room.getKey());
|
||||
if (CollectionUtils.isNotEmpty(smembers)) {
|
||||
smembers.forEach(smember -> {
|
||||
String runningRoomStr = jedisService.hget(RedisKey.room_running.getKey(), smember);
|
||||
if (StringUtils.isNotBlank(runningRoomStr)) {
|
||||
RunningRoomVo runningRoomVo = gson.fromJson(runningRoomStr, RunningRoomVo.class);
|
||||
if (runningRoomVo != null && runningRoomVo.getOnlineNum() != 0) {
|
||||
roomUids.add(smember);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return roomUids;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有在线并且有人房间列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private List<String> getAllOnlineRoom() {
|
||||
List<String> roomUids = new ArrayList<>();
|
||||
Map<String, String> map = jedisService.hgetAll(RedisKey.room_running.getKey());
|
||||
if (map != null && map.size() > 0) {
|
||||
for (String key : map.keySet()) {
|
||||
RunningRoomVo runningRoomVo = gson.fromJson(map.get(key), RunningRoomVo.class);
|
||||
if (runningRoomVo != null && runningRoomVo.getOnlineNum() != 0) {
|
||||
roomUids.add(key);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return roomUids;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有数美现在正在审核的requestId集合
|
||||
* <p>
|
||||
* {
|
||||
* "code": 1100,
|
||||
* "message": "成功",
|
||||
* "requestId": "b0fe038a9fa8195b129012af2dba619e",
|
||||
* "detail": [
|
||||
* {
|
||||
* "audioStarttime": "2019-08-28 16:33:17",
|
||||
* "audioUrl": "",
|
||||
* "requestId": "832b7fa23b8b3e424b58da8b6cb37f87"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private List<String> getAuditingRequestIds() {
|
||||
List<String> requestIds = new ArrayList<>();
|
||||
try {
|
||||
AuditAudioListRetVo mediaRetVo = auditAudioRoomService.getAuditMedia();
|
||||
if (mediaRetVo.getCode() == 1100 && CollectionUtils.isNotEmpty(mediaRetVo.getDetail())) {
|
||||
requestIds = mediaRetVo.getDetail().stream().map(item -> item.get("requestId").toString()).collect(Collectors.toList());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("getAuditingRequestIds error cause by:", e.getMessage());
|
||||
|
||||
}
|
||||
return requestIds;
|
||||
}
|
||||
|
||||
private void restartAuditAudioRoom(Long roomUid, AuditAudioRoom audioRoom) {
|
||||
bizExecutor.execute(() -> {
|
||||
Room room = roomService.getRoomByUid(roomUid);
|
||||
try {
|
||||
AuditAudioBaseRetVo mediaRetVo = auditAudioRoomService.sendAuditMediaRoom(roomUid, room.getRoomId());
|
||||
if (mediaRetVo.getCode() == 1100) {
|
||||
audioRoom.setRequestId(mediaRetVo.getRequestId());
|
||||
audioRoom.setUpdateTime(new Date());
|
||||
auditAudioRoomMapper.updateByPrimaryKeySelective(audioRoom);
|
||||
jedisService.hset(RedisKey.audit_audio_room.getKey(), room.getUid().toString(), gson.toJson(audioRoom));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("sendAuditMediaRoom error cause by:", e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.car.CarportService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class CarTask extends BaseTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CarTask.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
private CarportService carportService;
|
||||
|
||||
|
||||
/**
|
||||
* 清除过期,凌晨10分和15分
|
||||
*/
|
||||
@Scheduled(cron = "0 20,35 0 * * ?")
|
||||
public void clearExpireCar() {
|
||||
logger.info("clearExpireCar start ===============");
|
||||
carportService.releaseAllExpireCar();
|
||||
logger.info("clearExpireCar finish ===============");
|
||||
}
|
||||
|
||||
/**
|
||||
* 提醒快过期用户, 凌晨30分
|
||||
*/
|
||||
@Scheduled(cron = "0 30 12 * * ?")
|
||||
public void sendNoticeCar() {
|
||||
logger.info("sendNoticeCar start ===============");
|
||||
carportService.sendWillExpireNotice();
|
||||
logger.info("sendNoticeCar finish ===============");
|
||||
}
|
||||
}
|
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 文 件 名: ChargeNotifyTask
|
||||
* 版 权:
|
||||
* 描 述: <描述>
|
||||
* 创建人: H1
|
||||
* 创建时间: 2021/4/19
|
||||
* 修改人:
|
||||
* 修改内容:
|
||||
* 修改时间:
|
||||
*/
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.common.push.MarkdownMessage;
|
||||
import com.accompany.business.mybatismapper.ChargeNotifyMapper;
|
||||
import com.accompany.business.service.push.EnterpriseWechatPushService;
|
||||
import com.accompany.business.vo.ChargeNotifyVO;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.utils.StringUtils;
|
||||
import com.accompany.core.service.SysConfService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <br>类描述: 充值异常提醒
|
||||
* <br>功能详细描述:
|
||||
*
|
||||
* @author H1
|
||||
* @date [2021/4/19]
|
||||
*/
|
||||
//@Component
|
||||
@Slf4j
|
||||
public class ChargeNotifyTask extends BaseTask {
|
||||
@Autowired
|
||||
private EnterpriseWechatPushService enterpriseWechatPushService;
|
||||
@Autowired
|
||||
private ChargeNotifyMapper chargeNotifyMapper;
|
||||
@Autowired
|
||||
private SysConfService sysConfService;
|
||||
|
||||
@Scheduled(cron = "0 0/10 * * * ?")
|
||||
public void sendChargeNotify() {
|
||||
log.info("开始获取最近10分钟的充值订单情况, currTimeStamp {}", System.currentTimeMillis());
|
||||
List<ChargeNotifyVO> statList = chargeNotifyMapper.listChargeStat(10);
|
||||
String sendNotifyFailRateStr = sysConfService.getDefaultSysConfValueById(Constant.SysConfId.SEND_CHARGE_NOTIFY_FAIL_RATE, "0.9");
|
||||
if (CollectionUtils.isNotEmpty(statList)) {
|
||||
for (ChargeNotifyVO vo : statList) {
|
||||
log.info("充值概况,statVo {}", JSON.toJSONString(vo));
|
||||
double failRate = new BigDecimal(vo.getFailNum()).divide(new BigDecimal(vo.getTotalNum())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
||||
log.info("chargeApp {} channel {}, failRate {}", vo.getChargeApp(), vo.getChargeChannel(), failRate);
|
||||
if (failRate >= Double.valueOf(sendNotifyFailRateStr)) {
|
||||
sendEnterpriseWechatMsg(vo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送企业微信通知
|
||||
* @param vo
|
||||
*/
|
||||
private void sendEnterpriseWechatMsg(ChargeNotifyVO vo) {
|
||||
MarkdownMessage msg = new MarkdownMessage();
|
||||
msg.add(MarkdownMessage.getHeaderText(3, "充值服务异常提醒"));
|
||||
msg.add(MarkdownMessage.getReferenceText(getChannelName(vo.getChargeChannel())));
|
||||
String appName = getAppName(vo.getChargeApp());
|
||||
msg.add(MarkdownMessage.getReferenceText("(" + appName + ")" + "前10分钟支付失败率过高,请关注"));
|
||||
enterpriseWechatPushService.pushMessage(msg);
|
||||
}
|
||||
|
||||
private String getChannelName(String channel) {
|
||||
String channelName = "";
|
||||
switch (channel) {
|
||||
case Constant.ChargeChannel.alipay: {
|
||||
channelName = "支付宝支付";
|
||||
break;
|
||||
}
|
||||
case Constant.ChargeChannel.alipay_wap: {
|
||||
channelName = "支付宝H5支付";
|
||||
break;
|
||||
}
|
||||
case Constant.ChargeChannel.ios_pay: {
|
||||
channelName = "IOS支付";
|
||||
break;
|
||||
}
|
||||
case Constant.ChargeChannel.lucky_tarot: {
|
||||
channelName = "幸运塔罗充值";
|
||||
break;
|
||||
}
|
||||
case Constant.ChargeChannel.wx: {
|
||||
channelName = "微信支付";
|
||||
break;
|
||||
}
|
||||
case Constant.ChargeChannel.wx_micro_mall_pub: {
|
||||
channelName = "微商城微信公众号支付";
|
||||
break;
|
||||
}
|
||||
case Constant.ChargeChannel.wx_mini_app_channel: {
|
||||
channelName = "小程序支付";
|
||||
break;
|
||||
}
|
||||
case Constant.ChargeChannel.wx_pub: {
|
||||
channelName = "微信公众号支付";
|
||||
break;
|
||||
}
|
||||
case Constant.ChargeChannel.wx_wap: {
|
||||
channelName = "微信H5支付";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return channelName;
|
||||
}
|
||||
|
||||
private String getAppName(String app) {
|
||||
String appName = "";
|
||||
if (StringUtils.isNotBlank(app)) {
|
||||
if (app.contains("PlanetStar")) {
|
||||
return "66星球";
|
||||
}
|
||||
if (app.contains("yinyou")) {
|
||||
return "大鹅开黑";
|
||||
}
|
||||
}
|
||||
return appName;
|
||||
}
|
||||
}
|
@@ -0,0 +1,108 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.user.UsersService;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import com.accompany.scheduler.config.TaskPropertyConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.Trigger;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author yubin
|
||||
* @Description 检查长时间未使用未登录的用户,将其资产冻结
|
||||
* @Date 2019-06-19 10:57
|
||||
*/
|
||||
@Slf4j
|
||||
//@Component
|
||||
public class CheckLongTimeUnused extends BaseTask implements SchedulingConfigurer {
|
||||
|
||||
|
||||
@Autowired
|
||||
private TaskPropertyConfig taskPropertyConfig;
|
||||
|
||||
@Autowired
|
||||
private UsersService usersService;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
taskRegistrar.addTriggerTask(doTask(), getTrigger());
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务执行方法
|
||||
* @return
|
||||
*/
|
||||
private Runnable doTask() {
|
||||
return () -> frozeExpiredUsers();
|
||||
}
|
||||
|
||||
/**
|
||||
* 冻结长时间未登录的用户资产
|
||||
*/
|
||||
private void frozeExpiredUsers(){
|
||||
Calendar instance = Calendar.getInstance();
|
||||
//截止时间=当前时间-90天
|
||||
instance.add(Calendar.DAY_OF_MONTH,-taskPropertyConfig.getBeforeDay());
|
||||
Date endTime = instance.getTime();
|
||||
//开始时间
|
||||
Date starTime = DateTimeUtil.convertStrToDate(taskPropertyConfig.getStartTime());
|
||||
if(starTime == null){
|
||||
starTime = DateTimeUtil.convertStrToDate("2019-01-01");
|
||||
}
|
||||
if(starTime.after(endTime)){
|
||||
log.warn("frozeExpireUser startTime:{} cannot after endTime:{}",starTime,endTime);
|
||||
return;
|
||||
}
|
||||
log.info("frozeExpireUser param,starTime:{},endTime:{},size:{},beforeDay:{},checkUseTime:{}",taskPropertyConfig.getStartTime(),
|
||||
endTime, taskPropertyConfig.getSize(), taskPropertyConfig.getBeforeDay(), taskPropertyConfig.getCheckUserTime());
|
||||
List<Users> usersWithBalances = usersService.getUsersWithBalances(starTime, endTime, taskPropertyConfig.getSize());
|
||||
if(CollectionUtils.isEmpty(usersWithBalances)){
|
||||
log.info("frozeExpireUser usersWithBalances is empty");
|
||||
return;
|
||||
}
|
||||
//更新用户的冻结状态和清除用户的缓存
|
||||
int row = usersService.updateUserStatusByUidList(usersWithBalances, Constant.UserStatus.FROZEN);
|
||||
if(row > 0){
|
||||
deleteUserCache(usersWithBalances);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除对应的缓存
|
||||
* @param usersWithBalances
|
||||
*/
|
||||
private void deleteUserCache(List<Users> usersWithBalances){
|
||||
usersWithBalances.forEach(user ->{
|
||||
this.jedisService.hdel(RedisKey.user.getKey(), String.valueOf(user.getUid()));
|
||||
this.jedisService.hdel(RedisKey.user_summary.getKey(), String.valueOf(user.getUid()));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务触发器
|
||||
* @return
|
||||
*/
|
||||
private Trigger getTrigger() {
|
||||
return triggerContext -> {
|
||||
// 触发器
|
||||
CronTrigger trigger = new CronTrigger(taskPropertyConfig.getCheckUserTime());
|
||||
return trigger.nextExecutionTime(triggerContext);
|
||||
};
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.model.FamilyRedPacket;
|
||||
import com.accompany.business.service.family.FamilyRedPacketService;
|
||||
import com.accompany.core.service.base.BaseService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* @author yangziwen
|
||||
* @description 定时清理过期红包任务
|
||||
* @date 2018/7/17 17:17
|
||||
*/
|
||||
//@Component
|
||||
public class CleanExpiredRedPacketTask extends BaseService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CleanExpiredRedPacketTask.class);
|
||||
|
||||
@Autowired
|
||||
private FamilyRedPacketService redPacketService;
|
||||
|
||||
@Scheduled(cron = "0 0/5 * * * *")
|
||||
public void cleanExpiredRedPackets() {
|
||||
List<FamilyRedPacket> redPacketList = this.redPacketService.getExpiredRedPackets();
|
||||
logger.info("cleanExpiredRedPackets(), size={}", redPacketList == null ? 0 : redPacketList.size());
|
||||
|
||||
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
for (FamilyRedPacket redPacket : redPacketList) {
|
||||
executor.execute(() -> {
|
||||
this.redPacketService.cleanExpiredRedPacket(redPacket);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,86 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.accompany.business.dto.UserCpSecretValCacheDto;
|
||||
import com.accompany.business.mybatismapper.user.UserCoupleMapper;
|
||||
import com.accompany.business.service.user.UserCoupleService;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.common.utils.StringUtils;
|
||||
import com.accompany.core.service.SysConfService;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.google.gson.Gson;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* cp用户扣减经验任务处理
|
||||
*/
|
||||
@Component
|
||||
public class CpUserDeduSecretValTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CpUserDeduSecretValTask.class);
|
||||
|
||||
private static final Integer STEP_LEN = 500;
|
||||
|
||||
@Autowired
|
||||
private UserCoupleService userCoupleService;
|
||||
@Autowired
|
||||
private UserCoupleMapper userCoupleMapper;
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
@Autowired
|
||||
private SysConfService sysConfService;
|
||||
|
||||
private Gson gson = new Gson();
|
||||
|
||||
/**
|
||||
* 凌晨4点执行
|
||||
*/
|
||||
@Scheduled(cron = "0 0 4 * * ?")
|
||||
public void deduSecretVal() {
|
||||
logger.info("begin deduSecretVal =============================================================");
|
||||
|
||||
Integer counter = 0;
|
||||
Integer start = 0;
|
||||
Integer len = STEP_LEN;
|
||||
|
||||
Integer deduVal = Integer.valueOf(sysConfService.getDefaultSysConfValueById(Constant.SysConfId.CP_DEDU_SECRET_VAL_DAILY, String.valueOf(Constant.UserRelationDefaultVal.cp_dedu_secret_val_daily)));
|
||||
|
||||
Integer dayNeed = Integer.valueOf(sysConfService.getDefaultSysConfValueById(Constant.SysConfId.DEDU_SECRET_VAL_DAY_NEED, String.valueOf(Constant.UserRelationDefaultVal.dedu_secret_val_day_need)));
|
||||
|
||||
List<Long> idList = userCoupleMapper.queryUserCoupleInCp(start, len);
|
||||
|
||||
while (!CollectionUtil.isEmpty(idList)) {
|
||||
for (Long id : idList) {
|
||||
try {
|
||||
String cpExperStr = jedisService.hget(RedisKey.user_cp_secret_val.getKey(), String.valueOf(id));
|
||||
if (StringUtils.isEmpty(cpExperStr)) continue;
|
||||
|
||||
UserCpSecretValCacheDto userCpSecretValCacheDto = gson.fromJson(cpExperStr, UserCpSecretValCacheDto.class);
|
||||
//获取最后一次增加亲密值对应日期第二天的0点时刻
|
||||
Date addSecretDate = DateTimeUtil.addDays(DateTimeUtil.getZeroTimeByDate(DateTimeUtil.convertMsToDate(userCpSecretValCacheDto.getMs())), 1);
|
||||
Integer dayNum = DateTimeUtil.diffDayByDate(new Date(), addSecretDate);
|
||||
if (dayNum < dayNeed) continue;
|
||||
|
||||
userCoupleService.addSecretVal(id, Long.valueOf(deduVal));
|
||||
}catch(Exception e){
|
||||
logger.info("cpUserDeduSecretValTask执行cp记录{}扣经验{}任务异常{}", id, e.getMessage());
|
||||
logger.error("execute cpUserUnboundTask error,error={}",e);
|
||||
}
|
||||
}
|
||||
|
||||
counter++;
|
||||
start = STEP_LEN * counter;
|
||||
idList = userCoupleMapper.queryUserCoupleInCp(start, len);
|
||||
}
|
||||
logger.info("end deduSecretVal =============================================================");
|
||||
}
|
||||
}
|
@@ -0,0 +1,89 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.accompany.business.model.user.UserCouple;
|
||||
import com.accompany.business.model.user.UserCoupleTask;
|
||||
import com.accompany.business.mybatismapper.user.UserCoupleMapper;
|
||||
import com.accompany.business.service.user.UserCoupleTaskService;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* CP陪伴时长扫描
|
||||
*/
|
||||
@Component
|
||||
public class CpUserKeepTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CpUserKeepTask.class);
|
||||
|
||||
private static final Integer STEP_LEN = 500;
|
||||
|
||||
@Autowired
|
||||
private UserCoupleMapper userCoupleMapper;
|
||||
@Autowired
|
||||
private UserCoupleTaskService userCoupleTaskService;
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
|
||||
/**
|
||||
* 每天9点执行
|
||||
*/
|
||||
@Scheduled(cron = "0 0 9 * * ?")
|
||||
public void scanAndDealKeepCpDuration() {
|
||||
logger.info("begin cpUserKeepTask =============================================================");
|
||||
|
||||
Integer counter = 0;
|
||||
Integer start = 0;
|
||||
Integer len = STEP_LEN;
|
||||
|
||||
|
||||
List<UserCoupleTask> userCoupleTaskList = userCoupleTaskService.queryCoupleTotalTaskByType(Constant.UserCoupleTaskType.companion);
|
||||
if (CollectionUtil.isEmpty(userCoupleTaskList)) {
|
||||
logger.info("未检测到陪伴任务,放弃执行...");
|
||||
return;
|
||||
}
|
||||
|
||||
List<Integer> needList = userCoupleTaskList.stream().map(UserCoupleTask::getNeed).collect(Collectors.toList());
|
||||
|
||||
//扫描所有在24~48小时内达到对应任务时长的
|
||||
List<UserCouple> userCoupleList = userCoupleMapper.scanAndDealKeepCpDuration(needList, start, len);
|
||||
|
||||
while (!CollectionUtil.isEmpty(userCoupleList)) {
|
||||
for (UserCouple userCouple : userCoupleList) {
|
||||
try {
|
||||
//计算CP组建时间与当前时间差值
|
||||
Long diffMs = new Date().getTime() - userCouple.getAcceptTime().getTime();
|
||||
for (UserCoupleTask coupleTask : userCoupleTaskList) {
|
||||
//差值与任务所需时长比较
|
||||
Long taskMs = coupleTask.getNeed() * 60 * 60 * 1000l;
|
||||
if (diffMs > taskMs) continue;
|
||||
|
||||
Integer diffSecond = BigDecimal.valueOf((taskMs - diffMs) / 1000).intValue();
|
||||
|
||||
//设置key过期后做处理
|
||||
jedisService.setex(RedisKey.cp_user_keep_duration.getKey(userCouple.getId() + StrUtil.UNDERLINE + coupleTask.getId()), diffSecond, String.valueOf(1));
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.error("execute cpUserKeepTask error,error={}",e);
|
||||
}
|
||||
}
|
||||
|
||||
counter++;
|
||||
start = STEP_LEN * counter;
|
||||
userCoupleList = userCoupleMapper.scanAndDealKeepCpDuration(needList, start, len);
|
||||
}
|
||||
logger.info("end cpUserKeepTask =============================================================");
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.accompany.business.mybatismapper.user.UserCoupleMapper;
|
||||
import com.accompany.business.service.user.UserCoupleService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Component
|
||||
public class CpUserUnboundTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CpUserUnboundTask.class);
|
||||
|
||||
private static final Integer STEP_LEN = 500;
|
||||
|
||||
@Autowired
|
||||
private UserCoupleService userCoupleService;
|
||||
@Autowired
|
||||
private UserCoupleMapper userCoupleMapper;
|
||||
|
||||
/**
|
||||
* 每10分钟执行一次
|
||||
*/
|
||||
@Scheduled(cron = "0 */10 * * * ?")
|
||||
public void denyCpInvite() {
|
||||
logger.info("begin cpUserUnboundTask =============================================================");
|
||||
|
||||
Integer counter = 0;
|
||||
Integer start = 0;
|
||||
Integer len = STEP_LEN;
|
||||
|
||||
|
||||
List<Long> idList = userCoupleMapper.getOverdueWaitUnboundList(start, len);
|
||||
|
||||
while (!CollectionUtil.isEmpty(idList)) {
|
||||
for (Long id : idList) {
|
||||
try {
|
||||
logger.info("cpUserUnboundTask执行cp邀请{}自动拒绝", id);
|
||||
userCoupleService.unboundDeal(id);
|
||||
}catch(Exception e){
|
||||
logger.info("cpUserUnboundTask执行cp邀请{}自动拒绝任务异常{}", id, e.getMessage());
|
||||
logger.error("execute cpUserUnboundTask error,error={}",e);
|
||||
}
|
||||
}
|
||||
|
||||
counter++;
|
||||
start = STEP_LEN * counter;
|
||||
idList = userCoupleMapper.getOverdueWaitUnboundList(start, len);
|
||||
}
|
||||
logger.info("end cpUserUnboundTask =============================================================");
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.accompany.business.mybatismapper.user.UserCoupleMapper;
|
||||
import com.accompany.business.service.user.UserCoupleService;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Component
|
||||
public class DenyInviteCpTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DenyInviteCpTask.class);
|
||||
|
||||
private static final Integer STEP_LEN = 500;
|
||||
|
||||
@Autowired
|
||||
private UserCoupleService userCoupleService;
|
||||
@Autowired
|
||||
private UserCoupleMapper userCoupleMapper;
|
||||
|
||||
/**
|
||||
* 每5分钟执行一次
|
||||
*/
|
||||
@Scheduled(cron = "0 */5 * * * ?")
|
||||
public void denyCpInvite() {
|
||||
logger.info("begin denyInviteCpTask =============================================================");
|
||||
|
||||
Integer counter = 0;
|
||||
Integer start = 0;
|
||||
Integer len = STEP_LEN;
|
||||
|
||||
|
||||
List<Long> idList = userCoupleMapper.getOverdueInviteList(start, len);
|
||||
|
||||
while (!CollectionUtil.isEmpty(idList)) {
|
||||
for (Long id : idList) {
|
||||
try {
|
||||
logger.info("denyInviteCpTask执行cp邀请{}自动拒绝", id);
|
||||
userCoupleService.replyCpInvite(id, Constant.UserCoupleState.expire);
|
||||
}catch(Exception e){
|
||||
logger.info("denyInviteCpTask执行cp邀请{}自动拒绝任务异常{}", id, e.getMessage());
|
||||
logger.error("execute denyInviteCpTask error,error={}",e);
|
||||
}
|
||||
}
|
||||
|
||||
counter++;
|
||||
start = STEP_LEN * counter;
|
||||
idList = userCoupleMapper.getOverdueInviteList(start, len);
|
||||
}
|
||||
logger.info("end denyInviteCpTask =============================================================");
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.box.DrawLotteryRecordDayService;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
|
||||
@Component
|
||||
public class DrawLotteryRecordDayTask extends BaseTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DrawLotteryRecordDayTask.class);
|
||||
|
||||
@Autowired
|
||||
private DrawLotteryRecordDayService drawLotteryRecordDayService;
|
||||
|
||||
/**
|
||||
* 每天0点统计昨天的许愿数据到数据库
|
||||
*/
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
public void addDataByDay() throws ParseException {
|
||||
logger.info("DrawLotteryRecordDayService start ===============");
|
||||
Date date = DateTimeUtil.addDays(new Date(), -1);
|
||||
drawLotteryRecordDayService.addDataByDay(DateTimeUtil.convertDate(date, DateTimeUtil.DEFAULT_DATE_PATTERN));
|
||||
logger.info("DrawLotteryRecordDayService finish ===============");
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,76 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.activities.ActivitiesDrawService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import com.accompany.scheduler.config.TaskPropertyConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.Trigger;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
|
||||
/**
|
||||
* Created By LeeNana on 2019/11/5.
|
||||
* 转盘的定时器
|
||||
*/
|
||||
//@Component
|
||||
@Slf4j
|
||||
public class DrawTurnTableTask extends BaseTask implements SchedulingConfigurer {
|
||||
@Autowired
|
||||
private ActivitiesDrawService activitiesDrawService;
|
||||
|
||||
@Autowired
|
||||
private TaskPropertyConfig taskPropertyConfig;
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
taskRegistrar.addTriggerTask(doTask(), getTrigger());
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务触发器
|
||||
* @return
|
||||
*/
|
||||
private Trigger getTrigger() {
|
||||
return triggerContext -> {
|
||||
// 触发器
|
||||
CronTrigger trigger = new CronTrigger(taskPropertyConfig.getUpdatePrizeTime());
|
||||
return trigger.nextExecutionTime(triggerContext);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务执行方法
|
||||
* @return
|
||||
*/
|
||||
private Runnable doTask() {
|
||||
return () -> updatePrizeMsg();
|
||||
}
|
||||
|
||||
|
||||
// @Scheduled(cron = "0/5 * * * * ?")
|
||||
//处理转盘滚屏数据
|
||||
public void updatePrizeMsg(){
|
||||
log.info("updatePrizeMsg start........");
|
||||
try {
|
||||
activitiesDrawService.updatePrizeMsgTask(taskPropertyConfig.getPrizeSize());
|
||||
log.info("updatePrizeMsg end........");
|
||||
}catch (Exception e){
|
||||
log.error("updatePrizeMsg failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 0-23 * * ?")
|
||||
public void delRunawayValue(){
|
||||
log.info("delRunawayValue() start..........");
|
||||
try {
|
||||
activitiesDrawService.delRunawayValue();
|
||||
log.info("delRunawayValue() end..........");
|
||||
}catch (Exception e){
|
||||
log.error("delRunawayValue() failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.community.DynamicTaskService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import com.accompany.scheduler.config.TaskPropertyConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.Trigger;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Created By LeeNana on 2019/11/25.
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DynamicHotValueTask extends BaseTask implements SchedulingConfigurer {
|
||||
@Autowired
|
||||
private TaskPropertyConfig taskPropertyConfig;
|
||||
@Autowired
|
||||
private DynamicTaskService dynamicTaskService;
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
taskRegistrar.addTriggerTask(doTask(), getTrigger());
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务触发器
|
||||
* @return
|
||||
*/
|
||||
private Trigger getTrigger() {
|
||||
return triggerContext -> {
|
||||
// 触发器
|
||||
CronTrigger trigger = new CronTrigger(taskPropertyConfig.getUpdateHotValueTime());
|
||||
return trigger.nextExecutionTime(triggerContext);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务执行方法
|
||||
* @return
|
||||
*/
|
||||
private Runnable doTask() {
|
||||
return () -> updateHotValue();
|
||||
}
|
||||
|
||||
|
||||
public void updateHotValue(){
|
||||
log.info("updateHotValue start........");
|
||||
try {
|
||||
dynamicTaskService.updateHotValueTask();
|
||||
log.info("updateHotValue end........");
|
||||
}catch (Exception e){
|
||||
log.error("updateHotValue failed", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,118 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.community.DynamicService;
|
||||
import com.accompany.business.service.community.DynamicStatService;
|
||||
import com.accompany.community.constant.DynamicStatusEnum;
|
||||
import com.accompany.community.entity.Dynamic;
|
||||
import com.accompany.community.query.DynamicDataStatQuery;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 话题定时器,处理僵尸房
|
||||
* @author fangchengyan
|
||||
* @date 2019-12-02
|
||||
*/
|
||||
@Component
|
||||
public class DynamicTask extends BaseTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DynamicTask.class);
|
||||
|
||||
@Autowired
|
||||
private DynamicService dynamicService;
|
||||
@Autowired
|
||||
private DynamicStatService dynamicStatService;
|
||||
|
||||
/**
|
||||
* 机器人自动点赞
|
||||
* 第一个赞在发布后1小时内
|
||||
* 第二个赞在第一个赞之后的24小时内
|
||||
*/
|
||||
@Scheduled(cron = "11 */1 * * * ?")
|
||||
public void autoLike() {
|
||||
// 第一次点赞: 第一个赞在发布后1小时内
|
||||
logger.info("first like: dynamic auto like start ================");
|
||||
int hourResult = 0;
|
||||
String hourKey = RedisKey.dynamic_wait_to_like_in_one_hour.getKey();
|
||||
List<Long> hourDynamicIdList = dynamicService.getDynamicIdFromLikeQueue(hourKey);
|
||||
if(CollectionUtils.isNotEmpty(hourDynamicIdList)) {
|
||||
for (Long dynamicId : hourDynamicIdList) {
|
||||
Dynamic dynamic = dynamicService.getDynamic(dynamicId);
|
||||
// 状态不对,不需要再点赞了
|
||||
if(dynamic == null
|
||||
|| DynamicStatusEnum.NOT_PASS.getValue().equals(dynamic.getStatus())
|
||||
|| DynamicStatusEnum.DELETE.getValue().equals(dynamic.getStatus())
|
||||
|| DynamicStatusEnum.UNSHELVE.getValue().equals(dynamic.getStatus())
|
||||
|| DynamicStatusEnum.NOT_PASS_MACHINE.getValue().equals(dynamic.getStatus())) {
|
||||
dynamicService.removeDynamicFormQueue(hourKey, dynamicId);
|
||||
continue;
|
||||
}
|
||||
int val = dynamicService.autoLikeByRobot(dynamicId, 1);
|
||||
if (val > 0) {
|
||||
// 点赞完成后,添加到第二个队列中,并从原来的队列中移除
|
||||
dynamicService.addToLikeInOneDayQueue(dynamicId, System.currentTimeMillis());
|
||||
dynamicService.removeDynamicFormQueue(hourKey, dynamicId);
|
||||
hourResult += val;
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info("first like: dynamic auto like end, record num:{} =================", hourResult);
|
||||
|
||||
// 第二次点赞: 第二个在第一次点赞后24小时内
|
||||
logger.info("second like: dynamic auto like start ================");
|
||||
int dayResult = 0;
|
||||
String dayKey = RedisKey.dynamic_wait_to_like_in_one_day.getKey();
|
||||
List<Long> dayDynamicIdList = dynamicService.getDynamicIdFromLikeQueue(dayKey);
|
||||
if(CollectionUtils.isNotEmpty(dayDynamicIdList)) {
|
||||
for (Long dynamicId : dayDynamicIdList) {
|
||||
Dynamic dynamic = dynamicService.getDynamic(dynamicId);
|
||||
// 状态不对,不需要再点赞了
|
||||
if(dynamic == null
|
||||
|| DynamicStatusEnum.NOT_PASS.getValue().equals(dynamic.getStatus())
|
||||
|| DynamicStatusEnum.DELETE.getValue().equals(dynamic.getStatus())
|
||||
|| DynamicStatusEnum.UNSHELVE.getValue().equals(dynamic.getStatus())
|
||||
|| DynamicStatusEnum.NOT_PASS_MACHINE.getValue().equals(dynamic.getStatus())) {
|
||||
dynamicService.removeDynamicFormQueue(dayKey, dynamicId);
|
||||
continue;
|
||||
}
|
||||
int val = dynamicService.autoLikeByRobot(dynamicId, 1);
|
||||
if (val > 0) {
|
||||
// 点赞完成后,从第二个队列中移除
|
||||
dynamicService.removeDynamicFormQueue(dayKey, dynamicId);
|
||||
dayResult += val;
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info("second like: dynamic auto like end, record num:{} =================", dayResult);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计动态相关数据
|
||||
* 统计前一天的数据
|
||||
*/
|
||||
@Scheduled(cron = "17 23 3 * * ?")
|
||||
public void dynamicDataStat() {
|
||||
Date now = new Date();
|
||||
Date yesterday = DateTimeUtil.addDays(now, -1);
|
||||
DynamicDataStatQuery query = DynamicDataStatQuery.builder()
|
||||
.startTime(DateTimeUtil.getBeginTimeOfDay(yesterday))
|
||||
.endTime(DateTimeUtil.getEndTimeOfDay(yesterday))
|
||||
.build();
|
||||
dynamicStatService.statDataForHistoryByDay(query);
|
||||
// 统计全部
|
||||
query.setWorldId(0L);
|
||||
dynamicStatService.statDataForHistoryByDay(query);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.model.FamilyApplyRecord;
|
||||
import com.accompany.business.service.family.FamilyApplyService;
|
||||
import com.accompany.core.service.base.BaseService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* @author yangming
|
||||
* @description 定时处理过期未处理申请
|
||||
* @date 2018/7/17 17:17
|
||||
*/
|
||||
//@Component
|
||||
public class FamilyApplyRecordExpiredTask extends BaseService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(FamilyApplyRecordExpiredTask.class);
|
||||
|
||||
@Autowired
|
||||
private FamilyApplyService familyApplyService;
|
||||
|
||||
@Scheduled(cron = "0 0/10 * * * *")
|
||||
public void cleanExpiredApplyRecords() {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
List<FamilyApplyRecord> familyApplyRecords = this.familyApplyService.getExpireApplyRecords();
|
||||
logger.info("cleanExpiredApplyRecords(), size={}", familyApplyRecords == null ? 0 : familyApplyRecords.size());
|
||||
|
||||
for (FamilyApplyRecord familyApplyRecord : familyApplyRecords) {
|
||||
executor.execute(() -> {
|
||||
this.familyApplyService.cleanFamilyApplyRecords(familyApplyRecord);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.firstpage.FirstPageRecommendRoomService;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
/**
|
||||
* 2 * @Author: zhuct
|
||||
* 3 * @Date: 2019/6/5 18:31
|
||||
* 4
|
||||
*/
|
||||
//@Component
|
||||
public class FirstPageTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FirstPageTask.class);
|
||||
@Autowired
|
||||
private FirstPageRecommendRoomService firstPageRecommendRoomService;
|
||||
|
||||
@Scheduled(cron = "0 */2 * * * ?")
|
||||
public void refreshRecommendRoomStatus() {
|
||||
// 更新推荐房间的状态
|
||||
logger.info("refreshRecommendRoomStatus start ================");
|
||||
firstPageRecommendRoomService.refreshRecommendRoomStatus();
|
||||
logger.info("refreshRecommendRoomStatus end =================");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新推荐中的房间缓存
|
||||
*/
|
||||
@Scheduled(cron = "0 */1 * * * ?")
|
||||
public void reloadRecommendCache() {
|
||||
logger.info("reloadRecommendCache start ==============");
|
||||
firstPageRecommendRoomService.reloadRecommendCacheByLabelType(Constant.FirstPageLabelType.MALE);
|
||||
firstPageRecommendRoomService.reloadRecommendCacheByLabelType(Constant.FirstPageLabelType.FEMALE);
|
||||
logger.info("reloadRecommendCache end ==============");
|
||||
|
||||
}
|
||||
|
||||
//@Scheduled(cron = "0 */3 * * * ?")
|
||||
//public void filterTabRoom() {
|
||||
// // 过滤 没有活人 全局隐藏 上锁的 tab房间
|
||||
// logger.info("filterTabRoom start ================");
|
||||
// firstPageTabService.filterTabRoom();
|
||||
// logger.info("filterTabRoom end =================");
|
||||
//}
|
||||
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.constant.FlowStatisEnum;
|
||||
import com.accompany.business.service.activity.ActYearCeremonyService;
|
||||
import com.accompany.business.service.flow.FlowStatisService;
|
||||
import com.accompany.business.vo.activity.ActYearCeremonyConfig;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class FlowStatisTask extends BaseTask {
|
||||
|
||||
@Autowired
|
||||
private FlowStatisService flowStatisticsService;
|
||||
@Autowired
|
||||
private ActYearCeremonyService actYearCeremonyService;
|
||||
|
||||
/**
|
||||
* 2021年度庆典 每天 00:10(12点预留以防定时器宕机) 分保存昨日流量数据
|
||||
*/
|
||||
@Scheduled(cron = "0 10 00,12 * * ?")
|
||||
public void yearCeremonyFlow() {
|
||||
log.info("FlowStatisTask.yearCeremonyFlow start ================");
|
||||
ActYearCeremonyConfig config = actYearCeremonyService.getActYearCeremonyConf();
|
||||
if(DateTimeUtil.isBetweenDate(new Date(), config.getStartTime(), config.getEndTime())){
|
||||
flowStatisticsService.statisYesterDayFlow(FlowStatisEnum.YEAR_CEREMONY);
|
||||
}
|
||||
log.info("FlowStatisTask.yearCeremonyFlow end ================");
|
||||
}
|
||||
}
|
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 文 件 名: GameMatchTask
|
||||
* 版 权:
|
||||
* 描 述: <描述>
|
||||
* 创建人: chenzhixiang
|
||||
* 创建时间: 2021/2/4
|
||||
* 修改人:
|
||||
* 修改内容:
|
||||
* 修改时间:
|
||||
*/
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.accompany.business.service.gamemange.GameManageBizService;
|
||||
import com.xuanyin.gamematch.model.GameManageInfo;
|
||||
import com.xuanyin.gamematch.model.GameManageQuickGameGroup;
|
||||
import com.xuanyin.gamematch.service.GameManageInfoService;
|
||||
import com.xuanyin.gamematch.service.GameManageQuickGameGroupService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <br>类描述: 比赛管理相关定时任务
|
||||
* <br>功能详细描述:
|
||||
*
|
||||
* @author chenzhixiang
|
||||
* @date [2021/2/4]
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class GameManageTask {
|
||||
|
||||
@Autowired
|
||||
private GameManageInfoService gameManageInfoService;
|
||||
@Autowired
|
||||
private GameManageBizService gameManageBizService;
|
||||
@Autowired
|
||||
private GameManageQuickGameGroupService gameManageQuickGameGroupService;
|
||||
|
||||
@Scheduled(cron = "0 */1 * * * ?")
|
||||
public void closeNotEnoughQuotaMath() {
|
||||
log.info("[GameManageTask closeNotEnoughQuotaMath]开始关闭未达到最低开赛人数的比赛");
|
||||
List<GameManageInfo> notEnoughQuotaMatches = gameManageInfoService.listNotEnoughQuotaMatch();
|
||||
if (CollectionUtil.isNotEmpty(notEnoughQuotaMatches)) {
|
||||
log.info("[closeNotEnoughQuotaMath]需要关闭的比赛数:{}", notEnoughQuotaMatches.size());
|
||||
notEnoughQuotaMatches.forEach(match -> {
|
||||
try {
|
||||
gameManageBizService.closeNotEnoughQuotaMath(match);
|
||||
} catch (Exception e) {
|
||||
log.error("[closeNotEnoughQuotaMath]关闭比赛异常。matchId:" + match.getMatchId(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 */1 * * * ?")
|
||||
public void sendEnterStartMsg() {
|
||||
log.info("[sendEnterStartMsg]开始发送开始进房消息任务");
|
||||
List<GameManageInfo> needSendEnterStartMsgMatches = gameManageInfoService.listNeedSendEnterStartMsgMatch();
|
||||
if (CollectionUtil.isNotEmpty(needSendEnterStartMsgMatches)) {
|
||||
log.info("[sendEnterStartMsg]需要发送开始进房消息比赛数:{}", needSendEnterStartMsgMatches.size());
|
||||
needSendEnterStartMsgMatches.forEach(match -> {
|
||||
try {
|
||||
gameManageBizService.sendEnterStartMsg(match);
|
||||
} catch (Exception e) {
|
||||
log.error("[sendEnterStartMsg]发送开始进房消息。matchId:" + match.getMatchId(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动流局快速赛
|
||||
*/
|
||||
@Scheduled(cron = "0/30 * * * * ?")
|
||||
public void dismissQuickGame() {
|
||||
log.info("[dismissQuickGame]开始自动流局未达到开赛要求的快速赛");
|
||||
List<GameManageInfo> gameList = gameManageInfoService.listNeedDismissQuickGame();
|
||||
if (CollectionUtil.isNotEmpty(gameList)) {
|
||||
log.info("[dismissQuickGame]需要流局的比赛数:{}", gameList.size());
|
||||
gameList.forEach(match -> {
|
||||
try {
|
||||
// 流局
|
||||
gameManageBizService.dismissQuickGame(match, false);
|
||||
// 创建新的场次
|
||||
Integer remainCount = gameManageQuickGameGroupService.countGroupRemainGame(match.getMatchGroupId());
|
||||
if (null == remainCount || remainCount > 0) {
|
||||
log.info("[dismissQuickGame]自动创建下一场比赛:quickGameGroupId {}", match.getMatchGroupId());
|
||||
gameManageInfoService.createQuickGameMatch(gameManageQuickGameGroupService.getById(match.getMatchGroupId()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[dismissQuickGame]自动流局异常。matchId:" + match.getMatchId(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速赛开始比赛后创建新的一轮快速赛
|
||||
*/
|
||||
@Scheduled(cron = "0/30 * * * * ?")
|
||||
public void createNewQuickGameWhenGameStart() {
|
||||
log.info("[createNewQuickGameWhenGameStart]开始自动创建下一场比赛的快速赛");
|
||||
List<GameManageQuickGameGroup> groupList = gameManageQuickGameGroupService.listWithoutQuotaingGameGroup();
|
||||
if (CollectionUtil.isNotEmpty(groupList)) {
|
||||
log.info("[createNewQuickGameWhenGameStart]自动创建下一场比赛:{}", groupList.size());
|
||||
groupList.forEach(group -> {
|
||||
try {
|
||||
// 创建新的场次
|
||||
Integer remainCount = gameManageQuickGameGroupService.countGroupRemainGame(group.getGroupId());
|
||||
if (null == remainCount || remainCount > 0) {
|
||||
log.info("[createNewQuickGameWhenGameStart]自动创建下一场比赛:quickGameGroupId {}", group.getGroupId());
|
||||
gameManageInfoService.createQuickGameMatch(group);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[createNewQuickGameWhenGameStart]自动创建下一场比赛。quickGameGroupId:" + group.getGroupId(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 文 件 名: GameMatchTask
|
||||
* 版 权:
|
||||
* 描 述: <描述>
|
||||
* 创建人: chenzhixiang
|
||||
* 创建时间: 2021/2/4
|
||||
* 修改人:
|
||||
* 修改内容:
|
||||
* 修改时间:
|
||||
*/
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.accompany.business.model.match.GameMatchInfo;
|
||||
import com.accompany.business.service.match.GameMatchInfoService;
|
||||
import com.accompany.business.service.match.GameMatchService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <br>类描述: 比赛管理相关定时任务
|
||||
* <br>功能详细描述:
|
||||
*
|
||||
* @author chenzhixiang
|
||||
* @date [2021/2/4]
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class GameMatchTask {
|
||||
|
||||
@Autowired
|
||||
private GameMatchInfoService gameMatchInfoService;
|
||||
@Autowired
|
||||
private GameMatchService gameMatchService;
|
||||
|
||||
@Scheduled(cron = "0 */1 * * * ?")
|
||||
public void closeNotEnoughQuotaMath() {
|
||||
log.info("[closeNotEnoughQuotaMath]开始关闭未达到最低开赛人数的比赛");
|
||||
List<GameMatchInfo> notEnoughQuotaMatches = gameMatchInfoService.listNotEnoughQuotaMatch();
|
||||
if (CollectionUtil.isNotEmpty(notEnoughQuotaMatches)) {
|
||||
log.info("[closeNotEnoughQuotaMath]需要关闭的比赛数:{}", notEnoughQuotaMatches.size());
|
||||
notEnoughQuotaMatches.forEach(match -> {
|
||||
try {
|
||||
gameMatchService.closeNotEnoughQuotaMath(match);
|
||||
} catch (Exception e) {
|
||||
log.error("[closeNotEnoughQuotaMath]关闭比赛异常。matchId:" + match.getMatchId(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 */1 * * * ?")
|
||||
public void sendEnterStartMsg() {
|
||||
log.info("[sendEnterStartMsg]开始发送开始进房消息任务");
|
||||
List<GameMatchInfo> needSendEnterStartMsgMatches = gameMatchInfoService.listNeedSendEnterStartMsgMatch();
|
||||
if (CollectionUtil.isNotEmpty(needSendEnterStartMsgMatches)) {
|
||||
log.info("[sendEnterStartMsg]需要发送开始进房消息比赛数:{}", needSendEnterStartMsgMatches.size());
|
||||
needSendEnterStartMsgMatches.forEach(match -> {
|
||||
try {
|
||||
gameMatchService.sendEnterStartMsg(match);
|
||||
} catch (Exception e) {
|
||||
log.error("[sendEnterStartMsg]发送开始进房消息。matchId:" + match.getMatchId(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.mybatismapper.UsersMapperExpend;
|
||||
import com.accompany.business.service.user.UserGiftWallService;
|
||||
import com.accompany.core.model.UsersExample;
|
||||
import com.accompany.core.mybatismapper.UsersMapper;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author qiudonglin
|
||||
* @description 定时统计用户是否完成礼物成就的收集
|
||||
* @date 2020/3/6/0006
|
||||
*/
|
||||
//@Component
|
||||
public class GiftAchievementTask extends BaseTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GiftAchievementTask.class);
|
||||
|
||||
@Autowired
|
||||
private UsersMapper usersMapper;
|
||||
@Autowired
|
||||
private UsersMapperExpend usersMapperExpend;
|
||||
@Autowired
|
||||
private UserGiftWallService userGiftWallService;
|
||||
|
||||
@Scheduled(cron = "0 0 11,23 * * *")
|
||||
public void statisticsUserGiftAchievement() {
|
||||
logger.info("statisticsUserGiftAchievement start ===============");
|
||||
|
||||
UsersExample usersExample = new UsersExample();
|
||||
usersExample.createCriteria().andDefUserNotEqualTo((byte) 3);
|
||||
long count = usersMapper.countByExample(usersExample);
|
||||
logger.info("总用户数:{}", count);
|
||||
int limit = 500;
|
||||
for (int i = 0; i < count; i = i + limit) {
|
||||
List<Long> list = usersMapperExpend.getUidByPage(i, limit);
|
||||
logger.info("offset:{}", i);
|
||||
list.forEach(uid -> userGiftWallService.updateUserAchievementTypeRecord(uid));
|
||||
}
|
||||
|
||||
logger.info("statisticsUserGiftAchievement finish ===============");
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.message.GiftMessage;
|
||||
import com.accompany.business.service.gift.GiftMessageService;
|
||||
import com.accompany.business.service.gift.GiftService;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class GiftTask extends BaseTask {
|
||||
|
||||
@Autowired
|
||||
private GiftMessageService giftMessageService;
|
||||
/**
|
||||
* 重新消费队列的消息
|
||||
*/
|
||||
@Scheduled(cron = "0 */5 * * * ?")
|
||||
public void retryGiftQueue() {
|
||||
log.info("retryGiftQueue start ...");
|
||||
Map<String, String> map = jedisService.hgetAll(RedisKey.mq_gift_status.getKey());
|
||||
if (map == null || map.size() == 0) {
|
||||
return;
|
||||
}
|
||||
Set<String> keySet = map.keySet();
|
||||
long curTime = System.currentTimeMillis();
|
||||
long gapTime = 1000 * 60 * 10; // 十分钟内没被消费
|
||||
|
||||
for (String key : keySet) {
|
||||
try {
|
||||
String val = map.get(key);
|
||||
GiftMessage giftMessage = gson.fromJson(val, GiftMessage.class);
|
||||
if (curTime - giftMessage.getMessTime() > gapTime) {
|
||||
giftMessageService.handleGiftMessage(giftMessage);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("retryGiftQueue error", e);
|
||||
}
|
||||
}
|
||||
log.info("retryGiftQueue end ...");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private GiftService giftService;
|
||||
|
||||
/**
|
||||
* 礼物上线定时任务
|
||||
* 每分钟的第1s执行一次
|
||||
*/
|
||||
@Scheduled(cron = "1 */1 * * * ?")
|
||||
public void GiftOnline() {
|
||||
log.info("onLine gift task start");
|
||||
int num = giftService.onLineAllInTimeGift();
|
||||
log.info("onLine gift task end, onLine gift num = {} ", num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 礼物下线定时任务
|
||||
* 每分钟的第1s执行一次
|
||||
*/
|
||||
@Scheduled(cron = "1 */1 * * * ?")
|
||||
public void GiftOffline() {
|
||||
log.info("offLine gift task start");
|
||||
int num = giftService.offLineAllOutTimeGift();
|
||||
log.info("offLine gift task end, offLine gift num = {} ", num);
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.model.HallOperateRecord;
|
||||
import com.accompany.business.mybatismapper.HallOperateRecordMapperExpand;
|
||||
import com.accompany.core.service.base.BaseService;
|
||||
import com.accompany.business.service.hall.HallManageService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* 处理模厅 邀请、申请未处理过期记录
|
||||
*/
|
||||
//@Component
|
||||
public class HallRecordExpiredTask extends BaseService {
|
||||
@Autowired
|
||||
private HallManageService hallManageService;
|
||||
@Autowired
|
||||
private HallOperateRecordMapperExpand hallOperateRecordMapperExpand;
|
||||
|
||||
@Scheduled(cron = "0 */15 * * * *")
|
||||
public void cleanExpiredApplyRecords() {
|
||||
//更新所有未处理的失效邀请和申请记录
|
||||
int result = hallOperateRecordMapperExpand.dealInviteApplyEffectRecord();
|
||||
logger.info("dealInviteApplyEffectRecord size={}",result);
|
||||
//处理普通成员的退出申请 14天自动退出
|
||||
List<HallOperateRecord> quitEffectRecord = hallOperateRecordMapperExpand.getQuitEffectRecord();
|
||||
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
for (HallOperateRecord record : quitEffectRecord) {
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
hallManageService.delEffectQuitRecord(record);
|
||||
} catch (Exception e) {
|
||||
logger.error("delEffectQuitRecord error,recordId={},errorMsg={}",record.getId(), e.getMessage());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.headwear.HeadwearService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author yangziwen
|
||||
* @description
|
||||
* @date 2018/5/16 20:30
|
||||
*/
|
||||
@Component
|
||||
public class HeadwearTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(HeadwearTask.class);
|
||||
|
||||
@Autowired
|
||||
private HeadwearService headwearService;
|
||||
|
||||
@Scheduled(cron = "0 0 1 * * ?")
|
||||
public void clearExpireUserHeadwear() {
|
||||
logger.info("BEGIN CLEAN EXPIRED USER HEADWEAR...");
|
||||
this.headwearService.cleanExpiredUserHeadwear();
|
||||
logger.info("END CLEAN EXPIRED USER HEADWEAR...");
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 30 12 * * ?")
|
||||
public void notifyExpiringUserHeadwear() {
|
||||
logger.info("BEGIN NOTIFY USER HEADWEAR EXPIRING...");
|
||||
this.headwearService.notifyExpiringUserHeadwear();
|
||||
logger.info("END NOTIFY USER HEADWEAR EXPIRING...");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,146 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.model.FaceJson;
|
||||
import com.accompany.business.service.room.FaceJsonService;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.BlankUtil;
|
||||
import com.accompany.core.model.Room;
|
||||
import com.accompany.core.mybatismapper.RoomMapperExpand;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class HomeTask extends BaseTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(HomeTask.class);
|
||||
public static volatile boolean isDoHomeDataJob = false;
|
||||
|
||||
@Autowired
|
||||
private RoomMapperExpand roomMapperExpand;
|
||||
@Autowired
|
||||
private FaceJsonService faceJsonService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 定时刷新首页数据, 2min
|
||||
*/
|
||||
// @Scheduled(cron = "0 */2 * * * ?")
|
||||
// public void doHomeDataJob(){
|
||||
// try {
|
||||
// isDoHomeDataJob = true;
|
||||
// logger.info("HomeDataJob doHomeDataJob start.....");
|
||||
// homeService.doHomeDataJob();
|
||||
// logger.info("HomeDataJob doHomeDataJob finish.....");
|
||||
// } catch (Exception e) {
|
||||
// logger.error("doHomeDataJob error,", e);
|
||||
// }finally {
|
||||
// isDoHomeDataJob = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 从配置池中获取房间列表,随机排序后保存到缓存;
|
||||
* 首页加载时从缓存中获取,分页返回
|
||||
*/
|
||||
//@Scheduled(cron = "0 */2 * * * ?")
|
||||
public void cacheRandomRoom(){
|
||||
try {
|
||||
List<Room> list = roomMapperExpand.selectPoolRooms();
|
||||
if (BlankUtil.isBlank(list)) {
|
||||
jedisService.set(RedisKey.home_room_random.getKey(), "[]");
|
||||
return;
|
||||
}
|
||||
// 打乱列表的排序
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
int pos = random.nextInt(list.size());
|
||||
Room curRoom = list.get(i);
|
||||
// 当前位置的元素换成随机位置上的元素
|
||||
list.set(i, list.get(pos));
|
||||
list.set(pos, curRoom);
|
||||
}
|
||||
jedisService.set(RedisKey.home_room_random.getKey(), gson.toJson(list));
|
||||
} catch (Exception e) {
|
||||
logger.error("cacheRandomRoom error", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存当前有效的表情JSON
|
||||
*/
|
||||
@Scheduled(cron = "0 */5 * * * ?")
|
||||
public void cacheFaceJson() {
|
||||
logger.info("cacheFaceJson start ============");
|
||||
int tryTime = 0;
|
||||
FaceJson faceJson = null;
|
||||
while (tryTime++ < 3 && faceJson == null) {
|
||||
try {
|
||||
faceJson = faceJsonService.getFaceJsonFromDB();
|
||||
if (faceJson != null) {
|
||||
jedisService.set(RedisKey.face_json.getKey(), gson.toJson(faceJson));
|
||||
break;
|
||||
}
|
||||
TimeUnit.SECONDS.sleep(2);
|
||||
} catch (Exception e) {
|
||||
logger.error("cacheFaceJson error", e);
|
||||
}
|
||||
}
|
||||
logger.info("cacheFaceJson finish ============");
|
||||
}
|
||||
|
||||
///**
|
||||
// * 五分钟缓存一次星推荐房间数据
|
||||
// */
|
||||
//@Scheduled(cron = "0 */5 * * * ?")
|
||||
//public void cacheHotRecomRoom(){
|
||||
// logger.info("cacheHotRecomRoom() start ===============");
|
||||
// try {
|
||||
// /* 2019.02.22 V4 首页房间改版 home_hot_manual_recomm表没有用了
|
||||
// List<HomeRoomFlowPeriod> homeRoomFlowPeriodList = homeService.getHomeHotManualRecommList();
|
||||
// if (!BlankUtil.isBlank(homeRoomFlowPeriodList)) {
|
||||
// List<RoomVo> recomRoom = homeService.convertHomeRoomToRoomVo(homeRoomFlowPeriodList);
|
||||
// if (!BlankUtil.isBlank(recomRoom)) {
|
||||
// jedisService.set(RedisKey.home_hot_recom.getKey(), gson.toJson(recomRoom));
|
||||
// }else{
|
||||
// jedisService.set(RedisKey.home_hot_recom.getKey(),"[]");
|
||||
// }
|
||||
// }else{
|
||||
// jedisService.set(RedisKey.home_hot_recom.getKey(),"[]");
|
||||
// }*/
|
||||
// List<RoomVo> recomRoom = homeV2Service.genRecommendRoomPeriodData();
|
||||
// if (!BlankUtil.isBlank(recomRoom)) {
|
||||
// jedisService.set(RedisKey.home_hot_recom.getKey(), gson.toJson(recomRoom));
|
||||
// }else{
|
||||
// jedisService.set(RedisKey.home_hot_recom.getKey(),"[]");
|
||||
// }
|
||||
// }catch(Exception e){
|
||||
// logger.error("cacheHotRecomRoom() error",e);
|
||||
// }
|
||||
// logger.info("cacheHotRecomRoom() finishi =============");
|
||||
//}
|
||||
|
||||
/*
|
||||
* 每天18点缓存新起之秀数据,24点过期
|
||||
*/
|
||||
@Scheduled(cron = " 0 0 18 * * ?")
|
||||
public void cacheNewStarShowData() {
|
||||
logger.info("cacheNewStarShowData() start ============");
|
||||
try {
|
||||
jedisService.set(RedisKey.new_star_show_segment.getKey(), "true", 6 * 3600);
|
||||
} catch (Exception e) {
|
||||
logger.error("cacheNewStarShowData() error", e);
|
||||
}
|
||||
logger.info("cacheNewStarShowData() finish ============");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.linearlypool.LinearlyPrizePoolService;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class LinearlyPoolTask {
|
||||
|
||||
@Autowired
|
||||
private LinearlyPrizePoolService linearlyPrizePoolService;
|
||||
|
||||
@Scheduled(cron = "*/30 * * * * *")
|
||||
public void createPoolLine() {
|
||||
log.info("开始检查是否需要创建奖品线任务");
|
||||
try {
|
||||
linearlyPrizePoolService.createPoolLineIfNecessary();
|
||||
} catch (Exception e) {
|
||||
log.error("检查是否需要创建奖品线出错", e);
|
||||
}
|
||||
log.info("完成检查是否需要创建奖品线任务");
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 */12 * * * *")
|
||||
public void clearDrawOutPoolLine() {
|
||||
log.info("开始清理已抽取完的奖品线任务");
|
||||
try {
|
||||
linearlyPrizePoolService.clearDrawOutPoolLine();
|
||||
} catch (Exception e) {
|
||||
log.error("清理已抽取完的奖品线出错", e);
|
||||
}
|
||||
log.info("完成清理已抽取完的奖品线任务");
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理过期的linearly_prize_pool_draw_line_item_day中数据
|
||||
*/
|
||||
@Scheduled(cron = "0 0 9 * * ?")
|
||||
public void clearExpiredDayDrawRecordDatas() {
|
||||
try {
|
||||
log.info("开始清理过期的linearly_prize_pool_draw_line_item_day中数据");
|
||||
linearlyPrizePoolService.clearExpiredDrawLineDatas();
|
||||
log.info("结束清理过期的linearly_prize_pool_draw_line_item_day中数据");
|
||||
} catch (Exception e) {
|
||||
log.error("清理过期的linearly_prize_pool_draw_line_item_day中数据失败...", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 定点播报
|
||||
*/
|
||||
@Scheduled(cron = "${scheduler.linealy-pool.static-report-cron}")
|
||||
public void reportTotalStatisticsInHour() {
|
||||
try {
|
||||
log.info("开始定点播报");
|
||||
Date endTime = DateTimeUtil.getCurrHourTimeV2();
|
||||
Date startTime = DateTimeUtil.getNextHour(endTime, -1);
|
||||
linearlyPrizePoolService.reportTotalStatisticsByTime(startTime, endTime);
|
||||
log.info("结束定点播报");
|
||||
} catch (Exception e) {
|
||||
log.error("定点播报失败...", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,94 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.model.TopLine;
|
||||
import com.accompany.business.model.TopLineExample;
|
||||
import com.accompany.business.mybatismapper.TopLineMapper;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.core.service.common.JedisLockService;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*定时加载定时发布的 头条
|
||||
*/
|
||||
//@Component
|
||||
public class LoadFixedToplineTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(LoadFixedToplineTask.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
private TopLineMapper topLineMapper;
|
||||
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
|
||||
@Autowired
|
||||
private JedisLockService jedisLockService;
|
||||
|
||||
|
||||
/**
|
||||
* 每两分钟往 头条缓存里写入数据
|
||||
*/
|
||||
@Scheduled(cron = "0 0/2 * * * *")
|
||||
public void loadingJob() {
|
||||
logger.info("LOADING TOPLINE JOB");
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
//加锁获取状态
|
||||
String lock = jedisLockService.lock(RedisKey.top_line_update.getKey(),10,10000);
|
||||
try {
|
||||
|
||||
if(lock != null) {
|
||||
String value = jedisService.get(RedisKey.top_line_update_time.getKey());
|
||||
long last = 0;
|
||||
if(value == null) {
|
||||
try {
|
||||
last = Long.valueOf(value);
|
||||
}catch (Exception e) {
|
||||
logger.error("redis 里的时间存储错误");
|
||||
}
|
||||
}
|
||||
|
||||
TopLineExample example = new TopLineExample();
|
||||
example.setOffset(0);
|
||||
example.setLimit(100);
|
||||
|
||||
example.createCriteria().andIsPublishEqualTo((byte)1)
|
||||
.andPublishTimeBetween(last, now)
|
||||
.andIsPublishEqualTo((byte)1);
|
||||
example.setOrderByClause("publish_time DESC");
|
||||
|
||||
List<TopLine> toplines = topLineMapper.selectByExample(example);
|
||||
if(toplines.size() > 0) {
|
||||
Map<String, Double> map = new HashMap<>();
|
||||
for(int i = 0; i < toplines.size() ;i++ ) {
|
||||
TopLine topLine = toplines.get(i);
|
||||
String string = JSONObject.toJSON(topLine).toString();
|
||||
map.put(string, -topLine.getPublishTime().doubleValue());
|
||||
}
|
||||
|
||||
jedisService.zaddLimit(RedisKey.top_line_key.getKey(), map, 100);
|
||||
}
|
||||
|
||||
jedisService.set(RedisKey.top_line_update_time.getKey(),String.valueOf(now));
|
||||
}
|
||||
}finally {
|
||||
jedisLockService.unlock(RedisKey.top_line_update.getKey(), lock);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.MasterApprenticeService;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by chucheng on 2019/2/15.
|
||||
* 师徒任务过期
|
||||
*/
|
||||
//@Component
|
||||
public class MentorTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MentorTask.class);
|
||||
|
||||
@Autowired
|
||||
private MasterApprenticeService service;
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
|
||||
@Scheduled(cron = "0 0 * * * ?")
|
||||
public void execute()
|
||||
{
|
||||
try {
|
||||
logger.info("开始扫描师徒任务=========");
|
||||
this.service.bathExpireProgress(7L);
|
||||
logger.info("完成扫描师徒任务==========");
|
||||
} catch (Exception e) {
|
||||
logger.error("扫描师徒任务出错...", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 师傅关注徒弟5分钟徒弟没有响应
|
||||
* 给师傅发送通知
|
||||
*/
|
||||
@Scheduled(cron = "*/30 * * * * ?")
|
||||
public void sendTipsToMaster(){
|
||||
logger.info("sendTipsToMaster(), task start");
|
||||
try{
|
||||
Map<String,String> masterTask = jedisService.hgetAll(RedisKey.master_apprentice_like.getKey());
|
||||
if(masterTask.isEmpty()){
|
||||
return ;
|
||||
}
|
||||
for(Map.Entry<String,String> entry : masterTask.entrySet()){
|
||||
Long millions = Long.valueOf(entry.getValue());
|
||||
if(System.currentTimeMillis()-millions >= 300000){
|
||||
String key = entry.getKey();
|
||||
String[] uids = key.split("_");
|
||||
String gender = this.service .getTargetGenderTag(Long.valueOf(uids[0]));
|
||||
this.service.sendResultTips(Long.valueOf(uids[1]),Long.valueOf(uids[0]),
|
||||
"嗷嗷,"+gender+"好像离开了,我们找下个"+gender+"求抱抱吧?",
|
||||
Constant.DefineProtocol.CUSTOM_MSG_MENTORING_RELATIONSHIP,
|
||||
Constant.DefineProtocol.CUSTOM_MSG_SUB_MENTORING_RELATIONSHIP_MISSION_FAIL_TIPS);
|
||||
this.jedisService.hdel(RedisKey.master_apprentice_like.getKey(),key);
|
||||
}
|
||||
}
|
||||
}catch(Exception e) {
|
||||
logger.error("sendTipsToMaster error", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,79 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.accompany.business.model.miniGame.MiniGameInviteRecord;
|
||||
import com.accompany.business.mybatismapper.miniGame.MiniGameInviteRecordMapper;
|
||||
import com.accompany.business.service.miniGame.MiniGameInviteRecordService;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.core.service.user.UsersBaseService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Component
|
||||
public class MiniGameDenyTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MiniGameDenyTask.class);
|
||||
|
||||
private static final Integer STEP_LEN = 500;
|
||||
|
||||
@Autowired
|
||||
private MiniGameInviteRecordMapper miniGameInviteRecordMapper;
|
||||
@Autowired
|
||||
private MiniGameInviteRecordService miniGameInviteRecordService;
|
||||
@Autowired
|
||||
private UsersBaseService usersBaseService;
|
||||
|
||||
/**
|
||||
* 每2分钟执行一次
|
||||
*/
|
||||
@Scheduled(cron = "0 */2 * * * ?")
|
||||
public void endCrossRoomPk() {
|
||||
logger.info("begin miniGameDenyTask =============================================================");
|
||||
|
||||
//查询1小时以内未结束的PK
|
||||
Integer counter = 0;
|
||||
Integer start = 0;
|
||||
Integer len = STEP_LEN;
|
||||
|
||||
List<MiniGameInviteRecord> recordList = miniGameInviteRecordMapper.getOverdueDenyInviteList(start, len);
|
||||
|
||||
while (!CollectionUtil.isEmpty(recordList)) {
|
||||
for (MiniGameInviteRecord miniGameInviteRecord : recordList) {
|
||||
try {
|
||||
if (!Constant.MiniGameInviteState.wait.equals(miniGameInviteRecord.getState())) continue;
|
||||
|
||||
int num = miniGameInviteRecordService.updateInviteState(miniGameInviteRecord.getId(), Constant.MiniGameInviteState.deny);
|
||||
if (num == 0) return;
|
||||
|
||||
if (ObjectUtil.isNull(miniGameInviteRecord)) return;
|
||||
|
||||
logger.info("执行小游戏{}自动拒绝消息发送", miniGameInviteRecord.getId());
|
||||
//miniGameInviteRecordService.sendDenyMsg(miniGameInviteRecord.getRoomUid(), miniGameInviteRecord.getUid());
|
||||
|
||||
Users replyUsers = usersBaseService.getUsersByUid(miniGameInviteRecord.getUid());
|
||||
if (ObjectUtil.isNull(replyUsers)) return;
|
||||
String denyMsg = String.format(Constant.MiniGameConstant.deny_msg, replyUsers.getNick());
|
||||
miniGameInviteRecordService.replyMsg(miniGameInviteRecord, denyMsg, false);
|
||||
|
||||
}catch(Exception e){
|
||||
logger.info("小游戏邀请{}自动拒绝任务异常{}", miniGameInviteRecord.getId(), e.getMessage());
|
||||
logger.error("execute miniGameDenyTask error,error={}",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
counter++;
|
||||
start = STEP_LEN * counter;
|
||||
recordList = miniGameInviteRecordMapper.getOverdueDenyInviteList(start, len);
|
||||
}
|
||||
|
||||
logger.info("end miniGameDenyTask =============================================================");
|
||||
}
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.noble.NobleUsersService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
//@Component
|
||||
public class NobleTask extends BaseTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(NobleTask.class);
|
||||
|
||||
@Autowired
|
||||
private NobleUsersService nobleUsersService;
|
||||
|
||||
|
||||
/**
|
||||
* 清除过期的贵族,凌晨10分和15分
|
||||
*/
|
||||
@Scheduled(cron = "0 10,15 0 * * ?")
|
||||
public void clearExpireNoble() {
|
||||
logger.info("clearExpireNoble start ===============");
|
||||
nobleUsersService.releaseAllExpireNoble();
|
||||
logger.info("clearExpireNoble finish ===============");
|
||||
}
|
||||
|
||||
/**
|
||||
* 提醒快过期贵族用户, 凌晨20分
|
||||
*/
|
||||
@Scheduled(cron = "0 20 12 * * ?")
|
||||
public void sendNoticeNoble() {
|
||||
logger.info("sendNoticeNoble start ===============");
|
||||
nobleUsersService.sendWillExpireNotice();
|
||||
logger.info("sendNoticeNoble finish ===============");
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果贵族过期的用户之前的贵族没有过期
|
||||
* 恢复之前的贵族
|
||||
*/
|
||||
@Scheduled(cron = "* */10 * * * ?")
|
||||
public void restoreUserNoble(){
|
||||
logger.info("restoreUserNoble start ===============");
|
||||
nobleUsersService.restoreUserNoble();
|
||||
logger.info("restoreUserNoble finish ==============");
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除已经过期的体验卡
|
||||
*/
|
||||
@Scheduled(cron = "* * 0/1 * * ?")
|
||||
public void cleanExpire(){
|
||||
logger.info("cleanExpire start ===============");
|
||||
nobleUsersService.cleanExpire();
|
||||
logger.info("cleanExpire finish ==============");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String version = "2.3.2";
|
||||
String replace = version.replace(".", "");
|
||||
int versionInt = Integer.parseInt(replace);
|
||||
if(versionInt<230){
|
||||
System.out.println("版本过低,请升级版本号");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.user.UsersParentModeService;
|
||||
import com.accompany.core.util.StringUtils;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 青少年模式 限制时间段进房
|
||||
* 0点--扫描所有在房间的青少年模式的用户, 写进redis中, 自定义消息发给客户端,由客户端踢出房间
|
||||
* 再次进房或者开房判断是否可以进入
|
||||
* --如果中间关闭青少年模式, 清除限制
|
||||
* 6点--清除数据
|
||||
* Created by liuyang on 2019/8/6.
|
||||
*/
|
||||
@Component
|
||||
public class ParentModeTask extends BaseTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ParentModeTask.class);
|
||||
|
||||
@Autowired
|
||||
private UsersParentModeService usersParentModeService;
|
||||
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
public void scanParentMode() {
|
||||
String parentSwitch = jedisService.get(RedisKey.parent_task_switch.getKey());
|
||||
if (StringUtils.isBlank(parentSwitch)) {
|
||||
parentSwitch = "1";
|
||||
}
|
||||
logger.info("----------scanParentMode start----------");
|
||||
if (parentSwitch.equalsIgnoreCase("1")) {
|
||||
usersParentModeService.pushParentModel();
|
||||
}
|
||||
logger.info("----------scanParentMode finish----------");
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 6 * * ?")
|
||||
public void cleanParentMode() {
|
||||
logger.info("----------cleanParentMode start----------");
|
||||
usersParentModeService.cleanParentModel();
|
||||
logger.info("----------cleanParentMode finish----------");
|
||||
}
|
||||
|
||||
//0点清除充值限额
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
public void cleanChargeLimit() {
|
||||
logger.info("----------cleanChargeLimit start----------");
|
||||
usersParentModeService.cleanChargeLimit();
|
||||
logger.info("----------cleanChargeLimit finish----------");
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.room.PermitRoomTimeService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class PermitRoomTimeTask extends BaseTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PermitRoomTimeTask.class);
|
||||
|
||||
@Autowired
|
||||
private PermitRoomTimeService permitRoomTimeService;
|
||||
|
||||
/**
|
||||
* 每隔半个钟检查一次牌照房
|
||||
*/
|
||||
@Scheduled(cron = "0 0/30 * * * ?")
|
||||
public void checkPermitRoomTime() {
|
||||
logger.info("checkPermitRoomTime start ===============");
|
||||
permitRoomTimeService.checkPermitRoomTime();
|
||||
logger.info("checkPermitRoomTime finish ===============");
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.prettyno.PrettyNumberService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Created by PaperCut on 2018/8/20.
|
||||
*/
|
||||
@Component
|
||||
public class PrettyNumberTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(PrettyNumberTask.class);
|
||||
|
||||
@Autowired
|
||||
private PrettyNumberService prettyNumberService;
|
||||
|
||||
@Scheduled(cron = "0 */30 * * * ?")
|
||||
public void scanPrettyNo()
|
||||
{
|
||||
try {
|
||||
logger.info("开始扫描靓号=========");
|
||||
this.prettyNumberService.scanExpiredPretty();
|
||||
logger.info("完成扫描靓号==========");
|
||||
} catch (Exception e) {
|
||||
logger.error("扫描靓号出错...", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.signweb.PrizeGoldPoolService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
|
||||
/**
|
||||
* 金币奖池定时器
|
||||
*/
|
||||
//@Component
|
||||
public class PrizeGoldPoolTask extends BaseTask implements ApplicationContextAware {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PrizeGoldPoolTask.class);
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
PrizeGoldPoolService prizeGoldPoolService;
|
||||
|
||||
/**
|
||||
* 0点更新奖池金额,更新奖池奖品的金币数量总计与被抽中数量总计
|
||||
*/
|
||||
@Scheduled(cron = "1 0 0 * * ?")
|
||||
public void refreshPrizeUseNum(){
|
||||
logger.info("refreshPrizeUseNum() start ========");
|
||||
|
||||
try {
|
||||
prizeGoldPoolService.goldNumIsUpdate();
|
||||
prizeGoldPoolService.updateGoldNumTotalAndUsePrizeNumTotal();
|
||||
} catch (Exception e) {
|
||||
logger.error("refreshPrizeUseNum error...",e);
|
||||
}
|
||||
logger.info("refreshPrizeUseNum() finish ========");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.recommend.RecommendService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
/**
|
||||
* Created by PaperCut on 2019/1/4.
|
||||
* 房间推荐业务定时器
|
||||
*/
|
||||
//@Component
|
||||
public class RecommendTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(RecommendTask.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
private RecommendService recommendService;
|
||||
/**
|
||||
* 每个一小时重新刷新推荐房a
|
||||
*/
|
||||
@Scheduled(cron = "0 0 0/1 * * ? ")
|
||||
public void refreshRecomCache() {
|
||||
// 更新推荐房记录的状态
|
||||
logger.info("refresh recommend cache start ================");
|
||||
recommendService.reloadRecomRoom();
|
||||
logger.info("refresh recommend cache to cache end =================");
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描用户过期的推荐卡
|
||||
*/
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
public void scanCardExpired() {
|
||||
logger.info("Scan expired recommend card start ==============");
|
||||
recommendService.scanExpired();
|
||||
logger.info("Scan expired recommend card end ==============");
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.core.model.channel.ChannelContentPartition;
|
||||
import com.accompany.core.service.channel.ChannelContentPartitionService;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 渠道内容定时器
|
||||
*/
|
||||
@Component
|
||||
public class RefreshCurrentTypeChannelTask extends BaseTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RefreshCurrentTypeChannelTask.class);
|
||||
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
@Autowired
|
||||
private ChannelContentPartitionService channelContentPartitionService;
|
||||
|
||||
|
||||
/**
|
||||
* 每日5点刷新
|
||||
*/
|
||||
@Scheduled(cron = "0 0 5 * * ?")
|
||||
public void execute() throws Exception {
|
||||
logger.info("======================================刷新当日用户类型对应的渠道缓存开始======================================");
|
||||
if (!jedisService.exits(RedisKey.channel_content_record.getKey())) {
|
||||
channelContentPartitionService.initChannelContentCache();
|
||||
}
|
||||
|
||||
Map<String, String> resultMap = jedisService.hgetAll(RedisKey.channel_content_record.getKey());
|
||||
if (MapUtil.isEmpty(resultMap)) {
|
||||
jedisService.del(RedisKey.current_day_new_user.getKey());
|
||||
return;
|
||||
}
|
||||
|
||||
List<ChannelContentPartition> channelList = resultMap.entrySet().stream()
|
||||
.map(entry -> gson.fromJson(entry.getValue(), ChannelContentPartition.class)).filter(channelContentPartition -> Constant.ChannelUserType.current_day_user.equals(channelContentPartition.getUserType()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (CollectionUtils.isEmpty(channelList)) {
|
||||
jedisService.del(RedisKey.current_day_new_user.getKey());
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取对应渠道注册的所有新用户
|
||||
List<Long> allErbanNoList = channelContentPartitionService.getAllErbanNoList(channelList);
|
||||
|
||||
if (CollectionUtils.isEmpty(allErbanNoList)) {
|
||||
jedisService.del(RedisKey.current_day_new_user.getKey());
|
||||
return;
|
||||
}
|
||||
|
||||
allErbanNoList = allErbanNoList.stream().distinct().collect(Collectors.toList());
|
||||
|
||||
//先删除再写入
|
||||
channelContentPartitionService.dealSyncCache(allErbanNoList, true);
|
||||
logger.info("======================================刷新当日用户类型对应的渠道缓存结束======================================");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.room.RoomService;
|
||||
import com.accompany.business.vo.RoomVo;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author yanghaoyu
|
||||
* <p>
|
||||
* 定时刷新房间人数
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class RefreshPersonTask extends BaseTask {
|
||||
@Autowired
|
||||
private RoomService roomService;
|
||||
|
||||
@Scheduled(cron = "${scheduler.refresh-in-room-person.refresh-cron}")
|
||||
public void execute(){
|
||||
log.info("定时任务:刷新人数正在执行。");
|
||||
List<RoomVo> roomList = roomService.getHomeRunningRoomList();
|
||||
for (RoomVo roomVo : roomList) {
|
||||
try {
|
||||
roomService.scanRoomOnline(roomVo);
|
||||
} catch (Exception e) {
|
||||
log.error("更新房间人数失败, roomVo:{}", gson.toJson(roomVo), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询出的人数随机算法
|
||||
* @param personNum
|
||||
* @return
|
||||
*/
|
||||
private Integer selectPersonNumMethod(Integer personNum) {
|
||||
if (personNum == 0) {
|
||||
return 1;
|
||||
}
|
||||
personNum = personNum * 10;
|
||||
Random random = new Random();
|
||||
if (personNum > 0 && personNum < 50) {
|
||||
personNum = personNum - (random.nextInt(2) + 1);
|
||||
} else if (personNum >= 50 && personNum < 100) {
|
||||
personNum = personNum - (random.nextInt(4) + 1);
|
||||
} else if (personNum >= 100 && personNum < 500) {
|
||||
personNum = personNum - (random.nextInt(9) + 1);
|
||||
} else if (personNum >= 500 && personNum < 1000) {
|
||||
personNum = personNum - (random.nextInt(19) + 1);
|
||||
} else if (personNum >= 1000 && personNum < 10000) {
|
||||
personNum = personNum - (random.nextInt(29) + 1);
|
||||
} else if (personNum >= 10000) {
|
||||
personNum = personNum - (random.nextInt(39) + 1);
|
||||
}
|
||||
return personNum;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.RobotV2Service;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Created by PaperCut on 2018/5/3.
|
||||
*/
|
||||
@Component
|
||||
public class RobotTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(RobotTask.class);
|
||||
|
||||
@Autowired
|
||||
RobotV2Service robotV2Service;
|
||||
|
||||
/**
|
||||
* 机器人24小时过期,需要定时刷新任务
|
||||
*/
|
||||
@Scheduled(cron = "0 0 4,6 * * ?")
|
||||
public void refreshRobot() {
|
||||
logger.info("Refresh robot start.");
|
||||
robotV2Service.refreshAllRobot();
|
||||
logger.info("Refresh robot finish.");
|
||||
}
|
||||
}
|
@@ -0,0 +1,133 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.business.model.GuildRoom;
|
||||
import com.accompany.business.model.GuildRoomExample;
|
||||
import com.accompany.business.model.RoomFlowPayRecord;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.business.mybatismapper.GiftSendRecordMapperExpand;
|
||||
import com.accompany.business.mybatismapper.GuildRoomMapper;
|
||||
import com.accompany.business.mybatismapper.RoomFlowPayRecordMapper;
|
||||
import com.accompany.business.service.RoomFlowPayRecordService;
|
||||
import com.accompany.business.service.user.UsersService;
|
||||
import com.accompany.business.vo.room.RoomSerialVo;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.constant.PaymentConstant;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.common.utils.WeekUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yangming
|
||||
* @date 2018-09-18
|
||||
* @description 统计每周房间礼物赠送记录,插入到流水提成记录表
|
||||
*/
|
||||
//@Component
|
||||
public class RoomFlowTask extends BaseTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(RoomFlowTask.class);
|
||||
|
||||
@Autowired
|
||||
private GiftSendRecordMapperExpand giftSendRecordMapperExpand;
|
||||
@Autowired
|
||||
private GuildRoomMapper guildRoomMapper;
|
||||
@Autowired
|
||||
private RoomFlowPayRecordMapper roomFlowPayRecordMapper;
|
||||
@Autowired
|
||||
private UsersService usersService;
|
||||
@Autowired
|
||||
private RoomFlowPayRecordService roomFlowPayRecordService;
|
||||
|
||||
private static final String DATE_FORMAT_PATTERN = "yyyy/MM/dd";
|
||||
/**
|
||||
* 每周一六点导入上周公会房间流水
|
||||
*/
|
||||
@Scheduled(cron = "0 0 6 ? * MON")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void insertRoomFlowRecord(){
|
||||
try{
|
||||
logger.info("insertRoomFlowRecord start========");
|
||||
Date now = Calendar.getInstance().getTime();
|
||||
Date beginDay = WeekUtil.getFirstDayOfLastWeek(now);
|
||||
Date endDay = WeekUtil.getFirstDayOfWeek(now);
|
||||
Date weekLastDay = WeekUtil.getLastDayOfLastWeek(now);
|
||||
GuildRoomExample guildRoomExample = new GuildRoomExample();
|
||||
List<GuildRoom> guildRooms = guildRoomMapper.selectByExample(guildRoomExample);
|
||||
if(guildRooms!=null&&guildRooms.size()>0){
|
||||
for(GuildRoom guildRoom:guildRooms){
|
||||
insertRoomFlowByOne(beginDay,endDay,weekLastDay,guildRoom);
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
logger.error("insertRoomFlowRecord fail,errorMsg={}",e);
|
||||
}
|
||||
logger.info("insertRoomFlowRecord finish=======");
|
||||
}
|
||||
|
||||
private void insertRoomFlowByOne(Date beginDay,Date endDay,Date weekLastDay,GuildRoom guildRoom){
|
||||
try{
|
||||
Date beginDate = DateTimeUtil.getDate(beginDay);
|
||||
Date endDate = DateTimeUtil.getDate(endDay);
|
||||
Date weekLastDate = DateTimeUtil.getDate(weekLastDay);
|
||||
//本周数据已存在直接跳过
|
||||
RoomFlowPayRecord record = roomFlowPayRecordService.getRoomFlowRecordByUidAndDate(beginDate,weekLastDate,guildRoom.getRoomUid());
|
||||
if(record==null) {
|
||||
RoomSerialVo roomSerialVo = giftSendRecordMapperExpand.getRoomSerialByDateAndRoomUid(beginDate, endDate, guildRoom.getRoomUid());
|
||||
Long roomFlow = roomSerialVo == null ? 0L : roomSerialVo.getTotalGold();
|
||||
Double flowRate = guildRoom.getFlowRate() == null ? 0D : guildRoom.getFlowRate();
|
||||
Double sponsorRate = guildRoom.getSponsorRate() == null ? 0D : guildRoom.getSponsorRate();
|
||||
//获取支付金额
|
||||
Double chargeMoney = new BigDecimal(roomFlow).multiply(PaymentConstant.GOLD_EXCHANGE_CASH_RATE).doubleValue();
|
||||
RoomFlowPayRecord roomFlowPayRecord = new RoomFlowPayRecord();
|
||||
roomFlowPayRecord.setRoomUid(guildRoom.getRoomUid());
|
||||
roomFlowPayRecord.setFlowNum((double) roomFlow);
|
||||
roomFlowPayRecord.setFlowRate(guildRoom.getFlowRate());
|
||||
roomFlowPayRecord.setPayAmount(new BigDecimal(chargeMoney).multiply(new BigDecimal(flowRate)).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());
|
||||
roomFlowPayRecord.setAlipayAccount(guildRoom.getAlipayAccount());
|
||||
roomFlowPayRecord.setAlipayAccountName(guildRoom.getAlipayAccountName());
|
||||
roomFlowPayRecord.setPhone(guildRoom.getPhone());
|
||||
roomFlowPayRecord.setBankAccount(guildRoom.getBankAccount());
|
||||
roomFlowPayRecord.setBankAccountName(guildRoom.getBankAccountName());
|
||||
roomFlowPayRecord.setDepositBank(guildRoom.getDepositBank());
|
||||
roomFlowPayRecord.setSponsorName(guildRoom.getSponsorName());
|
||||
roomFlowPayRecord.setSponsorRate(guildRoom.getSponsorRate());
|
||||
roomFlowPayRecord.setSponsorPayAmount(new BigDecimal(chargeMoney).multiply(new BigDecimal(sponsorRate)).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());
|
||||
roomFlowPayRecord.setSponsorAlipayAccount(guildRoom.getSponsorAlipayAccount());
|
||||
roomFlowPayRecord.setSponsorAlipayAccountName(guildRoom.getSponsorAlipayAccountName());
|
||||
roomFlowPayRecord.setSponsorBankAccount(guildRoom.getSponsorBankAccount());
|
||||
roomFlowPayRecord.setSponsorBankAccountName(guildRoom.getSponsorBankAccountName());
|
||||
roomFlowPayRecord.setSponsorDepositBank(guildRoom.getSponsorDepositBank());
|
||||
roomFlowPayRecord.setSponsorPhone(guildRoom.getSponsorPhone());
|
||||
|
||||
String beginStr = DateTimeUtil.convertDate(beginDay, DATE_FORMAT_PATTERN);
|
||||
String endStr = DateTimeUtil.convertDate(weekLastDate, DATE_FORMAT_PATTERN);
|
||||
Users user = usersService.getUsersByUid(guildRoom.getRoomUid());
|
||||
if (user == null) {
|
||||
throw new ServiceException(BusiStatus.USERNOTEXISTS);
|
||||
}
|
||||
roomFlowPayRecord.setRemark(beginStr + "-" + endStr + "用户" + user.getNick() + "房间金币流水" + roomFlow + "提成记录");
|
||||
roomFlowPayRecord.setApplyStatus(Constant.WithDrawStatus.ing);
|
||||
roomFlowPayRecord.setBeginTime(beginDate);
|
||||
roomFlowPayRecord.setEndTime(weekLastDate);
|
||||
roomFlowPayRecord.setCreateTime(Calendar.getInstance().getTime());
|
||||
roomFlowPayRecord.setUpdateTime(Calendar.getInstance().getTime());
|
||||
roomFlowPayRecordMapper.insert(roomFlowPayRecord);
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.error("insertRoomFlowByOne error, errorMsg={}",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,241 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.model.RoomTag;
|
||||
import com.accompany.business.service.home.HomeService;
|
||||
import com.accompany.business.service.noble.NobleRecomService;
|
||||
import com.accompany.business.service.rank.PermitRoomTaskService;
|
||||
import com.accompany.business.service.room.RoomCleanService;
|
||||
import com.accompany.business.service.room.RoomService;
|
||||
import com.accompany.business.service.room.RoomTagService;
|
||||
import com.accompany.business.service.singleroom.SingleRoomTaskService;
|
||||
import com.accompany.business.service.user.UsersService;
|
||||
import com.accompany.business.vo.RoomVo;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.BlankUtil;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.core.util.StringUtils;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Component
|
||||
public class RoomTask extends BaseTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(RoomTask.class);
|
||||
|
||||
@Autowired
|
||||
private RoomTagService roomTagService;
|
||||
@Autowired
|
||||
private HomeService homeService;
|
||||
@Autowired
|
||||
private RoomCleanService roomCleanService;
|
||||
@Autowired
|
||||
private NobleRecomService nobleRecomService;
|
||||
@Autowired
|
||||
private UsersService usersService;
|
||||
@Autowired
|
||||
private RoomService roomService;
|
||||
@Autowired
|
||||
private PermitRoomTaskService permitRoomTaskService;
|
||||
|
||||
/**
|
||||
* 清除房间内周贡献榜数据
|
||||
*/
|
||||
@Scheduled(cron = "0 0 5 ? * 1")
|
||||
public void clearWeekRank() {
|
||||
logger.info("clearWeekRank start ===============");
|
||||
jedisService.hdeleteKey(RedisKey.send_gift_weeklist.getKey());
|
||||
logger.info("clearWeekRank finish ===============");
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存标签数据, 30s
|
||||
*/
|
||||
@Scheduled(cron = "*/30 * * ? * *")
|
||||
public void cacheTagRoom() {
|
||||
logger.info("cache room_tag_list start ===============");
|
||||
List<RoomTag> list = roomTagService.getAllRoomTagsFromDB();
|
||||
if (list != null) {
|
||||
// 缓存房间标签列表
|
||||
jedisService.set(RedisKey.room_tag_room.getKey(), gson.toJson(list));
|
||||
for (RoomTag roomTag : list) {
|
||||
// 缓存每个标签的数据
|
||||
jedisService.hset(RedisKey.room_tag_list.getKey(), roomTag.getId().toString(), gson.toJson(roomTag));
|
||||
}
|
||||
}
|
||||
logger.info("cache room_tag_list finish ===============");
|
||||
|
||||
// 缓存顶部标签数据
|
||||
logger.info("cache room_tag_top start ===============");
|
||||
list = roomTagService.getAppTopTagsFromDB();
|
||||
jedisService.set(RedisKey.room_tag_top.getKey(), gson.toJson(list));
|
||||
logger.info("cache room_tag_top finish ===============");
|
||||
}
|
||||
@Scheduled(cron = "*/30 * * * * ?")
|
||||
public void filterChatPartyRoom() {
|
||||
// 过滤 陪伴房、 关闭的、没有活人、上锁的嗨聊房间
|
||||
logger.info("filterChatPartyRoom start ================");
|
||||
roomService.filterChatPartyRoom();
|
||||
logger.info("filterChatPartyRoom end =================");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 清除僵尸房,分为两种情况:
|
||||
* 1、普通房间,没人在线时直接关闭;
|
||||
* 2、牌照房间,没人在线或者只有机器人在房间时,不在页面上显示
|
||||
*/
|
||||
@Scheduled(cron = "0 */10 * ? * *")
|
||||
public void clearInvalidRoom() {
|
||||
logger.info("clearInvalidRoom start==============");
|
||||
roomCleanService.cleanInvalidRoom();
|
||||
logger.info("clearInvalidRoom finish=============");
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步房间状态
|
||||
*/
|
||||
@Scheduled(cron = "0 15 3 * * ?")
|
||||
public void syncRoomStatus() {
|
||||
logger.info("syncRoomStatus start==============");
|
||||
long result = roomCleanService.syncRoomStatus();
|
||||
logger.info("syncRoomStatus end============== clean room: {}", result);
|
||||
}
|
||||
|
||||
public List<RoomVo> getNobleRecomRoom(List<Long> recomUids){
|
||||
logger.info("getNobleRecomRoom recomUids:{}", recomUids);
|
||||
String[] arrUid = new String[recomUids.size()];
|
||||
for (int i = 0; i < arrUid.length; i++) {
|
||||
arrUid[i] = recomUids.get(i).toString();
|
||||
}
|
||||
|
||||
List<String> list = jedisService.hmread(RedisKey.room.getKey(), arrUid);
|
||||
Map<Long, Users> usersMap = usersService.getUsersMapBatch(arrUid);
|
||||
List<RoomVo> roomVos = Lists.newArrayList();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
RoomVo roomVo = gson.fromJson(list.get(i), RoomVo.class);
|
||||
Users users = usersMap.get(roomVo.getUid());
|
||||
if (users != null) {
|
||||
roomVo.setNick(users.getNick());
|
||||
roomVo.setAvatar(users.getAvatar());
|
||||
roomVo.setGender(users.getGender());
|
||||
roomVo.setErbanNo(users.getErbanNo());
|
||||
}
|
||||
roomVo.setIsRecom((byte)1);
|
||||
roomVos.add(roomVo);
|
||||
logger.info("getNobleRecomRoom roomVo:{}", roomVo);
|
||||
}
|
||||
logger.info("getNobleRecomRoom roomVos:{}", roomVos.size());
|
||||
return roomVos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取需要隐藏的在线房间,如牌照房没人时的房间
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<Long> getHideRunningRoom() {
|
||||
List<Long> list = Lists.newArrayList();
|
||||
try {
|
||||
Map<String, String> map = jedisService.hgetAll(RedisKey.room_permit_hide.getKey());
|
||||
if (map != null) {
|
||||
Set<String> keySet = map.keySet();
|
||||
for (String key : keySet) {
|
||||
if (!BlankUtil.isBlank(key) && !BlankUtil.isBlank(map.get(key))) {
|
||||
list.add(Long.valueOf(map.get(key)));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("getHideRunningRoom error", e);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤热门推荐上的房间
|
||||
* @param homeRooms
|
||||
* @param hideRooms
|
||||
* @return
|
||||
*/
|
||||
public List<RoomVo> filteHideRoomForHomeHotManual(List<RoomVo> homeRooms, List<Long> hideRooms) {
|
||||
List<RoomVo> resultRoom = Lists.newArrayList();
|
||||
for (RoomVo roomVo : homeRooms) {
|
||||
if (!roomVo.getValid() || !roomCleanService.hasRealUserInRoom(roomVo.getRoomId())) {
|
||||
continue;
|
||||
}
|
||||
if(StringUtils.isNotBlank(roomVo.getRoomPwd())) {
|
||||
continue;
|
||||
}
|
||||
boolean isExist = false;
|
||||
for (Long uid : hideRooms) {
|
||||
if (roomVo.getUid().equals(uid)) {
|
||||
isExist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isExist) {
|
||||
resultRoom.add(roomVo);
|
||||
}
|
||||
}
|
||||
return resultRoom;
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤没活人的房间
|
||||
*
|
||||
* @param rooms
|
||||
* @return
|
||||
*/
|
||||
public List<RoomVo> filteRobotRoom(List<RoomVo> rooms) {
|
||||
Iterator<RoomVo> it = rooms.iterator();
|
||||
while (it.hasNext()) {
|
||||
RoomVo roomVo = it.next();
|
||||
if (roomVo.getOnlineNum() < 21 && !roomCleanService.hasRealUserInRoom(roomVo.getRoomId())) {
|
||||
it.remove();
|
||||
} else if(StringUtils.isNotBlank(roomVo.getRoomPwd())) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
return rooms;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送牌照房上小时榜单TOP1通知 (每一小时扫描一次)
|
||||
*/
|
||||
@Scheduled(cron = "0 0 */1 * * ?")
|
||||
public void sendLastHourTop1Notify() {
|
||||
logger.info("发送牌照房上小时榜单TOP1通知...");
|
||||
permitRoomTaskService.sendLastHourTop1Notify();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<String> list = Lists.newArrayList();
|
||||
list.add("11");
|
||||
list.add("113");
|
||||
list.add("114");
|
||||
list.add("115");
|
||||
|
||||
System.out.println(list);
|
||||
|
||||
Iterator<String> it = list.iterator();
|
||||
while (it.hasNext()) {
|
||||
String next = it.next();
|
||||
if (next.equals("113") || next.equals("114")) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
System.out.println(list.size());
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.seekelfin.SeekElfinPreWarningService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SeekElfinPreWarningTask extends BaseTask {
|
||||
|
||||
@Autowired
|
||||
private SeekElfinPreWarningService seekElfinPreWarningService;
|
||||
|
||||
/**
|
||||
* 自动轮播寻找小精灵
|
||||
*/
|
||||
@Scheduled(cron = "0 0 */1 * * ?")
|
||||
public void handleBroadcastTask() {
|
||||
try {
|
||||
log.info("开始自动轮播寻找小精灵");
|
||||
seekElfinPreWarningService.handleBroadcast();
|
||||
log.info("开始自动轮播寻找小精灵");
|
||||
} catch (Exception e) {
|
||||
log.error("开始自动轮播寻找小精灵失败...", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,171 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.message.SignDrawGoldMessage;
|
||||
import com.accompany.business.message.SignMessage;
|
||||
import com.accompany.business.model.UserSignRound;
|
||||
import com.accompany.business.service.signweb.*;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* 签到定时器
|
||||
*/
|
||||
//@Component
|
||||
public class SignGoldTask extends BaseTask implements ApplicationContextAware {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SignGoldTask.class);
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
PrizeGoldPoolService prizeGoldPoolService;
|
||||
@Autowired
|
||||
SignGoldService signGoldService;
|
||||
@Autowired
|
||||
UserSignRoundService userSignRoundService;
|
||||
@Autowired
|
||||
SignPrizeRecordService signPrizeRecordService;
|
||||
@Autowired
|
||||
private SignService signService;
|
||||
@Autowired
|
||||
private SignDrawGoldService signDrawGoldService;
|
||||
|
||||
/**
|
||||
* 更新奖池金额,更新奖池奖品的金币数量总计与被抽中数量总计
|
||||
* 清空瓜分金币通知栏,并从DB取最新10条瓜分金币消息进Cache
|
||||
*/
|
||||
@Scheduled(cron = "1 0 0 * * ?")
|
||||
public void updateSignGoldNum(){
|
||||
logger.info("sign() start ========");
|
||||
|
||||
try {
|
||||
prizeGoldPoolService.goldNumIsUpdate();
|
||||
signGoldService.setDrawGoldNoticeCacheFromDB(true);
|
||||
|
||||
prizeGoldPoolService.updateGoldNumTotalAndUsePrizeNumTotal();
|
||||
} catch (Exception e) {
|
||||
logger.error("sign error...",e);
|
||||
}
|
||||
logger.info("sign() finish ========");
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空过期的用户当前轮数记录
|
||||
* 清空过期的用户当前轮数礼物领取记录
|
||||
*/
|
||||
@Scheduled(cron = "1 0 0 * * ?")
|
||||
public void clearAndSignRoundCache(){
|
||||
logger.info("clearAndSignRoundCache() start ========");
|
||||
|
||||
try {
|
||||
List<String> list = userSignRoundService.delExpiredUserSignRoundCache();
|
||||
signPrizeRecordService.delSignPrizeRecordCache(list);
|
||||
} catch (Exception e) {
|
||||
logger.error("clearAndSignRoundCache error...",e);
|
||||
}
|
||||
logger.info("clearAndSignRoundCache() finish ========");
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户当前轮数过期后,自动开启下一轮
|
||||
*/
|
||||
@Scheduled(cron = "5 0 0 * * ?")
|
||||
public void autoAddUserSignRound(){
|
||||
logger.info("autoAddUserSignRound() start ========");
|
||||
|
||||
try {
|
||||
List<UserSignRound> expireUserSignRounds = userSignRoundService.getExpireUserSignRoun();
|
||||
userSignRoundService.batchInsertUserSignRound(expireUserSignRounds);//开启下一轮
|
||||
userSignRoundService.initReplenishCount(expireUserSignRounds);//初始化补签次数
|
||||
} catch (Exception e) {
|
||||
logger.error("autoAddUserSignRound error...",e);
|
||||
}
|
||||
logger.info("autoAddUserSignRound() finish ========");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重新消费签到消费队列的消息
|
||||
*/
|
||||
@Scheduled(cron = "0 */2 * * * ?")
|
||||
public void retrySignQueue(){
|
||||
Map<String,String> map = jedisService.hgetAll(RedisKey.mq_sign_status.getKey());
|
||||
if (map == null || map.size() == 0) {
|
||||
return;
|
||||
}
|
||||
Set<String> keySet = map.keySet();
|
||||
long curTime = System.currentTimeMillis();
|
||||
long gapTime = 1000 * 60 * 30; // 三十分钟内没被消费
|
||||
int countMess = 0; // 未被消费的消息
|
||||
|
||||
for (String key : keySet) {
|
||||
try {
|
||||
String val = map.get(key);
|
||||
if("0".equals(val)){//旧bug,之前为0的数据删除
|
||||
jedisService.hdel(RedisKey.mq_sign_status.getKey(), key);
|
||||
continue;
|
||||
}
|
||||
SignMessage signMessage = gson.fromJson(val, SignMessage.class);
|
||||
if(curTime - signMessage.getMessTime() > gapTime) {
|
||||
signService.handlerSign(signMessage);
|
||||
countMess++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("retrySignInQueue error e={}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重新消费瓜分金币队列的消息
|
||||
*/
|
||||
@Scheduled(cron = "0 */2 * * * ?")
|
||||
public void retrySignDrawGoldQueue(){
|
||||
Map<String,String> map = jedisService.hgetAll(RedisKey.mq_sign_draw_gold_status.getKey());
|
||||
if (map == null || map.size() == 0) {
|
||||
return;
|
||||
}
|
||||
Set<String> keySet = map.keySet();
|
||||
long curTime = System.currentTimeMillis();
|
||||
long gapTime = 1000 * 60 * 30; // 三十分钟内没被消费
|
||||
int countMess = 0; // 未被消费的消息
|
||||
|
||||
for (String key : keySet) {
|
||||
try {
|
||||
String val = map.get(key);
|
||||
if("0".equals(val)){//不处理旧数据 值为0的数据
|
||||
continue;
|
||||
}
|
||||
SignDrawGoldMessage signDrawGoldMessage = gson.fromJson(val, SignDrawGoldMessage.class);
|
||||
|
||||
if(curTime - signDrawGoldMessage.getMessTime() > gapTime) {
|
||||
signDrawGoldService.handleDrawGoldMessage(signDrawGoldMessage);
|
||||
countMess++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("retrySignDrawGoldQueue error e={}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.signweb.SignGoldService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
/**
|
||||
* @author chucheng
|
||||
* @date 2019-03-19
|
||||
* @description 签到提醒
|
||||
*/
|
||||
//@Component
|
||||
public class SignRemindTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SignRemindTask.class);
|
||||
|
||||
@Autowired
|
||||
private SignGoldService signService;
|
||||
|
||||
@Scheduled(cron = "0 0 18 * * ?")
|
||||
public void execute(){
|
||||
try {
|
||||
logger.info("开始推送签到提醒=========");
|
||||
this.signService.sendRemind();
|
||||
logger.info("完成推送签到提醒==========");
|
||||
} catch (Exception e) {
|
||||
logger.error("推送签到提醒出错...", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.room.SingleBroadcastTimeService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SingleBroadcastRoomTimeTask extends BaseTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SingleBroadcastRoomTimeTask.class);
|
||||
|
||||
@Autowired
|
||||
private SingleBroadcastTimeService singleBroadcastTimeService;
|
||||
|
||||
/**
|
||||
* 每隔5分钟检查一次个播房房
|
||||
*/
|
||||
@Scheduled(cron = "0 0/5 * * * ?")
|
||||
public void checkSingleRoomTime() {
|
||||
logger.info("checkSingleRoomTime start ===============");
|
||||
singleBroadcastTimeService.checkSingleRoomTime();
|
||||
logger.info("checkSingleRoomTime finish ===============");
|
||||
}
|
||||
}
|
@@ -0,0 +1,88 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.model.UserPurseStatistics;
|
||||
import com.accompany.business.mybatismapper.UserBackpackMapperExpand;
|
||||
import com.accompany.business.mybatismapper.UserPurseStatisticsMapper;
|
||||
import com.accompany.business.service.purse.UserPurseService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import com.accompany.scheduler.config.TaskPropertyConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.Trigger;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @Author yubin
|
||||
* @Description 检查长时间未使用未登录的用户,将其资产冻结
|
||||
* @Date 2019-06-19 10:57
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SumUserPurseTask extends BaseTask implements SchedulingConfigurer {
|
||||
|
||||
|
||||
@Autowired
|
||||
private TaskPropertyConfig taskPropertyConfig;
|
||||
|
||||
@Autowired
|
||||
private UserPurseService userPurseService;
|
||||
|
||||
@Autowired
|
||||
private UserPurseStatisticsMapper userPurseStatisticsMapper;
|
||||
|
||||
@Autowired
|
||||
UserBackpackMapperExpand userBackpackMapperExpand;
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
// taskRegistrar.addTriggerTask(doTask(), getTrigger());
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务执行方法
|
||||
* @return
|
||||
*/
|
||||
private Runnable doTask() {
|
||||
return () -> sumUserPurse();
|
||||
}
|
||||
|
||||
/**
|
||||
* 冻结长时间未登录的用户资产
|
||||
*/
|
||||
private void sumUserPurse(){
|
||||
Map<String, Object> objectMap = userPurseService.sumGoldNumAndDiamondNum();
|
||||
Double giftValue = userBackpackMapperExpand.statisticsGiftValue();
|
||||
log.info("sumGoldNumAndDiamondNum result:{}", objectMap.toString());
|
||||
Optional.ofNullable(objectMap).ifPresent(map -> {
|
||||
UserPurseStatistics userPurseStatistics = new UserPurseStatistics();
|
||||
userPurseStatistics.setGoldNum(((BigDecimal) map.get("goldNum")).longValue());
|
||||
userPurseStatistics.setDiamondNum((Double) map.get("diamondNum"));
|
||||
userPurseStatistics.setCreateTime(new Date());
|
||||
userPurseStatistics.setBackpackGoldNum(giftValue);
|
||||
log.info("saveStatistics param:{}", userPurseStatistics.toString());
|
||||
userPurseStatisticsMapper.insertSelective(userPurseStatistics);
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务触发器
|
||||
* @return
|
||||
*/
|
||||
private Trigger getTrigger() {
|
||||
return triggerContext -> {
|
||||
// 触发器
|
||||
CronTrigger trigger = new CronTrigger(taskPropertyConfig.getSumPurseTime());
|
||||
return trigger.nextExecutionTime(triggerContext);
|
||||
};
|
||||
}
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.community.DynamicTaskService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import com.accompany.scheduler.config.TaskPropertyConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.Trigger;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
|
||||
/**
|
||||
* Created By LeeNana on 2019/11/27.
|
||||
* 统计待审核的动态 声音瓶子
|
||||
*/
|
||||
//@Component
|
||||
@Slf4j
|
||||
public class SystemNotifyTask extends BaseTask implements SchedulingConfigurer {
|
||||
@Autowired
|
||||
private TaskPropertyConfig taskPropertyConfig;
|
||||
@Autowired
|
||||
private DynamicTaskService dynamicTaskService;
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
taskRegistrar.addTriggerTask(doTask(), getTrigger());
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务触发器
|
||||
* @return
|
||||
*/
|
||||
private Trigger getTrigger() {
|
||||
return triggerContext -> {
|
||||
// 触发器
|
||||
CronTrigger trigger = new CronTrigger(taskPropertyConfig.getUpdateAuditCount());
|
||||
return trigger.nextExecutionTime(triggerContext);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务执行方法
|
||||
* @return
|
||||
*/
|
||||
private Runnable doTask() {
|
||||
return () -> auditDynamicAndVoice();
|
||||
}
|
||||
|
||||
|
||||
public void auditDynamicAndVoice(){
|
||||
log.info("auditDynamicAndVoice start........");
|
||||
try {
|
||||
dynamicTaskService.auditDynamicAndVoice();
|
||||
log.info("auditDynamicAndVoice end........");
|
||||
}catch (Exception e){
|
||||
log.error("auditDynamicAndVoice failed", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.model.UserPurse;
|
||||
import com.accompany.business.mybatismapper.UserPurseMapper;
|
||||
import com.accompany.business.service.purse.UserPurseService;
|
||||
import com.accompany.business.service.record.BillRecordService;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.core.enumeration.BillObjTypeEnum;
|
||||
import com.accompany.core.enumeration.ExchangeTypeEnum;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.core.service.common.JedisLockService;
|
||||
import com.accompany.core.util.StringUtils;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created By LeeNana on 2020/3/11.
|
||||
* 活动定时器
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class UserPurseTask extends BaseTask {
|
||||
@Autowired
|
||||
private UserPurseService userPurseService;
|
||||
@Autowired
|
||||
private JedisLockService jedisLockService;
|
||||
@Autowired
|
||||
private UserPurseMapper userPurseMapper;
|
||||
@Autowired
|
||||
private BillRecordService billRecordService;
|
||||
|
||||
/**
|
||||
* 三日情侣活动
|
||||
*/
|
||||
@Scheduled(cron = "0 0 3 * * ?")
|
||||
public void excCrystalToGold(){
|
||||
log.info("excCrystalToGold() start..........");
|
||||
List<UserPurse> userPurseList = userPurseService.list();
|
||||
if(CollectionUtils.isEmpty(userPurseList)){
|
||||
return;
|
||||
}
|
||||
userPurseList.stream().forEach(userPurse -> {
|
||||
try {
|
||||
this.exCrystalToGold(userPurse.getUid());
|
||||
}catch (Exception e){
|
||||
log.error("exCrystalToGold() failed, uid:{}", userPurse.getUid(), e);
|
||||
}
|
||||
});
|
||||
log.info("sendMsgToUser() end..........");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 水晶兑换金币
|
||||
* @param uid
|
||||
* @return
|
||||
*/
|
||||
private Boolean exCrystalToGold(Long uid) {
|
||||
String lockVal = jedisLockService.lock(RedisKey.lock_user_crystal.getKey(uid.toString()));
|
||||
try {
|
||||
if (StringUtils.isBlank(lockVal)) {
|
||||
throw new ServiceException(BusiStatus.SERVER_BUSY);
|
||||
}
|
||||
UserPurse userPurse = userPurseService.queryUserPurse(uid);
|
||||
Double crystalNum = userPurse.getCrystals();
|
||||
if(crystalNum <= 0){
|
||||
log.error("exCrystalToGold failed, uid:{}, crystal:{}", uid, crystalNum);
|
||||
return false;
|
||||
}
|
||||
//保证操作原子性
|
||||
ExchangeTypeEnum exchangeTypeEnum = ExchangeTypeEnum.CRYSTAL_TO_GOLD;
|
||||
Double goldNum = BigDecimal.valueOf(crystalNum).multiply(BigDecimal.valueOf(exchangeTypeEnum.getRate()))
|
||||
.setScale(2,BigDecimal.ROUND_HALF_DOWN).doubleValue();
|
||||
int ret = userPurseMapper.exCrystalToGold(uid, crystalNum, goldNum);
|
||||
boolean result = SqlHelper.retBool(ret);
|
||||
if(result) {
|
||||
billRecordService.insertGeneralBillRecord(uid,uid,null,BillObjTypeEnum.EXCHANGE_CRYSTAL_TO_GOLD_PAY,crystalNum);
|
||||
billRecordService.insertGeneralBillRecord(uid,uid,null,BillObjTypeEnum.EXCHANGE_CRYSTAL_TO_GOLD_INCOME,goldNum);
|
||||
log.info("exCrystalToGold,uid:{},result:{}",result);
|
||||
}
|
||||
return result;
|
||||
} finally {
|
||||
jedisLockService.unlock(RedisKey.lock_user_crystal.getKey(uid.toString()), lockVal);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.message.VoiceLikeMessage;
|
||||
import com.accompany.business.service.voice.VoiceService;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Author: chucheng
|
||||
* @Date: 2019/6/6 17:32
|
||||
* @Description: 辅助消费声音瓶子喜欢/不喜欢消息
|
||||
*/
|
||||
//@Component
|
||||
public class VoiceLikeMessageTask extends BaseTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(VoiceLikeMessageTask.class);
|
||||
|
||||
@Autowired
|
||||
private VoiceService voiceService;
|
||||
|
||||
/**
|
||||
* 辅助消费队列的消息
|
||||
*/
|
||||
@Scheduled(cron = "0 */2 * * * ?")
|
||||
public void retryVoiceLikeQueue(){
|
||||
Map<String,String> map = jedisService.hgetAll(RedisKey.voice_like_status.getKey());
|
||||
if (map == null || map.size() == 0) {
|
||||
return;
|
||||
}
|
||||
Set<String> keySet = map.keySet();
|
||||
long curTime = System.currentTimeMillis();
|
||||
long gapTime = 1000 * 60 * 10; // 十分钟内没被消费
|
||||
|
||||
for (String key : keySet) {
|
||||
try {
|
||||
String val = map.get(key);
|
||||
VoiceLikeMessage message = gson.fromJson(val, VoiceLikeMessage.class);
|
||||
if(curTime - message.getMessTime() > gapTime) {
|
||||
voiceService.handleVoiceLikeMessage(message);
|
||||
logger.info("retry call handleVoiceLikeMessage. message = {}", JSONObject.toJSONString(message));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("retry call handleVoiceLikeMessage error", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.world.WorldRoomService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
/**
|
||||
* 话题定时器,处理僵尸房
|
||||
*/
|
||||
//@Component
|
||||
public class WorldRoomTask extends BaseTask {
|
||||
private static final Logger logger = LoggerFactory.getLogger(WorldRoomTask.class);
|
||||
|
||||
@Autowired
|
||||
private WorldRoomService worldRoomService;
|
||||
|
||||
@Scheduled(cron = "0 */3 * * * ?")
|
||||
public void filterWorldRoom() {
|
||||
// 过滤 没有活人的派对
|
||||
logger.info("filterWorldRoom start ================");
|
||||
worldRoomService.filterWorldRoom();
|
||||
logger.info("filterWorldRoom end =================");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,88 @@
|
||||
package com.accompany.scheduler.task;
|
||||
|
||||
import com.accompany.business.service.world.WorldMemberActiveRecordService;
|
||||
import com.accompany.business.service.world.WorldMemberApplyRecordService;
|
||||
import com.accompany.business.service.world.WorldPreCleanRecordService;
|
||||
import com.accompany.business.service.world.WorldService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 话题相关的定时任务
|
||||
*
|
||||
* @author fangchengyan
|
||||
* @date 2019-07-10 9:59
|
||||
*/
|
||||
@Component
|
||||
public class WorldTask extends BaseTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(WorldTask.class);
|
||||
|
||||
@Autowired
|
||||
private WorldService worldService;
|
||||
@Autowired
|
||||
private WorldMemberApplyRecordService worldMemberApplyRecordService;
|
||||
@Autowired
|
||||
private WorldPreCleanRecordService worldPreCleanRecordService;
|
||||
@Autowired
|
||||
private WorldMemberActiveRecordService worldMemberActiveRecordService;
|
||||
|
||||
@Scheduled(cron = "5 0/10 * * * ?")
|
||||
public void clearExpireApplyRecord(){
|
||||
worldMemberApplyRecordService.cleanExpireApplyRecord();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "35 2/10 * * * ?")
|
||||
public void preCleanWorld(){
|
||||
try {
|
||||
worldService.preCleanWorld();
|
||||
} catch (Exception e) {
|
||||
logger.error("预清理世界异常!", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动清除话题分为两个阶段:
|
||||
* 1. 话题创建后,超过3天人数不足3人,进入预清理阶段,并且发出预警信息
|
||||
* 2. 发出预警信息后再过3天,话题人数依旧不足3人,话题就正式解散
|
||||
*/
|
||||
@Scheduled(cron = "35 4/10 * * * ?")
|
||||
public void autoCleanWorld(){
|
||||
try {
|
||||
worldPreCleanRecordService.autoCleanWorld();
|
||||
} catch (Exception e) {
|
||||
logger.error("清理世界异常!", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 自动退出话题:
|
||||
* 加入话题后,连续五天没有在话题活跃的用户,将被移出该话题,并发送系统消息通知;
|
||||
*
|
||||
* 活跃行为包括:
|
||||
* 1、发言,包括文字、语音和表情;
|
||||
* 2、送礼物;
|
||||
* 3、创建语音派对;
|
||||
* 4、加入语音派对;
|
||||
*
|
||||
* 2019-11-02 暂时不启用,待1.2.3版本发布且使用人数达到80%后再启用
|
||||
* 2019-11-12 启用
|
||||
*/
|
||||
@Scheduled(cron = "35 10 3 * * ?")
|
||||
public void autoCleanInactiveMember(){
|
||||
logger.info("清理未活跃的话题成员开始...");
|
||||
try {
|
||||
worldMemberActiveRecordService.cleanInactiveMember(5, null);
|
||||
} catch (Exception e) {
|
||||
logger.error("清理不活跃的话题成员异常!", e);
|
||||
}
|
||||
logger.info("清理未活跃的话题成员完成...");
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 文 件 名: LuckySeaPreWarningTask
|
||||
* 版 权:
|
||||
* 描 述: <描述>
|
||||
* 创建人: H1
|
||||
* 创建时间: 2021/9/23
|
||||
* 修改人:
|
||||
* 修改内容:
|
||||
* 修改时间:
|
||||
*/
|
||||
package com.accompany.scheduler.task.activity;
|
||||
|
||||
import com.accompany.business.service.callbattle.ActCallBattlePreWarningService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* <br>类描述:
|
||||
* <br>功能详细描述:
|
||||
*
|
||||
* @author H1
|
||||
* @date [2021/9/23]
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ActCallBattlePreWarningTask extends BaseTask {
|
||||
|
||||
@Autowired
|
||||
private ActCallBattlePreWarningService actCallBattlePreWarningService;
|
||||
|
||||
/**
|
||||
* 自动轮播守护星球
|
||||
*/
|
||||
@Scheduled(cron = "0 0 */1 * * ?")
|
||||
public void handleBroadcastTask() {
|
||||
try {
|
||||
log.info("开始自动轮播守护星球");
|
||||
actCallBattlePreWarningService.handleBroadcast();
|
||||
log.info("结束自动轮播守护星球");
|
||||
} catch (Exception e) {
|
||||
log.error("开始自动轮播守护星球失败...", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* 文 件 名: LuckySeaActTask
|
||||
* 版 权:
|
||||
* 描 述: <描述>
|
||||
* 创建人: H1
|
||||
* 创建时间: 2021/1/6
|
||||
* 修改人:
|
||||
* 修改内容:
|
||||
* 修改时间:
|
||||
*/
|
||||
package com.accompany.scheduler.task.activity;
|
||||
|
||||
import com.accompany.business.config.ActCallBattleConfig;
|
||||
import com.accompany.business.model.callbattle.ActCallBattleItem;
|
||||
import com.accompany.business.service.callbattle.ActCallBattleBizService;
|
||||
import com.accompany.business.service.callbattle.ActCallBattlePreWarningService;
|
||||
import com.accompany.business.vo.callbattle.ActCallBattleInfoVo;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.core.service.SysConfService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* <br>类描述:
|
||||
* <br>功能详细描述:
|
||||
*
|
||||
* @author H1
|
||||
* @date [2021/1/6]
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ActCallBattleTask extends BaseTask implements ApplicationListener<ApplicationStartedEvent> {
|
||||
|
||||
@Autowired
|
||||
private SysConfService sysConfService;
|
||||
@Autowired
|
||||
private ActCallBattlePreWarningService actCallBattlePreWarningService;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
@Autowired
|
||||
private ActCallBattleBizService actCallBattleBizService;
|
||||
|
||||
private volatile static boolean taskStarted = false;
|
||||
|
||||
public void runTask() {
|
||||
RLock lock = redissonClient.getLock(RedisKey.call_battle_run_task.getKey());
|
||||
try {
|
||||
// 加锁,保证只有一个线程能执行这个流程
|
||||
boolean isHasLock = lock.tryLock(30, -1, TimeUnit.SECONDS);
|
||||
|
||||
if (isHasLock) {
|
||||
log.info("召唤战斗活动, 获取锁成功");
|
||||
while (true) {
|
||||
// 活动开关是否开着
|
||||
Boolean actSwitch = Optional.of(
|
||||
Boolean.parseBoolean(sysConfService.getSysConfValueById(Constant.SysConfId.CALL_BATTLE_SWITCH))).orElse(false);
|
||||
log.info("召唤战斗活动, 开关状态: {}", actSwitch);
|
||||
if (actSwitch) {
|
||||
String roundId = null;
|
||||
Date nextRoundStartTime = null;
|
||||
Long stock = actCallBattleBizService.getStock();
|
||||
// 获取游戏的配置
|
||||
List<ActCallBattleItem> itemList = actCallBattleBizService.listActItem();
|
||||
ActCallBattleConfig timeConfig = actCallBattleBizService.getActTimeConfig();
|
||||
long drawMills = 0L;
|
||||
try {
|
||||
boolean needCreateNewAct = true;
|
||||
boolean needWaitUserDraw = true;
|
||||
Integer waitUserDrawTime = timeConfig.getChooseStageTime();
|
||||
// 处理异常活动
|
||||
ActCallBattleInfoVo actInfo = actCallBattleBizService.getNewestActInfo(null);
|
||||
if (null != actInfo && StringUtils.isNotBlank(actInfo.getRoundId())) {
|
||||
if (actInfo.getStatus().equals(Constant.LuckySeaActStatus.CHOOSE_STAGE)) {
|
||||
needCreateNewAct = false;
|
||||
roundId = actInfo.getRoundId();
|
||||
Long intervalSecond = (System.currentTimeMillis() - actInfo.getStartTime().getTime()) / 1000;
|
||||
log.info("召唤战斗活动, 上一轮投注时间发生异常的活动到现在的间隔时间{}秒, roundId:{}", intervalSecond, roundId);
|
||||
if (intervalSecond <= timeConfig.getChooseStageTime()) {
|
||||
waitUserDrawTime = timeConfig.getChooseStageTime() - intervalSecond.intValue();
|
||||
log.info("召唤战斗活动, 上一轮投注时间发生异常的活动留给用户的下注时间{}秒", waitUserDrawTime);
|
||||
} else {
|
||||
log.info("召唤战斗活动, 上一轮投注时间发生异常的活动直接进行开奖, roundId:{}", roundId);
|
||||
needWaitUserDraw = false;
|
||||
}
|
||||
} else if (actInfo.getStatus().equals(Constant.LuckySeaActStatus.DRAWING)) {
|
||||
needCreateNewAct = false;
|
||||
needWaitUserDraw = false;
|
||||
roundId = actInfo.getRoundId();
|
||||
log.info("召唤战斗活动, 上一轮投注时间发生异常的活动直接进行开奖, roundId:{}", roundId);
|
||||
}
|
||||
}
|
||||
// 创建新的一轮游戏
|
||||
if (needCreateNewAct) {
|
||||
roundId = actCallBattleBizService.createNewRoundAct(nextRoundStartTime,timeConfig.getChooseStageTime() );
|
||||
}
|
||||
// 等待用户投碎片
|
||||
if (needWaitUserDraw) {
|
||||
log.info("召唤战斗活动, 开始等待用户投入碎片, currTime: {}", System.currentTimeMillis());
|
||||
Thread.sleep(waitUserDrawTime * 1000);
|
||||
log.info("召唤战斗活动, 结束等待用户投入碎片, currTime: {}", System.currentTimeMillis());
|
||||
}
|
||||
actCallBattleBizService.updateActStatus(roundId, Constant.LuckySeaActStatus.DRAWING);
|
||||
// 开奖
|
||||
drawMills = actCallBattleBizService.actDraw(itemList, roundId, timeConfig, stock);
|
||||
} catch (Exception e) {
|
||||
// 更新活动状态, 此轮游戏标识为异常,不开始下一轮游戏
|
||||
log.error("召唤战斗活动开奖时出现异常, roundId: " + roundId, e);
|
||||
actCallBattleBizService.updateActStatus(roundId, Constant.LuckySeaActStatus.GAME_ABNORMAL);
|
||||
actCallBattleBizService.compensateUserPieceWhenGameAbnormal(roundId, stock);
|
||||
break;
|
||||
}
|
||||
try {
|
||||
// 异步更新用户抽奖记录
|
||||
actCallBattleBizService.updateUserDrawRecordAsync(roundId, itemList);
|
||||
// 等待开奖动画与页面渲染开奖结果时间
|
||||
long sleepMills = (timeConfig.getDrawOverStageTime() + timeConfig.getWaitingDrawStageTime()) * 1000
|
||||
- drawMills;
|
||||
if (sleepMills > 0) {
|
||||
log.info("召唤战斗活动, 等待开奖动画与页面渲染开奖结果时间{}毫秒", sleepMills);
|
||||
Thread.sleep(sleepMills);
|
||||
}
|
||||
log.info("召唤战斗活动此轮结束, roundId:{}", roundId);
|
||||
// 异步更新活动endTime
|
||||
nextRoundStartTime = new Date();
|
||||
actCallBattleBizService.endAct(roundId, nextRoundStartTime);
|
||||
// 进行预警数据统计
|
||||
actCallBattlePreWarningService.handleGoldPreWarning();
|
||||
} catch (Exception e) {
|
||||
// 更新活动状态
|
||||
log.error("召唤战斗活动更新用户抽奖记录与分发奖励时出现异常, roundId: " + roundId, e);
|
||||
actCallBattleBizService.updateActStatus(roundId, Constant.LuckySeaActStatus.SUCCESS_DRAW_UPDATE_DATA_FAIL);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
log.info("召唤战斗活动, 开关未开启,线程进入休眠: {}", actSwitch);
|
||||
Thread.sleep(60 * 1000);
|
||||
continue;
|
||||
} catch (Exception e){
|
||||
log.error("召唤战斗活动线程休眠时出现异常", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.warn("召唤战斗活动, 获取锁失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("启动召唤战斗活动流程任务异常",e);
|
||||
} finally {
|
||||
if (lock.isLocked()) {
|
||||
log.info("召唤战斗活动, 释放锁");
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationStartedEvent event) {
|
||||
log.info("ready to start lucky sea task");
|
||||
if (!ActCallBattleTask.taskStarted) {
|
||||
synchronized (ActCallBattleTask.class) {
|
||||
if (!ActCallBattleTask.taskStarted) {
|
||||
ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
executorService.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
log.info("start lucky sea task");
|
||||
ActCallBattleTask.taskStarted = true;
|
||||
runTask();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 文 件 名: ActLuckyBagRankTask
|
||||
* 版 权:
|
||||
* 描 述: <描述>
|
||||
* 创建人: H1
|
||||
* 创建时间: 2022/4/18
|
||||
* 修改人:
|
||||
* 修改内容:
|
||||
* 修改时间:
|
||||
*/
|
||||
package com.accompany.scheduler.task.activity;
|
||||
|
||||
import com.accompany.business.service.activities.ActCandyBizService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* <br>类描述: 2022糖果集市定时任务
|
||||
* <br>功能详细描述:
|
||||
*
|
||||
* @author H1
|
||||
* @date [2022/4/18]
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ActCandy2022Task {
|
||||
|
||||
@Autowired
|
||||
private ActCandyBizService actCandyBizService;
|
||||
|
||||
/**
|
||||
* 2022糖果集市活动自动发放奖励
|
||||
*/
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
public void sendAward() {
|
||||
log.info("2022糖果集市活动自动发放奖励...");
|
||||
actCandyBizService.sendAward();
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 文 件 名: ActLuckyBagRankTask
|
||||
* 版 权:
|
||||
* 描 述: <描述>
|
||||
* 创建人: H1
|
||||
* 创建时间: 2022/4/18
|
||||
* 修改人:
|
||||
* 修改内容:
|
||||
* 修改时间:
|
||||
*/
|
||||
package com.accompany.scheduler.task.activity;
|
||||
|
||||
import com.accompany.business.service.activity.ActLuckyBagRankService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* <br>类描述:
|
||||
* <br>功能详细描述:
|
||||
*
|
||||
* @author H1
|
||||
* @date [2022/4/18]
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ActLuckyBagRankTask {
|
||||
|
||||
@Autowired
|
||||
private ActLuckyBagRankService actLuckyBagRankService;
|
||||
|
||||
/**
|
||||
* 2022福袋榜单活动自动发放奖励
|
||||
*/
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
public void sendAward() {
|
||||
log.info("2022福袋榜单活动自动发放奖励...");
|
||||
actLuckyBagRankService.sendAward();
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package com.accompany.scheduler.task.activity;
|
||||
|
||||
import com.accompany.business.service.activity.ActivityLuckyPlanetService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ActLuckyPlanetTask {
|
||||
@Autowired
|
||||
private ActivityLuckyPlanetService activityLuckyPlanetService;
|
||||
|
||||
/**
|
||||
* 2022福袋榜单活动日榜奖励自动发放
|
||||
*/
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
public void sendAward() {
|
||||
log.info("2022福袋榜单活动自动发放奖励...");
|
||||
// 幸运榜
|
||||
activityLuckyPlanetService.sendDayRankReward(1);
|
||||
// 魅力榜
|
||||
activityLuckyPlanetService.sendDayRankReward(2);
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
package com.accompany.scheduler.task.activity;
|
||||
|
||||
import com.accompany.business.service.activity.ActivityMidAutumnService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ActMinAutumn2022Task {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ActivityMidAutumnService activityMidAutumnService;
|
||||
|
||||
/**
|
||||
* 2022中秋活动cp日榜奖励自动发放
|
||||
*/
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
public void sendAward() {
|
||||
log.info("2022福袋榜单活动自动发放奖励...");
|
||||
activityMidAutumnService.sendDailyRankReward();
|
||||
}
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
package com.accompany.scheduler.task.activity;
|
||||
|
||||
import com.accompany.business.constant.BackpackReduceRecordEnum;
|
||||
import com.accompany.business.model.BackpackReduceRecord;
|
||||
import com.accompany.business.model.Gift;
|
||||
import com.accompany.business.mybatismapper.ActivityAudioCardMapper;
|
||||
import com.accompany.business.mybatismapper.BackpackReduceRecordMapper;
|
||||
import com.accompany.business.service.activity.ActivityAudioCardService;
|
||||
import com.accompany.business.service.gift.GiftService;
|
||||
import com.accompany.business.service.user.UserBackpackService;
|
||||
import com.accompany.business.vo.UserBackpackVo;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AudioCardActTask extends BaseTask {
|
||||
|
||||
@Autowired
|
||||
private ActivityAudioCardService activityAudioCardService;
|
||||
@Autowired
|
||||
private ActivityAudioCardMapper activityAudioCardMapper;
|
||||
@Autowired
|
||||
private UserBackpackService userBackpackService;
|
||||
@Autowired
|
||||
private GiftService giftService;
|
||||
@Autowired
|
||||
private BackpackReduceRecordMapper backpackReduceRecordMapper;
|
||||
|
||||
/**
|
||||
* 试音卡礼物有效期三天
|
||||
*/
|
||||
@Scheduled(cron = "0 0/30 * * * ?")
|
||||
public void sendBonus() {
|
||||
Integer audioCardId = activityAudioCardService.getAudioCardConfig();
|
||||
// 试音卡三天后过期
|
||||
List<Long> uidList = activityAudioCardMapper.getAudioCardExpireByTime(audioCardId);
|
||||
Gift gift = giftService.newGetGiftById(audioCardId);
|
||||
BackpackReduceRecord record;
|
||||
Integer giftCount = 0;
|
||||
for(Long uid : uidList){
|
||||
record = new BackpackReduceRecord();
|
||||
List<UserBackpackVo> userBackpackList = userBackpackService.getUserBackpackList(uid);
|
||||
for(UserBackpackVo vo : userBackpackList){
|
||||
if(vo.getGiftId().equals(gift.getGiftId())){
|
||||
giftCount = vo.getCount();
|
||||
record.setCount(giftCount);
|
||||
}
|
||||
}
|
||||
record.setReduceCount(giftCount);
|
||||
record.setUid(uid);
|
||||
record.setReduceType(BackpackReduceRecordEnum.AUDIO_CARD.getValue());
|
||||
record.setObjDes(BackpackReduceRecordEnum.AUDIO_CARD.getDesc());
|
||||
record.setReduceTime(new Date());
|
||||
backpackReduceRecordMapper.insert(record);
|
||||
userBackpackService.reduceBackpackGift(uid,gift.getGiftId(),giftCount);
|
||||
log.info("试音卡活动:用户"+ uid + " 的试音卡过期,自动清空");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package com.accompany.scheduler.task.activity;
|
||||
|
||||
import com.accompany.business.service.activity.ChildrenActivityService;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
//@Component
|
||||
public class ChildrenActivityTask extends BaseTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ChildrenActivityTask.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
ChildrenActivityService childrenActivityService;
|
||||
|
||||
|
||||
/**
|
||||
* 活动结束发放奖励
|
||||
*/
|
||||
@Scheduled(cron = "0 41 11 29 5 *")
|
||||
public void sendBonus() {
|
||||
logger.info("ChildrenActivityTask sendBonus start ===============");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
String year = String.valueOf(calendar.get(Calendar.YEAR));
|
||||
logger.info("ChildrenActivityTask current year: {}", year);
|
||||
// 只在2020年执行任务
|
||||
if (year.equals("2020")) {
|
||||
childrenActivityService.sendBonus();
|
||||
}
|
||||
logger.info("ChildrenActivityTask sendBonus finish ===============");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 文 件 名: ActLuckyBagRankTask
|
||||
* 版 权:
|
||||
* 描 述: <描述>
|
||||
* 创建人: H1
|
||||
* 创建时间: 2022/4/18
|
||||
* 修改人:
|
||||
* 修改内容:
|
||||
* 修改时间:
|
||||
*/
|
||||
package com.accompany.scheduler.task.activity;
|
||||
|
||||
import com.accompany.business.service.activities.CpAct2022BizService;
|
||||
import com.accompany.business.service.activities.SummerAct2022BizService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* <br>类描述: 2022七夕定时任务
|
||||
* <br>功能详细描述:
|
||||
*
|
||||
* @author H1
|
||||
* @date [2022/4/18]
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CpAct2022Task {
|
||||
|
||||
@Autowired
|
||||
private CpAct2022BizService cpAct2022BizService;
|
||||
|
||||
/**
|
||||
* 2022七夕活动自动发放奖励
|
||||
*/
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
public void sendAward() {
|
||||
log.info("2022七夕活动自动发放奖励...");
|
||||
cpAct2022BizService.sendAward();
|
||||
}
|
||||
}
|
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 文 件 名: LuckySeaActTask
|
||||
* 版 权:
|
||||
* 描 述: <描述>
|
||||
* 创建人: H1
|
||||
* 创建时间: 2021/1/6
|
||||
* 修改人:
|
||||
* 修改内容:
|
||||
* 修改时间:
|
||||
*/
|
||||
package com.accompany.scheduler.task.activity;
|
||||
|
||||
import com.accompany.business.config.LuckySeaActConfig;
|
||||
import com.accompany.business.model.activity.LuckySeaItem;
|
||||
import com.accompany.business.service.activities.ActivitiesLuckySeaService;
|
||||
import com.accompany.business.vo.activities.LuckySeaActInfoVo;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.core.service.SysConfService;
|
||||
import com.accompany.core.util.StringUtils;
|
||||
import com.accompany.scheduler.base.BaseTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* <br>类描述:
|
||||
* <br>功能详细描述:
|
||||
*
|
||||
* @author H1
|
||||
* @date [2021/1/6]
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class LuckySeaActTask extends BaseTask {
|
||||
|
||||
@Autowired
|
||||
private ActivitiesLuckySeaService activitiesLuckySeaService;
|
||||
@Autowired
|
||||
private SysConfService sysConfService;
|
||||
|
||||
@PostConstruct
|
||||
public void handleLuckySeaAct() {
|
||||
ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
executorService.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runTask();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void runTask() {
|
||||
while (true) {
|
||||
// 活动开关是否开着
|
||||
Boolean actSwitch = Optional.ofNullable(
|
||||
Boolean.parseBoolean(sysConfService.getSysConfValueById(Constant.SysConfId.LUCKY_SEA_SWITCH))).orElse(false);
|
||||
log.info("深海奇缘活动, 开关状态: {}", actSwitch);
|
||||
if (actSwitch) {
|
||||
String modelType = sysConfService.getDefaultSysConfValueById(Constant.SysConfId.LUCKY_SEA_MODEL, Constant.luckySeaItemType.NORMAL.toString());
|
||||
log.info("深海奇缘活动, 当前模式: {}", modelType);
|
||||
String roundId = null;
|
||||
Date nextRoundStartTime = null;
|
||||
Long stock = activitiesLuckySeaService.getStock();
|
||||
try {
|
||||
boolean needCreateNewAct = true;
|
||||
boolean needWaitUserDraw = true;
|
||||
LuckySeaActConfig timeConfig = activitiesLuckySeaService.getLuckySeaTimeConfig();
|
||||
Integer waitUserDrawTime = timeConfig.getChooseStageTime();
|
||||
// 获取游戏的配置
|
||||
List<LuckySeaItem> itemList = activitiesLuckySeaService.listLuckySeaItem(Integer.valueOf(modelType));
|
||||
// 处理异常活动
|
||||
LuckySeaActInfoVo lastLuckySeaActInfo = activitiesLuckySeaService.getNewestLuckySeaActInfo(null);
|
||||
if (null != lastLuckySeaActInfo && StringUtils.isNotBlank(lastLuckySeaActInfo.getRoundId())) {
|
||||
if (lastLuckySeaActInfo.getStatus().equals(Constant.LuckySeaActStatus.CHOOSE_STAGE)) {
|
||||
needCreateNewAct = false;
|
||||
roundId = lastLuckySeaActInfo.getRoundId();
|
||||
Long intervalSecond = (System.currentTimeMillis() - lastLuckySeaActInfo.getStartTime().getTime()) / 1000;
|
||||
log.info("深海奇缘活动, 上一轮投注时间发生异常的活动到现在的间隔时间{}秒, roundId:{}", intervalSecond, roundId);
|
||||
if (intervalSecond <= timeConfig.getChooseStageTime()) {
|
||||
waitUserDrawTime = timeConfig.getChooseStageTime() - intervalSecond.intValue();
|
||||
log.info("深海奇缘活动, 上一轮投注时间发生异常的活动留给用户的下注时间{}秒", waitUserDrawTime);
|
||||
} else {
|
||||
log.info("深海奇缘活动, 上一轮投注时间发生异常的活动直接进行开奖, roundId:{}", roundId);
|
||||
needWaitUserDraw = false;
|
||||
}
|
||||
} else if (lastLuckySeaActInfo.getStatus().equals(Constant.LuckySeaActStatus.DRAWING)) {
|
||||
needCreateNewAct = false;
|
||||
needWaitUserDraw = false;
|
||||
roundId = lastLuckySeaActInfo.getRoundId();
|
||||
log.info("深海奇缘活动, 上一轮投注时间发生异常的活动直接进行开奖, roundId:{}", roundId);
|
||||
}
|
||||
}
|
||||
// 创建新的一轮游戏
|
||||
if (needCreateNewAct) {
|
||||
roundId = activitiesLuckySeaService.createNewRoundAct(nextRoundStartTime,timeConfig.getChooseStageTime() );
|
||||
}
|
||||
// 等待用户投碎片
|
||||
if (needWaitUserDraw) {
|
||||
log.info("深海奇缘活动, 开始等待用户投入碎片, currTime: {}", System.currentTimeMillis());
|
||||
Thread.sleep(waitUserDrawTime * 1000);
|
||||
log.info("深海奇缘活动, 结束等待用户投入碎片, currTime: {}", System.currentTimeMillis());
|
||||
}
|
||||
activitiesLuckySeaService.updateLuckyActStatus(roundId, Constant.LuckySeaActStatus.DRAWING);
|
||||
// 开奖
|
||||
Long drawSeconds = activitiesLuckySeaService.luckySeaActDraw(itemList, roundId, timeConfig, stock);
|
||||
// 异步更新用户抽奖记录
|
||||
activitiesLuckySeaService.updateUserDrawRecordAsync(roundId, itemList, Integer.valueOf(modelType));
|
||||
// 等待开奖动画与页面渲染开奖结果时间
|
||||
long sleepSeconds = timeConfig.getDrawOverStageTime() + timeConfig.getWaitingDrawStageTime() - drawSeconds;
|
||||
log.info("深海奇缘活动, 等待开奖动画与页面渲染开奖结果时间{}秒", sleepSeconds);
|
||||
Thread.sleep(sleepSeconds * 1000);
|
||||
log.info("深海奇缘活动此轮结束, roundId:{}", roundId);
|
||||
// 异步更新活动endTime
|
||||
nextRoundStartTime = new Date();
|
||||
activitiesLuckySeaService.endLuckyAct(roundId, nextRoundStartTime);
|
||||
} catch (Exception e) {
|
||||
// 更新活动状态, 此轮游戏标识为异常,不开始下一轮游戏
|
||||
log.error("深海奇缘活动出现异常, roundId: " + roundId, e);
|
||||
activitiesLuckySeaService.updateLuckyActStatus(roundId, Constant.LuckySeaActStatus.GAME_ABNORMAL);
|
||||
activitiesLuckySeaService.compensateUserPieceWhenGameAbnormal(roundId, stock);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
log.info("深海奇缘活动, 开关未开启,线程进入休眠: {}", actSwitch);
|
||||
Thread.sleep(60 * 1000);
|
||||
continue;
|
||||
} catch (Exception e){
|
||||
log.error("深海奇缘活动线程休眠时出现异常", e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user